]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliBackgroundSelection.cxx
Extending the functionality of the physics selection. Instead of providing a yes...
[u/mrichter/AliRoot.git] / ANALYSIS / AliBackgroundSelection.cxx
index 5fe31c13824f2ff0b51a055075204dbdca1d4768..fc17688c00eee76ff53ac459931fbceb482eef57 100644 (file)
@@ -1,45 +1,68 @@
+// ----------------------------------------------------------------
+// AliBackgroundSelection
+//
+// This class implements to cuts to reject background events from the
+// samples to be used in the physics analysis:
+// 1. A linear cut on the correlation cluster vs tracklets
+// 2. A cut on the delta phi window used by the vertexer Z
+// The parameters used in both cuts can be set
+// 
+// The class also produces control histograms for all and accepted
+// events, for each trigger class present in the data independently.
+// Histograms are booked on the fly in the UserExec, whenever a new
+// trigger class is found.
+//
+// After the first implementation, it was realized that the deltaphi
+// cut is more a quality selection cut than an event selection cut, so
+// it is effectively disabled by default.
+//
+// Author: Michele Floris, CERN
+// ----------------------------------------------------------------
+
+
 #include "AliBackgroundSelection.h"
 #include "TH2F.h"
 #include "TList.h"
-#include "AliLog.h"
 #include "TString.h"
 #include "AliESDInputHandlerRP.h"
 #include "AliAnalysisManager.h"
 #include "TTree.h"
+#include "AliMultiplicity.h"
 #ifdef PASS1RECO
 #include "../ITS/AliITSRecPoint.h"
 #endif
-#include "AliMultiplicity.h"
+
+
 
 ClassImp(AliBackgroundSelection)
 
 AliBackgroundSelection::AliBackgroundSelection():
-  AliAnalysisCuts(), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
+  AliAnalysisCuts(), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(10)
 {
-  
+  // ctor
   fOutputHist = new TList();
   fOutputHist->SetOwner();
   fACut = 65;
   fBCut = 4;
-  fDeltaPhiCut = 0.02;
+  fDeltaPhiCut = 10; // effectively disabling delta phi cut by default
 }
 
 AliBackgroundSelection::AliBackgroundSelection(const char* name, const char* title):
-  AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
+  AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(10)
 {
-
+  // ctor
   fOutputHist = new TList();
   fOutputHist->SetOwner();
   fACut = 65;
   fBCut = 4;
-  fDeltaPhiCut = 0.02;
+  fDeltaPhiCut = 10; //  effectively disabling delta phi cut by default
 
 }
 
 AliBackgroundSelection::AliBackgroundSelection(const AliBackgroundSelection& obj) : AliAnalysisCuts(obj),
 fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
 {
-
+  // copy ctor
   fOutputHist  = obj.fOutputHist;
   fACut        = obj.fACut;
   fBCut        = obj.fBCut;
@@ -47,6 +70,7 @@ fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
 }
 
 AliBackgroundSelection::~AliBackgroundSelection() {
+  // dtor
   if(fOutputHist) {
     delete fOutputHist;
     fOutputHist = 0;
@@ -54,7 +78,10 @@ AliBackgroundSelection::~AliBackgroundSelection() {
 
 }
 
-Bool_t AliBackgroundSelection::IsSelected(TObject* obj){
+Bool_t AliBackgroundSelection::IsSelected(TObject* const obj) 
+{
+  // returns false if the event is identifiead as beam background,
+  // true otherwise.
 
   // reset fSelected
   SetSelected(kFALSE);
@@ -187,6 +214,7 @@ Bool_t AliBackgroundSelection::IsSelected(TObject* obj){
 
 void   AliBackgroundSelection::Init(){
 
+  // Set default cut values
   fACut = 65;
   fBCut = 4;
 
@@ -195,6 +223,8 @@ void   AliBackgroundSelection::Init(){
 
 void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_name){
 
+  // Book control histogram for the cut on the correlation cluster vs tracklets
+
   Bool_t oldStatus = TH1::AddDirectoryStatus();
   TH1::AddDirectory(kFALSE);
 
@@ -217,6 +247,8 @@ void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_na
 
 void AliBackgroundSelection::BookDeltaPhiHisto(const char * trigger_name){
 
+  // Book control histogram for the cut on the DeltaPhi window used by vertexer Z
+
   Bool_t oldStatus = TH1::AddDirectoryStatus();
   TH1::AddDirectory(kFALSE);
 
@@ -236,6 +268,12 @@ void AliBackgroundSelection::BookDeltaPhiHisto(const char * trigger_name){
 }
 
 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHisto(const char * trigger_name){
+
+  // Returns the control histogram corresponding to a given trigger
+  // class. If it does not exist, it creates it and adds it to the
+  // output list
+  // All Events
+
   if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
   TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));  
   if(!h) {
@@ -245,6 +283,12 @@ TH2F * AliBackgroundSelection::GetClusterVsTrackletsHisto(const char * trigger_n
   return h;
 }
 TH1F * AliBackgroundSelection::GetDeltaPhiHisto(const char * trigger_name){
+
+  // Returns the control histogram corresponding to a given trigger
+  // class. If it does not exist, it creates it and adds it to the
+  // output list
+  // All Events
+
   if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
   TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoName(trigger_name));  
   if(!h) {
@@ -256,6 +300,11 @@ TH1F * AliBackgroundSelection::GetDeltaPhiHisto(const char * trigger_name){
 
 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * trigger_name){
 
+  // Returns the control histogram corresponding to a given trigger
+  // class. If it does not exist, it creates it and adds it to the
+  // output list
+  // Events passing the cut only
+
   if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
   TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
   if(!h) {
@@ -268,6 +317,11 @@ TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * t
 
 TH1F * AliBackgroundSelection::GetDeltaPhiHistoAccepted(const char * trigger_name){
 
+  // Returns the control histogram corresponding to a given trigger
+  // class. If it does not exist, it creates it and adds it to the
+  // output list
+  // Events passing the cut only
+
   if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
   TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoNameAccepted(trigger_name));  
   if(!h) {
@@ -279,6 +333,9 @@ TH1F * AliBackgroundSelection::GetDeltaPhiHistoAccepted(const char * trigger_nam
 }
 
 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char * trigger_name){
+
+  // build up the name of the cluster vs tracklets histo using the trigger class
+
     static TString str;
     str = ("hCvsT");
     str = str+GetName()+"_"+trigger_name;
@@ -286,6 +343,8 @@ const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char *
 }
 
 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(const char * trigger_name){
+
+  // build up the name of the cluster vs tracklets histo using the trigger class (accepted events)
     static TString str;
     str = ("hCvsT");
     str = str+GetName()+"_"+trigger_name + "_accepted";
@@ -293,6 +352,10 @@ const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(cons
 }
 
 const char * AliBackgroundSelection::GetDeltaPhiHistoName(const char * trigger_name){
+
+  // build up the name of the delta phi histo using the trigger class
+
+
     static TString str;
     str = ("hDeltaPhi");
     str = str+GetName()+"_"+trigger_name;
@@ -300,13 +363,16 @@ const char * AliBackgroundSelection::GetDeltaPhiHistoName(const char * trigger_n
 }
 
 const char * AliBackgroundSelection::GetDeltaPhiHistoNameAccepted(const char * trigger_name){
+
+  // build up the name of the delta phi histo using the trigger class (accepted events)
+
     static TString str;
     str = ("hDeltaPhi");
     str = str+GetName()+"_"+trigger_name + "_accepted";
     return str.Data();
 }
 
-Long64_t AliBackgroundSelection::Merge(TCollection* list)
+Long64_t AliBackgroundSelection::Merge(TCollection* const list)
 {
   // Merge a list of AliBackgroundSelection objects with this (needed for
   // PROOF).
@@ -316,7 +382,7 @@ Long64_t AliBackgroundSelection::Merge(TCollection* list)
   // the same order. We thus also have to sort the list (sorting is
   // done by name in TList).
 
-  AliInfo("Merging");
+  //AliInfo("Merging");
 
   if (!list)
     return 0;
@@ -334,9 +400,10 @@ Long64_t AliBackgroundSelection::Merge(TCollection* list)
   Int_t count = 0;
   // 1. Sort this list
   fOutputHist->Sort();
-
+  
   while ((obj = iter->Next())) {
-    
+    Bool_t foundDiffinThisIterStep = kFALSE;
+    //    Printf("%d - %s",count, obj->GetName());
     AliBackgroundSelection* entry = dynamic_cast<AliBackgroundSelection*> (obj);
     if (entry == 0) 
       continue;
@@ -348,49 +415,55 @@ Long64_t AliBackgroundSelection::Merge(TCollection* list)
 
     Bool_t areListsDifferent=kTRUE;
     Int_t iloop = 0;
-    Int_t max_loops = hlist->GetSize() + fOutputHist->GetSize(); // In the worst case all of the histos will be different...
+    Int_t maxLoops = hlist->GetSize() + fOutputHist->GetSize(); // In the worst case all of the histos will be different...    
     while(areListsDifferent) {
-      if(iloop>max_loops) AliFatal("Infinite Loop?");
+      if(iloop>maxLoops) AliFatal("Infinite Loop?");
       iloop++;
       // sort
       hlist->Sort();
       fOutputHist->Sort();
+      // loop over the largest 
+
       // loop over the largest 
       TObject * hist =0;
       TIterator * iterlist = 0;
-      if (hlist->GetSize() >= fOutputHist->GetSize()) iterlist = hlist->MakeIterator();
-      else                                            iterlist = fOutputHist->MakeIterator();
-       
+      TList * thislist  = 0; // the list over which I'm iterating (i.e. the largest)
+      TList * otherlist = 0; // the other list
+
+      if (hlist->GetSize() >= fOutputHist->GetSize()) { 
+       thislist  = hlist;
+       otherlist = fOutputHist;
+      }
+      else{
+       thislist  = fOutputHist;
+       otherlist = hlist;      
+      }
+      iterlist = thislist->MakeIterator();
+
       while ((hist= iterlist->Next())){ 
-       // if we missed a trigger type, we missed it for both histo categories
-       // getters automatically book non-existing histos
-       
-       // We have to work out trigger class from name:
-       TString trigger_name = hist->GetName();
-       trigger_name.ReplaceAll("_accepted","");
-       trigger_name = trigger_name(trigger_name.Last('_')+1,trigger_name.Length());
-       
-       if (hlist->GetSize() >= fOutputHist->GetSize()) {
-         GetDeltaPhiHisto(trigger_name.Data());                
-         GetClusterVsTrackletsHisto(trigger_name.Data());
+       if(!otherlist->FindObject(hist->GetName())){
+         //AliInfo(Form("Adding object %s",hist->GetName()));
+         foundDiffinThisIterStep = kTRUE;
+         TH1 * hclone =  (TH1*) hist->Clone();
+         hclone->Reset();
+         otherlist->Add(hclone);
        }
-       else {
-         entry->GetDeltaPhiHisto(trigger_name.Data());
-         entry->GetClusterVsTrackletsHisto(trigger_name.Data());
-       }               
       }
 
+      delete iterlist;
       // re-sort before checking
       hlist->Sort();
       fOutputHist->Sort();
 
       // check if everything is fine    
+      areListsDifferent=kFALSE;
       if (hlist->GetSize() == fOutputHist->GetSize()) {        
        Int_t nhist =  fOutputHist->GetSize();
        for(Int_t ihist = 0; ihist < nhist; ihist++){
-         if(strcmp(fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName())) break;
+         if(strcmp(fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName())) areListsDifferent = kTRUE;
        }
-       areListsDifferent=kFALSE;
+      } else {
+       areListsDifferent=kTRUE;
       }
     }
 
@@ -404,11 +477,25 @@ Long64_t AliBackgroundSelection::Merge(TCollection* list)
        AliFatal(Form("Mismatching histos: %s -> %s", fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName()));
       }
     }
-    
-    Int_t n = 0;
-    collections[n++].Add(hlist);
 
-    count++;
+    if (foundDiffinThisIterStep){
+      iter->Reset(); // We found a difference: previous lists could
+                    // also be affected... We start from scratch
+      Int_t n = 0;
+      collections[n++].Clear();
+      count = 0;
+    }
+    else {
+//       AliInfo("hlist");
+//       hlist->Print();
+//       AliInfo("fOutputHist");
+//       fOutputHist->Print();
+      
+      Int_t n = 0;
+      collections[n++].Add(hlist);
+      
+      count++;
+    }
   }
 
   Int_t n = 0;