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