]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFtrackerV1.cxx
Merging of the three alignment macros into one
[u/mrichter/AliRoot.git] / TOF / AliTOFtrackerV1.cxx
index 58b01e851083fc8ab4026928982710c8109863a4..a20f6018029bf8dd9eb212f0335eef8b6091d42d 100644 (file)
@@ -15,7 +15,7 @@
 
 //--------------------------------------------------------------------//
 //                                                                    //
-// AliTOFtrackerV1 Class                                                //
+// AliTOFtrackerV1 Class                                              //
 // Task: Perform association of the ESD tracks to TOF Clusters        //
 // and Update ESD track with associated TOF Cluster parameters        //
 //                                                                    //
 #include <TFile.h>
 #include <TH1F.h>
 #include <TH2F.h>
+#include <TSeqCollection.h>
 
-#include "AliAlignObj.h"
 #include "AliESDtrack.h"
 #include "AliESDEvent.h"
 #include "AliLog.h"
 #include "AliTrackPointArray.h"
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
 
-#include "AliTOFcalib.h"
 #include "AliTOFRecoParam.h"
+#include "AliTOFReconstructor.h"
 #include "AliTOFcluster.h"
 #include "AliTOFGeometry.h"
 #include "AliTOFtrackerV1.h"
 #include "AliTOFtrack.h"
-
-#include "AliCDBManager.h"
+#include "AliTOFpidESD.h"
 
 extern TROOT *gROOT;
 
@@ -65,8 +66,8 @@ AliTOFtrackerV1::AliTOFtrackerV1():
   fnbadmatch(0),
   fnunmatch(0),
   fnmatch(0),
-  fTracks(0x0),
-  fSeeds(0x0),
+  fTracks(new TClonesArray("AliTOFtrack")),
+  fSeeds(new TClonesArray("AliESDtrack")),
   fHDigClusMap(0x0),
   fHDigNClus(0x0),
   fHDigClusTime(0x0),
@@ -80,78 +81,8 @@ AliTOFtrackerV1::AliTOFtrackerV1():
   fHRecSigZVsPWin(0x0)
  { 
   //AliTOFtrackerV1 main Ctor
-   
-   // Read the reconstruction parameters from the OCDB
-   AliTOFcalib *calib = new AliTOFcalib();
-   fRecoParam = (AliTOFRecoParam*)calib->ReadRecParFromCDB("TOF/Calib",-1);
-   if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
-   Double_t parPID[2];   
-   parPID[0]=fRecoParam->GetTimeResolution();
-   parPID[1]=fRecoParam->GetTimeNSigma();
-   fPid=new AliTOFpidESD(parPID);
-   InitCheckHists();
-   delete calib;
 
-}
-//_____________________________________________________________________________
-AliTOFtrackerV1::AliTOFtrackerV1(const AliTOFtrackerV1 &t):
-  AliTracker(),
-  fRecoParam(0x0),
-  fPid(0x0),
-  fN(0),
-  fNseeds(0),
-  fNseedsTOF(0),
-  fngoodmatch(0),
-  fnbadmatch(0),
-  fnunmatch(0),
-  fnmatch(0),
-  fTracks(0x0),
-  fSeeds(0x0),
-  fHDigClusMap(0x0),
-  fHDigNClus(0x0),
-  fHDigClusTime(0x0),
-  fHDigClusToT(0x0),
-  fHRecNClus(0x0),
-  fHRecChi2(0x0),
-  fHRecDistZ(0x0),
-  fHRecSigYVsP(0x0),
-  fHRecSigZVsP(0x0),
-  fHRecSigYVsPWin(0x0),
-  fHRecSigZVsPWin(0x0)
- { 
-  //AliTOFtrackerV1 copy Ctor
-
-  fNseeds=t.fNseeds;
-  fNseeds=t.fNseeds;
-  fNseedsTOF=t.fNseedsTOF;
-  fngoodmatch=t.fngoodmatch;
-  fnbadmatch=t.fnbadmatch;
-  fnunmatch=t.fnunmatch;
-  fnmatch=t.fnmatch;
-  fRecoParam=t.fRecoParam;
-  fPid=t.fPid;
-  fSeeds=t.fSeeds;
-  fTracks=t.fTracks;
-  fN=t.fN;
-}
-
-//_____________________________________________________________________________
-AliTOFtrackerV1& AliTOFtrackerV1::operator=(const AliTOFtrackerV1 &t)
-{ 
-  //AliTOFtrackerV1 assignment operator
-
-  this->fNseeds=t.fNseeds;
-  this->fNseedsTOF=t.fNseedsTOF;
-  this->fngoodmatch=t.fngoodmatch;
-  this->fnbadmatch=t.fnbadmatch;
-  this->fnunmatch=t.fnunmatch;
-  this->fnmatch=t.fnmatch;
-  this->fRecoParam = t.fRecoParam;
-  this->fPid = t.fPid;
-  this->fSeeds=t.fSeeds;
-  this->fTracks=t.fTracks;
-  this->fN=t.fN;
-  return *this;
+   InitCheckHists();
 
 }
 //_____________________________________________________________________________
@@ -177,6 +108,16 @@ AliTOFtrackerV1::~AliTOFtrackerV1() {
   delete fHRecSigZVsP;
   delete fHRecSigYVsPWin;
   delete fHRecSigZVsPWin;
+  if (fTracks){
+    fTracks->Delete();
+    delete fTracks;
+    fTracks=0x0;
+  }
+  if (fSeeds){
+    fSeeds->Delete();
+    delete fSeeds;
+    fSeeds=0x0;
+  }
 }
 //_____________________________________________________________________________
 Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent* event) {
@@ -184,6 +125,23 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent* event) {
   // Gets seeds from ESD event and Match with TOF Clusters
   //
 
+  // initialize RecoParam for current event
+
+  AliInfo("Initializing params for TOF... ");
+
+  fRecoParam = AliTOFReconstructor::GetRecoParam();  // instantiate reco param from STEER...
+
+  if (fRecoParam == 0x0) { 
+    AliFatal("No Reco Param found for TOF!!!");
+  }
+  //fRecoParam->Dump();
+  //if(fRecoParam->GetApplyPbPbCuts())fRecoParam=fRecoParam->GetPbPbparam();
+  //fRecoParam->PrintParameters();
+
+  Double_t parPID[2];   
+  parPID[0]=fRecoParam->GetTimeResolution();
+  parPID[1]=fRecoParam->GetTimeNSigma();
+  fPid=new AliTOFpidESD(parPID);
 
   //Initialise some counters
 
@@ -196,7 +154,6 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent* event) {
 
   Int_t ntrk=event->GetNumberOfTracks();
   fNseeds = ntrk;
-  fSeeds= new TClonesArray("AliESDtrack",ntrk);
   TClonesArray &aESDTrack = *fSeeds;
 
 
@@ -261,16 +218,8 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent* event) {
   //Make TOF PID
   fPid->MakePID(event,timeZero);
 
-  if (fSeeds) {
-    fSeeds->Delete();
-    delete fSeeds;
-    fSeeds = 0x0;
-  }
-  if (fTracks) {
-    fTracks->Delete();
-    delete fTracks;
-    fTracks = 0x0;
-  }
+  fSeeds->Clear();
+  fTracks->Clear();
   return 0;
   
 }
@@ -281,14 +230,13 @@ void AliTOFtrackerV1::CollectESD() {
   Int_t seedsTOF1=0;
   Int_t seedsTOF2=0;
  
-  fTracks= new TClonesArray("AliTOFtrack");
   TClonesArray &aTOFTrack = *fTracks;
   for (Int_t i=0; i<fNseeds; i++) {
 
     AliESDtrack *t =(AliESDtrack*)fSeeds->UncheckedAt(i);
     if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
 
-    // TRD 'good' tracks, already propagated at 371 cm
+    // TRD 'good' tracks, already propagated at 372 cm
 
     AliTOFtrack *track = new AliTOFtrack(*t); // New
     Double_t x = track->GetX(); //New
@@ -366,7 +314,7 @@ void AliTOFtrackerV1::MatchTracks( ){
     Double_t cov[15]; trackTOFin->GetExternalCovariance(cov);
 
     Double_t z    = par[1];   
-    Double_t dz   =  scaleFact*3.*TMath::Sqrt(cov[2]+dZ*dZ/12);
+    Double_t dz   =  scaleFact*3.*TMath::Sqrt(cov[2]+dZ*dZ/12.);
     Double_t dphi =  scaleFact*3.*TMath::Sqrt(cov[0]+dY*dY/12.)/sensRadius; 
 
     Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
@@ -384,10 +332,14 @@ void AliTOFtrackerV1::MatchTracks( ){
     Int_t index[kncmax];//to keep track of the cluster index
     for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {  
       AliTOFcluster *c=fClusters[k];
-      if(nc>kncmax)break;
+      //      if(nc>kncmax)break; /* R+ fix (buffer overflow) */
+      if(nc>=kncmax)break; /* R+ fix (buffer overflow protection) */
       if(c->GetZ() > z+dz) break;
       if(c->IsUsed()) continue;      
-      if(!c->GetStatus()) continue; // skip bad channels as declared in OCDB  
+      if(!c->GetStatus()) {
+             AliDebug(1,"Cluster in channel declared bad!");
+             continue; // skip bad channels as declared in OCDB  
+      }
       Float_t xyz[3]; c->GetGlobalXYZ(xyz);
       Double_t clPhi=TMath::ATan2(xyz[1],xyz[0]);
       Double_t dph=TMath::Abs(clPhi-phi);
@@ -398,7 +350,7 @@ void AliTOFtrackerV1::MatchTracks( ){
       nc++;  
     }
 
-    //start propagation: go to the average TOF pad middle plane at ~378.5 cm
+    //start propagation: go to the average TOF pad middle plane at ~379.5 cm
 
     Float_t  xTOF = sensRadius;
     Double_t ymax = xTOF*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
@@ -410,7 +362,7 @@ void AliTOFtrackerV1::MatchTracks( ){
        break;
       }
     } else if (ysect <-ymax) {
-      if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
+      if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
        break;
       }
     }
@@ -422,7 +374,8 @@ void AliTOFtrackerV1::MatchTracks( ){
     AliTOFcluster *bestCluster=0;
     Double_t bestChi2=maxChi2; 
     Int_t idclus=-1;
-    for (Int_t i=0; i<nc; i++){
+    //    for (Int_t i=0; i<nc; i++){ /* R+ fix (unsafe) */
+    for (Int_t i=0; i<nc && i<kncmax; i++){ /* R+ fix (buffer overflow protection) */
       AliTOFcluster *c=clusters[i];  // one of the preselected clusters     
       Double_t chi2=trackTOFin->GetPredictedChi2((AliCluster3D*)c); 
       if (chi2 >= bestChi2) continue;
@@ -438,6 +391,16 @@ void AliTOFtrackerV1::MatchTracks( ){
     }
 
     fnmatch++;
+
+    AliDebug(2, Form("%7i     %7i     %10i     %10i  %10i  %10i      %7i",
+                    iseed,
+                    fnmatch-1,
+                    TMath::Abs(trackTOFin->GetLabel()),
+                    bestCluster->GetLabel(0), 
+                    bestCluster->GetLabel(1), 
+                    bestCluster->GetLabel(2),
+                    idclus)); // AdC
+
     bestCluster->Use(); 
     if (
        (bestCluster->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
@@ -458,6 +421,8 @@ void AliTOFtrackerV1::MatchTracks( ){
     //Propagate the track to the best matched cluster
     trackTOFin->PropagateTo(bestCluster);
 
+    // Fill the track residual histograms.
+    FillResiduals(trackTOFin,bestCluster,kFALSE);
 
     //now take the local distance in Z from the pad center for time walk correction
     Float_t tiltangle = AliTOFGeometry::GetAngles(bestCluster->GetDetInd(1),bestCluster->GetDetInd(2))*TMath::DegToRad();
@@ -534,13 +499,17 @@ Int_t AliTOFtrackerV1::LoadClusters(TTree *cTree) {
     return 1;
   }
 
-  TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
+  static TClonesArray dummy("AliTOFcluster",10000);
+  dummy.Clear();
+  TClonesArray *clusters=&dummy;
   branch->SetAddress(&clusters);
 
   cTree->GetEvent(0);
   Int_t nc=clusters->GetEntriesFast();
   fHDigNClus->Fill(nc);
 
+  AliInfo(Form("Number of clusters: %d",nc));
+
   for (Int_t i=0; i<nc; i++) {
     AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
     fClusters[i]=new AliTOFcluster(*c); fN++;
@@ -691,6 +660,23 @@ void AliTOFtrackerV1::InitCheckHists() {
 
   //Init histos for Digits/Reco QA and Calibration
 
+  TDirectory *dir = gDirectory;
+  TFile *logFileTOF = 0;
+
+  TSeqCollection *list = gROOT->GetListOfFiles();
+  int n = list->GetEntries();
+  Bool_t isThere=kFALSE;
+  for(int i=0; i<n; i++) {
+    logFileTOF = (TFile*)list->At(i);
+    if (strstr(logFileTOF->GetName(), "TOFQA.root")){
+      isThere=kTRUE;
+      break;
+    } 
+  }
+
+  if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
+  logFileTOF->cd(); 
+
   //Digits "QA" 
   fHDigClusMap = new TH2F("TOFDig_ClusMap", "",182,0.5,182.5,864, 0.5,864.5);  
   fHDigNClus = new TH1F("TOFDig_NClus", "",200,0.5,200.5);  
@@ -705,6 +691,9 @@ void AliTOFtrackerV1::InitCheckHists() {
   fHRecSigZVsP=new TH2F("TOFDig_SigZVsP", "",40,0.,4.,100, 0.,5.);
   fHRecSigYVsPWin=new TH2F("TOFDig_SigYVsPWin", "",40,0.,4.,100, 0.,50.);
   fHRecSigZVsPWin=new TH2F("TOFDig_SigZVsPWin", "",40,0.,4.,100, 0.,50.);
+
+  dir->cd();
+
 }
 
 //_________________________________________________________________________
@@ -732,6 +721,10 @@ void AliTOFtrackerV1::SaveCheckHists() {
     } 
   }
    
+  if(!isThere) {
+         AliError(Form("File TOFQA.root not found!! not wring histograms...."));
+         return;
+  }
   logFile->cd();
   fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
   fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
@@ -746,22 +739,8 @@ void AliTOFtrackerV1::SaveCheckHists() {
   fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
   logFile->Flush();  
 
-  if(!isThere)logFileTOF = new TFile( "TOFQA.root","RECREATE");
-  logFileTOF->cd(); 
-  fHDigClusMap->Write(fHDigClusMap->GetName(), TObject::kOverwrite);
-  fHDigNClus->Write(fHDigNClus->GetName(), TObject::kOverwrite);
-  fHDigClusTime->Write(fHDigClusTime->GetName(), TObject::kOverwrite);
-  fHDigClusToT->Write(fHDigClusToT->GetName(), TObject::kOverwrite);
-  fHRecNClus->Write(fHRecNClus->GetName(), TObject::kOverwrite);
-  fHRecChi2->Write(fHRecChi2->GetName(), TObject::kOverwrite);
-  fHRecDistZ->Write(fHRecDistZ->GetName(), TObject::kOverwrite);
-  fHRecSigYVsP->Write(fHRecSigYVsP->GetName(), TObject::kOverwrite);
-  fHRecSigZVsP->Write(fHRecSigZVsP->GetName(), TObject::kOverwrite);
-  fHRecSigYVsPWin->Write(fHRecSigYVsPWin->GetName(), TObject::kOverwrite);
-  fHRecSigZVsPWin->Write(fHRecSigZVsPWin->GetName(), TObject::kOverwrite);
-  logFileTOF->Flush();  
-
   dir->cd();
+
   }
 //_________________________________________________________________________
 Float_t AliTOFtrackerV1::CorrectTimeWalk( Float_t dist, Float_t tof) {
@@ -792,3 +771,17 @@ Float_t AliTOFtrackerV1::GetTimeZerofromTOF(AliESDEvent * /*event*/) const {
   }
   return 0.;
 }
+//_________________________________________________________________________
+
+void AliTOFtrackerV1::FillClusterArray(TObjArray* arr) const
+{
+  //
+  // Returns the TOF cluster array
+  //
+
+  if (fN==0)
+    arr = 0x0;
+  else
+    for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
+
+}