]>
Commit | Line | Data |
---|---|---|
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 | #include "AliMUONGeometryDetElement.h" | |
25 | ||
26 | #include "AliLog.h" | |
27 | ||
28 | #include <TGeoMatrix.h> | |
29 | #include <Riostream.h> | |
30 | ||
31 | #include <sstream> | |
32 | ||
33 | /// \cond CLASSIMP | |
34 | ClassImp(AliMUONGeometryDetElement) | |
35 | /// \endcond | |
36 | ||
37 | const TString AliMUONGeometryDetElement::fgkDENamePrefix = "DE"; | |
38 | ||
39 | //______________________________________________________________________________ | |
40 | AliMUONGeometryDetElement::AliMUONGeometryDetElement( | |
41 | Int_t detElemId, | |
42 | const TString& volumePath) | |
43 | : TObject(), | |
44 | fDEName(), | |
45 | fVolumePath(volumePath), | |
46 | fLocalTransformation(0), | |
47 | fGlobalTransformation(0) | |
48 | { | |
49 | /// Standard constructor | |
50 | ||
51 | SetUniqueID(detElemId); | |
52 | ||
53 | fDEName = fgkDENamePrefix; | |
54 | fDEName += detElemId; | |
55 | } | |
56 | ||
57 | //______________________________________________________________________________ | |
58 | AliMUONGeometryDetElement::AliMUONGeometryDetElement() | |
59 | : TObject(), | |
60 | fDEName(), | |
61 | fVolumePath(), | |
62 | fLocalTransformation(0), | |
63 | fGlobalTransformation(0) | |
64 | { | |
65 | /// Default constructor | |
66 | } | |
67 | ||
68 | //______________________________________________________________________________ | |
69 | AliMUONGeometryDetElement::~AliMUONGeometryDetElement() | |
70 | { | |
71 | /// Destructor | |
72 | ||
73 | delete fLocalTransformation; | |
74 | delete fGlobalTransformation; | |
75 | } | |
76 | ||
77 | // | |
78 | // private methods | |
79 | // | |
80 | ||
81 | //______________________________________________________________________________ | |
82 | void AliMUONGeometryDetElement::PrintTransform( | |
83 | const TGeoHMatrix* transform) const | |
84 | { | |
85 | /// Print the detection element transformation | |
86 | ||
87 | cout << "DetElemId: " << GetUniqueID(); | |
88 | cout << " name: " << fVolumePath << endl; | |
89 | ||
90 | if ( !transform ) { | |
91 | cout << " Transformation not defined." << endl; | |
92 | return; | |
93 | } | |
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 | //______________________________________________________________________________ | |
132 | void AliMUONGeometryDetElement::Global2Local( | |
133 | Float_t xg, Float_t yg, Float_t zg, | |
134 | Float_t& xl, Float_t& yl, Float_t& zl) const | |
135 | { | |
136 | /// Transform point from the global reference frame (ALIC) | |
137 | /// to the local reference frame of this detection element. | |
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 | //______________________________________________________________________________ | |
152 | void AliMUONGeometryDetElement::Global2Local( | |
153 | Double_t xg, Double_t yg, Double_t zg, | |
154 | Double_t& xl, Double_t& yl, Double_t& zl) const | |
155 | { | |
156 | /// Transform point from the global reference frame (ALIC) | |
157 | /// to the local reference frame of this detection element | |
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 | //______________________________________________________________________________ | |
178 | void AliMUONGeometryDetElement::Local2Global( | |
179 | Float_t xl, Float_t yl, Float_t zl, | |
180 | Float_t& xg, Float_t& yg, Float_t& zg) const | |
181 | { | |
182 | /// Transform point from the local reference frame of this detection element | |
183 | /// to the global reference frame (ALIC). | |
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 | //______________________________________________________________________________ | |
198 | void AliMUONGeometryDetElement::Local2Global( | |
199 | Double_t xl, Double_t yl, Double_t zl, | |
200 | Double_t& xg, Double_t& yg, Double_t& zg) const | |
201 | { | |
202 | /// Transform point from the local reference frame of this detection element | |
203 | /// to the global reference frame (ALIC). | |
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 | ||
223 | //______________________________________________________________________________ | |
224 | void AliMUONGeometryDetElement::SetLocalTransformation( | |
225 | const TGeoHMatrix& transform) | |
226 | { | |
227 | /// Set local transformation; | |
228 | /// give warning if the global transformation is already defined. | |
229 | ||
230 | if (fLocalTransformation) { | |
231 | delete fLocalTransformation; | |
232 | AliWarning("Local transformation already defined was deleted."); | |
233 | } | |
234 | ||
235 | fLocalTransformation = new TGeoHMatrix(transform); | |
236 | } | |
237 | ||
238 | //______________________________________________________________________________ | |
239 | void AliMUONGeometryDetElement::SetGlobalTransformation( | |
240 | const TGeoHMatrix& transform) | |
241 | { | |
242 | /// Set global transformation; | |
243 | /// give warning if the global transformation is already defined. | |
244 | ||
245 | if (fGlobalTransformation) { | |
246 | delete fGlobalTransformation; | |
247 | AliWarning("Global transformation already defined was deleted."); | |
248 | } | |
249 | ||
250 | fGlobalTransformation = new TGeoHMatrix(transform); | |
251 | } | |
252 | ||
253 | //______________________________________________________________________________ | |
254 | void AliMUONGeometryDetElement::PrintLocalTransform() const | |
255 | { | |
256 | /// Print detection element relative transformation | |
257 | /// (the transformation wrt module frame) | |
258 | ||
259 | PrintTransform(fLocalTransformation); | |
260 | } | |
261 | ||
262 | //______________________________________________________________________________ | |
263 | void AliMUONGeometryDetElement::PrintGlobalTransform() const | |
264 | { | |
265 | /// Print detection element global transformation | |
266 | /// (the transformation wrt global frame) | |
267 | ||
268 | PrintTransform(fGlobalTransformation); | |
269 | } | |
270 | ||
271 | //______________________________________________________________________________ | |
272 | TString 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 | //______________________________________________________________________________ | |
284 | Int_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 |