1 #include "AliBackgroundSelection.h"
6 #include "AliESDInputHandlerRP.h"
7 #include "AliAnalysisManager.h"
9 #include "../ITS/AliITSRecPoint.h"
10 #include "AliMultiplicity.h"
12 ClassImp(AliBackgroundSelection)
14 AliBackgroundSelection::AliBackgroundSelection():
15 AliAnalysisCuts(), fOutputHist(0), fACut(0), fBCut(0)
18 fOutputHist = new TList();
19 fOutputHist->SetOwner();
26 AliBackgroundSelection::AliBackgroundSelection(const char* name, const char* title):
27 AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0)
30 fOutputHist = new TList();
31 fOutputHist->SetOwner();
36 AliBackgroundSelection::AliBackgroundSelection(const AliBackgroundSelection& obj) : AliAnalysisCuts(obj),
37 fOutputHist(0), fACut(0), fBCut(0)
40 fOutputHist = obj.fOutputHist;
46 AliBackgroundSelection::~AliBackgroundSelection() {
47 if(fOutputHist) delete fOutputHist;
51 Bool_t AliBackgroundSelection::IsSelected(TObject* obj){
56 AliESDInputHandlerRP* handlerRP = dynamic_cast<AliESDInputHandlerRP*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
58 AliFatal("Cannot get the AliESDInputHandlerRP");
60 TTree* itsClusterTree = handlerRP->GetTreeR("ITS");
62 AliError("Cannot get the ITS Cluster tree");
65 // AliFatal("Cannot get the ITS Cluster tree");
67 TClonesArray* itsClusters = new TClonesArray("AliITSRecPoint");
68 TBranch* itsClusterBranch=itsClusterTree->GetBranch("ITSRecPoints");
70 itsClusterBranch->SetAddress(&itsClusters);
72 Int_t nItsSubs = (Int_t)itsClusterTree->GetEntries();
75 AliESDEvent * esdEv = (AliESDEvent*) obj;
77 // Get # spd clusters and of tracklets
81 // loop over the its subdetectors
82 for (Int_t iIts=0; iIts < nItsSubs; iIts++) {
84 if (!itsClusterTree->GetEvent(iIts))
87 Int_t nClusters = itsClusters->GetEntriesFast();
91 AliITSRecPoint* cluster = (AliITSRecPoint*) itsClusters->UncheckedAt(nClusters);
93 Int_t layer = cluster->GetLayer();
95 if (layer < 3) { // SPD
101 const AliMultiplicity* mult = esdEv->GetMultiplicity();
103 AliFatal("No multiplicity object"); // TODO: Should this be fatal?
105 Int_t ntracklet = mult->GetNumberOfTracklets();
107 Float_t limit = fACut + ntracklet * fBCut;
109 if (spdClusters > limit) SetSelected(kFALSE);
110 else SetSelected(kTRUE );
113 // Fill control histos for all trigger classes
114 TString trgClasses = esdEv->GetFiredTriggerClasses();
115 TObjArray * tokens = trgClasses.Tokenize(" ");
117 while(TObjString * tok = (TObjString*) iter.Next()){
118 TString trg = tok->GetString();
119 trg.Strip(TString::kTrailing, ' ');
120 trg.Strip(TString::kLeading, ' ');
121 // Printf("TRG: [%s]\n",trg.Data());
122 TH2F * hCvsT = GetClusterVsTrackletsHisto(trg.Data());
124 // if histo does not exist, book it on the fly (also books accepted histo)
125 BookClusterVsTrackletsHisto(trg.Data());
126 hCvsT = GetClusterVsTrackletsHisto(trg.Data());
128 TH2F * hCvsTa = GetClusterVsTrackletsHistoAccepted(trg.Data());
129 hCvsT->Fill(ntracklet,spdClusters);
130 if(Selected()) hCvsTa->Fill(ntracklet,spdClusters);
133 if(tokens) delete tokens;
136 if(itsClusters) delete itsClusters;
142 void AliBackgroundSelection::Init(){
150 void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_name){
152 TH2F * h1 = new TH2F(GetClusterVsTrackletsHistoName(trigger_name),trigger_name, 50, -0.5, 49.5, 1000, -0.5, 999.5);
153 h1->SetXTitle("Tracklets");
154 h1->SetYTitle("SPD Clusters");
155 AliInfo(Form("Creating histos: %s, all and accepted", GetClusterVsTrackletsHistoName(trigger_name)));
157 TH2F * h2 = new TH2F(GetClusterVsTrackletsHistoNameAccepted(trigger_name),TString(trigger_name)+ "(accepted)",
158 50, -0.5, 49.5, 1000, -0.5, 999.5);
159 h2->SetXTitle("Tracklets");
160 h2->SetYTitle("SPD Clusters");
162 fOutputHist->Add(h1);
163 fOutputHist->Add(h2);
166 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHisto(const char * trigger_name){
167 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
168 return (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));
172 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * trigger_name){
174 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
175 return (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
179 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char * trigger_name){
182 str = str+GetName()+"_"+trigger_name;
186 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(const char * trigger_name){
189 str = str+GetName()+"_"+trigger_name + "_accepted";
193 Long64_t AliBackgroundSelection::Merge(TCollection* list)
195 // Merge a list of AliBackgroundSelection objects with this (needed for
197 // Returns the number of merged objects (including this).
205 TIterator* iter = list->MakeIterator();
208 // collections of all histograms
209 const Int_t nHists = 1;
210 TList collections[nHists];
213 while ((obj = iter->Next())) {
215 AliBackgroundSelection* entry = dynamic_cast<AliBackgroundSelection*> (obj);
220 collections[n++].Add(entry->fOutputHist);
226 fOutputHist->Merge(&collections[n++]);