]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUGeomTGeo.h
Merge branch 'master' into dev
[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 chip types:                                    //
21 //  The coarse type defines chips served by different classes,         //
22 //  like Pix. Each such a chip type can have kMaxSegmPerChipType       //
23 //  segmentations (pitch etc.) whose parameteres are stored in the     //
24 //  AliITSsegmentation derived class (like AliITSUSegmentationPix)     //
25 //  This allows to have in the setup chips served by the same          //
26 //  classes but with different segmentations.                          //
27 //  The full chip type is composed as:                                 //
28 //  CoarseType*kMaxSegmPerChipType + segmentationType                  //
29 //  The only requirement on the segmentationType that should be        //
30 //  < kMaxSegmPerChipType.                                             //
31 //  The methods like GetLayerChipTypeID return the full chip 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 {kChipTypePix=0, kNChipTypes, kMaxSegmPerChipType=10}; // defined detector chip 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  GetNChips()                                                    const {return fNChips;}
58   Int_t  GetNChipRowsPerModule(Int_t lay)                               const {return fNChipRowsPerModule[lay];}
59   Int_t  GetNChipColsPerModule(Int_t lay)                               const {return fNChipRowsPerModule[lay] ? fNChipsPerModule[lay]/fNChipRowsPerModule[lay] : -1;}
60   Int_t  GetNChipsPerModule(Int_t lay)                                  const {return fNChipsPerModule[lay];}
61   Int_t  GetNChipsPerHalfStave(Int_t lay)                               const {return fNChipsPerHalfStave[lay];}
62   Int_t  GetNChipsPerStave(Int_t lay)                                   const {return fNChipsPerStave[lay];}
63   Int_t  GetNChipsPerLayer(Int_t lay)                                   const {return fNChipsPerLayer[lay];}
64   Int_t  GetNModules(Int_t lay)                                         const {return fNModules[lay];}
65   Int_t  GetNHalfStaves(Int_t lay)                                      const {return fNHalfStaves[lay];}
66   Int_t  GetNStaves(Int_t lay)                                          const {return fNStaves[lay];}
67   Int_t  GetNLayers()                                                   const {return fNLayers;}
68   
69   Int_t  GetChipIndex(Int_t lay,int detInLay)                           const {return GetFirstChipIndex(lay)+detInLay;}
70   Int_t  GetChipIndex(Int_t lay,Int_t sta,Int_t detInSta)               const;
71   Int_t  GetChipIndex(Int_t lay,Int_t sta, Int_t subSta, Int_t detInSubSta) const;
72   Int_t  GetChipIndex(Int_t lay,Int_t sta, Int_t subSta, Int_t md, Int_t detInMod) const;
73   Bool_t GetChipId(Int_t index,Int_t &lay,Int_t &sta,Int_t &ssta,Int_t &mod,Int_t &chip)        const;
74   Int_t  GetLayer(Int_t index)                                          const;
75   Int_t  GetStave(Int_t index)                                          const;
76   Int_t  GetHalfStave(Int_t index)                                      const;
77   Int_t  GetModule(Int_t index)                                         const;
78   Int_t  GetChipIdInLayer(Int_t index)                                  const;
79   Int_t  GetChipIdInStave(Int_t index)                                  const;
80   Int_t  GetChipIdInHalfStave(Int_t index)                              const;
81   Int_t  GetChipIdInModule(Int_t index)                                 const;
82   //
83   Int_t  GetLastChipIndex(Int_t lay)                                       const {return fLastChipIndex[lay];}
84   Int_t  GetFirstChipIndex(Int_t lay)                                      const {return (lay==0) ? 0:fLastChipIndex[lay-1]+1;}
85   //  
86   const char *GetSymName(Int_t index)                                     const;
87   const char *GetSymName(Int_t lay,Int_t sta,Int_t det)                   const;
88   //
89   // Attention: these are the matrices for the alignable volumes of the chips, i.e. not necessarily the sensors
90   TGeoHMatrix* GetMatrix(Int_t index)                                     const;
91   TGeoHMatrix* GetMatrix(Int_t lay,Int_t sta,Int_t det)                   const;
92   Bool_t GetTranslation(Int_t index, Double_t t[3])                       const;
93   Bool_t GetTranslation(Int_t lay,Int_t sta,Int_t det, Double_t t[3])     const;
94   Bool_t GetRotation(Int_t index, Double_t r[9])                          const;
95   Bool_t GetRotation(Int_t lay,Int_t sta,Int_t det, Double_t r[9])        const;
96   Bool_t GetOrigMatrix(Int_t index, TGeoHMatrix &m)                       const;
97   Bool_t GetOrigMatrix(Int_t lay,Int_t sta,Int_t det, TGeoHMatrix &m)     const;
98   Bool_t GetOrigTranslation(Int_t index, Double_t t[3])                   const;
99   Bool_t GetOrigTranslation(Int_t lay,Int_t sta,Int_t det, Double_t t[3]) const;
100   Bool_t GetOrigRotation(Int_t index, Double_t r[9])                      const;
101   Bool_t GetOrigRotation(Int_t lay,Int_t sta,Int_t det, Double_t r[9])    const;
102   //
103   const TGeoHMatrix* GetMatrixT2L(Int_t index);
104   const TGeoHMatrix* GetMatrixT2L(Int_t lay,Int_t sta,Int_t det)  {return GetMatrixT2L( GetChipIndex(lay,sta,det) );}
105   const TGeoHMatrix* GetMatrixSens(Int_t index);
106   const TGeoHMatrix* GetMatrixSens(Int_t lay,Int_t sta,Int_t det) {return GetMatrixSens( GetChipIndex(lay,sta,det) );}
107   //
108   Bool_t GetTrackingMatrix(Int_t index, TGeoHMatrix &m);
109   Bool_t GetTrackingMatrix(Int_t lay,Int_t sta,Int_t det, TGeoHMatrix &m);
110   //
111   // Attention: these are transformations wrt sensitive volume!
112   void   LocalToGlobal(Int_t index, const Double_t *loc, Double_t *glob);
113   void   LocalToGlobal(Int_t lay, Int_t sta, Int_t det,const Double_t *loc, Double_t *glob);
114   //
115   void   GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc);
116   void   GlobalToLocal(Int_t lay, Int_t sta, Int_t det,const Double_t *glob, Double_t *loc);
117   //
118   void   LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob);
119   void   GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc);
120   Int_t  GetLayerChipTypeID(Int_t lr)                                         const;
121   Int_t  GetChipChipTypeID(Int_t id)                                        const;
122   //
123   const AliITSsegmentation* GetSegmentationByID(Int_t id)                    const;
124   const AliITSsegmentation* GetSegmentation(Int_t lr)                        const;
125   TObjArray*          GetSegmentations()                                     const {return (TObjArray*)fSegm;}
126   virtual void Print(Option_t *opt="")  const;
127   //
128   static      UInt_t GetUIDShift()                                      {return fgUIDShift;}
129   static      void   SetUIDShift(UInt_t s=16)                           {fgUIDShift = s<16 ? s:16;}
130   //
131   static const char* GetITSVolPattern()                                 {return fgITSVolName.Data();}
132   static const char* GetITSLayerPattern()                               {return fgITSLrName.Data();}
133   static const char* GetITSWrapVolPattern()                             {return fgITSWrapVolName.Data();}
134   static const char* GetITSStavePattern()                               {return fgITSStaveName.Data();}
135   static const char* GetITSHalfStavePattern()                           {return fgITSHalfStaveName.Data();}
136   static const char* GetITSModulePattern()                              {return fgITSModuleName.Data();}
137   static const char* GetITSChipPattern()                                {return fgITSChipName.Data();}
138   static const char* GetITSSensorPattern()                              {return fgITSSensName.Data();}
139   static const char* GetITSsegmentationFileName()                       {return fgITSsegmFileName.Data();}
140   static const char* GetChipTypeName(Int_t i);
141
142   static void        SetITSVolPattern(const char* nm)                   {fgITSVolName = nm;}
143   static void        SetITSLayerPattern(const char* nm)                 {fgITSLrName = nm;}
144   static void        SetITSWrapVolPattern(const char* nm)               {fgITSWrapVolName = nm;}
145   static void        SetITSStavePattern(const char* nm)                 {fgITSStaveName = nm;}
146   static void        SetITSHalfStavePattern(const char* nm)             {fgITSHalfStaveName = nm;}
147   static void        SetITSModulePattern(const char* nm)                {fgITSModuleName = nm;}
148   static void        SetITSChipPattern(const char* nm)                  {fgITSChipName = nm;}
149   static void        SetITSSensorPattern(const char* nm)                {fgITSSensName = nm;}
150   static void        SetChipTypeName(Int_t i,const char* nm);
151   static void        SetITSsegmentationFileName(const char* nm)         {fgITSsegmFileName = nm;}
152   static UInt_t      ComposeChipTypeID(UInt_t segmId);
153   //
154   static const char *ComposeSymNameITS();
155   static const char *ComposeSymNameLayer(Int_t lr);
156   static const char *ComposeSymNameStave(Int_t lr, Int_t sta);
157   static const char *ComposeSymNameHalfStave(Int_t lr, Int_t sta, Int_t ssta);
158   static const char *ComposeSymNameModule(Int_t lr, Int_t sta, Int_t ssta, Int_t mod);
159   static const char *ComposeSymNameChip(Int_t lr, Int_t sta, Int_t ssta, Int_t mod, Int_t chip);
160   //
161   // hack to avoid using AliGeomManager
162   Int_t              LayerToVolUID(Int_t lay,int detInLay)        const {return ChipVolUID(GetChipIndex(lay,detInLay));}
163   static Int_t       ChipVolUID(Int_t mod)                            {return (mod&0xffff)<<fgUIDShift;}
164   //
165  protected:
166   void         FetchMatrices();
167   void         CreateT2LMatrices();
168   TGeoHMatrix* ExtractMatrixT2L(Int_t index)                      const;
169   TGeoHMatrix* ExtractMatrixSens(Int_t index)                     const;
170   Bool_t       GetLayer(Int_t index,Int_t &lay,Int_t &index2)     const;
171   TGeoPNEntry* GetPNEntry(Int_t index)                            const;
172   Int_t        ExtractNChipsPerModule(Int_t lay, Int_t &nrow)     const;
173   Int_t        ExtractNumberOfStaves(Int_t lay)                   const;
174   Int_t        ExtractNumberOfHalfStaves(Int_t lay)               const;
175   Int_t        ExtractNumberOfModules(Int_t lay)                  const;
176   Int_t        ExtractLayerChipType(Int_t lay)                    const;
177   Int_t        ExtractNumberOfLayers();
178   void         BuildITS(Bool_t loadSegm);
179   //
180  protected:
181   //
182   //
183   Int_t  fVersion;             // ITS Version 
184   Int_t  fNLayers;             // number of layers
185   Int_t  fNChips;              // The total number of chips
186   Int_t *fNStaves;             //[fNLayers] Array of the number of staves/layer(layer)
187   Int_t *fNHalfStaves;         //[fNLayers] Array of the number of substaves/stave(layer)
188   Int_t *fNModules;            //[fNLayers] Array of the number of modules/substave(layer)
189   Int_t *fNChipsPerModule;     //[fNLayers] Array of the number of chips per module (group of chips on the substaves)
190   Int_t *fNChipRowsPerModule;  //[fNLayers] Array of the number of chips rows per module (relevant for OB modules)
191   Int_t *fNChipsPerHalfStave;  //[fNLayers] Array of the number of chips per substave
192   Int_t *fNChipsPerStave;      //[fNLayers] Array of the number of chips per stave
193   Int_t *fNChipsPerLayer;      //[fNLayers] Array of the number of chips per stave
194
195   //
196   Int_t *fLrChipType;          //[fNLayers] Array of layer chip types
197   Int_t *fLastChipIndex;       //[fNLayers] max ID of the detctor in the layer
198   Char_t fLr2Wrapper[AliITSUAux::kMaxLayers]; // layer -> wrapper correspondence
199   //
200   TObjArray* fMatSens;         // Sensor's matrices pointers in the geometry
201   TObjArray* fMatT2L;          // Tracking to Local matrices pointers in the geometry
202   TObjArray* fSegm;            // segmentations
203   //
204   static UInt_t   fgUIDShift;               // bit shift to go from mod.id to modUUID for TGeo
205   static TString  fgITSVolName;             // ITS mother volume name
206   static TString  fgITSLrName;              // ITS Layer name
207   static TString  fgITSStaveName;           // ITS Stave name 
208   static TString  fgITSHalfStaveName;       // ITS HalfStave name 
209   static TString  fgITSModuleName;          // ITS Module name 
210   static TString  fgITSChipName;            // ITS Chip name 
211   static TString  fgITSSensName;            // ITS Sensor name 
212   static TString  fgITSWrapVolName;         // ITS Wrapper volume name 
213   static TString  fgITSChipTypeName[kNChipTypes]; // ITS upg detType Names
214   //
215   static TString  fgITSsegmFileName;         // file name for segmentations
216   //
217   ClassDef(AliITSUGeomTGeo, 2) // ITS geometry based on TGeo
218 };
219
220 //_____________________________________________________________________________________________
221 inline const char *AliITSUGeomTGeo::GetSymName(Int_t lay,Int_t sta,Int_t det) const    
222 {
223   // sym name
224   return GetSymName(GetChipIndex(lay,sta,det));
225 }
226
227 //_____________________________________________________________________________________________
228 inline TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t lay,Int_t sta,Int_t det) const    
229 {
230   // chip current matrix
231   return GetMatrix(GetChipIndex(lay,sta,det));
232 }
233
234 //_____________________________________________________________________________________________
235 inline Bool_t AliITSUGeomTGeo::GetTranslation(Int_t lay,Int_t sta,Int_t det, Double_t t[3]) const    
236 {
237   // translation
238   return GetTranslation(GetChipIndex(lay,sta,det),t); 
239 }
240
241 //_____________________________________________________________________________________________
242 inline Bool_t AliITSUGeomTGeo::GetRotation(Int_t lay,Int_t sta,Int_t det, Double_t r[9]) const    
243 {
244   // rot
245   return GetRotation(GetChipIndex(lay,sta,det),r); 
246 }
247
248 //_____________________________________________________________________________________________
249 inline Bool_t AliITSUGeomTGeo::GetOrigMatrix(Int_t lay,Int_t sta,Int_t det, TGeoHMatrix &m) const    
250 {
251   // orig matrix
252   return GetOrigMatrix(GetChipIndex(lay,sta,det),m); 
253 }
254
255 //_____________________________________________________________________________________________
256 inline Bool_t AliITSUGeomTGeo::GetOrigTranslation(Int_t lay,Int_t sta,Int_t det, Double_t t[3]) const    
257 {
258   // orig trans
259   return GetOrigTranslation(GetChipIndex(lay,sta,det),t); 
260 }
261
262 //_____________________________________________________________________________________________
263 inline Bool_t AliITSUGeomTGeo::GetOrigRotation(Int_t lay,Int_t sta,Int_t det, Double_t r[9]) const    
264 {
265   // orig rot
266   return GetOrigRotation(GetChipIndex(lay,sta,det),r); 
267 }
268
269 //_____________________________________________________________________________________________
270 inline Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t lay,Int_t sta,Int_t det, TGeoHMatrix &m)
271 {
272   // tracking mat
273   return GetTrackingMatrix(GetChipIndex(lay,sta,det),m); 
274 }
275
276 //_____________________________________________________________________________________________
277 inline Int_t  AliITSUGeomTGeo::GetLayerChipTypeID(Int_t lr) const  
278 {
279   // detector type ID of layer
280   return fLrChipType[lr];
281 }
282
283 //_____________________________________________________________________________________________
284 inline Int_t  AliITSUGeomTGeo::GetChipChipTypeID(Int_t id) const  
285 {
286   // detector type ID of chip
287   return GetLayerChipTypeID(GetLayer(id));
288
289
290 //_____________________________________________________________________________________________
291 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixSens(Int_t index)
292 {
293   // access global to sensor matrix
294   if (!fMatSens) FetchMatrices();
295   return (TGeoHMatrix*)fMatSens->At(index);
296 }
297
298 //_____________________________________________________________________________________________
299 inline const TGeoHMatrix* AliITSUGeomTGeo::GetMatrixT2L(Int_t index)
300 {
301   // access tracking to local matrix
302   if (!fMatT2L) FetchMatrices();
303   return (TGeoHMatrix*)fMatT2L->At(index);
304 }
305
306 //______________________________________________________________________
307 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t index,const Double_t *loc, Double_t *glob)
308 {
309   // sensor local to global 
310   GetMatrixSens(index)->LocalToMaster(loc,glob);
311 }
312
313 //______________________________________________________________________
314 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t index, const Double_t *glob, Double_t *loc)
315 {
316   // global to sensor local 
317   GetMatrixSens(index)->MasterToLocal(glob,loc);
318 }
319
320 //______________________________________________________________________
321 inline void AliITSUGeomTGeo::LocalToGlobalVect(Int_t index, const Double_t *loc, Double_t *glob)
322 {
323   // sensor local to global 
324   GetMatrixSens(index)->LocalToMasterVect(loc,glob);
325 }
326
327 //______________________________________________________________________
328 inline void AliITSUGeomTGeo::GlobalToLocalVect(Int_t index, const Double_t *glob, Double_t *loc)
329 {
330   // global to sensor local
331   GetMatrixSens(index)->MasterToLocalVect(glob,loc);
332 }
333
334 //_____________________________________________________________________________________________
335 inline void AliITSUGeomTGeo::LocalToGlobal(Int_t lay, Int_t sta, Int_t det,const Double_t *loc, Double_t *glob)
336 {
337   // Local2Master (sensor)
338   LocalToGlobal(GetChipIndex(lay,sta,det), loc, glob);
339 }
340
341 //_____________________________________________________________________________________________
342 inline void AliITSUGeomTGeo::GlobalToLocal(Int_t lay, Int_t sta, Int_t det,const Double_t *glob, Double_t *loc)
343 {
344   // master2local (sensor)
345   GlobalToLocal(GetChipIndex(lay,sta,det), glob, loc);
346 }
347
348 //_____________________________________________________________________________________________
349 inline const char* AliITSUGeomTGeo::GetChipTypeName(Int_t i)
350 {
351   if (i>=kNChipTypes) i/=kMaxSegmPerChipType; // full type is provided
352   return fgITSChipTypeName[i].Data();
353 }
354
355 //_____________________________________________________________________________________________
356 inline void AliITSUGeomTGeo::SetChipTypeName(Int_t i, const char* nm)
357 {
358   if (i>=kNChipTypes) i/=kMaxSegmPerChipType; // full type is provided
359   fgITSChipTypeName[i] = nm;
360 }
361
362 //_____________________________________________________________________________________________
363 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentationByID(Int_t id) const 
364 {
365   // get segmentation by ID
366   return fSegm ? (AliITSsegmentation*)fSegm->At(id) : 0;
367 }
368
369 //_____________________________________________________________________________________________
370 inline const AliITSsegmentation* AliITSUGeomTGeo::GetSegmentation(Int_t lr) const 
371 {
372   // get segmentation of layer
373   return fSegm ? (AliITSsegmentation*)fSegm->At( GetLayerChipTypeID(lr) ) : 0;
374 }
375
376 #endif