]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryDetElement.cxx
Number of readout errors was not properly histogrammed
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryDetElement.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17
18 //-----------------------------------------------------------------------------
19 // Class AliMUONGeometryDetElement
20 // --------------------------------------
21 // The class defines the detection element.
22 // Author: Ivana Hrivnacova, IPN Orsay
23 //-----------------------------------------------------------------------------
24
25 #include "AliMUONGeometryDetElement.h"
26
27 #include "AliLog.h"
28
29 #include <TGeoMatrix.h>
30 #include <Riostream.h>
31
32 #include <sstream>
33
34 /// \cond CLASSIMP
35 ClassImp(AliMUONGeometryDetElement)
36 /// \endcond
37
38 //
39 // static methods
40 //
41
42 //______________________________________________________________________________
43 const TString& AliMUONGeometryDetElement::GetDENamePrefix()
44 {
45   ///< Geometry DE name prefix
46   static const TString kDENamePrefix = "DE";
47   return kDENamePrefix;
48 }  
49
50 //______________________________________________________________________________
51 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
52 {
53 /// Return the module name for given moduleId
54
55   TString deName(GetDENamePrefix());
56   deName += detElemId;
57   return deName;
58 }   
59
60 //______________________________________________________________________________
61 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
62  : TObject(),
63    fDEName(GetDEName(detElemId)),
64    fVolumePath(),
65    fLocalTransformation(0),
66    fGlobalTransformation(0)
67
68 /// Standard constructor
69
70   SetUniqueID(detElemId);
71 }
72
73 //______________________________________________________________________________
74 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
75                                         Int_t detElemId,
76                                         const TString& volumePath)
77  : TObject(),
78    fDEName(GetDEName(detElemId)),
79    fVolumePath(volumePath),
80    fLocalTransformation(0),
81    fGlobalTransformation(0)
82
83 /// Standard constructor
84
85   SetUniqueID(detElemId);
86 }
87
88 //______________________________________________________________________________
89 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
90  : TObject(),
91    fDEName(),
92    fVolumePath(),
93    fLocalTransformation(0),
94    fGlobalTransformation(0)
95 {
96 /// Root IO constructor
97 }
98
99 //______________________________________________________________________________
100 AliMUONGeometryDetElement::~AliMUONGeometryDetElement() 
101 {
102 /// Destructor
103
104   delete fLocalTransformation;
105   delete fGlobalTransformation;
106 }
107
108 //
109 // private methods
110 //
111
112 //______________________________________________________________________________
113 void  AliMUONGeometryDetElement::PrintTransform(
114                                             const TGeoHMatrix* transform) const
115 {
116 /// Print the detection element transformation
117
118   cout << "DetElemId: " << GetUniqueID();
119   cout << "  name: " << fVolumePath << endl;
120
121   if ( !transform ) {
122     cout << "    Transformation not defined." << endl;
123     return;
124   }  
125
126   const double* translation = transform->GetTranslation();
127   cout << "   translation: "
128 #if defined (__DECCXX)
129        << translation[0] << ", " 
130        << translation[1] << ", "
131        << translation[2] << endl;
132 #else
133        << std::fixed
134        << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
135        << std::setw(7) << std::setprecision(4) << translation[1] << ", "
136        << std::setw(7) << std::setprecision(4) << translation[2] << endl;
137 #endif
138          
139   const double* rotation = transform->GetRotationMatrix();
140   cout << "   rotation matrix:  "
141 #if defined (__DECCXX)
142        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
143        << "                     "           
144        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
145        << "                     "           
146        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
147 #else
148        << std::fixed
149        << std::setw(7) << std::setprecision(4) 
150        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
151        << "                     "           
152        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
153        << "                     "           
154        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
155 #endif
156 }     
157
158 //
159 // public methods
160 //
161
162 //______________________________________________________________________________
163 void  AliMUONGeometryDetElement::Global2Local(
164                                   Float_t xg, Float_t yg, Float_t zg, 
165                                   Float_t& xl, Float_t& yl, Float_t& zl) const
166 {
167 /// Transform point from the global reference frame (ALIC)
168 /// to the local reference frame of this detection element.
169
170   Double_t dxg = xg;
171   Double_t dyg = yg;
172   Double_t dzg = zg;
173
174   Double_t dxl, dyl, dzl;
175   Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);  
176   
177   xl = dxl;
178   yl = dyl;
179   zl = dzl;
180 }
181                                   
182 //______________________________________________________________________________
183 void  AliMUONGeometryDetElement::Global2Local(
184                                   Double_t xg, Double_t yg, Double_t zg, 
185                                   Double_t& xl, Double_t& yl, Double_t& zl) const
186 {
187 /// Transform point from the global reference frame (ALIC)
188 /// to the local reference frame of this detection element
189
190    // Check transformation
191    if (!fGlobalTransformation) {
192      AliError(Form("Global transformation for detection element %d not defined.",
193                     GetUniqueID()));
194      return;
195    }  
196    
197    // Transform point 
198    Double_t pg[3] = { xg, yg, zg };
199    Double_t pl[3] = { 0., 0., 0. };
200    fGlobalTransformation->MasterToLocal(pg, pl);
201    
202    // Return transformed point
203    xl = pl[0];
204    yl = pl[1];     
205    zl = pl[2];  
206 }
207                                   
208 //______________________________________________________________________________
209 void  AliMUONGeometryDetElement::Local2Global(
210                  Float_t xl, Float_t yl, Float_t zl, 
211                  Float_t& xg, Float_t& yg, Float_t& zg) const
212 {
213 /// Transform point from the local reference frame of this detection element 
214 /// to the global reference frame (ALIC).
215
216   Double_t dxl = xl;
217   Double_t dyl = yl;
218   Double_t dzl = zl;
219
220   Double_t dxg, dyg, dzg;
221   Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);  
222   
223   xg = dxg;
224   yg = dyg;
225   zg = dzg;
226 }
227
228 //______________________________________________________________________________
229 void  AliMUONGeometryDetElement::Local2Global(
230                  Double_t xl, Double_t yl, Double_t zl, 
231                  Double_t& xg, Double_t& yg, Double_t& zg) const
232 {
233 /// Transform point from the local reference frame of this detection element 
234 /// to the global reference frame (ALIC).
235
236    // Check transformation
237    if (!fGlobalTransformation) {
238      AliError(Form("Global transformation for detection element %d not defined.",
239                     GetUniqueID()));
240      return;
241    }  
242    
243    // Transform point 
244    Double_t pl[3] = { xl, yl, zl };
245    Double_t pg[3] = { 0., 0., 0. };
246    fGlobalTransformation->LocalToMaster(pl, pg);
247    
248    // Return transformed point
249    xg = pg[0];
250    yg = pg[1];     
251    zg = pg[2];  
252 }
253
254 //______________________________________________________________________________
255 void AliMUONGeometryDetElement::SetLocalTransformation(
256                                                 const TGeoHMatrix& transform, 
257                                                 Bool_t warn)
258
259 /// Set local transformation;
260 /// give warning if the global transformation is already defined.
261  
262   if ( fLocalTransformation ) {
263     delete fLocalTransformation;
264     if ( warn ) {
265       AliWarning("Local transformation already defined was deleted.");
266     }  
267   }  
268
269   fLocalTransformation = new TGeoHMatrix(transform);
270 }  
271                                               
272 //______________________________________________________________________________
273 void AliMUONGeometryDetElement::SetGlobalTransformation(
274                                                 const TGeoHMatrix& transform,
275                                                 Bool_t warn)
276
277 /// Set global transformation;
278 /// give warning if the global transformation is already defined.
279  
280   if (fGlobalTransformation) {
281     delete fGlobalTransformation;
282     if ( warn ) {
283       AliWarning("Global transformation already defined was deleted.");
284     }  
285   }  
286
287   fGlobalTransformation = new TGeoHMatrix(transform);
288 }  
289                                               
290 //______________________________________________________________________________
291 void AliMUONGeometryDetElement::PrintLocalTransform() const
292 {
293 /// Print detection element relative transformation
294 /// (the transformation wrt module frame)
295
296   PrintTransform(fLocalTransformation);
297 }  
298
299 //______________________________________________________________________________
300 void AliMUONGeometryDetElement::PrintGlobalTransform() const
301 {
302 /// Print detection element global transformation
303 /// (the transformation wrt global frame)
304
305   PrintTransform(fGlobalTransformation);
306 }  
307
308 //______________________________________________________________________________
309 TString AliMUONGeometryDetElement::GetVolumeName() const
310
311 /// Extract volume name from the path
312   
313   std::string volPath = fVolumePath.Data();
314   std::string::size_type first = volPath.rfind('/')+1;
315   std::string::size_type last = volPath.rfind('_');
316   
317   return volPath.substr(first, last-first );
318 }
319
320 //______________________________________________________________________________
321 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
322
323 /// Extract volume copyNo from the path
324   
325   string volPath = fVolumePath.Data();
326   std::string::size_type first = volPath.rfind('_');
327   std::string copyNoStr = volPath.substr(first+1, volPath.length());
328   std::istringstream in(copyNoStr);
329   Int_t copyNo;
330   in >> copyNo;
331   
332   return copyNo;
333 }
334