Added Add method to the various correction classes and update AliSystematicSelection.
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaSystematicsSelector.cxx
index da6bfcc..e00075f 100644 (file)
 #include <TH2F.h>
 #include <TH1F.h>
 #include <TParticle.h>
+#include <TParticlePDG.h>
 
 #include <AliLog.h>
 #include <AliESD.h>
 #include <AliStack.h>
 #include <AliHeader.h>
 #include <AliGenEventHeader.h>
-#include <AliGenPythiaEventHeader.h>
-#include <AliGenCocktailEventHeader.h>
-
+#include <../PYTHIA6/AliGenPythiaEventHeader.h>
+#include <../EVGEN/AliGenCocktailEventHeader.h>
 
 #include "esdTrackCuts/AliESDtrackCuts.h"
 #include "AliPWG0Helper.h"
+#include "AliPWG0depHelper.h"
 #include "dNdEta/AlidNdEtaCorrection.h"
 
 ClassImp(AlidNdEtaSystematicsSelector)
@@ -33,7 +34,9 @@ AlidNdEtaSystematicsSelector::AlidNdEtaSystematicsSelector() :
   fSigmaVertex(0),
   fEsdTrackCuts(0),
   fPIDParticles(0),
-  fPIDTracks(0)
+  fPIDTracks(0),
+  fSignMode(0),
+  fMultiplicityMode(0)
 {
   //
   // Constructor. Initialization of pointers
@@ -42,9 +45,10 @@ AlidNdEtaSystematicsSelector::AlidNdEtaSystematicsSelector() :
   for (Int_t i=0; i<4; ++i)
     fdNdEtaCorrectionSpecies[i] = 0;
 
-  for (Int_t i=0; i<3; ++i)
+  for (Int_t i=0; i<3; ++i) {
     fdNdEtaCorrectionVertexReco[i] = 0;
-
+    fdNdEtaCorrectionTriggerBias[i] = 0;
+  }
 }
 
 AlidNdEtaSystematicsSelector::~AlidNdEtaSystematicsSelector()
@@ -126,8 +130,36 @@ void AlidNdEtaSystematicsSelector::SlaveBegin(TTree* tree)
     fdNdEtaCorrectionVertexReco[2] = new AlidNdEtaCorrection("vertexRecoDD", "vertexRecoDD");
   }
 
+  if (option.Contains("triggerbias")) {
+    fdNdEtaCorrectionTriggerBias[0] = new AlidNdEtaCorrection("triggerBiasND", "triggerBiasND");
+    fdNdEtaCorrectionTriggerBias[1] = new AlidNdEtaCorrection("triggerBiasSD", "triggerBiasSD");
+    fdNdEtaCorrectionTriggerBias[2] = new AlidNdEtaCorrection("triggerBiasDD", "triggerBiasDD");
+  }
+
   fPIDParticles = new TH1F("pid_particles", "PID of generated primary particles", 10001, -5000.5, 5000.5);
   fPIDTracks = new TH1F("pid_tracks", "MC PID of reconstructed tracks", 10001, -5000.5, 5000.5);
+
+  if (option.Contains("only-positive"))
+  {
+    AliInfo("Processing only positive particles.");
+    fSignMode = 1;
+  }
+  else if (option.Contains("only-negative"))
+  {
+    AliInfo("Processing only negative particles.");
+    fSignMode = -1;
+  }
+
+  if (option.Contains("low-multiplicity"))
+  {
+    AliInfo("Processing only events with low multiplicity.");
+    fMultiplicityMode = 1;
+  }
+  else if (option.Contains("high-multiplicity"))
+  {
+    AliInfo("Processing only events with high multiplicity.");
+    fMultiplicityMode = 2;
+  }
 }
 
 Bool_t AlidNdEtaSystematicsSelector::Process(Long64_t entry)
@@ -173,117 +205,78 @@ Bool_t AlidNdEtaSystematicsSelector::Process(Long64_t entry)
     return kFALSE;
   }
 
-  TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
-
-  if (fdNdEtaCorrectionSpecies[0])
-    FillCorrectionMaps(list);
-
-  if (fSecondaries)
-    FillSecondaries();
-
-  if (fSigmaVertex)
-    FillSigmaVertex();
-
+  // --------------------------------------------------------------
+  // related to events:
+  //
   // stuff for vertex reconstruction correction systematics
-  if (fdNdEtaCorrectionVertexReco[0]) {
-    AliHeader* header = GetHeader();
-    if (!header) {
-      AliDebug(AliLog::kError, "Header not available");
-      return kFALSE;
-    }
+  Bool_t vertexRecoStudy  = kFALSE;
+  Bool_t triggerBiasStudy = kFALSE;
+  if (fdNdEtaCorrectionVertexReco[0])  vertexRecoStudy = kTRUE;
+  if (fdNdEtaCorrectionTriggerBias[0]) triggerBiasStudy = kTRUE;
 
-    // is there a smart way to check if it is really a pythia header?
-    AliGenCocktailEventHeader* genHeaders = dynamic_cast<AliGenCocktailEventHeader*>(header->GenEventHeader());
-    if (!genHeaders)
-      return kTRUE;
-
-    TList* headerList = genHeaders->GetHeaders();
-    if (!headerList)
-      return kTRUE;
-    
-    AliGenPythiaEventHeader* genHeader = 0;
-    for (Int_t i=0; i<headerList->GetEntries(); i++) {
-      genHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
-      if (genHeader)
-       break;
-    }        
-    if (!genHeader)
-      return kTRUE;
+  AliHeader* header = GetHeader();
+  if (!header) {
+    AliDebug(AliLog::kError, "Header not available");
+    return kFALSE;
+  }
+  
+  // getting process information NB: this only works for Pythia !!!
+  Int_t processtype = AliPWG0depHelper::GetPythiaEventProcessType(header);
     
-    Int_t processtype = genHeader->ProcessType();      
-
-    // get the MC vertex
-    TArrayF vtxMC(3);
-    genHeader->PrimaryVertex(vtxMC);
-
-    Int_t nGoodTracks = list->GetEntries();
-
-    Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
-    Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
-
-    // genHeader->Print();
-    // printf("  heps %d %d %d %f \n", eventTriggered, vertexReconstructed, processtype, vtxMC[2]);
-
-    // non diffractive
-    if (processtype!=92 && processtype!=93 && processtype!=94) { 
-      fdNdEtaCorrectionVertexReco[0]->FillEvent(vtxMC[2], nGoodTracks);
-      if (eventTriggered) {
-       fdNdEtaCorrectionVertexReco[0]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
-       if (vertexReconstructed)
-         fdNdEtaCorrectionVertexReco[0]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
-      }
-    }
-
-    // single diffractive
-    if (processtype==92 || processtype==93) { 
-      fdNdEtaCorrectionVertexReco[1]->FillEvent(vtxMC[2], nGoodTracks);
-      if (eventTriggered) {
-       fdNdEtaCorrectionVertexReco[1]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
-       if (vertexReconstructed)
-         fdNdEtaCorrectionVertexReco[1]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
-      }
-    }
-
-    // double diffractive
-    if (processtype==94) { 
-      fdNdEtaCorrectionVertexReco[2]->FillEvent(vtxMC[2], nGoodTracks);
-      if (eventTriggered) {
-       fdNdEtaCorrectionVertexReco[2]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
-       if (vertexReconstructed)
-         fdNdEtaCorrectionVertexReco[2]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
-      }
-    }
+  // can only read pythia headers, either directly or from cocktalil header
+  AliGenEventHeader* genHeader = (AliGenEventHeader*)(header->GenEventHeader());
+  
+  if (!genHeader) {
+    AliDebug(AliLog::kError, "Gen header not available");
+    return kFALSE;
   }
-
-  delete list;
-  list = 0;
-
-  return kTRUE;
-}
-
-void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
-{
-  // fills the correction maps for different particle species
-
-  AliStack* stack = GetStack();
-  AliHeader* header = GetHeader();
-
-  Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
-  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD);
-
+  
   // get the MC vertex
-  AliGenEventHeader* genHeader = header->GenEventHeader();
-
   TArrayF vtxMC(3);
   genHeader->PrimaryVertex(vtxMC);
+  
+  TObjArray* listOfTracks    = fEsdTrackCuts->GetAcceptedTracks(fESD);
+  Int_t nGoodTracks          = listOfTracks->GetEntries();
+  
+  Bool_t eventTriggered      = AliPWG0Helper::IsEventTriggered(fESD);
+  Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD);
+  
+  // non diffractive
+  if (processtype!=92 && processtype!=93 && processtype!=94) { 
+    // NB: passing the wrong process type here (1), since the process type is defined by the index in the array (here non-diffractive)
+    if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[0]->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);      
+    if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[0] ->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);
+  }
+  
+  // single diffractive
+  if (processtype==92 || processtype==93) { 
+    if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[1]->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);     
+    if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[1] ->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);
+  }
+  
+  // double diffractive
+  if (processtype==94) { 
+    if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[2]->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);     
+    if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[2] ->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);
+  }
+
+  if (eventTriggered & vertexReconstructed) {
+    for (Int_t i=0; i<4; ++i) {
+      if (fdNdEtaCorrectionSpecies[i])
+       fdNdEtaCorrectionSpecies[i]->FillEvent(vtxMC[2], nGoodTracks, eventTriggered, vertexReconstructed, 1);
+    }
+  }
+
+  // --------------------------------------------------------------
+  // MC particle loop
+  //
 
-  // loop over mc particles
   Int_t nPrim  = stack->GetNprimary();
 
   for (Int_t iMc = 0; iMc < nPrim; ++iMc)
   {
     TParticle* particle = stack->Particle(iMc);
-
+    
     if (!particle)
     {
       AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
@@ -292,13 +285,16 @@ void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
 
     if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
       continue;
-
+    
+    if (SignOK(particle->GetPDG()) == kFALSE)
+      continue;
+    
     Float_t eta = particle->Eta();
     Float_t pt = particle->Pt();
-
+    
     Int_t id = -1;
     switch (TMath::Abs(particle->GetPdgCode()))
-    {
+      {
       case 211: id = 0; break;
       case 321: id = 1; break;
       case 2212: id = 2; break;
@@ -317,18 +313,45 @@ void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
       default: id = 3; break;
     }
 
-    if (vertexReconstructed)
-    {
-      fdNdEtaCorrectionSpecies[id]->FillParticle(vtxMC[2], eta, pt);
+    if (eventTriggered & vertexReconstructed) {
+      if (fdNdEtaCorrectionSpecies[id])
+       fdNdEtaCorrectionSpecies[id]->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
       //if (pt < 0.1)
-        fPIDParticles->Fill(particle->GetPdgCode());
+      if (fPIDParticles)
+       fPIDParticles->Fill(particle->GetPdgCode());
+    }
+    
+    // non diffractive
+    if (processtype!=92 && processtype!=93 && processtype!=94) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[0]->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[0] ->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
+    }
+    // single diffractive
+    if (processtype==92 || processtype==93) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[1]->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[1] ->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
+    }
+    // double diffractive
+    if (processtype==94) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[2]->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[2] ->FillMCParticle(vtxMC[2], eta, pt, eventTriggered, vertexReconstructed, 1);
     }
 
-    fdNdEtaCorrectionSpecies[id]->FillParticleAllEvents(eta, pt);
-    if (eventTriggered)
-      fdNdEtaCorrectionSpecies[id]->FillParticleWhenEventTriggered(eta, pt);
   }// end of mc particle
 
+
+  // --------------------------------------------------------------
+  // ESD track loop
+  //
+
+  if (fMultiplicityMode == 1 && listOfTracks->GetEntries() > 20 ||
+      fMultiplicityMode == 2 && listOfTracks->GetEntries() < 40)
+  {
+    delete listOfTracks;
+    listOfTracks = 0;
+    return kTRUE;
+  }
+
   // loop over esd tracks
   TIterator* iter = listOfTracks->MakeIterator();
   TObject* obj = 0;
@@ -338,6 +361,28 @@ void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
     if (!esdTrack)
       continue;
 
+    Float_t eta = particle->Eta();
+    Float_t pt  = particle->Pt();
+    
+    // non diffractive
+    if (processtype!=92 && processtype!=93 && processtype!=94) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[0]->FillTrackedParticle(vtxMC[2], eta, pt);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[0] ->FillTrackedParticle(vtxMC[2], eta, pt);
+    }
+    
+    // single diffractive
+    if (processtype==92 || processtype==93) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[1]->FillTrackedParticle(vtxMC[2], eta, pt);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[1] ->FillTrackedParticle(vtxMC[2], eta, pt);
+    }
+
+    // double diffractive
+    if (processtype==94) { 
+      if (triggerBiasStudy) fdNdEtaCorrectionTriggerBias[2]->FillTrackedParticle(vtxMC[2], eta, pt);
+      if (vertexRecoStudy)  fdNdEtaCorrectionVertexReco[2] ->FillTrackedParticle(vtxMC[2], eta, pt);
+    }
+    
+
     // using the properties of the mc particle
     Int_t label = TMath::Abs(esdTrack->GetLabel());
     TParticle* particle = stack->Particle(label);
@@ -373,6 +418,9 @@ void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
     if (!mother)
       continue;
 
+    if (SignOK(mother->GetPDG()) == kFALSE)
+      continue;
+
     //printf("We continue with particle %d (pdg %d)\n", label, mother->GetPdgCode());
 
     Int_t id = -1;
@@ -384,35 +432,36 @@ void AlidNdEtaSystematicsSelector::FillCorrectionMaps(TObjArray* listOfTracks)
       default:   id = 3; break;
     }
 
-    if (vertexReconstructed)
-    {
-      fdNdEtaCorrectionSpecies[id]->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt());
-      //if (particle->Pt() < 0.1)
-        fPIDTracks->Fill(particle->GetPdgCode());
+    if (vertexReconstructed && eventTriggered) {
+      if (fdNdEtaCorrectionSpecies[id])
+       fdNdEtaCorrectionSpecies[id]->FillTrackedParticle(vtxMC[2], eta, pt);
+      //if (pt < 0.1)
+      if (fPIDTracks)
+       fPIDTracks->Fill(particle->GetPdgCode());
     }
   } // end of track loop
 
-  Int_t nGoodTracks = listOfTracks->GetEntries();
-
-  for (Int_t i=0; i<4; ++i)
-  {
-    fdNdEtaCorrectionSpecies[i]->FillEvent(vtxMC[2], nGoodTracks);
-    if (eventTriggered)
-    {
-      fdNdEtaCorrectionSpecies[i]->FillEventWithTrigger(vtxMC[2], nGoodTracks);
-      if (vertexReconstructed)
-        fdNdEtaCorrectionSpecies[i]->FillEventWithTriggerWithReconstructedVertex(vtxMC[2], nGoodTracks);
-    }
-  }
-
+  
   delete iter;
   iter = 0;
+
+  if (fSecondaries)
+    FillSecondaries();
+
+  if (fSigmaVertex)
+    FillSigmaVertex();
+
+
+  delete listOfTracks;
+  listOfTracks = 0;
+
+  return kTRUE;
 }
 
 void AlidNdEtaSystematicsSelector::FillSecondaries()
 {
   // fills the secondary histograms
-
+  
   AliStack* stack = GetStack();
 
   Int_t particlesPrimaries = 0;
@@ -568,10 +617,14 @@ void AlidNdEtaSystematicsSelector::SlaveTerminate()
   if (fSigmaVertex)
     fOutput->Add(fSigmaVertex);
 
-  for (Int_t i=0; i<3; ++i)
+  for (Int_t i=0; i<3; ++i) {
     if (fdNdEtaCorrectionVertexReco[i])
       fOutput->Add(fdNdEtaCorrectionVertexReco[i]);
-
+    
+    if (fdNdEtaCorrectionTriggerBias[i])
+      fOutput->Add(fdNdEtaCorrectionTriggerBias[i]);
+  }
+  
 }
 
 void AlidNdEtaSystematicsSelector::Terminate()
@@ -587,6 +640,14 @@ void AlidNdEtaSystematicsSelector::Terminate()
     fdNdEtaCorrectionSpecies[i] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject(Form("correction_%d", i)));
   fSigmaVertex = dynamic_cast<TH1F*> (fOutput->FindObject("fSigmaVertex"));
 
+  fdNdEtaCorrectionVertexReco[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("vertexRecoND"));
+  fdNdEtaCorrectionVertexReco[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("vertexRecoSD"));
+  fdNdEtaCorrectionVertexReco[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("vertexRecoDD"));
+
+  fdNdEtaCorrectionTriggerBias[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("triggerBiasND"));
+  fdNdEtaCorrectionTriggerBias[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("triggerBiasSD"));
+  fdNdEtaCorrectionTriggerBias[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("triggerBiasDD"));
+
   if (fPIDParticles)
   {
     TDatabasePDG* pdgDB = new TDatabasePDG;
@@ -604,9 +665,13 @@ void AlidNdEtaSystematicsSelector::Terminate()
     pdgDB = 0;
   }
 
-  for (Int_t i=0; i<3; ++i)
+  for (Int_t i=0; i<3; ++i) {
     if (fdNdEtaCorrectionVertexReco[i])
       fdNdEtaCorrectionVertexReco[i]->Finish();
+    
+    if (fdNdEtaCorrectionTriggerBias[i])
+      fdNdEtaCorrectionTriggerBias[i]->Finish();
+  }
 
   TFile* fout = TFile::Open("systematics.root", "RECREATE");
 
@@ -618,15 +683,19 @@ void AlidNdEtaSystematicsSelector::Terminate()
 
   if (fSigmaVertex)
     fSigmaVertex->Write();
-
+  
   for (Int_t i=0; i<4; ++i)
     if (fdNdEtaCorrectionSpecies[i])
       fdNdEtaCorrectionSpecies[i]->SaveHistograms();
 
-  for (Int_t i=0; i<3; ++i)
+  for (Int_t i=0; i<3; ++i) {
     if (fdNdEtaCorrectionVertexReco[i])
       fdNdEtaCorrectionVertexReco[i]->SaveHistograms();
 
+    if (fdNdEtaCorrectionTriggerBias[i])
+      fdNdEtaCorrectionTriggerBias[i]->SaveHistograms();
+  }
+
   fout->Write();
   fout->Close();
 
@@ -642,3 +711,32 @@ void AlidNdEtaSystematicsSelector::Terminate()
     fSigmaVertex->Draw();
   }
 }
+
+Bool_t AlidNdEtaSystematicsSelector::SignOK(TParticlePDG* particle)
+{
+  // returns if a particle with this sign should be counted
+  // this is determined by the value of fSignMode, which should have the same sign
+  // as the charge
+  // if fSignMode is 0 all particles are counted
+
+  if (fSignMode == 0)
+    return kTRUE;
+
+  if (!particle)
+  {
+    printf("WARNING: not counting a particle that does not have a pdg particle\n");
+    return kFALSE;
+  }
+
+  Double_t charge = particle->Charge();
+
+  if (fSignMode > 0)
+    if (charge < 0)
+      return kFALSE;
+
+  if (fSignMode < 0)
+    if (charge > 0)
+      return kFALSE;
+
+  return kTRUE;
+}