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