AliRoot Core  edcc906 (edcc906)
AliMUONGeometryDetElement.cxx
Go to the documentation of this file.
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 
18 //-----------------------------------------------------------------------------
19 // Class AliMUONGeometryDetElement
20 // --------------------------------------
21 // The class defines the detection element.
22 // Author: Ivana Hrivnacova, IPN Orsay
23 //-----------------------------------------------------------------------------
24 
26 
27 #include "AliLog.h"
28 
29 #include <TGeoMatrix.h>
30 #include <Riostream.h>
31 
32 #include <sstream>
33 
34 using std::cout;
35 using std::endl;
36 using std::string;
40 
41 //
42 // static methods
43 //
44 
45 //______________________________________________________________________________
46 const TString& AliMUONGeometryDetElement::GetDENamePrefix()
47 {
49  static const TString kDENamePrefix = "DE";
50  return kDENamePrefix;
51 }
52 
53 //______________________________________________________________________________
54 TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
55 {
57 
58  TString deName(GetDENamePrefix());
59  deName += detElemId;
60  return deName;
61 }
62 
63 //______________________________________________________________________________
65  : TObject(),
66  fDEName(GetDEName(detElemId)),
67  fVolumePath(),
70 {
72 
73  SetUniqueID(detElemId);
74 }
75 
76 //______________________________________________________________________________
78  Int_t detElemId,
79  const TString& volumePath)
80  : TObject(),
81  fDEName(GetDEName(detElemId)),
82  fVolumePath(volumePath),
85 {
87 
88  SetUniqueID(detElemId);
89 }
90 
91 //______________________________________________________________________________
93  : TObject(),
94  fDEName(),
95  fVolumePath(),
98 {
100 }
101 
102 //______________________________________________________________________________
104 {
106 
107  delete fLocalTransformation;
108  delete fGlobalTransformation;
109 }
110 
111 //
112 // private methods
113 //
114 
115 //______________________________________________________________________________
117  const TGeoHMatrix* transform) const
118 {
120 
121  cout << "DetElemId: " << GetUniqueID();
122  cout << " name: " << fVolumePath << endl;
123 
124  if ( !transform ) {
125  cout << " Transformation not defined." << endl;
126  return;
127  }
128 
129  const double* translation = transform->GetTranslation();
130  cout << " translation: "
131 #if defined (__DECCXX)
132  << translation[0] << ", "
133  << translation[1] << ", "
134  << translation[2] << endl;
135 #else
136  << std::fixed
137  << std::setw(7) << std::setprecision(4) << translation[0] << ", "
138  << std::setw(7) << std::setprecision(4) << translation[1] << ", "
139  << std::setw(7) << std::setprecision(4) << translation[2] << endl;
140 #endif
141 
142  const double* rotation = transform->GetRotationMatrix();
143  cout << " rotation matrix: "
144 #if defined (__DECCXX)
145  << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
146  << " "
147  << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
148  << " "
149  << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
150 #else
151  << std::fixed
152  << std::setw(7) << std::setprecision(4)
153  << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
154  << " "
155  << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl
156  << " "
157  << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
158 #endif
159 }
160 
161 //
162 // public methods
163 //
164 
165 //______________________________________________________________________________
167  Float_t xg, Float_t yg, Float_t zg,
168  Float_t& xl, Float_t& yl, Float_t& zl) const
169 {
172 
173  Double_t dxg = xg;
174  Double_t dyg = yg;
175  Double_t dzg = zg;
176 
177  Double_t dxl, dyl, dzl;
178  Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);
179 
180  xl = dxl;
181  yl = dyl;
182  zl = dzl;
183 }
184 
185 //______________________________________________________________________________
187  Double_t xg, Double_t yg, Double_t zg,
188  Double_t& xl, Double_t& yl, Double_t& zl) const
189 {
192 
193  // Check transformation
194  if (!fGlobalTransformation) {
195  AliError(Form("Global transformation for detection element %d not defined.",
196  GetUniqueID()));
197  return;
198  }
199 
200  // Transform point
201  Double_t pg[3] = { xg, yg, zg };
202  Double_t pl[3] = { 0., 0., 0. };
203  fGlobalTransformation->MasterToLocal(pg, pl);
204 
205  // Return transformed point
206  xl = pl[0];
207  yl = pl[1];
208  zl = pl[2];
209 }
210 
211 //______________________________________________________________________________
213  Float_t xl, Float_t yl, Float_t zl,
214  Float_t& xg, Float_t& yg, Float_t& zg) const
215 {
218 
219  Double_t dxl = xl;
220  Double_t dyl = yl;
221  Double_t dzl = zl;
222 
223  Double_t dxg, dyg, dzg;
224  Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);
225 
226  xg = dxg;
227  yg = dyg;
228  zg = dzg;
229 }
230 
231 //______________________________________________________________________________
233  Double_t xl, Double_t yl, Double_t zl,
234  Double_t& xg, Double_t& yg, Double_t& zg) const
235 {
238 
239  // Check transformation
240  if (!fGlobalTransformation) {
241  AliError(Form("Global transformation for detection element %d not defined.",
242  GetUniqueID()));
243  return;
244  }
245 
246  // Transform point
247  Double_t pl[3] = { xl, yl, zl };
248  Double_t pg[3] = { 0., 0., 0. };
249  fGlobalTransformation->LocalToMaster(pl, pg);
250 
251  // Return transformed point
252  xg = pg[0];
253  yg = pg[1];
254  zg = pg[2];
255 }
256 
257 //______________________________________________________________________________
259  const TGeoHMatrix& transform,
260  Bool_t warn)
261 {
264 
265  if ( fLocalTransformation ) {
266  delete fLocalTransformation;
267  if ( warn ) {
268  AliWarning("Local transformation already defined was deleted.");
269  }
270  }
271 
272  fLocalTransformation = new TGeoHMatrix(transform);
273 }
274 
275 //______________________________________________________________________________
277  const TGeoHMatrix& transform,
278  Bool_t warn)
279 {
282 
283  if (fGlobalTransformation) {
284  delete fGlobalTransformation;
285  if ( warn ) {
286  AliWarning("Global transformation already defined was deleted.");
287  }
288  }
289 
290  fGlobalTransformation = new TGeoHMatrix(transform);
291 }
292 
293 //______________________________________________________________________________
295 {
298 
300 }
301 
302 //______________________________________________________________________________
304 {
307 
309 }
310 
311 //______________________________________________________________________________
313 {
315 
316  std::string volPath = fVolumePath.Data();
317  std::string::size_type first = volPath.rfind('/')+1;
318  std::string::size_type last = volPath.rfind('_');
319 
320  return volPath.substr(first, last-first );
321 }
322 
323 //______________________________________________________________________________
325 {
327 
328  string volPath = fVolumePath.Data();
329  std::string::size_type first = volPath.rfind('_');
330  std::string copyNoStr = volPath.substr(first+1, volPath.length());
331  std::istringstream in(copyNoStr);
332  Int_t copyNo;
333  in >> copyNo;
334 
335  return copyNo;
336 }
337 
AliMUONGeometryDetElement()
Not implemented.
void Local2Global(Float_t xl, Float_t yl, Float_t zl, Float_t &xg, Float_t &yg, Float_t &zg) const
TString fDEName
detection element name
#define AliWarning(message)
Definition: AliLog.h:541
void Global2Local(Float_t xg, Float_t yg, Float_t zg, Float_t &xl, Float_t &yl, Float_t &zl) const
void SetGlobalTransformation(const TGeoHMatrix &transform, Bool_t warn=true)
TString GetDEName() const
Return detection element ID.
static const TString & GetDENamePrefix()
void SetLocalTransformation(const TGeoHMatrix &transform, Bool_t warn=true)
TGeoHMatrix * fLocalTransformation
the transformation wrt module
void PrintTransform(const TGeoHMatrix *transform) const
TString fVolumePath
the full path of aligned volume or envelope in geometry
#define AliError(message)
Definition: AliLog.h:591
Class for storing detection element transformations.
TGeoHMatrix * fGlobalTransformation
the transformation wrt world