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