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
24 #include "AliMUONGeometryDetElement.h"
28 #include <TGeoMatrix.h>
29 #include <Riostream.h>
34 ClassImp(AliMUONGeometryDetElement)
37 const TString AliMUONGeometryDetElement::fgkDENamePrefix = "DE";
39 //______________________________________________________________________________
40 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
42 /// Return the module name for given moduleId
44 TString deName(fgkDENamePrefix);
49 //______________________________________________________________________________
50 AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
52 fDEName(GetDEName(detElemId)),
54 fLocalTransformation(0),
55 fGlobalTransformation(0)
57 /// Standard constructor
59 SetUniqueID(detElemId);
62 //______________________________________________________________________________
63 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
65 const TString& volumePath)
67 fDEName(GetDEName(detElemId)),
68 fVolumePath(volumePath),
69 fLocalTransformation(0),
70 fGlobalTransformation(0)
72 /// Standard constructor
74 SetUniqueID(detElemId);
77 //______________________________________________________________________________
78 AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
82 fLocalTransformation(0),
83 fGlobalTransformation(0)
85 /// Root IO constructor
88 //______________________________________________________________________________
89 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
93 delete fLocalTransformation;
94 delete fGlobalTransformation;
101 //______________________________________________________________________________
102 void AliMUONGeometryDetElement::PrintTransform(
103 const TGeoHMatrix* transform) const
105 /// Print the detection element transformation
107 cout << "DetElemId: " << GetUniqueID();
108 cout << " name: " << fVolumePath << endl;
111 cout << " Transformation not defined." << endl;
115 const double* translation = transform->GetTranslation();
116 cout << " translation: "
117 #if defined (__DECCXX)
118 << translation[0] << ", "
119 << translation[1] << ", "
120 << translation[2] << endl;
123 << std::setw(7) << std::setprecision(4) << translation[0] << ", "
124 << std::setw(7) << std::setprecision(4) << translation[1] << ", "
125 << std::setw(7) << std::setprecision(4) << translation[2] << endl;
128 const double* rotation = transform->GetRotationMatrix();
129 cout << " rotation matrix: "
130 #if defined (__DECCXX)
131 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
133 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
135 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
138 << std::setw(7) << std::setprecision(4)
139 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
141 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
143 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
151 //______________________________________________________________________________
152 void AliMUONGeometryDetElement::Global2Local(
153 Float_t xg, Float_t yg, Float_t zg,
154 Float_t& xl, Float_t& yl, Float_t& zl) const
156 /// Transform point from the global reference frame (ALIC)
157 /// to the local reference frame of this detection element.
163 Double_t dxl, dyl, dzl;
164 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
171 //______________________________________________________________________________
172 void AliMUONGeometryDetElement::Global2Local(
173 Double_t xg, Double_t yg, Double_t zg,
174 Double_t& xl, Double_t& yl, Double_t& zl) const
176 /// Transform point from the global reference frame (ALIC)
177 /// to the local reference frame of this detection element
179 // Check transformation
180 if (!fGlobalTransformation) {
181 AliError(Form("Global transformation for detection element %d not defined.",
187 Double_t pg[3] = { xg, yg, zg };
188 Double_t pl[3] = { 0., 0., 0. };
189 fGlobalTransformation->MasterToLocal(pg, pl);
191 // Return transformed point
197 //______________________________________________________________________________
198 void AliMUONGeometryDetElement::Local2Global(
199 Float_t xl, Float_t yl, Float_t zl,
200 Float_t& xg, Float_t& yg, Float_t& zg) const
202 /// Transform point from the local reference frame of this detection element
203 /// to the global reference frame (ALIC).
209 Double_t dxg, dyg, dzg;
210 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
217 //______________________________________________________________________________
218 void AliMUONGeometryDetElement::Local2Global(
219 Double_t xl, Double_t yl, Double_t zl,
220 Double_t& xg, Double_t& yg, Double_t& zg) const
222 /// Transform point from the local reference frame of this detection element
223 /// to the global reference frame (ALIC).
225 // Check transformation
226 if (!fGlobalTransformation) {
227 AliError(Form("Global transformation for detection element %d not defined.",
233 Double_t pl[3] = { xl, yl, zl };
234 Double_t pg[3] = { 0., 0., 0. };
235 fGlobalTransformation->LocalToMaster(pl, pg);
237 // Return transformed point
243 //______________________________________________________________________________
244 void AliMUONGeometryDetElement::SetLocalTransformation(
245 const TGeoHMatrix& transform)
247 /// Set local transformation;
248 /// give warning if the global transformation is already defined.
250 if (fLocalTransformation) {
251 delete fLocalTransformation;
252 AliWarning("Local transformation already defined was deleted.");
255 fLocalTransformation = new TGeoHMatrix(transform);
258 //______________________________________________________________________________
259 void AliMUONGeometryDetElement::SetGlobalTransformation(
260 const TGeoHMatrix& transform)
262 /// Set global transformation;
263 /// give warning if the global transformation is already defined.
265 if (fGlobalTransformation) {
266 delete fGlobalTransformation;
267 AliWarning("Global transformation already defined was deleted.");
270 fGlobalTransformation = new TGeoHMatrix(transform);
273 //______________________________________________________________________________
274 void AliMUONGeometryDetElement::PrintLocalTransform() const
276 /// Print detection element relative transformation
277 /// (the transformation wrt module frame)
279 PrintTransform(fLocalTransformation);
282 //______________________________________________________________________________
283 void AliMUONGeometryDetElement::PrintGlobalTransform() const
285 /// Print detection element global transformation
286 /// (the transformation wrt global frame)
288 PrintTransform(fGlobalTransformation);
291 //______________________________________________________________________________
292 TString AliMUONGeometryDetElement::GetVolumeName() const
294 /// Extract volume name from the path
296 std::string volPath = fVolumePath.Data();
297 std::string::size_type first = volPath.rfind('/')+1;
298 std::string::size_type last = volPath.rfind('_');
300 return volPath.substr(first, last-first );
303 //______________________________________________________________________________
304 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
306 /// Extract volume copyNo from the path
308 string volPath = fVolumePath.Data();
309 std::string::size_type first = volPath.rfind('_');
310 std::string copyNoStr = volPath.substr(first+1, volPath.length());
311 std::istringstream in(copyNoStr);