]>
Commit | Line | Data |
---|---|---|
6ddbe5ad | 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 | /////////////////////////////////////////////////////////////////////////// | |
17 | // AliITSgeomTGeo is a simple interface class to TGeoManager // | |
18 | // It is used in the simulation and reconstruction in order to // | |
19 | // query the TGeo ITS geometry // | |
20 | // // | |
21 | // author - cvetan.cheshkov@cern.ch // | |
22 | // 15/02/2007 // | |
23 | /////////////////////////////////////////////////////////////////////////// | |
24 | ||
25 | #include <TString.h> | |
26 | #include <TGeoManager.h> | |
27 | #include <TGeoPhysicalNode.h> | |
28 | ||
29 | #include "AliITSgeomTGeo.h" | |
30 | #include "AliLog.h" | |
31 | #include "AliAlignObj.h" | |
32 | ||
33 | ClassImp(AliITSgeomTGeo) | |
34 | ||
35 | const Int_t AliITSgeomTGeo::fgkNModules = 2198; | |
36 | const Int_t AliITSgeomTGeo::fgkNLadders[kNLayers] = {20,40,14,22,34,38}; | |
37 | const Int_t AliITSgeomTGeo::fgkNDetectors[kNLayers] = {4,4,6,8,22,25}; | |
38 | ||
39 | //______________________________________________________________________ | |
40 | Int_t AliITSgeomTGeo::GetModuleIndex(Int_t lay,Int_t lad,Int_t det) | |
41 | { | |
42 | // The method is taken from the old AliITSgeom class by Bjorn Nilsen | |
43 | // | |
44 | // This routine computes the module index number from the layer, | |
45 | // ladder, and detector numbers. The number of ladders and detectors | |
46 | // per layer is set statically | |
47 | // see above for details. | |
48 | // Inputs: | |
49 | // Int_t lay The layer number. Starting from 1. | |
50 | // Int_t lad The ladder number. Starting from 1. | |
51 | // Int_t det The detector number. Starting from 1. | |
52 | // Return: | |
53 | // the module index number, starting from zero. | |
54 | // -1 in case of error | |
55 | ||
56 | if (lay < 1 || lay > kNLayers) { | |
57 | AliErrorClass(Form("Invalid layer: %d (1 -> %d",lay,kNLayers)); | |
58 | return -1; | |
59 | } | |
60 | ||
61 | if (lad < 1 || lad > fgkNLadders[lay-1] || | |
62 | det < 1 || det > fgkNDetectors[lay-1]) { | |
63 | AliErrorClass(Form("Invalid layer,ladder,detector combination: %d, %d, %d",lay,lad,det)); | |
64 | return -1; | |
65 | } | |
66 | ||
67 | Int_t index = fgkNDetectors[lay-1] * (lad-1) + (det-1); | |
68 | for(Int_t iLayer=0;iLayer < (lay-1); iLayer++) | |
69 | index += fgkNDetectors[iLayer]*fgkNLadders[iLayer]; | |
70 | ||
71 | return index; | |
72 | } | |
73 | ||
74 | //______________________________________________________________________ | |
75 | Bool_t AliITSgeomTGeo::GetLayer(Int_t index,Int_t &lay,Int_t &index2) | |
76 | { | |
77 | // The method is taken from the old AliITSgeom class by Bjorn Nilsen | |
78 | // | |
79 | // This routine computes the layer number for a | |
80 | // given the module index. The number of ladders and detectors | |
81 | // per layer is defined statically, | |
82 | // see above for details. | |
83 | // Inputs: | |
84 | // Int_t index The module index number, starting from zero. | |
85 | // Outputs: | |
86 | // Int_t index2 The module index inside a layer, starting from zero. | |
87 | // Int_t lay The layer number. Starting from 1. | |
88 | // Return: | |
89 | // kTRUE in case of valid index | |
90 | // kFALSE in case of error | |
91 | ||
92 | if (index < 0 || index >= fgkNModules) { | |
93 | index2 = -1; | |
94 | AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules)); | |
95 | return -1; | |
96 | } | |
97 | ||
98 | lay = 0; | |
99 | index2 = 0; | |
100 | do { | |
101 | index2 += fgkNLadders[lay]*fgkNDetectors[lay]; | |
102 | lay++; | |
103 | } while(index2 <= index); | |
104 | index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1]; | |
105 | index2 = index - index2; | |
106 | ||
107 | return lay; | |
108 | } | |
109 | ||
110 | //______________________________________________________________________ | |
111 | Bool_t AliITSgeomTGeo::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det) | |
112 | { | |
113 | // The method is taken from the old AliITSgeom class by Bjorn Nilsen | |
114 | // | |
115 | // This routine computes the layer, ladder and detector number | |
116 | // given the module index number. The number of ladders and detectors | |
117 | // per layer is defined statically, | |
118 | // see above for details. | |
119 | // Inputs: | |
120 | // Int_t index The module index number, starting from zero. | |
121 | // Outputs: | |
122 | // Int_t lay The layer number. Starting from 1. | |
123 | // Int_t lad The ladder number. Starting from 1. | |
124 | // Int_t det The detector number. Starting from 1. | |
125 | // Return: | |
126 | // kTRUE in case of valid index | |
127 | // kFALSE in case of error | |
128 | ||
129 | if (index < 0 || index >= fgkNModules) { | |
130 | lay = lad = det = -1; | |
131 | AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules)); | |
132 | return kFALSE; | |
133 | } | |
134 | ||
135 | lay = lad = det = 0; | |
136 | Int_t index2 = 0; | |
137 | do { | |
138 | index2 += fgkNLadders[lay]*fgkNDetectors[lay]; | |
139 | lay++; | |
140 | } while(index2 <= index); | |
141 | index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1]; | |
142 | ||
143 | do { | |
144 | index2 += fgkNDetectors[lay-1]; | |
145 | lad++; | |
146 | } while(index2 <= index); | |
147 | index2 -= fgkNDetectors[lay-1]; | |
148 | ||
149 | det = index-index2+1; | |
150 | ||
151 | return kTRUE; | |
152 | } | |
153 | ||
154 | //______________________________________________________________________ | |
155 | const char* AliITSgeomTGeo::GetSymName(Int_t index) | |
156 | { | |
157 | // Get the TGeoPNEntry symbolic name | |
158 | // for a given module identified by 'index' | |
159 | ||
160 | if (index < 0 || index >= fgkNModules) { | |
161 | AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules)); | |
162 | return NULL; | |
163 | } | |
164 | ||
165 | Int_t lay, index2; | |
166 | if (!GetLayer(index,lay,index2)) return NULL; | |
167 | ||
168 | return AliAlignObj::SymName((AliAlignObj::ELayerID)((lay-1)+AliAlignObj::kSPD1),index2); | |
169 | } | |
170 | ||
171 | //______________________________________________________________________ | |
172 | TGeoHMatrix* AliITSgeomTGeo::GetMatrix(Int_t index) | |
173 | { | |
174 | // Get the transformation matrix for a given module 'index' | |
175 | // by quering the TGeoManager | |
176 | ||
177 | TGeoPNEntry *pne = GetPNEntry(index); | |
178 | if (!pne) return NULL; | |
179 | ||
180 | const char* path = pne->GetTitle(); | |
181 | ||
182 | if (!gGeoManager->cd(path)) { | |
183 | AliErrorClass(Form("Volume path %s not valid!",path)); | |
184 | return NULL; | |
185 | } | |
186 | ||
187 | return gGeoManager->GetCurrentMatrix(); | |
188 | } | |
189 | ||
190 | //______________________________________________________________________ | |
191 | Bool_t AliITSgeomTGeo::GetTranslation(Int_t index, Double_t t[3]) | |
192 | { | |
193 | // Get the translation vector for a given module 'index' | |
194 | // by quering the TGeoManager | |
195 | ||
196 | TGeoHMatrix *m = GetMatrix(index); | |
197 | if (!m) return kFALSE; | |
198 | ||
199 | Double_t *trans = m->GetTranslation(); | |
200 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; | |
201 | ||
202 | return kTRUE; | |
203 | } | |
204 | ||
205 | //______________________________________________________________________ | |
206 | Bool_t AliITSgeomTGeo::GetRotation(Int_t index, Double_t r[9]) | |
207 | { | |
208 | // Get the rotation matrix for a given module 'index' | |
209 | // by quering the TGeoManager | |
210 | ||
211 | TGeoHMatrix *m = GetMatrix(index); | |
212 | if (!m) return kFALSE; | |
213 | ||
214 | Double_t *rot = m->GetRotationMatrix(); | |
215 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; | |
216 | ||
217 | return kTRUE; | |
218 | } | |
219 | ||
220 | //______________________________________________________________________ | |
221 | Bool_t AliITSgeomTGeo::GetOrigMatrix(Int_t index, TGeoHMatrix &m) | |
222 | { | |
223 | // Get the original (ideal geometry) TGeo matrix for | |
224 | // a given module identified by 'index'. | |
225 | // The method is slow, so it should be used | |
226 | // with great care. | |
227 | ||
228 | m.Clear(); | |
229 | ||
230 | const char *symname = GetSymName(index); | |
231 | if (!symname) return kFALSE; | |
232 | ||
233 | return AliAlignObj::GetOrigGlobalMatrix(symname,m); | |
234 | } | |
235 | ||
236 | //______________________________________________________________________ | |
237 | Bool_t AliITSgeomTGeo::GetOrigTranslation(Int_t index, Double_t t[3]) | |
238 | { | |
239 | // Get the original translation vector (ideal geometry) | |
240 | // for a given module 'index' by quering the TGeoManager | |
241 | ||
242 | TGeoHMatrix m; | |
243 | if (!GetOrigMatrix(index,m)) return kFALSE; | |
244 | ||
245 | Double_t *trans = m.GetTranslation(); | |
246 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; | |
247 | ||
248 | return kTRUE; | |
249 | } | |
250 | ||
251 | //______________________________________________________________________ | |
252 | Bool_t AliITSgeomTGeo::GetOrigRotation(Int_t index, Double_t r[9]) | |
253 | { | |
254 | // Get the original rotation matrix (ideal geometry) | |
255 | // for a given module 'index' by quering the TGeoManager | |
256 | ||
257 | TGeoHMatrix m; | |
258 | if (!GetOrigMatrix(index,m)) return kFALSE; | |
259 | ||
260 | Double_t *rot = m.GetRotationMatrix(); | |
261 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; | |
262 | ||
263 | return kTRUE; | |
264 | } | |
265 | ||
266 | //______________________________________________________________________ | |
267 | const TGeoHMatrix* AliITSgeomTGeo::GetTracking2LocalMatrix(Int_t index) | |
268 | { | |
269 | // Get the matrix which transforms from the tracking to local r.s. | |
270 | // The method queries directly the TGeoPNEntry | |
271 | ||
272 | TGeoPNEntry *pne = GetPNEntry(index); | |
273 | if (!pne) return NULL; | |
274 | ||
275 | const TGeoHMatrix *m = pne->GetMatrix(); | |
276 | if (!m) | |
277 | AliErrorClass(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName())); | |
278 | ||
279 | return m; | |
280 | } | |
281 | ||
282 | //______________________________________________________________________ | |
283 | Bool_t AliITSgeomTGeo::GetTrackingMatrix(Int_t index, TGeoHMatrix &m) | |
284 | { | |
285 | // Get the matrix which transforms from the tracking r.s. to | |
286 | // the global one. | |
287 | // Returns kFALSE in case of error. | |
288 | ||
289 | m.Clear(); | |
290 | ||
291 | TGeoHMatrix *m1 = GetMatrix(index); | |
292 | if (!m1) return kFALSE; | |
293 | ||
294 | const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index); | |
295 | if (!m2) return kFALSE; | |
296 | ||
297 | m = *m1; | |
298 | m.Multiply(m2); | |
299 | ||
300 | return kTRUE; | |
301 | } | |
302 | ||
303 | //______________________________________________________________________ | |
304 | TGeoPNEntry* AliITSgeomTGeo::GetPNEntry(Int_t index) | |
305 | { | |
306 | // Get a pointer to the TGeoPNEntry of a module | |
307 | // identified by 'index' | |
308 | // Returns NULL in case of invalid index, | |
309 | // missing TGeoManager or invalid symbolic name | |
310 | ||
311 | if (index < 0 || index >= fgkNModules) { | |
312 | AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules)); | |
313 | return NULL; | |
314 | } | |
315 | ||
316 | if (!gGeoManager || !gGeoManager->IsClosed()) { | |
317 | AliErrorClass("Can't get the matrix! gGeoManager doesn't exist or it is still opened!"); | |
318 | return NULL; | |
319 | } | |
320 | ||
321 | TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(GetSymName(index)); | |
322 | if (!pne) | |
323 | AliErrorClass(Form("The symbolic volume name %s does not correspond to a physical entry!", | |
324 | GetSymName(index))); | |
325 | ||
326 | return pne; | |
327 | } |