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 AliMUONGeometryDetElement::AliMUONGeometryDetElement(
42 const TString& volumePath)
45 fVolumePath(volumePath),
46 fLocalTransformation(0),
47 fGlobalTransformation(0)
49 /// Standard constructor
51 SetUniqueID(detElemId);
53 fDEName = fgkDENamePrefix;
57 //______________________________________________________________________________
58 AliMUONGeometryDetElement::AliMUONGeometryDetElement()
62 fLocalTransformation(0),
63 fGlobalTransformation(0)
65 /// Default constructor
68 //______________________________________________________________________________
69 AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
73 delete fLocalTransformation;
74 delete fGlobalTransformation;
81 //______________________________________________________________________________
82 void AliMUONGeometryDetElement::PrintTransform(
83 const TGeoHMatrix* transform) const
85 /// Print the detection element transformation
87 cout << "DetElemId: " << GetUniqueID();
88 cout << " name: " << fVolumePath << endl;
91 cout << " Transformation not defined." << endl;
95 const double* translation = transform->GetTranslation();
96 cout << " translation: "
97 #if defined (__DECCXX)
98 << translation[0] << ", "
99 << translation[1] << ", "
100 << translation[2] << endl;
103 << std::setw(7) << std::setprecision(4) << translation[0] << ", "
104 << std::setw(7) << std::setprecision(4) << translation[1] << ", "
105 << std::setw(7) << std::setprecision(4) << translation[2] << endl;
108 const double* rotation = transform->GetRotationMatrix();
109 cout << " rotation matrix: "
110 #if defined (__DECCXX)
111 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
113 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
115 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
118 << std::setw(7) << std::setprecision(4)
119 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
121 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
123 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
131 //______________________________________________________________________________
132 void AliMUONGeometryDetElement::Global2Local(
133 Float_t xg, Float_t yg, Float_t zg,
134 Float_t& xl, Float_t& yl, Float_t& zl) const
136 /// Transform point from the global reference frame (ALIC)
137 /// to the local reference frame of this detection element.
143 Double_t dxl, dyl, dzl;
144 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
151 //______________________________________________________________________________
152 void AliMUONGeometryDetElement::Global2Local(
153 Double_t xg, Double_t yg, Double_t zg,
154 Double_t& xl, Double_t& yl, Double_t& zl) const
156 /// Transform point from the global reference frame (ALIC)
157 /// to the local reference frame of this detection element
159 // Check transformation
160 if (!fGlobalTransformation) {
161 AliError(Form("Global transformation for detection element %d not defined.",
167 Double_t pg[3] = { xg, yg, zg };
168 Double_t pl[3] = { 0., 0., 0. };
169 fGlobalTransformation->MasterToLocal(pg, pl);
171 // Return transformed point
177 //______________________________________________________________________________
178 void AliMUONGeometryDetElement::Local2Global(
179 Float_t xl, Float_t yl, Float_t zl,
180 Float_t& xg, Float_t& yg, Float_t& zg) const
182 /// Transform point from the local reference frame of this detection element
183 /// to the global reference frame (ALIC).
189 Double_t dxg, dyg, dzg;
190 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
197 //______________________________________________________________________________
198 void AliMUONGeometryDetElement::Local2Global(
199 Double_t xl, Double_t yl, Double_t zl,
200 Double_t& xg, Double_t& yg, Double_t& zg) const
202 /// Transform point from the local reference frame of this detection element
203 /// to the global reference frame (ALIC).
205 // Check transformation
206 if (!fGlobalTransformation) {
207 AliError(Form("Global transformation for detection element %d not defined.",
213 Double_t pl[3] = { xl, yl, zl };
214 Double_t pg[3] = { 0., 0., 0. };
215 fGlobalTransformation->LocalToMaster(pl, pg);
217 // Return transformed point
223 //______________________________________________________________________________
224 void AliMUONGeometryDetElement::SetLocalTransformation(
225 const TGeoHMatrix& transform)
227 /// Set local transformation;
228 /// give warning if the global transformation is already defined.
230 if (fLocalTransformation) {
231 delete fLocalTransformation;
232 AliWarning("Local transformation already defined was deleted.");
235 fLocalTransformation = new TGeoHMatrix(transform);
238 //______________________________________________________________________________
239 void AliMUONGeometryDetElement::SetGlobalTransformation(
240 const TGeoHMatrix& transform)
242 /// Set global transformation;
243 /// give warning if the global transformation is already defined.
245 if (fGlobalTransformation) {
246 delete fGlobalTransformation;
247 AliWarning("Global transformation already defined was deleted.");
250 fGlobalTransformation = new TGeoHMatrix(transform);
253 //______________________________________________________________________________
254 void AliMUONGeometryDetElement::PrintLocalTransform() const
256 /// Print detection element relative transformation
257 /// (the transformation wrt module frame)
259 PrintTransform(fLocalTransformation);
262 //______________________________________________________________________________
263 void AliMUONGeometryDetElement::PrintGlobalTransform() const
265 /// Print detection element global transformation
266 /// (the transformation wrt global frame)
268 PrintTransform(fGlobalTransformation);
271 //______________________________________________________________________________
272 TString AliMUONGeometryDetElement::GetVolumeName() const
274 /// Extract volume name from the path
276 std::string volPath = fVolumePath.Data();
277 std::string::size_type first = volPath.rfind('/')+1;
278 std::string::size_type last = volPath.rfind('_');
280 return volPath.substr(first, last-first );
283 //______________________________________________________________________________
284 Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
286 /// Extract volume copyNo from the path
288 string volPath = fVolumePath.Data();
289 std::string::size_type first = volPath.rfind('_');
290 std::string copyNoStr = volPath.substr(first+1, volPath.length());
291 std::istringstream in(copyNoStr);