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