1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //
21 // author - cvetan.cheshkov@cern.ch //
23 ///////////////////////////////////////////////////////////////////////////
27 #include <TGeoManager.h>
28 #include <TGeoPhysicalNode.h>
30 #include "AliITSgeomTGeo.h"
32 #include "AliAlignObj.h"
34 ClassImp(AliITSgeomTGeo)
36 const Int_t AliITSgeomTGeo::fgkNModules = 2198;
37 const Int_t AliITSgeomTGeo::fgkNLadders[kNLayers] = {20,40,14,22,34,38};
38 const Int_t AliITSgeomTGeo::fgkNDetectors[kNLayers] = {4,4,6,8,22,25};
40 //______________________________________________________________________
41 Int_t AliITSgeomTGeo::GetModuleIndex(Int_t lay,Int_t lad,Int_t det)
43 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
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.
54 // the module index number, starting from zero.
55 // -1 in case of error
57 if (lay < 1 || lay > kNLayers) {
58 AliErrorClass(Form("Invalid layer: %d (1 -> %d",lay,kNLayers));
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));
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];
75 //______________________________________________________________________
76 Bool_t AliITSgeomTGeo::GetLayer(Int_t index,Int_t &lay,Int_t &index2)
78 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
85 // Int_t index The module index number, starting from zero.
87 // Int_t index2 The module index inside a layer, starting from zero.
88 // Int_t lay The layer number. Starting from 1.
90 // kTRUE in case of valid index
91 // kFALSE in case of error
93 if (index < 0 || index >= fgkNModules) {
95 AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules));
102 index2 += fgkNLadders[lay]*fgkNDetectors[lay];
104 } while(index2 <= index);
105 index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1];
106 index2 = index - index2;
111 //______________________________________________________________________
112 Bool_t AliITSgeomTGeo::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det)
114 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
121 // Int_t index The module index number, starting from zero.
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.
127 // kTRUE in case of valid index
128 // kFALSE in case of error
130 if (index < 0 || index >= fgkNModules) {
131 lay = lad = det = -1;
132 AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules));
139 index2 += fgkNLadders[lay]*fgkNDetectors[lay];
141 } while(index2 <= index);
142 index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1];
145 index2 += fgkNDetectors[lay-1];
147 } while(index2 <= index);
148 index2 -= fgkNDetectors[lay-1];
150 det = index-index2+1;
155 //______________________________________________________________________
156 const char* AliITSgeomTGeo::GetSymName(Int_t index)
158 // Get the TGeoPNEntry symbolic name
159 // for a given module identified by 'index'
161 if (index < 0 || index >= fgkNModules) {
162 AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules));
167 if (!GetLayer(index,lay,index2)) return NULL;
169 return AliGeomManager::SymName((AliGeomManager::ELayerID)((lay-1)+AliGeomManager::kSPD1),index2);
172 //______________________________________________________________________
173 TGeoHMatrix* AliITSgeomTGeo::GetMatrix(Int_t index)
175 // Get the transformation matrix for a given module 'index'
176 // by quering the TGeoManager
178 TGeoPNEntry *pne = GetPNEntry(index);
179 if (!pne) return NULL;
181 TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
182 if (pnode) return pnode->GetMatrix();
184 const char* path = pne->GetTitle();
185 if (!gGeoManager->cd(path)) {
186 AliErrorClass(Form("Volume path %s not valid!",path));
189 return gGeoManager->GetCurrentMatrix();
192 //______________________________________________________________________
193 Bool_t AliITSgeomTGeo::GetTranslation(Int_t index, Double_t t[3])
195 // Get the translation vector for a given module 'index'
196 // by quering the TGeoManager
198 TGeoHMatrix *m = GetMatrix(index);
199 if (!m) return kFALSE;
201 Double_t *trans = m->GetTranslation();
202 for (Int_t i = 0; i < 3; i++) t[i] = trans[i];
207 //______________________________________________________________________
208 Bool_t AliITSgeomTGeo::GetRotation(Int_t index, Double_t r[9])
210 // Get the rotation matrix for a given module 'index'
211 // by quering the TGeoManager
213 TGeoHMatrix *m = GetMatrix(index);
214 if (!m) return kFALSE;
216 Double_t *rot = m->GetRotationMatrix();
217 for (Int_t i = 0; i < 9; i++) r[i] = rot[i];
222 //______________________________________________________________________
223 Bool_t AliITSgeomTGeo::GetOrigMatrix(Int_t index, TGeoHMatrix &m)
225 // Get the original (ideal geometry) TGeo matrix for
226 // a given module identified by 'index'.
227 // The method is slow, so it should be used
232 const char *symname = GetSymName(index);
233 if (!symname) return kFALSE;
235 return AliGeomManager::GetOrigGlobalMatrix(symname,m);
238 //______________________________________________________________________
239 Bool_t AliITSgeomTGeo::GetOrigTranslation(Int_t index, Double_t t[3])
241 // Get the original translation vector (ideal geometry)
242 // for a given module 'index' by quering the TGeoManager
245 if (!GetOrigMatrix(index,m)) return kFALSE;
247 Double_t *trans = m.GetTranslation();
248 for (Int_t i = 0; i < 3; i++) t[i] = trans[i];
253 //______________________________________________________________________
254 Bool_t AliITSgeomTGeo::GetOrigRotation(Int_t index, Double_t r[9])
256 // Get the original rotation matrix (ideal geometry)
257 // for a given module 'index' by quering the TGeoManager
260 if (!GetOrigMatrix(index,m)) return kFALSE;
262 Double_t *rot = m.GetRotationMatrix();
263 for (Int_t i = 0; i < 9; i++) r[i] = rot[i];
268 //______________________________________________________________________
269 const TGeoHMatrix* AliITSgeomTGeo::GetTracking2LocalMatrix(Int_t index)
271 // Get the matrix which transforms from the tracking to local r.s.
272 // The method queries directly the TGeoPNEntry
274 TGeoPNEntry *pne = GetPNEntry(index);
275 if (!pne) return NULL;
277 const TGeoHMatrix *m = pne->GetMatrix();
279 AliErrorClass(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName()));
284 //______________________________________________________________________
285 Bool_t AliITSgeomTGeo::GetTrackingMatrix(Int_t index, TGeoHMatrix &m)
287 // Get the matrix which transforms from the tracking r.s. to
289 // Returns kFALSE in case of error.
293 TGeoHMatrix *m1 = GetMatrix(index);
294 if (!m1) return kFALSE;
296 const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index);
297 if (!m2) return kFALSE;
305 //______________________________________________________________________
306 TGeoPNEntry* AliITSgeomTGeo::GetPNEntry(Int_t index)
308 // Get a pointer to the TGeoPNEntry of a module
309 // identified by 'index'
310 // Returns NULL in case of invalid index,
311 // missing TGeoManager or invalid symbolic name
313 if (index < 0 || index >= fgkNModules) {
314 AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules));
318 if (!gGeoManager || !gGeoManager->IsClosed()) {
319 AliErrorClass("Can't get the matrix! gGeoManager doesn't exist or it is still opened!");
323 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(GetSymName(index));
325 AliErrorClass(Form("The symbolic volume name %s does not correspond to a physical entry!",
331 //______________________________________________________________________
332 Bool_t AliITSgeomTGeo::LocalToGlobal(Int_t index,
333 const Double_t *loc, Double_t *glob)
335 // Make the conversion from the local sensitive reference system to the global
336 // reference system, for an arbitrary local position. The input is the pointer
337 // to the array of local coordinates, the result is sent to the glob pointer.
339 // Please don't use this method to get the global coordinates of clusters, use
340 // the direct method of AliCluster instead.
342 const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index);
343 if (!m2) return kFALSE;
345 // The shift (in local y only) between alignable and sensitive volume
346 // is extracted directly from the Tracking2Local matrix
347 Double_t locSens[] = {loc[0], loc[1]+m2->GetTranslation()[1], loc[2]};
349 TGeoHMatrix *ml = GetMatrix(index);
350 if (!ml) return kFALSE;
351 ml->LocalToMaster(locSens,glob);
355 //______________________________________________________________________
356 Bool_t AliITSgeomTGeo::GlobalToLocal(Int_t index,
357 const Double_t *glob, Double_t *loc)
359 // Make the conversion from the global reference system to the sensitive local
360 // reference system, for an arbitrary global position. The input is the pointer
361 // to the array of global coordinates, the result is sent to the loc pointer.
363 TGeoHMatrix *ml = GetMatrix(index);
364 if (!ml) return kFALSE;
366 const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index);
367 if (!m2) return kFALSE;
368 ml->MasterToLocal(glob,loc);
369 // The shift (in local y only) between alignable and sensitive volume
370 // is extracted directly from the Tracking2Local matrix
371 loc[1] -= m2->GetTranslation()[1];
376 //______________________________________________________________________
377 Bool_t AliITSgeomTGeo::LocalToGlobalVect(Int_t index,
378 const Double_t *loc, Double_t *glob)
380 // Make the conversion from the local sensitive reference system to the global
381 // reference system, for an arbitrary vector. The input is the pointer to the
382 // array of local coordinates, the result is sent to the glob pointer.
384 TGeoHMatrix *ml = GetMatrix(index);
385 if (!ml) return kFALSE;
386 ml->LocalToMasterVect(loc,glob);
390 //______________________________________________________________________
391 Bool_t AliITSgeomTGeo::GlobalToLocalVect(Int_t index,
392 const Double_t *glob, Double_t *loc)
394 // Make the conversion from the global reference system to the sensitive local
395 // reference system, for an arbitrary vector. The input is the pointer to the
396 // array of global coordinates, the result is sent to the loc pointer.
398 TGeoHMatrix *ml = GetMatrix(index);
399 if (!ml) return kFALSE;
400 ml->MasterToLocalVect(glob,loc);