]> 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 8641e2b4c496eae5d06e24957dd72d9a4e59dae4..9e433b360f37abbbc1a22ccffd21f7c3c607c6be 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.21  2002/11/21 16:09:44  cblume
-Change fgkRpadW to 1.0 cm for new pad plane
-
-Revision 1.20  2002/10/31 17:45:35  cblume
-New chamber geometry
-
-Revision 1.19  2002/10/14 14:57:43  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.15.6.2  2002/07/24 10:09:30  alibrary
-Updating VirtualMC
-
-Revision 1.15.6.1  2002/06/10 15:28:58  hristov
-Merged with v3-08-02
-
-Revision 1.17  2002/04/05 13:20:12  cblume
-Remove const for CreateGeometry
-
-Revision 1.16  2002/03/28 14:59:07  cblume
-Coding conventions
-
-Revision 1.18  2002/06/12 09:54:35  cblume
-Update of tracking code provided by Sergei
-
-Revision 1.17  2002/04/05 13:20:12  cblume
-Remove const for CreateGeometry
-
-Revision 1.16  2002/03/28 14:59:07  cblume
-Coding conventions
-
-Revision 1.15  2002/02/11 14:21:16  cblume
-Update of the geometry. Get rid of MANY
-
-Revision 1.14  2001/11/06 17:19:41  cblume
-Add detailed geometry and simple simulator
-
-Revision 1.13  2001/08/02 08:30:45  cblume
-Fix positions of cooling material
-
-Revision 1.12  2001/05/21 16:45:47  hristov
-Last minute changes (C.Blume)
-
-Revision 1.11  2001/05/11 07:56:12  hristov
-Consistent declarations needed on Alpha
-
-Revision 1.10  2001/05/07 08:08:05  cblume
-Update of TRD code
-
-Revision 1.9  2001/03/27 12:48:33  cblume
-Correct for volume overlaps
-
-Revision 1.8  2001/03/13 09:30:35  cblume
-Update of digitization. Moved digit branch definition to AliTRD
-
-Revision 1.7  2001/02/14 18:22:26  cblume
-Change in the geometry of the padplane
-
-Revision 1.6  2000/11/01 14:53:20  cblume
-Merge with TRD-develop
-
-Revision 1.1.4.7  2000/10/16 01:16:53  cblume
-Changed timebin 0 to be the one closest to the readout
-
-Revision 1.1.4.6  2000/10/15 23:35:57  cblume
-Include geometry constants as static member
-
-Revision 1.1.4.5  2000/10/06 16:49:46  cblume
-Made Getters const
-
-Revision 1.1.4.4  2000/10/04 16:34:58  cblume
-Replace include files by forward declarations
-
-Revision 1.1.4.3  2000/09/22 14:43:40  cblume
-Allow the pad/timebin-dimensions to be changed after initialization
-
-Revision 1.1.4.2  2000/09/18 13:37:01  cblume
-Minor coding corrections
-
-Revision 1.5  2000/10/02 21:28:19  fca
-Removal of useless dependecies via forward declarations
-
-Revision 1.4  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-Revision 1.3  2000/06/07 16:25:37  cblume
-Try to remove compiler warnings on Sun and HP
-
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-Revision 1.1.4.1  2000/05/08 14:45:55  cblume
-Bug fix in RotateBack(). Geometry update
-
-Revision 1.4  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-Revision 1.3  2000/06/07 16:25:37  cblume
-Try to remove compiler warnings on Sun and HP
-
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-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$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -132,8 +22,16 @@ Add new TRD classes
 ///////////////////////////////////////////////////////////////////////////////
 
 
+#include <TError.h>
+
+#include "AliRunLoader.h"
 #include "AliTRDgeometry.h"
-#include "AliTRDparameter.h"
+#include "AliTRDpadPlane.h"
+
+#include "AliRun.h"
+#include "AliTRD.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCommonParam.h"
 
 ClassImp(AliTRDgeometry)
 
@@ -167,6 +65,10 @@ ClassImp(AliTRDgeometry)
   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; 
@@ -175,7 +77,7 @@ ClassImp(AliTRDgeometry)
   // Amplification region
   const Float_t AliTRDgeometry::fgkCamH    =   0.7;
   // Readout
-  const Float_t AliTRDgeometry::fgkCroH    =   2.0;
+  const Float_t AliTRDgeometry::fgkCroH    =   2.316;
   // Total height
   const Float_t AliTRDgeometry::fgkCH      = AliTRDgeometry::fgkCraH
                                            + AliTRDgeometry::fgkCdrH
@@ -183,7 +85,7 @@ ClassImp(AliTRDgeometry)
                                            + AliTRDgeometry::fgkCroH;  
 
   // Vertical spacing of the chambers
-  const Float_t AliTRDgeometry::fgkVspace  =   2.1;
+  const Float_t AliTRDgeometry::fgkVspace  =   1.784;
 
   // Horizontal spacing of the chambers
   const Float_t AliTRDgeometry::fgkHspace  =   2.0;
@@ -204,7 +106,8 @@ ClassImp(AliTRDgeometry)
   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   =   1.0;
+  const Float_t AliTRDgeometry::fgkCpadW   =   0.0;
   const Float_t AliTRDgeometry::fgkRpadW   =   1.0;
 
   //
@@ -234,6 +137,14 @@ ClassImp(AliTRDgeometry)
   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()
@@ -243,7 +154,6 @@ AliTRDgeometry::AliTRDgeometry():AliGeometry()
   //
 
   Init();
-
 }
 
 //_____________________________________________________________________________
@@ -252,7 +162,6 @@ AliTRDgeometry::~AliTRDgeometry()
   //
   // AliTRDgeometry destructor
   //
-
 }
 
 //_____________________________________________________________________________
@@ -289,20 +198,32 @@ void AliTRDgeometry::Init()
   Int_t isect;
 
   // The outer width of the chambers
-  fCwidth[0] =  95.6;
-  fCwidth[1] = 100.1;
-  fCwidth[2] = 104.5;
-  fCwidth[3] = 108.9;
-  fCwidth[4] = 113.4;
-  fCwidth[5] = 117.8;
+  //
+  // 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 }
-                                     , { 147.0, 147.0, 110.0, 147.0, 147.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++) {
@@ -330,7 +251,7 @@ void AliTRDgeometry::Init()
 }
 
 //_____________________________________________________________________________
-void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
+void AliTRDgeometry::CreateGeometry(Int_t)
 {
   //
   // Create TRD geometry
@@ -339,9 +260,8 @@ void AliTRDgeometry::CreateGeometry(Int_t *idtmed)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDgeometry::Local2Global(Int_t idet, Float_t *local
-                                   , Float_t *global
-                                   , AliTRDparameter *par) const
+Bool_t AliTRDgeometry::Local2Global(Int_t idet, Double_t *local
+                                   , Double_t *global) const
 {
   //
   // Converts local pad-coordinates (row,col,time) into 
@@ -352,44 +272,42 @@ Bool_t AliTRDgeometry::Local2Global(Int_t idet, Float_t *local
   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,par);
+  return Local2Global(iplan,icham,isect,local,global);
 
 }
  
 //_____________________________________________________________________________
 Bool_t AliTRDgeometry::Local2Global(Int_t iplan, Int_t icham, Int_t isect
-                                  , Float_t *local, Float_t *global
-                                  , AliTRDparameter *par) const
+                                  , Double_t *local, Double_t *global) const
 {
   //
   // Converts local pad-coordinates (row,col,time) into 
   // global ALICE reference frame coordinates (x,y,z)
   //
 
-  if (!par) {
-    Error("Local2Global","No parameter defined\n");
+  AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
+  if (!commonParam)
     return kFALSE;
-  }
 
-  Int_t    idet      = GetDetector(iplan,icham,isect); // Detector number
+  AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
+  if (!calibration)
+    return kFALSE;  
+  
+  AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
 
-  Float_t  padRow    = local[0]+0.5;                   // Pad Row position
-  Float_t  padCol    = local[1]+0.5;                   // Pad Column position
-  Float_t  timeSlice = local[2]+0.5;                   // Time "position"
-
-  Float_t  row0      = par->GetRow0(iplan,icham,isect);
-  Float_t  col0      = par->GetCol0(iplan);
-  Float_t  time0     = par->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 - par->GetTimeBefore()) 
-         * par->GetTimeBinSize();
-  rot[1] = col0  + padCol                    
-         * par->GetColPadSize(iplan);
-  rot[2] = row0  + padRow                    
-         * par->GetRowPadSize(iplan,icham,isect);
+  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);
@@ -397,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) const
+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
@@ -416,7 +408,7 @@ Bool_t AliTRDgeometry::Rotate(Int_t d, Float_t *pos, Float_t *rot) const
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDgeometry::RotateBack(Int_t d, Float_t *rot, Float_t *pos) const
+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
@@ -435,7 +427,7 @@ Bool_t AliTRDgeometry::RotateBack(Int_t d, Float_t *rot, Float_t *pos) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetDetectorSec(const Int_t p, const Int_t c) const
+Int_t AliTRDgeometry::GetDetectorSec(Int_t p, Int_t c)
 {
   //
   // Convert plane / chamber into detector number for one single sector
@@ -446,7 +438,7 @@ Int_t AliTRDgeometry::GetDetectorSec(const Int_t p, const Int_t c) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetDetector(const Int_t p, const Int_t c, const Int_t s) const
+Int_t AliTRDgeometry::GetDetector(Int_t p, Int_t c, Int_t s)
 {
   //
   // Convert plane / chamber / sector into detector number
@@ -457,7 +449,7 @@ Int_t AliTRDgeometry::GetDetector(const Int_t p, const Int_t c, const Int_t s) c
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetPlane(const Int_t d) const
+Int_t AliTRDgeometry::GetPlane(Int_t d) const
 {
   //
   // Reconstruct the plane number from the detector number
@@ -468,7 +460,7 @@ Int_t AliTRDgeometry::GetPlane(const Int_t d) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetChamber(const Int_t d) const
+Int_t AliTRDgeometry::GetChamber(Int_t d) const
 {
   //
   // Reconstruct the chamber number from the detector number
@@ -479,7 +471,7 @@ Int_t AliTRDgeometry::GetChamber(const Int_t d) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDgeometry::GetSector(const Int_t d) const
+Int_t AliTRDgeometry::GetSector(Int_t d) const
 {
   //
   // Reconstruct the sector number from the detector number
@@ -490,26 +482,32 @@ Int_t AliTRDgeometry::GetSector(const Int_t d) const
 }
 
 //_____________________________________________________________________________
-void AliTRDgeometry::SetOldGeometry()
+AliTRDgeometry* AliTRDgeometry::GetGeometry(AliRunLoader* runLoader)
 {
   //
-  // Use the old chamber lengths
+  // load the geometry from the galice file
   //
 
-  Int_t icham;
-  Int_t iplan;
+  if (!runLoader) runLoader = AliRunLoader::GetRunLoader();
+  if (!runLoader) {
+    ::Error("AliTRDgeometry::GetGeometry", "No run loader");
+    return NULL;
+  }
 
-  Float_t length[kNplan][kNcham]   = { { 123.5, 123.5, 110.0, 123.5, 123.5 }
-                                    , { 131.0, 131.0, 110.0, 131.0, 131.0 }
-                                    , { 134.5, 138.5, 110.0, 138.5, 134.5 }
-                                    , { 142.0, 146.0, 110.0, 146.0, 142.0 }
-                                    , { 142.0, 153.0, 110.0, 153.0, 142.0 }
-                                     , { 134.0, 160.5, 110.0, 160.5, 134.0 } };
+  TDirectory* saveDir = gDirectory;
+  runLoader->CdGAFile();
 
-  for (icham = 0; icham < kNcham; icham++) {
-    for (iplan = 0; iplan < kNplan; iplan++) {
-      fClength[iplan][icham]   = length[iplan][icham];
-    }
+  // 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;
 }