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