Added charge to the clusters tree
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUGeomTGeo.h
CommitLineData
451f5018 1#ifndef ALIITSUGEOMTGEO_H
2#define ALIITSUGEOMTGEO_H
a11ef2e4 3
451f5018 4/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
7/////////////////////////////////////////////////////////////////////////
8// AliITSUGeomTGeo is a simple interface class to TGeoManager //
9// It is used in the simulation and reconstruction in order to //
10// query the TGeo ITS geometry //
11// //
12// author - cvetan.cheshkov@cern.ch //
13// 15/02/2007 //
14// adapted to ITSupg 18/07/2012 - ruben.shahoyan@cern.ch //
15// RS: in order to preserve the static character of the class but //
16// make it dynamically access geometry, we need to check in every //
17// method if the structures are initialized. To be converted to //
18// singleton at later stage. //
19// //
20// Note on the upgrade detector types: //
21// The coarse type defines detectors served by different classes, //
75875328 22// like Pix. Each such a detector type can have kMaxSegmPerDetType //
451f5018 23// segmentations (pitch etc.) whose parameteres are stored in the //
75875328 24// AliITSsegmentation derived class (like AliITSUSegmentationPix) //
451f5018 25// This allows to have in the setup modules served by the same //
26// classes but with different segmentations. //
27// The full detector type is composed as: //
28// CoarseType*kMaxSegmPerDetType + segmentationType //
29// The only requirement on the segmentationType that should be //
30// < kMaxSegmPerDetType. //
31// The methods like GetLayerDetTypeID return the full detector type //
32// //
33// //
34/////////////////////////////////////////////////////////////////////////
35
36#include <TObject.h>
37#include <TGeoMatrix.h>
38#include <TString.h>
a11ef2e4 39#include <TObjArray.h>
43361342 40#include "AliITSUAux.h"
451f5018 41
42class TGeoPNEntry;
43class TDatime;
546d00d8 44class AliITSsegmentation;
451f5018 45
46class AliITSUGeomTGeo : public TObject {
47
48 public:
49 enum {kITSVNA, kITSVUpg}; // ITS version
02d6eccc 50 enum {kDetTypePix=0, kNDetTypes, kMaxSegmPerDetType=10}; // defined detector types (each one can have different segmentations)
451f5018 51 //
546d00d8 52 AliITSUGeomTGeo(Bool_t build = kFALSE, Bool_t loadSegmentations = kTRUE);
451f5018 53 virtual ~AliITSUGeomTGeo();
54 AliITSUGeomTGeo(const AliITSUGeomTGeo &src);
55 AliITSUGeomTGeo& operator=(const AliITSUGeomTGeo &geom);
56 //
02d6eccc 57 Int_t GetNModules() const {return fNModules;}
58 Int_t GetNDetectors(Int_t lay) const {return fNDetectors[lay];}
59 Int_t GetNLadders(Int_t lay) const {return fNLadders[lay];}
60 Int_t GetNLayers() const {return fNLayers;}
451f5018 61
02d6eccc 62 Int_t GetModuleIndex(Int_t lay,int detInLay) const {return GetFirstModIndex(lay)+detInLay;}
451f5018 63 Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det) const;
64 Bool_t GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det) const;
65 Int_t GetLayer(Int_t index) const;
66 Int_t GetLadder(Int_t index) const;
67 Int_t GetModIdInLayer(Int_t index) const;
68 Int_t GetModIdInLadder(Int_t index) const;
69 //
70 Int_t GetLastModIndex(Int_t lay) const {return fLastModIndex[lay];}
71 Int_t GetFirstModIndex(Int_t lay) const {return (lay==0) ? 0:fLastModIndex[lay-1]+1;}
72 //
73 const char *GetSymName(Int_t index) const;
74 const char *GetSymName(Int_t lay,Int_t lad,Int_t det) const;
75 //
76 // Attention: these are the matrices for the alignable volumes of the modules, i.e. not necessarily the sensors
77 TGeoHMatrix* GetMatrix(Int_t index) const;
78 TGeoHMatrix* GetMatrix(Int_t lay,Int_t lad,Int_t det) const;
79 Bool_t GetTranslation(Int_t index, Double_t t[3]) const;
80 Bool_t GetTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const;
81 Bool_t GetRotation(Int_t index, Double_t r[9]) const;
82 Bool_t GetRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const;
83 Bool_t GetOrigMatrix(Int_t index, TGeoHMatrix &m) const;
84 Bool_t GetOrigMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m) const;
85 Bool_t GetOrigTranslation(Int_t index, Double_t t[3]) const;
86 Bool_t GetOrigTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const;
87 Bool_t GetOrigRotation(Int_t index, Double_t r[9]) const;
88 Bool_t GetOrigRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const;
89 //
cf457606 90 const TGeoHMatrix* GetMatrixT2L(Int_t index);
91 const TGeoHMatrix* GetMatrixT2L(Int_t lay,Int_t lad,Int_t det) {return GetMatrixT2L( GetModuleIndex(lay,lad,det) );}
92 const TGeoHMatrix* GetMatrixSens(Int_t index);
93 const TGeoHMatrix* GetMatrixSens(Int_t lay,Int_t lad,Int_t det) {return GetMatrixSens( GetModuleIndex(lay,lad,det) );}
451f5018 94 //
cf457606 95 Bool_t GetTrackingMatrix(Int_t index, TGeoHMatrix &m);
96 Bool_t GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m);
451f5018 97 //
98 // Attention: these are transformations wrt sensitive volume!
cf457606 99 void LocalToGlobal(Int_t index, const Double_t *loc, Double_t *glob);
100 void LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob);
451f5018 101 //
cf457606 102 void GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc);
103 void GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc);
451f5018 104 //
cf457606 105 void LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob);
106 void GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc);
451f5018 107 Int_t GetLayerDetTypeID(Int_t lr) const;
108 Int_t GetModuleDetTypeID(Int_t id) const;
109 //
546d00d8 110 const AliITSsegmentation* GetSegmentationByID(Int_t id) const;
111 const AliITSsegmentation* GetSegmentation(Int_t lr) const;
112 TObjArray* GetSegmentations() const {return (TObjArray*)fSegm;}
02d6eccc 113 virtual void Print(Option_t *opt="") const;
114
cf457606 115 static const char* GetITSVolPattern() {return fgkITSVolName;}
116 static const char* GetITSLayerPattern() {return fgkITSLrName;}
43361342 117 static const char* GetITSWrapVolPattern() {return fgkITSWrapVolName;}
cf457606 118 static const char* GetITSLadderPattern() {return fgkITSLadName;}
119 static const char* GetITSModulePattern() {return fgkITSModName;}
120 static const char* GetITSSensorPattern() {return fgkITSSensName;}
cf457606 121 static const char* GetITSsegmentationFileName() {return fgITSsegmFileName.Data();}
75875328 122 static const char* GetDetTypeName(Int_t i);
cf457606 123 static void SetITSsegmentationFileName(const char* nm) {fgITSsegmFileName = nm;}
451f5018 124 static UInt_t ComposeDetTypeID(UInt_t segmId);
125 //
392efe73 126 static const char *ComposeSymNameITS();
127 static const char *ComposeSymNameLayer(Int_t lr);
128 static const char *ComposeSymNameLadder(Int_t lr, Int_t lad);
129 static const char *ComposeSymNameModule(Int_t lr, Int_t lad, int det);
130 //
02d6eccc 131 // hack to avoid using AliGeomManager
cf457606 132 Int_t LayerToVolUID(Int_t lay,int detInLay) const {return GetModuleIndex(lay,detInLay);}
133 static Int_t ModuleVolUID(Int_t mod) {return mod;}
134 //
135 protected:
136 void FetchMatrices();
af4b47c9 137 void CreateT2LMatrices();
cf457606 138 TGeoHMatrix* ExtractMatrixT2L(Int_t index) const;
139 TGeoHMatrix* ExtractMatrixSens(Int_t index) const;
140 Bool_t GetLayer(Int_t index,Int_t &lay,Int_t &index2) const;
141 TGeoPNEntry* GetPNEntry(Int_t index) const;
142 Int_t ExtractNumberOfDetectors(Int_t lay) const;
143 Int_t ExtractNumberOfLadders(Int_t lay) const;
144 Int_t ExtractLayerDetType(Int_t lay) const;
43361342 145 Int_t ExtractNumberOfLayers();
546d00d8 146 void BuildITS(Bool_t loadSegm);
02d6eccc 147 //
546d00d8 148 protected:
af4b47c9 149 //
451f5018 150 //
151 Int_t fVersion; // ITS Version
152 Int_t fNLayers; // number of layers
af4b47c9 153 Int_t fNModules; // The total number of modules
451f5018 154 Int_t *fNLadders; //[fNLayers] Array of the number of ladders/layer(layer)
155 Int_t *fLrDetType; //[fNLayers] Array of layer detector types
156 Int_t *fNDetectors; //[fNLayers] Array of the number of detector/ladder(layer)
157 Int_t *fLastModIndex; //[fNLayers] max ID of the detctor in the layer
43361342 158 Char_t fLr2Wrapper[AliITSUAux::kMaxLayers]; // layer -> wrapper correspondence
451f5018 159 //
cf457606 160 TObjArray* fMatSens; // Sensor's matrices pointers in the geometry
161 TObjArray* fMatT2L; // Tracking to Local matrices pointers in the geometry
546d00d8 162 TObjArray* fSegm; // segmentations
cf457606 163 //
451f5018 164 static const char* fgkITSVolName; // ITS mother volume name
165 static const char* fgkITSLrName; // ITS Layer name
166 static const char* fgkITSLadName; // ITS Ladder name
167 static const char* fgkITSModName; // ITS Module name
168 static const char* fgkITSSensName; // ITS Sensor name
43361342 169 static const char* fgkITSWrapVolName; // ITS Wrapper volume name
451f5018 170 static const char* fgkITSDetTypeName[kNDetTypes]; // ITS upg detType Names
171 //
172 static TString fgITSsegmFileName; // file name for segmentations
173 //
174 ClassDef(AliITSUGeomTGeo, 1) // ITS geometry based on TGeo
175};
176
177//_____________________________________________________________________________________________
178inline const char *AliITSUGeomTGeo::GetSymName(Int_t lay,Int_t lad,Int_t det) const
179{
180 // sym name
181 return GetSymName(GetModuleIndex(lay,lad,det));
182}
183
184//_____________________________________________________________________________________________
185inline TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t lay,Int_t lad,Int_t det) const
186{
187 // module current matrix
188 return GetMatrix(GetModuleIndex(lay,lad,det));
189}
190
191//_____________________________________________________________________________________________
192inline Bool_t AliITSUGeomTGeo::GetTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
193{
194 // translation
195 return GetTranslation(GetModuleIndex(lay,lad,det),t);
196}
197
198//_____________________________________________________________________________________________
199inline Bool_t AliITSUGeomTGeo::GetRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
200{
201 // rot
202 return GetRotation(GetModuleIndex(lay,lad,det),r);
203}
204
205//_____________________________________________________________________________________________
206inline Bool_t AliITSUGeomTGeo::GetOrigMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m) const
207{
208 // orig matrix
209 return GetOrigMatrix(GetModuleIndex(lay,lad,det),m);
210}
211
212//_____________________________________________________________________________________________
213inline Bool_t AliITSUGeomTGeo::GetOrigTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
214{
215 // orig trans
216 return GetOrigTranslation(GetModuleIndex(lay,lad,det),t);
217}
218
219//_____________________________________________________________________________________________
220inline Bool_t AliITSUGeomTGeo::GetOrigRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
221{
222 // orig rot
223 return GetOrigRotation(GetModuleIndex(lay,lad,det),r);
224}
225
226//_____________________________________________________________________________________________
cf457606 227inline Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m)
451f5018 228{
cf457606 229 // tracking mat
230 return GetTrackingMatrix(GetModuleIndex(lay,lad,det),m);
451f5018 231}
232
233//_____________________________________________________________________________________________
cf457606 234inline Int_t AliITSUGeomTGeo::GetLayerDetTypeID(Int_t lr) const
451f5018 235{
cf457606 236 // detector type ID of layer
237 return fLrDetType[lr];
451f5018 238}
239
240//_____________________________________________________________________________________________
cf457606 241inline Int_t AliITSUGeomTGeo::GetModuleDetTypeID(Int_t id) const
451f5018 242{
cf457606 243 // detector type ID of module
244 return GetLayerDetTypeID(GetLayer(id));
245}
451f5018 246
247//_____________________________________________________________________________________________
cf457606 248inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixSens(Int_t index)
451f5018 249{
cf457606 250 // access global to sensor matrix
251 if (!fMatSens) FetchMatrices();
252 return (TGeoHMatrix*)fMatSens->At(index);
451f5018 253}
254
255//_____________________________________________________________________________________________
cf457606 256inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixT2L(Int_t index)
451f5018 257{
cf457606 258 // access tracking to local matrix
259 if (!fMatT2L) FetchMatrices();
260 return (TGeoHMatrix*)fMatT2L->At(index);
261}
262
263//______________________________________________________________________
264inline void AliITSUGeomTGeo::LocalToGlobal(Int_t index,const Double_t *loc, Double_t *glob)
265{
266 // sensor local to global
267 GetMatrixSens(index)->LocalToMaster(loc,glob);
268}
269
270//______________________________________________________________________
271inline void AliITSUGeomTGeo::GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc)
272{
273 // global to sensor local
274 GetMatrixSens(index)->MasterToLocal(glob,loc);
275}
276
277//______________________________________________________________________
278inline void AliITSUGeomTGeo::LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob)
279{
280 // sensor local to global
281 GetMatrixSens(index)->LocalToMasterVect(loc,glob);
282}
283
284//______________________________________________________________________
285inline void AliITSUGeomTGeo::GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc)
286{
287 // global to sensor local
288 GetMatrixSens(index)->MasterToLocalVect(glob,loc);
451f5018 289}
290
291//_____________________________________________________________________________________________
cf457606 292inline void AliITSUGeomTGeo::LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob)
451f5018 293{
cf457606 294 // Local2Master (sensor)
295 LocalToGlobal(GetModuleIndex(lay,lad,det), loc, glob);
451f5018 296}
297
298//_____________________________________________________________________________________________
cf457606 299inline void AliITSUGeomTGeo::GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc)
451f5018 300{
cf457606 301 // master2local (sensor)
302 GlobalToLocal(GetModuleIndex(lay,lad,det), glob, loc);
303}
451f5018 304
75875328 305//_____________________________________________________________________________________________
306inline const char* AliITSUGeomTGeo::GetDetTypeName(Int_t i)
307{
308 if (i>=kNDetTypes) i/=kMaxSegmPerDetType; // full type is provided
309 return fgkITSDetTypeName[i];
310}
451f5018 311
546d00d8 312//_____________________________________________________________________________________________
313inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentationByID(Int_t id) const
314{
315 // get segmentation by ID
316 return fSegm ? (AliITSsegmentation*)fSegm->At(id) : 0;
317}
318
319//_____________________________________________________________________________________________
320inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentation(Int_t lr) const
321{
322 // get segmentation of layer
323 return fSegm ? (AliITSsegmentation*)fSegm->At( GetLayerDetTypeID(lr) ) : 0;
324}
325
451f5018 326#endif