]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFGeometry.cxx
set systematics covariance matrix
[u/mrichter/AliRoot.git] / TOF / AliTOFGeometry.cxx
index a735b1c8cb58f3563feef4ee57f9c63508a8dd04..308cb675476cc343b6ad4c31e0cbb05081966965 100644 (file)
 
 /*
 $Log$
+Revision 1.20.1  2007/05/19 decaro
+         Added the following methods:
+             GetVolumeIndices(Int_t index, Int_t *det), to get
+          the volume indices (sector, plate, strip, padz, padx,
+          stored respectively in det[0], det[1], det[2], det[3], det[4])
+          from the calibration channel index;
+             NStrip(Int_t nPlate), to get the strips number
+          per each kind of TOF module.
+
 Revision 1.20  2007/10/08 17:52:55  decaro
 hole region in front of PHOS detector: update of sectors' numbers
 
@@ -109,8 +118,9 @@ Revision 0.01  2003/12/04 S.Arcelli
 //#include "TGeoMatrix.h"
 #include "TMath.h"
 
-#include "AliLog.h"
 #include "AliConst.h"
+#include "AliGeomManager.h"
+#include "AliLog.h"
 
 #include "AliTOFGeometry.h"
 
@@ -123,11 +133,10 @@ const Float_t AliTOFGeometry::fgkZlenB    = 146.5;    // length (cm) of the B mo
 const Float_t AliTOFGeometry::fgkZlenC    = 170.45;   // length (cm) of the C module
 const Float_t AliTOFGeometry::fgkMaxhZtof = 370.6;    // Max half z-size of TOF (cm)
 
-const Float_t AliTOFGeometry::fgkxTOF     = 371.-0.01;// Inner radius of the TOF for Reconstruction (cm)
-const Float_t AliTOFGeometry::fgkRmin     = 370.-0.01;// Inner radius of the TOF (cm)
-const Float_t AliTOFGeometry::fgkRmax     = 399.-0.01;// Outer radius of the TOF (cm)
+const Float_t AliTOFGeometry::fgkxTOF     = 372.00;// Inner radius of the TOF for Reconstruction (cm)
+const Float_t AliTOFGeometry::fgkRmin     = 371.00;// Inner radius of the TOF (cm)
+const Float_t AliTOFGeometry::fgkRmax     = 400.05;// Outer radius of the TOF (cm)
 
-const Int_t AliTOFGeometry::fgkTimeDiff   = 25000;  // Min signal separation (ps)
 const Float_t AliTOFGeometry::fgkXPad     = 2.5;    // Pad size in the x direction (cm)
 const Float_t AliTOFGeometry::fgkZPad     = 3.5;    // Pad size in the z direction (cm)
 
@@ -139,9 +148,16 @@ const Float_t AliTOFGeometry::fgkSigmaForTail2= 0.5;//Sig2 for simulation of TDC
 const Float_t AliTOFGeometry::fgkPhiSec= 20;//sector Phi width (deg)
 
 const Float_t AliTOFGeometry::fgkTdcBin = 24.4;     // time-of-flight bin width [ps]
-const Float_t AliTOFGeometry::fgkToTBin = 48.8;     // time-over-threshold  bin width [ps]
+const Float_t AliTOFGeometry::fgkToTBin = 48.8;     // time-over-threshold bin width [ps]
+const Float_t AliTOFGeometry::fgkBunchCrossingBin = fgkTdcBin * 1024; // bunch-crossing bin width [ps]
 
-const Float_t AliTOFGeometry::fgkAngles[kNPlates][kMaxNstrip] ={
+const Float_t AliTOFGeometry::fgkSlewTOTMin = 10.; // min TOT for slewing correction [ns]
+const Float_t AliTOFGeometry::fgkSlewTOTMax = 16.; // max TOT for slewing correction [ns]
+
+const Float_t AliTOFGeometry::fgkDeadTime = 25E+03;        // Single channel dead time (ps)
+const Float_t AliTOFGeometry::fgkMatchingWindow = fgkTdcBin*TMath::Power(2,13); // Matching window  (ps)
+
+const Float_t AliTOFGeometry::fgkAngles[kNPlates][kMaxNstrip] = {
     { 43.99,  43.20,  42.40,  41.59,  40.77,  39.94,  39.11,  38.25,  37.40,  36.53,
       35.65,  34.76,  33.87,  32.96,  32.05,  31.13,  30.19,  29.24,  12.33,  0.00},
 
@@ -157,7 +173,9 @@ const Float_t AliTOFGeometry::fgkAngles[kNPlates][kMaxNstrip] ={
     {-12.33, -29.24, -30.19, -31.13, -32.05, -32.96, -33.87, -34.76, -35.65, -36.53,
      -37.40, -38.25, -39.11, -39.94, -40.77, -41.59, -42.40, -43.20, -43.99,  0.00}
   };
-const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip]= {
+
+/*
+const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip] = {
     {-8.2,  -7.5,  -8.2,  -7.7,  -8.1,  -7.6,  -7.7,  -7.7,  -7.7,  -7.7,
      -7.5,  -7.2,  -7.3,  -7.5,  -7.6,  -7.8,  -8.3,  -9.3,  -3.1,   0.0},
 
@@ -168,14 +186,58 @@ const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip]= {
      -4.8,  -9.9,  -5.0, -10.4,  -2.5,   0.0,   0.0,   0.0,   0.0,   0.0},
 
     {-10.4, -7.4,  -4.6, -10.2,  -7.2,  -4.4, -10.4,  -8.0,  -5.8,  -3.6,
-     -10.1,  -7.7, -5.9,  -3.9, -10.1,  -9.0,  -8.5,  -8.1,  -7.9,   0.0},
+     -10.1, -7.7,  -5.9,  -3.9, -10.1,  -9.0,  -8.5,  -8.1,  -7.9,   0.0},
 
-    { -3.1,  -9.3, -8.3,  -7.8,  -7.6,  -7.5,  -7.3,  -7.2,  -7.5,  -7.7,
-      -7.7,  -7.7, -7.7,  -7.6,  -8.1,  -7.7,  -8.2,  -7.5,  -8.2,   0.0}
+    { -3.1, -9.3,  -8.3,  -7.8,  -7.6,  -7.5,  -7.3,  -7.2,  -7.5,  -7.7,
+      -7.7, -7.7,  -7.7,  -7.6,  -8.1,  -7.7,  -8.2,  -7.5,  -8.2,   0.0}
   };
+*/
+/*
+const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip] = {
+  {  -8.405, -10.885,  -8.405,  -7.765,  -8.285,  -7.745,  -7.865,  -7.905,  -7.895,  -7.885,
+     -7.705,  -7.395,  -7.525,  -7.645, -11.285, -10.355,  -8.365,  -9.385,  -3.255,   0.000 },
+  {  -7.905,  -8.235,  -8.605,  -9.045, -10.205,  -3.975,  -5.915,  -7.765, -10.205,  -3.635,
+     -5.885,  -8.005, -10.505,  -4.395,  -7.325, -10.235,  -4.655,  -7.495, -10.515,   0.000 },
+  {  -2.705, -10.645,  -5.165, -10.095,  -4.995, -10.815,  -4.835, -10.385,  -4.835, -10.815,
+     -4.995, -10.095,  -5.165, -10.645,  -2.705,   0.000,   0.000,   0.000,   0.000,   0.000 },
+  { -10.515,  -7.495,  -4.655, -10.235,  -7.325,  -4.395, -10.505,  -8.005,  -5.885,  -3.635,
+    -10.205,  -7.765,  -5.915,  -3.975, -10.205,  -9.045,  -8.605,  -8.235,  -7.905,   0.000 },
+  {  -3.255,  -9.385,  -8.365, -10.355, -11.285,  -7.645,  -7.525,  -7.395,  -7.705,  -7.885,
+     -7.895,  -7.905,  -7.865,  -7.745,  -8.285,  -7.765,  -8.405, -10.885,  -8.405,   0.000 }
+};
+*/
+
 
+const Float_t AliTOFGeometry::fgkHeights[kNPlates][kMaxNstrip] = {
+  { -8.405,  -7.725,  -8.405,  -7.765,  -8.285,  -7.745,  -7.865,  -7.905,  -7.895,  -7.885,
+    -7.705,  -7.395,  -7.525,  -7.645,  -7.835,  -7.965,  -8.365,  -9.385,  -3.255,   0.000 },
+  { -7.905,  -8.235,  -8.605,  -9.045, -10.205,  -3.975,  -5.915,  -7.765, -10.205,  -3.635,
+    -5.885,  -8.005, -10.505,  -4.395,  -7.325, -10.235,  -4.655,  -7.495, -10.515,   0.000 },
+  { -2.705, -10.645,  -5.165, -10.095,  -4.995, -10.085,  -4.835, -10.385,  -4.835, -10.085,
+    -4.995, -10.095,  -5.165, -10.645,  -2.705,   0.000,   0.000,   0.000,   0.000,   0.000 },
+  {-10.515,  -7.495,  -4.655, -10.235,  -7.325,  -4.395, -10.505,  -8.005,  -5.885,  -3.635,
+   -10.205,  -7.765,  -5.915,  -3.975, -10.205,  -9.045,  -8.605,  -8.235,  -7.905,   0.000 },
+  { -3.255,  -9.385,  -8.365,  -7.965,  -7.835,  -7.645,  -7.525,  -7.395,  -7.705,  -7.885,
+    -7.895,  -7.905,  -7.865,  -7.745,  -8.285,  -7.765,  -8.405,  -7.725,  -8.405,   0.000 }
+};
+
+
+
+const Float_t AliTOFGeometry::fgkDistances[kNPlates][kMaxNstrip] = {
+  { 364.14,  354.88,  344.49,  335.31,  325.44,  316.51,  307.11,  297.91,  288.84,  279.89,
+    271.20,  262.62,  253.84,  245.20,  236.56,  228.06,  219.46,  210.63,  206.09,    0.00 },
+  { 194.57,  186.38,  178.25,  170.13,  161.78,  156.62,  148.10,  139.72,  131.23,  125.87,
+    117.61,  109.44,  101.29,   95.46,   87.36,   79.37,   73.17,   65.33,   57.71,    0.00 },
+  {  49.28,   41.35,   35.37,   27.91,   21.20,   13.94,    7.06,    0.00,   -7.06,  -13.94,
+    -21.20,  -27.91,  -35.37,  -41.35,  -49.28,    0.00,    0.00,    0.00,    0.00,    0.00 },
+  { -57.71,  -65.33,  -73.17,  -79.37,  -87.36,  -95.46, -101.29, -109.44, -117.61, -125.87,
+   -131.23, -139.72, -148.10, -156.62, -161.78, -170.13, -178.25, -186.38, -194.57,    0.00 },
+  {-206.09, -210.63, -219.46, -228.06, -236.56, -245.20, -253.84, -262.62, -271.20, -279.89,
+   -288.84, -297.91, -307.11, -316.51, -325.44, -335.31, -344.49, -354.88, -364.14,    0.00 }
+};
 
-const Float_t AliTOFGeometry::fgkDistances[kNPlates][kMaxNstrip]= {
+/*
+const Float_t AliTOFGeometry::fgkDistances[kNPlates][kMaxNstrip] = {
     { 364.1,  354.9,  344.5,  335.4,  325.5,  316.6,  307.2,  298.0,  288.9,  280.0,
       271.3,  262.7,  254.0,  244.8,  236.1,  227.7,  219.1,  210.3,  205.7,    0.0},
 
@@ -191,6 +253,7 @@ const Float_t AliTOFGeometry::fgkDistances[kNPlates][kMaxNstrip]= {
     {-205.7, -210.3, -219.1, -227.7, -236.1, -244.8, -254.0, -262.7, -271.3, -280.0,
      -288.9, -298.0, -307.2, -316.6, -325.5, -335.4, -344.5, -354.9, -364.1,    0.0}
   };
+*/
 //_____________________________________________________________________________
 AliTOFGeometry::AliTOFGeometry():
   fHoles(1)
@@ -266,7 +329,7 @@ void AliTOFGeometry::DetToStripRF(Int_t nPadX, Int_t nPadZ, Float_t &x,  Float_t
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::DistanceToPadPar(Int_t *det, Float_t *pos, Float_t *dist3d) const
+Float_t AliTOFGeometry::DistanceToPadPar(Int_t *det, const Float_t * const pos, Float_t *dist3d) const
 {
 //
 // Returns distance of  space point with coor pos (x,y,z) (cm) wrt 
@@ -329,7 +392,7 @@ Float_t AliTOFGeometry::DistanceToPadPar(Int_t *det, Float_t *pos, Float_t *dist
 
 }
 //_____________________________________________________________________________
-Bool_t AliTOFGeometry::IsInsideThePadPar(Int_t *det, Float_t *pos) const
+Bool_t AliTOFGeometry::IsInsideThePadPar(Int_t *det, const Float_t * const pos) const
 {
 //
 // Returns true if space point with coor pos (x,y,z) (cm) falls 
@@ -400,44 +463,65 @@ Bool_t AliTOFGeometry::IsInsideThePadPar(Int_t *det, Float_t *pos) const
 
 }
 //_____________________________________________________________________________
-Bool_t AliTOFGeometry::IsInsideThePad(TGeoHMatrix mat, Float_t *pos, Float_t *dist3d) const
+Bool_t AliTOFGeometry::IsInsideThePad(TGeoHMatrix mat, const Float_t * const pos, Float_t *dist3d) const
 {
-//
-// Returns true if space point with coor pos (x,y,z) (cm) falls 
-// inside pad with Detector Indices idet (iSect,iPlate,iStrip,iPadX,iPadZ) 
-//
+  //
+  // Returns true if space point with coor pos (x,y,z) [cm] falls inside
+  // pad identified by the matrix mat. In case dist3d!=0, dist3d vector
+  // has been filled with the 3D distance between the impact point on
+  // the pad and the pad centre (in the reference frame of the TOF pad
+  // identified by the matrix mat).
+  //
 
   const Float_t kPadDepth = 0.5;      // heigth of Sensitive Layer
-  Double_t vecg[3];
-  vecg[0]=pos[0];
-  vecg[1]=pos[1];
-  vecg[2]=pos[2];
-  Double_t veclr[3]={-1.,-1.,-1.};
-  Double_t vecl[3]={-1.,-1.,-1.};
-  mat.MasterToLocal(vecg,veclr);  
-  vecl[0]=veclr[1];
-  vecl[1]=veclr[0];
-  //take into account reflections 
-  vecl[2]=-veclr[2];
-
-  Float_t xr = vecl[0];
-  Float_t yr = vecl[1];
-  Float_t zr = vecl[2];
 
-  if (dist3d){
-    dist3d[0] = vecl[0];
-    dist3d[1] = vecl[1];
-    dist3d[2] = vecl[2];
+  Double_t posg[3];
+  posg[0] = pos[0];
+  posg[1] = pos[1];
+  posg[2] = pos[2];
+
+  // from ALICE global reference system
+  // towards TOF pad reference system
+  Double_t posl[3] = {0., 0., 0.};
+  mat.MasterToLocal(posg,posl);
+
+  Float_t xr = posl[0];
+  Float_t yr = posl[1];
+  Float_t zr = posl[2];
+
+  Bool_t isInside = false;
+  if (TMath::Abs(yr)<= kPadDepth*0.5 &&
+      TMath::Abs(xr)<= fgkXPad*0.5 &&
+      TMath::Abs(zr)<= fgkZPad*0.5)
+    isInside = true;
+
+  if (dist3d) {
+    //Double_t padl[3] = {0., 0., 0.};
+    dist3d[0] = posl[0]/* - padl[0]*/;
+    dist3d[1] = posl[1]/* - padl[1]*/;
+    dist3d[2] = posl[2]/* - padl[2]*/;
+
+    /*
+    Double_t padg[3] = {0., 0., 0.};
+    // from TOF pad local reference system
+    // towards ALICE global reference system
+    TGeoHMatrix inverse = mat.Inverse();
+    inverse.MasterToLocal(padl,padg);
+
+    // returns the 3d distance
+    // between the impact point on the pad
+    // and the pad centre (in the ALICE global reference frame)
+    dist3d[0] = posg[0] - padg[0];
+    dist3d[1] = posg[1] - padg[1];
+    dist3d[2] = posg[2] - padg[2];
+    */
   }
  
-  Bool_t isInside=false; 
-  if(TMath::Abs(xr)<= kPadDepth*0.5 && TMath::Abs(yr)<= (fgkXPad*0.5) && TMath::Abs(zr)<= (fgkZPad*0.5))
-    isInside=true; 
   return isInside;
 
 }
 //_____________________________________________________________________________
-void AliTOFGeometry::GetVolumePath(Int_t *ind, Char_t *path ) {
+void AliTOFGeometry::GetVolumePath(const Int_t * const ind, Char_t *path ) {
   //--------------------------------------------------------------------
   // This function returns the colume path of a given pad 
   //--------------------------------------------------------------------
@@ -537,7 +621,7 @@ void AliTOFGeometry::GetPos(Int_t *det, Float_t *pos)
   pos[2]=tr[2];
 }
 //_____________________________________________________________________________
-Int_t AliTOFGeometry::GetPlate(Float_t *pos) const
+Int_t AliTOFGeometry::GetPlate(const Float_t * const pos) const
 {
   //
   // Returns the Plate index 
@@ -622,26 +706,23 @@ Int_t AliTOFGeometry::GetPlate(Float_t *pos) const
       }
     }
 
-  if      (zLocal>-fgkZlenA*0.5/*fgkMaxhZtof*/ && zLocal<-kExterInterModBorder2)       iPlate = 0;
-  else if (zLocal>-kExterInterModBorder1       && zLocal<-kInterCentrModBorder2)       iPlate = 1;
-  else if (zLocal>-kInterCentrModBorder1       && zLocal< kInterCentrModBorder1)       iPlate = 2;
-  else if (zLocal> kInterCentrModBorder2       && zLocal< kExterInterModBorder1)       iPlate = 3;
-  else if (zLocal> kExterInterModBorder2       && zLocal< fgkZlenA*0.5/*fgkMaxhZtof*/) iPlate = 4;
+  if      (zLocal>-fgkZlenA*0.5          && zLocal<-kExterInterModBorder2) iPlate = 0;
+  else if (zLocal>-kExterInterModBorder1 && zLocal<-kInterCentrModBorder2) iPlate = 1;
+  else if (zLocal>-kInterCentrModBorder1 && zLocal< kInterCentrModBorder1) iPlate = 2;
+  else if (zLocal> kInterCentrModBorder2 && zLocal< kExterInterModBorder1) iPlate = 3;
+  else if (zLocal> kExterInterModBorder2 && zLocal< fgkZlenA*0.5)          iPlate = 4;
   
   return iPlate;
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTOFGeometry::GetSector(Float_t *pos) const
+Int_t AliTOFGeometry::GetSector(const Float_t * const pos) const
 {
   //
   // Returns the Sector index 
   //
 
-  //const Float_t khAlWall = 0.1;
-  //const Float_t kModuleWallThickness = 0.3;
-
   Int_t   iSect = -1; 
 
   Float_t x = pos[0];
@@ -650,10 +731,8 @@ Int_t AliTOFGeometry::GetSector(Float_t *pos) const
 
   Float_t rho = TMath::Sqrt(x*x + y*y);
 
-  //if (!((z>=-fgkMaxhZtof && z<=fgkMaxhZtof) &&
   if (!((z>=-fgkZlenA*0.5 && z<=fgkZlenA*0.5) &&
        (rho>=(fgkRmin) && rho<=(fgkRmax)))) {
-    //(rho>=(fgkRmin-0.05)+kModuleWallThickness && rho<=(fgkRmax-0.05)-kModuleWallThickness-khAlWall-kModuleWallThickness))) {
     //AliError("Detector Index could not be determined");
     return iSect;
   }
@@ -666,7 +745,7 @@ Int_t AliTOFGeometry::GetSector(Float_t *pos) const
 
 }
 //_____________________________________________________________________________
-Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
+Int_t AliTOFGeometry::GetStrip(const Float_t * const pos) const
 {
   //
   // Returns the Strip index 
@@ -685,7 +764,9 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
    
   Float_t posLocal[3];
   for (Int_t ii=0; ii<3; ii++) posLocal[ii] = pos[ii];
+  AliDebug(1,Form("  posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ",
+                 posLocal[0],posLocal[1],posLocal[2]));
+
   Int_t isector = GetSector(posLocal);
   if(isector == -1){
     //AliError("Detector Index could not be determined");
@@ -698,14 +779,10 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
   Int_t nstrips=0;
   switch (iplate) {
   case 0:
-    nstrips=kNStripC;
-    break;
   case 4:
     nstrips=kNStripC;
     break;
   case 1:
-    nstrips=kNStripB;
-    break;
   case 3:
     nstrips=kNStripB;
     break;
@@ -721,9 +798,13 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
      90., (isector+0.5)*fgkPhiSec
     };
   Rotation(posLocal,angles);
+  AliDebug(1,Form("  posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ",
+                 posLocal[0],posLocal[1],posLocal[2]));
 
   Float_t step[3] = {0., 0., (fgkRmax+fgkRmin)*0.5};
   Translation(posLocal,step);
+  AliDebug(1,Form("  posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ",
+                 posLocal[0],posLocal[1],posLocal[2]));
 
   // B071/B074/B075 = BTO1/2/3 reference frame -> FTOA = FLTA reference frame
   angles[0] = 90.;
@@ -734,6 +815,8 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
   angles[5] =270.;
 
   Rotation(posLocal,angles);
+  AliDebug(1,Form("  posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ",
+                 posLocal[0],posLocal[1],posLocal[2]));
 
   // FTOA/B/C = FLTA/B/C reference frame -> FSTR reference frame
   Int_t totStrip=0;
@@ -771,6 +854,8 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
       angles[5] = 270.;
     }
     Rotation(posLoc2,angles);
+    AliDebug(1,Form(" strip %2d:  posLoc2[0] = %f, posLoc2[1] = %f, posLoc2[2] = %f ",
+                   istrip, posLoc2[0],posLoc2[1],posLoc2[2]));
 
     if ((TMath::Abs(posLoc2[0])<=klstripx*0.5) &&
        (TMath::Abs(posLoc2[1])<=khstripy*0.5) &&
@@ -778,9 +863,11 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
       iStrip = istrip;
       totStrip++;
       for (Int_t jj=0; jj<3; jj++) posLocal[jj]=posLoc2[jj];
-      //AliInfo(Form(" posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ", posLocal[0],posLocal[1],posLocal[2]));
+      AliDebug(2,Form(" posLocal[0] = %f, posLocal[1] = %f, posLocal[2] = %f ",
+                     posLocal[0],posLocal[1],posLocal[2]));
 
-      //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]));
+      AliDebug(2,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]));
       break;
     }
 
@@ -792,7 +879,7 @@ Int_t AliTOFGeometry::GetStrip(Float_t *pos) const
   
 }
 //_____________________________________________________________________________
-Int_t AliTOFGeometry::GetPadZ(Float_t *pos) const
+Int_t AliTOFGeometry::GetPadZ(const Float_t * const pos) const
 {
   //
   // Returns the Pad index along Z 
@@ -872,26 +959,20 @@ Int_t AliTOFGeometry::GetPadZ(Float_t *pos) const
   }
   Rotation(posLocal,angles);
 
-  //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
-  //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
-
-    step[0] =-0.5*kNpadX*fgkXPad;
-    step[1] = 0.;
-    step[2] =-0.5*kNpadZ*fgkZPad;
-    Translation(posLocal,step);
-
-    iPadZ = (Int_t)(posLocal[2]/fgkZPad);
-    if (iPadZ==kNpadZ) iPadZ--;
-    else if (iPadZ>kNpadZ) iPadZ=-1;
+  step[0] =-0.5*kNpadX*fgkXPad;
+  step[1] = 0.;
+  step[2] =-0.5*kNpadZ*fgkZPad;
+  Translation(posLocal,step);
 
-  //}
-  // else AliError("Detector Index could not be determined");
+  iPadZ = (Int_t)(posLocal[2]/fgkZPad);
+  if (iPadZ==kNpadZ) iPadZ--;
+  else if (iPadZ>kNpadZ) iPadZ=-1;
 
   return iPadZ;
 
 }
 //_____________________________________________________________________________
-Int_t AliTOFGeometry::GetPadX(Float_t *pos) const
+Int_t AliTOFGeometry::GetPadX(const Float_t * const pos) const
 {
   //
   // Returns the Pad index along X 
@@ -971,26 +1052,20 @@ Int_t AliTOFGeometry::GetPadX(Float_t *pos) const
   }
   Rotation(posLocal,angles);
 
-  //if (TMath::Abs(posLocal[0])<=klsensmx*0.5 && /*TMath::Abs(posLocal[1])<=khsensmy*0.5+0.005 &&*/ TMath::Abs(posLocal[2])<=kwsensmz*0.5) {
-  //if (TMath::Abs(posLocal[1])<=khsensmy*0.5) {
-
-    step[0] =-0.5*kNpadX*fgkXPad;
-    step[1] = 0.;
-    step[2] =-0.5*kNpadZ*fgkZPad;
-    Translation(posLocal,step);
-
-    iPadX = (Int_t)(posLocal[0]/fgkXPad);
-    if (iPadX==kNpadX) iPadX--;
-    else if (iPadX>kNpadX) iPadX=-1;
+  step[0] =-0.5*kNpadX*fgkXPad;
+  step[1] = 0.;
+  step[2] =-0.5*kNpadZ*fgkZPad;
+  Translation(posLocal,step);
 
-  //}
-  //else AliError("Detector Index could not be determined");
+  iPadX = (Int_t)(posLocal[0]/fgkXPad);
+  if (iPadX==kNpadX) iPadX--;
+  else if (iPadX>kNpadX) iPadX=-1;
 
   return iPadX;
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetX(Int_t *det) const
+Float_t AliTOFGeometry::GetX(const Int_t * const det) const
 {
   //
   // Returns X coordinate (cm)
@@ -1023,7 +1098,6 @@ Float_t AliTOFGeometry::GetX(Int_t *det) const
   */
 
   // Pad reference frame -> FSTR reference frame
-  //  /*
   Float_t posLocal[3] = {0., 0., 0.};
   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
   Translation(posLocal,step);
@@ -1031,7 +1105,6 @@ Float_t AliTOFGeometry::GetX(Int_t *det) const
   step[0] = kNpadX*0.5*fgkXPad;
   step[1] = 0.;
   step[2] = kNpadZ*0.5*fgkZPad;
-  //  */
   /*
   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
@@ -1103,7 +1176,7 @@ Float_t AliTOFGeometry::GetX(Int_t *det) const
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetY(Int_t *det) const
+Float_t AliTOFGeometry::GetY(const Int_t * const det) const
 {
   //
   // Returns Y coordinate (cm)
@@ -1136,7 +1209,6 @@ Float_t AliTOFGeometry::GetY(Int_t *det) const
   */
 
   // Pad reference frame -> FSTR reference frame
-  //  /*
   Float_t posLocal[3] = {0., 0., 0.};
   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
   Translation(posLocal,step);
@@ -1144,7 +1216,6 @@ Float_t AliTOFGeometry::GetY(Int_t *det) const
   step[0] = kNpadX*0.5*fgkXPad;
   step[1] = 0.;
   step[2] = kNpadZ*0.5*fgkZPad;
-  //  */
   /*
   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
@@ -1218,7 +1289,7 @@ Float_t AliTOFGeometry::GetY(Int_t *det) const
 }
 
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetZ(Int_t *det) const
+Float_t AliTOFGeometry::GetZ(const Int_t * const det) const
 {
   //
   // Returns Z coordinate (cm)
@@ -1236,7 +1307,6 @@ Float_t AliTOFGeometry::GetZ(Int_t *det) const
   */
 
   // Pad reference frame -> FSTR reference frame
-  //  /*
   Float_t posLocal[3] = {0., 0., 0.};
   Float_t step[3] = {-(ipadx+0.5)*fgkXPad, 0., -(ipadz+0.5)*fgkZPad};
   Translation(posLocal,step);
@@ -1244,7 +1314,6 @@ Float_t AliTOFGeometry::GetZ(Int_t *det) const
   step[0] = kNpadX*0.5*fgkXPad;
   step[1] = 0.;
   step[2] = kNpadZ*0.5*fgkZPad;
-  //  */
   /*
   Float_t posLocal[3] = {(ipadx+0.5)*fgkXPad, 0., (ipadz+0.5)*fgkZPad};
   Float_t step[3]= {kNpadX*0.5*fgkXPad, 0., kNpadZ*0.5*fgkZPad};
@@ -1382,7 +1451,7 @@ void AliTOFGeometry::DetToSectorRF(Int_t vol[5], Double_t **coord)
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetPadDx(Float_t *pos)
+Float_t AliTOFGeometry::GetPadDx(const Float_t * const pos)
 {
   //
   // Returns the x coordinate in the Pad reference frame
@@ -1483,7 +1552,7 @@ Float_t AliTOFGeometry::GetPadDx(Float_t *pos)
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetPadDy(Float_t *pos)
+Float_t AliTOFGeometry::GetPadDy(const Float_t * const pos)
 {
   //
   // Returns the y coordinate in the Pad reference frame
@@ -1584,7 +1653,7 @@ Float_t AliTOFGeometry::GetPadDy(Float_t *pos)
 
 }
 //_____________________________________________________________________________
-Float_t AliTOFGeometry::GetPadDz(Float_t *pos)
+Float_t AliTOFGeometry::GetPadDz(const Float_t * const pos)
 {
   //
   // Returns the z coordinate in the Pad reference frame
@@ -1735,7 +1804,7 @@ void AliTOFGeometry::Rotation(Float_t *xyz, Double_t rotationAngles[6]) const
 void AliTOFGeometry::InverseRotation(Float_t *xyz, Double_t rotationAngles[6]) const
 {
   //
-  //
+  // Rotates the vector xyz acordint to the rotationAngles
   //
 
   Int_t ii=0;
@@ -1766,22 +1835,210 @@ void AliTOFGeometry::InverseRotation(Float_t *xyz, Double_t rotationAngles[6]) c
 }
 //_____________________________________________________________________________
 
-Int_t AliTOFGeometry::GetIndex(Int_t *detId)
+Int_t AliTOFGeometry::GetIndex(const Int_t * const detId)
 {
   //Retrieve calibration channel index 
   Int_t isector = detId[0];
   if (isector >= kNSectors){
-    printf("Wrong sector number in TOF (%d) !",isector);
+    printf("Wrong sector number in TOF (%d) !\n",isector);
     return -1;
   }
   Int_t iplate = detId[1];
   if (iplate >= kNPlates){
-    printf("Wrong plate number in TOF (%d) !",iplate);
+    printf("Wrong plate number in TOF (%d) !\n",iplate);
     return -1;
   }
   Int_t istrip = detId[2];
+  Int_t stripOffset = GetStripNumberPerSM(iplate,istrip);
+  if (stripOffset==-1) {
+    printf("Wrong strip number per SM in TOF (%d) !\n",stripOffset);
+    return -1;
+  }
+
   Int_t ipadz = detId[3];
   Int_t ipadx = detId[4];
+
+  Int_t idet = ((2*(kNStripC+kNStripB)+kNStripA)*kNpadZ*kNpadX)*isector +
+               (stripOffset*kNpadZ*kNpadX)+
+              (kNpadX)*ipadz+
+               ipadx;
+  return idet;
+}
+//_____________________________________________________________________________
+
+void AliTOFGeometry::GetVolumeIndices(Int_t index, Int_t *detId)
+{
+  //
+  // Retrieve volume indices from the calibration channel index 
+  //
+
+  detId[0] = index/NpadXStrip()/NStripXSector();
+
+  Int_t dummyStripPerModule = 
+    ( index - ( NStripXSector()*NpadXStrip()*detId[0]) ) / NpadXStrip();
+  if (dummyStripPerModule<kNStripC) {
+    detId[1] = 0;
+    detId[2] = dummyStripPerModule;
+  }
+  else if (dummyStripPerModule>=kNStripC && dummyStripPerModule<kNStripC+kNStripB) {
+    detId[1] = 1;
+    detId[2] = dummyStripPerModule-kNStripC;
+  }
+  else if (dummyStripPerModule>=kNStripC+kNStripB && dummyStripPerModule<kNStripC+kNStripB+kNStripA) {
+    detId[1] = 2;
+    detId[2] = dummyStripPerModule-kNStripC-kNStripB;
+  }
+  else if (dummyStripPerModule>=kNStripC+kNStripB+kNStripA && dummyStripPerModule<kNStripC+kNStripB+kNStripA+kNStripB) {
+    detId[1] = 3;
+    detId[2] = dummyStripPerModule-kNStripC-kNStripB-kNStripA;
+  }
+  else if (dummyStripPerModule>=kNStripC+kNStripB+kNStripA+kNStripB && dummyStripPerModule<NStripXSector()) {
+    detId[1] = 4;
+    detId[2] = dummyStripPerModule-kNStripC-kNStripB-kNStripA-kNStripB;
+  }
+
+  Int_t padPerStrip = ( index - ( NStripXSector()*NpadXStrip()*detId[0]) ) - dummyStripPerModule*NpadXStrip();
+
+  detId[3] = padPerStrip / kNpadX; // padZ
+  detId[4] = padPerStrip - detId[3]*kNpadX; // padX
+
+}
+//_____________________________________________________________________________
+
+Int_t AliTOFGeometry::NStrip(Int_t nPlate)
+{
+  //
+  // Returns the strips number for the plate number 'nPlate'
+  //
+
+  Int_t nStrips = kNStripC;
+
+  switch(nPlate) {
+  case 2:
+    nStrips = kNStripA;
+    break;
+  case 1:
+  case 3:
+    nStrips = kNStripB;
+    break;
+  case 0:
+  case 4:
+  default:
+    nStrips = kNStripC;
+    break;
+  }
+
+  return nStrips;
+
+}
+//-------------------------------------------------------------------------
+
+UShort_t AliTOFGeometry::GetAliSensVolIndex(Int_t isector, Int_t iplate, Int_t istrip) const
+{
+  //
+  // Get the index of the TOF alignable volume in the AliGeomManager order.
+  //
+
+  Int_t index = GetStripNumber(isector, iplate, istrip);
+
+  UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
+
+  return volIndex;
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetStripNumber(Int_t isector, Int_t iplate, Int_t istrip)
+{
+  //
+  // Get the serial number of the TOF strip number istrip [0,14/18],
+  //   in the module number iplate [0,4],
+  //   in the TOF SM number isector [0,17].
+  // This number will range in [0,1637].
+  //
+
+  Bool_t check = (isector >= kNSectors);
+
+  if (check)
+    printf("E-AliTOFGeometry::GetStripNumber: Wrong sector number in TOF (%d)!\n",isector);
+
+  Int_t index = -1;
+  Int_t stripInSM = GetStripNumberPerSM(iplate, istrip);
+  if (!check && stripInSM!=-1)
+    index = (2*(kNStripC+kNStripB)+kNStripA)*isector + stripInSM;
+
+  return index;
+
+}
+//-------------------------------------------------------------------------
+
+void AliTOFGeometry::GetStripAndModule(Int_t iStripPerSM, Int_t &iplate, Int_t &istrip)
+{
+  //
+  // Convert the serial number of the TOF strip number iStripPerSM [0,90]
+  // in module number iplate [0,4] and strip number istrip [0,14/18].
+  //
+
+  if (iStripPerSM<0 || iStripPerSM>=kNStripC+kNStripB+kNStripA+kNStripB+kNStripC) {
+    iplate = -1;
+    istrip = -1;
+  }
+  else if (iStripPerSM<kNStripC) {
+    iplate = 0;
+    istrip = iStripPerSM;
+  }
+  else if (iStripPerSM>=kNStripC && iStripPerSM<kNStripC+kNStripB) {
+    iplate = 1;
+    istrip = iStripPerSM-kNStripC;
+  }
+  else if (iStripPerSM>=kNStripC+kNStripB && iStripPerSM<kNStripC+kNStripB+kNStripA) {
+    iplate = 2;
+    istrip = iStripPerSM-kNStripC-kNStripB;
+  }
+  else if (iStripPerSM>=kNStripC+kNStripB+kNStripA && iStripPerSM<kNStripC+kNStripB+kNStripA+kNStripB) {
+    iplate = 3;
+    istrip = iStripPerSM-kNStripC-kNStripB-kNStripA;
+  }
+  else if (iStripPerSM>=kNStripC+kNStripB+kNStripA+kNStripB && iStripPerSM<kNStripC+kNStripB+kNStripA+kNStripB+kNStripC) {
+    iplate = 4;
+    istrip = iStripPerSM-kNStripC-kNStripB-kNStripA-kNStripB;
+  }
+
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetStripNumberPerSM(Int_t iplate, Int_t istrip)
+{
+  //
+  // Get the serial number of the TOF strip number istrip [0,14/18],
+  //   in the module number iplate [0,4].
+  // This number will range in [0,90].
+  //
+
+  Int_t index = -1;
+
+  Bool_t check = (
+                 (iplate<0 || iplate>=kNPlates)
+                 ||
+                 (
+                  (iplate==2 && (istrip<0 || istrip>=kNStripA))
+                  ||
+                  (iplate!=2 && (istrip<0 || istrip>=kNStripC))
+                  )
+                 );
+
+  if (iplate<0 || iplate>=kNPlates)
+    printf("E-AliTOFGeometry::GetStripNumberPerSM: Wrong plate number in TOF (%1d)!\n",iplate);
+
+  if (
+      (iplate==2 && (istrip<0 || istrip>=kNStripA))
+      ||
+      (iplate!=2 && (istrip<0 || istrip>=kNStripC))
+      )
+    printf("E-AliTOFGeometry::GetStripNumberPerSM: Wrong strip number in TOF "
+          "(strip=%2d in the plate=%1d)!\n",istrip,iplate);
+
   Int_t stripOffset = 0;
   switch (iplate) {
   case 0:
@@ -1799,19 +2056,147 @@ Int_t AliTOFGeometry::GetIndex(Int_t *detId)
   case 4:
     stripOffset = kNStripC+kNStripB+kNStripA+kNStripB;
     break;
-  default:
-    printf("Wrong plate number in TOF (%d) !",iplate);
-    return -1;
   };
 
-  Int_t idet = ((2*(kNStripC+kNStripB)+kNStripA)
-               *kNpadZ*kNpadX)*isector +
-               (stripOffset*kNpadZ*kNpadX)+
-               (kNpadZ*kNpadX)*istrip+
-              (kNpadX)*ipadz+
-               ipadx;
-  return idet;
+  if (!check) index = stripOffset + istrip;
+
+  return index;
+
 }
+//-------------------------------------------------------------------------
 
+void AliTOFGeometry::PadRF2TrackingRF(Float_t *ctrackPos, Float_t *differenceT)
+{
+  //
+  // To convert the 3D distance ctrackPos, referred to the ALICE RF,
+  // into the 3D distance differenceT, referred to the tracking RF
+  // in case ctrakPos belongs to a TOF sensitive volume.
+  //
+
+  for (Int_t ii=0; ii<3; ii++) differenceT[ii] = 999.;
+
+  AliDebug(1,Form(" track position in ALICE global Ref. frame -> %f, %f, %f",
+                 ctrackPos[0],ctrackPos[1],ctrackPos[2]));
+
+  Int_t detId[5] = {-1,-1,-1,-1,-1};
 
+  detId[0] = GetSector(ctrackPos);
+  if (detId[0]==-1) {
+    AliWarning(Form("This point does not belong to any TOF sector"));
+    return;
+  }
+
+  detId[1] = GetPlate(ctrackPos);
+  if (detId[1]==-1) {
+    AliWarning(Form("This point does not belong to any TOF module"));
+    return;
+  }
+
+  detId[2] = GetStrip(ctrackPos);
+  if (detId[2]==-1) {
+    AliWarning(Form("This point does not belong to any TOF strip"));
+    return;
+  }
 
+  detId[3] = GetPadZ(ctrackPos);
+  if (detId[3]==-1) {
+    AliWarning(Form("This point does not belong to any TOF pad-row"));
+    return;
+  }
+
+  detId[4] = GetPadX(ctrackPos);
+  if (detId[4]==-1) {
+    AliWarning(Form("This point does not belong to any TOF pad"));
+    return;
+  }
+
+
+  UShort_t alignableStripIndex =
+    GetAliSensVolIndex(detId[0],detId[1],detId[2]);
+  AliDebug(1,Form(" sector = %2d, plate = %1d, strip = %2d (padZ = %1d, padX = %2d) "
+                 "---> stripIndex = %4d",
+                 detId[0], detId[1], detId[2], detId[3], detId[4], alignableStripIndex));
+
+  // pad centre coordinates in the strip ref. frame
+  Double_t padCentreL[3] = {(detId[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()
+                           +AliTOFGeometry::XPad()/2.,
+                           0.,
+                           (detId[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::XPad()
+                           +AliTOFGeometry::XPad()/2.};
+  // pad centre coordinates in the strip tracking frame
+  Double_t padCentreT[3] = {0., 0., 0.};
+  TGeoHMatrix l2t = *AliGeomManager::GetTracking2LocalMatrix(alignableStripIndex);
+  l2t.MasterToLocal(padCentreL,padCentreT);
+
+
+  Char_t path[100];
+  // pad centre coordinates in its ref. frame
+  Double_t padCentreL2[3] = {0., 0., 0.};
+  // pad centre coordinates in the ALICE global ref. frame
+  Double_t padCentreG[3] = {0., 0., 0.};
+  GetVolumePath(detId,path);
+  gGeoManager->cd(path);
+  TGeoHMatrix g2l = *gGeoManager->GetCurrentMatrix();
+  TGeoHMatrix l2g = g2l.Inverse();
+  l2g.MasterToLocal(padCentreL2,padCentreG);
+
+
+  Char_t path2[100];
+  // strip centre coordinates in its ref. frame
+  Double_t stripCentreL[3] = {0., 0., 0.};
+  // strip centre coordinates in the ALICE global ref. frame
+  Double_t stripCentreG[3] = {0., 0., 0.};
+  GetVolumePath(detId[0],detId[1],detId[2],path2);
+  gGeoManager->cd(path2);
+  TGeoHMatrix g2lb = *gGeoManager->GetCurrentMatrix();
+  TGeoHMatrix l2gb = g2lb.Inverse();
+  l2gb.MasterToLocal(stripCentreL,stripCentreG);
+
+  TGeoHMatrix g2t = 0;
+  AliGeomManager::GetTrackingMatrix(alignableStripIndex, g2t);
+
+  // track position in the ALICE global ref. frame
+  Double_t posG[3];
+  for (Int_t ii=0; ii<3; ii++) posG[ii] = (Double_t)ctrackPos[ii];
+
+  // strip centre coordinates in the tracking ref. frame
+  Double_t stripCentreT[3] = {0., 0., 0.};
+  // track position in the tracking ref. frame
+  Double_t posT[3] = {0., 0., 0.};
+  g2t.MasterToLocal(posG,posT);
+  g2t.MasterToLocal(stripCentreG,stripCentreT);
+
+  for (Int_t ii=0; ii<3; ii++)
+    AliDebug(1,Form(" track position in ALICE global and tracking RFs -> posG[%d] = %f --- posT[%d] = %f",
+                   ii, posG[ii], ii, posT[ii]));
+  for (Int_t ii=0; ii<3; ii++)
+    AliDebug(1,Form(" pad centre coordinates in its, the ALICE global and tracking RFs -> "
+                   "padCentreL[%d] = %f --- padCentreG[%d] = %f --- padCentreT[%d] = %f",
+                   ii, padCentreL[ii],
+                   ii, padCentreG[ii],
+                   ii, padCentreT[ii]));
+  for (Int_t ii=0; ii<3; ii++)
+    AliDebug(1,Form(" strip centre coordinates in its, the ALICE global and tracking RFs -> "
+                   "stripCentreL[%d] = %f --- stripCentreG[%d] = %f --- stripCentreT[%d] = %f",
+                   ii, stripCentreL[ii],
+                   ii, stripCentreG[ii],
+                   ii, stripCentreT[ii]));
+  for (Int_t ii=0; ii<3; ii++)
+    AliDebug(1,Form(" difference between the track position and the pad centre in the tracking RF "
+                   "-> posT[%d]-padCentreT[%d] = %f",
+                   ii,ii,
+                   posT[ii]-padCentreT[ii]));
+
+  for (Int_t ii=0; ii<3; ii++) differenceT[ii] = (Float_t)(posT[ii]-padCentreT[ii]);
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetTOFsupermodule(const Int_t index)
+{
+  // Return the TOF supermodule where TOF channel index is located
+
+  if (index<0 || index>=NPadXSector()*NSectors()) return -1;
+  else return index/NpadXStrip()/NStripXSector();
+
+}