]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSgeom.h
Default changed: geometry file (.det) is not read by default
[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     //     This function sets the rotation matrix in a Double
223     // precision pointer for a given module. mat[i][j] => mat[3*i+j].
224     void  SetRotMatrix(Int_t index,Double_t *mat){Double_t rot[3][3];
225           for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) rot[i][j]=mat[3*i+j];
226           GetGeomMatrix(index)->SetMatrix(rot);}
227
228 //
229     //     Will define fShape if it isn't already defined.
230     void DefineShapes(Int_t size=4)
231         {if(fShape==0) fShape = new TObjArray(size);else fShape->Expand(size);}
232     //     this function returns a pointer to the class describing a particular
233     // detector type based on AliITSDetector value. This will return a pointer
234     // to one of the classes AliITSgeomSPD, AliITSgeomSDD, or AliITSgeomSSD,
235     // for example.
236     virtual TObject *GetShape(AliITSDetector idet)
237         {return fShape->At((Int_t)idet);};
238     //     This function returns a pointer to the class describing the
239     // detector for a particular module index. This will return a pointer
240     // to one of the classes AliITSgeomSPD, AliITSgeomSDD, or AliITSgeomSSD,
241     // for example.
242     virtual TObject *GetShape(Int_t index){
243         return fShape->At(GetGeomMatrix(index)->
244                           GetDetectorIndex());}
245     //     This function returns a pointer to the class describing the
246     // detector for a particular layer ladder and detector numbers. This
247     // will return a pointer to one of the classes AliITSgeomSPD,
248     // AliITSgeomSDD, or AliITSgeomSSD, for example.
249     virtual TObject *GetShape(Int_t lay,Int_t lad,Int_t det)
250                              {return GetShape(GetModuleIndex(lay,lad,det));}
251 //
252 //  Setters
253     //     Sets the rotation angles and matrix for a give module index
254     // via the double precision array a[3] [radians].
255     void SetByAngles(Int_t index,const Double_t a[]){
256         GetGeomMatrix(index)->SetAngles(a);}
257     //     Sets the rotation angles and matrix for a give module index
258     // via the 3 floating precision variables rx, ry, and rz [radians].
259     void SetByAngles(Int_t index,
260                      Float_t rx, Float_t ry, Float_t rz) {
261                      Double_t a[3];a[0] = rx;a[1] = ry;a[2] = rz;
262                      GetGeomMatrix(index)->SetAngles(a);}
263     //     Sets the rotation angles and matrix for a give layer, ladder,
264     // and detector numbers via the 3 floating precision variables rx,
265     // ry, and rz [radians].
266     void SetByAngles(Int_t lay,Int_t lad,Int_t det,
267                      Float_t rx, Float_t ry, Float_t rz) {
268                      SetByAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
269 //
270     //     Sets the rotation angles and matrix for a give module index
271     // via the Double precision array a[6] [degree]. The angles are those
272     // defined by GEANT 3.12.
273     void SetByGeantAngles(Int_t index,const Double_t *ang){
274         GetGeomMatrix(index)->MatrixFromSixAngles(ang);}
275     //     Sets the rotation angles and matrix for a give layer, ladder
276     // and detector, in the array id[3] via the Double precision array
277     // a[6] [degree]. The angles are those defined by GEANT 3.12.
278     void SetByGeantAngles(const Int_t *id,const Double_t *ang){
279         SetByGeantAngles(GetModuleIndex(id),ang);}
280     //     Sets the rotation angles and matrix for a give layer, ladder
281     // and detector, via the Double precision array a[6] [degree]. The
282     // angles are those defined by GEANT 3.12.
283     void SetByGeantAngles(Int_t lay,Int_t lad,Int_t det,
284                           const Double_t *ang){
285         SetByGeantAngles(GetModuleIndex(lay,lad,det),ang);}
286 //
287     //     This function sets a new translation vector, given by the
288     // array x[3], for the Cartesian coordinate transformation
289     // for a give module index.
290     void SetTrans(Int_t index,Double_t x[]){
291         GetGeomMatrix(index)->SetTranslation(x);}
292     //     This function sets a new translation vector, given by the three
293     // variables x, y, and z, for the Cartesian coordinate transformation
294     // for the detector defined by layer, ladder and detector.
295     void SetTrans(Int_t lay,Int_t lad,Int_t det,
296                   Float_t x,Float_t y,Float_t z){Double_t t[3];
297                   t[0] = x;t[1] = y;t[2] = z;
298                   SetTrans(GetModuleIndex(lay,lad,det),t);}
299 //
300     //     This function adds one more shape element to the TObjArray
301     // fShape. It is primarily used in the constructor functions of the
302     // AliITSgeom class. The pointer *shape can be the pointer to any
303     // class that is derived from TObject (this is true for nearly every
304     // ROOT class). This does not appear to be working properly at this time.
305     void AddShape(TObject *shp){fShape->AddLast(shp);}
306     //     This function deletes an existing shape element, of type TObject,
307     // and replaces it with the one specified. This is primarily used to
308     // changes the parameters to the segmentation class for a particular
309     // type of detector.
310     void ReSetShape(Int_t dtype,TObject *shp){
311          fShape->RemoveAt(dtype);fShape->AddAt(shp,dtype);}
312 //
313 //  transformations
314     //     Transforms from the ALICE Global coordinate system
315     // to the detector local coordinate system for the detector
316     // defined by the layer, ladder, and detector numbers. The
317     // global and local coordinate are given in two floating point
318     // arrays g[3], and l[3].
319     void GtoL(Int_t lay,Int_t lad,Int_t det,
320               const Float_t *g,Float_t *l){
321          GtoL(GetModuleIndex(lay,lad,det),g,l);}
322     //     Transforms from the ALICE Global coordinate system
323     // to the detector local coordinate system for the detector
324     // defined by the id[0], id[1], and id[2] numbers. The
325     // global and local coordinate are given in two floating point
326     // arrays g[3], and l[3].
327     void GtoL(const Int_t *id,const Float_t *g,Float_t *l){
328          GtoL(GetModuleIndex(id),g,l);}
329     //     Transforms from the ALICE Global coordinate system
330     // to the detector local coordinate system for the detector
331     // module index number. The global and local coordinate are
332     // given in two floating point arrays g[3], and l[3].
333     void GtoL(Int_t index,const Float_t *g,Float_t *l){
334          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
335          GetGeomMatrix(index)->GtoLPosition(dg,dl);
336          for(i=0;i<3;i++) l[i] =dl[i];}
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 Double point
341     // arrays g[3], and l[3].
342     void GtoL(Int_t lay,Int_t lad,Int_t det,
343               const Double_t *g,Double_t *l){
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 Double point
349     // arrays g[3], and l[3].
350     void GtoL(const Int_t *id,const Double_t *g,Double_t *l){
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 Double point arrays g[3], and l[3].
356     void GtoL(Int_t index,const Double_t *g,Double_t *l){
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 //
361     //     Transforms from the ALICE Global coordinate system
362     // to the detector local coordinate system (used for ITS tracking)
363     // for the detector module index number. The global and local
364     // coordinate are given in two Double point arrays g[3], and l[3].
365     void GtoLtracking(Int_t index,const Double_t *g,Double_t *l){
366          if(IsGeantToTracking()) GtoL(index,g,l);
367          else GetGeomMatrix(index)->GtoLPositionTracking(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 id[3]. The global and local
371     // coordinate are given in two Double point arrays g[3], and l[3].
372     void GtoLtracking(const Int_t *id,const Double_t *g,Double_t *l){
373          GtoLtracking(GetModuleIndex(id),g,l);}
374     //     Transforms from the ALICE Global coordinate system
375     // to the detector local coordinate system (used for ITS tracking)
376     // for the detector layer ladder and detector numbers. The global
377     // and local coordinate are given in two Double point arrays g[3],
378     // and l[3].
379     void GtoLtracking(Int_t lay,Int_t lad,Int_t det,
380                       const Double_t *g,Double_t *l){
381          GtoLtracking(GetModuleIndex(lay,lad,det),g,l);}
382 //
383     //     Transforms of momentum types of quantities from the ALICE
384     // Global coordinate system to the detector local coordinate system
385     // for the detector layer ladder and detector numbers. The global
386     // and local coordinate are given in two float point arrays g[3],
387     // and l[3].
388     void GtoLMomentum(Int_t lay,Int_t lad,Int_t det,
389                       const Float_t *g,Float_t *l){
390                          GtoLMomentum(GetModuleIndex(lay,lad,det),g,l);}
391     //     Transforms of momentum types of quantities from the ALICE
392     // Global coordinate system to the detector local coordinate system
393     // for the detector module index number. The global and local
394     // coordinate are given in two float point arrays g[3], and l[3].
395     void GtoLMomentum(Int_t index,const Float_t *g,Float_t *l){
396          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
397          GetGeomMatrix(index)->GtoLMomentum(dg,dl);
398          for(i=0;i<3;i++) l[i] =dl[i];}
399     //     Transforms of momentum types of quantities from the ALICE
400     // Global coordinate system to the detector local coordinate system
401     // for the detector layer ladder and detector numbers. The global
402     // and local coordinate are given in two Double point arrays g[3],
403     // and l[3].
404     void GtoLMomentum(Int_t lay,Int_t lad,Int_t det,
405                       const Double_t *g,Double_t *l){
406          GtoLMomentum(GetModuleIndex(lay,lad,det),g,l);}
407     //     Transforms of momentum types of quantities from the ALICE
408     // Global coordinate system to the detector local coordinate system
409     // for the detector module index number. The global and local
410     // coordinate are given in two Double point arrays g[3], and l[3].
411     void GtoLMomentum(Int_t index,const Double_t *g,Double_t *l){
412          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
413          GetGeomMatrix(index)->GtoLMomentum(dg,dl);
414          for(i=0;i<3;i++) l[i] =dl[i];}
415 //
416     //     Transforms of momentum types of quantities from the ALICE
417     // Global coordinate system to the detector local coordinate system
418     // (used for ITS tracking) for the detector module index number.
419     // The global and local coordinate are given in two Double point
420     // arrays g[3], and l[3].
421     void GtoLMomentumTracking(Int_t index,const Double_t *g,Double_t *l){
422          if(IsGeantToTracking()) GtoLMomentum(index,g,l);
423          else GetGeomMatrix(index)->GtoLMomentumTracking(g,l);}
424     //     Transforms of momentum types of quantities from the ALICE
425     // Global coordinate system to the detector local coordinate system
426     // (used for ITS tracking) for the detector id[3].
427     // The global and local coordinate are given in two Double point
428     // arrays g[3], and l[3].
429     void GtoLMomentumTracking(const Int_t *id,const Double_t *g,Double_t *l){
430                  GtoLMomentumTracking(GetModuleIndex(id),g,l);}
431     //     Transforms of momentum types of quantities from the ALICE
432     // Global coordinate system to the detector local coordinate system
433     // (used for ITS tracking) for the detector layer ladder and detector
434     // numbers. The global and local coordinate are given in two Double point
435     // arrays g[3], and l[3].
436     void GtoLMomentumTracking(Int_t lay,Int_t lad,Int_t det,
437                               const Double_t *g,Double_t *l){
438                         GtoLMomentumTracking(GetModuleIndex(lay,lad,det),g,l);}
439 //
440     //     Transforms from the detector local coordinate system
441     // to the ALICE Global coordinate  system for the detector
442     // defined by the layer, ladder, and detector numbers. The
443     // global and local coordinate are given in two floating point
444     // arrays g[3], and l[3].
445     void LtoG(Int_t lay,Int_t lad,Int_t det,
446               const Float_t *l,Float_t *g){
447                      LtoG(GetModuleIndex(lay,lad,det),l,g);}
448     //     Transforms from the detector local coordinate system
449     // to the ALICE Global coordinate system for the detector
450     // defined by the id[0], id[1], and id[2] numbers. The
451     // global and local coordinate are given in two floating point
452     // arrays g[3], and l[3].
453     void LtoG(const Int_t *id,const Float_t *l,Float_t *g){
454                      LtoG(GetModuleIndex(id),l,g);}
455     //     Transforms from the detector local coordinate system
456     // to the ALICE Global coordinate system for the detector
457     // module index number. The global and local coordinate are
458     // given in two floating point arrays g[3], and l[3].
459     void LtoG(Int_t index,const Float_t *l,Float_t *g){
460          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dl[i] = l[i];
461          GetGeomMatrix(index)->LtoGPosition(dl,dg);
462          for(i=0;i<3;i++) g[i] =dg[i];}
463     //     Transforms from the detector local coordinate system
464     // to the ALICE Global coordinate system for the detector
465     // defined by the layer, ladder, and detector numbers. The
466     // global and local coordinate are given in two Double point
467     // arrays g[3], and l[3].
468     void LtoG(Int_t lay,Int_t lad,Int_t det,
469               const Double_t *l,Double_t *g){
470                       LtoG(GetModuleIndex(lay,lad,det),l,g);}
471     //     Transforms from the detector local coordinate system
472     // to the ALICE Global coordinate system for the detector
473     // defined by the id[0], id[1], and id[2] numbers. The
474     // global and local coordinate are given in two Double point
475     // arrays g[3], and l[3].
476     void LtoG(const Int_t *id,const Double_t *l,Double_t *g){
477                        LtoG(GetModuleIndex(id),l,g);}
478     //     Transforms from the detector local coordinate system
479     // to the ALICE Global coordinate system for the detector
480     // module index number. The global and local coordinate are
481     // given in two Double point arrays g[3], and l[3].
482     void LtoG(Int_t index,const Double_t *l,Double_t *g){
483          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dl[i] = l[i];
484          GetGeomMatrix(index)->LtoGPosition(dl,dg);
485          for(i=0;i<3;i++) g[i] =dg[i];}
486 //
487     //     Transforms from the detector local coordinate system (used
488     // for ITS tracking) to the ALICE Global coordinate system 
489     // for the detector module index number. The global and local
490     // coordinate are given in two Double point arrays g[3], and l[3].
491     void LtoGtracking(Int_t index,const Double_t *l,Double_t *g){
492          if(IsGeantToTracking()) LtoG(index,l,g);
493          else GetGeomMatrix(index)->LtoGPositionTracking(l,g);}
494     //     Transforms from the detector local coordinate system (used
495     // for ITS tracking) to the ALICE Global coordinate system 
496     // for the detector id[3]. The global and local
497     // coordinate are given in two Double point arrays g[3], and l[3].
498     void LtoGtracking(const Int_t *id,const Double_t *l,Double_t *g){
499          LtoGtracking(GetModuleIndex(id),l,g);}
500     //     Transforms from the detector local coordinate system (used
501     // for ITS tracking) to the detector local coordinate system
502     // for the detector layer ladder and detector numbers. The global
503     // and local coordinate are given in two Double point arrays g[3],
504     // and l[3].
505     void LtoGtracking(Int_t lay,Int_t lad,Int_t det,
506                       const Double_t *l,Double_t *g){
507          LtoGtracking(GetModuleIndex(lay,lad,det),l,g);}
508 //
509     //     Transforms of momentum types of quantities from the detector
510     // local coordinate system to the ALICE Global coordinate system
511     // for the detector layer ladder and detector numbers. The global
512     // and local coordinate are given in two float point arrays g[3],
513     // and l[3].
514     void LtoGMomentum(Int_t lay,Int_t lad,Int_t det,
515                       const Float_t *l,Float_t *g){
516          LtoGMomentum(GetModuleIndex(lay,lad,det),l,g);}
517     //     Transforms of momentum types of quantities from the detector
518     // local coordinate system to the ALICE Global coordinate system
519     // for the detector module index number. The global and local
520     // coordinate are given in two float point arrays g[3], and l[3].
521     void LtoGMomentum(Int_t index,const Float_t *l,Float_t *g){
522          Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dl[i] = l[i];
523          GetGeomMatrix(index)->LtoGMomentum(dl,dg);
524          for(i=0;i<3;i++) g[i] =dg[i];}
525     //     Transforms of momentum types of quantities from the detector
526     // local coordinate system to the ALICE Global coordinate system
527     // for the detector layer ladder and detector numbers. The global
528     // and local coordinate are given in two Double point arrays g[3],
529     // and l[3].
530     void LtoGMomentum(Int_t lay,Int_t lad,Int_t det,
531                            const Double_t *l,Double_t *g){
532                         LtoGMomentum(GetModuleIndex(lay,lad,det),l,g);}
533     //     Transforms of momentum types of quantities from the detector
534     // local coordinate system to the ALICE Global coordinate system
535     // for the detector module index number. The global and local
536     // coordinate are given in two Double point arrays g[3], and l[3].
537     void LtoGMomentum(Int_t index,const Double_t *l,Double_t *g){
538          GetGeomMatrix(index)->LtoGMomentum(l,g);}
539 //
540     //     Transforms of momentum types of quantities from the detector 
541     // local coordinate system (used for ITS tracking) to the detector
542     // system ALICE Global for the detector module index number.
543     // The global and local coordinate are given in two Double point
544     // arrays g[3], and l[3].
545     void LtoGMomentumTracking(Int_t index,const Double_t *l,Double_t *g){
546          if(IsGeantToTracking()) LtoGMomentum(index,l,g);
547          else GetGeomMatrix(index)->LtoGMomentumTracking(l,g);}
548     //     Transforms of momentum types of quantities from the detector
549     // local coordinate system (used for ITS tracking) to the ALICE
550     // Global coordinate system for the detector id[3].
551     // The global and local coordinate are given in two Double point
552     // arrays g[3], and l[3].
553     void LtoGMomentumTracking(const Int_t *id,const Double_t *l,Double_t *g){
554                  LtoGMomentumTracking(GetModuleIndex(id),l,g);}
555     //     Transforms of momentum types of quantities from the detector
556     // local coordinate system (used for ITS tracking) to the ALICE
557     // Global coordinate system for the detector layer ladder and detector
558     // numbers. The global and local coordinate are given in two Double point
559     // arrays g[3], and l[3].
560     void LtoGMomentumTracking(Int_t lay,Int_t lad,Int_t det,
561                               const Double_t *l,Double_t *g){
562                         LtoGMomentumTracking(GetModuleIndex(lay,lad,det),l,g);}
563 //
564     //     Transforms from one detector local coordinate system
565     // to another detector local coordinate system for the detector
566     // module index1 number to the detector module index2 number. The
567     //  local coordinates are given in two Double point arrays l1[3],
568     // and l2[3].
569     void LtoL(Int_t index1,Int_t index2,Double_t *l1,Double_t *l2){
570          Double_t g[3]; LtoG(index1,l1,g);GtoL(index2,g,l2);}
571     //     Transforms from one detector local coordinate system
572     // to another detector local coordinate system for the detector
573     // id1[3] to the detector id2[3]. The local coordinates are given
574     // in two Double point arrays l1[3], and l2[3].
575     void LtoL(const Int_t *id1,const Int_t *id2,Double_t *l1,Double_t *l2){
576          LtoL(GetModuleIndex(id1[0],id1[1],id1[2]),
577               GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
578 //
579     //     Transforms from one detector local coordinate system (used for
580     // ITS tracking) to another detector local coordinate system (used
581     // for ITS tracking) for the detector module index1 number to the
582     // detector module index2 number. The local coordinates are given
583     // in two Double point arrays l1[3], and l2[3].
584     void LtoLtracking(Int_t index1,Int_t index2,
585                            Double_t *l1,Double_t *l2){
586          Double_t g[3]; LtoGtracking(index1,l1,g);GtoLtracking(index2,g,l2);}
587     //     Transforms from one detector local coordinate system (used for
588     // ITS tracking) to another detector local coordinate system (used
589     // for ITS tracking) for the detector id1[3] to the detector id2[3].
590     // The local coordinates are given in two Double point arrays l1[3],
591     // and l2[3].
592     void LtoLtracking(const Int_t *id1,const Int_t *id2,
593                            Double_t *l1,Double_t *l2){
594          LtoLtracking(GetModuleIndex(id1[0],id1[1],id1[2]),
595               GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
596 //
597     //     Transforms of momentum types of quantities from one detector
598     // local coordinate system to another detector local coordinate
599     // system for the detector module index1 number to the detector
600     // module index2 number. The local coordinates are given in two
601     // Double point arrays l1[3], and l2[3].
602     void LtoLMomentum(Int_t index1,Int_t index2,
603                       const Double_t *l1,Double_t *l2){
604          Double_t g[3]; LtoGMomentum(index1,l1,g);GtoLMomentum(index2,g,l2);}
605     //     Transforms of momentum types of quantities from one detector
606     // local coordinate system to another detector local coordinate
607     // system for the detector id1[3] to the detector id2[3]. The local
608     // coordinates are given in two Double point arrays l1[3], and l2[3].
609     void LtoLMomentum(const Int_t *id1,const Int_t *id2,
610                       const Double_t *l1,Double_t *l2){
611          LtoLMomentum(GetModuleIndex(id1[0],id1[1],id1[2]),
612                       GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
613 //
614     //     Transforms of momentum types of quantities from one detector
615     // local coordinate system (used by ITS tracking) to another detector
616     // local coordinate system (used by ITS tracking) for the detector
617     // module index1 number to the detector module index2 number. The
618     // local coordinates are given in two Double point arrays l1[3],
619     // and l2[3].
620     void LtoLMomentumTracking(Int_t index1,Int_t index2,
621                            Double_t *l1,Double_t *l2){
622          Double_t g[3]; LtoGMomentumTracking(index1,l1,g);
623                         GtoLMomentumTracking(index2,g,l2);}
624     //     Transforms of momentum types of quantities from one detector
625     // local coordinate system (used by ITS tracking) to another detector
626     // local coordinate system (used by ITS tracking) for the detector
627     // id1[3] to the detector id2[3]. The local coordinates are given in
628     // two Double point arrays l1[3], and l2[3].
629     void LtoLMomentumTracking(const Int_t *id1,const Int_t *id2,
630                            Double_t *l1,Double_t *l2){
631          LtoLMomentumTracking(GetModuleIndex(id1[0],id1[1],id1[2]),
632                               GetModuleIndex(id2[0],id2[1],id2[2]),l1,l2);}
633 //
634     //     Transforms a matrix, like an Uncertainty or Error matrix from
635     // the ALICE Global coordinate system to a detector local coordinate
636     // system. The specific detector is determined by the module index
637     // number.
638     void GtoLErrorMatrix(Int_t index,const Double_t **g,Double_t **l){
639          GetGeomMatrix(index)->GtoLPositionError((Double_t (*)[3])g,(Double_t (*)[3])l);}
640 //
641     //     Transforms a matrix, like an Uncertainty or Error matrix from
642     // the ALICE Global coordinate system to a detector local coordinate
643     // system (used by ITS tracking). The specific detector is determined
644     // by the module index number.
645     void GtoLErrorMatrixTracking(Int_t index,const Double_t **g,
646                                  Double_t **l){
647         if(IsGeantToTracking()) GetGeomMatrix(index)->GtoLPositionError((
648             Double_t (*)[3])g,(Double_t (*)[3])l);
649         else GetGeomMatrix(index)->GtoLPositionErrorTracking(
650              (Double_t (*)[3])g,(Double_t (*)[3])l);}
651 //
652     //     Transforms a matrix, like an Uncertainty or Error matrix from
653     // the detector local coordinate system to a ALICE Global coordinate
654     // system. The specific detector is determined by the module index
655     // number.
656     void LtoGErrorMatrix(Int_t index,const Double_t **l,Double_t **g){
657          GetGeomMatrix(index)->LtoGPositionError((Double_t (*)[3])l,(Double_t (*)[3])g);}
658 //
659     //     Transforms a matrix, like an Uncertainty or Error matrix from
660     // the detector local coordinate system (used by ITS tracking) to a
661     // ALICE Global coordinate system. The specific detector is determined
662     // by the module index number.
663     void LtoGErrorMatrixTracking(Int_t index,const Double_t **l,
664                                  Double_t **g){
665          if(IsGeantToTracking()) GetGeomMatrix(index)->LtoGPositionError((
666             Double_t (*)[3])g,(Double_t (*)[3])l);
667         else GetGeomMatrix(index)->LtoGPositionErrorTracking((Double_t (*)[3])l,
668                                                (Double_t (*)[3])g);}
669 //
670     //     Transforms a matrix, like an Uncertainty or Error matrix from
671     // one detector local coordinate system to another detector local
672     // coordinate system. The specific detector is determined by the
673     // two module index number index1 and index2.
674     void LtoLErrorMatrix(Int_t index1,Int_t index2,
675                          const Double_t **l1,Double_t **l2){
676         Double_t g[3][3];
677                   LtoGErrorMatrix(index1,l1,(Double_t **)g);
678                   GtoLErrorMatrix(index2,(const Double_t **)g,l2);}
679 //
680     //     Transforms a matrix, like an Uncertainty or Error matrix from
681     // one detector local coordinate system (used by ITS tracking) to
682     // another detector local coordinate system (used by ITS tracking).
683     // The specific detector is determined by the two module index number
684     // index1 and index2.
685     void LtoLErrorMatrixTraking(Int_t index1,Int_t index2,
686                          const Double_t **l1,Double_t **l2){Double_t g[3][3];
687                   LtoGErrorMatrixTracking(index1,l1,(Double_t **)g);
688                   GtoLErrorMatrixTracking(index2,(const Double_t **)g,l2);}
689 //  Find Specific Modules
690     // Locate the nearest module to the point g, in ALICE global Cartesian
691     // coordinates [cm] in a give layer. If layer = 0 then it search in
692     // all layers.
693     Int_t    GetNearest(const Double_t g[3],Int_t lay=0);
694     // Locates the nearest 27 modules, in nearest order, to the point g, in
695     // ALICE global Cartesian coordinates [cm] in a give layer. If layer = 0
696     // then it searches in all layers. (there are 27 elements in a 3x3x3
697     // cube.
698     void     GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay=0);
699     // Returns the distance [cm] between the point g[3] and the center of
700     // the detector/module specified by the the module index number.
701     Double_t Distance(Int_t index,const Double_t g[3]){
702          return  TMath::Sqrt(GetGeomMatrix(index)->Distance2(g));}
703 //  Geometry manipulation
704     // This function performs a Cartesian translation and rotation of
705     // the full ITS from its default position by an amount determined by
706     // the three element arrays tran and rot.
707     void GlobalChange(const Float_t  *tran,const Float_t  *rot);
708     // This function performs a Cylindrical translation and rotation of
709     // the full ITS from its default position by an amount determined by
710     // the three element arrays tran and rot.
711     void GlobalCylindericalChange(const Float_t *tran,const Float_t *rot);
712     // This function performs a Gaussian random displacement and/or
713     // rotation about the present global position of each active
714     // volume/detector of the ITS with variances given by stran and srot.
715     void RandomChange(const Float_t *stran,const Float_t *srot);
716     // This function performs a Gaussian random displacement and/or
717     // rotation about the present global position of each active
718     // volume/detector of the ITS with variances given by stran and srot.
719     // But in Cylindrical coordinates.
720     void RandomCylindericalChange(const Float_t *stran,const Float_t *srot);
721     // This function converts these transformations from Alice global and
722     // local to Tracking global and local.
723     void GeantToTracking(AliITSgeom &source); // This converts the geometry
724 //  Other routines.
725     // This routine prints, to a file, the difference between this class
726     // and "other".
727     void PrintComparison(FILE *fp,AliITSgeom *other);
728     // This routine prints, to a file, the contents of this class.
729     void PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det);
730     // This function prints out this class in a single stream. This steam
731     // can be read by ReadGeom.
732     ofstream &PrintGeom(ofstream &out);
733     // This function reads in that single steam printed out by PrintGeom.
734     ifstream &ReadGeom(ifstream &in);
735
736     //Conversion from det. local coordinates to local ("V2") coordinates
737     //used for tracking
738
739     void DetLToTrackingV2(Int_t md, Float_t xin, Float_t zin, Float_t &yout, Float_t &zout); 
740
741     void TrackingV2ToDetL(Int_t md,Float_t yin,Float_t zin,Float_t &xout,Float_t &zout);
742
743  private:
744     char       fVersion[20];// Transformation version.
745     Int_t      fTrans;   // Flag to keep track of which transformation 
746     Int_t      fNmodules;// The total number of modules
747     Int_t      fNlayers; // The number of layers.
748     Int_t     *fNlad;  //[fNlayers] Array of the number of ladders/layer(layer)
749     Int_t     *fNdet;//[fNlayers] Array of the number of detector/ladder(layer)
750     TObjArray *fGm;      // Structure of translation. and rotation.
751     TObjArray *fShape;   // Array of shapes and detector information.
752
753     ClassDef(AliITSgeom,2) // ITS geometry class
754 };
755
756 #endif