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