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