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