]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFGeometry.cxx
97aaa83880304ed0792ff448360bf7a37028b304
[u/mrichter/AliRoot.git] / TOF / AliTOFGeometry.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.19  2007/10/04 14:05:09  zampolli
19 AliTOFGeometryV5 becoming AliTOFGeometry
20
21 Revision 1.18  2007/02/19 18:55:26  decaro
22 Added getter methods for volume path (for Event Display)
23
24 Revision 1.17.1  2006/12/15 
25          Added method DetToStripRF(...) to get
26          a pad corner coordinates in its strip reference frame
27          (A.De Caro, M.Di Stefano)
28 Revision 1.17  2006/08/22 13:30:02  arcelli
29 removal of effective c++ warnings (C.Zampolli)
30
31 Revision 1.16  2006/04/20 22:30:50  hristov
32 Coding conventions (Annalisa)
33
34 Revision 1.15  2006/04/16 22:29:05  hristov
35 Coding conventions (Annalisa)
36
37 Revision 1.14  2006/04/05 08:35:38  hristov
38 Coding conventions (S.Arcelli, C.Zampolli)
39
40 Revision 1.13  2006/03/12 14:37:54  arcelli
41  Changes for TOF Reconstruction using TGeo
42
43 Revision 1.12  2006/02/28 10:38:00  decaro
44 AliTOFGeometry::fAngles, AliTOFGeometry::fHeights, AliTOFGeometry::fDistances arrays: dimension definition in the right location
45
46 Revision 1.11  2005/12/15 14:17:29  decaro
47 Correction of some parameter values
48
49 Revision 1.10  2005/12/15 08:55:32  decaro
50 New TOF geometry description (V5) -G. Cara Romeo and A. De Caro
51
52 Revision 1.9.1  2005/07/19 A. De Caro
53         Created daughter-classes AliTOFGeometryV4 and AliTOFGeometryV5
54         => moved global methods IsInsideThePad, DistanceToPad,
55         GetPlate, GetSector, GetStrip, GetPadX, GetPadZ,
56         GetX, GetY, GetZ, GetPadDx, GetPadDy and GetPadDz
57         in daughter-classes
58
59 Revision 1.9  2005/10/20 12:41:35  hristov
60 Implementation of parallel tracking. It is not the default version, one can use it passing option MI from AliReconstruction to TOF (M.Ivanov)
61
62 Revision 1.8  2004/11/29 08:28:01  decaro
63 Introduction of a new TOF constant (i.e. TDC bin width)
64
65 Revision 1.7  2004/11/05 07:20:08  decaro
66 TOF library splitting and conversion of some printout messages in AliLog schema (T.Kuhr)
67
68 Revision 1.6  2004/06/15 15:27:59  decaro
69 TOF raw data: preliminary implementation and style changes
70
71 Revision 1.5  2004/04/20 14:37:22  hristov
72 Using TMath::Abs instead of fabs, arrays of variable size created/deleted correctly (HP,Sun)
73
74 Revision 1.4  2004/04/13 09:42:51  decaro
75 Track reconstruction code for TOF: updating
76
77 Revision 1.3  2003/12/29 18:40:39  hristov
78 Copy/paste error corrected
79
80 Revision 1.2  2003/12/29 17:26:01  hristov
81 Using enum to initaialize static ints in the header file, the initialization of static floats moved to the implementation file
82
83 Revision 1.1  2003/12/29 15:18:03  decaro
84 TOF geometry updating (addition of AliTOFGeometry)
85
86 Revision 0.05  2004/6/11 A.De Caro
87         Implement Global method NpadXStrip
88         Insert four float constants (originally  in AliTOF class)
89 Revision 0.04  2004/4/05 S.Arcelli
90         Implement Global methods IsInsideThePad 
91                                   DistanceToPad 
92 Revision 0.03  2003/12/14 S.Arcelli
93         Set Phi range [-180,180]->[0,360] 
94 Revision 0.02  2003/12/10 S.Arcelli:
95         Implement Global methods GetPos & GetDetID 
96 Revision 0.01  2003/12/04 S.Arcelli
97 */
98
99 ///////////////////////////////////////////////////////////////////////////////
100 //                                                                           //
101 //  TOF Geometry class                                                       //
102 //                                                                           //
103 ///////////////////////////////////////////////////////////////////////////////
104
105 #include "TGeoManager.h"
106 #include "AliTOFGeometry.h"
107 #include "AliLog.h"
108 #include "AliConst.h"
109
110 extern TGeoManager *gGeoManager;
111
112 ClassImp(AliTOFGeometry)
113
114 const Float_t AliTOFGeometry::fgkZlenA    = 370.6*2.; // length (cm) of the A module
115 const Float_t AliTOFGeometry::fgkZlenB    = 146.5;    // length (cm) of the B module
116 const Float_t AliTOFGeometry::fgkZlenC    = 170.45;   // length (cm) of the C module
117 const Float_t AliTOFGeometry::fgkMaxhZtof = 370.6;    // Max half z-size of TOF (cm)
118
119 const Float_t AliTOFGeometry::fgkxTOF     = 371.-0.01;// Inner radius of the TOF for Reconstruction (cm)
120 const Float_t AliTOFGeometry::fgkRmin     = 370.-0.01;// Inner radius of the TOF (cm)
121 const Float_t AliTOFGeometry::fgkRmax     = 399.-0.01;// Outer radius of the TOF (cm)
122
123 const Int_t AliTOFGeometry::fgkTimeDiff   = 25000;  // Min signal separation (ps)
124 const Float_t AliTOFGeometry::fgkXPad     = 2.5;    // Pad size in the x direction (cm)
125 const Float_t AliTOFGeometry::fgkZPad     = 3.5;    // Pad size in the z direction (cm)
126
127 const Float_t AliTOFGeometry::fgkStripLength = 122.;// Strip Length (rho X phi direction) (cm)
128
129 const Float_t AliTOFGeometry::fgkSigmaForTail1= 2.; //Sig1 for simulation of TDC tails 
130 const Float_t AliTOFGeometry::fgkSigmaForTail2= 0.5;//Sig2 for simulation of TDC tails
131
132 const Float_t AliTOFGeometry::fgkPhiSec= 20;//sector Phi width (deg)
133
134 const Float_t AliTOFGeometry::fgkTdcBin = 24.4;     // time-of-flight bin width [ps]
135 const Float_t AliTOFGeometry::fgkToTBin = 48.8;     // time-over-threshold  bin width [ps]
136
137 const Float_t AliTOFGeometry::fgkAngles[kNPlates][kMaxNstrip] ={
138     { 43.99,  43.20,  42.40,  41.59,  40.77,  39.94,  39.11,  38.25,  37.40,  36.53,
139       35.65,  34.76,  33.87,  32.96,  32.05,  31.13,  30.19,  29.24,  12.33,  0.00},
140
141     { 27.26,  26.28,  25.30,  24.31,  23.31,  22.31,  21.30,  20.29,  19.26,  18.24,
142       17.20,  16.16,  15.11,  14.05,  13.00,  11.93,  10.87,   9.80,   8.74,  0.00},
143
144     {  0.00,   6.30,   5.31,   4.25,   3.19,   2.12,   1.06,   0.00,  -1.06,  -2.12,
145       -3.19,  -4.25,  -5.31,  -6.30,   0.00,   0.00,   0.00,   0.00,   0.00,  0.00},
146
147     { -8.74,  -9.80, -10.87, -11.93, -13.00, -14.05, -15.11, -16.16, -17.20, -18.24,
148      -19.26, -20.29, -21.30, -22.31, -23.31, -24.31, -25.30, -26.28, -27.26,  0.00},
149     
150     {-12.33, -29.24, -30.19, -31.13, -32.05, -32.96, -33.87, -34.76, -35.65, -36.53,
151      -37.40, -38.25, -39.11, -39.94, -40.77, -41.59, -42.40, -43.20, -43.99,  0.00}
152   };
153 const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip]= {
154     {-8.2,  -7.5,  -8.2,  -7.7,  -8.1,  -7.6,  -7.7,  -7.7,  -7.7,  -7.7,
155      -7.5,  -7.2,  -7.3,  -7.5,  -7.6,  -7.8,  -8.3,  -9.3,  -3.1,   0.0},
156
157     {-7.9,  -8.1,  -8.5,  -9.0, -10.1,  -3.9,  -5.9,  -7.7, -10.1,  -3.6,
158      -5.8,  -8.0, -10.4,  -4.4,  -7.2, -10.2,  -4.6,  -7.4, -10.4,   0.0},
159
160     {-2.5, -10.4,  -5.0,  -9.9,  -4.8,  -9.9,  -4.7, -10.2,  -4.7,  -9.9,
161      -4.8,  -9.9,  -5.0, -10.4,  -2.5,   0.0,   0.0,   0.0,   0.0,   0.0},
162
163     {-10.4, -7.4,  -4.6, -10.2,  -7.2,  -4.4, -10.4,  -8.0,  -5.8,  -3.6,
164      -10.1,  -7.7, -5.9,  -3.9, -10.1,  -9.0,  -8.5,  -8.1,  -7.9,   0.0},
165
166     { -3.1,  -9.3, -8.3,  -7.8,  -7.6,  -7.5,  -7.3,  -7.2,  -7.5,  -7.7,
167       -7.7,  -7.7, -7.7,  -7.6,  -8.1,  -7.7,  -8.2,  -7.5,  -8.2,   0.0}
168   };
169
170
171 const Float_t AliTOFGeometry::fgkDistances[kNPlates][kMaxNstrip]= {
172     { 364.1,  354.9,  344.5,  335.4,  325.5,  316.6,  307.2,  298.0,  288.9,  280.0,
173       271.3,  262.7,  254.0,  244.8,  236.1,  227.7,  219.1,  210.3,  205.7,    0.0},
174
175     { 194.2,  186.1,  177.9,  169.8,  161.5,  156.3,  147.8,  139.4,  130.9,  125.6,
176       117.3,  109.2,  101.1,   95.3,   87.1,   79.2,   73.0,   65.1,   57.6,    0.0},
177
178     {  49.5,   41.3,   35.3,   27.8,   21.2,   13.9,    7.0,    0.0,   -7.0,  -13.9,
179       -21.2,  -27.8,  -35.3,  -41.3,  -49.5,    0.0,    0.0,    0.0,    0.0,    0.0},
180
181     { -57.6,  -65.1,  -73.0,  -79.2,  -87.1,  -95.3, -101.1, -109.2, -117.3, -125.6,
182      -130.9, -139.4, -147.8, -156.3, -161.5, -169.8, -177.9, -186.1, -194.2,    0.0},
183
184     {-205.7, -210.3, -219.1, -227.7, -236.1, -244.8, -254.0, -262.7, -271.3, -280.0,
185      -288.9, -298.0, -307.2, -316.6, -325.5, -335.4, -344.5, -354.9, -364.1,    0.0}
186   };
187 //_____________________________________________________________________________
188 AliTOFGeometry::AliTOFGeometry():
189   fHoles(0)
190 {
191   //
192   // AliTOFGeometry default constructor
193   //
194
195 }
196
197 //_____________________________________________________________________________
198 AliTOFGeometry::~AliTOFGeometry()
199 {
200   //
201   // AliTOFGeometry destructor
202   //
203 }
204 //_____________________________________________________________________________
205 void AliTOFGeometry::ImportGeometry(){
206   TGeoManager::Import("geometry.root");
207 }
208 //_____________________________________________________________________________
209 void AliTOFGeometry::GetPosPar(Int_t *det, Float_t *pos) const
210 {
211 //
212 // Returns space point coor (x,y,z) (cm)  for Detector 
213 // Indices  (iSect,iPlate,iStrip,iPadX,iPadZ) 
214 //
215
216   pos[0]=GetX(det);  
217   pos[1]=GetY(det);  
218   pos[2]=GetZ(det);
219   
220 }
221 //_____________________________________________________________________________
222 void AliTOFGeometry::GetDetID( Float_t *pos, Int_t *det) const
223 {
224  //
225  // Returns Detector Indices (iSect,iPlate,iStrip,iPadX,iPadZ) 
226  // space point coor (x,y,z) (cm)  
227
228
229   det[0]=GetSector(pos);  
230   det[1]=GetPlate(pos);  
231   det[2]=GetStrip(pos);
232   det[3]=GetPadZ(pos);
233   det[4]=GetPadX(pos);
234   
235 }
236 //_____________________________________________________________________________
237
238 void AliTOFGeometry::DetToStripRF(Int_t nPadX, Int_t nPadZ, Float_t &x,  Float_t &z) const
239 {
240   //
241   // Returns the local coordinates (x, z) in strip reference frame
242   // for the bottom corner of the pad number (nPadX, nPadZ)
243   //
244   /*
245   const Float_t xCenterStrip = kNpadX * fgkXPad / 2.;
246   const Float_t zCenterStrip = kNpadZ * fgkZPad / 2.;
247
248   const Float_t xCenterPad = nPadX*fgkXPad + fgkXPad / 2.;
249   const Float_t zCenterPad = nPadZ*fgkZPad + fgkZPad / 2.;
250
251   x = xCenterPad - xCenterStrip;
252   z = zCenterPad - zCenterStrip;
253   */
254
255
256   x = (nPadX - kNpadX*0.5) * fgkXPad;
257   z = (nPadZ - kNpadZ*0.5) * fgkZPad;
258
259
260 }
261 //_____________________________________________________________________________
262 Float_t AliTOFGeometry::DistanceToPadPar(Int_t *det, Float_t *pos, Float_t *dist3d) const
263 {
264 //
265 // Returns distance of  space point with coor pos (x,y,z) (cm) wrt 
266 // pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
267 //
268     
269   //Transform pos into Sector Frame
270
271   Float_t x = pos[0];
272   Float_t y = pos[1];
273   Float_t z = pos[2];
274
275   Float_t radius = TMath::Sqrt(x*x+y*y);
276   //Float_t phi=TMath::ATan(y/x);       
277   //if(phi<0) phi = k2PI+phi; //2.*TMath::Pi()+phi;
278   Float_t phi = TMath::Pi()+TMath::ATan2(-y,-x);        
279   //  Get the local angle in the sector philoc
280   Float_t angle   = phi*kRaddeg-( Int_t (kRaddeg*phi/fgkPhiSec) + 0.5)*fgkPhiSec;
281   Float_t xs = radius*TMath::Cos(angle/kRaddeg);
282   Float_t ys = radius*TMath::Sin(angle/kRaddeg);
283   Float_t zs = z;
284
285   // Do the same for the selected pad
286
287   Float_t g[3];
288   GetPosPar(det,g);
289
290   Float_t padRadius = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
291   //Float_t padPhi = TMath::ATan(g[1]/g[0]);    
292   //if(padPhi<0) padPhi = k2Pi + padPhi;
293   Float_t padPhi = TMath::Pi()+TMath::ATan2(-g[1],-g[0]);       
294
295   //  Get the local angle in the sector philoc
296   Float_t padAngle = padPhi*kRaddeg-( Int_t (padPhi*kRaddeg/fgkPhiSec)+ 0.5) * fgkPhiSec;
297   Float_t padxs = padRadius*TMath::Cos(padAngle/kRaddeg);
298   Float_t padys = padRadius*TMath::Sin(padAngle/kRaddeg);
299   Float_t padzs = g[2];
300   
301   //Now move to local pad coordinate frame. Translate:
302   
303   Float_t xt = xs-padxs;
304   Float_t yt = ys-padys;
305   Float_t zt = zs-padzs;
306   //Now Rotate:
307   
308   Float_t alpha = GetAngles(det[1],det[2]);
309   Float_t xr =  xt*TMath::Cos(alpha/kRaddeg)+zt*TMath::Sin(alpha/kRaddeg);
310   Float_t yr =  yt;
311   Float_t zr = -xt*TMath::Sin(alpha/kRaddeg)+zt*TMath::Cos(alpha/kRaddeg);
312
313   Float_t dist = TMath::Sqrt(xr*xr+yr*yr+zr*zr);
314
315   if (dist3d){
316     dist3d[0] = xr;
317     dist3d[1] = yr;
318     dist3d[2] = zr;
319   }
320
321   return dist;
322
323 }
324 //_____________________________________________________________________________
325 Bool_t AliTOFGeometry::IsInsideThePadPar(Int_t *det, Float_t *pos) const
326 {
327 //
328 // Returns true if space point with coor pos (x,y,z) (cm) falls 
329 // inside pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
330 //
331
332   Bool_t isInside=false; 
333
334   /*
335   const Float_t khhony    = 1.0          ; // heigth of HONY  Layer
336   const Float_t khpcby    = 0.08         ; // heigth of PCB   Layer
337   const Float_t khrgly    = 0.055        ; // heigth of RED GLASS  Layer
338   const Float_t khglfy    = 0.285        ; // heigth of GLASS+FISHLINE  Layer
339   const Float_t khcpcby   = 0.16         ; // heigth of PCB  Central Layer
340   //const Float_t kwcpcbz   = 12.4         ; // z dimension of PCB  Central Layer
341   const Float_t khstripy = 2.*khhony+2.*khpcby+4.*khrgly+2.*khglfy+khcpcby;//3.11
342   //const Float_t kwstripz = kwcpcbz;
343   //const Float_t klstripx = fgkStripLength;
344   */
345
346   const Float_t kPadDepth = 0.5;//0.05;//0.11;//0.16;//          // heigth of Sensitive Layer
347
348   //Transform pos into Sector Frame
349
350   Float_t x = pos[0];
351   Float_t y = pos[1];
352   Float_t z = pos[2];
353
354   Float_t radius = TMath::Sqrt(x*x+y*y);
355   Float_t phi = TMath::Pi()+TMath::ATan2(-y,-x);        
356
357   //  Get the local angle in the sector philoc
358   Float_t angle = phi*kRaddeg-( Int_t (kRaddeg*phi/fgkPhiSec) + 0.5) *fgkPhiSec;
359   Float_t xs = radius*TMath::Cos(angle/kRaddeg);
360   Float_t ys = radius*TMath::Sin(angle/kRaddeg);
361   Float_t zs = z;
362
363   // Do the same for the selected pad
364
365   Float_t g[3];
366   GetPosPar(det,g);
367
368   Float_t padRadius = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
369   Float_t padPhi = TMath::Pi()+TMath::ATan2(-g[1],-g[0]);       
370
371   //  Get the local angle in the sector philoc
372   Float_t padAngle = padPhi*kRaddeg-( Int_t (padPhi*kRaddeg/fgkPhiSec)+ 0.5) * fgkPhiSec; 
373   Float_t padxs = padRadius*TMath::Cos(padAngle/kRaddeg);
374   Float_t padys = padRadius*TMath::Sin(padAngle/kRaddeg);
375   Float_t padzs = g[2];
376
377   //Now move to local pad coordinate frame. Translate:
378
379   Float_t xt = xs-padxs;
380   Float_t yt = ys-padys;
381   Float_t zt = zs-padzs;
382
383   //Now Rotate:
384
385   Float_t alpha = GetAngles(det[1],det[2]);
386   Float_t xr =  xt*TMath::Cos(alpha/kRaddeg)+zt*TMath::Sin(alpha/kRaddeg);
387   Float_t yr =  yt;
388   Float_t zr = -xt*TMath::Sin(alpha/kRaddeg)+zt*TMath::Cos(alpha/kRaddeg);
389
390   if(TMath::Abs(xr)<=kPadDepth*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5))
391     isInside=true;
392   return isInside;
393
394 }
395 //_____________________________________________________________________________
396 Bool_t AliTOFGeometry::IsInsideThePad(TGeoHMatrix mat, Float_t *pos, Float_t *dist3d) const
397 {
398 //
399 // Returns true if space point with coor pos (x,y,z) (cm) falls 
400 // inside pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
401 //
402
403   const Float_t kPadDepth = 0.5;      // heigth of Sensitive Layer
404   Double_t vecg[3];
405   vecg[0]=pos[0];
406   vecg[1]=pos[1];
407   vecg[2]=pos[2];
408   Double_t veclr[3]={-1.,-1.,-1.};
409   Double_t vecl[3]={-1.,-1.,-1.};
410   mat.MasterToLocal(vecg,veclr);  
411   vecl[0]=veclr[1];
412   vecl[1]=veclr[0];
413   //take into account reflections 
414   vecl[2]=-veclr[2];
415
416   Float_t xr = vecl[0];
417   Float_t yr = vecl[1];
418   Float_t zr = vecl[2];
419
420   if (dist3d){
421     dist3d[0] = vecl[0];
422     dist3d[1] = vecl[1];
423     dist3d[2] = vecl[2];
424   }
425  
426   Bool_t isInside=false; 
427   if(TMath::Abs(xr)<= kPadDepth*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5))
428     isInside=true; 
429   return isInside;
430
431 }
432 //_____________________________________________________________________________
433 void AliTOFGeometry::GetVolumePath(Int_t *ind, Char_t *path ) {
434   //--------------------------------------------------------------------
435   // This function returns the colume path of a given pad 
436   //--------------------------------------------------------------------
437   Int_t sector = ind[0];
438   Char_t  string1[100];
439   Char_t  string2[100];
440   Char_t  string3[100];
441   
442   Int_t icopy=-1;
443   icopy=sector;
444  
445   sprintf(string1,"/ALIC_1/B077_1/BSEGMO%i_1/BTOF%i_1",icopy,icopy);
446   
447   Int_t iplate=ind[1];
448   Int_t istrip=ind[2];
449   if( iplate==0) icopy=istrip; 
450   if( iplate==1) icopy=istrip+NStripC(); 
451   if( iplate==2) icopy=istrip+NStripC()+NStripB(); 
452   if( iplate==3) icopy=istrip+NStripC()+NStripB()+NStripA(); 
453   if( iplate==4) icopy=istrip+NStripC()+2*NStripB()+NStripA(); 
454   icopy++;
455   sprintf(string2,"FTOA_0/FLTA_0/FSTR_%i",icopy);
456   if(fHoles && (sector==13 || sector==14 || sector==15)){
457     if(iplate<2)  sprintf(string2,"FTOB_0/FLTB_0/FSTR_%i",icopy);
458     if(iplate>2)  sprintf(string2,"FTOC_0/FLTC_0/FSTR_%i",icopy);
459   }
460  
461   Int_t padz = ind[3]+1; 
462   Int_t padx = ind[4]+1;
463   sprintf(string3,"FPCB_1/FSEN_1/FSEZ_%i/FPAD_%i",padz,padx);
464   sprintf(path,"%s/%s/%s",string1,string2,string3); 
465
466 }
467 //_____________________________________________________________________________
468 void AliTOFGeometry::GetVolumePath(Int_t sector, Char_t *path ){
469   //--------------------------------------------------------------------
470   // This function returns the colume path of a given sector 
471   //--------------------------------------------------------------------
472
473   Char_t string[100];
474
475   Int_t icopy = sector;
476
477   sprintf(string,"/ALIC_1/B077_1/BSEGMO%i_1/BTOF%i_1",icopy,icopy);
478   sprintf(path,"%s",string);
479
480 }
481 //_____________________________________________________________________________
482 void AliTOFGeometry::GetVolumePath(Int_t sector, Int_t plate, Int_t strip, Char_t *path ) {
483   //--------------------------------------------------------------------
484   // This function returns the colume path of a given strip 
485   //--------------------------------------------------------------------
486
487   Char_t string1[100];
488   Char_t string2[100];
489   Char_t string3[100];
490   
491   Int_t icopy = sector;
492
493   sprintf(string1,"/ALIC_1/B077_1/BSEGMO%i_1/BTOF%i_1",icopy,icopy);
494   
495   if(plate==0) icopy=strip; 
496   if(plate==1) icopy=strip+NStripC(); 
497   if(plate==2) icopy=strip+NStripC()+NStripB(); 
498   if(plate==3) icopy=strip+NStripC()+NStripB()+NStripA(); 
499   if(plate==4) icopy=strip+NStripC()+2*NStripB()+NStripA(); 
500   icopy++;
501   sprintf(string2,"FTOA_0/FLTA_0/FSTR_%i",icopy);
502   if(fHoles && (sector==13 || sector==14 || sector==15)){
503     if(plate<2)  sprintf(string2,"FTOB_0/FLTB_0/FSTR_%i",icopy);
504     if(plate>2)  sprintf(string2,"FTOC_0/FLTC_0/FSTR_%i",icopy);
505   }
506
507   sprintf(string3,"FPCB_1/FSEN_1");
508   sprintf(path,"%s/%s/%s",string1,string2,string3); 
509
510 }
511 //_____________________________________________________________________________
512 void AliTOFGeometry::GetPos(Int_t *det, Float_t *pos) 
513 {
514 //
515 // Returns space point coor (x,y,z) (cm)  for Detector 
516 // Indices  (iSect,iPlate,iStrip,iPadX,iPadZ) 
517 //
518   Char_t path[100];
519   GetVolumePath(det,path );
520   if (!gGeoManager) {
521     printf("ERROR: no TGeo\n");
522   }
523   gGeoManager->cd(path);
524   TGeoHMatrix global;
525   global = *gGeoManager->GetCurrentMatrix();
526   const Double_t *tr = global.GetTranslation();
527
528   pos[0]=tr[0];  
529   pos[1]=tr[1];  
530   pos[2]=tr[2];
531 }
532 //_____________________________________________________________________________
533 Int_t AliTOFGeometry::GetPlate(Float_t *pos) const
534 {
535   //
536   // Returns the Plate index 
537   //
538   const Float_t kInterCentrModBorder1 = 49.5;
539   const Float_t kInterCentrModBorder2 = 57.5;
540   const Float_t kExterInterModBorder1 = 196.0;
541   const Float_t kExterInterModBorder2 = 203.5;
542
543   const Float_t kLengthExInModBorder  = 4.7;
544   const Float_t kLengthInCeModBorder  = 7.0;
545
546   //const Float_t khAlWall = 0.1;
547   const Float_t kModuleWallThickness = 0.3;
548   //const Float_t kHoneycombLayerThickness = 1.5;
549
550   Int_t iPlate=-1;
551
552   Float_t posLocal[3];
553   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
554
555   Int_t isector = GetSector(posLocal);
556   if(isector == -1){
557     //AliError("Detector Index could not be determined");
558     return iPlate;
559   }
560
561   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
562   Double_t angles[6] = 
563     {90., 90.+(isector+0.5)*fgkPhiSec,
564       0., 0.,
565      90., (isector+0.5)*fgkPhiSec
566     };
567   Rotation(posLocal,angles);
568
569   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
570   Translation(posLocal,step);
571
572   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
573   angles[0] = 90.;
574   angles[1] =  0.;
575   angles[2] =  0.;
576   angles[3] =  0.;
577   angles[4] = 90.;
578   angles[5] =270.;
579
580   Rotation(posLocal,angles);
581
582   Float_t yLocal = posLocal[1];
583   Float_t zLocal = posLocal[2];
584
585   Float_t deltaRhoLoc  = (fgkRmax-fgkRmin)*0.5 - kModuleWallThickness + yLocal;
586   Float_t deltaZetaLoc = TMath::Abs(zLocal);
587
588   Float_t deltaRHOmax = 0.;
589
590   if (TMath::Abs(zLocal)>=kExterInterModBorder1 && TMath::Abs(zLocal)<=kExterInterModBorder2) 
591     {
592       deltaRhoLoc -= kLengthExInModBorder;
593       deltaZetaLoc = kExterInterModBorder2-deltaZetaLoc;
594       deltaRHOmax  = (fgkRmax - fgkRmin)*0.5 - kModuleWallThickness - 2.*kLengthExInModBorder; // old 5.35, new 4.8
595
596       if (deltaRhoLoc > deltaZetaLoc*deltaRHOmax/(kInterCentrModBorder2-kInterCentrModBorder1)) {
597         if (zLocal<0) iPlate = 0;
598         else iPlate = 4;
599       }
600       else {
601         if (zLocal<0) iPlate = 1;
602         else iPlate = 3;
603       }
604     }
605   else if (TMath::Abs(zLocal)>=kInterCentrModBorder1 && TMath::Abs(zLocal)<=kInterCentrModBorder2) 
606     {
607       deltaRhoLoc -= kLengthInCeModBorder;
608       deltaZetaLoc = deltaZetaLoc-kInterCentrModBorder1;
609       deltaRHOmax = (fgkRmax - fgkRmin)*0.5 - kModuleWallThickness - 2.*kLengthInCeModBorder; // old 0.39, new 0.2
610
611       if (deltaRhoLoc>deltaZetaLoc*deltaRHOmax/(kInterCentrModBorder2-kInterCentrModBorder1)) iPlate = 2;
612       else {
613         if (zLocal<0) iPlate = 1;
614         else iPlate = 3;
615       }
616     }
617
618   if      (zLocal>-fgkZlenA*0.5/*fgkMaxhZtof*/ && zLocal<-kExterInterModBorder2)       iPlate = 0;
619   else if (zLocal>-kExterInterModBorder1       && zLocal<-kInterCentrModBorder2)       iPlate = 1;
620   else if (zLocal>-kInterCentrModBorder1       && zLocal< kInterCentrModBorder1)       iPlate = 2;
621   else if (zLocal> kInterCentrModBorder2       && zLocal< kExterInterModBorder1)       iPlate = 3;
622   else if (zLocal> kExterInterModBorder2       && zLocal< fgkZlenA*0.5/*fgkMaxhZtof*/) iPlate = 4;
623   
624   return iPlate;
625
626 }
627
628 //_____________________________________________________________________________
629 Int_t AliTOFGeometry::GetSector(Float_t *pos) const
630 {
631   //
632   // Returns the Sector index 
633   //
634
635   //const Float_t khAlWall = 0.1;
636   //const Float_t kModuleWallThickness = 0.3;
637
638   Int_t   iSect = -1; 
639
640   Float_t x = pos[0];
641   Float_t y = pos[1];
642   Float_t z = pos[2];
643
644   Float_t rho = TMath::Sqrt(x*x + y*y);
645
646   //if (!((z>=-fgkMaxhZtof && z<=fgkMaxhZtof) &&
647   if (!((z>=-fgkZlenA*0.5 && z<=fgkZlenA*0.5) &&
648         (rho>=(fgkRmin) && rho<=(fgkRmax)))) {
649     //(rho>=(fgkRmin-0.05)+kModuleWallThickness && rho<=(fgkRmax-0.05)-kModuleWallThickness-khAlWall-kModuleWallThickness))) {
650     //AliError("Detector Index could not be determined");
651     return iSect;
652   }
653
654   Float_t phi = TMath::Pi() + TMath::ATan2(-y,-x);      
655
656   iSect  = (Int_t) (phi*kRaddeg/fgkPhiSec);
657   
658   return iSect;
659
660 }
661 //_____________________________________________________________________________
662 Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
663 {
664   //
665   // Returns the Strip index 
666   //
667   const Float_t khhony    = 1.0          ; // heigth of HONY  Layer
668   const Float_t khpcby    = 0.08         ; // heigth of PCB   Layer
669   const Float_t khrgly    = 0.055        ; // heigth of RED GLASS  Layer
670   const Float_t khglfy    = 0.285        ; // heigth of GLASS+FISHLINE  Layer
671   const Float_t khcpcby   = 0.16         ; // heigth of PCB  Central Layer
672   const Float_t kwcpcbz   = 12.4         ; // z dimension of PCB  Central Layer
673   const Float_t khstripy = 2.*khhony+2.*khpcby+4.*khrgly+2.*khglfy+khcpcby;//3.11
674   const Float_t kwstripz = kwcpcbz;
675   const Float_t klstripx = fgkStripLength;
676   
677   Int_t iStrip=-1;
678    
679   Float_t posLocal[3];
680   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
681  
682   Int_t isector = GetSector(posLocal);
683   if(isector == -1){
684     //AliError("Detector Index could not be determined");
685     return iStrip;}
686   Int_t iplate =  GetPlate(posLocal);
687   if(iplate == -1){
688     //AliError("Detector Index could not be determined");
689     return iStrip;} 
690
691   Int_t nstrips=0;
692   switch (iplate) {
693   case 0:
694     nstrips=kNStripC;
695     break;
696   case 4:
697     nstrips=kNStripC;
698     break;
699   case 1:
700     nstrips=kNStripB;
701     break;
702   case 3:
703     nstrips=kNStripB;
704     break;
705   case 2:
706     nstrips=kNStripA;
707     break;
708   }
709   
710   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
711   Double_t angles[6] = 
712     {90., 90.+(isector+0.5)*fgkPhiSec,
713       0., 0.,
714      90., (isector+0.5)*fgkPhiSec
715     };
716   Rotation(posLocal,angles);
717
718   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
719   Translation(posLocal,step);
720
721   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
722   angles[0] = 90.;
723   angles[1] =  0.;
724   angles[2] =  0.;
725   angles[3] =  0.;
726   angles[4] = 90.;
727   angles[5] =270.;
728
729   Rotation(posLocal,angles);
730
731   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
732   Int_t totStrip=0;
733   for (Int_t istrip=0; istrip<nstrips; istrip++){
734
735     Float_t posLoc2[3]={posLocal[0],posLocal[1],posLocal[2]};         
736
737     step[0] = 0.;
738     step[1] = GetHeights(iplate,istrip);
739     step[2] = -GetDistances(iplate,istrip);
740     Translation(posLoc2,step);
741
742     if      (GetAngles(iplate,istrip) >0.) {
743       angles[0] = 90.;
744       angles[1] =  0.;
745       angles[2] = 90.+GetAngles(iplate,istrip);
746       angles[3] = 90.;
747       angles[4] = GetAngles(iplate,istrip);
748       angles[5] = 90.;
749     }
750     else if (GetAngles(iplate,istrip)==0.) {
751       angles[0] = 90.;
752       angles[1] =  0.;
753       angles[2] = 90.;
754       angles[3] = 90.;
755       angles[4] =  0;
756       angles[5] =  0.;
757     }
758     else if (GetAngles(iplate,istrip) <0.) {
759       angles[0] = 90.;
760       angles[1] =  0.;
761       angles[2] = 90.+GetAngles(iplate,istrip);
762       angles[3] = 90.;
763       angles[4] =-GetAngles(iplate,istrip);
764       angles[5] = 270.;
765     }
766     Rotation(posLoc2,angles);
767
768     if ((TMath::Abs(posLoc2[0])<=klstripx*0.5) &&
769         (TMath::Abs(posLoc2[1])<=khstripy*0.5) &&
770         (TMath::Abs(posLoc2[2])<=kwstripz*0.5)) {
771       iStrip = istrip;
772       totStrip++;
773       for (Int_t jj=0; jj<3; jj++) posLocal[jj]=posLoc2[jj];
774       //AliInfo(Form(" posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ", posLocal[0],posLocal[1],posLocal[2]));
775
776       //AliInfo(Form(" GetAngles(%1i,%2i) = %f, pos[0] = %f, pos[1] = %f, pos[2] = %f", iplate, istrip, GetAngles(iplate,istrip), pos[0], pos[1], pos[2]));
777       break;
778     }
779
780     if (totStrip>1) AliInfo(Form("total strip number found %2i",totStrip));
781
782   }
783
784   return iStrip;
785   
786 }
787 //_____________________________________________________________________________
788 Int_t AliTOFGeometry::GetPadZ(Float_t *pos) const
789 {
790   //
791   // Returns the Pad index along Z 
792   //
793   //const Float_t klsensmx = kNpadX*fgkXPad;  // length of Sensitive Layer
794   //const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer
795   //const Float_t kwsensmz = kNpadZ*fgkZPad;  // width of Sensitive Layer
796
797   Int_t iPadZ = -1;
798
799   Float_t posLocal[3];
800   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
801  
802   Int_t isector = GetSector(posLocal);
803   if(isector == -1){
804     //AliError("Detector Index could not be determined");
805     return iPadZ;}
806   Int_t iplate =  GetPlate(posLocal);
807   if(iplate == -1){
808     //AliError("Detector Index could not be determined");
809     return iPadZ;}
810   Int_t istrip =  GetStrip(posLocal);
811   if(istrip == -1){
812     //AliError("Detector Index could not be determined");
813     return iPadZ;}
814
815   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
816   Double_t angles[6] = 
817     {90., 90.+(isector+0.5)*fgkPhiSec,
818       0., 0.,
819      90., (isector+0.5)*fgkPhiSec
820     };
821   Rotation(posLocal,angles);
822
823   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
824   Translation(posLocal,step);
825
826   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
827   angles[0] = 90.;
828   angles[1] =  0.;
829   angles[2] =  0.;
830   angles[3] =  0.;
831   angles[4] = 90.;
832   angles[5] =270.;
833
834   Rotation(posLocal,angles);
835
836   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
837   step[0] = 0.;
838   step[1] = GetHeights(iplate,istrip);
839   step[2] = -GetDistances(iplate,istrip);
840   Translation(posLocal,step);
841
842   if      (GetAngles(iplate,istrip) >0.) {
843     angles[0] = 90.;
844     angles[1] =  0.;
845     angles[2] = 90.+GetAngles(iplate,istrip);
846     angles[3] = 90.;
847     angles[4] = GetAngles(iplate,istrip);
848     angles[5] = 90.;
849   }
850   else if (GetAngles(iplate,istrip)==0.) {
851     angles[0] = 90.;
852     angles[1] =  0.;
853     angles[2] = 90.;
854     angles[3] = 90.;
855     angles[4] =  0;
856     angles[5] =  0.;
857   }
858   else if (GetAngles(iplate,istrip) <0.) {
859     angles[0] = 90.;
860     angles[1] =  0.;
861     angles[2] = 90.+GetAngles(iplate,istrip);
862     angles[3] = 90.;
863     angles[4] =-GetAngles(iplate,istrip);
864     angles[5] = 270.;
865   }
866   Rotation(posLocal,angles);
867
868   //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
869   //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
870
871     step[0] =-0.5*kNpadX*fgkXPad;
872     step[1] = 0.;
873     step[2] =-0.5*kNpadZ*fgkZPad;
874     Translation(posLocal,step);
875
876     iPadZ = (Int_t)(posLocal[2]/fgkZPad);
877     if (iPadZ==kNpadZ) iPadZ--;
878     else if (iPadZ>kNpadZ) iPadZ=-1;
879
880   //}
881   // else AliError("Detector Index could not be determined");
882
883   return iPadZ;
884
885 }
886 //_____________________________________________________________________________
887 Int_t AliTOFGeometry::GetPadX(Float_t *pos) const
888 {
889   //
890   // Returns the Pad index along X 
891   //
892   //const Float_t klsensmx = kNpadX*fgkXPad;  // length of Sensitive Layer
893   //const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer
894   //const Float_t kwsensmz = kNpadZ*fgkZPad;  // width of Sensitive Layer
895
896   Int_t iPadX  = -1;
897
898   Float_t posLocal[3];
899   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
900  
901   Int_t isector = GetSector(posLocal);
902   if(isector == -1){
903     //AliError("Detector Index could not be determined");
904     return iPadX;}
905   Int_t iplate =  GetPlate(posLocal);
906   if(iplate == -1){
907     //AliError("Detector Index could not be determined");
908     return iPadX;} 
909   Int_t istrip =  GetStrip(posLocal);
910   if(istrip == -1){  
911     //AliError("Detector Index could not be determined");
912     return iPadX;}
913
914   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
915   Double_t angles[6] = 
916     {90., 90.+(isector+0.5)*fgkPhiSec,
917       0.,  0.,
918      90., (isector+0.5)*fgkPhiSec
919     };
920   Rotation(posLocal,angles);
921
922   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
923   Translation(posLocal,step);
924
925   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
926   angles[0] = 90.;
927   angles[1] =  0.;
928   angles[2] =  0.;
929   angles[3] =  0.;
930   angles[4] = 90.;
931   angles[5] =270.;
932
933   Rotation(posLocal,angles);
934
935   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
936   step[0] = 0.;
937   step[1] = GetHeights(iplate,istrip);
938   step[2] = -GetDistances(iplate,istrip);
939   Translation(posLocal,step);
940
941   if      (GetAngles(iplate,istrip) >0.) {
942     angles[0] = 90.;
943     angles[1] =  0.;
944     angles[2] = 90.+GetAngles(iplate,istrip);
945     angles[3] = 90.;
946     angles[4] = GetAngles(iplate,istrip);
947     angles[5] = 90.;
948   }
949   else if (GetAngles(iplate,istrip)==0.) {
950     angles[0] = 90.;
951     angles[1] =  0.;
952     angles[2] = 90.;
953     angles[3] = 90.;
954     angles[4] =  0;
955     angles[5] =  0.;
956   }
957   else if (GetAngles(iplate,istrip) <0.) {
958     angles[0] = 90.;
959     angles[1] =  0.;
960     angles[2] = 90.+GetAngles(iplate,istrip);
961     angles[3] = 90.;
962     angles[4] =-GetAngles(iplate,istrip);
963     angles[5] = 270.;
964   }
965   Rotation(posLocal,angles);
966
967   //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
968   //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
969
970     step[0] =-0.5*kNpadX*fgkXPad;
971     step[1] = 0.;
972     step[2] =-0.5*kNpadZ*fgkZPad;
973     Translation(posLocal,step);
974
975     iPadX = (Int_t)(posLocal[0]/fgkXPad);
976     if (iPadX==kNpadX) iPadX--;
977     else if (iPadX>kNpadX) iPadX=-1;
978
979   //}
980   //else AliError("Detector Index could not be determined");
981
982   return iPadX;
983
984 }
985 //_____________________________________________________________________________
986 Float_t AliTOFGeometry::GetX(Int_t *det) const
987 {
988   //
989   // Returns X coordinate (cm)
990   //
991
992   Int_t isector = det[0];
993   Int_t iplate  = det[1];
994   Int_t istrip  = det[2];
995   Int_t ipadz   = det[3];
996   Int_t ipadx   = det[4];
997
998   /*
999   // Find out distance d on the plane wrt median phi:
1000   Float_t d = (ipadx+0.5-kNpadX*0.5)*fgkXPad;
1001
1002   // The radius r in xy plane:
1003   //Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
1004   //  (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg)-0.25; ???
1005   Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
1006     (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg);
1007
1008   // local azimuthal angle in the sector philoc
1009   Float_t philoc  = TMath::ATan(d/r);
1010   //if(philoc<0.) philoc = k2PI + philoc;
1011
1012   // azimuthal angle in the global frame  phi
1013   Float_t phi   = philoc*kRaddeg+(isector+0.5)*fgkPhiSec;
1014
1015   Float_t xCoor = r/TMath::Cos(philoc)*TMath::Cos(phi/kRaddeg);
1016   */
1017
1018   // Pad reference frame -> FSTR reference frame
1019   //  /*
1020   Float_t posLocal[3] = {0., 0., 0.};
1021   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
1022   Translation(posLocal,step);
1023
1024   step[0] = kNpadX*0.5*fgkXPad;
1025   step[1] = 0.;
1026   step[2] = kNpadZ*0.5*fgkZPad;
1027   //  */
1028   /*
1029   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
1030   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
1031   */
1032   Translation(posLocal,step);
1033
1034   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
1035   Double_t angles[6];
1036   if      (GetAngles(iplate,istrip) >0.) {
1037     angles[0] = 90.;
1038     angles[1] =  0.;
1039     angles[2] = 90.+GetAngles(iplate,istrip);
1040     angles[3] = 90.;
1041     angles[4] = GetAngles(iplate,istrip);
1042     angles[5] = 90.;
1043   }
1044   else if (GetAngles(iplate,istrip)==0.) {
1045     angles[0] = 90.;
1046     angles[1] =  0.;
1047     angles[2] = 90.;
1048     angles[3] = 90.;
1049     angles[4] =  0;
1050     angles[5] =  0.;
1051   }
1052   else if (GetAngles(iplate,istrip) <0.) {
1053     angles[0] = 90.;
1054     angles[1] =  0.;
1055     angles[2] = 90.+GetAngles(iplate,istrip);
1056     angles[3] = 90.;
1057     angles[4] =-GetAngles(iplate,istrip);
1058     angles[5] = 270.;
1059   }
1060
1061   InverseRotation(posLocal,angles);
1062
1063   step[0] = 0.;
1064   step[1] = -GetHeights(iplate,istrip);
1065   step[2] =  GetDistances(iplate,istrip);
1066   Translation(posLocal,step);
1067
1068   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1069   angles[0] = 90.;
1070   angles[1] =  0.;
1071   angles[2] =  0.;
1072   angles[3] =  0.;
1073   angles[4] = 90.;
1074   angles[5] =270.;
1075
1076   InverseRotation(posLocal,angles);
1077
1078   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
1079   step[0] = 0.;
1080   step[1] = 0.;
1081   step[2] = -((fgkRmax+fgkRmin)*0.5);
1082   Translation(posLocal,step);
1083
1084   angles[0] = 90.;
1085   angles[1] = 90.+(isector+0.5)*fgkPhiSec;
1086   angles[2] = 0.;
1087   angles[3] = 0.;
1088   angles[4] = 90.;
1089   angles[5] = (isector+0.5)*fgkPhiSec;
1090
1091   InverseRotation(posLocal,angles);
1092
1093   Float_t xCoor = posLocal[0];
1094
1095   return xCoor;
1096
1097 }
1098 //_____________________________________________________________________________
1099 Float_t AliTOFGeometry::GetY(Int_t *det) const
1100 {
1101   //
1102   // Returns Y coordinate (cm)
1103   //
1104
1105   Int_t isector = det[0];
1106   Int_t iplate  = det[1];
1107   Int_t istrip  = det[2];
1108   Int_t ipadz   = det[3];
1109   Int_t ipadx   = det[4];
1110
1111   /*
1112   // Find out distance d on the plane wrt median phi:
1113   Float_t d = (ipadx+0.5-kNpadX*0.5)*fgkXPad;
1114
1115   // The radius r in xy plane:
1116   //Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
1117   //  (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg)-0.25; ???
1118   Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
1119     (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg);
1120
1121   // local azimuthal angle in the sector philoc
1122   Float_t philoc = TMath::ATan(d/r);
1123   //if(philoc<0.) philoc = k2PI + philoc;
1124
1125   // azimuthal angle in the global frame  phi
1126   Float_t phi   = philoc*kRaddeg+(isector+0.5)*fgkPhiSec;
1127
1128   Float_t yCoor = r/TMath::Cos(philoc)*TMath::Sin(phi/kRaddeg);
1129   */
1130
1131   // Pad reference frame -> FSTR reference frame
1132   //  /*
1133   Float_t posLocal[3] = {0., 0., 0.};
1134   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
1135   Translation(posLocal,step);
1136
1137   step[0] = kNpadX*0.5*fgkXPad;
1138   step[1] = 0.;
1139   step[2] = kNpadZ*0.5*fgkZPad;
1140   //  */
1141   /*
1142   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
1143   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
1144   */
1145   Translation(posLocal,step);
1146
1147   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
1148
1149   Double_t angles[6];
1150   if      (GetAngles(iplate,istrip) >0.) {
1151     angles[0] = 90.;
1152     angles[1] =  0.;
1153     angles[2] = 90.+GetAngles(iplate,istrip);
1154     angles[3] = 90.;
1155     angles[4] = GetAngles(iplate,istrip);
1156     angles[5] = 90.;
1157   }
1158   else if (GetAngles(iplate,istrip)==0.) {
1159     angles[0] = 90.;
1160     angles[1] =  0.;
1161     angles[2] = 90.;
1162     angles[3] = 90.;
1163     angles[4] =  0;
1164     angles[5] =  0.;
1165   }
1166   else if (GetAngles(iplate,istrip) <0.) {
1167     angles[0] = 90.;
1168     angles[1] =  0.;
1169     angles[2] = 90.+GetAngles(iplate,istrip);
1170     angles[3] = 90.;
1171     angles[4] =-GetAngles(iplate,istrip);
1172     angles[5] = 270.;
1173   }
1174
1175   InverseRotation(posLocal,angles);
1176
1177   step[0] = 0.;
1178   step[1] = -GetHeights(iplate,istrip);
1179   step[2] =  GetDistances(iplate,istrip);
1180   Translation(posLocal,step);
1181
1182   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1183   angles[0] = 90.;
1184   angles[1] =  0.;
1185   angles[2] =  0.;
1186   angles[3] =  0.;
1187   angles[4] = 90.;
1188   angles[5] =270.;
1189
1190   InverseRotation(posLocal,angles);
1191
1192   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
1193   step[0] = 0.;
1194   step[1] = 0.;
1195   step[2] = -((fgkRmax+fgkRmin)*0.5);
1196   Translation(posLocal,step);
1197
1198   angles[0] = 90.;
1199   angles[1] = 90.+(isector+0.5)*fgkPhiSec;
1200   angles[2] = 0.;
1201   angles[3] = 0.;
1202   angles[4] = 90.;
1203   angles[5] = (isector+0.5)*fgkPhiSec;
1204
1205   InverseRotation(posLocal,angles);
1206
1207   Float_t yCoor = posLocal[1];
1208
1209   return yCoor;
1210
1211 }
1212
1213 //_____________________________________________________________________________
1214 Float_t AliTOFGeometry::GetZ(Int_t *det) const
1215 {
1216   //
1217   // Returns Z coordinate (cm)
1218   //
1219
1220   Int_t isector = det[0];
1221   Int_t iplate  = det[1];
1222   Int_t istrip  = det[2];
1223   Int_t ipadz   = det[3];
1224   Int_t ipadx   = det[4];
1225
1226   /*
1227   Float_t zCoor = GetDistances(iplate,istrip) +
1228     (0.5-ipadz) * fgkZPad * TMath::Cos(GetAngles(iplate,istrip)*kDegrad);
1229   */
1230
1231   // Pad reference frame -> FSTR reference frame
1232   //  /*
1233   Float_t posLocal[3] = {0., 0., 0.};
1234   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
1235   Translation(posLocal,step);
1236
1237   step[0] = kNpadX*0.5*fgkXPad;
1238   step[1] = 0.;
1239   step[2] = kNpadZ*0.5*fgkZPad;
1240   //  */
1241   /*
1242   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
1243   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
1244   */
1245   Translation(posLocal,step);
1246
1247   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
1248   Double_t angles[6];
1249   if      (GetAngles(iplate,istrip) >0.) {
1250     angles[0] = 90.;
1251     angles[1] =  0.;
1252     angles[2] = 90.+GetAngles(iplate,istrip);
1253     angles[3] = 90.;
1254     angles[4] = GetAngles(iplate,istrip);
1255     angles[5] = 90.;
1256   }
1257   else if (GetAngles(iplate,istrip)==0.) {
1258     angles[0] = 90.;
1259     angles[1] =  0.;
1260     angles[2] = 90.;
1261     angles[3] = 90.;
1262     angles[4] =  0;
1263     angles[5] =  0.;
1264   }
1265   else if (GetAngles(iplate,istrip) <0.) {
1266     angles[0] = 90.;
1267     angles[1] =  0.;
1268     angles[2] = 90.+GetAngles(iplate,istrip);
1269     angles[3] = 90.;
1270     angles[4] =-GetAngles(iplate,istrip);
1271     angles[5] = 270.;
1272   }
1273
1274   InverseRotation(posLocal,angles);
1275
1276   step[0] = 0.;
1277   step[1] = -GetHeights(iplate,istrip);
1278   step[2] =  GetDistances(iplate,istrip);
1279   Translation(posLocal,step);
1280
1281   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1282   angles[0] = 90.;
1283   angles[1] =  0.;
1284   angles[2] =  0.;
1285   angles[3] =  0.;
1286   angles[4] = 90.;
1287   angles[5] =270.;
1288
1289   InverseRotation(posLocal,angles);
1290
1291   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
1292   step[0] = 0.;
1293   step[1] = 0.;
1294   step[2] = -((fgkRmax+fgkRmin)*0.5);
1295   Translation(posLocal,step);
1296
1297   angles[0] = 90.;
1298   angles[1] = 90.+(isector+0.5)*fgkPhiSec;
1299   angles[2] = 0.;
1300   angles[3] = 0.;
1301   angles[4] = 90.;
1302   angles[5] = (isector+0.5)*fgkPhiSec;
1303
1304   InverseRotation(posLocal,angles);
1305
1306   Float_t zCoor = posLocal[2];
1307
1308   return zCoor;
1309
1310 }
1311 //_____________________________________________________________________________
1312
1313 void AliTOFGeometry::DetToSectorRF(Int_t vol[5], Double_t **coord)
1314 {
1315   //
1316   // Returns the local coordinates (x, y, z) in sector reference frame
1317   // for the 4 corners of each sector pad (vol[1], vol[2], vol[3], vol[4])
1318   //
1319
1320   if (!gGeoManager) printf("ERROR: no TGeo\n");
1321
1322   // ALICE -> TOF Sector
1323   Char_t path1[100]="";
1324   GetVolumePath(vol[0],path1);
1325   gGeoManager->cd(path1);
1326   TGeoHMatrix aliceToSector;
1327   aliceToSector = *gGeoManager->GetCurrentMatrix();
1328
1329   // TOF Sector -> ALICE
1330   //TGeoHMatrix sectorToALICE = aliceToSector.Inverse();
1331
1332   // ALICE -> TOF Pad
1333   Char_t path2[100]="";
1334   GetVolumePath(vol,path2);
1335   gGeoManager->cd(path2);
1336   TGeoHMatrix aliceToPad;
1337   aliceToPad = *gGeoManager->GetCurrentMatrix();
1338
1339   // TOF Pad -> ALICE
1340   TGeoHMatrix padToALICE = aliceToPad.Inverse();
1341
1342   // TOF Pad -> TOF Sector
1343   TGeoHMatrix padToSector = padToALICE*aliceToSector;
1344
1345   // TOF Sector -> TOF Pad
1346   //TGeoHMatrix sectorToPad = sectorToALICE*aliceToPad;
1347
1348   // coordinates of the pad bottom corner
1349   Double_t **cornerPad = new Double_t*[4];
1350   for (Int_t ii=0; ii<4; ii++) cornerPad[ii] = new Double_t[3];
1351
1352   cornerPad[0][0] = -fgkXPad/2.;
1353   cornerPad[0][1] =  0.;
1354   cornerPad[0][2] = -fgkZPad/2.;
1355
1356   cornerPad[1][0] =  fgkXPad/2.;
1357   cornerPad[1][1] =  0.;
1358   cornerPad[1][2] = -fgkZPad/2.;
1359
1360   cornerPad[2][0] =  fgkXPad/2.;
1361   cornerPad[2][1] =  0.;
1362   cornerPad[2][2] =  fgkZPad/2.;
1363
1364   cornerPad[3][0] = -fgkXPad/2.;
1365   cornerPad[3][1] =  0.;
1366   cornerPad[3][2] =  fgkZPad/2.;
1367
1368   for(Int_t aa=0; aa<4; aa++) for(Int_t bb=0; bb<3; bb++) coord[aa][bb]=0.;
1369
1370   for (Int_t jj=0; jj<4; jj++) padToSector.MasterToLocal(&cornerPad[jj][0], &coord[jj][0]);
1371
1372   delete cornerPad;
1373
1374   //sectorToPad.LocalToMaster(cornerPad, coord);
1375
1376 }
1377 //_____________________________________________________________________________
1378 Float_t AliTOFGeometry::GetPadDx(Float_t *pos)
1379 {
1380   //
1381   // Returns the x coordinate in the Pad reference frame
1382   //
1383
1384   Float_t xpad = -2.;
1385
1386   Float_t posLocal[3];
1387   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1388  
1389   Int_t isector = GetSector(posLocal);
1390   if(isector == -1){
1391     //AliError("Detector Index could not be determined");
1392     return xpad;}
1393   Int_t iplate =  GetPlate(posLocal);
1394   if(iplate == -1){
1395     //AliError("Detector Index could not be determined");
1396     return xpad;} 
1397   Int_t istrip =  GetStrip(posLocal);
1398   if(istrip == -1){  
1399     //AliError("Detector Index could not be determined");
1400     return xpad;}
1401   Int_t ipadz =  GetPadZ(posLocal);
1402   if(ipadz == -1){  
1403     //AliError("Detector Index could not be determined");
1404     return xpad;}
1405   Int_t ipadx =  GetPadX(posLocal);
1406   if(ipadx == -1){
1407     //AliError("Detector Index could not be determined");
1408     return xpad;}
1409
1410   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1411   Double_t angles[6] = 
1412     {90., 90.+(isector+0.5)*fgkPhiSec,
1413       0.,  0.,
1414      90., (isector+0.5)*fgkPhiSec
1415     };
1416   Rotation(posLocal,angles);
1417
1418   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1419   Translation(posLocal,step);
1420
1421   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1422   angles[0] = 90.;
1423   angles[1] =  0.;
1424   angles[2] =  0.;
1425   angles[3] =  0.;
1426   angles[4] = 90.;
1427   angles[5] =270.;
1428
1429   Rotation(posLocal,angles);
1430
1431   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1432   step[0] = 0.;
1433   step[1] = GetHeights(iplate,istrip);
1434   step[2] = -GetDistances(iplate,istrip);
1435   Translation(posLocal,step);
1436
1437   if      (GetAngles(iplate,istrip) >0.) {
1438     angles[0] = 90.;
1439     angles[1] =  0.;
1440     angles[2] = 90.+GetAngles(iplate,istrip);
1441     angles[3] = 90.;
1442     angles[4] = GetAngles(iplate,istrip);
1443     angles[5] = 90.;
1444   }
1445   else if (GetAngles(iplate,istrip)==0.) {
1446     angles[0] = 90.;
1447     angles[1] =  0.;
1448     angles[2] = 90.;
1449     angles[3] = 90.;
1450     angles[4] =  0;
1451     angles[5] =  0.;
1452   }
1453   else if (GetAngles(iplate,istrip) <0.) {
1454     angles[0] = 90.;
1455     angles[1] =  0.;
1456     angles[2] = 90.+GetAngles(iplate,istrip);
1457     angles[3] = 90.;
1458     angles[4] =-GetAngles(iplate,istrip);
1459     angles[5] = 270.;
1460   }
1461   Rotation(posLocal,angles);
1462
1463   step[0] =-0.5*kNpadX*fgkXPad;
1464   step[1] = 0.;
1465   step[2] =-0.5*kNpadZ*fgkZPad;
1466   Translation(posLocal,step);
1467
1468   step[0] = (ipadx+0.5)*fgkXPad;
1469   step[1] = 0.;
1470   step[2] = (ipadz+0.5)*fgkZPad;
1471   Translation(posLocal,step);
1472   
1473   xpad=posLocal[0];
1474
1475   return xpad;
1476
1477 }
1478 //_____________________________________________________________________________
1479 Float_t AliTOFGeometry::GetPadDy(Float_t *pos)
1480 {
1481   //
1482   // Returns the y coordinate in the Pad reference frame
1483   //
1484
1485   Float_t ypad = -2.;
1486
1487   Float_t posLocal[3];
1488   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1489  
1490   Int_t isector = GetSector(posLocal);
1491   if(isector == -1){
1492     //AliError("Detector Index could not be determined");
1493     return ypad;}
1494   Int_t iplate =  GetPlate(posLocal);
1495   if(iplate == -1){
1496     //AliError("Detector Index could not be determined");
1497     return ypad;} 
1498   Int_t istrip =  GetStrip(posLocal);
1499   if(istrip == -1){  
1500     //AliError("Detector Index could not be determined");
1501     return ypad;}
1502   Int_t ipadz =  GetPadZ(posLocal);
1503   if(ipadz == -1){  
1504     //AliError("Detector Index could not be determined");
1505     return ypad;}
1506   Int_t ipadx =  GetPadX(posLocal);
1507   if(ipadx == -1){
1508     //AliError("Detector Index could not be determined");
1509     return ypad;}
1510
1511   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1512   Double_t angles[6] = 
1513     {90., 90.+(isector+0.5)*fgkPhiSec,
1514       0.,  0.,
1515      90., (isector+0.5)*fgkPhiSec
1516     };
1517   Rotation(posLocal,angles);
1518
1519   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1520   Translation(posLocal,step);
1521
1522   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1523   angles[0] = 90.;
1524   angles[1] =  0.;
1525   angles[2] =  0.;
1526   angles[3] =  0.;
1527   angles[4] = 90.;
1528   angles[5] =270.;
1529
1530   Rotation(posLocal,angles);
1531
1532   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1533   step[0] = 0.;
1534   step[1] = GetHeights(iplate,istrip);
1535   step[2] = -GetDistances(iplate,istrip);
1536   Translation(posLocal,step);
1537
1538   if      (GetAngles(iplate,istrip) >0.) {
1539     angles[0] = 90.;
1540     angles[1] =  0.;
1541     angles[2] = 90.+GetAngles(iplate,istrip);
1542     angles[3] = 90.;
1543     angles[4] = GetAngles(iplate,istrip);
1544     angles[5] = 90.;
1545   }
1546   else if (GetAngles(iplate,istrip)==0.) {
1547     angles[0] = 90.;
1548     angles[1] =  0.;
1549     angles[2] = 90.;
1550     angles[3] = 90.;
1551     angles[4] =  0;
1552     angles[5] =  0.;
1553   }
1554   else if (GetAngles(iplate,istrip) <0.) {
1555     angles[0] = 90.;
1556     angles[1] =  0.;
1557     angles[2] = 90.+GetAngles(iplate,istrip);
1558     angles[3] = 90.;
1559     angles[4] =-GetAngles(iplate,istrip);
1560     angles[5] = 270.;
1561   }
1562   Rotation(posLocal,angles);
1563
1564   step[0] =-0.5*kNpadX*fgkXPad;
1565   step[1] = 0.;
1566   step[2] =-0.5*kNpadZ*fgkZPad;
1567   Translation(posLocal,step);
1568   
1569   step[0] = (ipadx+0.5)*fgkXPad;
1570   step[1] = 0.;
1571   step[2] = (ipadz+0.5)*fgkZPad;
1572   Translation(posLocal,step);
1573   
1574   ypad=posLocal[1];
1575   
1576   return ypad;
1577
1578 }
1579 //_____________________________________________________________________________
1580 Float_t AliTOFGeometry::GetPadDz(Float_t *pos)
1581 {
1582   //
1583   // Returns the z coordinate in the Pad reference frame
1584   //
1585
1586   Float_t zpad = -2.;
1587
1588   Float_t posLocal[3];
1589   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1590  
1591   Int_t isector = GetSector(posLocal);
1592   if(isector == -1){
1593     //AliError("Detector Index could not be determined");
1594     return zpad;}
1595   Int_t iplate =  GetPlate(posLocal);
1596   if(iplate == -1){
1597     //AliError("Detector Index could not be determined");
1598     return zpad;} 
1599   Int_t istrip =  GetStrip(posLocal);
1600   if(istrip == -1){  
1601     //AliError("Detector Index could not be determined");
1602     return zpad;}
1603   Int_t ipadz =  GetPadZ(posLocal);
1604   if(ipadz == -1){  
1605     //AliError("Detector Index could not be determined");
1606     return zpad;}
1607   Int_t ipadx =  GetPadX(posLocal);
1608   if(ipadx == -1){
1609     //AliError("Detector Index could not be determined");
1610     return zpad;}
1611
1612   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1613   Double_t angles[6] = 
1614     {90., 90.+(isector+0.5)*fgkPhiSec,
1615       0.,  0.,
1616      90., (isector+0.5)*fgkPhiSec
1617     };
1618   Rotation(posLocal,angles);
1619
1620   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1621   Translation(posLocal,step);
1622
1623   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1624   angles[0] = 90.;
1625   angles[1] =  0.;
1626   angles[2] =  0.;
1627   angles[3] =  0.;
1628   angles[4] = 90.;
1629   angles[5] =270.;
1630
1631   Rotation(posLocal,angles);
1632
1633   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1634   step[0] = 0.;
1635   step[1] = GetHeights(iplate,istrip);
1636   step[2] = -GetDistances(iplate,istrip);
1637   Translation(posLocal,step);
1638
1639   if      (GetAngles(iplate,istrip) >0.) {
1640     angles[0] = 90.;
1641     angles[1] =  0.;
1642     angles[2] = 90.+GetAngles(iplate,istrip);
1643     angles[3] = 90.;
1644     angles[4] = GetAngles(iplate,istrip);
1645     angles[5] = 90.;
1646   }
1647   else if (GetAngles(iplate,istrip)==0.) {
1648     angles[0] = 90.;
1649     angles[1] =  0.;
1650     angles[2] = 90.;
1651     angles[3] = 90.;
1652     angles[4] =  0;
1653     angles[5] =  0.;
1654   }
1655   else if (GetAngles(iplate,istrip) <0.) {
1656     angles[0] = 90.;
1657     angles[1] =  0.;
1658     angles[2] = 90.+GetAngles(iplate,istrip);
1659     angles[3] = 90.;
1660     angles[4] =-GetAngles(iplate,istrip);
1661     angles[5] = 270.;
1662   }
1663   Rotation(posLocal,angles);
1664
1665   step[0] =-0.5*kNpadX*fgkXPad;
1666   step[1] = 0.;
1667   step[2] =-0.5*kNpadZ*fgkZPad;
1668   Translation(posLocal,step);
1669   
1670   step[0] = (ipadx+0.5)*fgkXPad;
1671   step[1] = 0.;
1672   step[2] = (ipadz+0.5)*fgkZPad;
1673   Translation(posLocal,step);
1674
1675   zpad=posLocal[2];
1676
1677   return zpad;
1678
1679 }
1680 //_____________________________________________________________________________
1681
1682 void AliTOFGeometry::Translation(Float_t *xyz, Float_t translationVector[3]) const
1683 {
1684   //
1685   // Return the vector xyz translated by translationVector vector
1686   //
1687
1688   Int_t ii=0;
1689
1690   for (ii=0; ii<3; ii++)
1691     xyz[ii] -= translationVector[ii];
1692
1693   return;
1694
1695 }
1696 //_____________________________________________________________________________
1697
1698 void AliTOFGeometry::Rotation(Float_t *xyz, Double_t rotationAngles[6]) const
1699 {
1700   //
1701   // Return the vector xyz rotated according to the rotationAngles angles
1702   //
1703
1704   Int_t ii=0;
1705   /*
1706   TRotMatrix *matrix = new TRotMatrix("matrix","matrix", angles[0], angles[1],
1707                                       angles[2], angles[3],
1708                                       angles[4], angles[5]);
1709   */
1710
1711   for (ii=0; ii<6; ii++) rotationAngles[ii]*=kDegrad;
1712
1713   Float_t xyzDummy[3] = {0., 0., 0.};
1714
1715   for (ii=0; ii<3; ii++) {
1716     xyzDummy[ii] =
1717       xyz[0]*TMath::Sin(rotationAngles[2*ii])*TMath::Cos(rotationAngles[2*ii+1]) +
1718       xyz[1]*TMath::Sin(rotationAngles[2*ii])*TMath::Sin(rotationAngles[2*ii+1]) +
1719       xyz[2]*TMath::Cos(rotationAngles[2*ii]);
1720   }
1721
1722   for (ii=0; ii<3; ii++) xyz[ii]=xyzDummy[ii];
1723
1724   return;
1725
1726 }
1727 //_____________________________________________________________________________
1728 void AliTOFGeometry::InverseRotation(Float_t *xyz, Double_t rotationAngles[6]) const
1729 {
1730   //
1731   //
1732   //
1733
1734   Int_t ii=0;
1735
1736   for (ii=0; ii<6; ii++) rotationAngles[ii]*=kDegrad;
1737
1738   Float_t xyzDummy[3] = {0., 0., 0.};
1739
1740   xyzDummy[0] =
1741     xyz[0]*TMath::Sin(rotationAngles[0])*TMath::Cos(rotationAngles[1]) +
1742     xyz[1]*TMath::Sin(rotationAngles[2])*TMath::Cos(rotationAngles[3]) +
1743     xyz[2]*TMath::Sin(rotationAngles[4])*TMath::Cos(rotationAngles[5]);
1744   
1745   xyzDummy[1] =
1746     xyz[0]*TMath::Sin(rotationAngles[0])*TMath::Sin(rotationAngles[1]) +
1747     xyz[1]*TMath::Sin(rotationAngles[2])*TMath::Sin(rotationAngles[3]) +
1748     xyz[2]*TMath::Sin(rotationAngles[4])*TMath::Sin(rotationAngles[5]);
1749   
1750   xyzDummy[2] =
1751     xyz[0]*TMath::Cos(rotationAngles[0]) +
1752     xyz[1]*TMath::Cos(rotationAngles[2]) +
1753     xyz[2]*TMath::Cos(rotationAngles[4]);
1754   
1755   for (ii=0; ii<3; ii++) xyz[ii]=xyzDummy[ii];
1756
1757   return;
1758
1759 }
1760 //_____________________________________________________________________________
1761
1762 Int_t AliTOFGeometry::GetIndex(Int_t *detId)
1763 {
1764   //Retrieve calibration channel index 
1765   Int_t isector = detId[0];
1766   if (isector >= kNSectors){
1767     printf("Wrong sector number in TOF (%d) !",isector);
1768     return -1;
1769   }
1770   Int_t iplate = detId[1];
1771   if (iplate >= kNPlates){
1772     printf("Wrong plate number in TOF (%d) !",iplate);
1773     return -1;
1774   }
1775   Int_t istrip = detId[2];
1776   Int_t ipadz = detId[3];
1777   Int_t ipadx = detId[4];
1778   Int_t stripOffset = 0;
1779   switch (iplate) {
1780   case 0:
1781     stripOffset = 0;
1782     break;
1783   case 1:
1784     stripOffset = kNStripC;
1785     break;
1786   case 2:
1787     stripOffset = kNStripC+kNStripB;
1788     break;
1789   case 3:
1790     stripOffset = kNStripC+kNStripB+kNStripA;
1791     break;
1792   case 4:
1793     stripOffset = kNStripC+kNStripB+kNStripA+kNStripB;
1794     break;
1795   default:
1796     printf("Wrong plate number in TOF (%d) !",iplate);
1797     return -1;
1798   };
1799
1800   Int_t idet = ((2*(kNStripC+kNStripB)+kNStripA)
1801                *kNpadZ*kNpadX)*isector +
1802                (stripOffset*kNpadZ*kNpadX)+
1803                (kNpadZ*kNpadX)*istrip+
1804                (kNpadX)*ipadz+
1805                 ipadx;
1806   return idet;
1807 }
1808
1809
1810