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