]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSgeom.h
Adding includes required by ROOT
[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
29 #include "AliITSgeomMatrix.h"
30
31 typedef enum {kND=-1,kSPD=0, kSDD=1, kSSD=2, kSSDp=3,kSDDp=4} AliITSDetector;
32
33 //_______________________________________________________________________
34
35 class AliITSgeom : public TObject {
36
37  public:
38     AliITSgeom();                      // Default constructor
39     AliITSgeom(const char *filename);  // Constructor
40     AliITSgeom(Int_t itype,Int_t nlayers,const Int_t *nlads,const Int_t *ndets,
41                Int_t nmods); // Constructor
42     AliITSgeom(const AliITSgeom &source);    // Copy constructor
43     AliITSgeom& operator=(const AliITSgeom &source);// = operator
44     virtual ~AliITSgeom();             // Default destructor
45     // Zero and reinitilizes this class.
46     void Init(Int_t itype,Int_t nlayers,const Int_t *nlads,
47               const Int_t *ndets,Int_t mods);
48     // this function allocates a AliITSgeomMatrix for a particular module.
49     void CreateMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
50                       AliITSDetector idet,const Double_t tran[3],
51                       const Double_t rot[10]);
52     void ReadNewFile(const char *filename);  // Constructor for new format.
53     void WriteNewFile(const char *filename)const; // Output for new format.
54     // Getters
55     Int_t GetTransformationType() const {return fTrans;}
56     //
57     // returns kTRUE if the transformation defined by this class is
58     // for Global GEANT coordinate system to the local GEANT coordinate system
59     // of the detector. These are the transformation used by GEANT.
60     Bool_t IsGeantToGeant()     const {return (fTrans == 0);}
61     // returns kTRUE if the transformation defined by this class is
62     // for Global GEANT coordinate system to the local "Tracking" coordinate
63     // system of the detector. These are the transformation used by the
64     // Tracking code.
65     Bool_t IsGeantToTracking()  const {return ((fTrans&&0xfffe)!= 0);}
66     // returns kTRUE if the transformation defined by this class is
67     // for Global GEANT coordinate system to the local GEANT coordinate system
68     // of the detector but may have been displaced by some typically small
69     // amount. These are modified transformation similar to that used by GEANT.
70     Bool_t IsGeantToDisplaced() const {return ((fTrans&&0xfffd)!= 0);}
71     // returns kTRUE if the shape defined by ishape has been defined in this
72     // set of transformations. Typical values of ishape are kSPD, kSDD, kSSD,
73     // kSSD2.
74     Bool_t IsShapeDefined(Int_t ishape)const {
75         return ((fShape.At(ishape))!=0);}
76     //
77     //     This function returns a pointer to the particular AliITSgeomMatrix
78     // class for a specific module index.
79     AliITSgeomMatrix *GetGeomMatrix(Int_t index){if(index<fGm.GetSize()&&index>=0)
80         return (AliITSgeomMatrix*)(fGm.At(index));else Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
81     AliITSgeomMatrix *GetGeomMatrix(Int_t index)const{if(index<fGm.GetSize()&&index>=0)
82         return (AliITSgeomMatrix*)(fGm.At(index));else Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
83     // This function find and return the number of detector types only.
84     Int_t GetNDetTypes()const{Int_t max;return GetNDetTypes(max);};
85     // This function find and return the number of detector types and the
86     // maximum det type value.
87     Int_t GetNDetTypes(Int_t &max)const;
88     // This function finds and return the number of detector types and the
89     // and the number of each type in the TArrayI and their types.
90     Int_t GetNDetTypes(TArrayI &maxs,AliITSDetector *types)const;
91     //     This function returns the number of detectors/ladder for a give 
92     // layer. In particular it returns fNdet[layer-1].
93     Int_t GetNdetectors(Int_t lay) const {return fNdet[lay-1];}
94     //     This function returns the number of ladders for a give layer. In
95     // particular it returns fNlad[layer-1].
96     Int_t GetNladders(Int_t lay)   const {return fNlad[lay-1];};
97     //     This function returns the number of layers defined in the ITS
98     // geometry. In particular it returns fNlayers.
99     Int_t GetNlayers()                   const {return fNlayers;}
100     Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det)const;
101     //     This function returns the module index number given the layer,
102     // ladder and detector numbers put into the array id[3].
103     Int_t GetModuleIndex(const Int_t *id)const{
104         return GetModuleIndex(id[0],id[1],id[2]);}
105     void  GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det)const;
106     // Returns the detector type
107     //Int_t GetModuleType(Int_t index)const{
108     //    return GetGeomMatrix(index)->GetDetectorIndex();}
109     AliITSDetector GetModuleType(Int_t index)const{
110         return (AliITSDetector)(GetGeomMatrix(index)->GetDetectorIndex());}
111     // Returns the detector type as a string
112     const char * GetModuleTypeName(Int_t index)const{
113         return GetDetectorTypeName(GetModuleType(index));} 
114     // Returns the detector type as a string
115     const char * GetDetectorTypeName(Int_t index)const{switch(index) {
116     case kSPD : return "kSPD" ; case kSDD : return "kSDD" ;
117     case kSSD : return "kSSD" ; case kSSDp: return "kSSDp";
118     case kSDDp: return "kSDDp"; default   : return "Undefined";};}
119     //
120     Int_t GetStartDet(Int_t dtype )const;
121     Int_t GetLastDet(Int_t dtype)const;
122     //     Returns the starting module index number for SPD detector,
123     // assuming the modules are placed in the "standard" cylindrical
124     // ITS structure.
125     Int_t GetStartSPD()const{return GetStartDet(kSPD);}
126     //     Returns the ending module index number for SPD detector,
127     // assuming the modules are placed in the "standard" cylindrical
128     // ITS structure.
129     Int_t GetLastSPD()const{return GetLastDet(kSPD);}
130     //     Returns the starting module index number for SDD detector,
131     // assuming the modules are placed in the "standard" cylindrical
132     // ITS structure.
133     Int_t GetStartSDD()const{return GetStartDet(kSDD);}
134     //     Returns the ending module index number for SDD detector,
135     // assuming the modules are placed in the "standard" cylindrical
136     // ITS structure.
137     Int_t GetLastSDD()const{return GetLastDet(kSDD);}
138     //     Returns the starting module index number for SSD detector,
139     // assuming the modules are placed in the "standard" cylindrical
140     // ITS structure.
141     Int_t GetStartSSD()const{return GetStartDet(kSSD);}
142     //     Returns the ending module index number for SSD detector,
143     // assuming the modules are placed in the "standard" cylindrical
144     // ITS structure.
145     Int_t GetLastSSD()const{return GetLastDet(kSSD);}
146     //     Returns the last module index number.
147     Int_t GetIndexMax() const {return fNmodules;}
148     //
149     //     This function returns the rotation angles for a give module 
150     // in the Double point array ang[3]. The angles are in radians
151     void  GetAngles(Int_t index,Double_t *ang)const{
152         GetGeomMatrix(index)->GetAngles(ang);}
153     //     This function returns the rotation angles for a give module
154     // in the three floating point variables provided. rx = frx,
155     // fy = fry, rz = frz. The angles are in radians
156     void  GetAngles(Int_t index,Float_t &rx,Float_t &ry,Float_t &rz)const{
157         Double_t a[3];GetAngles(index,a);rx = a[0];ry = a[1];rz = a[2];}
158     //     This function returns the rotation angles for a give detector on
159     // a give ladder in a give layer in the three floating point variables
160     // provided. rx = frx, fy = fry, rz = frz. The angles are in radians
161     void  GetAngles(Int_t lay,Int_t lad,Int_t det,
162                     Float_t &rx,Float_t &ry,Float_t &rz)const{
163         GetAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
164     //
165     //     This function returns the 6 GEANT rotation angles for a give 
166     // module in the double point array ang[3]. The angles are in degrees
167     void  GetGeantAngles(Int_t index,Double_t *ang)const{
168         GetGeomMatrix(index)->SixAnglesFromMatrix(ang);}
169     //
170     //     This function returns the Cartesian translation for a give
171     // module in the Double array t[3]. The units are
172     // those of the Monte Carlo, generally cm.
173     void  GetTrans(Int_t index,Double_t *t)const{
174         GetGeomMatrix(index)->GetTranslation(t);}
175     //     This function returns the Cartesian translation for a give
176     // module index in the three floating point variables provided.
177     // x = fx0, y = fy0, z = fz0. The units are those of the Mont
178     // Carlo, generally cm.
179     void  GetTrans(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
180         Double_t t[3];GetTrans(index,t);x = t[0];y = t[1];z = t[2];}
181     //     This function returns the Cartesian translation for a give
182     // detector on a give ladder in a give layer in the three floating
183     // point variables provided. x = fx0, y = fy0, z = fz0. The units are
184     // those of the Monte Carlo, generally cm.
185     void  GetTrans(Int_t lay,Int_t lad,Int_t det,
186                    Float_t &x,Float_t &y,Float_t &z)const{
187         GetTrans(GetModuleIndex(lay,lad,det),x,y,z);}
188     //
189     //     This function returns the Cartesian translation for a give
190     // module in the Double array t[3]. The units are
191     // those of the Monte Carlo, generally cm.
192     void  GetTransCyln(Int_t index,Double_t *t)const{
193         GetGeomMatrix(index)->GetTranslationCylinderical(t);}
194     //     This function returns the Cartesian translation for a give
195     // module index in the three floating point variables provided.
196     // x = fx0, y = fy0, z = fz0. The units are those of the Mont
197     // Carlo, generally cm.
198     void  GetTransCyln(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
199         Double_t t[3];GetTransCyln(index,t);x = t[0];y = t[1];z = t[2];}
200     //     This function returns the Cartesian translation for a give
201     // detector on a give ladder in a give layer in the three floating
202     // point variables provided. x = fx0, y = fy0, z = fz0. The units are
203     // those of the Monte Carlo, generally cm.
204     void  GetTransCyln(Int_t lay,Int_t lad,Int_t det,
205                        Float_t &x,Float_t &y,Float_t &z)const{
206         GetTransCyln(GetModuleIndex(lay,lad,det),x,y,z);}
207     //
208     //      This function returns the Cartesian translation [cm] and the
209     // 6 GEANT rotation angles [degrees]for a given layer ladder and
210     // detector number, in the TVector x (at least 9 elements large).
211     // This function is required to be in-lined for speed.
212     void  GetCenterThetaPhi(Int_t lay,Int_t lad,Int_t det,TVector &x)const{
213         Double_t t[3],a[6];Int_t i=GetModuleIndex(lay,lad,det);GetTrans(i,t);
214         GetGeantAngles(i,a);x(0)=t[0];x(1)=t[1];x(2)=t[2];x(3)=a[0];x(4)=a[1];
215         x(5)=a[2];x(6)=a[3];x(7)=a[4];x(8)=a[5];}
216     //
217     //     This function returns the rotation matrix in Double
218     // precision for a given module.
219     void  GetRotMatrix(Int_t index,Double_t mat[3][3])const{
220         GetGeomMatrix(index)->GetMatrix(mat);}
221     //     This function returns the rotation matrix in a Double
222     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
223     void  GetRotMatrix(Int_t index,Double_t *mat)const{
224         Double_t rot[3][3];GetRotMatrix(index,rot);
225         for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
226     //     This function returns the rotation matrix in a floating 
227     // precision pointer for a given layer ladder and detector module.
228     // mat[i][j] => mat[3*i+j].
229     void  GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Float_t *mat)const{
230         GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
231     //     This function returns the rotation matrix in a Double
232     // precision pointer for a given layer ladder and detector module.
233     // mat[i][j] => mat[3*i+j].
234     void  GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Double_t *mat)const{
235         GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
236     //     This function returns the rotation matrix in a floating
237     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
238     void  GetRotMatrix(Int_t index,Float_t *mat)const{
239           Double_t rot[3][3];
240           GetGeomMatrix(index)->GetMatrix(rot);
241           for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
242     //     This function sets the rotation matrix in a Double
243     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
244     void  SetRotMatrix(Int_t index,Double_t *mat){Double_t rot[3][3];
245           for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) rot[i][j]=mat[3*i+j];
246           GetGeomMatrix(index)->SetMatrix(rot);}
247     //
248     //     Will define fShape if it isn't already defined.
249     void DefineShapes(Int_t size=5){fShape.Expand(size);}
250     //     this function returns a pointer to the array of detector
251     // descriptions, Segmentation.
252     virtual TObjArray *GetShapeArray(){return &fShape;};
253     //     this function returns a pointer to the class describing a particular
254     // detector type based on AliITSDetector value. This will return a pointer
255     // to one of the classes AliITSgeomSPD, AliITSgeomSDD, or 
256     // AliITSgeomSSD, for example.
257     virtual TObject *GetShape(AliITSDetector idet){
258         return fShape.At((Int_t)idet);};
259     virtual TObject *GetShape(AliITSDetector idet)const{
260         return fShape.At((Int_t)idet);};
261     //     This function returns a pointer to the class describing the
262     // detector for a particular module index. This will return a pointer
263     // to one of the classes AliITSgeomSPD, AliITSgeomSDD, 
264     // or AliITSgeomSSD, for example.
265     virtual TObject *GetShape(Int_t index){
266         return fShape.At(GetGeomMatrix(index)->GetDetectorIndex());}
267     virtual TObject *GetShape(Int_t index)const{
268         return fShape.At(GetGeomMatrix(index)->GetDetectorIndex());}
269     //     This function returns a pointer to the class describing the
270     // detector for a particular layer ladder and detector numbers. This
271     // will return a pointer to one of the classes AliITSgeomSPD,
272     // AliITSgeomSDD, or AliITSgeomSSD, for example.
273     virtual TObject *GetShape(Int_t lay,Int_t lad,Int_t det)
274         {return GetShape(GetModuleIndex(lay,lad,det));}
275     //
276     //  Setters
277     //     Sets the rotation angles and matrix for a give module index
278     // via the double precision array a[3] [radians].
279     void SetByAngles(Int_t index,const Double_t a[]){
280         GetGeomMatrix(index)->SetAngles(a);}
281     //     Sets the rotation angles and matrix for a give module index
282     // via the 3 floating precision variables rx, ry, and rz [radians].
283     void SetByAngles(Int_t index,Float_t rx, Float_t ry, Float_t rz) {
284         Double_t a[3];a[0] = rx;a[1] = ry;a[2] = rz;
285         GetGeomMatrix(index)->SetAngles(a);}
286     //     Sets the rotation angles and matrix for a give layer, ladder,
287     // and detector numbers via the 3 floating precision variables rx,
288     // ry, and rz [radians].
289     void SetByAngles(Int_t lay,Int_t lad,Int_t det,
290                      Float_t rx, Float_t ry, Float_t rz) {
291         SetByAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
292     //
293     //     Sets the rotation angles and matrix for a give module index
294     // via the Double precision array a[6] [degree]. The angles are those
295     // defined by GEANT 3.12.
296     void SetByGeantAngles(Int_t index,const Double_t *ang){
297         GetGeomMatrix(index)->MatrixFromSixAngles(ang);}
298     //     Sets the rotation angles and matrix for a give layer, ladder
299     // and detector, in the array id[3] via the Double precision array
300     // a[6] [degree]. The angles are those defined by GEANT 3.12.
301     void SetByGeantAngles(const Int_t *id,const Double_t *ang){
302         SetByGeantAngles(GetModuleIndex(id),ang);}
303     //     Sets the rotation angles and matrix for a give layer, ladder
304     // and detector, via the Double precision array a[6] [degree]. The
305     // angles are those defined by GEANT 3.12.
306     void SetByGeantAngles(Int_t lay,Int_t lad,Int_t det,
307                           const Double_t *ang){
308         SetByGeantAngles(GetModuleIndex(lay,lad,det),ang);}
309     //
310     //     This function sets a new translation vector, given by the
311     // array x[3], for the Cartesian coordinate transformation
312     // for a give module index.
313     void SetTrans(Int_t index,Double_t x[]){
314         GetGeomMatrix(index)->SetTranslation(x);}
315     //     This function sets a new translation vector, given by the three
316     // variables x, y, and z, for the Cartesian coordinate transformation
317     // for the detector defined by layer, ladder and detector.
318     void SetTrans(Int_t lay,Int_t lad,Int_t det,
319                   Float_t x,Float_t y,Float_t z){Double_t t[3];
320                   t[0] = x;t[1] = y;t[2] = z;
321                   SetTrans(GetModuleIndex(lay,lad,det),t);}
322     //
323     //     This function adds one more shape element to the TObjArray
324     // fShape. It is primarily used in the constructor functions of the
325     // AliITSgeom class. The pointer *shape can be the pointer to any
326     // class that is derived from TObject (this is true for nearly every
327     // ROOT class). This does not appear to be working properly at this time.
328     void AddShape(TObject *shp){fShape.AddLast(shp);}
329     //     This function deletes an existing shape element, of type TObject,
330     // and replaces it with the one specified. This is primarily used to
331     // changes the parameters to the geom class for a particular
332     // type of detector.
333     void ReSetShape(Int_t dtype,TObject *shp){
334         delete (fShape.At(dtype));fShape.AddAt(shp,dtype);}
335     //
336     //  transformations
337     //     Transforms from the ALICE Global coordinate system
338     // to the detector local coordinate system for the detector
339     // defined by the layer, ladder, and detector numbers. The
340     // global and local coordinate are given in two floating point
341     // arrays g[3], and l[3].
342     void GtoL(Int_t lay,Int_t lad,Int_t det,
343               const Float_t *g,Float_t *l)const{
344         GtoL(GetModuleIndex(lay,lad,det),g,l);}
345     //     Transforms from the ALICE Global coordinate system
346     // to the detector local coordinate system for the detector
347     // defined by the id[0], id[1], and id[2] numbers. The
348     // global and local coordinate are given in two floating point
349     // arrays g[3], and l[3].
350     void GtoL(const Int_t *id,const Float_t *g,Float_t *l)const{
351         GtoL(GetModuleIndex(id),g,l);}
352     //     Transforms from the ALICE Global coordinate system
353     // to the detector local coordinate system for the detector
354     // module index number. The global and local coordinate are
355     // given in two floating point arrays g[3], and l[3].
356     void GtoL(Int_t index,const Float_t *g,Float_t *l)const{
357         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
358         GetGeomMatrix(index)->GtoLPosition(dg,dl);
359         for(i=0;i<3;i++) l[i] =dl[i];}
360     //     Transforms from the ALICE Global coordinate system
361     // to the detector local coordinate system for the detector
362     // defined by the layer, ladder, and detector numbers. The
363     // global and local coordinate are given in two Double point
364     // arrays g[3], and l[3].
365     void GtoL(Int_t lay,Int_t lad,Int_t det,
366               const Double_t *g,Double_t *l)const{
367         GtoL(GetModuleIndex(lay,lad,det),g,l);}
368     //     Transforms from the ALICE Global coordinate system
369     // to the detector local coordinate system for the detector
370     // defined by the id[0], id[1], and id[2] numbers. The
371     // global and local coordinate are given in two Double point
372     // arrays g[3], and l[3].
373     void GtoL(const Int_t *id,const Double_t *g,Double_t *l)const{
374         GtoL(GetModuleIndex(id),g,l);}
375     //     Transforms from the ALICE Global coordinate system
376     // to the detector local coordinate system for the detector
377     // module index number. The global and local coordinate are
378     // given in two Double point arrays g[3], and l[3].
379     void GtoL(Int_t index,const Double_t g[3],Double_t l[3])const{
380         GetGeomMatrix(index)->GtoLPosition(g,l);}
381     //
382     //     Transforms from the ALICE Global coordinate system
383     // to the detector local coordinate system (used for ITS tracking)
384     // for the detector module index number. The global and local
385     // coordinate are given in two Double point arrays g[3], and l[3].
386     void GtoLtracking(Int_t index,const Double_t *g,Double_t *l)const{
387         if(IsGeantToTracking()) GtoL(index,g,l);
388         else GetGeomMatrix(index)->GtoLPositionTracking(g,l);}
389     //     Transforms from the ALICE Global coordinate system
390     // to the detector local coordinate system (used for ITS tracking)
391     // for the detector id[3]. The global and local
392     // coordinate are given in two Double point arrays g[3], and l[3].
393     void GtoLtracking(const Int_t *id,const Double_t *g,Double_t *l)const{
394         GtoLtracking(GetModuleIndex(id),g,l);}
395     //     Transforms from the ALICE Global coordinate system
396     // to the detector local coordinate system (used for ITS tracking)
397     // for the detector layer ladder and detector numbers. The global
398     // and local coordinate are given in two Double point arrays g[3],
399     // and l[3].
400     void GtoLtracking(Int_t lay,Int_t lad,Int_t det,
401                       const Double_t *g,Double_t *l)const{
402         GtoLtracking(GetModuleIndex(lay,lad,det),g,l);}
403     //
404     //     Transforms of momentum types of quantities from the ALICE
405     // Global coordinate system to the detector local coordinate system
406     // for the detector layer ladder and detector numbers. The global
407     // and local coordinate are given in two float point arrays g[3],
408     // and l[3].
409     void GtoLMomentum(Int_t lay,Int_t lad,Int_t det,
410                       const Float_t *g,Float_t *l)const{
411         GtoLMomentum(GetModuleIndex(lay,lad,det),g,l);}
412     //     Transforms of momentum types of quantities from the ALICE
413     // Global coordinate system to the detector local coordinate system
414     // for the detector module index number. The global and local
415     // coordinate are given in two float point arrays g[3], and l[3].
416     void GtoLMomentum(Int_t index,const Float_t *g,Float_t *l)const{
417         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
418         GetGeomMatrix(index)->GtoLMomentum(dg,dl);
419         for(i=0;i<3;i++) l[i] =dl[i];}
420     //     Transforms of momentum types of quantities from the ALICE
421     // Global coordinate system to the detector local coordinate system
422     // for the detector layer ladder and detector numbers. The global
423     // and local coordinate are given in two Double point arrays g[3],
424     // and l[3].
425     void GtoLMomentum(Int_t lay,Int_t lad,Int_t det,
426                       const Double_t *g,Double_t *l)const{
427         GtoLMomentum(GetModuleIndex(lay,lad,det),g,l);}
428     //     Transforms of momentum types of quantities from the ALICE
429     // Global coordinate system to the detector local coordinate system
430     // for the detector module index number. The global and local
431     // coordinate are given in two Double point arrays g[3], and l[3].
432     void GtoLMomentum(Int_t index,const Double_t *g,Double_t *l)const{
433         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
434         GetGeomMatrix(index)->GtoLMomentum(dg,dl);
435         for(i=0;i<3;i++) l[i] =dl[i];}
436     //
437     //     Transforms of momentum types of quantities from the ALICE
438     // Global coordinate system to the detector local coordinate system
439     // (used for ITS tracking) for the detector module index number.
440     // The global and local coordinate are given in two Double point
441     // arrays g[3], and l[3].
442     void GtoLMomentumTracking(Int_t index,const Double_t *g,Double_t *l)const{
443         if(IsGeantToTracking()) GtoLMomentum(index,g,l);
444         else GetGeomMatrix(index)->GtoLMomentumTracking(g,l);}
445     //     Transforms of momentum types of quantities from the ALICE
446     // Global coordinate system to the detector local coordinate system
447     // (used for ITS tracking) for the detector id[3].
448     // The global and local coordinate are given in two Double point
449     // arrays g[3], and l[3].
450     void GtoLMomentumTracking(const Int_t *id,
451                               const Double_t *g,Double_t *l)const{
452         GtoLMomentumTracking(GetModuleIndex(id),g,l);}
453     //     Transforms of momentum types of quantities from the ALICE
454     // Global coordinate system to the detector local coordinate system
455     // (used for ITS tracking) for the detector layer ladder and detector
456     // numbers. The global and local coordinate are given in two Double point
457     // arrays g[3], and l[3].
458     void GtoLMomentumTracking(Int_t lay,Int_t lad,Int_t det,
459                               const Double_t *g,Double_t *l)const{
460         GtoLMomentumTracking(GetModuleIndex(lay,lad,det),g,l);}
461     //
462     //     Transforms from the detector local coordinate system
463     // to the ALICE Global coordinate  system for the detector
464     // defined by the layer, ladder, and detector numbers. The
465     // global and local coordinate are given in two floating point
466     // arrays g[3], and l[3].
467     void LtoG(Int_t lay,Int_t lad,Int_t det,
468               const Float_t *l,Float_t *g)const{
469         LtoG(GetModuleIndex(lay,lad,det),l,g);}
470     //     Transforms from the detector local coordinate system
471     // to the ALICE Global coordinate system for the detector
472     // defined by the id[0], id[1], and id[2] numbers. The
473     // global and local coordinate are given in two floating point
474     // arrays g[3], and l[3].
475     void LtoG(const Int_t *id,const Float_t *l,Float_t *g)const{
476         LtoG(GetModuleIndex(id),l,g);}
477     //     Transforms from the detector local coordinate system
478     // to the ALICE Global coordinate system for the detector
479     // module index number. The global and local coordinate are
480     // given in two floating point arrays g[3], and l[3].
481     void LtoG(Int_t index,const Float_t *l,Float_t *g)const{
482         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dl[i] = l[i];
483         GetGeomMatrix(index)->LtoGPosition(dl,dg);
484         for(i=0;i<3;i++) g[i] =dg[i];}
485     //     Transforms from the detector local coordinate system
486     // to the ALICE Global coordinate system for the detector
487     // defined by the layer, ladder, and detector numbers. The
488     // global and local coordinate are given in two Double point
489     // arrays g[3], and l[3].
490     void LtoG(Int_t lay,Int_t lad,Int_t det,
491               const Double_t *l,Double_t *g)const{
492         LtoG(GetModuleIndex(lay,lad,det),l,g);}
493     //     Transforms from the detector local coordinate system
494     // to the ALICE Global coordinate system for the detector
495     // defined by the id[0], id[1], and id[2] numbers. The
496     // global and local coordinate are given in two Double point
497     // arrays g[3], and l[3].
498     void LtoG(const Int_t *id,const Double_t *l,Double_t *g)const{
499         LtoG(GetModuleIndex(id),l,g);}
500     //     Transforms from the detector local coordinate system
501     // to the ALICE Global coordinate system for the detector
502     // module index number. The global and local coordinate are
503     // given in two Double point arrays g[3], and l[3].
504     void LtoG(Int_t index,const Double_t *l,Double_t *g)const{
505         GetGeomMatrix(index)->LtoGPosition(l,g);}
506     //
507     //     Transforms from the detector local coordinate system (used
508     // for ITS tracking) to the ALICE Global coordinate system 
509     // for the detector module index number. The global and local
510     // coordinate are given in two Double point arrays g[3], and l[3].
511     void LtoGtracking(Int_t index,const Double_t *l,Double_t *g)const{
512         if(IsGeantToTracking()) LtoG(index,l,g);
513         else GetGeomMatrix(index)->LtoGPositionTracking(l,g);}
514     //     Transforms from the detector local coordinate system (used
515     // for ITS tracking) to the ALICE Global coordinate system 
516     // for the detector id[3]. The global and local
517     // coordinate are given in two Double point arrays g[3], and l[3].
518     void LtoGtracking(const Int_t *id,const Double_t *l,Double_t *g)const{
519         LtoGtracking(GetModuleIndex(id),l,g);}
520     //     Transforms from the detector local coordinate system (used
521     // for ITS tracking) to the detector local coordinate system
522     // for the detector layer ladder and detector numbers. The global
523     // and local coordinate are given in two Double point arrays g[3],
524     // and l[3].
525     void LtoGtracking(Int_t lay,Int_t lad,Int_t det,
526                       const Double_t *l,Double_t *g)const{
527         LtoGtracking(GetModuleIndex(lay,lad,det),l,g);}
528     //
529     //     Transforms of momentum types of quantities from the detector
530     // local coordinate system to the ALICE Global coordinate system
531     // for the detector layer ladder and detector numbers. The global
532     // and local coordinate are given in two float point arrays g[3],
533     // and l[3].
534     void LtoGMomentum(Int_t lay,Int_t lad,Int_t det,
535                       const Float_t *l,Float_t *g)const{
536         LtoGMomentum(GetModuleIndex(lay,lad,det),l,g);}
537     //     Transforms of momentum types of quantities from the detector
538     // local coordinate system to the ALICE Global coordinate system
539     // for the detector module index number. The global and local
540     // coordinate are given in two float point arrays g[3], and l[3].
541     void LtoGMomentum(Int_t index,const Float_t *l,Float_t *g)const{
542         Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dl[i] = l[i];
543         GetGeomMatrix(index)->LtoGMomentum(dl,dg);
544         for(i=0;i<3;i++) g[i] =dg[i];}
545     //     Transforms of momentum types of quantities from the detector
546     // local coordinate system to the ALICE Global coordinate system
547     // for the detector layer ladder and detector numbers. The global
548     // and local coordinate are given in two Double point arrays g[3],
549     // and l[3].
550     void LtoGMomentum(Int_t lay,Int_t lad,Int_t det,
551                       const Double_t *l,Double_t *g)const{
552         LtoGMomentum(GetModuleIndex(lay,lad,det),l,g);}
553     //     Transforms of momentum types of quantities from the detector
554     // local coordinate system to the ALICE Global coordinate system
555     // for the detector module index number. The global and local
556     // coordinate are given in two Double point arrays g[3], and l[3].
557     void LtoGMomentum(Int_t index,const Double_t *l,Double_t *g)const{
558         GetGeomMatrix(index)->LtoGMomentum(l,g);}
559     //
560     //     Transforms of momentum types of quantities from the detector 
561     // local coordinate system (used for ITS tracking) to the detector
562     // system ALICE Global for the detector module index number.
563     // The global and local coordinate are given in two Double point
564     // arrays g[3], and l[3].
565     void LtoGMomentumTracking(Int_t index,const Double_t *l,Double_t *g)const{
566         if(IsGeantToTracking()) LtoGMomentum(index,l,g);
567         else GetGeomMatrix(index)->LtoGMomentumTracking(l,g);}
568     //     Transforms of momentum types of quantities from the detector
569     // local coordinate system (used for ITS tracking) to the ALICE
570     // Global coordinate system for the detector id[3].
571     // The global and local coordinate are given in two Double point
572     // arrays g[3], and l[3].
573     void LtoGMomentumTracking(const Int_t *id,const Double_t *l,Double_t *g)const{
574         LtoGMomentumTracking(GetModuleIndex(id),l,g);}
575     //     Transforms of momentum types of quantities from the detector
576     // local coordinate system (used for ITS tracking) to the ALICE
577     // Global coordinate system for the detector layer ladder and detector
578     // numbers. The global and local coordinate are given in two Double point
579     // arrays g[3], and l[3].
580     void LtoGMomentumTracking(Int_t lay,Int_t lad,Int_t det,
581                               const Double_t *l,Double_t *g)const{
582                         LtoGMomentumTracking(GetModuleIndex(lay,lad,det),l,g);}
583     //
584     //     Transforms from one detector local coordinate system
585     // to another detector local coordinate system for the detector
586     // module index1 number to the detector module index2 number. The
587     //  local coordinates are given in two Double point arrays l1[3],
588     // and l2[3].
589     void LtoL(Int_t index1,Int_t index2,Double_t *l1,Double_t *l2)const{
590         Double_t g[3]; LtoG(index1,l1,g);GtoL(index2,g,l2);}
591     //     Transforms from one detector local coordinate system
592     // to another detector local coordinate system for the detector
593     // id1[3] to the detector id2[3]. The local coordinates are given
594     // in two Double point arrays l1[3], and l2[3].
595     void LtoL(const Int_t *id1,const Int_t *id2,Double_t *l1,Double_t *l2)const{
596         LtoL(GetModuleIndex(id1[0],id1[1],id1[2]),
597               GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
598     //
599     //     Transforms from one detector local coordinate system (used for
600     // ITS tracking) to another detector local coordinate system (used
601     // for ITS tracking) for the detector module index1 number to the
602     // detector module index2 number. The local coordinates are given
603     // in two Double point arrays l1[3], and l2[3].
604     void LtoLtracking(Int_t index1,Int_t index2,
605                       Double_t *l1,Double_t *l2)const{
606         Double_t g[3]; LtoGtracking(index1,l1,g);GtoLtracking(index2,g,l2);}
607     //     Transforms from one detector local coordinate system (used for
608     // ITS tracking) to another detector local coordinate system (used
609     // for ITS tracking) for the detector id1[3] to the detector id2[3].
610     // The local coordinates are given in two Double point arrays l1[3],
611     // and l2[3].
612     void LtoLtracking(const Int_t *id1,const Int_t *id2,
613                       Double_t *l1,Double_t *l2)const{
614         LtoLtracking(GetModuleIndex(id1[0],id1[1],id1[2]),
615                      GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
616     //
617     //     Transforms of momentum types of quantities from one detector
618     // local coordinate system to another detector local coordinate
619     // system for the detector module index1 number to the detector
620     // module index2 number. The local coordinates are given in two
621     // Double point arrays l1[3], and l2[3].
622     void LtoLMomentum(Int_t index1,Int_t index2,
623                       const Double_t *l1,Double_t *l2)const{
624         Double_t g[3]; LtoGMomentum(index1,l1,g);GtoLMomentum(index2,g,l2);}
625     //     Transforms of momentum types of quantities from one detector
626     // local coordinate system to another detector local coordinate
627     // system for the detector id1[3] to the detector id2[3]. The local
628     // coordinates are given in two Double point arrays l1[3], and l2[3].
629     void LtoLMomentum(const Int_t *id1,const Int_t *id2,
630                       const Double_t *l1,Double_t *l2)const{
631         LtoLMomentum(GetModuleIndex(id1[0],id1[1],id1[2]),
632                      GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
633     //
634     //     Transforms of momentum types of quantities from one detector
635     // local coordinate system (used by ITS tracking) to another detector
636     // local coordinate system (used by ITS tracking) for the detector
637     // module index1 number to the detector module index2 number. The
638     // local coordinates are given in two Double point arrays l1[3],
639     // and l2[3].
640     void LtoLMomentumTracking(Int_t index1,Int_t index2,
641                               Double_t *l1,Double_t *l2)const{
642         Double_t g[3]; LtoGMomentumTracking(index1,l1,g);
643         GtoLMomentumTracking(index2,g,l2);}
644     //     Transforms of momentum types of quantities from one detector
645     // local coordinate system (used by ITS tracking) to another detector
646     // local coordinate system (used by ITS tracking) for the detector
647     // id1[3] to the detector id2[3]. The local coordinates are given in
648     // two Double point arrays l1[3], and l2[3].
649     void LtoLMomentumTracking(const Int_t *id1,const Int_t *id2,
650                               Double_t *l1,Double_t *l2)const{
651         LtoLMomentumTracking(GetModuleIndex(id1[0],id1[1],id1[2]),
652                               GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
653     //
654     //     Transforms a matrix, like an Uncertainty or Error matrix from
655     // the ALICE Global coordinate system to a detector local coordinate
656     // system. The specific detector is determined by the module index
657     // number.
658     void GtoLErrorMatrix(Int_t index,const Double_t **g,Double_t **l)const{
659         GetGeomMatrix(index)->GtoLPositionError((Double_t (*)[3])g,(Double_t (*)[3])l);}
660     //
661     //     Transforms a matrix, like an Uncertainty or Error matrix from
662     // the ALICE Global coordinate system to a detector local coordinate
663     // system (used by ITS tracking). The specific detector is determined
664     // by the module index number.
665     void GtoLErrorMatrixTracking(Int_t index,const Double_t **g,
666                                  Double_t **l)const{
667         if(IsGeantToTracking()) GetGeomMatrix(index)->GtoLPositionError((
668                                     Double_t (*)[3])g,(Double_t (*)[3])l);
669         else GetGeomMatrix(index)->GtoLPositionErrorTracking(
670             (Double_t (*)[3])g,(Double_t (*)[3])l);}
671     //
672     //     Transforms a matrix, like an Uncertainty or Error matrix from
673     // the detector local coordinate system to a ALICE Global coordinate
674     // system. The specific detector is determined by the module index
675     // number.
676     void LtoGErrorMatrix(Int_t index,const Double_t **l,Double_t **g)const{
677         GetGeomMatrix(index)->LtoGPositionError((Double_t (*)[3])l,(Double_t (*)[3])g);}
678     //
679     //     Transforms a matrix, like an Uncertainty or Error matrix from
680     // the detector local coordinate system (used by ITS tracking) to a
681     // ALICE Global coordinate system. The specific detector is determined
682     // by the module index number.
683     void LtoGErrorMatrixTracking(Int_t index,const Double_t **l,
684                                  Double_t **g)const{
685         if(IsGeantToTracking()) GetGeomMatrix(index)->LtoGPositionError((
686                                    Double_t (*)[3])g,(Double_t (*)[3])l);
687         else GetGeomMatrix(index)->LtoGPositionErrorTracking((Double_t (*)[3])l,
688                                                           (Double_t (*)[3])g);}
689     //
690     //     Transforms a matrix, like an Uncertainty or Error matrix from
691     // one detector local coordinate system to another detector local
692     // coordinate system. The specific detector is determined by the
693     // two module index number index1 and index2.
694     void LtoLErrorMatrix(Int_t index1,Int_t index2,
695                          const Double_t **l1,Double_t **l2)const{
696         Double_t g[3][3];
697         LtoGErrorMatrix(index1,l1,(Double_t **)g);
698         GtoLErrorMatrix(index2,(const Double_t **)g,l2);}
699     //
700     //     Transforms a matrix, like an Uncertainty or Error matrix from
701     // one detector local coordinate system (used by ITS tracking) to
702     // another detector local coordinate system (used by ITS tracking).
703     // The specific detector is determined by the two module index number
704     // index1 and index2.
705     void LtoLErrorMatrixTraking(Int_t index1,Int_t index2,
706                                 const Double_t **l1,Double_t **l2)const{
707         Double_t g[3][3];
708         LtoGErrorMatrixTracking(index1,l1,(Double_t **)g);
709         GtoLErrorMatrixTracking(index2,(const Double_t **)g,l2);}
710     //  Find Specific Modules
711     // Locate the nearest module to the point g, in ALICE global Cartesian
712     // coordinates [cm] in a give layer. If layer = 0 then it search in
713     // all layers.
714     Int_t    GetNearest(const Double_t g[3],Int_t lay=0)const;
715     // Locates the nearest 27 modules, in nearest order, to the point g, in
716     // ALICE global Cartesian coordinates [cm] in a give layer. If layer = 0
717     // then it searches in all layers. (there are 27 elements in a 3x3x3
718     // cube.
719     void     GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay=0)const;
720     // Returns the distance [cm] between the point g[3] and the center of
721     // the detector/module specified by the the module index number.
722     Double_t Distance(Int_t index,const Double_t g[3])const{
723         return  TMath::Sqrt(GetGeomMatrix(index)->Distance2(g));}
724     // loops over modules and computes the average cylindrical
725     // radius to a given layer and the range.
726     Double_t GetAverageRadiusOfLayer(Int_t layer,Double_t &range)const;
727     //  Geometry manipulation
728     // This function performs a Cartesian translation and rotation of
729     // the full ITS from its default position by an amount determined by
730     // the three element arrays tran and rot.
731     void GlobalChange(const Float_t  *tran,const Float_t  *rot);
732     // This function performs a Cylindrical translation and rotation of
733     // the full ITS from its default position by an amount determined by
734     // the three element arrays tran and rot.
735     void GlobalCylindericalChange(const Float_t *tran,const Float_t *rot);
736     // This function performs a Gaussian random displacement and/or
737     // rotation about the present global position of each active
738     // volume/detector of the ITS with variances given by stran and srot.
739     void RandomChange(const Float_t *stran,const Float_t *srot);
740     // This function performs a Gaussian random displacement and/or
741     // rotation about the present global position of each active
742     // volume/detector of the ITS with variances given by stran and srot.
743     // But in Cylindrical coordinates.
744     void RandomCylindericalChange(const Float_t *stran,const Float_t *srot);
745     // This function converts these transformations from Alice global and
746     // local to Tracking global and local.
747     void GeantToTracking(const AliITSgeom &source); // This converts the geometry
748     //  Other routines.
749     // This routine prints, to a file, the difference between this class
750     // and "other".
751     void PrintComparison(FILE *fp,AliITSgeom *other)const;
752     // This routine prints, to a file, the contents of this class.
753     void PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det)const;
754     // This function prints out this class in a single stream. This steam
755     // can be read by ReadGeom.
756     ofstream &PrintGeom(ofstream &out)const;
757     // This function reads in that single steam printed out by PrintGeom.
758     ifstream &ReadGeom(ifstream &in);
759
760     //Conversion from det. local coordinates to local ("V2") coordinates
761     //used for tracking
762
763     void DetLToTrackingV2(Int_t md, Float_t xin, Float_t zin, Float_t &yout, Float_t &zout); 
764
765     void TrackingV2ToDetL(Int_t md,Float_t yin,Float_t zin,Float_t &xout,Float_t &zout);
766
767
768  private:
769     TString    fVersion; // Transformation version.
770     Int_t      fTrans;   // Flag to keep track of which transformation 
771     Int_t      fNmodules;// The total number of modules
772     Int_t      fNlayers; // The number of layers.
773     TArrayI    fNlad;    // Array of the number of ladders/layer(layer)
774     TArrayI    fNdet;    // Array of the number of detector/ladder(layer)
775     TObjArray  fGm;      // Structure of translation. and rotation.
776     TObjArray  fShape;   // Array of shapes and detector information.
777
778     ClassDef(AliITSgeom,3) // ITS geometry class
779 };
780
781 #endif