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