1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 // Class AliMUONGeometryDetElement
20 // --------------------------------------
21 // The class defines the detection element.
22 // Author: Ivana Hrivnacova, IPN Orsay
23 //-----------------------------------------------------------------------------
25 #include "AliMUONGeometryDetElement.h"
29 #include <TGeoMatrix.h>
30 #include <Riostream.h>
35 ClassImp(AliMUONGeometryDetElement)
42 //______________________________________________________________________________
43 const TString& AliMUONGeometryDetElement::GetDENamePrefix()
45 ///< Geometry DE name prefix
46 static const TString kDENamePrefix = "DE";
50 //______________________________________________________________________________
51 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
53 /// Return the module name for given moduleId
55 TString deName(GetDENamePrefix());
60 //______________________________________________________________________________
61 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
63 fDEName(GetDEName(detElemId)),
65 fLocalTransformation(0),
66 fGlobalTransformation(0)
68 /// Standard constructor
70 SetUniqueID(detElemId);
73 //______________________________________________________________________________
74 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
76 const TString& volumePath)
78 fDEName(GetDEName(detElemId)),
79 fVolumePath(volumePath),
80 fLocalTransformation(0),
81 fGlobalTransformation(0)
83 /// Standard constructor
85 SetUniqueID(detElemId);
88 //______________________________________________________________________________
89 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
93 fLocalTransformation(0),
94 fGlobalTransformation(0)
96 /// Root IO constructor
99 //______________________________________________________________________________
100 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
104 delete fLocalTransformation;
105 delete fGlobalTransformation;
112 //______________________________________________________________________________
113 void AliMUONGeometryDetElement::PrintTransform(
114 const TGeoHMatrix* transform) const
116 /// Print the detection element transformation
118 cout << "DetElemId: " << GetUniqueID();
119 cout << " name: " << fVolumePath << endl;
122 cout << " Transformation not defined." << endl;
126 const double* translation = transform->GetTranslation();
127 cout << " translation: "
128 #if defined (__DECCXX)
129 << translation[0] << ", "
130 << translation[1] << ", "
131 << translation[2] << endl;
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;
139 const double* rotation = transform->GetRotationMatrix();
140 cout << " rotation matrix: "
141 #if defined (__DECCXX)
142 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
144 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
146 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
149 << std::setw(7) << std::setprecision(4)
150 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
152 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
154 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
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
167 /// Transform point from the global reference frame (ALIC)
168 /// to the local reference frame of this detection element.
174 Double_t dxl, dyl, dzl;
175 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
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
187 /// Transform point from the global reference frame (ALIC)
188 /// to the local reference frame of this detection element
190 // Check transformation
191 if (!fGlobalTransformation) {
192 AliError(Form("Global transformation for detection element %d not defined.",
198 Double_t pg[3] = { xg, yg, zg };
199 Double_t pl[3] = { 0., 0., 0. };
200 fGlobalTransformation->MasterToLocal(pg, pl);
202 // Return transformed point
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
213 /// Transform point from the local reference frame of this detection element
214 /// to the global reference frame (ALIC).
220 Double_t dxg, dyg, dzg;
221 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
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
233 /// Transform point from the local reference frame of this detection element
234 /// to the global reference frame (ALIC).
236 // Check transformation
237 if (!fGlobalTransformation) {
238 AliError(Form("Global transformation for detection element %d not defined.",
244 Double_t pl[3] = { xl, yl, zl };
245 Double_t pg[3] = { 0., 0., 0. };
246 fGlobalTransformation->LocalToMaster(pl, pg);
248 // Return transformed point
254 //______________________________________________________________________________
255 void AliMUONGeometryDetElement::SetLocalTransformation(
256 const TGeoHMatrix& transform,
259 /// Set local transformation;
260 /// give warning if the global transformation is already defined.
262 if ( fLocalTransformation ) {
263 delete fLocalTransformation;
265 AliWarning("Local transformation already defined was deleted.");
269 fLocalTransformation = new TGeoHMatrix(transform);
272 //______________________________________________________________________________
273 void AliMUONGeometryDetElement::SetGlobalTransformation(
274 const TGeoHMatrix& transform,
277 /// Set global transformation;
278 /// give warning if the global transformation is already defined.
280 if (fGlobalTransformation) {
281 delete fGlobalTransformation;
283 AliWarning("Global transformation already defined was deleted.");
287 fGlobalTransformation = new TGeoHMatrix(transform);
290 //______________________________________________________________________________
291 void AliMUONGeometryDetElement::PrintLocalTransform() const
293 /// Print detection element relative transformation
294 /// (the transformation wrt module frame)
296 PrintTransform(fLocalTransformation);
299 //______________________________________________________________________________
300 void AliMUONGeometryDetElement::PrintGlobalTransform() const
302 /// Print detection element global transformation
303 /// (the transformation wrt global frame)
305 PrintTransform(fGlobalTransformation);
308 //______________________________________________________________________________
309 TString AliMUONGeometryDetElement::GetVolumeName() const
311 /// Extract volume name from the path
313 std::string volPath = fVolumePath.Data();
314 std::string::size_type first = volPath.rfind('/')+1;
315 std::string::size_type last = volPath.rfind('_');
317 return volPath.substr(first, last-first );
320 //______________________________________________________________________________
321 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
323 /// Extract volume copyNo from the path
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);