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