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)
38 const TString AliMUONGeometryDetElement::fgkDENamePrefix = "DE";
40 //______________________________________________________________________________
41 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
43 /// Return the module name for given moduleId
45 TString deName(fgkDENamePrefix);
50 //______________________________________________________________________________
51 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
53 fDEName(GetDEName(detElemId)),
55 fLocalTransformation(0),
56 fGlobalTransformation(0)
58 /// Standard constructor
60 SetUniqueID(detElemId);
63 //______________________________________________________________________________
64 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
66 const TString& volumePath)
68 fDEName(GetDEName(detElemId)),
69 fVolumePath(volumePath),
70 fLocalTransformation(0),
71 fGlobalTransformation(0)
73 /// Standard constructor
75 SetUniqueID(detElemId);
78 //______________________________________________________________________________
79 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
83 fLocalTransformation(0),
84 fGlobalTransformation(0)
86 /// Root IO constructor
89 //______________________________________________________________________________
90 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
94 delete fLocalTransformation;
95 delete fGlobalTransformation;
102 //______________________________________________________________________________
103 void AliMUONGeometryDetElement::PrintTransform(
104 const TGeoHMatrix* transform) const
106 /// Print the detection element transformation
108 cout << "DetElemId: " << GetUniqueID();
109 cout << " name: " << fVolumePath << endl;
112 cout << " Transformation not defined." << endl;
116 const double* translation = transform->GetTranslation();
117 cout << " translation: "
118 #if defined (__DECCXX)
119 << translation[0] << ", "
120 << translation[1] << ", "
121 << translation[2] << endl;
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;
129 const double* rotation = transform->GetRotationMatrix();
130 cout << " rotation matrix: "
131 #if defined (__DECCXX)
132 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
134 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
136 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
139 << std::setw(7) << std::setprecision(4)
140 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
142 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
144 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
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
157 /// Transform point from the global reference frame (ALIC)
158 /// to the local reference frame of this detection element.
164 Double_t dxl, dyl, dzl;
165 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
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
177 /// Transform point from the global reference frame (ALIC)
178 /// to the local reference frame of this detection element
180 // Check transformation
181 if (!fGlobalTransformation) {
182 AliError(Form("Global transformation for detection element %d not defined.",
188 Double_t pg[3] = { xg, yg, zg };
189 Double_t pl[3] = { 0., 0., 0. };
190 fGlobalTransformation->MasterToLocal(pg, pl);
192 // Return transformed point
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
203 /// Transform point from the local reference frame of this detection element
204 /// to the global reference frame (ALIC).
210 Double_t dxg, dyg, dzg;
211 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
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
223 /// Transform point from the local reference frame of this detection element
224 /// to the global reference frame (ALIC).
226 // Check transformation
227 if (!fGlobalTransformation) {
228 AliError(Form("Global transformation for detection element %d not defined.",
234 Double_t pl[3] = { xl, yl, zl };
235 Double_t pg[3] = { 0., 0., 0. };
236 fGlobalTransformation->LocalToMaster(pl, pg);
238 // Return transformed point
244 //______________________________________________________________________________
245 void AliMUONGeometryDetElement::SetLocalTransformation(
246 const TGeoHMatrix& transform,
249 /// Set local transformation;
250 /// give warning if the global transformation is already defined.
252 if ( fLocalTransformation ) {
253 delete fLocalTransformation;
255 AliWarning("Local transformation already defined was deleted.");
259 fLocalTransformation = new TGeoHMatrix(transform);
262 //______________________________________________________________________________
263 void AliMUONGeometryDetElement::SetGlobalTransformation(
264 const TGeoHMatrix& transform,
267 /// Set global transformation;
268 /// give warning if the global transformation is already defined.
270 if (fGlobalTransformation) {
271 delete fGlobalTransformation;
273 AliWarning("Global transformation already defined was deleted.");
277 fGlobalTransformation = new TGeoHMatrix(transform);
280 //______________________________________________________________________________
281 void AliMUONGeometryDetElement::PrintLocalTransform() const
283 /// Print detection element relative transformation
284 /// (the transformation wrt module frame)
286 PrintTransform(fLocalTransformation);
289 //______________________________________________________________________________
290 void AliMUONGeometryDetElement::PrintGlobalTransform() const
292 /// Print detection element global transformation
293 /// (the transformation wrt global frame)
295 PrintTransform(fGlobalTransformation);
298 //______________________________________________________________________________
299 TString AliMUONGeometryDetElement::GetVolumeName() const
301 /// Extract volume name from the path
303 std::string volPath = fVolumePath.Data();
304 std::string::size_type first = volPath.rfind('/')+1;
305 std::string::size_type last = volPath.rfind('_');
307 return volPath.substr(first, last-first );
310 //______________________________________________________________________________
311 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
313 /// Extract volume copyNo from the path
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);