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>
38 ClassImp(AliMUONGeometryDetElement)
45 //______________________________________________________________________________
46 const TString& AliMUONGeometryDetElement::GetDENamePrefix()
48 ///< Geometry DE name prefix
49 static const TString kDENamePrefix = "DE";
53 //______________________________________________________________________________
54 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
56 /// Return the module name for given moduleId
58 TString deName(GetDENamePrefix());
63 //______________________________________________________________________________
64 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
66 fDEName(GetDEName(detElemId)),
68 fLocalTransformation(0),
69 fGlobalTransformation(0)
71 /// Standard constructor
73 SetUniqueID(detElemId);
76 //______________________________________________________________________________
77 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
79 const TString& volumePath)
81 fDEName(GetDEName(detElemId)),
82 fVolumePath(volumePath),
83 fLocalTransformation(0),
84 fGlobalTransformation(0)
86 /// Standard constructor
88 SetUniqueID(detElemId);
91 //______________________________________________________________________________
92 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
96 fLocalTransformation(0),
97 fGlobalTransformation(0)
99 /// Root IO constructor
102 //______________________________________________________________________________
103 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
107 delete fLocalTransformation;
108 delete fGlobalTransformation;
115 //______________________________________________________________________________
116 void AliMUONGeometryDetElement::PrintTransform(
117 const TGeoHMatrix* transform) const
119 /// Print the detection element transformation
121 cout << "DetElemId: " << GetUniqueID();
122 cout << " name: " << fVolumePath << endl;
125 cout << " Transformation not defined." << endl;
129 const double* translation = transform->GetTranslation();
130 cout << " translation: "
131 #if defined (__DECCXX)
132 << translation[0] << ", "
133 << translation[1] << ", "
134 << translation[2] << endl;
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;
142 const double* rotation = transform->GetRotationMatrix();
143 cout << " rotation matrix: "
144 #if defined (__DECCXX)
145 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
147 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
149 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
152 << std::setw(7) << std::setprecision(4)
153 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
155 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
157 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
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
170 /// Transform point from the global reference frame (ALIC)
171 /// to the local reference frame of this detection element.
177 Double_t dxl, dyl, dzl;
178 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
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
190 /// Transform point from the global reference frame (ALIC)
191 /// to the local reference frame of this detection element
193 // Check transformation
194 if (!fGlobalTransformation) {
195 AliError(Form("Global transformation for detection element %d not defined.",
201 Double_t pg[3] = { xg, yg, zg };
202 Double_t pl[3] = { 0., 0., 0. };
203 fGlobalTransformation->MasterToLocal(pg, pl);
205 // Return transformed point
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
216 /// Transform point from the local reference frame of this detection element
217 /// to the global reference frame (ALIC).
223 Double_t dxg, dyg, dzg;
224 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
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
236 /// Transform point from the local reference frame of this detection element
237 /// to the global reference frame (ALIC).
239 // Check transformation
240 if (!fGlobalTransformation) {
241 AliError(Form("Global transformation for detection element %d not defined.",
247 Double_t pl[3] = { xl, yl, zl };
248 Double_t pg[3] = { 0., 0., 0. };
249 fGlobalTransformation->LocalToMaster(pl, pg);
251 // Return transformed point
257 //______________________________________________________________________________
258 void AliMUONGeometryDetElement::SetLocalTransformation(
259 const TGeoHMatrix& transform,
262 /// Set local transformation;
263 /// give warning if the global transformation is already defined.
265 if ( fLocalTransformation ) {
266 delete fLocalTransformation;
268 AliWarning("Local transformation already defined was deleted.");
272 fLocalTransformation = new TGeoHMatrix(transform);
275 //______________________________________________________________________________
276 void AliMUONGeometryDetElement::SetGlobalTransformation(
277 const TGeoHMatrix& transform,
280 /// Set global transformation;
281 /// give warning if the global transformation is already defined.
283 if (fGlobalTransformation) {
284 delete fGlobalTransformation;
286 AliWarning("Global transformation already defined was deleted.");
290 fGlobalTransformation = new TGeoHMatrix(transform);
293 //______________________________________________________________________________
294 void AliMUONGeometryDetElement::PrintLocalTransform() const
296 /// Print detection element relative transformation
297 /// (the transformation wrt module frame)
299 PrintTransform(fLocalTransformation);
302 //______________________________________________________________________________
303 void AliMUONGeometryDetElement::PrintGlobalTransform() const
305 /// Print detection element global transformation
306 /// (the transformation wrt global frame)
308 PrintTransform(fGlobalTransformation);
311 //______________________________________________________________________________
312 TString AliMUONGeometryDetElement::GetVolumeName() const
314 /// Extract volume name from the path
316 std::string volPath = fVolumePath.Data();
317 std::string::size_type first = volPath.rfind('/')+1;
318 std::string::size_type last = volPath.rfind('_');
320 return volPath.substr(first, last-first );
323 //______________________________________________________________________________
324 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
326 /// Extract volume copyNo from the path
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);