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