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>
43 class AliITSsegmentation;
45 class AliITSUGeomTGeo : public TObject {
48 enum {kITSVNA, kITSVUpg}; // ITS version
49 enum {kDetTypePix=0, kNDetTypes, kMaxSegmPerDetType=10}; // defined detector types (each one can have different segmentations)
51 AliITSUGeomTGeo(Bool_t build = kFALSE, Bool_t loadSegmentations = kTRUE);
52 virtual ~AliITSUGeomTGeo();
53 AliITSUGeomTGeo(const AliITSUGeomTGeo &src);
54 AliITSUGeomTGeo& operator=(const AliITSUGeomTGeo &geom);
56 Int_t GetNModules() const {return fNModules;}
57 Int_t GetNDetectors(Int_t lay) const {return fNDetectors[lay];}
58 Int_t GetNLadders(Int_t lay) const {return fNLadders[lay];}
59 Int_t GetNLayers() const {return fNLayers;}
61 Int_t GetModuleIndex(Int_t lay,int detInLay) const {return GetFirstModIndex(lay)+detInLay;}
62 Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det) const;
63 Bool_t GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det) const;
64 Int_t GetLayer(Int_t index) const;
65 Int_t GetLadder(Int_t index) const;
66 Int_t GetModIdInLayer(Int_t index) const;
67 Int_t GetModIdInLadder(Int_t index) const;
69 Int_t GetLastModIndex(Int_t lay) const {return fLastModIndex[lay];}
70 Int_t GetFirstModIndex(Int_t lay) const {return (lay==0) ? 0:fLastModIndex[lay-1]+1;}
72 const char *GetSymName(Int_t index) const;
73 const char *GetSymName(Int_t lay,Int_t lad,Int_t det) const;
75 // Attention: these are the matrices for the alignable volumes of the modules, i.e. not necessarily the sensors
76 TGeoHMatrix* GetMatrix(Int_t index) const;
77 TGeoHMatrix* GetMatrix(Int_t lay,Int_t lad,Int_t det) const;
78 Bool_t GetTranslation(Int_t index, Double_t t[3]) const;
79 Bool_t GetTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const;
80 Bool_t GetRotation(Int_t index, Double_t r[9]) const;
81 Bool_t GetRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const;
82 Bool_t GetOrigMatrix(Int_t index, TGeoHMatrix &m) const;
83 Bool_t GetOrigMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m) const;
84 Bool_t GetOrigTranslation(Int_t index, Double_t t[3]) const;
85 Bool_t GetOrigTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const;
86 Bool_t GetOrigRotation(Int_t index, Double_t r[9]) const;
87 Bool_t GetOrigRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const;
89 const TGeoHMatrix* GetMatrixT2L(Int_t index);
90 const TGeoHMatrix* GetMatrixT2L(Int_t lay,Int_t lad,Int_t det) {return GetMatrixT2L( GetModuleIndex(lay,lad,det) );}
91 const TGeoHMatrix* GetMatrixSens(Int_t index);
92 const TGeoHMatrix* GetMatrixSens(Int_t lay,Int_t lad,Int_t det) {return GetMatrixSens( GetModuleIndex(lay,lad,det) );}
94 Bool_t GetTrackingMatrix(Int_t index, TGeoHMatrix &m);
95 Bool_t GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m);
97 // Attention: these are transformations wrt sensitive volume!
98 void LocalToGlobal(Int_t index, const Double_t *loc, Double_t *glob);
99 void LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob);
101 void GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc);
102 void GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc);
104 void LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob);
105 void GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc);
106 Int_t GetLayerDetTypeID(Int_t lr) const;
107 Int_t GetModuleDetTypeID(Int_t id) const;
109 const AliITSsegmentation* GetSegmentationByID(Int_t id) const;
110 const AliITSsegmentation* GetSegmentation(Int_t lr) const;
111 TObjArray* GetSegmentations() const {return (TObjArray*)fSegm;}
112 virtual void Print(Option_t *opt="") const;
114 static const char* GetITSVolPattern() {return fgkITSVolName;}
115 static const char* GetITSLayerPattern() {return fgkITSLrName;}
116 static const char* GetITSLadderPattern() {return fgkITSLadName;}
117 static const char* GetITSModulePattern() {return fgkITSModName;}
118 static const char* GetITSSensorPattern() {return fgkITSSensName;}
119 static const char* GetITSsegmentationFileName() {return fgITSsegmFileName.Data();}
120 static const char* GetDetTypeName(Int_t i);
121 static void SetITSsegmentationFileName(const char* nm) {fgITSsegmFileName = nm;}
122 static UInt_t ComposeDetTypeID(UInt_t segmId);
124 static const char *ComposeSymNameITS();
125 static const char *ComposeSymNameLayer(Int_t lr);
126 static const char *ComposeSymNameLadder(Int_t lr, Int_t lad);
127 static const char *ComposeSymNameModule(Int_t lr, Int_t lad, int det);
129 // hack to avoid using AliGeomManager
130 Int_t LayerToVolUID(Int_t lay,int detInLay) const {return GetModuleIndex(lay,detInLay);}
131 static Int_t ModuleVolUID(Int_t mod) {return mod;}
134 void FetchMatrices();
135 void CreateT2LMatrices();
136 TGeoHMatrix* ExtractMatrixT2L(Int_t index) const;
137 TGeoHMatrix* ExtractMatrixSens(Int_t index) const;
138 Bool_t GetLayer(Int_t index,Int_t &lay,Int_t &index2) const;
139 TGeoPNEntry* GetPNEntry(Int_t index) const;
140 Int_t ExtractNumberOfDetectors(Int_t lay) const;
141 Int_t ExtractNumberOfLadders(Int_t lay) const;
142 Int_t ExtractLayerDetType(Int_t lay) const;
143 Int_t ExtractNumberOfLayers() const;
144 void BuildITS(Bool_t loadSegm);
149 Int_t fVersion; // ITS Version
150 Int_t fNLayers; // number of layers
151 Int_t fNModules; // The total number of modules
152 Int_t *fNLadders; //[fNLayers] Array of the number of ladders/layer(layer)
153 Int_t *fLrDetType; //[fNLayers] Array of layer detector types
154 Int_t *fNDetectors; //[fNLayers] Array of the number of detector/ladder(layer)
155 Int_t *fLastModIndex; //[fNLayers] max ID of the detctor in the layer
157 TObjArray* fMatSens; // Sensor's matrices pointers in the geometry
158 TObjArray* fMatT2L; // Tracking to Local matrices pointers in the geometry
159 TObjArray* fSegm; // segmentations
161 static const char* fgkITSVolName; // ITS mother volume name
162 static const char* fgkITSLrName; // ITS Layer name
163 static const char* fgkITSLadName; // ITS Ladder name
164 static const char* fgkITSModName; // ITS Module name
165 static const char* fgkITSSensName; // ITS Sensor name
166 static const char* fgkITSDetTypeName[kNDetTypes]; // ITS upg detType Names
168 static TString fgITSsegmFileName; // file name for segmentations
170 ClassDef(AliITSUGeomTGeo, 1) // ITS geometry based on TGeo
173 //_____________________________________________________________________________________________
174 inline const char *AliITSUGeomTGeo::GetSymName(Int_t lay,Int_t lad,Int_t det) const
177 return GetSymName(GetModuleIndex(lay,lad,det));
180 //_____________________________________________________________________________________________
181 inline TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t lay,Int_t lad,Int_t det) const
183 // module current matrix
184 return GetMatrix(GetModuleIndex(lay,lad,det));
187 //_____________________________________________________________________________________________
188 inline Bool_t AliITSUGeomTGeo::GetTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
191 return GetTranslation(GetModuleIndex(lay,lad,det),t);
194 //_____________________________________________________________________________________________
195 inline Bool_t AliITSUGeomTGeo::GetRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
198 return GetRotation(GetModuleIndex(lay,lad,det),r);
201 //_____________________________________________________________________________________________
202 inline Bool_t AliITSUGeomTGeo::GetOrigMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m) const
205 return GetOrigMatrix(GetModuleIndex(lay,lad,det),m);
208 //_____________________________________________________________________________________________
209 inline Bool_t AliITSUGeomTGeo::GetOrigTranslation(Int_t lay,Int_t lad,Int_t det, Double_t t[3]) const
212 return GetOrigTranslation(GetModuleIndex(lay,lad,det),t);
215 //_____________________________________________________________________________________________
216 inline Bool_t AliITSUGeomTGeo::GetOrigRotation(Int_t lay,Int_t lad,Int_t det, Double_t r[9]) const
219 return GetOrigRotation(GetModuleIndex(lay,lad,det),r);
222 //_____________________________________________________________________________________________
223 inline Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m)
226 return GetTrackingMatrix(GetModuleIndex(lay,lad,det),m);
229 //_____________________________________________________________________________________________
230 inline Int_t AliITSUGeomTGeo::GetLayerDetTypeID(Int_t lr) const
232 // detector type ID of layer
233 return fLrDetType[lr];
236 //_____________________________________________________________________________________________
237 inline Int_t AliITSUGeomTGeo::GetModuleDetTypeID(Int_t id) const
239 // detector type ID of module
240 return GetLayerDetTypeID(GetLayer(id));
243 //_____________________________________________________________________________________________
244 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixSens(Int_t index)
246 // access global to sensor matrix
247 if (!fMatSens) FetchMatrices();
248 return (TGeoHMatrix*)fMatSens->At(index);
251 //_____________________________________________________________________________________________
252 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixT2L(Int_t index)
254 // access tracking to local matrix
255 if (!fMatT2L) FetchMatrices();
256 return (TGeoHMatrix*)fMatT2L->At(index);
259 //______________________________________________________________________
260 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t index,const Double_t *loc, Double_t *glob)
262 // sensor local to global
263 GetMatrixSens(index)->LocalToMaster(loc,glob);
266 //______________________________________________________________________
267 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc)
269 // global to sensor local
270 GetMatrixSens(index)->MasterToLocal(glob,loc);
273 //______________________________________________________________________
274 inline void AliITSUGeomTGeo::LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob)
276 // sensor local to global
277 GetMatrixSens(index)->LocalToMasterVect(loc,glob);
280 //______________________________________________________________________
281 inline void AliITSUGeomTGeo::GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc)
283 // global to sensor local
284 GetMatrixSens(index)->MasterToLocalVect(glob,loc);
287 //_____________________________________________________________________________________________
288 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob)
290 // Local2Master (sensor)
291 LocalToGlobal(GetModuleIndex(lay,lad,det), loc, glob);
294 //_____________________________________________________________________________________________
295 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc)
297 // master2local (sensor)
298 GlobalToLocal(GetModuleIndex(lay,lad,det), glob, loc);
301 //_____________________________________________________________________________________________
302 inline const char* AliITSUGeomTGeo::GetDetTypeName(Int_t i)
304 if (i>=kNDetTypes) i/=kMaxSegmPerDetType; // full type is provided
305 return fgkITSDetTypeName[i];
308 //_____________________________________________________________________________________________
309 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentationByID(Int_t id) const
311 // get segmentation by ID
312 return fSegm ? (AliITSsegmentation*)fSegm->At(id) : 0;
315 //_____________________________________________________________________________________________
316 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentation(Int_t lr) const
318 // get segmentation of layer
319 return fSegm ? (AliITSsegmentation*)fSegm->At( GetLayerDetTypeID(lr) ) : 0;