]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFGeometryV5.cxx
Add classes for TOF Calibration (C.Zampolli)
[u/mrichter/AliRoot.git] / TOF / AliTOFGeometryV5.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 0.1  2005/07/19 G. Cara Romeo and A. De Caro
19         Modify Global methods IsInsideThePad & DistanceToPad
20                according to the new TOF geometry
21         Implement Global  methods GetPadDx & GetPadDy & GetPadDz
22         Implement Private methods Translation & Rotation & InverseRotation
23         Modify Global methods GetDetID & GetPlate & GetSector &
24                               GetStrip & GetPadX & GetPadZ
25                according to the new TOF geometry
26         Modify Global methods GetPos & GetX & GetY & GetZ
27                according to the new TOF geometry
28 */
29
30 #include <stdlib.h>
31 #include <Riostream.h>
32 ///////////////////////////////////////////////////////////////////////////////
33 //                                                                           //
34 //  TOF Geometry class (new version)                                         //
35 //                                                                           //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include "AliLog.h"
39 #include "AliConst.h"
40 #include "AliTOFGeometry.h"
41 #include "AliTOFGeometryV5.h"
42
43 ClassImp(AliTOFGeometryV5)
44
45 const Int_t AliTOFGeometryV5::kNStripC      = 19;       // number of strips in C type module
46 const Int_t AliTOFGeometryV5::kMaxNstrip    = 19;       // Max. number of strips
47
48 const Float_t AliTOFGeometryV5::fgkZlenA    = 370.6*2.; // length (cm) of the A module
49 const Float_t AliTOFGeometryV5::fgkZlenB    = 146.5;    // length (cm) of the B module
50 const Float_t AliTOFGeometryV5::fgkZlenC    = 170.45;   // length (cm) of the C module
51 const Float_t AliTOFGeometryV5::fgkMaxhZtof = 370.6;    // Max half z-size of TOF (cm)
52 const Float_t AliTOFGeometryV5::fgkStripLength = 124.;  // Strip Length (rho X phi direction) (cm)
53
54 const Float_t AliTOFGeometryV5::fgkxTOF     = 371.-0.01;// Inner radius of the TOF for Reconstruction (cm)
55 const Float_t AliTOFGeometryV5::fgkRmin     = 370.-0.01;// Inner radius of the TOF (cm)
56 const Float_t AliTOFGeometryV5::fgkRmax     = 399.-0.01;// Outer radius of the TOF (cm)
57
58 //_____________________________________________________________________________
59 AliTOFGeometryV5::AliTOFGeometryV5()
60   :AliTOFGeometry()
61 {
62   //
63   // AliTOFGeometryV5 default constructor
64   //
65
66   AliTOFGeometry::kNStripC     = kNStripC;       // number of strips in C type module
67   AliTOFGeometry::kMaxNstrip   = kMaxNstrip;     // Max. number of strips
68
69   AliTOFGeometry::kZlenA       = fgkZlenA;       // length of the TOF supermodule (cm)
70   AliTOFGeometry::kZlenB       = fgkZlenB;       // length of the B module (cm)
71   AliTOFGeometry::kZlenC       = fgkZlenC;       // length of the C module (cm)
72   AliTOFGeometry::kMaxhZtof    = fgkMaxhZtof;    // Max half z-size of TOF supermodule (cm)
73   AliTOFGeometry::kStripLength = fgkStripLength; // Strip Length (rho X phi direction) (cm)
74
75   AliTOFGeometry::fgkxTOF   = fgkxTOF;           // Inner radius of the TOF for Reconstruction (cm)
76   AliTOFGeometry::fgkRmin   = fgkRmin;           // Inner radius of the TOF (cm)
77   AliTOFGeometry::fgkRmax   = fgkRmax;           // Outer radius of the TOF (cm)
78
79   Init();
80
81 }
82
83 //_____________________________________________________________________________
84 AliTOFGeometryV5::~AliTOFGeometryV5()
85 {
86   //
87   // AliTOFGeometryV5 destructor
88   //
89
90 }
91 //_____________________________________________________________________________
92 void AliTOFGeometryV5::Init()
93 {
94   //
95   // Initialize strip Tilt Angles, Heights and Distances
96   //
97   // Strips Tilt Angles
98  
99   // For each strip to be positoned in FLTA/FLTB/FLTC,
100   // define 3 arrays containing:
101   //   the angle of the normal with respect to the Y axis of FLTA/FLTB/FLTC
102   //   the Y of the center with respect to the FLTA/FLTB/FLTC reference frame
103   //   the Z of the center with respect to the BT01/BT02/BT03 reference frame
104
105
106   Float_t const kangles[kNPlates][kMaxNstrip] ={
107     { 43.99,  43.20,  42.40,  41.59,  40.77,  39.94,  39.11,  38.25,  37.40,  36.53,
108       35.65,  34.76,  33.87,  32.96,  32.05,  31.13,  30.19,  29.24,  12.33},
109
110     { 27.26,  26.28,  25.30,  24.31,  23.31,  22.31,  21.30,  20.29,  19.26,  18.24,
111       17.20,  16.16,  15.11,  14.05,  13.00,  11.93,  10.87,   9.80,   8.74},
112
113     {  0.00,   6.30,   5.31,   4.25,   3.19,   2.12,   1.06,   0.00,  -1.06,  -2.12,
114       -3.19,  -4.25,  -5.31,  -6.30,   0.00,   0.00,   0.00,   0.00,   0.00},
115
116     { -8.74,  -9.80, -10.87, -11.93, -13.00, -14.05, -15.11, -16.16, -17.20, -18.24,
117      -19.26, -20.29, -21.30, -22.31, -23.31, -24.31, -25.30, -26.28, -27.26},
118     
119     {-12.33, -29.24, -30.19, -31.13, -32.05, -32.96, -33.87, -34.76, -35.65, -36.53,
120      -37.40, -38.25, -39.11, -39.94, -40.77, -41.59, -42.40, -43.20, -43.99}
121   };
122
123   Float_t const kheights[kNPlates][kMaxNstrip]= {
124     {-8.2,  -7.5,  -8.2,  -7.7,  -8.1,  -7.6,  -7.7,  -7.7,  -7.7,  -7.7,
125      -7.5,  -7.2,  -7.3,  -7.5,  -7.6,  -7.8,  -8.3,  -9.3,  -3.1},
126
127     {-7.9,  -8.1,  -8.5,  -9.0, -10.1,  -3.9,  -5.9,  -7.7, -10.1,  -3.6,
128      -5.8,  -8.0, -10.4,  -4.4,  -7.2, -10.2,  -4.6,  -7.4, -10.4},
129
130     {-2.5, -10.4,  -5.0,  -9.9,  -4.8,  -9.9,  -4.7, -10.2,  -4.7,  -9.9,
131      -4.8,  -9.9,  -5.0, -10.4,  -2.5,   0.0,   0.0,   0.0,   0.0},
132
133     {-10.4, -7.4,  -4.6, -10.2,  -7.2,  -4.4, -10.4,  -8.0,  -5.8,  -3.6,
134      -10.1,  -7.7, -5.9,  -3.9, -10.1,  -9.0,  -8.5,  -8.1,  -7.9},
135
136     { -3.1,  -9.3, -8.3,  -7.8,  -7.6,  -7.5,  -7.3,  -7.2,  -7.5,  -7.7,
137       -7.7,  -7.7, -7.7,  -7.6,  -8.1,  -7.7,  -8.2,  -7.5,  -8.2}
138   };
139
140
141   Float_t const kdistances[kNPlates][kMaxNstrip]= {
142     { 364.1,  354.9,  344.5,  335.4,  325.5,  316.6,  307.2,  298.0,  288.9,  280.0,
143       271.3,  262.7,  254.0,  244.8,  236.1,  227.7,  219.1,  210.3,  205.7},
144
145     { 194.2,  186.1,  177.9,  169.8,  161.5,  156.3,  147.8,  139.4,  130.9,  125.6,
146       117.3,  109.2,  101.1,   95.3,   87.1,   79.2,   73.0,   65.1,   57.6},
147
148     {  49.5,   41.3,   35.3,   27.8,   21.2,   13.9,    7.0,    0.0,   -7.0,  -13.9,
149       -21.2,  -27.8,  -35.3,  -41.3,  -49.5,    0.0,    0.0,    0.0,    0.0},
150
151     { -57.6,  -65.1,  -73.0,  -79.2,  -87.1,  -95.3, -101.1, -109.2, -117.3, -125.6,
152      -130.9, -139.4, -147.8, -156.3, -161.5, -169.8, -177.9, -186.1, -194.2},
153
154     {-205.7, -210.3, -219.1, -227.7, -236.1, -244.8, -254.0, -262.7, -271.3, -280.0,
155      -288.9, -298.0, -307.2, -316.6, -325.5, -335.4, -344.5, -354.9, -364.1}
156   };
157
158
159    for (Int_t iplate = 0; iplate < kNPlates; iplate++) AliTOFGeometry::fAngles[iplate] = new Float_t[kMaxNstrip];
160    for (Int_t iplate = 0; iplate < kNPlates; iplate++) AliTOFGeometry::fHeights[iplate] = new Float_t[kMaxNstrip];
161    for (Int_t iplate = 0; iplate < kNPlates; iplate++) AliTOFGeometry::fDistances[iplate] = new Float_t[kMaxNstrip];
162
163   for (Int_t iplate = 0; iplate < kNPlates; iplate++) {
164     for (Int_t istrip = 0; istrip < kMaxNstrip; istrip++) {
165       AliTOFGeometry::fAngles[iplate][istrip]   = kangles[iplate][istrip];
166       AliTOFGeometry::fHeights[iplate][istrip]  = kheights[iplate][istrip];
167       AliTOFGeometry::fDistances[iplate][istrip]= kdistances[iplate][istrip];
168     }
169   }
170
171 }
172
173 //_____________________________________________________________________________
174 Float_t AliTOFGeometryV5::DistanceToPad(Int_t *det, Float_t *pos, Float_t *dist3d) 
175 {
176 //
177 // Returns distance of  space point with coor pos (x,y,z) (cm) wrt 
178 // pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
179 //
180     
181   //Transform pos into Sector Frame
182
183   Float_t x = pos[0];
184   Float_t y = pos[1];
185   Float_t z = pos[2];
186
187   Float_t radius = TMath::Sqrt(x*x+y*y);
188   //Float_t phi=TMath::ATan(y/x);       
189   //if(phi<0) phi = k2PI+phi; //2.*TMath::Pi()+phi;
190   Float_t phi = TMath::Pi()+TMath::ATan2(-y,-x);        
191   //  Get the local angle in the sector philoc
192   Float_t angle   = phi*kRaddeg-( Int_t (kRaddeg*phi/fPhiSec) + 0.5)*fPhiSec;
193   Float_t xs = radius*TMath::Cos(angle/kRaddeg);
194   Float_t ys = radius*TMath::Sin(angle/kRaddeg);
195   Float_t zs = z;
196
197   // Do the same for the selected pad
198
199   Float_t g[3];
200   GetPos(det,g);
201
202   Float_t padRadius = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
203   //Float_t padPhi = TMath::ATan(g[1]/g[0]);    
204   //if(padPhi<0) padPhi = k2Pi + padPhi;
205   Float_t padPhi = TMath::Pi()+TMath::ATan2(-g[1],-g[0]);       
206
207   //  Get the local angle in the sector philoc
208   Float_t padAngle = padPhi*kRaddeg-( Int_t (padPhi*kRaddeg/fPhiSec)+ 0.5) * fPhiSec;
209   Float_t padxs = padRadius*TMath::Cos(padAngle/kRaddeg);
210   Float_t padys = padRadius*TMath::Sin(padAngle/kRaddeg);
211   Float_t padzs = g[2];
212   
213   //Now move to local pad coordinate frame. Translate:
214   
215   Float_t xt = xs-padxs;
216   Float_t yt = ys-padys;
217   Float_t zt = zs-padzs;
218   //Now Rotate:
219   
220   Float_t alpha = GetAngles(det[1],det[2]);
221   Float_t xr =  xt*TMath::Cos(alpha/kRaddeg)+zt*TMath::Sin(alpha/kRaddeg);
222   Float_t yr =  yt;
223   Float_t zr = -xt*TMath::Sin(alpha/kRaddeg)+zt*TMath::Cos(alpha/kRaddeg);
224
225   Float_t dist = TMath::Sqrt(xr*xr+yr*yr+zr*zr);
226
227   if (dist3d){
228     dist3d[0] = xr;
229     dist3d[1] = yr;
230     dist3d[2] = zr;
231   }
232
233   return dist;
234
235 }
236
237 //_____________________________________________________________________________
238 Bool_t AliTOFGeometryV5::IsInsideThePad(Int_t *det, Float_t *pos) 
239 {
240 //
241 // Returns true if space point with coor pos (x,y,z) (cm) falls 
242 // inside pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
243 //
244
245   Bool_t isInside=false; 
246
247   /*
248   const Float_t khhony    = 1.0          ; // heigth of HONY  Layer
249   const Float_t khpcby    = 0.08         ; // heigth of PCB   Layer
250   const Float_t khrgly    = 0.055        ; // heigth of RED GLASS  Layer
251   const Float_t khglfy    = 0.285        ; // heigth of GLASS+FISHLINE  Layer
252   const Float_t khcpcby   = 0.16         ; // heigth of PCB  Central Layer
253   //const Float_t kwcpcbz   = 12.4         ; // z dimension of PCB  Central Layer
254   const Float_t khstripy = 2.*khhony+2.*khpcby+4.*khrgly+2.*khglfy+khcpcby;//3.11
255   //const Float_t kwstripz = kwcpcbz;
256   //const Float_t klstripx = fgkStripLength;
257   */
258
259   const Float_t khsensmy = 0.05;//0.05;//0.11;//0.16;//          // heigth of Sensitive Layer
260
261   //Transform pos into Sector Frame
262
263   Float_t x = pos[0];
264   Float_t y = pos[1];
265   Float_t z = pos[2];
266
267   Float_t radius = TMath::Sqrt(x*x+y*y);
268   Float_t phi = TMath::Pi()+TMath::ATan2(-y,-x);        
269
270   //  Get the local angle in the sector philoc
271   Float_t angle = phi*kRaddeg-( Int_t (kRaddeg*phi/fPhiSec) + 0.5) *fPhiSec;
272   Float_t xs = radius*TMath::Cos(angle/kRaddeg);
273   Float_t ys = radius*TMath::Sin(angle/kRaddeg);
274   Float_t zs = z;
275
276   // Do the same for the selected pad
277
278   Float_t g[3];
279   GetPos(det,g);
280
281   Float_t padRadius = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
282   Float_t padPhi = TMath::Pi()+TMath::ATan2(-g[1],-g[0]);       
283
284   //  Get the local angle in the sector philoc
285   Float_t padAngle = padPhi*kRaddeg-( Int_t (padPhi*kRaddeg/fPhiSec)+ 0.5) * fPhiSec; 
286   Float_t padxs = padRadius*TMath::Cos(padAngle/kRaddeg);
287   Float_t padys = padRadius*TMath::Sin(padAngle/kRaddeg);
288   Float_t padzs = g[2];
289
290   //Now move to local pad coordinate frame. Translate:
291
292   Float_t xt = xs-padxs;
293   Float_t yt = ys-padys;
294   Float_t zt = zs-padzs;
295
296   //Now Rotate:
297
298   Float_t alpha = GetAngles(det[1],det[2]);
299   Float_t xr =  xt*TMath::Cos(alpha/kRaddeg)+zt*TMath::Sin(alpha/kRaddeg);
300   Float_t yr =  yt;
301   Float_t zr = -xt*TMath::Sin(alpha/kRaddeg)+zt*TMath::Cos(alpha/kRaddeg);
302
303   //if(TMath::Abs(xr)<=1.50*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5)) ???
304   if(TMath::Abs(xr)<=khsensmy*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5))
305   //if(TMath::Abs(xr)<=khstripy*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5))
306     isInside=true;
307   return isInside;
308
309 }
310
311 //_____________________________________________________________________________
312 Float_t AliTOFGeometryV5::GetX(Int_t *det)
313 {
314   //
315   // Returns X coordinate (cm)
316   //
317
318   Int_t isector = det[0];
319   Int_t iplate  = det[1];
320   Int_t istrip  = det[2];
321   Int_t ipadz   = det[3];
322   Int_t ipadx   = det[4];
323
324   /*
325   // Find out distance d on the plane wrt median phi:
326   Float_t d = (ipadx+0.5-kNpadX*0.5)*fgkXPad;
327
328   // The radius r in xy plane:
329   //Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
330   //  (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg)-0.25; ???
331   Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
332     (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg);
333
334   // local azimuthal angle in the sector philoc
335   Float_t philoc  = TMath::ATan(d/r);
336   //if(philoc<0.) philoc = k2PI + philoc;
337
338   // azimuthal angle in the global frame  phi
339   Float_t phi   = philoc*kRaddeg+(isector+0.5)*fPhiSec;
340
341   Float_t xCoor = r/TMath::Cos(philoc)*TMath::Cos(phi/kRaddeg);
342   */
343
344   // Pad reference frame -> FSTR reference frame
345   //  /*
346   Float_t posLocal[3] = {0., 0., 0.};
347   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
348   Translation(posLocal,step);
349
350   step[0] = kNpadX*0.5*fgkXPad;
351   step[1] = 0.;
352   step[2] = kNpadZ*0.5*fgkZPad;
353   //  */
354   /*
355   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
356   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
357   */
358   Translation(posLocal,step);
359
360   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
361   Double_t angles[6];
362   if      (GetAngles(iplate,istrip) >0.) {
363     angles[0] = 90.;
364     angles[1] =  0.;
365     angles[2] = 90.+GetAngles(iplate,istrip);
366     angles[3] = 90.;
367     angles[4] = GetAngles(iplate,istrip);
368     angles[5] = 90.;
369   }
370   else if (GetAngles(iplate,istrip)==0.) {
371     angles[0] = 90.;
372     angles[1] =  0.;
373     angles[2] = 90.;
374     angles[3] = 90.;
375     angles[4] =  0;
376     angles[5] =  0.;
377   }
378   else if (GetAngles(iplate,istrip) <0.) {
379     angles[0] = 90.;
380     angles[1] =  0.;
381     angles[2] = 90.+GetAngles(iplate,istrip);
382     angles[3] = 90.;
383     angles[4] =-GetAngles(iplate,istrip);
384     angles[5] = 270.;
385   }
386
387   InverseRotation(posLocal,angles);
388
389   step[0] = 0.;
390   step[1] = -GetHeights(iplate,istrip);
391   step[2] =  GetDistances(iplate,istrip);
392   Translation(posLocal,step);
393
394   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
395   angles[0] = 90.;
396   angles[1] =  0.;
397   angles[2] =  0.;
398   angles[3] =  0.;
399   angles[4] = 90.;
400   angles[5] =270.;
401
402   InverseRotation(posLocal,angles);
403
404   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
405   step[0] = 0.;
406   step[1] = 0.;
407   step[2] = -((fgkRmax+fgkRmin)*0.5);
408   Translation(posLocal,step);
409
410   angles[0] = 90.;
411   angles[1] = 90.+(isector+0.5)*fPhiSec;
412   angles[2] = 0.;
413   angles[3] = 0.;
414   angles[4] = 90.;
415   angles[5] = (isector+0.5)*fPhiSec;
416
417   InverseRotation(posLocal,angles);
418
419   Float_t xCoor = posLocal[0];
420
421   return xCoor;
422
423 }
424 //_____________________________________________________________________________
425 Float_t AliTOFGeometryV5::GetY(Int_t *det)
426 {
427   //
428   // Returns Y coordinate (cm)
429   //
430
431   Int_t isector = det[0];
432   Int_t iplate  = det[1];
433   Int_t istrip  = det[2];
434   Int_t ipadz   = det[3];
435   Int_t ipadx   = det[4];
436
437   /*
438   // Find out distance d on the plane wrt median phi:
439   Float_t d = (ipadx+0.5-kNpadX*0.5)*fgkXPad;
440
441   // The radius r in xy plane:
442   //Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
443   //  (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg)-0.25; ???
444   Float_t r = (fgkRmin+fgkRmax)*0.5-0.01+GetHeights(iplate,istrip)+
445     (ipadz-0.5)*fgkZPad*TMath::Sin(GetAngles(iplate,istrip)/kRaddeg);
446
447   // local azimuthal angle in the sector philoc
448   Float_t philoc = TMath::ATan(d/r);
449   //if(philoc<0.) philoc = k2PI + philoc;
450
451   // azimuthal angle in the global frame  phi
452   Float_t phi   = philoc*kRaddeg+(isector+0.5)*fPhiSec;
453
454   Float_t yCoor = r/TMath::Cos(philoc)*TMath::Sin(phi/kRaddeg);
455   */
456
457   // Pad reference frame -> FSTR reference frame
458   //  /*
459   Float_t posLocal[3] = {0., 0., 0.};
460   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
461   Translation(posLocal,step);
462
463   step[0] = kNpadX*0.5*fgkXPad;
464   step[1] = 0.;
465   step[2] = kNpadZ*0.5*fgkZPad;
466   //  */
467   /*
468   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
469   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
470   */
471   Translation(posLocal,step);
472
473   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
474
475   Double_t angles[6];
476   if      (GetAngles(iplate,istrip) >0.) {
477     angles[0] = 90.;
478     angles[1] =  0.;
479     angles[2] = 90.+GetAngles(iplate,istrip);
480     angles[3] = 90.;
481     angles[4] = GetAngles(iplate,istrip);
482     angles[5] = 90.;
483   }
484   else if (GetAngles(iplate,istrip)==0.) {
485     angles[0] = 90.;
486     angles[1] =  0.;
487     angles[2] = 90.;
488     angles[3] = 90.;
489     angles[4] =  0;
490     angles[5] =  0.;
491   }
492   else if (GetAngles(iplate,istrip) <0.) {
493     angles[0] = 90.;
494     angles[1] =  0.;
495     angles[2] = 90.+GetAngles(iplate,istrip);
496     angles[3] = 90.;
497     angles[4] =-GetAngles(iplate,istrip);
498     angles[5] = 270.;
499   }
500
501   InverseRotation(posLocal,angles);
502
503   step[0] = 0.;
504   step[1] = -GetHeights(iplate,istrip);
505   step[2] =  GetDistances(iplate,istrip);
506   Translation(posLocal,step);
507
508   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
509   angles[0] = 90.;
510   angles[1] =  0.;
511   angles[2] =  0.;
512   angles[3] =  0.;
513   angles[4] = 90.;
514   angles[5] =270.;
515
516   InverseRotation(posLocal,angles);
517
518   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
519   step[0] = 0.;
520   step[1] = 0.;
521   step[2] = -((fgkRmax+fgkRmin)*0.5);
522   Translation(posLocal,step);
523
524   angles[0] = 90.;
525   angles[1] = 90.+(isector+0.5)*fPhiSec;
526   angles[2] = 0.;
527   angles[3] = 0.;
528   angles[4] = 90.;
529   angles[5] = (isector+0.5)*fPhiSec;
530
531   InverseRotation(posLocal,angles);
532
533   Float_t yCoor = posLocal[1];
534
535   return yCoor;
536
537 }
538
539 //_____________________________________________________________________________
540 Float_t AliTOFGeometryV5::GetZ(Int_t *det)
541 {
542   //
543   // Returns Z coordinate (cm)
544   //
545
546   Int_t isector = det[0];
547   Int_t iplate  = det[1];
548   Int_t istrip  = det[2];
549   Int_t ipadz   = det[3];
550   Int_t ipadx   = det[4];
551
552   /*
553   Float_t zCoor = GetDistances(iplate,istrip) +
554     (0.5-ipadz) * fgkZPad * TMath::Cos(GetAngles(iplate,istrip)*kDegrad);
555   */
556
557   // Pad reference frame -> FSTR reference frame
558   //  /*
559   Float_t posLocal[3] = {0., 0., 0.};
560   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
561   Translation(posLocal,step);
562
563   step[0] = kNpadX*0.5*fgkXPad;
564   step[1] = 0.;
565   step[2] = kNpadZ*0.5*fgkZPad;
566   //  */
567   /*
568   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
569   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
570   */
571   Translation(posLocal,step);
572
573   // FSTR reference frame -> FTOA/B/C = FLTA/B/C reference frame
574   Double_t angles[6];
575   if      (GetAngles(iplate,istrip) >0.) {
576     angles[0] = 90.;
577     angles[1] =  0.;
578     angles[2] = 90.+GetAngles(iplate,istrip);
579     angles[3] = 90.;
580     angles[4] = GetAngles(iplate,istrip);
581     angles[5] = 90.;
582   }
583   else if (GetAngles(iplate,istrip)==0.) {
584     angles[0] = 90.;
585     angles[1] =  0.;
586     angles[2] = 90.;
587     angles[3] = 90.;
588     angles[4] =  0;
589     angles[5] =  0.;
590   }
591   else if (GetAngles(iplate,istrip) <0.) {
592     angles[0] = 90.;
593     angles[1] =  0.;
594     angles[2] = 90.+GetAngles(iplate,istrip);
595     angles[3] = 90.;
596     angles[4] =-GetAngles(iplate,istrip);
597     angles[5] = 270.;
598   }
599
600   InverseRotation(posLocal,angles);
601
602   step[0] = 0.;
603   step[1] = -GetHeights(iplate,istrip);
604   step[2] =  GetDistances(iplate,istrip);
605   Translation(posLocal,step);
606
607   // FTOA = FLTA reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
608   angles[0] = 90.;
609   angles[1] =  0.;
610   angles[2] =  0.;
611   angles[3] =  0.;
612   angles[4] = 90.;
613   angles[5] =270.;
614
615   InverseRotation(posLocal,angles);
616
617   // B071/B074/B075 = BTO1/2/3 reference frame -> ALICE reference frame
618   step[0] = 0.;
619   step[1] = 0.;
620   step[2] = -((fgkRmax+fgkRmin)*0.5);
621   Translation(posLocal,step);
622
623   angles[0] = 90.;
624   angles[1] = 90.+(isector+0.5)*fPhiSec;
625   angles[2] = 0.;
626   angles[3] = 0.;
627   angles[4] = 90.;
628   angles[5] = (isector+0.5)*fPhiSec;
629
630   InverseRotation(posLocal,angles);
631
632   Float_t zCoor = posLocal[2];
633
634   return zCoor;
635
636 }
637
638 //_____________________________________________________________________________
639 Int_t AliTOFGeometryV5::GetSector(Float_t *pos) 
640 {
641   //
642   // Returns the Sector index 
643   //
644
645   //const Float_t khAlWall = 0.1;
646   //const Float_t kModuleWallThickness = 0.3;
647
648   Int_t   iSect = -1; 
649
650   Float_t x = pos[0];
651   Float_t y = pos[1];
652   Float_t z = pos[2];
653
654   Float_t rho = TMath::Sqrt(x*x + y*y);
655
656   //if (!((z>=-fgkMaxhZtof && z<=fgkMaxhZtof) &&
657   if (!((z>=-fgkZlenA*0.5 && z<=fgkZlenA*0.5) &&
658         (rho>=(fgkRmin) && rho<=(fgkRmax)))) {
659     //(rho>=(fgkRmin-0.05)+kModuleWallThickness && rho<=(fgkRmax-0.05)-kModuleWallThickness-khAlWall-kModuleWallThickness))) {
660     //AliError("Detector Index could not be determined");
661     return iSect;
662   }
663
664   Float_t phi = TMath::Pi() + TMath::ATan2(-y,-x);      
665
666   iSect  = (Int_t) (phi*kRaddeg/fPhiSec);
667   
668   return iSect;
669
670 }
671 //_____________________________________________________________________________
672
673 Int_t AliTOFGeometryV5::GetPlate(Float_t *pos)
674 {
675   //
676   // Returns the Plate index 
677   //
678   const Float_t kInterCentrModBorder1 = 49.5;
679   const Float_t kInterCentrModBorder2 = 57.5;
680   const Float_t kExterInterModBorder1 = 196.0;
681   const Float_t kExterInterModBorder2 = 203.5;
682
683   const Float_t kLengthExInModBorder  = 4.7;
684   const Float_t kLengthInCeModBorder  = 7.0;
685
686   //const Float_t khAlWall = 0.1;
687   const Float_t kModuleWallThickness = 0.3;
688   //const Float_t kHoneycombLayerThickness = 1.5;
689
690   Int_t iPlate=-1;
691
692   Float_t posLocal[3];
693   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
694
695   Int_t isector = GetSector(posLocal);
696   if(isector == -1){
697     //AliError("Detector Index could not be determined");
698     return iPlate;
699   }
700
701   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
702   Double_t angles[6] = 
703     {90., 90.+(isector+0.5)*fPhiSec,
704       0., 0.,
705      90., (isector+0.5)*fPhiSec
706     };
707   Rotation(posLocal,angles);
708
709   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
710   Translation(posLocal,step);
711
712   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
713   angles[0] = 90.;
714   angles[1] =  0.;
715   angles[2] =  0.;
716   angles[3] =  0.;
717   angles[4] = 90.;
718   angles[5] =270.;
719
720   Rotation(posLocal,angles);
721
722   Float_t yLocal = posLocal[1];
723   Float_t zLocal = posLocal[2];
724
725   Float_t deltaRhoLoc  = (fgkRmax-fgkRmin)*0.5 - kModuleWallThickness + yLocal;
726   Float_t deltaZetaLoc = TMath::Abs(zLocal);
727
728   Float_t deltaRHOmax = 0.;
729
730   if (TMath::Abs(zLocal)>=kExterInterModBorder1 && TMath::Abs(zLocal)<=kExterInterModBorder2) 
731     {
732       deltaRhoLoc -= kLengthExInModBorder;
733       deltaZetaLoc = kExterInterModBorder2-deltaZetaLoc;
734       deltaRHOmax  = (fgkRmax - fgkRmin)*0.5 - kModuleWallThickness - 2.*kLengthExInModBorder; // old 5.35, new 4.8
735
736       if (deltaRhoLoc > deltaZetaLoc*deltaRHOmax/(kInterCentrModBorder2-kInterCentrModBorder1)) {
737         if (zLocal<0) iPlate = 0;
738         else iPlate = 4;
739       }
740       else {
741         if (zLocal<0) iPlate = 1;
742         else iPlate = 3;
743       }
744     }
745   else if (TMath::Abs(zLocal)>=kInterCentrModBorder1 && TMath::Abs(zLocal)<=kInterCentrModBorder2) 
746     {
747       deltaRhoLoc -= kLengthInCeModBorder;
748       deltaZetaLoc = deltaZetaLoc-kInterCentrModBorder1;
749       deltaRHOmax = (fgkRmax - fgkRmin)*0.5 - kModuleWallThickness - 2.*kLengthInCeModBorder; // old 0.39, new 0.2
750
751       if (deltaRhoLoc>deltaZetaLoc*deltaRHOmax/(kInterCentrModBorder2-kInterCentrModBorder1)) iPlate = 2;
752       else {
753         if (zLocal<0) iPlate = 1;
754         else iPlate = 3;
755       }
756     }
757
758   if      (zLocal>-fgkZlenA*0.5/*fgkMaxhZtof*/ && zLocal<-kExterInterModBorder2)       iPlate = 0;
759   else if (zLocal>-kExterInterModBorder1       && zLocal<-kInterCentrModBorder2)       iPlate = 1;
760   else if (zLocal>-kInterCentrModBorder1       && zLocal< kInterCentrModBorder1)       iPlate = 2;
761   else if (zLocal> kInterCentrModBorder2       && zLocal< kExterInterModBorder1)       iPlate = 3;
762   else if (zLocal> kExterInterModBorder2       && zLocal< fgkZlenA*0.5/*fgkMaxhZtof*/) iPlate = 4;
763   
764   return iPlate;
765
766 }
767
768 //_____________________________________________________________________________
769 Int_t AliTOFGeometryV5::GetStrip(Float_t *pos)
770 {
771   //
772   // Returns the Strip index 
773   //
774   const Float_t khhony    = 1.0          ; // heigth of HONY  Layer
775   const Float_t khpcby    = 0.08         ; // heigth of PCB   Layer
776   const Float_t khrgly    = 0.055        ; // heigth of RED GLASS  Layer
777   const Float_t khglfy    = 0.285        ; // heigth of GLASS+FISHLINE  Layer
778   const Float_t khcpcby   = 0.16         ; // heigth of PCB  Central Layer
779   const Float_t kwcpcbz   = 12.4         ; // z dimension of PCB  Central Layer
780   const Float_t khstripy = 2.*khhony+2.*khpcby+4.*khrgly+2.*khglfy+khcpcby;//3.11
781   const Float_t kwstripz = kwcpcbz;
782   const Float_t klstripx = fgkStripLength;
783   
784   Int_t iStrip=-1;
785    
786   Float_t posLocal[3];
787   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
788  
789   Int_t isector = GetSector(posLocal);
790   if(isector == -1){
791     //AliError("Detector Index could not be determined");
792     return iStrip;}
793   Int_t iplate =  GetPlate(posLocal);
794   if(iplate == -1){
795     //AliError("Detector Index could not be determined");
796     return iStrip;} 
797
798   Int_t nstrips=0;
799   switch (iplate) {
800   case 0:
801     nstrips=kNStripC;
802     break;
803   case 4:
804     nstrips=kNStripC;
805     break;
806   case 1:
807     nstrips=kNStripB;
808     break;
809   case 3:
810     nstrips=kNStripB;
811     break;
812   case 2:
813     nstrips=kNStripA;
814     break;
815   }
816   
817   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
818   Double_t angles[6] = 
819     {90., 90.+(isector+0.5)*fPhiSec,
820       0., 0.,
821      90., (isector+0.5)*fPhiSec
822     };
823   Rotation(posLocal,angles);
824
825   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
826   Translation(posLocal,step);
827
828   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
829   angles[0] = 90.;
830   angles[1] =  0.;
831   angles[2] =  0.;
832   angles[3] =  0.;
833   angles[4] = 90.;
834   angles[5] =270.;
835
836   Rotation(posLocal,angles);
837
838   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
839   Int_t totStrip=0;
840   for (Int_t istrip=0; istrip<nstrips; istrip++){
841
842     Float_t posLoc2[3]={posLocal[0],posLocal[1],posLocal[2]};         
843
844     step[0] = 0.;
845     step[1] = GetHeights(iplate,istrip);
846     step[2] = -GetDistances(iplate,istrip);
847     Translation(posLoc2,step);
848
849     if      (GetAngles(iplate,istrip) >0.) {
850       angles[0] = 90.;
851       angles[1] =  0.;
852       angles[2] = 90.+GetAngles(iplate,istrip);
853       angles[3] = 90.;
854       angles[4] = GetAngles(iplate,istrip);
855       angles[5] = 90.;
856     }
857     else if (GetAngles(iplate,istrip)==0.) {
858       angles[0] = 90.;
859       angles[1] =  0.;
860       angles[2] = 90.;
861       angles[3] = 90.;
862       angles[4] =  0;
863       angles[5] =  0.;
864     }
865     else if (GetAngles(iplate,istrip) <0.) {
866       angles[0] = 90.;
867       angles[1] =  0.;
868       angles[2] = 90.+GetAngles(iplate,istrip);
869       angles[3] = 90.;
870       angles[4] =-GetAngles(iplate,istrip);
871       angles[5] = 270.;
872     }
873     Rotation(posLoc2,angles);
874
875     if ((TMath::Abs(posLoc2[0])<=klstripx*0.5) &&
876         (TMath::Abs(posLoc2[1])<=khstripy*0.5) &&
877         (TMath::Abs(posLoc2[2])<=kwstripz*0.5)) {
878       iStrip = istrip;
879       totStrip++;
880       for (Int_t jj=0; jj<3; jj++) posLocal[jj]=posLoc2[jj];
881       //AliInfo(Form(" posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ", posLocal[0],posLocal[1],posLocal[2]));
882
883       //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]));
884       break;
885     }
886
887     if (totStrip>1) AliInfo(Form("total strip number found %2i",totStrip));
888
889   }
890
891   return iStrip;
892   
893 }
894 //_____________________________________________________________________________
895 Int_t AliTOFGeometryV5::GetPadZ(Float_t *pos)
896 {
897   //
898   // Returns the Pad index along Z 
899   //
900   //const Float_t klsensmx = kNpadX*fgkXPad;  // length of Sensitive Layer
901   //const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer
902   //const Float_t kwsensmz = kNpadZ*fgkZPad;  // width of Sensitive Layer
903
904   Int_t iPadZ = -1;
905
906   Float_t posLocal[3];
907   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
908  
909   Int_t isector = GetSector(posLocal);
910   if(isector == -1){
911     //AliError("Detector Index could not be determined");
912     return iPadZ;}
913   Int_t iplate =  GetPlate(posLocal);
914   if(iplate == -1){
915     //AliError("Detector Index could not be determined");
916     return iPadZ;}
917   Int_t istrip =  GetStrip(posLocal);
918   if(istrip == -1){
919     //AliError("Detector Index could not be determined");
920     return iPadZ;}
921
922   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
923   Double_t angles[6] = 
924     {90., 90.+(isector+0.5)*fPhiSec,
925       0., 0.,
926      90., (isector+0.5)*fPhiSec
927     };
928   Rotation(posLocal,angles);
929
930   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
931   Translation(posLocal,step);
932
933   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
934   angles[0] = 90.;
935   angles[1] =  0.;
936   angles[2] =  0.;
937   angles[3] =  0.;
938   angles[4] = 90.;
939   angles[5] =270.;
940
941   Rotation(posLocal,angles);
942
943   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
944   step[0] = 0.;
945   step[1] = GetHeights(iplate,istrip);
946   step[2] = -GetDistances(iplate,istrip);
947   Translation(posLocal,step);
948
949   if      (GetAngles(iplate,istrip) >0.) {
950     angles[0] = 90.;
951     angles[1] =  0.;
952     angles[2] = 90.+GetAngles(iplate,istrip);
953     angles[3] = 90.;
954     angles[4] = GetAngles(iplate,istrip);
955     angles[5] = 90.;
956   }
957   else if (GetAngles(iplate,istrip)==0.) {
958     angles[0] = 90.;
959     angles[1] =  0.;
960     angles[2] = 90.;
961     angles[3] = 90.;
962     angles[4] =  0;
963     angles[5] =  0.;
964   }
965   else if (GetAngles(iplate,istrip) <0.) {
966     angles[0] = 90.;
967     angles[1] =  0.;
968     angles[2] = 90.+GetAngles(iplate,istrip);
969     angles[3] = 90.;
970     angles[4] =-GetAngles(iplate,istrip);
971     angles[5] = 270.;
972   }
973   Rotation(posLocal,angles);
974
975   //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
976   //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
977
978     step[0] =-0.5*kNpadX*fgkXPad;
979     step[1] = 0.;
980     step[2] =-0.5*kNpadZ*fgkZPad;
981     Translation(posLocal,step);
982
983     iPadZ = (Int_t)(posLocal[2]/fgkZPad);
984     if (iPadZ==kNpadZ) iPadZ--;
985     else if (iPadZ>kNpadZ) iPadZ=-1;
986
987   //}
988   // else AliError("Detector Index could not be determined");
989
990   return iPadZ;
991
992 }
993 //_____________________________________________________________________________
994 Int_t AliTOFGeometryV5::GetPadX(Float_t *pos)
995 {
996   //
997   // Returns the Pad index along X 
998   //
999   //const Float_t klsensmx = kNpadX*fgkXPad;  // length of Sensitive Layer
1000   //const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer
1001   //const Float_t kwsensmz = kNpadZ*fgkZPad;  // width of Sensitive Layer
1002
1003   Int_t iPadX  = -1;
1004
1005   Float_t posLocal[3];
1006   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1007  
1008   Int_t isector = GetSector(posLocal);
1009   if(isector == -1){
1010     //AliError("Detector Index could not be determined");
1011     return iPadX;}
1012   Int_t iplate =  GetPlate(posLocal);
1013   if(iplate == -1){
1014     //AliError("Detector Index could not be determined");
1015     return iPadX;} 
1016   Int_t istrip =  GetStrip(posLocal);
1017   if(istrip == -1){  
1018     //AliError("Detector Index could not be determined");
1019     return iPadX;}
1020
1021   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1022   Double_t angles[6] = 
1023     {90., 90.+(isector+0.5)*fPhiSec,
1024       0.,  0.,
1025      90., (isector+0.5)*fPhiSec
1026     };
1027   Rotation(posLocal,angles);
1028
1029   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1030   Translation(posLocal,step);
1031
1032   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1033   angles[0] = 90.;
1034   angles[1] =  0.;
1035   angles[2] =  0.;
1036   angles[3] =  0.;
1037   angles[4] = 90.;
1038   angles[5] =270.;
1039
1040   Rotation(posLocal,angles);
1041
1042   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1043   step[0] = 0.;
1044   step[1] = GetHeights(iplate,istrip);
1045   step[2] = -GetDistances(iplate,istrip);
1046   Translation(posLocal,step);
1047
1048   if      (GetAngles(iplate,istrip) >0.) {
1049     angles[0] = 90.;
1050     angles[1] =  0.;
1051     angles[2] = 90.+GetAngles(iplate,istrip);
1052     angles[3] = 90.;
1053     angles[4] = GetAngles(iplate,istrip);
1054     angles[5] = 90.;
1055   }
1056   else if (GetAngles(iplate,istrip)==0.) {
1057     angles[0] = 90.;
1058     angles[1] =  0.;
1059     angles[2] = 90.;
1060     angles[3] = 90.;
1061     angles[4] =  0;
1062     angles[5] =  0.;
1063   }
1064   else if (GetAngles(iplate,istrip) <0.) {
1065     angles[0] = 90.;
1066     angles[1] =  0.;
1067     angles[2] = 90.+GetAngles(iplate,istrip);
1068     angles[3] = 90.;
1069     angles[4] =-GetAngles(iplate,istrip);
1070     angles[5] = 270.;
1071   }
1072   Rotation(posLocal,angles);
1073
1074   //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
1075   //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
1076
1077     step[0] =-0.5*kNpadX*fgkXPad;
1078     step[1] = 0.;
1079     step[2] =-0.5*kNpadZ*fgkZPad;
1080     Translation(posLocal,step);
1081
1082     iPadX = (Int_t)(posLocal[0]/fgkXPad);
1083     if (iPadX==kNpadX) iPadX--;
1084     else if (iPadX>kNpadX) iPadX=-1;
1085
1086   //}
1087   //else AliError("Detector Index could not be determined");
1088
1089   return iPadX;
1090
1091 }
1092 //_____________________________________________________________________________
1093
1094 Float_t AliTOFGeometryV5::GetPadDx(Float_t *pos)
1095 {
1096   //
1097   // Returns the x coordinate in the Pad reference frame
1098   //
1099
1100   Float_t xpad = -2.;
1101
1102   Float_t posLocal[3];
1103   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1104  
1105   Int_t isector = GetSector(posLocal);
1106   if(isector == -1){
1107     //AliError("Detector Index could not be determined");
1108     return xpad;}
1109   Int_t iplate =  GetPlate(posLocal);
1110   if(iplate == -1){
1111     //AliError("Detector Index could not be determined");
1112     return xpad;} 
1113   Int_t istrip =  GetStrip(posLocal);
1114   if(istrip == -1){  
1115     //AliError("Detector Index could not be determined");
1116     return xpad;}
1117   Int_t ipadz =  GetPadZ(posLocal);
1118   if(ipadz == -1){  
1119     //AliError("Detector Index could not be determined");
1120     return xpad;}
1121   Int_t ipadx =  GetPadX(posLocal);
1122   if(ipadx == -1){
1123     //AliError("Detector Index could not be determined");
1124     return xpad;}
1125
1126   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1127   Double_t angles[6] = 
1128     {90., 90.+(isector+0.5)*fPhiSec,
1129       0.,  0.,
1130      90., (isector+0.5)*fPhiSec
1131     };
1132   Rotation(posLocal,angles);
1133
1134   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1135   Translation(posLocal,step);
1136
1137   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1138   angles[0] = 90.;
1139   angles[1] =  0.;
1140   angles[2] =  0.;
1141   angles[3] =  0.;
1142   angles[4] = 90.;
1143   angles[5] =270.;
1144
1145   Rotation(posLocal,angles);
1146
1147   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1148   step[0] = 0.;
1149   step[1] = GetHeights(iplate,istrip);
1150   step[2] = -GetDistances(iplate,istrip);
1151   Translation(posLocal,step);
1152
1153   if      (GetAngles(iplate,istrip) >0.) {
1154     angles[0] = 90.;
1155     angles[1] =  0.;
1156     angles[2] = 90.+GetAngles(iplate,istrip);
1157     angles[3] = 90.;
1158     angles[4] = GetAngles(iplate,istrip);
1159     angles[5] = 90.;
1160   }
1161   else if (GetAngles(iplate,istrip)==0.) {
1162     angles[0] = 90.;
1163     angles[1] =  0.;
1164     angles[2] = 90.;
1165     angles[3] = 90.;
1166     angles[4] =  0;
1167     angles[5] =  0.;
1168   }
1169   else if (GetAngles(iplate,istrip) <0.) {
1170     angles[0] = 90.;
1171     angles[1] =  0.;
1172     angles[2] = 90.+GetAngles(iplate,istrip);
1173     angles[3] = 90.;
1174     angles[4] =-GetAngles(iplate,istrip);
1175     angles[5] = 270.;
1176   }
1177   Rotation(posLocal,angles);
1178
1179   step[0] =-0.5*kNpadX*fgkXPad;
1180   step[1] = 0.;
1181   step[2] =-0.5*kNpadZ*fgkZPad;
1182   Translation(posLocal,step);
1183
1184   step[0] = (ipadx+0.5)*fgkXPad;
1185   step[1] = 0.;
1186   step[2] = (ipadz+0.5)*fgkZPad;
1187   Translation(posLocal,step);
1188   
1189   xpad=posLocal[0];
1190
1191   return xpad;
1192
1193 }
1194 //_____________________________________________________________________________
1195 Float_t AliTOFGeometryV5::GetPadDy(Float_t *pos)
1196 {
1197   //
1198   // Returns the x coordinate in the Pad reference frame
1199   //
1200
1201   Float_t ypad = -2.;
1202
1203   Float_t posLocal[3];
1204   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1205  
1206   Int_t isector = GetSector(posLocal);
1207   if(isector == -1){
1208     //AliError("Detector Index could not be determined");
1209     return ypad;}
1210   Int_t iplate =  GetPlate(posLocal);
1211   if(iplate == -1){
1212     //AliError("Detector Index could not be determined");
1213     return ypad;} 
1214   Int_t istrip =  GetStrip(posLocal);
1215   if(istrip == -1){  
1216     //AliError("Detector Index could not be determined");
1217     return ypad;}
1218   Int_t ipadz =  GetPadZ(posLocal);
1219   if(ipadz == -1){  
1220     //AliError("Detector Index could not be determined");
1221     return ypad;}
1222   Int_t ipadx =  GetPadX(posLocal);
1223   if(ipadx == -1){
1224     //AliError("Detector Index could not be determined");
1225     return ypad;}
1226
1227   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1228   Double_t angles[6] = 
1229     {90., 90.+(isector+0.5)*fPhiSec,
1230       0.,  0.,
1231      90., (isector+0.5)*fPhiSec
1232     };
1233   Rotation(posLocal,angles);
1234
1235   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1236   Translation(posLocal,step);
1237
1238   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1239   angles[0] = 90.;
1240   angles[1] =  0.;
1241   angles[2] =  0.;
1242   angles[3] =  0.;
1243   angles[4] = 90.;
1244   angles[5] =270.;
1245
1246   Rotation(posLocal,angles);
1247
1248   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1249   step[0] = 0.;
1250   step[1] = GetHeights(iplate,istrip);
1251   step[2] = -GetDistances(iplate,istrip);
1252   Translation(posLocal,step);
1253
1254   if      (GetAngles(iplate,istrip) >0.) {
1255     angles[0] = 90.;
1256     angles[1] =  0.;
1257     angles[2] = 90.+GetAngles(iplate,istrip);
1258     angles[3] = 90.;
1259     angles[4] = GetAngles(iplate,istrip);
1260     angles[5] = 90.;
1261   }
1262   else if (GetAngles(iplate,istrip)==0.) {
1263     angles[0] = 90.;
1264     angles[1] =  0.;
1265     angles[2] = 90.;
1266     angles[3] = 90.;
1267     angles[4] =  0;
1268     angles[5] =  0.;
1269   }
1270   else if (GetAngles(iplate,istrip) <0.) {
1271     angles[0] = 90.;
1272     angles[1] =  0.;
1273     angles[2] = 90.+GetAngles(iplate,istrip);
1274     angles[3] = 90.;
1275     angles[4] =-GetAngles(iplate,istrip);
1276     angles[5] = 270.;
1277   }
1278   Rotation(posLocal,angles);
1279
1280   step[0] =-0.5*kNpadX*fgkXPad;
1281   step[1] = 0.;
1282   step[2] =-0.5*kNpadZ*fgkZPad;
1283   Translation(posLocal,step);
1284   
1285   step[0] = (ipadx+0.5)*fgkXPad;
1286   step[1] = 0.;
1287   step[2] = (ipadz+0.5)*fgkZPad;
1288   Translation(posLocal,step);
1289   
1290   ypad=posLocal[1];
1291   
1292   return ypad;
1293
1294 }
1295 //_____________________________________________________________________________
1296 Float_t AliTOFGeometryV5::GetPadDz(Float_t *pos)
1297 {
1298   //
1299   // Returns the x coordinate in the Pad reference frame
1300   //
1301
1302   Float_t zpad = -2.;
1303
1304   Float_t posLocal[3];
1305   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
1306  
1307   Int_t isector = GetSector(posLocal);
1308   if(isector == -1){
1309     //AliError("Detector Index could not be determined");
1310     return zpad;}
1311   Int_t iplate =  GetPlate(posLocal);
1312   if(iplate == -1){
1313     //AliError("Detector Index could not be determined");
1314     return zpad;} 
1315   Int_t istrip =  GetStrip(posLocal);
1316   if(istrip == -1){  
1317     //AliError("Detector Index could not be determined");
1318     return zpad;}
1319   Int_t ipadz =  GetPadZ(posLocal);
1320   if(ipadz == -1){  
1321     //AliError("Detector Index could not be determined");
1322     return zpad;}
1323   Int_t ipadx =  GetPadX(posLocal);
1324   if(ipadx == -1){
1325     //AliError("Detector Index could not be determined");
1326     return zpad;}
1327
1328   // ALICE reference frame -> B071/B074/B075 = BTO1/2/3 reference frame
1329   Double_t angles[6] = 
1330     {90., 90.+(isector+0.5)*fPhiSec,
1331       0.,  0.,
1332      90., (isector+0.5)*fPhiSec
1333     };
1334   Rotation(posLocal,angles);
1335
1336   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
1337   Translation(posLocal,step);
1338
1339   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA/B/C = FLTA/B/C reference frame
1340   angles[0] = 90.;
1341   angles[1] =  0.;
1342   angles[2] =  0.;
1343   angles[3] =  0.;
1344   angles[4] = 90.;
1345   angles[5] =270.;
1346
1347   Rotation(posLocal,angles);
1348
1349   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
1350   step[0] = 0.;
1351   step[1] = GetHeights(iplate,istrip);
1352   step[2] = -GetDistances(iplate,istrip);
1353   Translation(posLocal,step);
1354
1355   if      (GetAngles(iplate,istrip) >0.) {
1356     angles[0] = 90.;
1357     angles[1] =  0.;
1358     angles[2] = 90.+GetAngles(iplate,istrip);
1359     angles[3] = 90.;
1360     angles[4] = GetAngles(iplate,istrip);
1361     angles[5] = 90.;
1362   }
1363   else if (GetAngles(iplate,istrip)==0.) {
1364     angles[0] = 90.;
1365     angles[1] =  0.;
1366     angles[2] = 90.;
1367     angles[3] = 90.;
1368     angles[4] =  0;
1369     angles[5] =  0.;
1370   }
1371   else if (GetAngles(iplate,istrip) <0.) {
1372     angles[0] = 90.;
1373     angles[1] =  0.;
1374     angles[2] = 90.+GetAngles(iplate,istrip);
1375     angles[3] = 90.;
1376     angles[4] =-GetAngles(iplate,istrip);
1377     angles[5] = 270.;
1378   }
1379   Rotation(posLocal,angles);
1380
1381   step[0] =-0.5*kNpadX*fgkXPad;
1382   step[1] = 0.;
1383   step[2] =-0.5*kNpadZ*fgkZPad;
1384   Translation(posLocal,step);
1385   
1386   step[0] = (ipadx+0.5)*fgkXPad;
1387   step[1] = 0.;
1388   step[2] = (ipadz+0.5)*fgkZPad;
1389   Translation(posLocal,step);
1390
1391   zpad=posLocal[2];
1392
1393   return zpad;
1394
1395 }
1396 //_____________________________________________________________________________
1397
1398 void AliTOFGeometryV5::Translation(Float_t *xyz, Float_t translationVector[3])
1399 {
1400
1401   Int_t ii=0;
1402
1403   for (ii=0; ii<3; ii++)
1404     xyz[ii] -= translationVector[ii];
1405
1406   return;
1407
1408 }
1409 //_____________________________________________________________________________
1410
1411 void AliTOFGeometryV5::Rotation(Float_t *xyz, Double_t rotationAngles[6])
1412 {
1413
1414   Int_t ii=0;
1415   /*
1416   TRotMatrix *matrix = new TRotMatrix("matrix","matrix", angles[0], angles[1],
1417                                       angles[2], angles[3],
1418                                       angles[4], angles[5]);
1419   */
1420
1421   for (ii=0; ii<6; ii++) rotationAngles[ii]*=kDegrad;
1422
1423   Float_t xyzDummy[3] = {0., 0., 0.};
1424
1425   for (ii=0; ii<3; ii++) {
1426     xyzDummy[ii] =
1427       xyz[0]*TMath::Sin(rotationAngles[2*ii])*TMath::Cos(rotationAngles[2*ii+1]) +
1428       xyz[1]*TMath::Sin(rotationAngles[2*ii])*TMath::Sin(rotationAngles[2*ii+1]) +
1429       xyz[2]*TMath::Cos(rotationAngles[2*ii]);
1430   }
1431
1432   for (ii=0; ii<3; ii++) xyz[ii]=xyzDummy[ii];
1433
1434   return;
1435
1436 }
1437 //_____________________________________________________________________________
1438 void AliTOFGeometryV5::InverseRotation(Float_t *xyz, Double_t rotationAngles[6])
1439 {
1440
1441   Int_t ii=0;
1442
1443   for (ii=0; ii<6; ii++) rotationAngles[ii]*=kDegrad;
1444
1445   Float_t xyzDummy[3] = {0., 0., 0.};
1446
1447   xyzDummy[0] =
1448     xyz[0]*TMath::Sin(rotationAngles[0])*TMath::Cos(rotationAngles[1]) +
1449     xyz[1]*TMath::Sin(rotationAngles[2])*TMath::Cos(rotationAngles[3]) +
1450     xyz[2]*TMath::Sin(rotationAngles[4])*TMath::Cos(rotationAngles[5]);
1451   
1452   xyzDummy[1] =
1453     xyz[0]*TMath::Sin(rotationAngles[0])*TMath::Sin(rotationAngles[1]) +
1454     xyz[1]*TMath::Sin(rotationAngles[2])*TMath::Sin(rotationAngles[3]) +
1455     xyz[2]*TMath::Sin(rotationAngles[4])*TMath::Sin(rotationAngles[5]);
1456   
1457   xyzDummy[2] =
1458     xyz[0]*TMath::Cos(rotationAngles[0]) +
1459     xyz[1]*TMath::Cos(rotationAngles[2]) +
1460     xyz[2]*TMath::Cos(rotationAngles[4]);
1461   
1462   for (ii=0; ii<3; ii++) xyz[ii]=xyzDummy[ii];
1463
1464   return;
1465
1466 }
1467 //_____________________________________________________________________________