]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSgeom.h
Modifications for short tracks afterburner. RecoParams regenerated (in itsupcdb.tar.gz)
[u/mrichter/AliRoot.git] / ITS / AliITSgeom.h
1 #ifndef ALIITSGEOM_H
2 #define ALIITSGEOM_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 /////////////////////////////////////////////////////////////////////////
9 //  ITS geometry manipulation routines.
10 //  Created April 15 1999.
11 //  version: 0.0.0
12 //  By: Bjorn S. Nilsen
13 //
14 //     A package of geometry routines to do transformations between
15 // local, detector active area, and ALICE global coordinate system in such
16 // a way as to allow for detector alignment studies and the like. All of
17 // the information needed to do the coordinate transformation are kept in
18 // a specialized structure for ease of implementation.
19 /////////////////////////////////////////////////////////////////////////
20 #include <Riostream.h>
21 #include <TObject.h>
22 #include <TObjArray.h>
23 #include <TVector.h>
24 #include <TString.h>
25 #include <TArrayI.h>
26 #include <TMath.h>
27 //
28 #include "AliITSgeomMatrix.h"
29 #include "AliLog.h"
30
31 typedef enum {kND=-1,kSPD=0, kSDD=1, kSSD=2, kSSDp=3,kSDDp=4, kUPG=5} AliITSDetector;
32
33 //_______________________________________________________________________
34
35 class AliITSgeom : public TObject {
36
37  public:
38     AliITSgeom();                      // Default constructor
39     AliITSgeom(Int_t itype,Int_t nlayers,const Int_t *nlads,const Int_t *ndets,
40                Int_t nmods); // Constructor
41     AliITSgeom(const AliITSgeom &source);    // Copy constructor
42     AliITSgeom& operator=(const AliITSgeom &source);// = operator
43     virtual ~AliITSgeom();             // Default destructor
44     // Zero and reinitilizes this class.
45     void Init(Int_t itype,Int_t nlayers,const Int_t *nlads,
46               const Int_t *ndets,Int_t mods);
47     // this function allocates a AliITSgeomMatrix for a particular module.
48     void CreateMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
49                       AliITSDetector idet,const Double_t tran[3],
50                       const Double_t rot[10]);
51     // Getters
52     Int_t GetTransformationType() const {return fTrans;}
53     //
54     // returns kTRUE if the transformation defined by this class is
55     // for Global GEANT coordinate system to the local GEANT coordinate system
56     // of the detector. These are the transformation used by GEANT.
57     Bool_t IsGeantToGeant()     const {return (fTrans == 0);}
58     // returns kTRUE if the transformation defined by this class is
59     // for Global GEANT coordinate system to the local "Tracking" coordinate
60     // system of the detector. These are the transformation used by the
61     // Tracking code.
62     Bool_t IsGeantToTracking()  const {return ((fTrans&0xfffe)!= 0);}
63     // returns kTRUE if the transformation defined by this class is
64     // for Global GEANT coordinate system to the local GEANT coordinate system
65     // of the detector but may have been displaced by some typically small
66     // amount. These are modified transformation similar to that used by GEANT.
67     Bool_t IsGeantToDisplaced() const {return ((fTrans&0xfffd)!= 0);}
68     //
69     //     This function returns a pointer to the particular AliITSgeomMatrix
70     // class for a specific module index.
71     AliITSgeomMatrix *GetGeomMatrix(Int_t index){if(index<fGm.GetSize()&&index>=0)
72         return (AliITSgeomMatrix*)(fGm.At(index));else 
73             Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
74     AliITSgeomMatrix *GetGeomMatrix(Int_t index)const{if(index<fGm.GetSize()&&index>=0)
75         return (AliITSgeomMatrix*)(fGm.At(index));else 
76             Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
77     // This function find and return the number of detector types only.
78     Int_t GetNDetTypes()const{Int_t max;return GetNDetTypes(max);};
79     // This function find and return the number of detector types and the
80     // maximum det type value.
81     Int_t GetNDetTypes(Int_t &max)const;
82     // This function finds and return the number of detector types and the
83     // and the number of each type in the TArrayI and their types.
84     Int_t GetNDetTypes(TArrayI &maxs,AliITSDetector *types)const;
85     //     This function returns the number of detectors/ladder for a give 
86     // layer. In particular it returns fNdet[layer-1].
87     Int_t GetNdetectors(Int_t lay) const {return fNdet[lay-1];}
88     //     This function returns the number of ladders for a give layer. In
89     // particular it returns fNlad[layer-1].
90     Int_t GetNladders(Int_t lay)   const {return fNlad[lay-1];};
91     //     This function returns the number of layers defined in the ITS
92     // geometry. In particular it returns fNlayers.
93     Int_t GetNlayers()                   const {return fNlayers;}
94     Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det)const;
95     //     This function returns the module index number given the layer,
96     // ladder and detector numbers put into the array id[3].
97     Int_t GetModuleIndex(const Int_t *id)const{
98         return GetModuleIndex(id[0],id[1],id[2]);}
99     void  GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det)const;
100     // Returns the detector type
101     //Int_t GetModuleType(Int_t index)const{
102     //    return GetGeomMatrix(index)->GetDetectorIndex();}
103     AliITSDetector GetModuleType(Int_t index)const{
104         return (AliITSDetector)(GetGeomMatrix(index)->GetDetectorIndex());}
105     // Returns the detector type as a string
106     const char * GetModuleTypeName(Int_t index)const{
107         return GetDetectorTypeName(GetModuleType(index));} 
108     // Returns the detector type as a string
109     const char * GetDetectorTypeName(Int_t index)const{switch(index) {
110     case kSPD : return "kSPD" ; case kSDD : return "kSDD" ;
111     case kSSD : return "kSSD" ; case kSSDp: return "kSSDp";
112     case kSDDp: return "kSDDp"; default   : return "Undefined";};}
113     //
114     Int_t GetStartDet(Int_t dtype )const;
115     Int_t GetLastDet(Int_t dtype)const;
116     //     Returns the starting module index number for SPD detector,
117     // assuming the modules are placed in the "standard" cylindrical
118     // ITS structure.
119     Int_t GetStartSPD()const{return GetStartDet(kSPD);}
120     //     Returns the ending module index number for SPD detector,
121     // assuming the modules are placed in the "standard" cylindrical
122     // ITS structure.
123     Int_t GetLastSPD()const{return GetLastDet(kSPD);}
124     //     Returns the starting module index number for SDD detector,
125     // assuming the modules are placed in the "standard" cylindrical
126     // ITS structure.
127     Int_t GetStartSDD()const{return GetStartDet(kSDD);}
128     //     Returns the ending module index number for SDD detector,
129     // assuming the modules are placed in the "standard" cylindrical
130     // ITS structure.
131     Int_t GetLastSDD()const{return GetLastDet(kSDD);}
132     //     Returns the starting module index number for SSD detector,
133     // assuming the modules are placed in the "standard" cylindrical
134     // ITS structure.
135     Int_t GetStartSSD()const{return GetStartDet(kSSD);}
136     //     Returns the ending module index number for SSD detector,
137     // assuming the modules are placed in the "standard" cylindrical
138     // ITS structure.
139     Int_t GetLastSSD()const{return GetLastDet(kSSD);}
140     //     Returns the last module index number.
141     Int_t GetIndexMax() const {return fNmodules;}
142     //
143     //     This function returns the rotation angles for a give module 
144     // in the Double point array ang[3]. The angles are in radians
145     void  GetAngles(Int_t index,Double_t *ang)const{
146         GetGeomMatrix(index)->GetAngles(ang);}
147     //     This function returns the rotation angles for a give module
148     // in the three floating point variables provided. rx = frx,
149     // fy = fry, rz = frz. The angles are in radians
150     void  GetAngles(Int_t index,Float_t &rx,Float_t &ry,Float_t &rz)const{
151         Double_t a[3];GetAngles(index,a);rx = a[0];ry = a[1];rz = a[2];}
152     //     This function returns the rotation angles for a give detector on
153     // a give ladder in a give layer in the three floating point variables
154     // provided. rx = frx, fy = fry, rz = frz. The angles are in radians
155     void  GetAngles(Int_t lay,Int_t lad,Int_t det,
156                     Float_t &rx,Float_t &ry,Float_t &rz)const{
157         GetAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
158     //
159     //     This function returns the 6 GEANT rotation angles for a give 
160     // module in the double point array ang[3]. The angles are in degrees
161     void  GetGeantAngles(Int_t index,Double_t *ang)const{
162         GetGeomMatrix(index)->SixAnglesFromMatrix(ang);}
163     //
164     //     This function returns the Cartesian translation for a give
165     // module in the Double array t[3]. The units are
166     // those of the Monte Carlo, generally cm.
167     void  GetTrans(Int_t index,Double_t *t)const{
168         GetGeomMatrix(index)->GetTranslation(t);}
169     //     This function returns the Cartesian translation for a give
170     // module index in the three floating point variables provided.
171     // x = fx0, y = fy0, z = fz0. The units are those of the Mont
172     // Carlo, generally cm.
173     void  GetTrans(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
174         Double_t t[3];GetTrans(index,t);x = t[0];y = t[1];z = t[2];}
175     //     This function returns the Cartesian translation for a give
176     // detector on a give ladder in a give layer in the three floating
177     // point variables provided. x = fx0, y = fy0, z = fz0. The units are
178     // those of the Monte Carlo, generally cm.
179     void  GetTrans(Int_t lay,Int_t lad,Int_t det,
180                    Float_t &x,Float_t &y,Float_t &z)const{
181         GetTrans(GetModuleIndex(lay,lad,det),x,y,z);}
182     //
183     //     This function returns the Cartesian translation for a give
184     // module in the Double array t[3]. The units are
185     // those of the Monte Carlo, generally cm.
186     void  GetTransCyln(Int_t index,Double_t *t)const{
187         GetGeomMatrix(index)->GetTranslationCylinderical(t);}
188     //     This function returns the Cartesian translation for a give
189     // module index in the three floating point variables provided.
190     // x = fx0, y = fy0, z = fz0. The units are those of the Mont
191     // Carlo, generally cm.
192     void  GetTransCyln(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
193         Double_t t[3];GetTransCyln(index,t);x = t[0];y = t[1];z = t[2];}
194     //     This function returns the Cartesian translation for a give
195     // detector on a give ladder in a give layer in the three floating
196     // point variables provided. x = fx0, y = fy0, z = fz0. The units are
197     // those of the Monte Carlo, generally cm.
198     void  GetTransCyln(Int_t lay,Int_t lad,Int_t det,
199                        Float_t &x,Float_t &y,Float_t &z)const{
200         GetTransCyln(GetModuleIndex(lay,lad,det),x,y,z);}
201     //
202     //      This function returns the Cartesian translation [cm] and the
203     // 6 GEANT rotation angles [degrees]for a given layer ladder and
204     // detector number, in the TVector x (at least 9 elements large).
205     // This function is required to be in-lined for speed.
206     void  GetCenterThetaPhi(Int_t lay,Int_t lad,Int_t det,TVector &x)const{
207         Double_t t[3],a[6];Int_t i=GetModuleIndex(lay,lad,det);GetTrans(i,t);
208         GetGeantAngles(i,a);x(0)=t[0];x(1)=t[1];x(2)=t[2];x(3)=a[0];x(4)=a[1];
209         x(5)=a[2];x(6)=a[3];x(7)=a[4];x(8)=a[5];}
210     //
211     //     This function returns the rotation matrix in Double
212     // precision for a given module.
213     void  GetRotMatrix(Int_t index,Double_t mat[3][3])const{
214         GetGeomMatrix(index)->GetMatrix(mat);}
215     //     This function returns the rotation matrix in a Double
216     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
217     void  GetRotMatrix(Int_t index,Double_t *mat)const{
218         Double_t rot[3][3];GetRotMatrix(index,rot);
219         for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
220     //     This function returns the rotation matrix in a floating 
221     // precision pointer for a given layer ladder and detector module.
222     // mat[i][j] => mat[3*i+j].
223     void  GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Float_t *mat)const{
224         GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
225     //     This function returns the rotation matrix in a Double
226     // precision pointer for a given layer ladder and detector module.
227     // mat[i][j] => mat[3*i+j].
228     void  GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Double_t *mat)const{
229         GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
230     //     This function returns the rotation matrix in a floating
231     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
232     void  GetRotMatrix(Int_t index,Float_t *mat)const{
233           Double_t rot[3][3];
234           GetGeomMatrix(index)->GetMatrix(rot);
235           for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
236     //     This function sets the rotation matrix in a Double
237     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
238     void  SetRotMatrix(Int_t index,const Double_t *mat){Double_t rot[3][3];
239           for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) rot[i][j]=mat[3*i+j];
240           GetGeomMatrix(index)->SetMatrix(rot);}
241     // Return the normal for a specific module
242     void GetGlobalNormal(Int_t index,Double_t n[3]){
243         GetGeomMatrix(index)->GetGlobalNormal(n[0],n[1],n[2]);}
244     //
245     //
246     //  Setters
247     //     Sets the rotation angles and matrix for a give module index
248     // via the double precision array a[3] [radians].
249     void SetByAngles(Int_t index,const Double_t a[]){
250         GetGeomMatrix(index)->SetAngles(a);}
251     //     Sets the rotation angles and matrix for a give module index
252     // via the 3 floating precision variables rx, ry, and rz [radians].
253     void SetByAngles(Int_t index,Float_t rx, Float_t ry, Float_t rz) {
254         Double_t a[3];a[0] = rx;a[1] = ry;a[2] = rz;
255         GetGeomMatrix(index)->SetAngles(a);}
256     //     Sets the rotation angles and matrix for a give layer, ladder,
257     // and detector numbers via the 3 floating precision variables rx,
258     // ry, and rz [radians].
259     void SetByAngles(Int_t lay,Int_t lad,Int_t det,
260                      Float_t rx, Float_t ry, Float_t rz) {
261         SetByAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
262     //
263     //     Sets the rotation angles and matrix for a give module index
264     // via the Double precision array a[6] [degree]. The angles are those
265     // defined by GEANT 3.12.
266     void SetByGeantAngles(Int_t index,const Double_t *ang){
267         GetGeomMatrix(index)->MatrixFromSixAngles(ang);}
268     //     Sets the rotation angles and matrix for a give layer, ladder
269     // and detector, in the array id[3] via the Double precision array
270     // a[6] [degree]. The angles are those defined by GEANT 3.12.
271     void SetByGeantAngles(const Int_t *id,const Double_t *ang){
272         SetByGeantAngles(GetModuleIndex(id),ang);}
273     //     Sets the rotation angles and matrix for a give layer, ladder
274     // and detector, via the Double precision array a[6] [degree]. The
275     // angles are those defined by GEANT 3.12.
276     void SetByGeantAngles(Int_t lay,Int_t lad,Int_t det,
277                           const Double_t *ang){
278         SetByGeantAngles(GetModuleIndex(lay,lad,det),ang);}
279     //
280     //     This function sets a new translation vector, given by the
281     // array x[3], for the Cartesian coordinate transformation
282     // for a give module index.
283     void SetTrans(Int_t index,Double_t x[]){
284         GetGeomMatrix(index)->SetTranslation(x);}
285     //     This function sets a new translation vector, given by the three
286     // variables x, y, and z, for the Cartesian coordinate transformation
287     // for the detector defined by layer, ladder and detector.
288     void SetTrans(Int_t lay,Int_t lad,Int_t det,
289                   Float_t x,Float_t y,Float_t z){Double_t t[3];
290                   t[0] = x;t[1] = y;t[2] = z;
291                   SetTrans(GetModuleIndex(lay,lad,det),t);}
292     //
293     //  transformations
294     //     Transforms from the ALICE Global coordinate system
295     // to the detector local coordinate system for the detector
296     // defined by the layer, ladder, and detector numbers. The
297     // global and local coordinate are given in two floating point
298     // arrays g[3], and l[3].
299     void GtoL(Int_t lay,Int_t lad,Int_t det,
300               const Float_t *g,Float_t *l)const{
301         GtoL(GetModuleIndex(lay,lad,det),g,l);}
302     //     Transforms from the ALICE Global coordinate system
303     // to the detector local coordinate system for the detector
304     // defined by the id[0], id[1], and id[2] numbers. The
305     // global and local coordinate are given in two floating point
306     // arrays g[3], and l[3].
307     void GtoL(const Int_t *id,const Float_t *g,Float_t *l)const{
308         GtoL(GetModuleIndex(id),g,l);}
309     //     Transforms from the ALICE Global coordinate system
310     // to the detector local coordinate system for the detector
311     // module index number. The global and local coordinate are
312     // given in two floating point arrays g[3], and l[3].
313     void GtoL(Int_t index,const Float_t *g,Float_t *l)const{
314         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
315         GetGeomMatrix(index)->GtoLPosition(dg,dl);
316         for(i=0;i<3;i++) l[i] =dl[i];}
317     //     Transforms from the ALICE Global coordinate system
318     // to the detector local coordinate system for the detector
319     // defined by the layer, ladder, and detector numbers. The
320     // global and local coordinate are given in two Double point
321     // arrays g[3], and l[3].
322     void GtoL(Int_t lay,Int_t lad,Int_t det,
323               const Double_t *g,Double_t *l)const{
324         GtoL(GetModuleIndex(lay,lad,det),g,l);}
325     //     Transforms from the ALICE Global coordinate system
326     // to the detector local coordinate system for the detector
327     // defined by the id[0], id[1], and id[2] numbers. The
328     // global and local coordinate are given in two Double point
329     // arrays g[3], and l[3].
330     void GtoL(const Int_t *id,const Double_t *g,Double_t *l)const{
331         GtoL(GetModuleIndex(id),g,l);}
332     //     Transforms from the ALICE Global coordinate system
333     // to the detector local coordinate system for the detector
334     // module index number. The global and local coordinate are
335     // given in two Double point arrays g[3], and l[3].
336     void GtoL(Int_t index,const Double_t g[3],Double_t l[3])const{
337         GetGeomMatrix(index)->GtoLPosition(g,l);}
338  
339     //  Find Specific Modules
340     // Locate the nearest module to the point g, in ALICE global Cartesian
341     // coordinates [cm] in a give layer. If layer = 0 then it search in
342     // all layers.
343     Int_t    GetNearest(const Double_t g[3],Int_t lay=0)const;
344     // Locates the nearest 27 modules, in nearest order, to the point g, in
345     // ALICE global Cartesian coordinates [cm] in a give layer. If layer = 0
346     // then it searches in all layers. (there are 27 elements in a 3x3x3
347     // cube.
348     void     GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay=0)const;
349     // Returns the distance [cm] between the point g[3] and the center of
350     // the detector/module specified by the the module index number.
351     Double_t Distance(Int_t index,const Double_t g[3])const{
352         return  TMath::Sqrt(GetGeomMatrix(index)->Distance2(g));}
353     // This routine prints, to a file, the contents of this class.
354     void PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det)const;
355     // This function prints out this class in a single stream. This steam
356     // can be read by ReadGeom.
357     // (Coverity warnings)    void PrintGeom(ostream *out)const;
358
359     //Conversion from det. local coordinates to local ("V2") coordinates
360     //used for tracking
361
362     void DetLToTrackingV2(Int_t md,Float_t xin,Float_t zin,
363                           Float_t &yout, Float_t &zout) const ; 
364
365     void TrackingV2ToDetL(Int_t md,Float_t yin,Float_t zin,
366                           Float_t &xout,Float_t &zout) const ;
367
368  private:
369     TString    fVersion; // Transformation version.
370     Int_t      fTrans;   // Flag to keep track of which transformation 
371     Int_t      fNmodules;// The total number of modules
372     Int_t      fNlayers; // The number of layers.
373     TArrayI    fNlad;    // Array of the number of ladders/layer(layer)
374     TArrayI    fNdet;    // Array of the number of detector/ladder(layer)
375     TObjArray  fGm;      // Structure of translation. and rotation.
376
377     ClassDef(AliITSgeom,4) // ITS geometry class
378 }; 
379 // Input and output function for standard C++ input/output.
380
381 #endif