]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryDetElement.cxx
930fb24000b97fc460e08bb563a34c5b5bce1d9b
[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 #include "AliMUONGeometryDetElement.h"
25
26 #include "AliLog.h"
27
28 #include <TGeoMatrix.h>
29 #include <Riostream.h>
30
31 #include <sstream>
32
33 /// \cond CLASSIMP
34 ClassImp(AliMUONGeometryDetElement)
35 /// \endcond
36
37 const TString AliMUONGeometryDetElement::fgkDENamePrefix = "DE";
38
39 //______________________________________________________________________________
40 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
41 {
42 /// Return the module name for given moduleId
43
44   TString deName(fgkDENamePrefix);
45   deName += detElemId;
46   return deName;
47 }   
48
49 //______________________________________________________________________________
50 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
51  : TObject(),
52    fDEName(GetDEName(detElemId)),
53    fVolumePath(),
54    fLocalTransformation(0),
55    fGlobalTransformation(0)
56
57 /// Standard constructor
58
59   SetUniqueID(detElemId);
60 }
61
62 //______________________________________________________________________________
63 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
64                                         Int_t detElemId,
65                                         const TString& volumePath)
66  : TObject(),
67    fDEName(GetDEName(detElemId)),
68    fVolumePath(volumePath),
69    fLocalTransformation(0),
70    fGlobalTransformation(0)
71
72 /// Standard constructor
73
74   SetUniqueID(detElemId);
75 }
76
77 //______________________________________________________________________________
78 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
79  : TObject(),
80    fDEName(),
81    fVolumePath(),
82    fLocalTransformation(0),
83    fGlobalTransformation(0)
84 {
85 /// Root IO constructor
86 }
87
88 //______________________________________________________________________________
89 AliMUONGeometryDetElement::~AliMUONGeometryDetElement() 
90 {
91 /// Destructor
92
93   delete fLocalTransformation;
94   delete fGlobalTransformation;
95 }
96
97 //
98 // private methods
99 //
100
101 //______________________________________________________________________________
102 void  AliMUONGeometryDetElement::PrintTransform(
103                                             const TGeoHMatrix* transform) const
104 {
105 /// Print the detection element transformation
106
107   cout << "DetElemId: " << GetUniqueID();
108   cout << "  name: " << fVolumePath << endl;
109
110   if ( !transform ) {
111     cout << "    Transformation not defined." << endl;
112     return;
113   }  
114
115   const double* translation = transform->GetTranslation();
116   cout << "   translation: "
117 #if defined (__DECCXX)
118        << translation[0] << ", " 
119        << translation[1] << ", "
120        << translation[2] << endl;
121 #else
122        << std::fixed
123        << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
124        << std::setw(7) << std::setprecision(4) << translation[1] << ", "
125        << std::setw(7) << std::setprecision(4) << translation[2] << endl;
126 #endif
127          
128   const double* rotation = transform->GetRotationMatrix();
129   cout << "   rotation matrix:  "
130 #if defined (__DECCXX)
131        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
132        << "                     "           
133        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
134        << "                     "           
135        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
136 #else
137        << std::fixed
138        << std::setw(7) << std::setprecision(4) 
139        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
140        << "                     "           
141        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
142        << "                     "           
143        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
144 #endif
145 }     
146
147 //
148 // public methods
149 //
150
151 //______________________________________________________________________________
152 void  AliMUONGeometryDetElement::Global2Local(
153                                   Float_t xg, Float_t yg, Float_t zg, 
154                                   Float_t& xl, Float_t& yl, Float_t& zl) const
155 {
156 /// Transform point from the global reference frame (ALIC)
157 /// to the local reference frame of this detection element.
158
159   Double_t dxg = xg;
160   Double_t dyg = yg;
161   Double_t dzg = zg;
162
163   Double_t dxl, dyl, dzl;
164   Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);  
165   
166   xl = dxl;
167   yl = dyl;
168   zl = dzl;
169 }
170                                   
171 //______________________________________________________________________________
172 void  AliMUONGeometryDetElement::Global2Local(
173                                   Double_t xg, Double_t yg, Double_t zg, 
174                                   Double_t& xl, Double_t& yl, Double_t& zl) const
175 {
176 /// Transform point from the global reference frame (ALIC)
177 /// to the local reference frame of this detection element
178
179    // Check transformation
180    if (!fGlobalTransformation) {
181      AliError(Form("Global transformation for detection element %d not defined.",
182                     GetUniqueID()));
183      return;
184    }  
185    
186    // Transform point 
187    Double_t pg[3] = { xg, yg, zg };
188    Double_t pl[3] = { 0., 0., 0. };
189    fGlobalTransformation->MasterToLocal(pg, pl);
190    
191    // Return transformed point
192    xl = pl[0];
193    yl = pl[1];     
194    zl = pl[2];  
195 }
196                                   
197 //______________________________________________________________________________
198 void  AliMUONGeometryDetElement::Local2Global(
199                  Float_t xl, Float_t yl, Float_t zl, 
200                  Float_t& xg, Float_t& yg, Float_t& zg) const
201 {
202 /// Transform point from the local reference frame of this detection element 
203 /// to the global reference frame (ALIC).
204
205   Double_t dxl = xl;
206   Double_t dyl = yl;
207   Double_t dzl = zl;
208
209   Double_t dxg, dyg, dzg;
210   Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);  
211   
212   xg = dxg;
213   yg = dyg;
214   zg = dzg;
215 }
216
217 //______________________________________________________________________________
218 void  AliMUONGeometryDetElement::Local2Global(
219                  Double_t xl, Double_t yl, Double_t zl, 
220                  Double_t& xg, Double_t& yg, Double_t& zg) const
221 {
222 /// Transform point from the local reference frame of this detection element 
223 /// to the global reference frame (ALIC).
224
225    // Check transformation
226    if (!fGlobalTransformation) {
227      AliError(Form("Global transformation for detection element %d not defined.",
228                     GetUniqueID()));
229      return;
230    }  
231    
232    // Transform point 
233    Double_t pl[3] = { xl, yl, zl };
234    Double_t pg[3] = { 0., 0., 0. };
235    fGlobalTransformation->LocalToMaster(pl, pg);
236    
237    // Return transformed point
238    xg = pg[0];
239    yg = pg[1];     
240    zg = pg[2];  
241 }
242
243 //______________________________________________________________________________
244 void AliMUONGeometryDetElement::SetLocalTransformation(
245                                                 const TGeoHMatrix& transform)
246
247 /// Set local transformation;
248 /// give warning if the global transformation is already defined.
249  
250   if (fLocalTransformation) {
251     delete fLocalTransformation;
252     AliWarning("Local transformation already defined was deleted.");
253   }  
254
255   fLocalTransformation = new TGeoHMatrix(transform);
256 }  
257                                               
258 //______________________________________________________________________________
259 void AliMUONGeometryDetElement::SetGlobalTransformation(
260                                                 const TGeoHMatrix& transform)
261
262 /// Set global transformation;
263 /// give warning if the global transformation is already defined.
264  
265   if (fGlobalTransformation) {
266     delete fGlobalTransformation;
267     AliWarning("Global transformation already defined was deleted.");
268   }  
269
270   fGlobalTransformation = new TGeoHMatrix(transform);
271 }  
272                                               
273 //______________________________________________________________________________
274 void AliMUONGeometryDetElement::PrintLocalTransform() const
275 {
276 /// Print detection element relative transformation
277 /// (the transformation wrt module frame)
278
279   PrintTransform(fLocalTransformation);
280 }  
281
282 //______________________________________________________________________________
283 void AliMUONGeometryDetElement::PrintGlobalTransform() const
284 {
285 /// Print detection element global transformation
286 /// (the transformation wrt global frame)
287
288   PrintTransform(fGlobalTransformation);
289 }  
290
291 //______________________________________________________________________________
292 TString AliMUONGeometryDetElement::GetVolumeName() const
293
294 /// Extract volume name from the path
295   
296   std::string volPath = fVolumePath.Data();
297   std::string::size_type first = volPath.rfind('/')+1;
298   std::string::size_type last = volPath.rfind('_');
299   
300   return volPath.substr(first, last-first );
301 }
302
303 //______________________________________________________________________________
304 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
305
306 /// Extract volume copyNo from the path
307   
308   string volPath = fVolumePath.Data();
309   std::string::size_type first = volPath.rfind('_');
310   std::string copyNoStr = volPath.substr(first+1, volPath.length());
311   std::istringstream in(copyNoStr);
312   Int_t copyNo;
313   in >> copyNo;
314   
315   return copyNo;
316 }
317