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(0)
20 fOutputHist = new TList();
21 fOutputHist->SetOwner();
27 AliBackgroundSelection::AliBackgroundSelection(const char* name, const char* title):
28 AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0), fDeltaPhiCut(0)
31 fOutputHist = new TList();
32 fOutputHist->SetOwner();
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){
63 AliESDInputHandlerRP* handlerRP = dynamic_cast<AliESDInputHandlerRP*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
65 AliFatal("Cannot get the AliESDInputHandlerRP");
67 TTree* itsClusterTree = handlerRP->GetTreeR("ITS");
69 AliError("Cannot get the ITS Cluster tree");
72 // AliFatal("Cannot get the ITS Cluster tree");
74 TClonesArray* itsClusters = new TClonesArray("AliITSRecPoint");
75 TBranch* itsClusterBranch=itsClusterTree->GetBranch("ITSRecPoints");
77 itsClusterBranch->SetAddress(&itsClusters);
79 Int_t nItsSubs = (Int_t)itsClusterTree->GetEntries();
82 AliESDEvent * esdEv = (AliESDEvent*) obj;
85 Float_t deltaPhi = 0.0; // deltaPhi is not available in pass1
87 // Get # spd clusters and of tracklets
91 // loop over the its subdetectors
92 for (Int_t iIts=0; iIts < nItsSubs; iIts++) {
94 if (!itsClusterTree->GetEvent(iIts))
97 Int_t nClusters = itsClusters->GetEntriesFast();
100 while (nClusters--) {
101 AliITSRecPoint* cluster = (AliITSRecPoint*) itsClusters->UncheckedAt(nClusters);
103 Int_t layer = cluster->GetLayer();
105 if (layer < 3) { // SPD
112 const AliMultiplicity* mult = esdEv->GetMultiplicity();
114 AliFatal("No multiplicity object"); // TODO: Should this be fatal?
116 Int_t ntracklet = mult->GetNumberOfTracklets();
119 // get deltaphi if vertexer z
120 Float_t deltaPhi = 0.0;
122 const AliESDVertex * vtxESD = esdEv->GetPrimaryVertexSPD();
124 if (vtxESD->IsFromVertexerZ()) deltaPhi = vtxESD->GetDispersion(); // dispersion contains deltaphi in case of vertexer Z
127 AliWarning("No Vertex");
132 // compute number of spd clusters
133 Float_t spdClusters = 0;
134 for(Int_t ilayer = 0; ilayer < 2; ilayer++){
135 spdClusters += mult->GetNumberOfITSClusters(ilayer);
140 Bool_t isCvsTOk = kFALSE;
141 Bool_t isDeltaPhiOk = kFALSE;
143 Float_t limit = fACut + ntracklet * fBCut;
144 if (spdClusters > limit) isCvsTOk = kFALSE;
145 else isCvsTOk = kTRUE ;
147 if(deltaPhi > fDeltaPhiCut) isDeltaPhiOk = kFALSE;
148 else isDeltaPhiOk = kTRUE ;
150 if (!isCvsTOk || !isDeltaPhiOk) SetSelected(kFALSE);
151 else SetSelected(kTRUE );
153 // Fill control histos for all trigger classes
154 TString trgClasses = esdEv->GetFiredTriggerClasses();
155 TObjArray * tokens = trgClasses.Tokenize(" ");
157 while(TObjString * tok = (TObjString*) iter.Next()){
158 // clean up trigger name
159 TString trg = tok->GetString();
160 trg.Strip(TString::kTrailing, ' ');
161 trg.Strip(TString::kLeading, ' ');
163 // cluster vs tracklets
164 TH2F * hCvsT = GetClusterVsTrackletsHisto(trg.Data());
165 TH2F * hCvsTa = GetClusterVsTrackletsHistoAccepted(trg.Data());
166 hCvsT->Fill(ntracklet,spdClusters);
167 if(isCvsTOk) hCvsTa->Fill(ntracklet,spdClusters);
170 TH1F * hDeltaPhi = GetDeltaPhiHisto(trg.Data());
171 TH1F * hDeltaPhia = GetDeltaPhiHistoAccepted(trg.Data());
172 hDeltaPhi->Fill(deltaPhi);
173 if(isDeltaPhiOk) hDeltaPhia->Fill(deltaPhi);
175 if(tokens) delete tokens;
180 itsClusters->Delete();
188 void AliBackgroundSelection::Init(){
196 void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_name){
198 Bool_t oldStatus = TH1::AddDirectoryStatus();
199 TH1::AddDirectory(kFALSE);
201 TH2F * h1 = new TH2F(GetClusterVsTrackletsHistoName(trigger_name),trigger_name, 50, -0.5, 49.5, 1000, -0.5, 999.5);
202 h1->SetXTitle("Tracklets");
203 h1->SetYTitle("SPD Clusters");
204 AliInfo(Form("Creating histos: %s, all and accepted", GetClusterVsTrackletsHistoName(trigger_name)));
206 TH2F * h2 = new TH2F(GetClusterVsTrackletsHistoNameAccepted(trigger_name),TString(trigger_name)+ "(accepted)",
207 50, -0.5, 49.5, 1000, -0.5, 999.5);
208 h2->SetXTitle("Tracklets");
209 h2->SetYTitle("SPD Clusters");
211 fOutputHist->Add(h1);
212 fOutputHist->Add(h2);
214 TH1::AddDirectory(oldStatus);
218 void AliBackgroundSelection::BookDeltaPhiHisto(const char * trigger_name){
220 Bool_t oldStatus = TH1::AddDirectoryStatus();
221 TH1::AddDirectory(kFALSE);
223 TH1F * h1 = new TH1F(GetDeltaPhiHistoName(trigger_name),trigger_name, 100,0,0.5);
224 h1->SetXTitle("#Delta #phi");
225 AliInfo(Form("Creating histos: %s, all and accepted", GetDeltaPhiHistoName(trigger_name)));
227 TH1F * h2 = new TH1F(GetDeltaPhiHistoNameAccepted(trigger_name),TString(trigger_name)+ "(accepted)", 100,0,0.5);
228 h2->SetXTitle("#Delta #phi");
231 fOutputHist->Add(h1);
232 fOutputHist->Add(h2);
234 TH1::AddDirectory(oldStatus);
238 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHisto(const char * trigger_name){
239 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
240 TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));
242 BookClusterVsTrackletsHisto(trigger_name);
243 h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoName(trigger_name));
247 TH1F * AliBackgroundSelection::GetDeltaPhiHisto(const char * trigger_name){
248 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
249 TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoName(trigger_name));
251 BookDeltaPhiHisto(trigger_name);
252 h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoName(trigger_name));
257 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * trigger_name){
259 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
260 TH2F * h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
262 BookClusterVsTrackletsHisto(trigger_name);
263 h = (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
269 TH1F * AliBackgroundSelection::GetDeltaPhiHistoAccepted(const char * trigger_name){
271 if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
272 TH1F * h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoNameAccepted(trigger_name));
274 BookDeltaPhiHisto(trigger_name);
275 h = (TH1F*) fOutputHist->FindObject(GetDeltaPhiHistoNameAccepted(trigger_name));
281 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char * trigger_name){
284 str = str+GetName()+"_"+trigger_name;
288 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(const char * trigger_name){
291 str = str+GetName()+"_"+trigger_name + "_accepted";
295 const char * AliBackgroundSelection::GetDeltaPhiHistoName(const char * trigger_name){
298 str = str+GetName()+"_"+trigger_name;
302 const char * AliBackgroundSelection::GetDeltaPhiHistoNameAccepted(const char * trigger_name){
305 str = str+GetName()+"_"+trigger_name + "_accepted";
309 Long64_t AliBackgroundSelection::Merge(TCollection* list)
311 // Merge a list of AliBackgroundSelection objects with this (needed for
313 // Returns the number of merged objects (including this).
315 // We have to make sure that all the list contain the same histos in
316 // the same order. We thus also have to sort the list (sorting is
317 // done by name in TList).
325 TIterator* iter = list->MakeIterator();
328 // collections of all histograms
329 const Int_t nHists = 1;
330 TList collections[nHists];
336 while ((obj = iter->Next())) {
338 AliBackgroundSelection* entry = dynamic_cast<AliBackgroundSelection*> (obj);
342 TList * hlist = entry->fOutputHist;
344 // Check if all histos in this fOutputHist are also in the one from entry and viceversa
345 // Use getters to automatically book non defined histos
347 if (hlist->GetSize() > fOutputHist->GetSize()) {
348 AliInfo("Found missing histo in reference");
350 TIterator * iterlist = hlist->MakeIterator();
351 while ((hist= iterlist->Next())){
352 // if we missed a trigger type, we missed it for both histo categories
353 // getters automatically book non-existing histos
355 // We have to work out trigger class from name:
356 TString trigger_name = hist->GetName();
357 trigger_name.ReplaceAll("_accepted","");
358 trigger_name = trigger_name(trigger_name.Last('_')+1,trigger_name.Length());
360 GetDeltaPhiHisto(trigger_name.Data());
361 GetClusterVsTrackletsHisto(trigger_name.Data());
363 // in this case we have to restart from scratch: our "reference" list was missing a histo
369 else if (hlist->GetSize() < fOutputHist->GetSize()) {
370 AliInfo("Found missing histo in entry");
371 TIterator * iterlist = fOutputHist->MakeIterator();
372 while ((hist = iterlist->Next())){
373 // if we missed a trigger type, we missed it for both histo categories
374 // getters automatically book non-existing histos
376 // We have to work out trigger class from name:
377 TString trigger_name = hist->GetName();
378 trigger_name.ReplaceAll("_accepted","");
379 trigger_name = trigger_name(trigger_name.Last('_')+1,trigger_name.Length());
381 entry->GetDeltaPhiHisto(trigger_name.Data());
382 entry->GetClusterVsTrackletsHisto(trigger_name.Data());
391 // check if everything is fine
392 if (hlist->GetSize() != fOutputHist->GetSize()) {
393 AliFatal("Mismatching size!");
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())){
398 AliFatal(Form("Mismatching histos: %s -> %s", fOutputHist->At(ihist)->GetName(),hlist->At(ihist)->GetName()));
403 collections[n++].Add(hlist);
409 fOutputHist->Merge(&collections[n++]);