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