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 // Class AliMUONGeometryDetElement
19 // --------------------------------------
20 // The class defines the detection element.
22 // Author: Ivana Hrivnacova, IPN Orsay
24 #include "AliMUONGeometryDetElement.h"
28 #include <TGeoMatrix.h>
29 #include <Riostream.h>
33 ClassImp(AliMUONGeometryDetElement)
35 //______________________________________________________________________________
36 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
38 const TString& volumePath)
40 fVolumePath(volumePath),
41 fLocalTransformation(0),
42 fGlobalTransformation(0)
44 /// Standard constructor
46 SetUniqueID(detElemId);
49 //______________________________________________________________________________
50 AliMUONGeometryDetElement::AliMUONGeometryDetElement()
53 fLocalTransformation(0),
54 fGlobalTransformation(0)
56 /// Default constructor
59 //______________________________________________________________________________
60 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
61 const AliMUONGeometryDetElement& rhs)
64 /// Protected copy constructor
66 AliFatal("Copy constructor is not implemented.");
69 //______________________________________________________________________________
70 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
74 delete fLocalTransformation;
75 delete fGlobalTransformation;
78 //______________________________________________________________________________
79 AliMUONGeometryDetElement&
80 AliMUONGeometryDetElement::operator = (const AliMUONGeometryDetElement& rhs)
82 /// Protected assignement operator
84 // check assignement to self
85 if (this == &rhs) return *this;
87 AliFatal("Assignment operator is not implemented.");
96 //______________________________________________________________________________
97 void AliMUONGeometryDetElement::PrintTransform(
98 const TGeoHMatrix* transform) const
100 /// Prints the detection element transformation
102 cout << "DetElemId: " << GetUniqueID();
103 cout << " name: " << fVolumePath << endl;
106 cout << " Transformation not defined." << endl;
110 const double* translation = transform->GetTranslation();
111 cout << " translation: "
112 #if defined (__DECCXX)
113 << translation[0] << ", "
114 << translation[1] << ", "
115 << translation[2] << endl;
118 << std::setw(7) << std::setprecision(4) << translation[0] << ", "
119 << std::setw(7) << std::setprecision(4) << translation[1] << ", "
120 << std::setw(7) << std::setprecision(4) << translation[2] << endl;
123 const double* rotation = transform->GetRotationMatrix();
124 cout << " rotation matrix: "
125 #if defined (__DECCXX)
126 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
128 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
130 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
133 << std::setw(7) << std::setprecision(4)
134 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
136 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
138 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
146 //______________________________________________________________________________
147 void AliMUONGeometryDetElement::Global2Local(
148 Float_t xg, Float_t yg, Float_t zg,
149 Float_t& xl, Float_t& yl, Float_t& zl) const
151 /// Transforms point from the global reference frame (ALIC)
152 /// to the local reference frame of the detection element specified
159 Double_t dxl, dyl, dzl;
160 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
167 //______________________________________________________________________________
168 void AliMUONGeometryDetElement::Global2Local(
169 Double_t xg, Double_t yg, Double_t zg,
170 Double_t& xl, Double_t& yl, Double_t& zl) const
172 /// Transforms point from the global reference frame (ALIC)
173 /// to the local reference frame of the detection element specified
176 // Check transformation
177 if (!fGlobalTransformation) {
178 AliError(Form("Global transformation for detection element %d not defined.",
184 Double_t pg[3] = { xg, yg, zg };
185 Double_t pl[3] = { 0., 0., 0. };
186 fGlobalTransformation->MasterToLocal(pg, pl);
188 // Return transformed point
194 //______________________________________________________________________________
195 void AliMUONGeometryDetElement::Local2Global(
196 Float_t xl, Float_t yl, Float_t zl,
197 Float_t& xg, Float_t& yg, Float_t& zg) const
199 /// Transforms point from the local reference frame of the detection element
200 /// specified by detElemId to the global reference frame (ALIC).
206 Double_t dxg, dyg, dzg;
207 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
214 //______________________________________________________________________________
215 void AliMUONGeometryDetElement::Local2Global(
216 Double_t xl, Double_t yl, Double_t zl,
217 Double_t& xg, Double_t& yg, Double_t& zg) const
219 /// Transforms point from the local reference frame of the detection element
220 /// specified by detElemId to the global reference frame (ALIC).
222 // Check transformation
223 if (!fGlobalTransformation) {
224 AliError(Form("Global transformation for detection element %d not defined.",
230 Double_t pl[3] = { xl, yl, zl };
231 Double_t pg[3] = { 0., 0., 0. };
232 fGlobalTransformation->LocalToMaster(pl, pg);
234 // Return transformed point
240 //______________________________________________________________________________
241 void AliMUONGeometryDetElement::SetLocalTransformation(
242 const TGeoHMatrix& transform)
244 /// Sets global transformation;
245 /// gives warning if the global transformation is already defined.
247 if (fLocalTransformation) {
248 delete fLocalTransformation;
249 AliWarning("Local transformation already defined was deleted.");
252 fLocalTransformation = new TGeoHMatrix(transform);
255 //______________________________________________________________________________
256 void AliMUONGeometryDetElement::SetGlobalTransformation(
257 const TGeoHMatrix& transform)
259 /// Sets global transformation;
260 /// gives warning if the global transformation is already defined.
262 if (fGlobalTransformation) {
263 delete fGlobalTransformation;
264 AliWarning("Global transformation already defined was deleted.");
267 fGlobalTransformation = new TGeoHMatrix(transform);
270 //______________________________________________________________________________
271 void AliMUONGeometryDetElement::PrintLocalTransform() const
273 /// Prints detection element relative transformation
274 /// (the transformation wrt module frame)
276 PrintTransform(fLocalTransformation);
279 //______________________________________________________________________________
280 void AliMUONGeometryDetElement::PrintGlobalTransform() const
282 /// Prints detection element global transformation
283 /// (the transformation wrt global frame)
285 PrintTransform(fGlobalTransformation);
288 //______________________________________________________________________________
289 TString AliMUONGeometryDetElement::GetVolumeName() const
291 /// Extract volume name from the path
293 std::string volPath = fVolumePath.Data();
294 std::string::size_type first = volPath.rfind('/')+1;
295 std::string::size_type last = volPath.rfind('_');
297 return volPath.substr(first, last-first );
300 //______________________________________________________________________________
301 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
303 /// Extract volume copyNo from the path
305 string volPath = fVolumePath.Data();
306 std::string::size_type first = volPath.rfind('_');
307 std::string copyNoStr = volPath.substr(first+1, volPath.length());
308 std::istringstream in(copyNoStr);