1 #ifndef ALIITSUGEOMTGEO_H
2 #define ALIITSUGEOMTGEO_H
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
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 //
12 // author - cvetan.cheshkov@cern.ch //
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. //
20 // Note on the upgrade detector types: //
21 // The coarse type defines detectors served by different classes, //
22 // like Pix. Each such a detector type can have kMaxSegmPerDetType //
23 // segmentations (pitch etc.) whose parameteres are stored in the //
24 // AliITSsegmentation derived class (like AliITSUSegmentationPix) //
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 //
34 /////////////////////////////////////////////////////////////////////////
37 #include <TGeoMatrix.h>
39 #include <TObjArray.h>
40 #include "AliITSUAux.h"
44 class AliITSsegmentation;
46 class AliITSUGeomTGeo : public TObject {
49 enum {kITSVNA, kITSVUpg}; // ITS version
50 enum {kDetTypePix=0, kNDetTypes, kMaxSegmPerDetType=10}; // defined detector types (each one can have different segmentations)
52 AliITSUGeomTGeo(Bool_t build = kFALSE, Bool_t loadSegmentations = kTRUE);
53 virtual ~AliITSUGeomTGeo();
54 AliITSUGeomTGeo(const AliITSUGeomTGeo &src);
55 AliITSUGeomTGeo& operator=(const AliITSUGeomTGeo &geom);
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;}
62 Int_t GetModuleIndex(Int_t lay,int detInLay) const {return GetFirstModIndex(lay)+detInLay;}
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;
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;}
73 const char *GetSymName(Int_t index) const;
74 const char *GetSymName(Int_t lay,Int_t lad,Int_t det) const;
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;
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) );}
95 Bool_t GetTrackingMatrix(Int_t index, TGeoHMatrix &m);
96 Bool_t GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m);
98 // Attention: these are transformations wrt sensitive volume!
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);
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);
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);
107 Int_t GetLayerDetTypeID(Int_t lr) const;
108 Int_t GetModuleDetTypeID(Int_t id) const;
110 const AliITSsegmentation* GetSegmentationByID(Int_t id) const;
111 const AliITSsegmentation* GetSegmentation(Int_t lr) const;
112 TObjArray* GetSegmentations() const {return (TObjArray*)fSegm;}
113 virtual void Print(Option_t *opt="") const;
115 static const char* GetITSVolPattern() {return fgkITSVolName;}
116 static const char* GetITSLayerPattern() {return fgkITSLrName;}
117 static const char* GetITSWrapVolPattern() {return fgkITSWrapVolName;}
118 static const char* GetITSLadderPattern() {return fgkITSLadName;}
119 static const char* GetITSModulePattern() {return fgkITSModName;}
120 static const char* GetITSSensorPattern() {return fgkITSSensName;}
121 static const char* GetITSsegmentationFileName() {return fgITSsegmFileName.Data();}
122 static const char* GetDetTypeName(Int_t i);
123 static void SetITSsegmentationFileName(const char* nm) {fgITSsegmFileName = nm;}
124 static UInt_t ComposeDetTypeID(UInt_t segmId);
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);
131 // hack to avoid using AliGeomManager
132 Int_t LayerToVolUID(Int_t lay,int detInLay) const {return GetModuleIndex(lay,detInLay);}
133 static Int_t ModuleVolUID(Int_t mod) {return mod;}
136 void FetchMatrices();
137 void CreateT2LMatrices();
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;
145 Int_t ExtractNumberOfLayers();
146 void BuildITS(Bool_t loadSegm);
151 Int_t fVersion; // ITS Version
152 Int_t fNLayers; // number of layers
153 Int_t fNModules; // The total number of modules
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
158 Char_t fLr2Wrapper[AliITSUAux::kMaxLayers]; // layer -> wrapper correspondence
160 TObjArray* fMatSens; // Sensor's matrices pointers in the geometry
161 TObjArray* fMatT2L; // Tracking to Local matrices pointers in the geometry
162 TObjArray* fSegm; // segmentations
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
169 static const char* fgkITSWrapVolName; // ITS Wrapper volume name
170 static const char* fgkITSDetTypeName[kNDetTypes]; // ITS upg detType Names
172 static TString fgITSsegmFileName; // file name for segmentations
174 ClassDef(AliITSUGeomTGeo, 1) // ITS geometry based on TGeo
177 //_____________________________________________________________________________________________
178 inline const char *AliITSUGeomTGeo::GetSymName(Int_t lay,Int_t lad,Int_t det) const
181 return GetSymName(GetModuleIndex(lay,lad,det));
184 //_____________________________________________________________________________________________
185 inline TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t lay,Int_t lad,Int_t det) const
187 // module current matrix
188 return GetMatrix(GetModuleIndex(lay,lad,det));
191 //_____________________________________________________________________________________________
192 inline Bool_t AliITSUGeomTGeo::GetTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
195 return GetTranslation(GetModuleIndex(lay,lad,det),t);
198 //_____________________________________________________________________________________________
199 inline Bool_t AliITSUGeomTGeo::GetRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
202 return GetRotation(GetModuleIndex(lay,lad,det),r);
205 //_____________________________________________________________________________________________
206 inline Bool_t AliITSUGeomTGeo::GetOrigMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m) const
209 return GetOrigMatrix(GetModuleIndex(lay,lad,det),m);
212 //_____________________________________________________________________________________________
213 inline Bool_t AliITSUGeomTGeo::GetOrigTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
216 return GetOrigTranslation(GetModuleIndex(lay,lad,det),t);
219 //_____________________________________________________________________________________________
220 inline Bool_t AliITSUGeomTGeo::GetOrigRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
223 return GetOrigRotation(GetModuleIndex(lay,lad,det),r);
226 //_____________________________________________________________________________________________
227 inline Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m)
230 return GetTrackingMatrix(GetModuleIndex(lay,lad,det),m);
233 //_____________________________________________________________________________________________
234 inline Int_t AliITSUGeomTGeo::GetLayerDetTypeID(Int_t lr) const
236 // detector type ID of layer
237 return fLrDetType[lr];
240 //_____________________________________________________________________________________________
241 inline Int_t AliITSUGeomTGeo::GetModuleDetTypeID(Int_t id) const
243 // detector type ID of module
244 return GetLayerDetTypeID(GetLayer(id));
247 //_____________________________________________________________________________________________
248 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixSens(Int_t index)
250 // access global to sensor matrix
251 if (!fMatSens) FetchMatrices();
252 return (TGeoHMatrix*)fMatSens->At(index);
255 //_____________________________________________________________________________________________
256 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixT2L(Int_t index)
258 // access tracking to local matrix
259 if (!fMatT2L) FetchMatrices();
260 return (TGeoHMatrix*)fMatT2L->At(index);
263 //______________________________________________________________________
264 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t index,const Double_t *loc, Double_t *glob)
266 // sensor local to global
267 GetMatrixSens(index)->LocalToMaster(loc,glob);
270 //______________________________________________________________________
271 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc)
273 // global to sensor local
274 GetMatrixSens(index)->MasterToLocal(glob,loc);
277 //______________________________________________________________________
278 inline void AliITSUGeomTGeo::LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob)
280 // sensor local to global
281 GetMatrixSens(index)->LocalToMasterVect(loc,glob);
284 //______________________________________________________________________
285 inline void AliITSUGeomTGeo::GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc)
287 // global to sensor local
288 GetMatrixSens(index)->MasterToLocalVect(glob,loc);
291 //_____________________________________________________________________________________________
292 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob)
294 // Local2Master (sensor)
295 LocalToGlobal(GetModuleIndex(lay,lad,det), loc, glob);
298 //_____________________________________________________________________________________________
299 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc)
301 // master2local (sensor)
302 GlobalToLocal(GetModuleIndex(lay,lad,det), glob, loc);
305 //_____________________________________________________________________________________________
306 inline const char* AliITSUGeomTGeo::GetDetTypeName(Int_t i)
308 if (i>=kNDetTypes) i/=kMaxSegmPerDetType; // full type is provided
309 return fgkITSDetTypeName[i];
312 //_____________________________________________________________________________________________
313 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentationByID(Int_t id) const
315 // get segmentation by ID
316 return fSegm ? (AliITSsegmentation*)fSegm->At(id) : 0;
319 //_____________________________________________________________________________________________
320 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentation(Int_t lr) const
322 // get segmentation of layer
323 return fSegm ? (AliITSsegmentation*)fSegm->At( GetLayerDetTypeID(lr) ) : 0;