]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDgeometry.cxx
Change default validity range
[u/mrichter/AliRoot.git] / TRD / AliTRDgeometry.cxx
index b1548d185256f193b264876df12c6444a010d98a..fe5eefe1ee08075a055b627123df496d2fe15e80 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "AliTRD.h"
 #include "AliTRDcalibDB.h"
-#include "AliTRDCommonParam.h"
 #include "AliTRDgeometry.h"
 #include "AliTRDpadPlane.h"
 
@@ -164,7 +163,7 @@ AliTRDgeometry::AliTRDgeometry()
   ,fMatrixArray(0)
   ,fMatrixCorrectionArray(0)
   ,fMatrixGeo(0)
-
+  ,fPadPlaneArray(0)
 {
   //
   // AliTRDgeometry default constructor
@@ -177,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
@@ -197,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;
+  }
+
 }
 
 //_____________________________________________________________________________
@@ -261,23 +275,259 @@ void AliTRDgeometry::Init()
   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;
     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)
 {
@@ -589,10 +839,10 @@ void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
       xpos  = 0.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 
+      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);      
@@ -934,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
@@ -1045,10 +1289,10 @@ void AliTRDgeometry::CreateServices(Int_t *idtmed)
       xpos  = 0.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 
+      zpos  = fgkVrocsm + fgkSMpltT + fgkCH + fgkVspace/2.0 - fgkSheight/2.0
             + iplan * (fgkCH + fgkVspace);
       zpos -= 0.742/2.0;
       fChamberUUorig[iDet][0] = xpos;
@@ -1087,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);
@@ -1120,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);
@@ -1145,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;
@@ -1197,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;
@@ -1322,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
+Bool_t AliTRDgeometry::RotateBack(Int_t det, Double_t *loc, Double_t *glb) 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>.
+  // 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);
 
-  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
-{
-  //
-  // 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>.
-  //
-
-  Int_t sector = GetSector(d);
-
-  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;
 
@@ -1382,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
@@ -1415,120 +1639,137 @@ Int_t AliTRDgeometry::GetSector(Int_t d) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
+AliTRDpadPlane *AliTRDgeometry::GetPadPlane(Int_t p, Int_t c)
 {
+  //
+  // Returns the pad plane for a given plane <p> and chamber <c> number
+  //
 
-  // return on which row this mcm sits 
+  if (!fPadPlaneArray) {
+    CreatePadPlaneArray();
+  }
 
-  return fgkMCMrow*(irob/2) + imcm/fgkMCMrow;
+  Int_t ipp = GetDetectorSec(p,c);
+  return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
 
-;
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
+Int_t AliTRDgeometry::GetRowMax(Int_t p, Int_t c, Int_t /*s*/)
 {
   //
-  // return which pad is connected to this adc channel.
+  // Returns the number of rows on the pad plane
   //
-  // ADC channels 2 to 19 are connected directly to a pad via PASA.
-  // ADC channels 0, 1 and 20 are not connected to the PASA on this MCM.
-  // So the mapping (for MCM 0 on ROB 0 at least) is
+
+  return GetPadPlane(p,c)->GetNrows();
+
+}
+
+//_____________________________________________________________________________
+Int_t AliTRDgeometry::GetColMax(Int_t p)
+{
   //
-  // ADC channel  :   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
-  // Pad          :   x  x 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0  x
-  // Func. returns:  19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0 -1
+  // Returns the number of rows on the pad plane
   //
-  // Here we assume that 21 ADC channels are transmitted. Maybe it will only be
-  // 18 later on!!!
+
+  return GetPadPlane(p,0)->GetNcols();
+
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDgeometry::GetRow0(Int_t p, Int_t c, Int_t /*s*/)
+{
   //
-  // This function maps also correctly the channels that cross from MCM to MCM
-  // (ADC channels 0, 1, 20).
+  // Returns the position of the border of the first pad in a row
   //
 
-  return (17-(iadc-2)) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
+  return GetPadPlane(p,c)->GetRow0();
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
+Double_t AliTRDgeometry::GetCol0(Int_t p)
 {
+  //
+  // Returns the position of the border of the first pad in a column
+  //
 
-  // return on which mcm this pad is
+  return GetPadPlane(p,0)->GetCol0();
 
-  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
+}
 
-  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
+//_____________________________________________________________________________
+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::GetROBfromPad(Int_t irow, Int_t icol) const
+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)
+  //
 
-  // return on which rob this pad is
+  if (iadc < 2 || iadc > 19 ) return -1;
 
-  return (irow/fgkMCMrow)*2 + GetColSide(icol);
+  return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2;
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
+Int_t AliTRDgeometry::GetMCMfromPad(Int_t irow, Int_t icol) const
 {
+  //
+  // Return on which mcm this pad is
+  //
 
-  // return on which side this rob sits (A side = 0, B side = 1)
-
-  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
+  if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1;
 
-  return irob%2;
+  return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow);
 
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetColSide(Int_t icol) const
+Int_t AliTRDgeometry::GetROBfromPad(Int_t irow, Int_t icol) const
 {
+  //
+  // Return on which rob this pad is
+  //
 
-  // return on which side this column sits (A side = 0, B side = 1)
-
-  if ( icol < 0 || icol >= fgkColmax ) return -1;
-
-  return icol/(fgkColmax/2);
+  return (irow/fgkMCMrow)*2 + GetColSide(icol);
 
 }
 
 //_____________________________________________________________________________
-AliTRDgeometry *AliTRDgeometry::GetGeometry(AliRunLoader *runLoader)
+Int_t AliTRDgeometry::GetRobSide(Int_t irob) const
 {
   //
-  // Load the geometry from the galice file
+  // Return on which side this rob sits (A side = 0, B side = 1)
   //
 
-  if (!runLoader) {
-    runLoader = AliRunLoader::GetRunLoader();
-  }
-  if (!runLoader) {
-    AliErrorGeneral("AliTRDgeometry::GetGeometry","No run loader");
-    return NULL;
-  }
+  if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1;
 
-  TDirectory *saveDir = gDirectory;
-  runLoader->CdGAFile();
+  return irob%2;
 
-  // 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::GetColSide(Int_t icol) const
+{
+  //
+  // Return on which side this column sits (A side = 0, B side = 1)
+  //
 
-  saveDir->cd();
-  return geom;
+  if ( icol < 0 || icol >= fgkColmax ) return -1;
+
+  return icol/(fgkColmax/2);
 
 }
 
@@ -1536,13 +1777,7 @@ AliTRDgeometry *AliTRDgeometry::GetGeometry(AliRunLoader *runLoader)
 Bool_t AliTRDgeometry::ReadGeoMatrices()
 {
   //
-  // Read the geo matrices from the current gGeoManager for each TRD detector
-  //
-  // This fill three arrays of TGeoHMatrix, ordered by detector numbers 
-  // for fast access:
-  //   fMatrixArray:           Used for transformation local <-> global ???
-  //   fMatrixCorrectionArray: Used for transformation local <-> tracking system
-  //   fMatrixGeo:             Alignable objects
+  // Read geo matrices from current gGeoManager for each TRD sector
   //
 
   if (!gGeoManager) {
@@ -1552,13 +1787,13 @@ Bool_t AliTRDgeometry::ReadGeoMatrices()
   fMatrixArray           = new TObjArray(kNdet); 
   fMatrixCorrectionArray = new TObjArray(kNdet);
   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++) {
 
-      // Find the path to the different alignable objects (ROCs)
-      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) {
@@ -1567,38 +1802,36 @@ Bool_t AliTRDgeometry::ReadGeoMatrices()
       if (!gGeoManager->cd(path)) {
         return kFALSE;
       }
-
-      // Get the geo matrix of the current alignable object
-      // and add it to the corresponding list
-      TGeoHMatrix *matrix   = gGeoManager->GetCurrentMatrix();
-      Int_t        iplane   = iLayer - AliAlignObj::kTRD1;
-      Int_t        isector  = iModule / Ncham();
-      Int_t        ichamber = iModule % Ncham();
-      Int_t        idet     = GetDetector(iplane,ichamber,isector);
-      fMatrixGeo->AddAt(new TGeoHMatrix(* matrix),idet);
-
-      // Construct the geo matrix for the local <-> global transformation
-      // and add it to the corresponding list.
-      // In addition to the original geo matrix also a rotation of the
-      // kind z-x-y to x-y--z is applied.
-      TGeoRotation rotMatrixA;
-      rotMatrixA.RotateY(90); 
-      rotMatrixA.RotateX(90);
-      TGeoHMatrix matrixGlobal(rotMatrixA.Inverse());
-      matrixGlobal.MultiplyLeft(matrix);
-      fMatrixArray->AddAt(new TGeoHMatrix(matrixGlobal),idet);
-
-      // Construct the geo matrix for the cluster transformation
-      // and add it to the corresponding list.
-      // In addition to the original geo matrix also a rotation of the
-      // kind x-y--z to z-x-y and a rotation by the sector angle is applied.
+      TGeoHMatrix *m         = gGeoManager->GetCurrentMatrix();
+      Int_t        iLayerTRD = iLayer - AliGeomManager::kTRD1;
+      Int_t        isector   = iModule/Ncham();
+      Int_t        ichamber  = iModule%Ncham();
+      Int_t        lid       = GetDetector(iLayerTRD,ichamber,isector);    
+
+      //
+      // Local geo system z-x-y  to x-y--z 
+      //
+      fMatrixGeo->AddAt(new TGeoHMatrix(*m),lid);
+      
+      TGeoRotation mchange; 
+      mchange.RotateY(90); 
+      mchange.RotateX(90);
+
+      TGeoHMatrix gMatrix(mchange.Inverse());
+      gMatrix.MultiplyLeft(m);
+      fMatrixArray->AddAt(new TGeoHMatrix(gMatrix),lid); 
+
+      //
+      // Cluster transformation matrix
+      //
+      TGeoHMatrix  rotMatrix(mchange.Inverse());
+      rotMatrix.MultiplyLeft(m);
       Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
-      TGeoHMatrix rotMatrixB(rotMatrixA.Inverse());
-      rotMatrixB.MultiplyLeft(matrix);
-      TGeoHMatrix rotSector;
+      TGeoHMatrix  rotSector;
       rotSector.RotateZ(sectorAngle);
-      rotMatrixB.MultiplyLeft(&rotSector);      
-      fMatrixCorrectionArray->AddAt(new TGeoHMatrix(rotMatrixB),idet);
+      rotMatrix.MultiplyLeft(&rotSector.Inverse());
+
+      fMatrixCorrectionArray->AddAt(new TGeoHMatrix(rotMatrix),lid);       
 
     }    
   }