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 ///////////////////////////////////////////////////////////////////////////
26 #include <TGeoManager.h>
27 #include <TGeoPhysicalNode.h>
29 #include "AliITSgeomTGeo.h"
31 #include "AliAlignObj.h"
33 ClassImp(AliITSgeomTGeo)
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};
39 //______________________________________________________________________
40 Int_t AliITSgeomTGeo::GetModuleIndex(Int_t lay,Int_t lad,Int_t det)
42 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
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.
53 // the module index number, starting from zero.
54 // -1 in case of error
56 if (lay < 1 || lay > kNLayers) {
57 AliErrorClass(Form("Invalid layer: %d (1 -> %d",lay,kNLayers));
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));
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];
74 //______________________________________________________________________
75 Bool_t AliITSgeomTGeo::GetLayer(Int_t index,Int_t &lay,Int_t &index2)
77 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
84 // Int_t index The module index number, starting from zero.
86 // Int_t index2 The module index inside a layer, starting from zero.
87 // Int_t lay The layer number. Starting from 1.
89 // kTRUE in case of valid index
90 // kFALSE in case of error
92 if (index < 0 || index >= fgkNModules) {
94 AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules));
101 index2 += fgkNLadders[lay]*fgkNDetectors[lay];
103 } while(index2 <= index);
104 index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1];
105 index2 = index - index2;
110 //______________________________________________________________________
111 Bool_t AliITSgeomTGeo::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det)
113 // The method is taken from the old AliITSgeom class by Bjorn Nilsen
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.
120 // Int_t index The module index number, starting from zero.
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.
126 // kTRUE in case of valid index
127 // kFALSE in case of error
129 if (index < 0 || index >= fgkNModules) {
130 lay = lad = det = -1;
131 AliErrorClass(Form("Invalid module index: %d (0 -> %d)",index,fgkNModules));
138 index2 += fgkNLadders[lay]*fgkNDetectors[lay];
140 } while(index2 <= index);
141 index2 -= fgkNLadders[lay-1]*fgkNDetectors[lay-1];
144 index2 += fgkNDetectors[lay-1];
146 } while(index2 <= index);
147 index2 -= fgkNDetectors[lay-1];
149 det = index-index2+1;
154 //______________________________________________________________________
155 const char* AliITSgeomTGeo::GetSymName(Int_t index)
157 // Get the TGeoPNEntry symbolic name
158 // for a given module identified by 'index'
160 if (index < 0 || index >= fgkNModules) {
161 AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules));
166 if (!GetLayer(index,lay,index2)) return NULL;
168 return AliAlignObj::SymName((AliAlignObj::ELayerID)((lay-1)+AliAlignObj::kSPD1),index2);
171 //______________________________________________________________________
172 TGeoHMatrix* AliITSgeomTGeo::GetMatrix(Int_t index)
174 // Get the transformation matrix for a given module 'index'
175 // by quering the TGeoManager
177 TGeoPNEntry *pne = GetPNEntry(index);
178 if (!pne) return NULL;
180 const char* path = pne->GetTitle();
182 if (!gGeoManager->cd(path)) {
183 AliErrorClass(Form("Volume path %s not valid!",path));
187 return gGeoManager->GetCurrentMatrix();
190 //______________________________________________________________________
191 Bool_t AliITSgeomTGeo::GetTranslation(Int_t index, Double_t t[3])
193 // Get the translation vector for a given module 'index'
194 // by quering the TGeoManager
196 TGeoHMatrix *m = GetMatrix(index);
197 if (!m) return kFALSE;
199 Double_t *trans = m->GetTranslation();
200 for (Int_t i = 0; i < 3; i++) t[i] = trans[i];
205 //______________________________________________________________________
206 Bool_t AliITSgeomTGeo::GetRotation(Int_t index, Double_t r[9])
208 // Get the rotation matrix for a given module 'index'
209 // by quering the TGeoManager
211 TGeoHMatrix *m = GetMatrix(index);
212 if (!m) return kFALSE;
214 Double_t *rot = m->GetRotationMatrix();
215 for (Int_t i = 0; i < 9; i++) r[i] = rot[i];
220 //______________________________________________________________________
221 Bool_t AliITSgeomTGeo::GetOrigMatrix(Int_t index, TGeoHMatrix &m)
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
230 const char *symname = GetSymName(index);
231 if (!symname) return kFALSE;
233 return AliAlignObj::GetOrigGlobalMatrix(symname,m);
236 //______________________________________________________________________
237 Bool_t AliITSgeomTGeo::GetOrigTranslation(Int_t index, Double_t t[3])
239 // Get the original translation vector (ideal geometry)
240 // for a given module 'index' by quering the TGeoManager
243 if (!GetOrigMatrix(index,m)) return kFALSE;
245 Double_t *trans = m.GetTranslation();
246 for (Int_t i = 0; i < 3; i++) t[i] = trans[i];
251 //______________________________________________________________________
252 Bool_t AliITSgeomTGeo::GetOrigRotation(Int_t index, Double_t r[9])
254 // Get the original rotation matrix (ideal geometry)
255 // for a given module 'index' by quering the TGeoManager
258 if (!GetOrigMatrix(index,m)) return kFALSE;
260 Double_t *rot = m.GetRotationMatrix();
261 for (Int_t i = 0; i < 9; i++) r[i] = rot[i];
266 //______________________________________________________________________
267 const TGeoHMatrix* AliITSgeomTGeo::GetTracking2LocalMatrix(Int_t index)
269 // Get the matrix which transforms from the tracking to local r.s.
270 // The method queries directly the TGeoPNEntry
272 TGeoPNEntry *pne = GetPNEntry(index);
273 if (!pne) return NULL;
275 const TGeoHMatrix *m = pne->GetMatrix();
277 AliErrorClass(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName()));
282 //______________________________________________________________________
283 Bool_t AliITSgeomTGeo::GetTrackingMatrix(Int_t index, TGeoHMatrix &m)
285 // Get the matrix which transforms from the tracking r.s. to
287 // Returns kFALSE in case of error.
291 TGeoHMatrix *m1 = GetMatrix(index);
292 if (!m1) return kFALSE;
294 const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index);
295 if (!m2) return kFALSE;
303 //______________________________________________________________________
304 TGeoPNEntry* AliITSgeomTGeo::GetPNEntry(Int_t index)
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
311 if (index < 0 || index >= fgkNModules) {
312 AliErrorClass(Form("Invalid ITS module index: %d (0 -> %d) !",index,fgkNModules));
316 if (!gGeoManager || !gGeoManager->IsClosed()) {
317 AliErrorClass("Can't get the matrix! gGeoManager doesn't exist or it is still opened!");
321 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(GetSymName(index));
323 AliErrorClass(Form("The symbolic volume name %s does not correspond to a physical entry!",