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