]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackingSector.cxx
fix for the corrupt data
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackingSector.cxx
index ae58d2c43a3e2a8624296c9f0fc44579969ba4fa..50c125c39e493e0eff1dba72e38abc9627d923ae 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.1.2.2  2000/10/04 16:34:58  cblume
-Replace include files by forward declarations
-
-Revision 1.1.2.1  2000/09/22 14:47:52  cblume
-Add the tracking code
-
-*/                        
-                                
-#include <TObject.h>
-
-#include "AliRun.h"
-
-#include "AliTRD.h" 
-#include "AliTRDconst.h"
-#include "AliTRDgeometry.h" 
-#include "AliTRDcluster.h" 
-#include "AliTRDtimeBin.h" 
-
-#include "AliTRDtrackingSector.h" 
-
-
-ClassImp(AliTRDtrackingSector) 
-
-//_______________________________________________________
+/* $Id: AliTRDtrackingSector.cxx 23810 2008-02-08 09:00:27Z hristov $ */
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//  Tracking data container for one sector                                   //
+//                                                                           //
+//  Authors:                                                                 //
+//    Alex Bercuci <A.Bercuci@gsi.de>                                        //
+//    Markus Fasel <M.Fasel@gsi.de>                                          //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliTRDtrackingSector.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCommonParam.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDpadPlane.h"
+#include "AliTRDtrackingChamber.h"
+
+ClassImp(AliTRDtrackingSector)
+
+//_____________________________________________________________________________
+AliTRDtrackingSector::AliTRDtrackingSector()
+  :fSector(-1)
+  ,fN(0)
+  ,fGeom(0x0)
+{
+       // Default constructor
+       
+       for(int ic=0; ic<kNChambersSector; ic++){
+               fChamber[ic] = 0x0;
+               fIndex[ic]   = -1;
+       }
+       for(int il=0; il<AliTRDgeometry::kNlayer; il++) fX0[il] = 0.;
+}
 
-AliTRDtrackingSector::~AliTRDtrackingSector()
+//_____________________________________________________________________________
+AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry *geo, Int_t gs)
+  :fSector(gs)
+  ,fN(0)
+  ,fGeom(geo)
 {
   //
-  // Destructor
+  // AliTRDtrackingSector Constructor
   //
 
-  delete[] fTimeBin;
-
+       for(int ic=0; ic<kNChambersSector; ic++){
+               fChamber[ic] = 0x0;
+               fIndex[ic]   = -1;
+       }
+       for(int il=0; il<AliTRDgeometry::kNlayer; il++) fX0[il] = 0.;
 }
 
-//_______________________________________________________
-AliTRDtimeBin &AliTRDtrackingSector::operator[](Int_t i)
+//_____________________________________________________________________________
+AliTRDtrackingSector::AliTRDtrackingSector(const AliTRDtrackingSector &/*t*/)
+  :fSector(-1)
+  ,fN(0)
+  ,fGeom(0x0)
 {
   //
-  // Index operator 
+  // Copy constructor
   //
 
-  return *(fTimeBin+i);
-
 }
 
-//_______________________________________________________
-
-void AliTRDtrackingSector::SetUp()
-{ 
-
-  AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
-  fGeom = TRD->GetGeometry();
-
-  fTimeBinSize = fGeom->GetTimeBinSize();
-
-  fN = kNplan * (Int_t(kDrThick/fTimeBinSize) + 1);
-
-  fTimeBin = new AliTRDtimeBin[fN]; 
+//_____________________________________________________________________________
+AliTRDtrackingSector::~AliTRDtrackingSector()
+{
+  //
+  // Destructor
+  //
 
 }
-
-//______________________________________________________
-
-Double_t AliTRDtrackingSector::GetX(Int_t l) const
+               
+//_____________________________________________________________________________
+void AliTRDtrackingSector::Init()
+{              
+//     Steer building of tracking chambers and build tracking sector.
+//     Propagate radial position information (calibration/alignment aware) from chambers to sector level
+//
+       
+       AliTRDtrackingChamber *tc = 0x0; int ic = 0; 
+       while((ic<kNChambersSector) && (tc = fChamber[ic++])) tc->Build(fGeom);
+               
+       Int_t nl;
+       for(int il=0; il<AliTRDgeometry::kNlayer; il++){
+               fX0[il] = 0.; nl = 0;
+               for(int is=0; is<AliTRDgeometry::kNstack; is++){
+                       Int_t idx = is*AliTRDgeometry::kNlayer + il;
+                       if(fIndex[idx]<0) continue;
+                       tc = GetChamber(fIndex[idx]);
+                       fX0[il] += tc->GetX(); nl++; 
+               }
+               if(!nl){
+                       //printf("Could not estimate radial position  of plane %d in sector %d.\n", ip, fSector);
+                       continue;
+               }
+               fX0[il] /= Float_t(nl);
+       }
+}
+//_____________________________________________________________________________
+void AliTRDtrackingSector::Clear(const Option_t *opt)
 {
-  if( (l<0) || (l>fN-1)) {
-    fprintf(stderr,"AliTRDtrackingSector::GetX: TimeBin index is out of range !\n");
-    return -99999.;
-  }
-  else { 
-    
-    Int_t tb_per_plane = fN/kNplan;
-    Int_t plane = l/tb_per_plane;
-    Int_t time_slice = l%(Int_t(kDrThick/fTimeBinSize) + 1);
-
-    Float_t t0 = fGeom->GetTime0(plane);
-    Double_t x = t0 + time_slice * fTimeBinSize;
-
-    //    cerr<<"plane, tb, x = "<<plane<<","<<time_slice<<","<<x<<endl;
-
-    return x;
-  }
+// Reset counters and steer chamber clear
+
+       for(Int_t ich=0; ich<fN; ich++){ 
+               fChamber[ich]->Clear(opt);
+               delete fChamber[ich]; fChamber[ich] = 0x0;   // I would avoid
+       }       
+       for(Int_t ich=0; ich<kNChambersSector; ich++) fIndex[ich] = -1;
+       fN = 0;
 }
 
-//______________________________________________________
-
-Double_t AliTRDtrackingSector::GetMaxY(Int_t l) const 
-{ 
-
-  if((l<(fN-1)) && (l>-1)) { 
-    Int_t tb_per_plane = fN/kNplan;
-    Int_t plane = l/tb_per_plane;
-    return fGeom->GetChamberWidth(plane); 
-  }
-  else {
-    fprintf(stderr,
-    "AliTRDtrackingSector::GetMaxY: TimeBin index is out of range !\n");
-    if(l<0) return fGeom->GetChamberWidth(0);
-    else return fGeom->GetChamberWidth(kNplan-1);
-  }
+//_____________________________________________________________________________
+AliTRDtrackingChamber* AliTRDtrackingSector::GetChamber(Int_t stack, Int_t layer, Bool_t build)
+{
+// Return chamber at position (stack, plane) in current 
+// sector or build a new one if it is not already created
+       
+       Int_t ch = stack*AliTRDgeometry::kNlayer + layer;
+       if(fIndex[ch] >= 0) return fChamber[Int_t(fIndex[ch])];
+       else if(!build) return 0x0;
+       
+       // CHAMBER HAS TO BE BUILD
+       Int_t rch = ch;do rch--; while(rch>=0 && fIndex[rch]<0);
+       fIndex[ch] = rch >=0 ? fIndex[rch]+1 : 0; 
+       fN++;
+       
+       memmove(&fChamber[Int_t(fIndex[ch])+1], &fChamber[Int_t(fIndex[ch])], (kNChambersSector-fIndex[ch]-1)*sizeof(void*));
+       for(Int_t ic = ch+1; ic<kNChambersSector; ic++) fIndex[ic] += fIndex[ic] >= 0 ? 1 : 0;
+       
+       return fChamber[Int_t(fIndex[ch])] = new AliTRDtrackingChamber(AliTRDgeometry::GetDetector(layer, stack, fSector));
 }
 
-//______________________________________________________
-
-Int_t AliTRDtrackingSector::GetTimeBinNumber(Double_t x) const
+//_____________________________________________________________________________
+AliTRDtrackingChamber** AliTRDtrackingSector::GetStack(Int_t stack)
 {
-  Float_t r_out = fGeom->GetTime0(kNplan-1) + kDrThick; 
-  Float_t r_in = fGeom->GetTime0(0);
-  //  cerr<<"GetTimeBinNumber: r_in,r_out = "<<r_in<<","<<r_out<<endl;
-
-  if(x >= r_out) return fN-1;
-  if(x <= r_in) return 0;
-
-  Float_t gap = fGeom->GetTime0(1) - fGeom->GetTime0(0);
-  //  cerr<<"GetTimeBinNumber: gap = "<<gap<<endl;
-
-  Int_t plane = Int_t((x - r_in + fTimeBinSize/2)/gap);
-  //  cerr<<"GetTimeBinNumber: plane="<<plane<<endl;
-
-  Int_t local_tb = Int_t((x-fGeom->GetTime0(plane))/fTimeBinSize + 0.5);
-  //  cerr<<"GetTimeBinNumber: local_tb="<<local_tb<<endl;
-
-  Int_t time_bin = plane * (Int_t(kDrThick/fTimeBinSize) + 1) + local_tb;
-  //  cerr<<"GetTimeBinNumber: time_bin = "<<time_bin<<endl;
-  
-
-  return time_bin;
+// Return chamber at position (stack, plane) in current 
+// sector or build a new one if it is not already created
+       
+       if(stack<0 || stack>=AliTRDgeometry::kNstack) return 0x0;
+       
+       Int_t ich, n = 0;
+       for(int il=0; il<AliTRDgeometry::kNlayer; il++){
+               ich = stack*AliTRDgeometry::kNlayer + il;
+               if(fIndex[ich] < 0) fStack[il] = 0x0; 
+               else{
+                       fStack[il] = fChamber[Int_t(fIndex[ich])];
+                       n++;
+               }
+       }
+       
+       return n ? &fStack[0] : 0x0;
 }
 
-//______________________________________________________
-
-Int_t AliTRDtrackingSector::GetTimeBin(Int_t det, Int_t local_tb) const 
+//_____________________________________________________________________________
+void AliTRDtrackingSector::Print(Option_t *)
 {
-  Int_t plane = fGeom->GetPlane(det);
+// Dump info about this tracking sector and the tracking chamber within
+// 
+
+       printf("\tSector %2d\n", fSector);
+       for(int il=0; il<6; il++){
+               for(int is =0; is<5; is++){
+                       Int_t ch = is*AliTRDgeometry::kNlayer + il;
+                       printf("%2d[%2d] ", fIndex[ch], fIndex[ch]>=0 ? fChamber[Int_t(fIndex[ch])]->GetNClusters() : 0);
+               }
+               printf("\n");
+       }
 
-  Int_t time_bin = plane * (Int_t(kDrThick/fTimeBinSize) + 1) + local_tb;  
-  return time_bin;
 }
-