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