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) {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) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
95 // -------------------------------------------------------------------------
96 AliAODEventCutsDiHadronPID::AliAODEventCutsDiHadronPID(const AliAODEventCutsDiHadronPID &source):
98 fTrigger(source.fTrigger),
99 fMinCentrality(source.fMinCentrality),
100 fMaxCentrality(source.fMaxCentrality),
101 fCentralityEstimator(source.fCentralityEstimator),
102 fMaxVertexZ(source.fMaxVertexZ),
103 fTestTrigger(source.fTestTrigger),
104 fTestCentrality(source.fTestCentrality),
105 fTestVertexZ(source.fTestVertexZ),
106 fSelectedEventQAHistos(0x0),
107 fAllEventQAHistos(0x0),
109 fHistRefMultiplicity(0x0),
110 fHistCentrality(0x0),
119 cout<<"AliAODEventCutsDiHadronPID Copy Constructor Called."<<endl;
120 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
122 //if (source.fSelectedEventQAHistos) fSelectedEventQAHistos = (TList*)source.fHistTrigger->Clone();
123 //if (source.fHistTrigger) fHistTrigger = (TH1F*)source.fHistTrigger->Clone();
124 //if (source.fHistRefMultiplicity) fHistRefMultiplicity = (TH1F*)source.fHistRefMultiplicity->Clone();
125 //if (source.fHistCentrality) fHistCentrality = (TH1F*)source.fHistCentrality->Clone();
126 //if (source.fHistVertexZ) fHistVertexZ = (TH1F*)source.fHistVertexZ->Clone();
130 // -------------------------------------------------------------------------
131 AliAODEventCutsDiHadronPID::~AliAODEventCutsDiHadronPID() {
137 cout<<"AliAODEventCutsDiHadronPID Destructor Called."<<endl;
138 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
140 if (fSelectedEventQAHistos) delete fSelectedEventQAHistos;
141 fSelectedEventQAHistos = 0x0;
142 if (fAllEventQAHistos) delete fAllEventQAHistos;
143 fAllEventQAHistos = 0x0;
147 // -------------------------------------------------------------------------
148 Long64_t AliAODEventCutsDiHadronPID::Merge(TCollection* list) {
154 cout<<"AliAODEventCutsDiHadronPID Merger Called."<<endl;
155 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
158 if (list->IsEmpty()) return 1;
160 if (!fSelectedEventQAHistos||!fAllEventQAHistos) {
161 cout<<"AliAODEventCutsDiHadronPID::Merge() - Warning, current object's histograms are missing... Generating."<<endl;
165 TIterator* iter = list->MakeIterator();
168 // List of collections
169 TList collection_fSelectedEventQAHistos;
170 TList collection_fAllEventQAHistos;
174 while ((obj = iter->Next())) {
175 AliAODEventCutsDiHadronPID* entry = dynamic_cast<AliAODEventCutsDiHadronPID*> (obj);
176 if (entry == 0) continue;
178 // Check if the object to be merged really has the same name! (FIXME!)
180 // Getting the lists from obj.
181 TList* list_fSelectedEventQAHistos = entry->GetListOfSelectedEventQAHistos();
182 TList* list_fAllEventQAHistos = entry->GetListOfAllEventQAHistos();
184 // Adding the retrieved lists to the collection.
185 if (list_fSelectedEventQAHistos) collection_fSelectedEventQAHistos.Add(list_fSelectedEventQAHistos);
186 if (list_fAllEventQAHistos) collection_fAllEventQAHistos.Add(list_fAllEventQAHistos);
191 // Merging. Note that we require the original list to exist.
192 // * Assume that if the collection happens to be empty, then nothing will happen.
193 // * All other variables are taken from the original object.
194 if (fSelectedEventQAHistos) fSelectedEventQAHistos->Merge(&collection_fSelectedEventQAHistos);
195 if (fAllEventQAHistos) fAllEventQAHistos->Merge(&collection_fAllEventQAHistos);
203 // -------------------------------------------------------------------------
204 void AliAODEventCutsDiHadronPID::CreateHistos() {
206 cout<<"AliAODEventCutsDiHadronPID - Creating histograms"<<endl;
207 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
209 // Create list of Event related QA histograms (selected events).
210 fSelectedEventQAHistos = new TList();
211 fSelectedEventQAHistos->SetName("SelectedEventQAHistos");
212 fSelectedEventQAHistos->SetOwner(kTRUE);
214 // The same, but for all events.
215 fAllEventQAHistos = new TList();
216 fAllEventQAHistos->SetName("AllEventQAHistos");
217 fAllEventQAHistos->SetOwner(kTRUE);
219 // Creating arrays of pointers to the QA histos.
220 fHistTrigger = new TH1F*[2];
221 fHistRefMultiplicity = new TH1F*[2];
222 fHistCentrality = new TH1F*[2];
223 fHistCentralityQuality = new TH1F*[2];
224 fHistVertexZ = new TH1F*[2];
226 const char* HistType[2] = {"Selected","All"};
228 for (Int_t iHistType = 0; iHistType < 2; iHistType++) {
230 // Trigger Histogram.
231 fHistTrigger[iHistType] = new TH1F(Form("fHistTrigger%s",HistType[iHistType]),"Trigger;;Count",2,-0.5,1.5);
232 fHistTrigger[iHistType]->GetXaxis()->SetBinLabel(1,"kMB");
233 fHistTrigger[iHistType]->GetXaxis()->SetBinLabel(2,"Other");
234 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistTrigger[iHistType]);
235 else fAllEventQAHistos->Add(fHistTrigger[iHistType]);
237 // Ref Multiplicity Histogram.
238 fHistRefMultiplicity[iHistType] = new TH1F(Form("fHistRefMultiplicity%s",HistType[iHistType]),"Reference Multiplicity;N_{tracks};Count",100,0.,10000.);
239 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistRefMultiplicity[iHistType]);
240 else fAllEventQAHistos->Add(fHistRefMultiplicity[iHistType]);
242 // Centrality Histogram.
243 fHistCentrality[iHistType] = new TH1F(Form("fHistCentrality%s",HistType[iHistType]),"Centrality;Centrality;Count",20,0,100);
244 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistCentrality[iHistType]);
245 else fAllEventQAHistos->Add(fHistCentrality[iHistType]);
247 // Centrality Quality.
248 fHistCentralityQuality[iHistType] = new TH1F(Form("fHistCentralityQuality%s",HistType[iHistType]),"Centrality Quality;Quality;Count",2,-0.5,1.5);
249 fHistCentralityQuality[iHistType]->GetXaxis()->SetBinLabel(1,"0");
250 fHistCentralityQuality[iHistType]->GetXaxis()->SetBinLabel(2,"Other");
251 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistCentralityQuality[iHistType]);
252 else fAllEventQAHistos->Add(fHistCentralityQuality[iHistType]);
254 // VertexZ Histogram.
255 fHistVertexZ[iHistType] = new TH1F(Form("fHistVertexZ%s",HistType[iHistType]),"VertexZ;z (cm);Count",60,-15.,15.);
256 if (iHistType == 0) fSelectedEventQAHistos->Add(fHistVertexZ[iHistType]);
257 else fAllEventQAHistos->Add(fHistVertexZ[iHistType]);
263 // -------------------------------------------------------------------------
264 Bool_t AliAODEventCutsDiHadronPID::IsSelected(AliAODEvent* event) {
266 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
268 if (!event) return kFALSE;
270 if (!fAllEventQAHistos||!fSelectedEventQAHistos) {cout<<"AliAODEventCutsDiHadronPID - Histograms were not created, you should have called CreateHistos()..."<<endl;}
272 // Input the event handler.
273 AliInputEventHandler* InputHandler = (AliInputEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
274 if (!InputHandler) return kFALSE;
276 Bool_t select = kTRUE;
279 UInt_t trigger = InputHandler->IsEventSelected();
280 Int_t triggerselect = 0; // 0 = selected.
282 if (!(trigger & fTrigger)) {
284 triggerselect = 1; // 1 = not selected.
288 AliCentrality* CurrentCentrality = 0x0;
289 Int_t CurrentCentralityQuality = -999;
290 Float_t percentile = -999.;
294 // Get the centrality object.
295 CurrentCentrality = event->GetCentrality();
296 if (!CurrentCentrality) select = kFALSE;
298 // Check the quality of the centrality estimation.
299 // If 0 then quality is OK, c.f. TOF/PbPb276/macros/TOFmatchEff.C
300 CurrentCentralityQuality = CurrentCentrality->GetQuality();
301 //cout<<"Centrality: "<<CurrentCentrality->GetCentralityPercentile(fCentralityEstimator.Data())<<" Quality: "<<CurrentCentrality->GetQuality()<<endl;
302 if (CurrentCentralityQuality) select = kFALSE;
305 percentile = CurrentCentrality->GetCentralityPercentile(fCentralityEstimator.Data());
306 if (fTestCentrality) {
307 if ((percentile < fMaxCentrality)||(percentile > fMinCentrality)) select = kFALSE;
312 // Get the primary vertex.
313 AliAODVertex* CurrentPrimaryVertex = event->GetPrimaryVertex();
314 if (!CurrentPrimaryVertex) select = kFALSE;
317 Double_t vtxz = CurrentPrimaryVertex->GetZ();
319 if (TMath::Abs(vtxz) > fMaxVertexZ) select = kFALSE;
322 // Get the event header.
323 AliAODHeader* CurrentHeader = event->GetHeader();
325 // Test minimum reference multiplicity.
326 Int_t CurrentRefMultiplicity = CurrentHeader->GetRefMultiplicity();
327 if (fTestMinRefMult) {
328 if (CurrentRefMultiplicity < fMinRefMult) select = kFALSE;
331 // Fill the histograms for selected events.
333 fHistTrigger[0]->Fill(triggerselect);
334 fHistRefMultiplicity[0]->Fill(CurrentHeader->GetRefMultiplicity());
335 if (fIsPbPb) fHistCentrality[0]->Fill(percentile);
336 if (fIsPbPb) fHistCentralityQuality[0]->Fill(CurrentCentralityQuality);
337 fHistVertexZ[0]->Fill(vtxz);
340 // Fill the histograms for all events.
341 fHistTrigger[1]->Fill(triggerselect);
342 fHistRefMultiplicity[1]->Fill(CurrentHeader->GetRefMultiplicity());
343 if (fIsPbPb) fHistCentrality[1]->Fill(percentile);
344 if (fIsPbPb) fHistCentralityQuality[1]->Fill(CurrentCentralityQuality);
345 fHistVertexZ[1]->Fill(vtxz);
347 cout<<"Event Selected: "<<select<<endl;
353 // -------------------------------------------------------------------------
354 void AliAODEventCutsDiHadronPID::PrintCuts() {
357 if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}