]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG1/TRD/AliTRDinfoGen.cxx
Fixed compilation
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDinfoGen.cxx
index 940c635f2de11482a20820c469514d81cf018303..5f5603e4d57ae10f2e1ddb243b7006966318cd73 100644 (file)
@@ -35,7 +35,8 @@
 #include <TObjArray.h>
 #include <TObject.h>
 #include <TString.h>
-#include <TH1F.h>
+#include <TH1S.h>
+#include <TPad.h>
 #include <TFile.h>
 #include <TTree.h>
 #include <TROOT.h>
@@ -44,6 +45,7 @@
 
 #include "AliLog.h"
 #include "AliAnalysisManager.h"
+#include "AliCDBManager.h"
 #include "AliESDEvent.h"
 #include "AliMCEvent.h"
 #include "AliESDInputHandler.h"
 #include "AliESDfriendTrack.h"
 #include "AliESDHeader.h"
 #include "AliESDtrack.h"
+#include "AliESDv0.h"
 #include "AliESDtrackCuts.h"
 #include "AliMCParticle.h"
 #include "AliPID.h"
 #include "AliStack.h"
-#include "AliTRDtrackV1.h"
 #include "AliTrackReference.h"
-#include "AliTRDgeometry.h"
-#include "AliTRDcluster.h"
-#include "AliTRDseedV1.h"
 #include "TTreeStream.h"
 
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 
+#include "AliTRDcalibDB.h"
+#include "AliTRDtrackerV1.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDtrackV1.h"
+#include "AliTRDseedV1.h"
+#include "AliTRDcluster.h"
 #include "AliTRDinfoGen.h"
 #include "info/AliTRDtrackInfo.h"
 #include "info/AliTRDeventInfo.h"
@@ -85,9 +90,9 @@ const Float_t AliTRDinfoGen::fgkTRD = 365.;
 const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
 const Int_t   AliTRDinfoGen::fgkEvVertexN = 1;
 
-const Float_t AliTRDinfoGen::fgkTrkDCAxy  = 40.;
-const Float_t AliTRDinfoGen::fgkTrkDCAz   = 15.;
-const Int_t   AliTRDinfoGen::fgkNclTPC    = 100;
+const Float_t AliTRDinfoGen::fgkTrkDCAxy  = 3.;
+const Float_t AliTRDinfoGen::fgkTrkDCAz   = 10.;
+const Int_t   AliTRDinfoGen::fgkNclTPC    = 70;
 const Float_t AliTRDinfoGen::fgkPt        = 0.2;
 const Float_t AliTRDinfoGen::fgkEta       = 0.9;
 
@@ -99,6 +104,8 @@ AliTRDinfoGen::AliTRDinfoGen()
   ,fMCev(NULL)
   ,fEventCut(NULL)
   ,fTrackCut(NULL)
+  ,fV0Cut(NULL)
+  ,fOCDB("local://$ALICE_ROOT/OCDB")
   ,fTrackInfo(NULL)
   ,fEventInfo(NULL)
   ,fV0Info(NULL)
@@ -106,12 +113,13 @@ AliTRDinfoGen::AliTRDinfoGen()
   ,fTracksSA(NULL)
   ,fTracksKink(NULL)
   ,fV0List(NULL)
+  ,fContainer(NULL)
   ,fDebugStream(NULL)
 {
   //
   // Default constructor
   //
-  SetNameTitle("infoGen", "MC-REC TRD-track list generator");
+  SetNameTitle("TRDinfoGen", "MC-REC TRD-track list generator");
 }
 
 //____________________________________________________________________
@@ -122,6 +130,8 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   ,fMCev(NULL)
   ,fEventCut(NULL)
   ,fTrackCut(NULL)
+  ,fV0Cut(NULL)
+  ,fOCDB("local://$ALICE_ROOT/OCDB")
   ,fTrackInfo(NULL)
   ,fEventInfo(NULL)
   ,fV0Info(NULL)
@@ -129,6 +139,7 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   ,fTracksSA(NULL)
   ,fTracksKink(NULL)
   ,fV0List(NULL)
+  ,fContainer(NULL)
   ,fDebugStream(NULL)
 {
   //
@@ -140,6 +151,7 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   DefineOutput(kTracksKink, TObjArray::Class());
   DefineOutput(kEventInfo, AliTRDeventInfo::Class());
   DefineOutput(kV0List, TObjArray::Class());
+  DefineOutput(kMonitor, TObjArray::Class()); // histogram list
 }
 
 //____________________________________________________________________
@@ -149,6 +161,7 @@ AliTRDinfoGen::~AliTRDinfoGen()
   
   if(fDebugStream) delete fDebugStream;
   if(fEvTrigger) delete fEvTrigger;
+  if(fV0Cut) delete fV0Cut;
   if(fTrackCut) delete fTrackCut;
   if(fEventCut) delete fEventCut;
   if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
@@ -167,9 +180,26 @@ AliTRDinfoGen::~AliTRDinfoGen()
     fTracksKink = NULL;
   }
   if(fV0List){ 
-    fV0List->Delete(); delete fV0List;
+    fV0List->Delete(); 
+    delete fV0List;
     fV0List = NULL;
   }
+  if(fContainer){ 
+    fContainer->Delete(); 
+    delete fContainer;
+    fContainer = NULL;
+  }
+}
+
+//____________________________________________________________________
+Bool_t AliTRDinfoGen::GetRefFigure(Int_t)
+{
+  if(!gPad){
+    AliWarning("Please provide a canvas to draw results.");
+    return kFALSE;
+  }
+  fContainer->At(0)->Draw("bar");
+  return kTRUE;
 }
 
 //____________________________________________________________________
@@ -186,6 +216,51 @@ void AliTRDinfoGen::UserCreateOutputObjects()
   fTracksSA = new TObjArray(20); fTracksSA->SetOwner(kTRUE);
   fTracksKink = new TObjArray(20); fTracksKink->SetOwner(kTRUE);
   fV0List = new TObjArray(10); fV0List->SetOwner(kTRUE);
+
+  // define general monitor
+  fContainer = new TObjArray(1); fContainer->SetOwner(kTRUE);
+  TH1 *h=new TH1S("hStat", "Run statistics;Observable;Entries", 12, -0.5, 11.5);
+  TAxis *ax(h->GetXaxis());
+  ax->SetBinLabel( 1, "ESD");
+  ax->SetBinLabel( 2, "MC");
+  ax->SetBinLabel( 3, "V0");
+  ax->SetBinLabel( 4, "TPC");
+  ax->SetBinLabel( 5, "TRDin");
+  ax->SetBinLabel( 6, "TRDout");
+  ax->SetBinLabel( 7, "Barrel");
+  ax->SetBinLabel( 8, "BarrelMC");
+  ax->SetBinLabel( 9, "SA");
+  ax->SetBinLabel(10, "SAMC");
+  ax->SetBinLabel(11, "Kink");
+  ax->SetBinLabel(12, "KinkMC");
+  fContainer->AddAt(h, 0);
+  PostData(kMonitor, fContainer);
+}
+
+//____________________________________________________________________
+Bool_t AliTRDinfoGen::Load(const Char_t *file, const Char_t *dir, const Char_t *name)
+{
+// Load data from performance file
+
+  if(!TFile::Open(file)){
+    AliWarning(Form("Couldn't open file %s.", file));
+    return kFALSE;
+  }
+  if(dir){
+    if(!gFile->cd(dir)){
+      AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
+      return kFALSE;
+    }
+  }
+  TObjArray *o(NULL);
+  const Char_t *tn=(name ? name : GetName());
+  if(!(o = (TObjArray*)gDirectory->Get(tn))){
+    AliWarning(Form("Missing histogram container %s.", tn));
+    return kFALSE;
+  }
+  fContainer = (TObjArray*)o->Clone(GetName());
+  gFile->Close();
+  return kTRUE;
 }
 
 //____________________________________________________________________
@@ -195,12 +270,22 @@ void AliTRDinfoGen::UserExec(Option_t *){
   //
 
   fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
-  fMCev = MCEvent();
-
   if(!fESDev){
     AliError("Failed retrieving ESD event");
     return;
   }
+  if(!IsInitOCDB()){
+    // prepare OCDB access
+    AliCDBManager* ocdb = AliCDBManager::Instance();
+    ocdb->SetDefaultStorage(fOCDB.Data());
+    ocdb->SetRun(fESDev->GetRunNumber());
+    AliTRDtrackerV1::SetNTimeBins(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
+    AliInfo(Form("OCDB :  Loc[%s] Run[%d] TB[%d]", fOCDB.Data(), ocdb->GetRun(), AliTRDtrackerV1::GetNTimeBins()));
+    SetInitOCDB();
+  }
+
+  // link MC if available
+  fMCev = MCEvent();
 
   // event selection : trigger cut
   if(UseLocalEvSelection() && fEvTrigger){ 
@@ -278,7 +363,9 @@ void AliTRDinfoGen::UserExec(Option_t *){
   AliTRDtrackV1 *track = NULL;
   AliTRDseedV1 *tracklet = NULL;
   AliTRDcluster *cl = NULL;
+  // LOOP 0 - over ESD tracks
   for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
+    new(fTrackInfo) AliTRDtrackInfo();
     esdTrack = fESDev->GetTrack(itrk);
     AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
 
@@ -322,9 +409,10 @@ void AliTRDinfoGen::UserExec(Option_t *){
         iref++;
       }
 
-      new(fTrackInfo) AliTRDtrackInfo();
+      fTrackInfo->SetMC();
       fTrackInfo->SetPDG(fPdg);
       fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
+      fTrackInfo->SetLabel(label);
       Int_t jref = iref;//, kref = 0;
       while(jref<nRefs){
         ref = mcParticle->GetTrackReference(jref);
@@ -334,9 +422,6 @@ void AliTRDinfoGen::UserExec(Option_t *){
         jref++;
       }
       AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
-    } else {
-      new (fTrackInfo) AliTRDtrackInfo();
-      fTrackInfo->SetPDG(fPdg);
     }
 
     // copy some relevant info to TRD track info
@@ -353,7 +438,6 @@ void AliTRDinfoGen::UserExec(Option_t *){
         dedx[in++]=esdTrack->GetTRDslice(il, is);
     for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
     fTrackInfo->SetSlices(in, dedx);
-    fTrackInfo->SetLabel(label);
     fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
     // some other Informations which we may wish to store in order to find problematic cases
     fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
@@ -439,13 +523,42 @@ void AliTRDinfoGen::UserExec(Option_t *){
     fTrackInfo->Delete("");
   }
 
-//   AliESDv0 *v0 = NULL;
-//   for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
-//     if(!(v0 = fESD->GetV0(iv0))) continue;
-//     fV0List->Add(new AliTRDv0Info(v0));
-//   }
+  // LOOP 1 - over ESD v0s
+  Bool_t kFOUND(kFALSE);
+  Float_t bField(fESDev->GetMagneticField());
+  AliESDv0 *v0(NULL);
+  for(Int_t iv0(0); iv0<fESDev->GetNumberOfV0s(); iv0++){
+    if(!(v0 = fESDev->GetV0(iv0))) continue;
+
+    // purge V0 irelevant for TRD
+    Int_t jb(0); AliTRDtrackInfo *ti(NULL);
+    for(Int_t ib(0); ib<nBarrel; ib++){ 
+      ti =   (AliTRDtrackInfo*)fTracksBarrel->At(ib);
+      Int_t id(ti->GetTrackId());
+      if(id!=v0->GetPindex() && id!=v0->GetNindex()) continue; 
+      kFOUND=kTRUE; ti->SetV0(); jb=ib+1;
+      break;
+    }
+    if(!kFOUND) continue;
+
+    // register v0
+    if(fV0Cut) new(fV0Info) AliTRDv0Info(*fV0Cut);
+    else new(fV0Info) AliTRDv0Info();
+    fV0Info->SetMagField(bField);
+    fV0Info->SetV0tracks(fESDev->GetTrack(v0->GetPindex()), fESDev->GetTrack(v0->GetNindex()));
+    fV0Info->SetV0Info(v0);
+    // mark the other leg too 
+    for(Int_t ib(jb); ib<nBarrel; ib++){ 
+      ti =   (AliTRDtrackInfo*)fTracksBarrel->At(ib);
+      if(!fV0Info->HasTrack(ti)) continue;
+      ti->SetV0();
+      break;
+    }
+    //fV0Info->Print("a");
+    fV0List->Add(new AliTRDv0Info(*fV0Info)); kFOUND=kFALSE;
+  }
 
-  // Insert also MC tracks which are passing TRD where the track is not reconstructed
+  // LOOP 2 - over MC tracks which are passing TRD where the track is not reconstructed
   if(HasMCdata()){
     AliDebug(10, "Output of the MC track map:");
     for(Int_t itk = 0; itk < nTracksMC;  itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
@@ -458,6 +571,7 @@ void AliTRDinfoGen::UserExec(Option_t *){
       Int_t iref = 0; AliTrackReference *ref = NULL; 
       Int_t nRefsTRD = 0;
       new(fTrackInfo) AliTRDtrackInfo();
+      fTrackInfo->SetMC();
       fTrackInfo->SetPDG(fPdg);
       while(iref<nRefs){ // count TRD TR
         Bool_t kIN(kFALSE);
@@ -501,16 +615,30 @@ void AliTRDinfoGen::UserExec(Option_t *){
     }
     delete[] trackMap;
   }
-  AliDebug(2, Form(
-    "\nEv[%3d] Tracks: ESD[%d] MC[%d]\n"
+  AliDebug(1, Form(
+    "\nEv[%3d] Tracks: ESD[%d] MC[%d] V0[%d]\n"
     "        TPCout[%d] TRDin[%d] TRDout[%d]\n"
     "        Barrel[%3d+%3d=%3d] SA[%2d+%2d=%2d] Kink[%2d+%2d=%2d]"
-    ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC
+    ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC, fV0List->GetEntries()
     , nTPC, nTRDin, nTRDout
     ,nBarrel, nBarrelMC, fTracksBarrel->GetEntries()
     ,nSA, nSAMC, fTracksSA->GetEntries()
     ,nKink, nKinkMC, fTracksKink->GetEntries()
   ));
+  // save track statistics
+  TH1 *h((TH1S*)fContainer->At(0));
+  h->Fill( 0., nTracksESD);
+  h->Fill( 1., nTracksMC);
+  h->Fill( 2., fV0List->GetEntries());
+  h->Fill( 3., nTPC);
+  h->Fill( 4., nTRDin);
+  h->Fill( 5., nTRDout);
+  h->Fill( 6., nBarrel);
+  h->Fill( 7., nBarrelMC);
+  h->Fill( 8., nSA);
+  h->Fill( 9., nSAMC);
+  h->Fill(10., nKink);
+  h->Fill(11., nKinkMC);
 
   PostData(kTracksBarrel, fTracksBarrel);
   PostData(kTracksSA, fTracksSA);
@@ -519,6 +647,15 @@ void AliTRDinfoGen::UserExec(Option_t *){
   PostData(kV0List, fV0List);
 }
 
+//____________________________________________________________________
+void AliTRDinfoGen::SetLocalV0Selection(AliTRDv0Info *v0)
+{
+// Set V0 cuts from outside
+
+  if(!fV0Cut) fV0Cut = new AliTRDv0Info(*v0);
+  else new(fV0Cut) AliTRDv0Info(*v0);
+}
+
 //____________________________________________________________________
 void AliTRDinfoGen::SetTrigger(const Char_t *trigger)
 {
@@ -538,3 +675,4 @@ TTreeSRedirector* AliTRDinfoGen::DebugStream()
 }
 
 
+