1 #include "AliBackgroundSelection.h"
6 #include "AliESDInputHandlerRP.h"
7 #include "AliAnalysisManager.h"
10 #include "../ITS/AliITSRecPoint.h"
12 #include "AliMultiplicity.h"
14 ClassImp(AliBackgroundSelection)
16 AliBackgroundSelection::AliBackgroundSelection():
17 AliAnalysisCuts(), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(10)
20 fOutputHist = new TList();
21 fOutputHist->SetOwner();
24 fDeltaPhiCut = 10; // effectively disabling delta phi cut by default
27 AliBackgroundSelection::AliBackgroundSelection(const char* name, const char* title):
28 AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(10)
31 fOutputHist = new TList();
32 fOutputHist->SetOwner();
35 fDeltaPhiCut = 10; // effectively disabling delta phi cut by default
39 AliBackgroundSelection::AliBackgroundSelection(const AliBackgroundSelection& obj) : AliAnalysisCuts(obj),
40 fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
43 fOutputHist = obj.fOutputHist;
46 fDeltaPhiCut = obj.fDeltaPhiCut;
49 AliBackgroundSelection::~AliBackgroundSelection() {
57 Bool_t AliBackgroundSelection::IsSelected(TObject* obj)
64 AliESDInputHandlerRP* handlerRP = dynamic_cast<AliESDInputHandlerRP*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
66 AliFatal("Cannot get the AliESDInputHandlerRP");
68 TTree* itsClusterTree = handlerRP->GetTreeR("ITS");
70 AliError("Cannot get the ITS Cluster tree");
73 // AliFatal("Cannot get the ITS Cluster tree");
75 TClonesArray* itsClusters = new TClonesArray("AliITSRecPoint");
76 TBranch* itsClusterBranch=itsClusterTree->GetBranch("ITSRecPoints");
78 itsClusterBranch->SetAddress(&itsClusters);
80 Int_t nItsSubs = (Int_t)itsClusterTree->GetEntries();
83 AliESDEvent * esdEv = (AliESDEvent*) obj;
86 Float_t deltaPhi = 0.0; // deltaPhi is not available in pass1
88 // Get # spd clusters and of tracklets
92 // loop over the its subdetectors
93 for (Int_t iIts=0; iIts < nItsSubs; iIts++) {
95 if (!itsClusterTree->GetEvent(iIts))
98 Int_t nClusters = itsClusters->GetEntriesFast();
100 // loop over clusters
101 while (nClusters--) {
102 AliITSRecPoint* cluster = (AliITSRecPoint*) itsClusters->UncheckedAt(nClusters);
104 Int_t layer = cluster->GetLayer();
106 if (layer < 3) { // SPD
113 const AliMultiplicity* mult = esdEv->GetMultiplicity();
115 AliFatal("No multiplicity object"); // TODO: Should this be fatal?
117 Int_t ntracklet = mult->GetNumberOfTracklets();
120 // get deltaphi if vertexer z
121 Float_t deltaPhi = 0.0;
123 const AliESDVertex * vtxESD = esdEv->GetPrimaryVertexSPD();
125 if (vtxESD->IsFromVertexerZ()) deltaPhi = vtxESD->GetDispersion(); // dispersion contains deltaphi in case of vertexer Z
128 AliWarning("No Vertex");
133 // compute number of spd clusters
134 Float_t spdClusters = 0;
135 for(Int_t ilayer = 0; ilayer < 2; ilayer++){
136 spdClusters += mult->GetNumberOfITSClusters(ilayer);
141 Bool_t isCvsTOk = kFALSE;
142 Bool_t isDeltaPhiOk = kFALSE;
144 Float_t limit = fACut + ntracklet * fBCut;
145 if (spdClusters > limit) isCvsTOk = kFALSE;
146 else isCvsTOk = kTRUE ;
148 if(deltaPhi > fDeltaPhiCut) isDeltaPhiOk = kFALSE;
149 else isDeltaPhiOk = kTRUE ;
151 if (!isCvsTOk || !isDeltaPhiOk) SetSelected(kFALSE);
152 else SetSelected(kTRUE );
154 // Fill control histos for all trigger classes
155 TString trgClasses = esdEv->GetFiredTriggerClasses();
156 TObjArray * tokens = trgClasses.Tokenize(" ");
158 while(TObjString * tok = (TObjString*) iter.Next()){
159 // clean up trigger name
160 TString trg = tok->GetString();
161 trg.Strip(TString::kTrailing, ' ');
162 trg.Strip(TString::kLeading, ' ');
164 // cluster vs tracklets
165 TH2F * hCvsT = GetClusterVsTrackletsHisto(trg.Data());
166 TH2F * hCvsTa = GetClusterVsTrackletsHistoAccepted(trg.Data());
167 hCvsT->Fill(ntracklet,spdClusters);
168 if(isCvsTOk) hCvsTa->Fill(ntracklet,spdClusters);
171 TH1F * hDeltaPhi = GetDeltaPhiHisto(trg.Data());
172 TH1F * hDeltaPhia = GetDeltaPhiHistoAccepted(trg.Data());
173 hDeltaPhi->Fill(deltaPhi);
174 if(isDeltaPhiOk) hDeltaPhia->Fill(deltaPhi);
176 if(tokens) delete tokens;
181 itsClusters->Delete();
189 void AliBackgroundSelection::Init(){
197 void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_name){
199 Bool_t oldStatus = TH1::AddDirectoryStatus();
200 TH1::AddDirectory(kFALSE);
202 TH2F * h1 = new TH2F(GetClusterVsTrackletsHistoName(trigger_name),trigger_name, 50, -0.5, 49.5, 1000, -0.5, 999.5);
203 h1->SetXTitle("Tracklets");
204 h1->SetYTitle("SPD Clusters");
205 AliInfo(Form("Creating histos: %s, all and accepted", GetClusterVsTrackletsHistoName(trigger_name)));
207 TH2F * h2 = new TH2F(GetClusterVsTrackletsHistoNameAccepted(trigger_name),TString(trigger_name)+ "(accepted)",
208 50, -0.5, 49.5, 1000, -0.5, 999.5);
209 h2->SetXTitle("Tracklets");
210 h2->SetYTitle("SPD Clusters");
212 fOutputHist->Add(h1);
213 fOutputHist->Add(h2);
215 TH1::AddDirectory(oldStatus);
219 void AliBackgroundSelection::BookDeltaPhiHisto(const char * trigger_name){
221 Bool_t oldStatus = TH1::AddDirectoryStatus();
222 TH1::AddDirectory(kFALSE);
224 TH1F * h1 = new TH1F(GetDeltaPhiHistoName(trigger_name),trigger_name, 100,0,0.5);
225 h1->SetXTitle("#Delta #phi");
226 AliInfo(Form("Creating histos: %s, all and accepted", GetDeltaPhiHistoName(trigger_name)));
228 TH1F * h2 = new TH1F(GetDeltaPhiHistoNameAccepted(trigger_name),TString(trigger_name)+ "(accepted)", 100,0,0.5);
229 h2->SetXTitle("#Delta #phi");
232 fOutputHist->Add(h1);
233 fOutputHist->Add(h2);
235 TH1::AddDirectory(oldStatus);
239 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHisto(const char * trigger_name){
240 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
241 TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));
243 BookClusterVsTrackletsHisto(trigger_name);
244 h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));
248 TH1F * AliBackgroundSelection::GetDeltaPhiHisto(const char * trigger_name){
249 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
250 TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoName(trigger_name));
252 BookDeltaPhiHisto(trigger_name);
253 h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoName(trigger_name));
258 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * trigger_name){
260 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
261 TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
263 BookClusterVsTrackletsHisto(trigger_name);
264 h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
270 TH1F * AliBackgroundSelection::GetDeltaPhiHistoAccepted(const char * trigger_name){
272 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
273 TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoNameAccepted(trigger_name));
275 BookDeltaPhiHisto(trigger_name);
276 h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoNameAccepted(trigger_name));
282 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char * trigger_name){
285 str = str+GetName()+"_"+trigger_name;
289 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(const char * trigger_name){
292 str = str+GetName()+"_"+trigger_name + "_accepted";
296 const char * AliBackgroundSelection::GetDeltaPhiHistoName(const char * trigger_name){
299 str = str+GetName()+"_"+trigger_name;
303 const char * AliBackgroundSelection::GetDeltaPhiHistoNameAccepted(const char * trigger_name){
306 str = str+GetName()+"_"+trigger_name + "_accepted";
310 Long64_t AliBackgroundSelection::Merge(TCollection* list)
312 // Merge a list of AliBackgroundSelection objects with this (needed for
314 // Returns the number of merged objects (including this).
316 // We have to make sure that all the list contain the same histos in
317 // the same order. We thus also have to sort the list (sorting is
318 // done by name in TList).
328 TIterator* iter = list->MakeIterator();
331 // collections of all histograms
332 const Int_t nHists = 1;
333 TList collections[nHists];
339 while ((obj = iter->Next())) {
340 Bool_t foundDiffinThisIterStep = kFALSE;
341 // Printf("%d - %s",count, obj->GetName());
342 AliBackgroundSelection* entry = dynamic_cast<AliBackgroundSelection*> (obj);
346 TList * hlist = entry->fOutputHist;
348 // Check if all histos in this fOutputHist are also in the one from entry and viceversa
349 // Use getters to automatically book non defined histos
351 Bool_t areListsDifferent=kTRUE;
353 Int_t max_loops = hlist->GetSize() + fOutputHist->GetSize(); // In the worst case all of the histos will be different...
354 while(areListsDifferent) {
355 if(iloop>max_loops) AliFatal("Infinite Loop?");
360 // loop over the largest
362 // loop over the largest
364 TIterator * iterlist = 0;
365 TList * thislist = 0; // the list over which I'm iterating (i.e. the largest)
366 TList * otherlist = 0; // the other list
368 if (hlist->GetSize() >= fOutputHist->GetSize()) {
370 otherlist = fOutputHist;
373 thislist = fOutputHist;
376 iterlist = thislist->MakeIterator();
378 while ((hist= iterlist->Next())){
379 if(!otherlist->FindObject(hist->GetName())){
380 AliInfo(Form("Adding object %s",hist->GetName()));
381 foundDiffinThisIterStep = kTRUE;
382 TH1 * hclone = (TH1*) hist->Clone();
384 otherlist->Add(hclone);
388 // re-sort before checking
392 // check if everything is fine
393 areListsDifferent=kFALSE;
394 if (hlist->GetSize() == fOutputHist->GetSize()) {
395 Int_t nhist = fOutputHist->GetSize();
396 for(Int_t ihist = 0; ihist < nhist; ihist++){
397 if(strcmp(fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName())) areListsDifferent = kTRUE;
400 areListsDifferent=kTRUE;
404 // last check: if something is not ok die loudly
405 if (hlist->GetSize() != fOutputHist->GetSize()) {
406 AliFatal("Mismatching size!");
408 Int_t nhist = fOutputHist->GetSize();
409 for(Int_t ihist = 0; ihist < nhist; ihist++){
410 if(strcmp(fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName())){
411 AliFatal(Form("Mismatching histos: %s -> %s", fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName()));
415 if (foundDiffinThisIterStep){
416 iter->Reset(); // We found a difference: previous lists could
417 // also be affected... We start from scratch
419 collections[n++].Clear();
425 // AliInfo("fOutputHist");
426 // fOutputHist->Print();
429 collections[n++].Add(hlist);
436 fOutputHist->Merge(&collections[n++]);