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