]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/DPhi/DiHadronPID/AliAODEventCutsDiHadronPID.cxx
coverity fixes (Misha Veldhoen <Misha.Veldhoen@cern.ch>)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / DiHadronPID / AliAODEventCutsDiHadronPID.cxx
1 // -------------------------------------------------------------------------
2 // Object managing event cuts, and holding QA histograms.
3 // -------------------------------------------------------------------------
4 // Author: Misha Veldhoen (misha.veldhoen@cern.ch)
5
6 #include <iostream>
7 #include "TList.h"
8 #include "TMath.h"
9 #include "TH1F.h"
10 #include "TH2F.h"
11 #include "TNamed.h"
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"
20
21 using namespace std;
22
23 ClassImp(AliAODEventCutsDiHadronPID);
24
25 // -------------------------------------------------------------------------
26 AliAODEventCutsDiHadronPID::AliAODEventCutsDiHadronPID():
27         TNamed(),
28         fIsPbPb(kTRUE),
29         fIsMC(kFALSE),
30         fTrigger(AliVEvent::kMB),
31         fMinCentrality(5.),
32         fMaxCentrality(0.),
33         fCentralityEstimator("V0M"),
34         fMaxVertexZ(10.),
35         fMinRefMult(0),
36         fTestTrigger(kFALSE),
37         fTestCentrality(kFALSE),
38         fTestVertexZ(kFALSE),
39         fTestMinRefMult(kFALSE),
40         fSelectedEventQAHistos(0x0),
41         fAllEventQAHistos(0x0),
42         fHistTrigger(0x0),
43         fHistRefMultiplicity(0x0),
44         fHistCentrality(0x0),
45         fHistCentralityQuality(0x0),
46         fHistVertexZ(0x0),
47         fDebug(0)
48
49 {
50
51         // 
52         // Default Constructor
53         //
54
55         cout<<"AliAODEventCutsDiHadronPID Default Constructor Called."<<endl;
56         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
57
58 }
59
60 // -------------------------------------------------------------------------
61 AliAODEventCutsDiHadronPID::AliAODEventCutsDiHadronPID(const char* name):
62         TNamed(name,"AOD Event Cuts"),
63         fIsPbPb(kTRUE),
64         fIsMC(kFALSE),  
65         fTrigger(AliVEvent::kMB),
66         fMinCentrality(5.),
67         fMaxCentrality(0.),
68         fCentralityEstimator("V0M"),
69         fMaxVertexZ(10.),
70         fMinRefMult(0), 
71         fTestTrigger(kFALSE),
72         fTestCentrality(kFALSE),
73         fTestVertexZ(kFALSE),
74         fTestMinRefMult(kFALSE),        
75         fSelectedEventQAHistos(0x0),
76         fAllEventQAHistos(0x0),
77         fHistTrigger(0x0),
78         fHistRefMultiplicity(0x0),
79         fHistCentrality(0x0),
80         fHistCentralityQuality(0x0),
81         fHistVertexZ(0x0),
82         fDebug(0)
83         
84 {
85
86         //
87         // Named Constructor
88         //
89
90         cout<<"AliAODEventCutsDiHadronPID Named Constructor Called."<<endl;
91         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
92
93 }
94
95 // -------------------------------------------------------------------------
96 AliAODEventCutsDiHadronPID::~AliAODEventCutsDiHadronPID() {
97
98         //
99         // Destructor
100         //
101
102         cout<<"AliAODEventCutsDiHadronPID Destructor Called."<<endl;
103         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
104
105         if (fSelectedEventQAHistos) delete fSelectedEventQAHistos;
106         fSelectedEventQAHistos = 0x0;
107         if (fAllEventQAHistos) delete fAllEventQAHistos;
108         fAllEventQAHistos = 0x0;
109
110 }
111
112 // -------------------------------------------------------------------------
113 Long64_t AliAODEventCutsDiHadronPID::Merge(TCollection* list) {
114
115         //
116         // Merger. 
117         // 
118
119         cout<<"AliAODEventCutsDiHadronPID Merger Called."<<endl;
120         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
121
122         if (!list) return 0;
123         if (list->IsEmpty()) return 1;
124
125         if (!fSelectedEventQAHistos||!fAllEventQAHistos) {
126                 cout<<"AliAODEventCutsDiHadronPID::Merge() - Warning, current object's histograms are missing... Generating."<<endl;
127                 CreateHistos();
128         }
129
130         TIterator* iter = list->MakeIterator();
131         TObject* obj;
132
133         // List of collections
134         TList collection_fSelectedEventQAHistos;
135         TList collection_fAllEventQAHistos;
136
137         Int_t count = 0;
138
139         while ((obj = iter->Next())) {
140         AliAODEventCutsDiHadronPID* entry = dynamic_cast<AliAODEventCutsDiHadronPID*> (obj);
141         if (entry == 0) continue;
142
143         // Check if the object to be merged really has the same name! (FIXME!)
144
145         // Getting the lists from obj.
146         TList* list_fSelectedEventQAHistos = entry->GetListOfSelectedEventQAHistos();
147         TList* list_fAllEventQAHistos = entry->GetListOfAllEventQAHistos();
148
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);
152
153         count++;
154     }
155
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);
161
162     delete iter;
163
164         return count+1;
165
166 }
167
168 // -------------------------------------------------------------------------
169 void AliAODEventCutsDiHadronPID::CreateHistos() {
170
171         cout<<"AliAODEventCutsDiHadronPID - Creating histograms"<<endl;
172         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
173
174         // Create list of Event related QA histograms (selected events).
175         fSelectedEventQAHistos = new TList();
176         fSelectedEventQAHistos->SetName("SelectedEventQAHistos");
177         fSelectedEventQAHistos->SetOwner(kTRUE);
178
179         // The same, but for all events.
180         fAllEventQAHistos = new TList();
181         fAllEventQAHistos->SetName("AllEventQAHistos");
182         fAllEventQAHistos->SetOwner(kTRUE);
183
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];
190
191         const char* HistType[2] = {"Selected","All"};
192
193         for (Int_t iHistType = 0; iHistType < 2; iHistType++) {
194
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]);
201
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]);
206
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]);
211
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]);
218
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]);
223
224         }
225
226 }
227
228 // -------------------------------------------------------------------------
229 Bool_t AliAODEventCutsDiHadronPID::IsSelected(AliAODEvent* event) {
230         
231         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
232
233         if (!event) return kFALSE;
234
235         if (!fAllEventQAHistos||!fSelectedEventQAHistos) {cout<<"AliAODEventCutsDiHadronPID - Histograms were not created, you should have called CreateHistos()..."<<endl;}
236
237         // Input the event handler.
238         AliInputEventHandler* InputHandler = (AliInputEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
239         if (!InputHandler) return kFALSE;
240
241         Bool_t select = kTRUE;
242
243         // Test Trigger.
244         UInt_t trigger = InputHandler->IsEventSelected();
245         Int_t triggerselect = 0; // 0 = selected.
246     if (fTestTrigger) {
247                 if (!(trigger & fTrigger)) {
248                         select = kFALSE;
249                         triggerselect = 1;      // 1 = not selected.
250                 }
251         }       
252
253         AliCentrality* CurrentCentrality = 0x0;
254         Int_t CurrentCentralityQuality = -999;
255         Float_t percentile = -999.;
256
257         if (fIsPbPb) {
258
259                 // Get the centrality object.
260             CurrentCentrality = event->GetCentrality();
261             if (!CurrentCentrality) {select = kFALSE; return select;}
262
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;
268
269                 // Test Centrality.
270             percentile = CurrentCentrality->GetCentralityPercentile(fCentralityEstimator.Data());
271                 if (fTestCentrality) {
272                 if ((percentile < fMaxCentrality)||(percentile > fMinCentrality)) select = kFALSE;
273                 }
274
275         }
276
277         // Get the primary vertex.
278         AliAODVertex* CurrentPrimaryVertex = event->GetPrimaryVertex();
279     if (!CurrentPrimaryVertex) {select = kFALSE; return select;}
280
281         // Test Vertex Z.
282     Double_t vtxz = CurrentPrimaryVertex->GetZ();
283         if (fTestVertexZ) {
284         if (TMath::Abs(vtxz) > fMaxVertexZ) select = kFALSE; 
285         }
286
287         // Get the event header.
288         AliAODHeader* CurrentHeader = event->GetHeader();
289
290         // Test minimum reference multiplicity.
291         Int_t CurrentRefMultiplicity = CurrentHeader->GetRefMultiplicity();
292         if (fTestMinRefMult) {
293                 if (CurrentRefMultiplicity < fMinRefMult) select = kFALSE;
294         }
295
296         // Fill the histograms for selected events.
297         if (select) {
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);
303         }
304
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);
311
312         cout<<"Event Selected: "<<select<<endl;
313
314         return select;
315
316 }
317
318 // -------------------------------------------------------------------------
319 void AliAODEventCutsDiHadronPID::PrintCuts() {
320
321         // NOT IMPLEMENTED.
322         if (fDebug > 1) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
323
324         return;
325
326 }