]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliBackgroundSelection.cxx
not write histograms to directory
[u/mrichter/AliRoot.git] / PWG0 / AliBackgroundSelection.cxx
1 #include "AliBackgroundSelection.h"
2 #include "TH2F.h"
3 #include "TList.h"
4 #include "AliLog.h"
5 #include "TString.h"
6 #include "AliESDInputHandlerRP.h"
7 #include "AliAnalysisManager.h"
8 #include "TTree.h"
9 #include "../ITS/AliITSRecPoint.h"
10 #include "AliMultiplicity.h"
11
12 ClassImp(AliBackgroundSelection)
13
14 AliBackgroundSelection::AliBackgroundSelection():
15   AliAnalysisCuts(), fOutputHist(0), fACut(0), fBCut(0)
16 {
17   
18   fOutputHist = new TList();
19   fOutputHist->SetOwner();
20   fACut = 65;
21   fBCut = 4;
22   
23
24 }
25
26 AliBackgroundSelection::AliBackgroundSelection(const char* name, const char* title):
27   AliAnalysisCuts(name,title), fOutputHist(0), fACut(0), fBCut(0)
28 {
29
30   fOutputHist = new TList();
31   fOutputHist->SetOwner();
32   fACut = 65;
33   fBCut = 4;
34 }
35
36 AliBackgroundSelection::AliBackgroundSelection(const AliBackgroundSelection& obj) : AliAnalysisCuts(obj),
37 fOutputHist(0), fACut(0), fBCut(0)
38 {
39
40   fOutputHist = obj.fOutputHist;
41   fACut       = obj.fACut;
42   fBCut       = obj.fBCut;
43
44 }
45
46 AliBackgroundSelection::~AliBackgroundSelection() {
47   if(fOutputHist) delete fOutputHist;
48
49 }
50
51 Bool_t AliBackgroundSelection::IsSelected(TObject* obj){
52
53   // reset fSelected
54   SetSelected(kFALSE);
55   // Get rec points
56   AliESDInputHandlerRP* handlerRP = dynamic_cast<AliESDInputHandlerRP*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
57   if (!handlerRP)
58     AliFatal("Cannot get the AliESDInputHandlerRP");
59
60   TTree* itsClusterTree = handlerRP->GetTreeR("ITS");
61   if (!itsClusterTree){
62     AliError("Cannot get the ITS Cluster tree");
63     return kFALSE;
64   }
65   //    AliFatal("Cannot get the ITS Cluster tree");
66
67   TClonesArray* itsClusters = new TClonesArray("AliITSRecPoint");
68   TBranch* itsClusterBranch=itsClusterTree->GetBranch("ITSRecPoints");
69
70   itsClusterBranch->SetAddress(&itsClusters);
71
72   Int_t nItsSubs = (Int_t)itsClusterTree->GetEntries();
73
74
75   AliESDEvent * esdEv = (AliESDEvent*) obj;
76
77   // Get # spd clusters and of tracklets
78   Int_t spdClusters=0;
79
80
81   // loop over the its subdetectors
82   for (Int_t iIts=0; iIts < nItsSubs; iIts++) {
83
84     if (!itsClusterTree->GetEvent(iIts))
85       continue;
86
87     Int_t nClusters = itsClusters->GetEntriesFast();
88
89     // loop over clusters
90     while (nClusters--) {
91       AliITSRecPoint* cluster = (AliITSRecPoint*) itsClusters->UncheckedAt(nClusters);
92
93       Int_t layer = cluster->GetLayer();
94
95       if (layer < 3) { // SPD
96         spdClusters++;
97       }
98     }
99   }
100
101   const AliMultiplicity* mult = esdEv->GetMultiplicity();
102   if (!mult){
103     AliFatal("No multiplicity object"); // TODO: Should this be fatal?
104   }
105   Int_t ntracklet = mult->GetNumberOfTracklets();
106
107   Float_t limit = fACut + ntracklet * fBCut;
108   
109   if (spdClusters > limit) SetSelected(kFALSE);
110   else                     SetSelected(kTRUE );
111
112
113   // Fill control histos for all trigger classes
114   TString trgClasses = esdEv->GetFiredTriggerClasses();
115   TObjArray * tokens = trgClasses.Tokenize(" ");
116   TIter iter(tokens);
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());
123     if(!hCvsT) {
124       // if histo does not exist, book it on the fly (also books accepted histo)
125       BookClusterVsTrackletsHisto(trg.Data());
126       hCvsT = GetClusterVsTrackletsHisto(trg.Data());
127     }
128     TH2F * hCvsTa = GetClusterVsTrackletsHistoAccepted(trg.Data());
129     hCvsT->Fill(ntracklet,spdClusters);
130     if(Selected()) hCvsTa->Fill(ntracklet,spdClusters);
131
132   }
133   if(tokens) delete tokens;
134   // return decision
135
136   if(itsClusters) delete itsClusters;
137
138   return Selected();
139 }
140
141
142 void   AliBackgroundSelection::Init(){
143
144   fACut = 65;
145   fBCut = 4;
146
147 }
148
149
150 void AliBackgroundSelection::BookClusterVsTrackletsHisto(const char * trigger_name){
151
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)));
156
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");
161
162   fOutputHist->Add(h1);
163   fOutputHist->Add(h2);
164 }
165
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));
169   
170 }
171
172 TH2F * AliBackgroundSelection::GetClusterVsTrackletsHistoAccepted(const char * trigger_name){
173
174   if(!fOutputHist) {AliError("List of histos not initialized");return 0;}
175   return (TH2F*) fOutputHist->FindObject(GetClusterVsTrackletsHistoNameAccepted(trigger_name));
176   
177 }
178
179 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoName(const char * trigger_name){
180     static TString str;
181     str = ("h");
182     str = str+GetName()+"_"+trigger_name;
183     return str.Data();
184 }
185
186 const char * AliBackgroundSelection::GetClusterVsTrackletsHistoNameAccepted(const char * trigger_name){
187     static TString str;
188     str = ("h");
189     str = str+GetName()+"_"+trigger_name + "_accepted";
190     return str.Data();
191 }
192
193 Long64_t AliBackgroundSelection::Merge(TCollection* list)
194 {
195   // Merge a list of AliBackgroundSelection objects with this (needed for
196   // PROOF).
197   // Returns the number of merged objects (including this).
198
199   if (!list)
200     return 0;
201
202   if (list->IsEmpty())
203     return 1;
204
205   TIterator* iter = list->MakeIterator();
206   TObject* obj;
207
208   // collections of all histograms
209   const Int_t nHists = 1;
210   TList collections[nHists];
211
212   Int_t count = 0;
213   while ((obj = iter->Next())) {
214
215     AliBackgroundSelection* entry = dynamic_cast<AliBackgroundSelection*> (obj);
216     if (entry == 0) 
217       continue;
218
219     Int_t n = 0;
220     collections[n++].Add(entry->fOutputHist);
221
222     count++;
223   }
224
225   Int_t n = 0;
226   fOutputHist->Merge(&collections[n++]);
227   
228   delete iter;
229
230   return count+1;
231 }
232
233