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