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