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 //______________________________________________________________________________
38 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
40 const TString& volumePath)
42 fVolumePath(volumePath),
43 fLocalTransformation(0),
44 fGlobalTransformation(0)
46 /// Standard constructor
48 SetUniqueID(detElemId);
51 //______________________________________________________________________________
52 AliMUONGeometryDetElement::AliMUONGeometryDetElement()
55 fLocalTransformation(0),
56 fGlobalTransformation(0)
58 /// Default constructor
61 //______________________________________________________________________________
62 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
66 delete fLocalTransformation;
67 delete fGlobalTransformation;
74 //______________________________________________________________________________
75 void AliMUONGeometryDetElement::PrintTransform(
76 const TGeoHMatrix* transform) const
78 /// Print the detection element transformation
80 cout << "DetElemId: " << GetUniqueID();
81 cout << " name: " << fVolumePath << endl;
84 cout << " Transformation not defined." << endl;
88 const double* translation = transform->GetTranslation();
89 cout << " translation: "
90 #if defined (__DECCXX)
91 << translation[0] << ", "
92 << translation[1] << ", "
93 << translation[2] << endl;
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;
101 const double* rotation = transform->GetRotationMatrix();
102 cout << " rotation matrix: "
103 #if defined (__DECCXX)
104 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
106 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
108 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
111 << std::setw(7) << std::setprecision(4)
112 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
114 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
116 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
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
129 /// Transform point from the global reference frame (ALIC)
130 /// to the local reference frame of this detection element.
136 Double_t dxl, dyl, dzl;
137 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
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
149 /// Transform point from the global reference frame (ALIC)
150 /// to the local reference frame of this detection element
152 // Check transformation
153 if (!fGlobalTransformation) {
154 AliError(Form("Global transformation for detection element %d not defined.",
160 Double_t pg[3] = { xg, yg, zg };
161 Double_t pl[3] = { 0., 0., 0. };
162 fGlobalTransformation->MasterToLocal(pg, pl);
164 // Return transformed point
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
175 /// Transform point from the local reference frame of this detection element
176 /// to the global reference frame (ALIC).
182 Double_t dxg, dyg, dzg;
183 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
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
195 /// Transform point from the local reference frame of this detection element
196 /// to the global reference frame (ALIC).
198 // Check transformation
199 if (!fGlobalTransformation) {
200 AliError(Form("Global transformation for detection element %d not defined.",
206 Double_t pl[3] = { xl, yl, zl };
207 Double_t pg[3] = { 0., 0., 0. };
208 fGlobalTransformation->LocalToMaster(pl, pg);
210 // Return transformed point
216 //______________________________________________________________________________
217 void AliMUONGeometryDetElement::SetLocalTransformation(
218 const TGeoHMatrix& transform)
220 /// Set local transformation;
221 /// give warning if the global transformation is already defined.
223 if (fLocalTransformation) {
224 delete fLocalTransformation;
225 AliWarning("Local transformation already defined was deleted.");
228 fLocalTransformation = new TGeoHMatrix(transform);
231 //______________________________________________________________________________
232 void AliMUONGeometryDetElement::SetGlobalTransformation(
233 const TGeoHMatrix& transform)
235 /// Set global transformation;
236 /// give warning if the global transformation is already defined.
238 if (fGlobalTransformation) {
239 delete fGlobalTransformation;
240 AliWarning("Global transformation already defined was deleted.");
243 fGlobalTransformation = new TGeoHMatrix(transform);
246 //______________________________________________________________________________
247 void AliMUONGeometryDetElement::PrintLocalTransform() const
249 /// Print detection element relative transformation
250 /// (the transformation wrt module frame)
252 PrintTransform(fLocalTransformation);
255 //______________________________________________________________________________
256 void AliMUONGeometryDetElement::PrintGlobalTransform() const
258 /// Print detection element global transformation
259 /// (the transformation wrt global frame)
261 PrintTransform(fGlobalTransformation);
264 //______________________________________________________________________________
265 TString AliMUONGeometryDetElement::GetVolumeName() const
267 /// Extract volume name from the path
269 std::string volPath = fVolumePath.Data();
270 std::string::size_type first = volPath.rfind('/')+1;
271 std::string::size_type last = volPath.rfind('_');
273 return volPath.substr(first, last-first );
276 //______________________________________________________________________________
277 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
279 /// Extract volume copyNo from the path
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);