]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUGeomTGeo.h
Added 2nd afterburner for short tracks (seen only by 2 outer layers)
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUGeomTGeo.h
1 #ifndef ALIITSUGEOMTGEO_H
2 #define ALIITSUGEOMTGEO_H
3
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,     //
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   //
32 //                                                                     //
33 //                                                                     //
34 /////////////////////////////////////////////////////////////////////////
35
36 #include <TObject.h>
37 #include <TGeoMatrix.h>
38 #include <TString.h>
39 #include <TObjArray.h>
40 #include "AliITSUAux.h"
41
42 class TGeoPNEntry;
43 class TDatime;
44 class AliITSsegmentation;
45
46 class AliITSUGeomTGeo : public TObject {
47
48  public:
49   enum {kITSVNA, kITSVUpg}; // ITS version
50   enum {kDetTypePix=0, kNDetTypes, kMaxSegmPerDetType=10}; // defined detector types (each one can have different segmentations)
51   //
52   AliITSUGeomTGeo(Bool_t build = kFALSE, Bool_t loadSegmentations = kTRUE);
53   virtual ~AliITSUGeomTGeo(); 
54   AliITSUGeomTGeo(const AliITSUGeomTGeo &src);
55   AliITSUGeomTGeo& operator=(const AliITSUGeomTGeo &geom);
56   //
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;}
61   
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;
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   //
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) );}
94   //
95   Bool_t GetTrackingMatrix(Int_t index, TGeoHMatrix &m);
96   Bool_t GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m);
97   //
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);
101   //
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);
104   //
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;
109   //
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;
114
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);
125   //
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   //
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;}
134   //
135  protected:
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);
147   //
148  protected:
149   //
150   //
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
159   //
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
163   //
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
171   //
172   static TString      fgITSsegmFileName;         // file name for segmentations
173   //
174   ClassDef(AliITSUGeomTGeo, 1) // ITS geometry based on TGeo
175 };
176
177 //_____________________________________________________________________________________________
178 inline 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 //_____________________________________________________________________________________________
185 inline 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 //_____________________________________________________________________________________________
192 inline 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 //_____________________________________________________________________________________________
199 inline 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 //_____________________________________________________________________________________________
206 inline 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 //_____________________________________________________________________________________________
213 inline 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 //_____________________________________________________________________________________________
220 inline 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 //_____________________________________________________________________________________________
227 inline Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t lay,Int_t lad,Int_t det, TGeoHMatrix &m)
228 {
229   // tracking mat
230   return GetTrackingMatrix(GetModuleIndex(lay,lad,det),m); 
231 }
232
233 //_____________________________________________________________________________________________
234 inline Int_t  AliITSUGeomTGeo::GetLayerDetTypeID(Int_t lr) const  
235 {
236   // detector type ID of layer
237   return fLrDetType[lr];
238 }
239
240 //_____________________________________________________________________________________________
241 inline Int_t  AliITSUGeomTGeo::GetModuleDetTypeID(Int_t id) const  
242 {
243   // detector type ID of module
244   return GetLayerDetTypeID(GetLayer(id));
245
246
247 //_____________________________________________________________________________________________
248 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixSens(Int_t index)
249 {
250   // access global to sensor matrix
251   if (!fMatSens) FetchMatrices();
252   return (TGeoHMatrix*)fMatSens->At(index);
253 }
254
255 //_____________________________________________________________________________________________
256 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixT2L(Int_t index)
257 {
258   // access tracking to local matrix
259   if (!fMatT2L) FetchMatrices();
260   return (TGeoHMatrix*)fMatT2L->At(index);
261 }
262
263 //______________________________________________________________________
264 inline 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 //______________________________________________________________________
271 inline 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 //______________________________________________________________________
278 inline 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 //______________________________________________________________________
285 inline 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);
289 }
290
291 //_____________________________________________________________________________________________
292 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t lay, Int_t lad, Int_t det,const Double_t *loc, Double_t *glob)
293 {
294   // Local2Master (sensor)
295   LocalToGlobal(GetModuleIndex(lay,lad,det), loc, glob);
296 }
297
298 //_____________________________________________________________________________________________
299 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t lay, Int_t lad, Int_t det,const Double_t *glob, Double_t *loc)
300 {
301   // master2local (sensor)
302   GlobalToLocal(GetModuleIndex(lay,lad,det), glob, loc);
303 }
304
305 //_____________________________________________________________________________________________
306 inline const char* AliITSUGeomTGeo::GetDetTypeName(Int_t i)
307 {
308   if (i>=kNDetTypes) i/=kMaxSegmPerDetType; // full type is provided
309   return fgkITSDetTypeName[i];
310 }
311
312 //_____________________________________________________________________________________________
313 inline 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 //_____________________________________________________________________________________________
320 inline 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
326 #endif