1 // -------------------------------------------------------------------------
2 // Object managing event cuts, and holding QA histograms.
3 // -------------------------------------------------------------------------
4 // Author: Misha Veldhoen (misha.veldhoen@cern.ch)
12 #include "TIterator.h"
13 #include "AliAODEvent.h"
14 #include "AliAODHeader.h"
15 #include "AliAODVertex.h"
16 #include "AliCentrality.h"
17 #include "AliAnalysisManager.h"
18 #include "AliInputEventHandler.h"
19 #include "AliAODEventCutsDiHadronPID.h"
23 ClassImp(AliAODEventCutsDiHadronPID);
25 // -------------------------------------------------------------------------
26 AliAODEventCutsDiHadronPID::AliAODEventCutsDiHadronPID():
30 fTrigger(AliVEvent::kMB),
33 fCentralityEstimator("V0M"),
37 fTestCentrality(kFALSE),
39 fTestMinRefMult(kFALSE),
40 fSelectedEventQAHistos(0x0),
41 fAllEventQAHistos(0x0),
43 fHistRefMultiplicity(0x0),
45 fHistCentralityQuality(0x0),
52 // Default Constructor
55 cout<<"AliAODEventCutsDiHadronPID Default Constructor Called."<<endl;
56 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
60 // -------------------------------------------------------------------------
61 AliAODEventCutsDiHadronPID::AliAODEventCutsDiHadronPID(const char* name):
62 TNamed(name,"AOD Event Cuts"),
65 fTrigger(AliVEvent::kMB),
68 fCentralityEstimator("V0M"),
72 fTestCentrality(kFALSE),
74 fTestMinRefMult(kFALSE),
75 fSelectedEventQAHistos(0x0),
76 fAllEventQAHistos(0x0),
78 fHistRefMultiplicity(0x0),
80 fHistCentralityQuality(0x0),
90 cout<<"AliAODEventCutsDiHadronPID Named Constructor Called."<<endl;
91 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
95 // -------------------------------------------------------------------------
96 AliAODEventCutsDiHadronPID::~AliAODEventCutsDiHadronPID() {
102 cout<<"AliAODEventCutsDiHadronPID Destructor Called."<<endl;
103 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
105 if (fSelectedEventQAHistos) delete fSelectedEventQAHistos;
106 fSelectedEventQAHistos = 0x0;
107 if (fAllEventQAHistos) delete fAllEventQAHistos;
108 fAllEventQAHistos = 0x0;
112 // -------------------------------------------------------------------------
113 Long64_t AliAODEventCutsDiHadronPID::Merge(TCollection* list) {
119 cout<<"AliAODEventCutsDiHadronPID Merger Called."<<endl;
120 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
123 if (list->IsEmpty()) return 1;
125 if (!fSelectedEventQAHistos||!fAllEventQAHistos) {
126 cout<<"AliAODEventCutsDiHadronPID::Merge() - Warning, current object's histograms are missing... Generating."<<endl;
130 TIterator* iter = list->MakeIterator();
133 // List of collections
134 TList collection_fSelectedEventQAHistos;
135 TList collection_fAllEventQAHistos;
139 while ((obj = iter->Next())) {
140 AliAODEventCutsDiHadronPID* entry = dynamic_cast<AliAODEventCutsDiHadronPID*> (obj);
141 if (entry == 0) continue;
143 // Check if the object to be merged really has the same name! (FIXME!)
145 // Getting the lists from obj.
146 TList* list_fSelectedEventQAHistos = entry->GetListOfSelectedEventQAHistos();
147 TList* list_fAllEventQAHistos = entry->GetListOfAllEventQAHistos();
149 // Adding the retrieved lists to the collection.
150 if (list_fSelectedEventQAHistos) collection_fSelectedEventQAHistos.Add(list_fSelectedEventQAHistos);
151 if (list_fAllEventQAHistos) collection_fAllEventQAHistos.Add(list_fAllEventQAHistos);
156 // Merging. Note that we require the original list to exist.
157 // * Assume that if the collection happens to be empty, then nothing will happen.
158 // * All other variables are taken from the original object.
159 if (fSelectedEventQAHistos) fSelectedEventQAHistos->Merge(&collection_fSelectedEventQAHistos);
160 if (fAllEventQAHistos) fAllEventQAHistos->Merge(&collection_fAllEventQAHistos);
168 // -------------------------------------------------------------------------
169 void AliAODEventCutsDiHadronPID::CreateHistos() {
171 cout<<"AliAODEventCutsDiHadronPID - Creating histograms"<<endl;
172 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
174 // Create list of Event related QA histograms (selected events).
175 fSelectedEventQAHistos = new TList();
176 fSelectedEventQAHistos->SetName("SelectedEventQAHistos");
177 fSelectedEventQAHistos->SetOwner(kTRUE);
179 // The same, but for all events.
180 fAllEventQAHistos = new TList();
181 fAllEventQAHistos->SetName("AllEventQAHistos");
182 fAllEventQAHistos->SetOwner(kTRUE);
184 // Creating arrays of pointers to the QA histos.
185 fHistTrigger = new TH1F*[2];
186 fHistRefMultiplicity = new TH1F*[2];
187 fHistCentrality = new TH1F*[2];
188 fHistCentralityQuality = new TH1F*[2];
189 fHistVertexZ = new TH1F*[2];
191 const char* HistType[2] = {"Selected","All"};
193 for (Int_t iHistType = 0; iHistType < 2; iHistType++) {
195 // Trigger Histogram.
196 fHistTrigger[iHistType] = new TH1F(Form("fHistTrigger%s",HistType[iHistType]),"Trigger;;Count",2,-0.5,1.5);
197 fHistTrigger[iHistType]->GetXaxis()->SetBinLabel(1,"kMB");
198 fHistTrigger[iHistType]->GetXaxis()->SetBinLabel(2,"Other");
199 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistTrigger[iHistType]);
200 else fAllEventQAHistos->Add(fHistTrigger[iHistType]);
202 // Ref Multiplicity Histogram.
203 fHistRefMultiplicity[iHistType] = new TH1F(Form("fHistRefMultiplicity%s",HistType[iHistType]),"Reference Multiplicity;N_{tracks};Count",100,0.,10000.);
204 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistRefMultiplicity[iHistType]);
205 else fAllEventQAHistos->Add(fHistRefMultiplicity[iHistType]);
207 // Centrality Histogram.
208 fHistCentrality[iHistType] = new TH1F(Form("fHistCentrality%s",HistType[iHistType]),"Centrality;Centrality;Count",20,0,100);
209 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistCentrality[iHistType]);
210 else fAllEventQAHistos->Add(fHistCentrality[iHistType]);
212 // Centrality Quality.
213 fHistCentralityQuality[iHistType] = new TH1F(Form("fHistCentralityQuality%s",HistType[iHistType]),"Centrality Quality;Quality;Count",2,-0.5,1.5);
214 fHistCentralityQuality[iHistType]->GetXaxis()->SetBinLabel(1,"0");
215 fHistCentralityQuality[iHistType]->GetXaxis()->SetBinLabel(2,"Other");
216 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistCentralityQuality[iHistType]);
217 else fAllEventQAHistos->Add(fHistCentralityQuality[iHistType]);
219 // VertexZ Histogram.
220 fHistVertexZ[iHistType] = new TH1F(Form("fHistVertexZ%s",HistType[iHistType]),"VertexZ;z (cm);Count",60,-15.,15.);
221 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistVertexZ[iHistType]);
222 else fAllEventQAHistos->Add(fHistVertexZ[iHistType]);
228 // -------------------------------------------------------------------------
229 Bool_t AliAODEventCutsDiHadronPID::IsSelected(AliAODEvent* event) {
231 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
233 if (!event) return kFALSE;
235 if (!fAllEventQAHistos||!fSelectedEventQAHistos) {cout<<"AliAODEventCutsDiHadronPID - Histograms were not created, you should have called CreateHistos()..."<<endl;}
237 // Input the event handler.
238 AliInputEventHandler* InputHandler = (AliInputEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
239 if (!InputHandler) return kFALSE;
241 Bool_t select = kTRUE;
244 UInt_t trigger = InputHandler->IsEventSelected();
245 Int_t triggerselect = 0; // 0 = selected.
247 if (!(trigger & fTrigger)) {
249 triggerselect = 1; // 1 = not selected.
253 AliCentrality* CurrentCentrality = 0x0;
254 Int_t CurrentCentralityQuality = -999;
255 Float_t percentile = -999.;
259 // Get the centrality object.
260 CurrentCentrality = event->GetCentrality();
261 if (!CurrentCentrality) {select = kFALSE; return select;}
263 // Check the quality of the centrality estimation.
264 // If 0 then quality is OK, c.f. TOF/PbPb276/macros/TOFmatchEff.C
265 CurrentCentralityQuality = CurrentCentrality->GetQuality();
266 //cout<<"Centrality: "<<CurrentCentrality->GetCentralityPercentile(fCentralityEstimator.Data())<<" Quality: "<<CurrentCentrality->GetQuality()<<endl;
267 if (CurrentCentralityQuality) select = kFALSE;
270 percentile = CurrentCentrality->GetCentralityPercentile(fCentralityEstimator.Data());
271 if (fTestCentrality) {
272 if ((percentile < fMaxCentrality)||(percentile > fMinCentrality)) select = kFALSE;
277 // Get the primary vertex.
278 AliAODVertex* CurrentPrimaryVertex = event->GetPrimaryVertex();
279 if (!CurrentPrimaryVertex) {select = kFALSE; return select;}
282 Double_t vtxz = CurrentPrimaryVertex->GetZ();
284 if (TMath::Abs(vtxz) > fMaxVertexZ) select = kFALSE;
287 // Get the event header.
288 AliAODHeader* CurrentHeader = event->GetHeader();
290 // Test minimum reference multiplicity.
291 Int_t CurrentRefMultiplicity = CurrentHeader->GetRefMultiplicity();
292 if (fTestMinRefMult) {
293 if (CurrentRefMultiplicity < fMinRefMult) select = kFALSE;
296 // Fill the histograms for selected events.
298 fHistTrigger[0]->Fill(triggerselect);
299 fHistRefMultiplicity[0]->Fill(CurrentHeader->GetRefMultiplicity());
300 if (fIsPbPb) fHistCentrality[0]->Fill(percentile);
301 if (fIsPbPb) fHistCentralityQuality[0]->Fill(CurrentCentralityQuality);
302 fHistVertexZ[0]->Fill(vtxz);
305 // Fill the histograms for all events.
306 fHistTrigger[1]->Fill(triggerselect);
307 fHistRefMultiplicity[1]->Fill(CurrentHeader->GetRefMultiplicity());
308 if (fIsPbPb) fHistCentrality[1]->Fill(percentile);
309 if (fIsPbPb) fHistCentralityQuality[1]->Fill(CurrentCentralityQuality);
310 fHistVertexZ[1]->Fill(vtxz);
312 cout<<"Event Selected: "<<select<<endl;
318 // -------------------------------------------------------------------------
319 void AliAODEventCutsDiHadronPID::PrintCuts() {
322 if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}