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