]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDgeometry.cxx
Change validity range
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
index 22e64a99baa6b44649997c51e82888944ea361c4..4bc3100c09b73414f62d00a4463c9e690dfd9cee 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "AliTRD.h"
 #include "AliTRDcalibDB.h"
-#include "AliTRDCommonParam.h"
 #include "AliTRDgeometry.h"
 #include "AliTRDpadPlane.h"
 
@@ -45,108 +44,118 @@ 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;
+  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
   //
 
   // Parameter of the BTRD mother volumes 
-  const Float_t AliTRDgeometry::fgkSheight =  77.9; 
-  const Float_t AliTRDgeometry::fgkSwidth1 =  94.881; 
-  const Float_t AliTRDgeometry::fgkSwidth2 = 122.353;
-  const Float_t AliTRDgeometry::fgkSlength = 751.0;
+  const Float_t  AliTRDgeometry::fgkSheight   =  77.9; 
+  const Float_t  AliTRDgeometry::fgkSwidth1   =  94.881; 
+  const Float_t  AliTRDgeometry::fgkSwidth2   = 122.353;
+  const Float_t  AliTRDgeometry::fgkSlength   = 751.0;
 
   // The super module side plates
-  const Float_t AliTRDgeometry::fgkSMpltT  =   0.2;
+  const Float_t  AliTRDgeometry::fgkSMpltT    =   0.2;
 
   // Height of different chamber parts
   // Radiator
-  const Float_t AliTRDgeometry::fgkCraH    =   4.8; 
+  const Float_t  AliTRDgeometry::fgkCraH      =   4.8; 
   // Drift region
-  const Float_t AliTRDgeometry::fgkCdrH    =   3.0;
+  const Float_t  AliTRDgeometry::fgkCdrH      =   3.0;
   // Amplification region
-  const Float_t AliTRDgeometry::fgkCamH    =   0.7;
+  const Float_t  AliTRDgeometry::fgkCamH      =   0.7;
   // Readout
-  const Float_t AliTRDgeometry::fgkCroH    =   2.316;
+  const Float_t  AliTRDgeometry::fgkCroH      =   2.316;
   // Total height
-  const Float_t AliTRDgeometry::fgkCH      = AliTRDgeometry::fgkCraH
-                                           + AliTRDgeometry::fgkCdrH
-                                           + AliTRDgeometry::fgkCamH
-                                           + AliTRDgeometry::fgkCroH;  
+  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;
+  const Float_t  AliTRDgeometry::fgkVspace    =   1.784;
   // Horizontal spacing of the chambers
-  const Float_t AliTRDgeometry::fgkHspace  =   2.0;
+  const Float_t  AliTRDgeometry::fgkHspace    =   2.0;
   // Radial distance of the first ROC to the outer plates of the SM
-  const Float_t AliTRDgeometry::fgkVrocsm  =   1.2;
+  const Float_t  AliTRDgeometry::fgkVrocsm    =   1.2;
 
   // Thicknesses of different parts of the chamber frame
   // Lower aluminum frame
-  const Float_t AliTRDgeometry::fgkCalT    =   0.4;
+  const Float_t  AliTRDgeometry::fgkCalT      =   0.4;
   // Lower Wacosit frame sides
-  const Float_t AliTRDgeometry::fgkCclsT   =   0.21;
+  const Float_t  AliTRDgeometry::fgkCclsT     =   0.21;
   // Lower Wacosit frame front
-  const Float_t AliTRDgeometry::fgkCclfT   =   1.0;
+  const Float_t  AliTRDgeometry::fgkCclfT     =   1.0;
   // Thickness of glue around radiator
-  const Float_t AliTRDgeometry::fgkCglT    =   0.25;
+  const Float_t  AliTRDgeometry::fgkCglT      =   0.25;
   // Upper Wacosit frame
-  const Float_t AliTRDgeometry::fgkCcuT    =   0.9;
+  const Float_t  AliTRDgeometry::fgkCcuT      =   0.9;
   // Al frame of back panel
-  const Float_t AliTRDgeometry::fgkCauT    =   1.5;
+  const Float_t  AliTRDgeometry::fgkCauT      =   1.5;
   // Additional Al of the lower chamber frame
-  const Float_t AliTRDgeometry::fgkCalW    =   1.11;
+  const Float_t  AliTRDgeometry::fgkCalW      =   1.11;
 
   // Additional width of the readout chamber frames
-  const Float_t AliTRDgeometry::fgkCroW    =   0.9;
+  const Float_t  AliTRDgeometry::fgkCroW      =   0.9;
 
   // Difference of outer chamber width and pad plane width
-  const Float_t AliTRDgeometry::fgkCpadW   =   0.0;
-  const Float_t AliTRDgeometry::fgkRpadW   =   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::fgkMyThick = 0.005;
-  const Float_t AliTRDgeometry::fgkRaThick = 0.3233;  
-  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::fgkWrThick = 0.0002;
-  const Float_t AliTRDgeometry::fgkCuThick = 0.0072; 
-  const Float_t AliTRDgeometry::fgkGlThick = 0.05;
-  const Float_t AliTRDgeometry::fgkSuThick = 0.0919; 
-  const Float_t AliTRDgeometry::fgkRcThick = 0.0058;
-  const Float_t AliTRDgeometry::fgkRpThick = 0.0632;
-  const Float_t AliTRDgeometry::fgkRoThick = 0.0028;
+  const Float_t  AliTRDgeometry::fgkMyThick   = 0.005;
+  const Float_t  AliTRDgeometry::fgkRaThick   = 0.3233;  
+  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::fgkWrThick   = 0.0002;
+  const Float_t  AliTRDgeometry::fgkCuThick   = 0.0072; 
+  const Float_t  AliTRDgeometry::fgkGlThick   = 0.05;
+  const Float_t  AliTRDgeometry::fgkSuThick   = 0.0919; 
+  const Float_t  AliTRDgeometry::fgkRcThick   = 0.0058;
+  const Float_t  AliTRDgeometry::fgkRpThick   = 0.0632;
+  const Float_t  AliTRDgeometry::fgkRoThick   = 0.0028;
 
   //
   // Position of the material layers
   //
-  //const Float_t AliTRDgeometry::fgkRaZpos  = -1.50;
-  const Float_t AliTRDgeometry::fgkRaZpos  =  0.0;
-  const Float_t AliTRDgeometry::fgkDrZpos  =  2.4;
-  const Float_t AliTRDgeometry::fgkAmZpos  =  0.0;
-  const Float_t AliTRDgeometry::fgkWrZpos  =  0.0;
-  const Float_t AliTRDgeometry::fgkCuZpos  = -0.9995;
-  const Float_t AliTRDgeometry::fgkGlZpos  = -0.5; 
-  const Float_t AliTRDgeometry::fgkSuZpos  =  0.0;
-  const Float_t AliTRDgeometry::fgkRcZpos  =  1.04;
-  const Float_t AliTRDgeometry::fgkRpZpos  =  1.0;
-  const Float_t AliTRDgeometry::fgkRoZpos  =  1.05;
+  const Float_t  AliTRDgeometry::fgkRaZpos    =  0.0;
+  const Float_t  AliTRDgeometry::fgkDrZpos    =  2.4;
+  const Float_t  AliTRDgeometry::fgkAmZpos    =  0.0;
+  const Float_t  AliTRDgeometry::fgkWrZpos    =  0.0;
+  const Float_t  AliTRDgeometry::fgkCuZpos    = -0.9995;
+  const Float_t  AliTRDgeometry::fgkGlZpos    = -0.5; 
+  const Float_t  AliTRDgeometry::fgkSuZpos    =  0.0;
+  const Float_t  AliTRDgeometry::fgkRcZpos    =  1.04;
+  const Float_t  AliTRDgeometry::fgkRpZpos    =  1.0;
+  const Float_t  AliTRDgeometry::fgkRoZpos    =  1.05;
+
+  const Int_t    AliTRDgeometry::fgkMCMmax    = 16;   
+  const Int_t    AliTRDgeometry::fgkMCMrow    = 4;   
+  const Int_t    AliTRDgeometry::fgkROBmaxC0  = 6; 
+  const Int_t    AliTRDgeometry::fgkROBmaxC1  = 8; 
+  const Int_t    AliTRDgeometry::fgkADCmax    = 21;   
+  const Int_t    AliTRDgeometry::fgkTBmax     = 60;   
+  const Int_t    AliTRDgeometry::fgkPadmax    = 18;   
+  const Int_t    AliTRDgeometry::fgkColmax    = 144;
+  const Int_t    AliTRDgeometry::fgkRowmaxC0  = 12;
+  const Int_t    AliTRDgeometry::fgkRowmaxC1  = 16;
 
   const Double_t AliTRDgeometry::fgkTime0Base = 300.65;
-  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()) };
+  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()
@@ -154,7 +163,7 @@ AliTRDgeometry::AliTRDgeometry()
   ,fMatrixArray(0)
   ,fMatrixCorrectionArray(0)
   ,fMatrixGeo(0)
-
+  ,fPadPlaneArray(0)
 {
   //
   // AliTRDgeometry default constructor
@@ -167,9 +176,10 @@ AliTRDgeometry::AliTRDgeometry()
 //_____________________________________________________________________________
 AliTRDgeometry::AliTRDgeometry(const AliTRDgeometry &g)
   :AliGeometry(g)
-  ,fMatrixArray(g.fMatrixArray)
-  ,fMatrixCorrectionArray(g.fMatrixCorrectionArray)
-  ,fMatrixGeo(g.fMatrixGeo)
+  ,fMatrixArray(0)
+  ,fMatrixCorrectionArray(0)
+  ,fMatrixGeo(0)
+  ,fPadPlaneArray(0)
 {
   //
   // AliTRDgeometry copy constructor
@@ -187,15 +197,29 @@ AliTRDgeometry::~AliTRDgeometry()
   //
 
   if (fMatrixArray) {
+    fMatrixArray->Delete();
     delete fMatrixArray;
-    fMatrixArray           = 0;
+    fMatrixArray = 0;
   }
 
   if (fMatrixCorrectionArray) {
+    fMatrixCorrectionArray->Delete();
     delete fMatrixCorrectionArray;
     fMatrixCorrectionArray = 0;
   }
 
+  if (fMatrixGeo) {
+    fMatrixGeo->Delete();
+    delete fMatrixGeo;
+    fMatrixGeo = 0;
+  }
+
+  if (fPadPlaneArray) {
+    fPadPlaneArray->Delete();
+    delete fPadPlaneArray;
+    fPadPlaneArray = 0;
+  }
+
 }
 
 //_____________________________________________________________________________
@@ -250,24 +274,260 @@ void AliTRDgeometry::Init()
   // The rotation matrix elements
   Float_t phi = 0.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;
+    phi = 2.0 * TMath::Pi() /  (Float_t) fgkNsect * ((Float_t) isect + 0.5);
     fRotB11[isect] = TMath::Cos(phi);
     fRotB12[isect] = TMath::Sin(phi);
     fRotB21[isect] = TMath::Sin(phi);
     fRotB22[isect] = TMath::Cos(phi);
   }
 
+  // Initialize the SM status
   for (isect = 0; isect < fgkNsect; isect++) {
     SetSMstatus(isect,1);
   }
  
 }
 
+//_____________________________________________________________________________
+void AliTRDgeometry::CreatePadPlaneArray()
+{
+  //
+  // Creates the array of AliTRDpadPlane objects
+  //
+
+  if (fPadPlaneArray) {
+    fPadPlaneArray->Delete();
+    delete fPadPlaneArray;
+  }
+
+  fPadPlaneArray = new TObjArray(fgkNplan * fgkNcham);  
+  for (Int_t iplan = 0; iplan < fgkNplan; iplan++) {
+    for (Int_t icham = 0; icham < fgkNcham; icham++) {
+      Int_t ipp = GetDetectorSec(iplan,icham);
+      fPadPlaneArray->AddAt(CreatePadPlane(iplan,icham),ipp);
+    }
+  }
+
+}
+
+//_____________________________________________________________________________
+AliTRDpadPlane *AliTRDgeometry::CreatePadPlane(Int_t iplan, Int_t icham)
+{
+  //
+  // Creates an AliTRDpadPlane object
+  //
+
+  AliTRDpadPlane *padPlane = new AliTRDpadPlane();
+
+  padPlane->SetPlane(iplan);
+  padPlane->SetChamber(icham);
+
+  padPlane->SetRowSpacing(0.0);
+  padPlane->SetColSpacing(0.0);
+
+  padPlane->SetLengthRim(1.0);
+  padPlane->SetWidthRim(0.5);
+
+  padPlane->SetNcols(144);
+
+  //
+  // The pad plane parameter
+  //
+  switch (iplan) {
+  case 0:
+    if (icham == 2) {
+      // L0C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(92.2);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.515);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.635);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    else {
+      // L0C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(122.0);
+      padPlane->SetWidth(92.2);
+      padPlane->SetLengthOPad(7.5);
+      padPlane->SetWidthOPad(0.515);
+      padPlane->SetLengthIPad(7.5);
+      padPlane->SetWidthIPad(0.635);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    break;
+  case 1:
+    if (icham == 2) {
+      // L1C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(96.6);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.585);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.665);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    else {
+      // L1C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(122.0);
+      padPlane->SetWidth(96.6);
+      padPlane->SetLengthOPad(7.5);
+      padPlane->SetWidthOPad(0.585);
+      padPlane->SetLengthIPad(7.5);
+      padPlane->SetWidthIPad(0.665);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    break;
+  case 2:
+    if (icham == 2) {
+      // L2C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(101.1);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.705);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.695);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    else {
+      // L2C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(129.0);
+      padPlane->SetWidth(101.1);
+      padPlane->SetLengthOPad(7.5);
+      padPlane->SetWidthOPad(0.705);
+      padPlane->SetLengthIPad(8.0);
+      padPlane->SetWidthIPad(0.695);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    break;
+  case 3:
+    if (icham == 2) {
+      // L3C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(105.5);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.775);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.725);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    else {
+      // L3C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(136.0);
+      padPlane->SetWidth(105.5);
+      padPlane->SetLengthOPad(7.5);
+      padPlane->SetWidthOPad(0.775);
+      padPlane->SetLengthIPad(8.5);
+      padPlane->SetWidthIPad(0.725);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    break;
+  case 4:
+    if (icham == 2) {
+      // L4C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(109.9);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.845);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.755);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    else {
+      // L4C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(143.0);
+      padPlane->SetWidth(109.9);
+      padPlane->SetLengthOPad(7.5);
+      padPlane->SetWidthOPad(0.845);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.755);
+      padPlane->SetTiltingAngle(-2.0);
+    }
+    break;
+  case 5:
+    if (icham == 2) {
+      // L5C0 type
+      padPlane->SetNrows(12);
+      padPlane->SetLength(108.0);
+      padPlane->SetWidth(114.4);
+      padPlane->SetLengthOPad(8.0);
+      padPlane->SetWidthOPad(0.965);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.785);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    else {
+      // L5C1 type
+      padPlane->SetNrows(16);
+      padPlane->SetLength(145.0);
+      padPlane->SetWidth(114.4);
+      padPlane->SetLengthOPad(8.5);
+      padPlane->SetWidthOPad(0.965);
+      padPlane->SetLengthIPad(9.0);
+      padPlane->SetWidthIPad(0.785);
+      padPlane->SetTiltingAngle(2.0);
+    }
+    break;
+  };
+
+  //
+  // The positions of the borders of the pads
+  //
+  // Row direction
+  //
+  Double_t row = fClength[iplan][icham] / 2.0
+               - fgkRpadW
+               - padPlane->GetLengthRim();
+  for (Int_t ir = 0; ir < padPlane->GetNrows(); ir++) {
+    padPlane->SetPadRow(ir,row);
+    row -= padPlane->GetRowSpacing();
+    if (ir == 0) {
+      row -= padPlane->GetLengthOPad();
+    }
+    else {
+      row -= padPlane->GetLengthIPad();
+    }
+  }
+  //
+  // Column direction
+  //
+  Double_t col = fCwidth[iplan] / 2.0
+               + fgkCroW
+               - padPlane->GetWidthRim();
+  for (Int_t ic = 0; ic < padPlane->GetNcols(); ic++) {
+    padPlane->SetPadCol(ic,col);
+    col -= padPlane->GetColSpacing();
+    if (ic == 0) {
+      col -= padPlane->GetWidthOPad();
+    }
+    else {
+      col -= padPlane->GetWidthIPad();
+    }
+  }
+  // Calculate the offset to translate from the local ROC system into
+  // the local supermodule system, which is used for clusters
+  Double_t rowTmp = fClength[iplan][0]
+                 + fClength[iplan][1]
+                  + fClength[iplan][2] / 2.0;
+  for (Int_t ic = 0; ic < icham; ic++) {
+    rowTmp -= fClength[iplan][ic];
+  }
+  padPlane->SetPadRowSMOffset(rowTmp - fClength[iplan][icham]/2.0);
+
+  return padPlane;
+
+}
+
 //_____________________________________________________________________________
 void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
 {
@@ -577,12 +837,12 @@ void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
 
       // Position the frames of the chambers in the TRD mother volume
       xpos  = 0.0;
-      ypos  = - fClength[iplan][0] - fClength[iplan][1] - fClength[iplan][2]/2.0;
+      ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
       for (Int_t ic = 0; ic < icham; ic++) {
-        ypos += fClength[iplan][ic];        
+        ypos -= fClength[iplan][ic];
       }
-      ypos += fClength[iplan][icham]/2.0;
-      zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0 
+      ypos -= fClength[iplan][icham]/2.0;
+      zpos  = fgkVrocsm + fgkSMpltT + fgkCraH/2.0 + fgkCdrH/2.0 - fgkSheight/2.0
             + iplan * (fgkCH + fgkVspace);
       // The lower aluminum frame, radiator + drift region
       sprintf(cTagV,"UA%02d",iDet);      
@@ -924,12 +1184,6 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
   gMC->Matrix(matrix[1],  80.0,   0.0,  90.0,  90.0,  10.0, 180.0);
   gMC->Matrix(matrix[2],   0.0,   0.0,  90.0,  90.0,  90.0,   0.0);
   gMC->Matrix(matrix[3], 180.0,   0.0,  90.0,  90.0,  90.0, 180.0);
-
-  AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
-  if (!commonParam) {
-    AliError("Could not get common parameters\n");
-    return;
-  }
     
   //
   // The cooling arterias
@@ -1033,12 +1287,12 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
       gMC->Gsvolu(cTagV,"BOX",idtmed[1302-1],parServ,kNparServ);
 
       xpos  = 0.0;
-      ypos  = - fClength[iplan][0] - fClength[iplan][1] - fClength[iplan][2]/2.0;
+      ypos  = fClength[iplan][0] + fClength[iplan][1] + fClength[iplan][2]/2.0;
       for (Int_t ic = 0; ic < icham; ic++) {
-        ypos += fClength[iplan][ic];        
+        ypos -= fClength[iplan][ic];
       }
-      ypos += fClength[iplan][icham]/2.0;
-      zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0 
+      ypos -= fClength[iplan][icham]/2.0;
+      zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
             + iplan * (fgkCH + fgkVspace);
       zpos -= 0.742/2.0;
       fChamberUUorig[iDet][0] = xpos;
@@ -1062,7 +1316,7 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
   // The cooling water
   parTube[0] =  0.0;
   parTube[1] =  0.2/2.0;
-  parTube[2] = -1.;
+  parTube[2] =  fCwidth[iplan]/2.0;
   gMC->Gsvolu("UTCH","TUBE",idtmed[1314-1],parTube,kNparTube);
   // Water inside the cooling pipe
   xpos = 0.0;
@@ -1077,7 +1331,7 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
     for (iplan = 0; iplan < kNplan; iplan++) {
       Int_t   iDet    = GetDetectorSec(iplan,icham);
       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
-      Int_t   nMCMrow = commonParam->GetRowMax(iplan,icham,0);
+      Int_t   nMCMrow = GetRowMax(iplan,icham,0);
       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
                       / ((Float_t) nMCMrow);
       sprintf(cTagV,"UU%02d",iDet);
@@ -1110,7 +1364,7 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
     for (iplan = 0; iplan < kNplan; iplan++) {
       Int_t   iDet    = GetDetectorSec(iplan,icham);
       Int_t   iCopy   = GetDetector(iplan,icham,0) * 100;
-      Int_t   nMCMrow = commonParam->GetRowMax(iplan,icham,0);
+      Int_t   nMCMrow = GetRowMax(iplan,icham,0);
       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
                       / ((Float_t) nMCMrow);
       sprintf(cTagV,"UU%02d",iDet);
@@ -1135,11 +1389,11 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
   const Float_t kMCMx    = 3.0;
   const Float_t kMCMy    = 3.0;
   const Float_t kMCMz    = 0.3;
-
+  
   const Float_t kMCMpcTh = 0.1;
-  const Float_t kMCMcuTh = 0.0215;
-  const Float_t kMCMsiTh = 0.003;
-  const Float_t kMCMcoTh = 0.1549;
+  const Float_t kMCMcuTh = 0.0025;
+  const Float_t kMCMsiTh = 0.03;
+  const Float_t kMCMcoTh = 0.04;
 
   // The mother volume for the MCMs (air)
   const Int_t kNparMCM = 3;
@@ -1187,7 +1441,7 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
     for (iplan = 0; iplan < kNplan; iplan++) {
       Int_t   iDet    = GetDetectorSec(iplan,icham);
       Int_t   iCopy   = GetDetector(iplan,icham,0) * 1000;
-      Int_t   nMCMrow = commonParam->GetRowMax(iplan,icham,0);
+      Int_t   nMCMrow = GetRowMax(iplan,icham,0);
       Float_t ySize   = (GetChamberLength(iplan,icham) - 2.0*fgkRpadW) 
                       / ((Float_t) nMCMrow);
       Int_t   nMCMcol = 8;
@@ -1312,38 +1566,18 @@ void AliTRDgeometry::GroupChamber(Int_t iplan, Int_t icham, Int_t *idtmed)
 }
 
 //_____________________________________________________________________________
-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
-  // the coordinates in the ALICE restframe <pos> into the 
-  // corresponding local frame <rot>.
-  //
-
-  Int_t sector = GetSector(d);
-
-  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;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliTRDgeometry::RotateBack(Int_t d, Double_t *rot, Double_t *pos) const
+Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) const
 {
   //
-  // Rotates a chambers from the position of sector 0 into its
-  // original position and transforms the corresponding local frame 
-  // coordinates <rot> into the coordinates of the ALICE restframe <pos>.
+  // Rotates a chambers to transform the corresponding local frame
+  // coordinates <loc> into the coordinates of the ALICE restframe <glb>.
   //
 
-  Int_t sector = GetSector(d);
+  Int_t sector = GetSector(det);
 
-  pos[0] =  rot[0] * fRotB11[sector] + rot[1] * fRotB12[sector];
-  pos[1] = -rot[0] * fRotB21[sector] + rot[1] * fRotB22[sector];
-  pos[2] =  rot[2];
+  glb[0] = loc[0] * fRotB11[sector] - loc[1] * fRotB12[sector];
+  glb[1] = loc[0] * fRotB21[sector] + loc[1] * fRotB22[sector];
+  glb[2] = loc[2];
 
   return kTRUE;
 
@@ -1372,7 +1606,7 @@ Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetPlane(Int_t d) const
+Int_t AliTRDgeometry::GetPlane(Int_t d)
 {
   //
   // Reconstruct the plane number from the detector number
@@ -1405,41 +1639,140 @@ Int_t AliTRDgeometry::GetSector(Int_t d) const
 }
 
 //_____________________________________________________________________________
-AliTRDgeometry *AliTRDgeometry::GetGeometry(AliRunLoader *runLoader)
+AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t p, Int_t c)
 {
   //
-  // Load the geometry from the galice file
+  // Returns the pad plane for a given plane <p> and chamber <c> number
   //
 
-  if (!runLoader) {
-    runLoader = AliRunLoader::GetRunLoader();
-  }
-  if (!runLoader) {
-    AliErrorGeneral("AliTRDgeometry::GetGeometry","No run loader");
-    return NULL;
+  if (!fPadPlaneArray) {
+    CreatePadPlaneArray();
   }
 
-  TDirectory *saveDir = gDirectory;
-  runLoader->CdGAFile();
+  Int_t ipp = GetDetectorSec(p,c);
+  return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
 
-  // Try from the galice.root file
-  AliTRDgeometry *geom = (AliTRDgeometry *) gDirectory->Get("TRDgeometry");
+}
 
-  if (!geom) {
-    // If it is not in the file, try to get it from the run loader 
-    AliTRD *trd = (AliTRD *) runLoader->GetAliRun()->GetDetector("TRD");
-    geom = trd->GetGeometry();
-  }
-  if (!geom) {
-    AliErrorGeneral("AliTRDgeometry::GetGeometry","Geometry not found");
-    return NULL;
-  }
+//_____________________________________________________________________________
+Int_t AliTRDgeometry::GetRowMax(Int_t p, Int_t c, Int_t /*s*/)
+{
+  //
+  // Returns the number of rows on the pad plane
+  //
+
+  return GetPadPlane(p,c)->GetNrows();
+
+}
+
+//_____________________________________________________________________________
+Int_t AliTRDgeometry::GetColMax(Int_t p)
+{
+  //
+  // Returns the number of rows on the pad plane
+  //
+
+  return GetPadPlane(p,0)->GetNcols();
+
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDgeometry::GetRow0(Int_t p, Int_t c, Int_t /*s*/)
+{
+  //
+  // Returns the position of the border of the first pad in a row
+  //
+
+  return GetPadPlane(p,c)->GetRow0();
+
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDgeometry::GetCol0(Int_t p)
+{
+  //
+  // Returns the position of the border of the first pad in a column
+  //
 
-  saveDir->cd();
-  return geom;
+  return GetPadPlane(p,0)->GetCol0();
 
 }
 
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
+//{
+  //
+  // Return on which row this mcm sits 
+  //
+//
+//  return fgkMCMrow*(irob/2) + imcm/fgkMCMrow;
+//
+//}
+
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
+//{
+  //
+  // Return which pad is connected to this adc channel. return -1 if it
+  // is one of the not directly connected adc channels (0, 1 20)
+  //
+//
+//  if (iadc < 2 || iadc > 19 ) return -1;
+//
+//  return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
+//
+//}
+
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
+//{
+  //
+  // Return on which mcm this pad is
+  //
+//
+//  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
+//
+//  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
+//
+//}
+
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetROBfromPad(Int_t irow, Int_t icol) const
+//{
+  //
+  // Return on which rob this pad is
+  //
+//
+//  return (irow/fgkMCMrow)*2 + GetColSide(icol);
+//
+//}
+
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
+//{
+  //
+  // Return on which side this rob sits (A side = 0, B side = 1)
+  //
+//
+//  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
+//
+//  return irob%2;
+//
+//}
+
+//_____________________________________________________________________________
+//Int_t AliTRDgeometry::GetColSide(Int_t icol) const
+//{
+  //
+  // Return on which side this column sits (A side = 0, B side = 1)
+  //
+//
+//  if ( icol < 0 || icol >= fgkColmax ) return -1;
+//
+//  return icol/(fgkColmax/2);
+//
+//}
+
 //_____________________________________________________________________________
 Bool_t AliTRDgeometry::ReadGeoMatrices()
 {
@@ -1456,11 +1789,11 @@ Bool_t AliTRDgeometry::ReadGeoMatrices()
   fMatrixGeo             = new TObjArray(kNdet);
   AliAlignObjAngles o;
 
-  for (Int_t iLayer = AliAlignObj::kTRD1; iLayer <= AliAlignObj::kTRD6; iLayer++) {
-    for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer); iModule++) {
+  for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
+    for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
 
-      UShort_t     volid   = AliAlignObj::LayerToVolUID(iLayer,iModule);
-      const char  *symname = AliAlignObj::SymName(volid);
+      UShort_t     volid   = AliGeomManager::LayerToVolUID(iLayer,iModule);
+      const char  *symname = AliGeomManager::SymName(volid);
       TGeoPNEntry *pne     = gGeoManager->GetAlignableEntry(symname);
       const char  *path    = symname;
       if (pne) {
@@ -1470,9 +1803,9 @@ Bool_t AliTRDgeometry::ReadGeoMatrices()
         return kFALSE;
       }
       TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
-      Int_t        iLayerTRD = iLayer - AliAlignObj::kTRD1;
-      Int_t        isector   = Nsect() - 1 - (iModule/Ncham());
-      Int_t        ichamber  = Ncham() - 1 - (iModule%Ncham());
+      Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
+      Int_t        isector   = iModule/Ncham();
+      Int_t        ichamber  = iModule%Ncham();
       Int_t        lid       = GetDetector(iLayerTRD,ichamber,isector);    
 
       //
@@ -1496,7 +1829,7 @@ Bool_t AliTRDgeometry::ReadGeoMatrices()
       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
       TGeoHMatrix  rotSector;
       rotSector.RotateZ(sectorAngle);
-      rotMatrix.MultiplyLeft(&rotSector);      
+      rotMatrix.MultiplyLeft(&rotSector.Inverse());
 
       fMatrixCorrectionArray->AddAt(new TGeoHMatrix(rotMatrix),lid);