]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDgeometry.cxx
Additional protection. The call to RecWithStack has to be removed in case of raw...
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
index a16e99aae7008fa3bf2cc4765a49d04c0608a32f..9e433b360f37abbbc1a22ccffd21f7c3c607c6be 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.1.4.1  2000/05/08 14:45:55  cblume
-Bug fix in RotateBack(). Geometry update
-
-Revision 1.1  2000/02/28 19:00:44  cblume
-Add new TRD classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -29,11 +21,131 @@ Add new TRD classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+
+#include <TError.h>
+
+#include "AliRunLoader.h"
 #include "AliTRDgeometry.h"
-#include "AliTRDrecPoint.h"
+#include "AliTRDpadPlane.h"
+
+#include "AliRun.h"
+#include "AliTRD.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCommonParam.h"
 
 ClassImp(AliTRDgeometry)
 
+//_____________________________________________________________________________
+
+  //
+  // The geometry constants
+  //
+  const Int_t   AliTRDgeometry::fgkNsect   = kNsect;
+  const Int_t   AliTRDgeometry::fgkNplan   = kNplan;
+  const Int_t   AliTRDgeometry::fgkNcham   = kNcham;
+  const Int_t   AliTRDgeometry::fgkNdet    = kNdet;
+
+  //
+  // Dimensions of the detector
+  //
+
+  // Inner and outer radius of the mother volumes 
+  const Float_t AliTRDgeometry::fgkRmin    = 294.0;
+  const Float_t AliTRDgeometry::fgkRmax    = 368.0;
+
+  // Upper and lower length of the mother volumes 
+  const Float_t AliTRDgeometry::fgkZmax1   = 378.35; 
+  const Float_t AliTRDgeometry::fgkZmax2   = 302.0; 
+
+  // Parameter of the BTR mother volumes 
+  const Float_t AliTRDgeometry::fgkSheight =  74.0; 
+  const Float_t AliTRDgeometry::fgkSwidth1 =  99.613;
+  const Float_t AliTRDgeometry::fgkSwidth2 = 125.707;
+  const Float_t AliTRDgeometry::fgkSlenTR1 = 751.0;
+  const Float_t AliTRDgeometry::fgkSlenTR2 = 313.5; 
+  const Float_t AliTRDgeometry::fgkSlenTR3 = 159.5;  
+
+  // The super module side plates
+  const Float_t AliTRDgeometry::fgkSMpltT  =   0.2;
+  const Float_t AliTRDgeometry::fgkSMgapT  =   0.5;  
+
+  // Height of different chamber parts
+  // Radiator
+  const Float_t AliTRDgeometry::fgkCraH    =   4.8; 
+  // Drift region
+  const Float_t AliTRDgeometry::fgkCdrH    =   3.0;
+  // Amplification region
+  const Float_t AliTRDgeometry::fgkCamH    =   0.7;
+  // Readout
+  const Float_t AliTRDgeometry::fgkCroH    =   2.316;
+  // Total height
+  const Float_t AliTRDgeometry::fgkCH      = AliTRDgeometry::fgkCraH
+                                           + AliTRDgeometry::fgkCdrH
+                                           + AliTRDgeometry::fgkCamH
+                                           + AliTRDgeometry::fgkCroH;  
+
+  // Vertical spacing of the chambers
+  const Float_t AliTRDgeometry::fgkVspace  =   1.784;
+
+  // Horizontal spacing of the chambers
+  const Float_t AliTRDgeometry::fgkHspace  =   2.0;
+
+  // Thicknesses of different parts of the chamber frame
+  // Lower aluminum frame
+  const Float_t AliTRDgeometry::fgkCalT    =   0.3;
+  // Lower G10 frame sides
+  const Float_t AliTRDgeometry::fgkCclsT   =   0.3;
+  // Lower G10 frame front
+  const Float_t AliTRDgeometry::fgkCclfT   =   1.0;
+  // Upper G10 frame
+  const Float_t AliTRDgeometry::fgkCcuT    =   0.9;
+  // Upper Al frame
+  const Float_t AliTRDgeometry::fgkCauT    =   1.5;
+
+  // Additional width of the readout chamber frames
+  const Float_t AliTRDgeometry::fgkCroW    =   0.9;
+
+  // Difference of outer chamber width and pad plane width
+  //const Float_t AliTRDgeometry::fgkCpadW   =   1.0;
+  const Float_t AliTRDgeometry::fgkCpadW   =   0.0;
+  const Float_t AliTRDgeometry::fgkRpadW   =   1.0;
+
+  //
+  // Thickness of the the material layers
+  //
+  const Float_t AliTRDgeometry::fgkRaThick = 0.3646;  
+  const Float_t AliTRDgeometry::fgkMyThick = 0.005;
+  const Float_t AliTRDgeometry::fgkDrThick = AliTRDgeometry::fgkCdrH;    
+  const Float_t AliTRDgeometry::fgkAmThick = AliTRDgeometry::fgkCamH;
+  const Float_t AliTRDgeometry::fgkXeThick = AliTRDgeometry::fgkDrThick
+                                           + AliTRDgeometry::fgkAmThick;
+  const Float_t AliTRDgeometry::fgkCuThick = 0.001; 
+  const Float_t AliTRDgeometry::fgkSuThick = 0.06; 
+  const Float_t AliTRDgeometry::fgkFeThick = 0.0044; 
+  const Float_t AliTRDgeometry::fgkCoThick = 0.02;
+  const Float_t AliTRDgeometry::fgkWaThick = 0.02;
+
+  //
+  // Position of the material layers
+  //
+  const Float_t AliTRDgeometry::fgkRaZpos  = -1.50;
+  const Float_t AliTRDgeometry::fgkMyZpos  =  0.895;
+  const Float_t AliTRDgeometry::fgkDrZpos  =  2.4;
+  const Float_t AliTRDgeometry::fgkAmZpos  =  0.0;
+  const Float_t AliTRDgeometry::fgkCuZpos  = -0.9995;
+  const Float_t AliTRDgeometry::fgkSuZpos  =  0.0000;
+  const Float_t AliTRDgeometry::fgkFeZpos  =  0.0322;
+  const Float_t AliTRDgeometry::fgkCoZpos  =  0.97;
+  const Float_t AliTRDgeometry::fgkWaZpos  =  0.99;
+  
+  const Double_t AliTRDgeometry::fgkTime0Base = Rmin() + CraHght() + CdrHght() + CamHght()/2.;
+  const Float_t  AliTRDgeometry::fgkTime0[6]  = { fgkTime0Base + 0 * (Cheight() + Cspace()), 
+                                                  fgkTime0Base + 1 * (Cheight() + Cspace()), 
+                                                  fgkTime0Base + 2 * (Cheight() + Cspace()), 
+                                                  fgkTime0Base + 3 * (Cheight() + Cspace()), 
+                                                  fgkTime0Base + 4 * (Cheight() + Cspace()), 
+                                                  fgkTime0Base + 5 * (Cheight() + Cspace()) };
+
 //_____________________________________________________________________________
 AliTRDgeometry::AliTRDgeometry():AliGeometry()
 {
@@ -42,13 +154,14 @@ AliTRDgeometry::AliTRDgeometry():AliGeometry()
   //
 
   Init();
-
 }
 
 //_____________________________________________________________________________
 AliTRDgeometry::~AliTRDgeometry()
 {
-
+  //
+  // AliTRDgeometry destructor
+  //
 }
 
 //_____________________________________________________________________________
@@ -57,240 +170,107 @@ void AliTRDgeometry::Init()
   //
   // Initializes the geometry parameter
   //
-
-  Int_t iplan;
-
-  // The width of the chambers
-  fCwidth[0]    =  99.6;
-  fCwidth[1]    = 104.1;
-  fCwidth[2]    = 108.5;
-  fCwidth[3]    = 112.9;
-  fCwidth[4]    = 117.4;
-  fCwidth[5]    = 121.8;
-
-  // The default pad dimensions
-  fRowPadSize  = 4.5;
-  fColPadSize  = 1.0;
-  fTimeBinSize = 0.1;
-
   // The maximum number of pads
   // and the position of pad 0,0,0 
   // 
   // chambers seen from the top:
   //     +----------------------------+
   //     |                            |
-  //     |                            |     ^
-  //     |                            | rphi|
-  //     |                            |     |
-  //     |0                           |     | 
-  //     +----------------------------+     +------>
+  //     |                            |      ^
+  //     |                            |  rphi|
+  //     |                            |      |
+  //     |0                           |      
+  //     +----------------------------+      +------>
   //                                             z 
-  // chambers seen from the side:           ^
-  //     +----------------------------+ time|
-  //     |                            |     |
-  //     |0                           |     |
-  //     +----------------------------+     +------>
+  // chambers seen from the side:            ^
+  //     +----------------------------+ drift|
+  //     |0                           |      |
+  //     |                            |      |
+  //     +----------------------------+      +------>
   //                                             z
   //                                             
+  // IMPORTANT: time bin 0 is now the first one in the drift region 
+  // closest to the readout !!!
+  //
 
-  // The pad column (rphi-direction)  
-  for (iplan = 0; iplan < kNplan; iplan++) {
-    fColMax[iplan] = 1 + TMath::Nint((fCwidth[iplan] - 2. * kCcthick) 
-                                                     / fColPadSize - 0.5);
-    fCol0[iplan]   = -fCwidth[iplan]/2. + kCcthick;
-  }
+  Int_t icham;
+  Int_t iplan;
+  Int_t isect;
 
-  // The time bucket
-  fTimeMax = 1 + TMath::Nint(kDrThick / fTimeBinSize - 0.5);
-  for (iplan = 0; iplan < kNplan; iplan++) {
-    fTime0[iplan]  = kRmin + kCcframe/2. + kDrZpos - 0.5 * kDrThick
-                           + iplan * (kCheight + kCspace);
-  } 
+  // The outer width of the chambers
+  //
+  // Changed with the introduction of 
+  // the new layer 0. The old layer 6
+  // is removed.
+  fCwidth[0] =  90.4;
+  fCwidth[1] =  94.8;
+  fCwidth[2] =  99.3;
+  fCwidth[3] = 103.7;
+  fCwidth[4] = 108.1;
+  fCwidth[5] = 112.6;
+  // Old layer 6
+  // fCwidth[5] = 117.0;
+
+  // The outer lengths of the chambers
+  // Includes the spacings between the chambers!
+  // Changed with the introduction of 
+  // the new layer 0. The old layer 6
+  // is removed.
+  Float_t length[kNplan][kNcham]   = { { 124.0, 124.0, 110.0, 124.0, 124.0 }
+                                    , { 124.0, 124.0, 110.0, 124.0, 124.0 }
+                                     , { 131.0, 131.0, 110.0, 131.0, 131.0 }
+                                     , { 138.0, 138.0, 110.0, 138.0, 138.0 }
+                                     , { 145.0, 145.0, 110.0, 145.0, 145.0 }
+                                    , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
+  // Old layer 6
+  //                                 , { 147.0, 147.0, 110.0, 147.0, 147.0 } };
+
+  for (icham = 0; icham < kNcham; icham++) {
+    for (iplan = 0; iplan < kNplan; iplan++) {
+      fClength[iplan][icham]   = length[iplan][icham];
+      fClengthPH[iplan][icham] = 0.0;
+      fClengthRH[iplan][icham] = 0.0;
+    }
+  }
 
+  // The rotation matrix elements
+  Float_t phi = 0;
+  for (isect = 0; isect < fgkNsect; isect++) {
+    phi = -2.0 * TMath::Pi() /  (Float_t) fgkNsect * ((Float_t) isect + 0.5);
+    fRotA11[isect] = TMath::Cos(phi);
+    fRotA12[isect] = TMath::Sin(phi);
+    fRotA21[isect] = TMath::Sin(phi);
+    fRotA22[isect] = TMath::Cos(phi);
+    phi = -1.0 * phi;
+    fRotB11[isect] = TMath::Cos(phi);
+    fRotB12[isect] = TMath::Sin(phi);
+    fRotB21[isect] = TMath::Sin(phi);
+    fRotB22[isect] = TMath::Cos(phi);
+  }
 }
 
 //_____________________________________________________________________________
-void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
+void AliTRDgeometry::CreateGeometry(Int_t)
 {
   //
-  // Create the TRD geometry
-  //
-  // Author: Christoph Blume (C.Blume@gsi.de) 20/07/99
-  //
-  // The volumes:
-  //    TRD1-3     (Air)   --- The TRD mother volumes for one sector. 
-  //                           To be placed into the spaceframe.
-  //
-  //    UAFI(/M/O) (Al)    --- The aluminum frame of the inner(/middle/outer) chambers (readout)
-  //    UCFI(/M/O) (C)     --- The carbon frame of the inner(/middle/outer) chambers 
-  //                           (driftchamber + radiator)
-  //    UAII(/M/O) (Air)   --- The inner part of the readout of the inner(/middle/outer) chambers
-  //    UFII(/M/O) (Air)   --- The inner part of the chamner and radiator of the 
-  //                           inner(/middle/outer) chambers
-  //
-  // The material layers in one chamber:
-  //    UL01       (G10)   --- The gas seal of the radiator
-  //    UL02       (CO2)   --- The gas in the radiator
-  //    UL03       (PE)    --- The foil stack
-  //    UL04       (Mylar) --- Entrance window to the driftvolume and HV-cathode
-  //    UL05       (Xe)    --- The driftvolume
-  //    UL06       (Xe)    --- The amplification region
-  //    
-  //    UL07       (Cu)    --- The pad plane
-  //    UL08       (G10)   --- The Nomex honeycomb support structure
-  //    UL09       (Cu)    --- FEE and signal lines
-  //    UL10       (PE)    --- The cooling devices
-  //    UL11       (Water) --- The cooling water
-
-  const Int_t npar_cha = 3;
-
-  Float_t par_dum[3];
-  Float_t par_cha[npar_cha];
-
-  Float_t xpos, ypos, zpos;
-
-  // The aluminum frames - readout + electronics (Al)
-  // The inner chambers
-  gMC->Gsvolu("UAFI","BOX ",idtmed[1301-1],par_dum,0);
-  // The middle chambers
-  gMC->Gsvolu("UAFM","BOX ",idtmed[1301-1],par_dum,0);
-  // The outer chambers
-  gMC->Gsvolu("UAFO","BOX ",idtmed[1301-1],par_dum,0);
-
-  // The inner part of the aluminum frames (Air)
-  // The inner chambers
-  gMC->Gsvolu("UAII","BOX ",idtmed[1302-1],par_dum,0);
-  // The middle chambers
-  gMC->Gsvolu("UAIM","BOX ",idtmed[1302-1],par_dum,0);
-  // The outer chambers
-  gMC->Gsvolu("UAIO","BOX ",idtmed[1302-1],par_dum,0);
-
-  // The carbon frames - radiator + driftchamber (C)
-  // The inner chambers
-  gMC->Gsvolu("UCFI","BOX ",idtmed[1307-1],par_dum,0);
-  // The middle chambers
-  gMC->Gsvolu("UCFM","BOX ",idtmed[1307-1],par_dum,0);
-  // The outer chambers
-  gMC->Gsvolu("UCFO","BOX ",idtmed[1307-1],par_dum,0);
-
-  // The inner part of the carbon frames (Air)
-  // The inner chambers
-  gMC->Gsvolu("UCII","BOX ",idtmed[1302-1],par_dum,0);
-  // The middle chambers
-  gMC->Gsvolu("UCIM","BOX ",idtmed[1302-1],par_dum,0);
-  // The outer chambers
-  gMC->Gsvolu("UCIO","BOX ",idtmed[1302-1],par_dum,0);
-
-  // The material layers inside the chambers
-  par_cha[0] = -1.;
-  par_cha[1] = -1.;
-  // G10 layer (radiator seal)
-  par_cha[2] = kSeThick/2;
-  gMC->Gsvolu("UL01","BOX ",idtmed[1313-1],par_cha,npar_cha);
-  // CO2 layer (radiator)
-  par_cha[2] = kRaThick/2;
-  gMC->Gsvolu("UL02","BOX ",idtmed[1312-1],par_cha,npar_cha);
-  // PE layer (radiator)
-  par_cha[2] = kPeThick/2;
-  gMC->Gsvolu("UL03","BOX ",idtmed[1303-1],par_cha,npar_cha);
-  // Mylar layer (entrance window + HV cathode) 
-  par_cha[2] = kMyThick/2;
-  gMC->Gsvolu("UL04","BOX ",idtmed[1308-1],par_cha,npar_cha);
-  // Xe/Isobutane layer (drift volume, sensitive) 
-  par_cha[2] = kDrThick/2.;
-  gMC->Gsvolu("UL05","BOX ",idtmed[1309-1],par_cha,npar_cha);
-  // Xe/Isobutane layer (amplification volume, not sensitive)
-  par_cha[2] = kAmThick/2.;
-  gMC->Gsvolu("UL06","BOX ",idtmed[1309-1],par_cha,npar_cha);
-  
-  // Cu layer (pad plane)
-  par_cha[2] = kCuThick/2;
-  gMC->Gsvolu("UL07","BOX ",idtmed[1305-1],par_cha,npar_cha);
-  // G10 layer (support structure)
-  par_cha[2] = kSuThick/2;
-  gMC->Gsvolu("UL08","BOX ",idtmed[1313-1],par_cha,npar_cha);
-  // Cu layer (FEE + signal lines)
-  par_cha[2] = kFeThick/2;
-  gMC->Gsvolu("UL09","BOX ",idtmed[1305-1],par_cha,npar_cha);
-  // PE layer (cooling devices)
-  par_cha[2] = kCoThick/2;
-  gMC->Gsvolu("UL10","BOX ",idtmed[1303-1],par_cha,npar_cha);
-  // Water layer (cooling)
-  par_cha[2] = kWaThick/2;
-  gMC->Gsvolu("UL11","BOX ",idtmed[1314-1],par_cha,npar_cha);
-
-  // Position the layers in the chambers
-  xpos = 0;
-  ypos = 0;
-
-  // G10 layer (radiator seal)
-  zpos = kSeZpos;
-  gMC->Gspos("UL01",1,"UCII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL01",2,"UCIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL01",3,"UCIO",xpos,ypos,zpos,0,"ONLY");
-  // CO2 layer (radiator)
-  zpos = kRaZpos;
-  gMC->Gspos("UL02",1,"UCII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL02",2,"UCIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL02",3,"UCIO",xpos,ypos,zpos,0,"ONLY");
-  // PE layer (radiator)
-  zpos = 0;
-  gMC->Gspos("UL03",1,"UL02",xpos,ypos,zpos,0,"ONLY");
-  // Mylar layer (entrance window + HV cathode)   
-  zpos = kMyZpos;
-  gMC->Gspos("UL04",1,"UCII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL04",2,"UCIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL04",3,"UCIO",xpos,ypos,zpos,0,"ONLY");
-  // Xe/Isobutane layer (drift volume) 
-  zpos = kDrZpos;
-  gMC->Gspos("UL05",1,"UCII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL05",2,"UCIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL05",3,"UCIO",xpos,ypos,zpos,0,"ONLY");
-  // Xe/Isobutane layer (amplification volume)
-  zpos = kAmZpos;
-  gMC->Gspos("UL06",1,"UCII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL06",2,"UCIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL06",3,"UCIO",xpos,ypos,zpos,0,"ONLY");
-
-  // Cu layer (pad plane)
-  zpos = kCuZpos;
-  gMC->Gspos("UL07",1,"UAII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL07",2,"UAIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL07",3,"UAIO",xpos,ypos,zpos,0,"ONLY");
-  // G10 layer (support structure)
-  zpos = kSuZpos;
-  gMC->Gspos("UL08",1,"UAII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL08",2,"UAIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL08",3,"UAIO",xpos,ypos,zpos,0,"ONLY");
-  // Cu layer (FEE + signal lines)
-  zpos = kFeZpos; 
-  gMC->Gspos("UL09",1,"UAII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL09",2,"UAIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL09",3,"UAIO",xpos,ypos,zpos,0,"ONLY");
-  // PE layer (cooling devices)
-  zpos = kCoZpos;
-  gMC->Gspos("UL10",1,"UAII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL10",2,"UAIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL10",3,"UAIO",xpos,ypos,zpos,0,"ONLY");
-  // Water layer (cooling)
-  zpos = kWaZpos;
-  gMC->Gspos("UL11",1,"UAII",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL11",1,"UAIM",xpos,ypos,zpos,0,"ONLY");
-  gMC->Gspos("UL11",1,"UAIO",xpos,ypos,zpos,0,"ONLY");
+  // Create TRD geometry
+  //
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDgeometry::Local2Global(Int_t idet, Float_t *local, Float_t *global)
+Bool_t AliTRDgeometry::Local2Global(Int_t idet, Double_t *local
+                                   , Double_t *global) const
 {
   //
   // Converts local pad-coordinates (row,col,time) into 
   // global ALICE reference frame coordinates (x,y,z)
   //
 
-  Int_t        icham     = GetChamber(idet);    // Chamber info (0-4)
-  Int_t        isect     = GetSector(idet);     // Sector info  (0-17)
-  Int_t        iplan     = GetPlane(idet);      // Plane info   (0-5)
+  Int_t icham = GetChamber(idet);    // Chamber info (0-4)
+  Int_t isect = GetSector(idet);     // Sector info  (0-17)
+  Int_t iplan = GetPlane(idet);      // Plane info   (0-5)
 
   return Local2Global(iplan,icham,isect,local,global);
 
@@ -298,29 +278,36 @@ Bool_t AliTRDgeometry::Local2Global(Int_t idet, Float_t *local, Float_t *global)
  
 //_____________________________________________________________________________
 Bool_t AliTRDgeometry::Local2Global(Int_t iplan, Int_t icham, Int_t isect
-                                  , Float_t *local, Float_t *global)
+                                  , Double_t *local, Double_t *global) const
 {
   //
   // Converts local pad-coordinates (row,col,time) into 
   // global ALICE reference frame coordinates (x,y,z)
   //
 
-  Int_t        idet      = GetDetector(iplan,icham,isect); // Detector number
+  AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
+  if (!commonParam)
+    return kFALSE;
 
-  Float_t      padRow    = local[0];                       // Pad Row position
-  Float_t      padCol    = local[1];                       // Pad Column position
-  Float_t      timeSlice = local[2];                       // Time "position"
+  AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
+  if (!calibration)
+    return kFALSE;  
+  
+  AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
 
-  Float_t      row0      = GetRow0(iplan,icham,isect);
-  Float_t      col0      = GetCol0(iplan);
-  Float_t      time0     = GetTime0(iplan);
+  // calculate (x,y,z) position in rotated chamber
+  Int_t    row       = ((Int_t) local[0]);
+  Int_t    col       = ((Int_t) local[1]);
+  Float_t  timeSlice = local[2] + 0.5;
+  Float_t  time0     = GetTime0(iplan);
 
-  Float_t      rot[3];
+  Int_t idet = GetDetector(iplan, icham, isect);
 
-  // calculate (x,y,z) position in rotated chamber
-  rot[0] = time0 + timeSlice * fTimeBinSize;
-  rot[1] = col0  + padCol    * fColPadSize;
-  rot[2] = row0  + padRow    * fRowPadSize;
+  Double_t  rot[3];
+  rot[0] = time0 - (timeSlice - calibration->GetT0(idet, col, row))
+      * calibration->GetVdrift(idet, col, row)/calibration->GetSamplingFrequency();
+  rot[1] = padPlane->GetColPos(col) - 0.5 * padPlane->GetColSize(col);
+  rot[2] = padPlane->GetRowPos(row) - 0.5 * padPlane->GetRowSize(row);
 
   // Rotate back to original position
   return RotateBack(idet,rot,global);
@@ -328,7 +315,81 @@ Bool_t AliTRDgeometry::Local2Global(Int_t iplan, Int_t icham, Int_t isect
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDgeometry::Rotate(Int_t d, Float_t *pos, Float_t *rot)
+Bool_t AliTRDgeometry::Global2Local(Int_t mode, Double_t *local, Double_t *global
+                                   , Int_t* index) const
+{
+  //
+  // Converts local pad-coordinates (row,col,time) into 
+  // global ALICE reference frame coordinates (x,y,z)
+  //
+  // index[0] = plane number
+  // index[1] = chamber number
+  // index[2] = sector number
+  //
+  // mode=0  - local coordinate in y, z,             x - rotated global   
+  // mode=2  - local coordinate in pad, and pad row, x - rotated global
+  //
+
+  //Int_t    idet    = GetDetector(iplan,icham,isect); // Detector number
+  Int_t    idet      = GetDetector(index[0],index[1],index[2]); // Detector number
+  Rotate(idet,global,local);
+  if (mode==0) return kTRUE;
+  //
+  //  Float_t  row0      = par->GetRow0(iplan,icham,isect);
+  //Float_t  col0      = par->GetCol0(iplan);
+  //Float_t  time0     = GetTime0(iplan);
+  //
+  // mode 1 to be implemented later
+  // calculate (x,y,z) position in time bin pad row pad
+  //
+  //rot[0] = time0 - (timeSlice - par->GetTimeBefore()) 
+  //       * par->GetDriftVelocity()/par->GetSamplingFrequency();
+  //rot[1] = col0  + padCol                    
+  //       * par->GetColPadSize(iplan);
+  //rot[2] = row0  + padRow                    
+  //       * par->GetRowPadSize(iplan,icham,isect);
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDgeometry::Global2Detector(Double_t global[3], Int_t index[3])
+{
+  //  
+  // input    = global position
+  // output   = index
+  // index[0] = plane number
+  // index[1] = chamber number
+  // index[2] = sector number
+  //
+
+  Float_t fi;
+  //
+  fi = TMath::ATan2(global[1],global[0]);
+  if (fi<0) fi += 2*TMath::Pi();
+  index[2] = Int_t(TMath::Nint((fi - GetAlpha()/2.)/GetAlpha()));
+  //
+  //
+  Float_t locx = global[0] * fRotA11[index[2]] + global[1] * fRotA12[index[2]];  
+  index[0] = 0;
+  Float_t max = locx - GetTime0(0);
+  for (Int_t iplane=1; iplane<fgkNplan;iplane++){
+    Float_t dist = TMath::Abs(locx - GetTime0(iplane));
+    if (dist < max){
+      index[0] = iplane;
+      max = dist;
+    }
+  }
+  Float_t theta = TMath::ATan2(global[2],locx);
+  index[1] = TMath::Nint(float(fgkNcham)*theta/(0.25*TMath::Pi()));
+  return kTRUE;
+
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliTRDgeometry::Rotate(Int_t d, Double_t *pos, Double_t *rot) const
 {
   //
   // Rotates all chambers in the position of sector 0 and transforms
@@ -336,12 +397,10 @@ Bool_t AliTRDgeometry::Rotate(Int_t d, Float_t *pos, Float_t *rot)
   // corresponding local frame <rot>.
   //
 
-  Int_t   sector = GetSector(d);
+  Int_t sector = GetSector(d);
 
-  Float_t phi    = -2.0 * kPI /  (Float_t) kNsect * ((Float_t) sector + 0.5);
-
-  rot[0] =  pos[0] * TMath::Cos(phi) + pos[1] * TMath::Sin(phi);
-  rot[1] = -pos[0] * TMath::Sin(phi) + pos[1] * TMath::Cos(phi);
+  rot[0] =  pos[0] * fRotA11[sector] + pos[1] * fRotA12[sector];
+  rot[1] = -pos[0] * fRotA21[sector] + pos[1] * fRotA22[sector];
   rot[2] =  pos[2];
 
   return kTRUE;
@@ -349,7 +408,7 @@ Bool_t AliTRDgeometry::Rotate(Int_t d, Float_t *pos, Float_t *rot)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDgeometry::RotateBack(Int_t d, Float_t *rot, Float_t *pos)
+Bool_t AliTRDgeometry::RotateBack(Int_t d, Double_t *rot, Double_t *pos) const
 {
   //
   // Rotates a chambers from the position of sector 0 into its
@@ -357,12 +416,10 @@ Bool_t AliTRDgeometry::RotateBack(Int_t d, Float_t *rot, Float_t *pos)
   // coordinates <rot> into the coordinates of the ALICE restframe <pos>.
   //
 
-  Int_t   sector = GetSector(d);
-
-  Float_t phi    =  2.0 * kPI /  (Float_t) kNsect * ((Float_t) sector + 0.5);
+  Int_t sector = GetSector(d);
 
-  pos[0] =  rot[0] * TMath::Cos(phi) + rot[1] * TMath::Sin(phi);
-  pos[1] = -rot[0] * TMath::Sin(phi) + rot[1] * TMath::Cos(phi);
+  pos[0] =  rot[0] * fRotB11[sector] + rot[1] * fRotB12[sector];
+  pos[1] = -rot[0] * fRotB21[sector] + rot[1] * fRotB22[sector];
   pos[2] =  rot[2];
 
   return kTRUE;
@@ -370,84 +427,87 @@ Bool_t AliTRDgeometry::RotateBack(Int_t d, Float_t *rot, Float_t *pos)
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
+Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c)
 {
   //
-  // Convert plane / chamber / sector into detector number
+  // Convert plane / chamber into detector number for one single sector
   //
 
-  return (p + c * kNplan + s * kNplan * kNcham);
+  return (p + c * fgkNplan);
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetPlane(Int_t d)
+Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
 {
   //
-  // Reconstruct the plane number from the detector number
+  // Convert plane / chamber / sector into detector number
   //
 
-  return ((Int_t) (d % kNplan));
+  return (p + c * fgkNplan + s * fgkNplan * fgkNcham);
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetChamber(Int_t d)
+Int_t AliTRDgeometry::GetPlane(Int_t d) const
 {
   //
-  // Reconstruct the chamber number from the detector number
+  // Reconstruct the plane number from the detector number
   //
 
-  return ((Int_t) (d % (kNplan * kNcham)) / kNplan);
+  return ((Int_t) (d % fgkNplan));
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetSector(Int_t d)
+Int_t AliTRDgeometry::GetChamber(Int_t d) const
 {
   //
-  // Reconstruct the sector number from the detector number
+  // Reconstruct the chamber number from the detector number
   //
 
-  return ((Int_t) (d / (kNplan * kNcham)));
+  return ((Int_t) (d % (fgkNplan * fgkNcham)) / fgkNplan);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDgeometry::GetGlobal(const AliRecPoint *p, TVector3 &pos, TMatrix &mat)
+Int_t AliTRDgeometry::GetSector(Int_t d) const
 {
-  // 
-  // Returns the global coordinate and error matrix of a AliTRDrecPoint
+  //
+  // Reconstruct the sector number from the detector number
   //
 
-  GetGlobal(p,pos);
+  return ((Int_t) (d / (fgkNplan * fgkNcham)));
 
 }
 
 //_____________________________________________________________________________
-void AliTRDgeometry::GetGlobal(const AliRecPoint *p, TVector3 &pos)
+AliTRDgeometry* AliTRDgeometry::GetGeometry(AliRunLoader* runLoader)
 {
-  // 
-  // Returns the global coordinate and error matrix of a AliTRDrecPoint
+  //
+  // load the geometry from the galice file
   //
 
-  Int_t detector = ((AliTRDrecPoint *) p)->GetDetector();
+  if (!runLoader) runLoader = AliRunLoader::GetRunLoader();
+  if (!runLoader) {
+    ::Error("AliTRDgeometry::GetGeometry", "No run loader");
+    return NULL;
+  }
 
-  Float_t global[3];
-  Float_t local[3];
-  local[0] = ((AliTRDrecPoint *) p)->GetLocalRow();
-  local[1] = ((AliTRDrecPoint *) p)->GetLocalCol();
-  local[2] = ((AliTRDrecPoint *) p)->GetLocalTime();
+  TDirectory* saveDir = gDirectory;
+  runLoader->CdGAFile();
 
-  if (Local2Global(detector,local,global)) {
-    pos.SetX(global[0]);
-    pos.SetY(global[1]);
-    pos.SetZ(global[2]);
-  }
-  else {
-    pos.SetX(0.0);
-    pos.SetY(0.0);
-    pos.SetZ(0.0);
+  // Try from the galice.root file
+  AliTRDgeometry* geom = (AliTRDgeometry*) gDirectory->Get("TRDgeometry");
+
+  if (!geom) {
+    // It is not in the file, try to get it from gAlice, 
+    // which corresponds to the run loader 
+    AliTRD * trd = (AliTRD*)runLoader->GetAliRun()->GetDetector("TRD");
+    geom = trd->GetGeometry();
   }
+  if (!geom) ::Error("AliTRDgeometry::GetGeometry", "Geometry not found");
 
+  saveDir->cd();
+  return geom;
 }