adding support for AliESDEvent in AliESDtrackCuts
[u/mrichter/AliRoot.git] / PWG0 / esdTrackCuts / AliTestESDtrackCutsSelector.cxx
index 211a8725a79c17f9a708bf07f5c5a43b1aefcb1e..f23f8210ba1e41199e61045b422a81f12c6907f7 100644 (file)
@@ -11,6 +11,7 @@
 #include <TChain.h>
 #include <TFile.h>
 #include <TH1F.h>
+#include <TH3F.h>
 
 #include <TSelector.h>
 #include <TFile.h>
@@ -29,8 +30,16 @@ ClassImp(AliTestESDtrackCutsSelector)
 AliTestESDtrackCutsSelector::AliTestESDtrackCutsSelector() :
   AliSelectorRL(),
   fEsdTrackCutsAll(0),
+  fEsdTrackCutsNoVtx(0),
   fEsdTrackCutsPri(0),
-  fEsdTrackCutsSec(0)
+  fEsdTrackCutsSec(0),
+  fEsdTrackCutsPlusZ(0),
+  fEsdTrackCutsMinusZ(0),
+  fEsdTrackCutsPos(0),
+  fEsdTrackCutsNeg(0),
+  fPIDAfterCutNoVtx(0),
+  fPIDAfterCutAll(0),
+  fVertex(0)
 {
   //
   // Constructor. Initialization of pointers
@@ -60,22 +69,28 @@ void AliTestESDtrackCutsSelector::ReadUserObjects(TTree* tree)
 {
   // read the user objects, called from slavebegin and begin
 
+  // only do it once
+  if (fEsdTrackCutsAll)
+    return;
+
   if (!fEsdTrackCutsAll && fInput)
     fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsAll")->Clone());
-  if (!fEsdTrackCutsPri && fInput)
-    fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsPri")->Clone());
-  if (!fEsdTrackCutsSec && fInput)
-    fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsSec")->Clone());
 
   if (!fEsdTrackCutsAll && tree)
     fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsAll"));
-  if (!fEsdTrackCutsPri && tree)
-    fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsPri"));
-  if (!fEsdTrackCutsSec && tree)
-    fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsSec"));
 
-  if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec)
-     AliDebug(AliLog::kError, "ERROR: Could not read esdTrackCutsXXX from input list.");
+  if (!fEsdTrackCutsAll)
+     AliDebug(AliLog::kError, "ERROR: Could not read fEsdTrackCutsAll from input list.");
+
+  fEsdTrackCutsNoVtx =    dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsNoVtx"));
+  fEsdTrackCutsNoVtx->SetRequireSigmaToVertex(kFALSE);
+
+  fEsdTrackCutsPri =    dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPri"));
+  fEsdTrackCutsSec =    dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsSec"));
+  fEsdTrackCutsPlusZ =  dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPlusZ"));
+  fEsdTrackCutsMinusZ = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsMinusZ"));
+  fEsdTrackCutsPos =    dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPos"));
+  fEsdTrackCutsNeg =    dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsNeg"));
 }
 
 void AliTestESDtrackCutsSelector::SlaveBegin(TTree* tree)
@@ -87,6 +102,29 @@ void AliTestESDtrackCutsSelector::SlaveBegin(TTree* tree)
   AliSelectorRL::SlaveBegin(tree);
 
   ReadUserObjects(tree);
+
+  fPIDAfterCutNoVtx = new TH1F("fPIDAfterCutNoVtx", "fPIDAfterCutNoVtx", 5001, -2500.5, 2500.5);
+  fPIDAfterCutAll   = new TH1F("fPIDAfterCutAll", "fPIDAfterCutAll", 5001, -2500.5, 2500.5);
+
+  fVertex = new TH3F("fVertex", "fVertex", 100, -10, 10, 100, -10, 10, 100, -10, 10);
+}
+
+void AliTestESDtrackCutsSelector::Init(TTree* tree)
+{
+  // read the user objects
+
+  AliSelectorRL::Init(tree);
+
+  // Enable only the needed branches
+  if (tree)
+  {
+    tree->SetBranchStatus("*", 0);
+    tree->SetBranchStatus("fTriggerMask", 1);
+    tree->SetBranchStatus("fSPDVertex*", 1);
+    tree->SetBranchStatus("fTracks.fLabel", 1);
+
+    AliESDtrackCuts::EnableNeededBranches(tree);
+  }
 }
 
 Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
@@ -116,7 +154,7 @@ Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
   if (!fESD) {
     AliDebug(AliLog::kError, "ESD branch not available");
     return kFALSE;
-  }  
+  }
 
   if (!AliPWG0Helper::IsVertexReconstructed(fESD)) {
     AliDebug(AliLog::kDebug+5, "Vertex is not reconstructed");
@@ -124,7 +162,7 @@ Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
   }
 
   // check if the esd track cut objects are there
-  if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec) {
+  if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec || !fEsdTrackCutsPlusZ || !fEsdTrackCutsMinusZ || !fEsdTrackCutsPos || !fEsdTrackCutsNeg) {
     AliDebug(AliLog::kError, "fEsdTrackCutsXXX not available");
     return kFALSE;
   }
@@ -147,7 +185,7 @@ Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
 
     AliESDtrack* esdTrack = fESD->GetTrack(t);
 
-    fEsdTrackCutsAll->AcceptTrack(esdTrack);
+    Bool_t passed = fEsdTrackCutsAll->AcceptTrack(esdTrack);
 
     // using the properties of the mc particle
     Int_t label = TMath::Abs(esdTrack->GetLabel());
@@ -164,7 +202,31 @@ Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
     if (label < nPrim)
       fEsdTrackCutsPri->AcceptTrack(esdTrack);
     else
+    {
       fEsdTrackCutsSec->AcceptTrack(esdTrack);
+      if (passed)
+      {
+        fPIDAfterCutAll->Fill(particle->GetPdgCode());
+        fVertex->Fill(particle->Vx(), particle->Vy(), particle->Vz());
+      }
+
+      if (fEsdTrackCutsNoVtx->AcceptTrack(esdTrack))
+        fPIDAfterCutNoVtx->Fill(particle->GetPdgCode());
+    }
+
+    TParticlePDG* pdgPart = particle->GetPDG();
+    if (pdgPart)
+    {
+      if (pdgPart->Charge() > 0)
+        fEsdTrackCutsPos->AcceptTrack(esdTrack);
+      else if (pdgPart->Charge() < 0)
+        fEsdTrackCutsNeg->AcceptTrack(esdTrack);
+    }
+
+    if (particle->Eta() < 0)
+      fEsdTrackCutsPlusZ->AcceptTrack(esdTrack);
+    else
+      fEsdTrackCutsMinusZ->AcceptTrack(esdTrack);
   }
   
   return kTRUE;
@@ -186,8 +248,16 @@ void AliTestESDtrackCutsSelector::SlaveTerminate()
   }
 
   fOutput->Add(fEsdTrackCutsAll);
+  fOutput->Add(fEsdTrackCutsNoVtx);
   fOutput->Add(fEsdTrackCutsPri);
   fOutput->Add(fEsdTrackCutsSec);
+  fOutput->Add(fEsdTrackCutsPlusZ);
+  fOutput->Add(fEsdTrackCutsMinusZ);
+  fOutput->Add(fEsdTrackCutsPos);
+  fOutput->Add(fEsdTrackCutsNeg);
+  fOutput->Add(fPIDAfterCutNoVtx);
+  fOutput->Add(fPIDAfterCutAll);
+  fOutput->Add(fVertex);
 }
 
 void AliTestESDtrackCutsSelector::Terminate()
@@ -198,23 +268,39 @@ void AliTestESDtrackCutsSelector::Terminate()
 
   AliSelectorRL::Terminate();
 
-  if (fOutput)
-    fOutput->Print();
-
   fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsAll"));
-  fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsPri"));
-  fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsSec"));
+  fEsdTrackCutsNoVtx = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsNoVtx"));
+  fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPri"));
+  fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsSec"));
+  fEsdTrackCutsPlusZ = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPlusZ"));
+  fEsdTrackCutsMinusZ = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsMinusZ"));
+  fEsdTrackCutsPos = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPos"));
+  fEsdTrackCutsNeg = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsNeg"));
+  fPIDAfterCutNoVtx = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDAfterCutNoVtx"));
+  fPIDAfterCutAll = dynamic_cast<TH1F*> (fOutput->FindObject("fPIDAfterCutAll"));
+  fVertex = dynamic_cast<TH3F*> (fOutput->FindObject("fVertex"));
 
   // check if the esd track cut objects are there
-  if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec) {
-    AliDebug(AliLog::kError, Form("fEsdTrackCutsXXX not available %p %p %p", fEsdTrackCutsAll, fEsdTrackCutsPri, fEsdTrackCutsSec));
+  if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec || !fEsdTrackCutsPlusZ || !fEsdTrackCutsMinusZ || !fEsdTrackCutsPos || !fEsdTrackCutsNeg) {
+    AliDebug(AliLog::kError, Form("fEsdTrackCutsXXX not available %p %p %p %p %p %p %p", fEsdTrackCutsAll, fEsdTrackCutsPri, fEsdTrackCutsSec, fEsdTrackCutsPlusZ, fEsdTrackCutsMinusZ, fEsdTrackCutsPos, fEsdTrackCutsNeg));
     return;
   }
 
   TFile* file = TFile::Open("trackCuts.root", "RECREATE");
-  fEsdTrackCutsAll->SaveHistograms("esdTrackCutsAll");
-  fEsdTrackCutsPri->SaveHistograms("esdTrackCutsPri");
-  fEsdTrackCutsSec->SaveHistograms("esdTrackCutsSec");
+
+  fEsdTrackCutsAll->SaveHistograms();
+  fEsdTrackCutsNoVtx->SaveHistograms();
+  fEsdTrackCutsPri->SaveHistograms();
+  fEsdTrackCutsSec->SaveHistograms();
+  fEsdTrackCutsPlusZ->SaveHistograms();
+  fEsdTrackCutsMinusZ->SaveHistograms();
+  fEsdTrackCutsPos->SaveHistograms();
+  fEsdTrackCutsNeg->SaveHistograms();
+  fPIDAfterCutNoVtx->Write();
+  fPIDAfterCutAll->Write();
+  fVertex->Write();
 
   file->Close();
+
+       fEsdTrackCutsAll->DrawHistograms();
 }