Adding code to patch St1 HV mapping
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryDetElement.cxx
CommitLineData
e118b27e 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16// $Id$
3d1463c8 17
18//-----------------------------------------------------------------------------
e118b27e 19// Class AliMUONGeometryDetElement
20// --------------------------------------
21// The class defines the detection element.
e118b27e 22// Author: Ivana Hrivnacova, IPN Orsay
3d1463c8 23//-----------------------------------------------------------------------------
e118b27e 24
8c0e3489 25#include "AliMUONGeometryDetElement.h"
e118b27e 26
27#include "AliLog.h"
28
8c0e3489 29#include <TGeoMatrix.h>
30#include <Riostream.h>
31
32#include <sstream>
e118b27e 33
b80faac0 34using std::cout;
35using std::endl;
36using std::string;
a9aad96e 37/// \cond CLASSIMP
e118b27e 38ClassImp(AliMUONGeometryDetElement)
a9aad96e 39/// \endcond
e118b27e 40
31edb2d7 41//
42// static methods
43//
44
45//______________________________________________________________________________
46const TString& AliMUONGeometryDetElement::GetDENamePrefix()
47{
48 ///< Geometry DE name prefix
49 static const TString kDENamePrefix = "DE";
50 return kDENamePrefix;
51}
e9a283f7 52
e118b27e 53//______________________________________________________________________________
ccc0dd0a 54TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
55{
56/// Return the module name for given moduleId
57
31edb2d7 58 TString deName(GetDENamePrefix());
ccc0dd0a 59 deName += detElemId;
60 return deName;
61}
62
63//______________________________________________________________________________
64AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
65 : TObject(),
66 fDEName(GetDEName(detElemId)),
67 fVolumePath(),
68 fLocalTransformation(0),
69 fGlobalTransformation(0)
70{
71/// Standard constructor
72
73 SetUniqueID(detElemId);
74}
75
76//______________________________________________________________________________
e118b27e 77AliMUONGeometryDetElement::AliMUONGeometryDetElement(
78 Int_t detElemId,
8c0e3489 79 const TString& volumePath)
e118b27e 80 : TObject(),
ccc0dd0a 81 fDEName(GetDEName(detElemId)),
8c0e3489 82 fVolumePath(volumePath),
e118b27e 83 fLocalTransformation(0),
84 fGlobalTransformation(0)
85{
692de412 86/// Standard constructor
e118b27e 87
88 SetUniqueID(detElemId);
e118b27e 89}
90
91//______________________________________________________________________________
ccc0dd0a 92AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
e118b27e 93 : TObject(),
ee04aaf6 94 fDEName(),
8c0e3489 95 fVolumePath(),
e118b27e 96 fLocalTransformation(0),
97 fGlobalTransformation(0)
98{
ccc0dd0a 99/// Root IO constructor
e118b27e 100}
101
102//______________________________________________________________________________
692de412 103AliMUONGeometryDetElement::~AliMUONGeometryDetElement()
104{
105/// Destructor
106
e118b27e 107 delete fLocalTransformation;
108 delete fGlobalTransformation;
109}
110
e118b27e 111//
112// private methods
113//
114
115//______________________________________________________________________________
116void AliMUONGeometryDetElement::PrintTransform(
8c0e3489 117 const TGeoHMatrix* transform) const
e118b27e 118{
a9aad96e 119/// Print the detection element transformation
e118b27e 120
121 cout << "DetElemId: " << GetUniqueID();
8c0e3489 122 cout << " name: " << fVolumePath << endl;
123
124 if ( !transform ) {
125 cout << " Transformation not defined." << endl;
126 return;
127 }
e118b27e 128
129 const double* translation = transform->GetTranslation();
130 cout << " translation: "
131#if defined (__DECCXX)
132 << translation[0] << ", "
133 << translation[1] << ", "
134 << translation[2] << endl;
135#else
136 << std::fixed
137 << std::setw(7) << std::setprecision(4) << translation[0] << ", "
138 << std::setw(7) << std::setprecision(4) << translation[1] << ", "
139 << std::setw(7) << std::setprecision(4) << translation[2] << endl;
140#endif
141
142 const double* rotation = transform->GetRotationMatrix();
143 cout << " rotation matrix: "
144#if defined (__DECCXX)
145 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
146 << " "
147 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
148 << " "
149 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
150#else
151 << std::fixed
152 << std::setw(7) << std::setprecision(4)
153 << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
154 << " "
155 << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
156 << " "
157 << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
158#endif
159}
160
161//
162// public methods
163//
164
165//______________________________________________________________________________
166void AliMUONGeometryDetElement::Global2Local(
167 Float_t xg, Float_t yg, Float_t zg,
168 Float_t& xl, Float_t& yl, Float_t& zl) const
169{
a9aad96e 170/// Transform point from the global reference frame (ALIC)
171/// to the local reference frame of this detection element.
e118b27e 172
173 Double_t dxg = xg;
174 Double_t dyg = yg;
175 Double_t dzg = zg;
176
177 Double_t dxl, dyl, dzl;
178 Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
179
180 xl = dxl;
181 yl = dyl;
182 zl = dzl;
183}
184
185//______________________________________________________________________________
186void AliMUONGeometryDetElement::Global2Local(
187 Double_t xg, Double_t yg, Double_t zg,
188 Double_t& xl, Double_t& yl, Double_t& zl) const
189{
a9aad96e 190/// Transform point from the global reference frame (ALIC)
191/// to the local reference frame of this detection element
e118b27e 192
193 // Check transformation
194 if (!fGlobalTransformation) {
195 AliError(Form("Global transformation for detection element %d not defined.",
196 GetUniqueID()));
197 return;
198 }
199
200 // Transform point
201 Double_t pg[3] = { xg, yg, zg };
202 Double_t pl[3] = { 0., 0., 0. };
203 fGlobalTransformation->MasterToLocal(pg, pl);
204
205 // Return transformed point
206 xl = pl[0];
207 yl = pl[1];
208 zl = pl[2];
209}
210
211//______________________________________________________________________________
212void AliMUONGeometryDetElement::Local2Global(
213 Float_t xl, Float_t yl, Float_t zl,
214 Float_t& xg, Float_t& yg, Float_t& zg) const
215{
a9aad96e 216/// Transform point from the local reference frame of this detection element
217/// to the global reference frame (ALIC).
e118b27e 218
219 Double_t dxl = xl;
220 Double_t dyl = yl;
221 Double_t dzl = zl;
222
223 Double_t dxg, dyg, dzg;
224 Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
225
226 xg = dxg;
227 yg = dyg;
228 zg = dzg;
229}
230
231//______________________________________________________________________________
232void AliMUONGeometryDetElement::Local2Global(
233 Double_t xl, Double_t yl, Double_t zl,
234 Double_t& xg, Double_t& yg, Double_t& zg) const
235{
a9aad96e 236/// Transform point from the local reference frame of this detection element
237/// to the global reference frame (ALIC).
e118b27e 238
239 // Check transformation
240 if (!fGlobalTransformation) {
241 AliError(Form("Global transformation for detection element %d not defined.",
242 GetUniqueID()));
243 return;
244 }
245
246 // Transform point
247 Double_t pl[3] = { xl, yl, zl };
248 Double_t pg[3] = { 0., 0., 0. };
249 fGlobalTransformation->LocalToMaster(pl, pg);
250
251 // Return transformed point
252 xg = pg[0];
253 yg = pg[1];
254 zg = pg[2];
255}
256
257//______________________________________________________________________________
8c0e3489 258void AliMUONGeometryDetElement::SetLocalTransformation(
450ca6fb 259 const TGeoHMatrix& transform,
260 Bool_t warn)
8c0e3489 261{
a9aad96e 262/// Set local transformation;
263/// give warning if the global transformation is already defined.
8c0e3489 264
450ca6fb 265 if ( fLocalTransformation ) {
8c0e3489 266 delete fLocalTransformation;
450ca6fb 267 if ( warn ) {
268 AliWarning("Local transformation already defined was deleted.");
269 }
8c0e3489 270 }
271
272 fLocalTransformation = new TGeoHMatrix(transform);
273}
274
275//______________________________________________________________________________
e118b27e 276void AliMUONGeometryDetElement::SetGlobalTransformation(
450ca6fb 277 const TGeoHMatrix& transform,
278 Bool_t warn)
e118b27e 279{
a9aad96e 280/// Set global transformation;
281/// give warning if the global transformation is already defined.
e118b27e 282
283 if (fGlobalTransformation) {
284 delete fGlobalTransformation;
450ca6fb 285 if ( warn ) {
286 AliWarning("Global transformation already defined was deleted.");
287 }
e118b27e 288 }
289
8c0e3489 290 fGlobalTransformation = new TGeoHMatrix(transform);
e118b27e 291}
292
293//______________________________________________________________________________
294void AliMUONGeometryDetElement::PrintLocalTransform() const
295{
a9aad96e 296/// Print detection element relative transformation
692de412 297/// (the transformation wrt module frame)
e118b27e 298
299 PrintTransform(fLocalTransformation);
300}
301
302//______________________________________________________________________________
303void AliMUONGeometryDetElement::PrintGlobalTransform() const
304{
a9aad96e 305/// Print detection element global transformation
692de412 306/// (the transformation wrt global frame)
e118b27e 307
a42ddaa5 308 PrintTransform(fGlobalTransformation);
e118b27e 309}
8c0e3489 310
311//______________________________________________________________________________
312TString AliMUONGeometryDetElement::GetVolumeName() const
313{
314/// Extract volume name from the path
315
316 std::string volPath = fVolumePath.Data();
317 std::string::size_type first = volPath.rfind('/')+1;
318 std::string::size_type last = volPath.rfind('_');
319
320 return volPath.substr(first, last-first );
321}
322
323//______________________________________________________________________________
324Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
325{
326/// Extract volume copyNo from the path
327
328 string volPath = fVolumePath.Data();
329 std::string::size_type first = volPath.rfind('_');
330 std::string copyNoStr = volPath.substr(first+1, volPath.length());
331 std::istringstream in(copyNoStr);
332 Int_t copyNo;
333 in >> copyNo;
334
335 return copyNo;
336}
337