]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/GammaConv/AliAnalysisTaskGammaCalo.cxx
Coverity fixes for TOF new CPass1 calib task
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliAnalysisTaskGammaCalo.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                                                                                                *
4  * Author: Baldo Sahlmueller, Friederike Bock                                             *
5  * Version 1.0                                                                                                                    *
6  *                                                                                                                                                *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is                  *
14  * provided "as is" without express or implied warranty.                          *
15  **************************************************************************/
16
17 //////////////////////////////////////////////////////////////////
18 //----------------------------------------------------------------
19 // Class used to do analysis on conversion photons + calo photons
20 //----------------------------------------------------------------
21 //////////////////////////////////////////////////////////////////
22 #include "TChain.h"
23 #include "TTree.h"
24 #include "TBranch.h"
25 #include "TFile.h"
26 #include "TH1F.h"
27 #include "TH2F.h"
28 #include "TH3F.h"
29 #include "THnSparse.h"
30 #include "TCanvas.h"
31 #include "TNtuple.h"
32 #include "AliAnalysisTask.h"
33 #include "AliAnalysisManager.h"
34 #include "AliESDEvent.h"
35 #include "AliESDInputHandler.h"
36 #include "AliMCEventHandler.h"
37 #include "AliMCEvent.h"
38 #include "AliMCParticle.h"
39 #include "AliCentrality.h"
40 #include "AliESDVZERO.h"
41 #include "AliESDpid.h"
42 #include "AliAnalysisTaskGammaCalo.h"
43 #include "AliVParticle.h"
44 #include "AliESDtrack.h"
45 #include "AliESDtrackCuts.h"
46 #include "AliKFVertex.h"
47 #include "AliV0ReaderV1.h"
48 #include "AliGenCocktailEventHeader.h"
49 #include "AliAODMCParticle.h"
50 #include "AliAODMCHeader.h"
51 #include "AliEventplane.h"
52 #include "AliAnalysisTaskEMCALClusterizeFast.h"
53 #include "AliAODEvent.h"
54 #include "AliAODInputHandler.h"
55 #include "AliESDEvent.h"
56 #include "AliESDInputHandler.h"
57 #include "AliInputEventHandler.h"
58
59 ClassImp(AliAnalysisTaskGammaCalo)
60
61 //________________________________________________________________________
62 AliAnalysisTaskGammaCalo::AliAnalysisTaskGammaCalo(): AliAnalysisTaskSE(),
63         fV0Reader(NULL),
64         fBGHandler(NULL),
65         fInputEvent(NULL),
66         fMCEvent(NULL),
67         fMCStack(NULL),
68         fCutFolder(NULL),
69         fESDList(NULL),
70         fBackList(NULL),
71         fMotherList(NULL),
72         fTrueList(NULL),
73         fMCList(NULL),
74         fHeaderNameList(NULL),
75         fOutputContainer(NULL),
76         fClusterCandidates(NULL),
77         fEventCutArray(NULL),
78         fEventCuts(NULL),
79         fClusterCutArray(NULL),
80         fCaloPhotonCuts(NULL),
81         fMesonCutArray(NULL),
82         fMesonCuts(NULL),
83         fHistoMotherInvMassPt(NULL),
84         fHistoMotherInvMass3ClusterPt(NULL),
85         fSparseMotherInvMassPtZM(NULL),
86         fHistoMotherBackInvMassPt(NULL),
87         fSparseMotherBackInvMassPtZM(NULL),
88         fHistoMotherInvMassEalpha(NULL),
89         fHistoMotherPi0PtY(NULL),
90         fHistoMotherEtaPtY(NULL),
91         fHistoMotherPi0PtAlpha(NULL),
92         fHistoMotherEtaPtAlpha(NULL),
93         fHistoMotherPi0PtOpenAngle(NULL),
94         fHistoMotherEtaPtOpenAngle(NULL),
95         fHistoMotherInvMassECalib(NULL),
96         fHistoMotherInvMassECalibalpha(NULL),
97         fHistoClusGammaPt(NULL),
98         fHistoMCHeaders(NULL),
99         fHistoMCAllGammaPt(NULL),
100         fHistoMCDecayGammaPi0Pt(NULL),
101         fHistoMCDecayGammaRhoPt(NULL),
102         fHistoMCDecayGammaEtaPt(NULL),
103         fHistoMCDecayGammaOmegaPt(NULL),
104         fHistoMCDecayGammaEtapPt(NULL),
105         fHistoMCDecayGammaPhiPt(NULL),
106         fHistoMCDecayGammaSigmaPt(NULL),
107         fHistoMCPi0Pt(NULL),
108         fHistoMCPi0WOWeightPt(NULL),
109         fHistoMCEtaPt(NULL),
110         fHistoMCEtaWOWeightPt(NULL),
111         fHistoMCPi0InAccPt(NULL),
112         fHistoMCEtaInAccPt(NULL),
113         fHistoMCPi0PtY(NULL),
114         fHistoMCEtaPtY(NULL),
115         fHistoMCPi0PtAlpha(NULL),
116         fHistoMCEtaPtAlpha(NULL),
117         fHistoMCK0sPt(NULL),
118         fHistoMCK0sWOWeightPt(NULL),
119         fHistoMCK0sPtY(NULL),
120         fHistoMCSecPi0PtvsSource(NULL),
121         fHistoMCSecPi0Source(NULL),
122         fHistoMCSecEtaPt(NULL),
123         fHistoMCSecEtaSource(NULL),
124         fHistoTruePi0InvMassPt(NULL),
125         fHistoTrueEtaInvMassPt(NULL),
126         fHistoTruePi0CaloPhotonInvMassPt(NULL),
127         fHistoTrueEtaCaloPhotonInvMassPt(NULL),
128         fHistoTruePi0CaloConvertedPhotonInvMassPt(NULL),
129         fHistoTrueEtaCaloConvertedPhotonInvMassPt(NULL),
130         fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt(NULL),
131         fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt(NULL),
132         fHistoTruePi0CaloElectronInvMassPt(NULL),
133         fHistoTrueEtaCaloElectronInvMassPt(NULL),
134         fHistoTruePi0CaloMergedClusterInvMassPt(NULL),
135         fHistoTrueEtaCaloMergedClusterInvMassPt(NULL),
136         fHistoTruePi0CaloMergedClusterPartConvInvMassPt(NULL),
137         fHistoTrueEtaCaloMergedClusterPartConvInvMassPt(NULL),
138         fHistoTruePi0NonMergedElectronPhotonInvMassPt(NULL),
139         fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt(NULL),
140         fHistoTruePrimaryPi0InvMassPt(NULL),
141         fHistoTruePrimaryEtaInvMassPt(NULL),
142         fHistoTruePrimaryPi0W0WeightingInvMassPt(NULL),
143         fHistoTruePrimaryEtaW0WeightingInvMassPt(NULL),
144         fProfileTruePrimaryPi0WeightsInvMassPt(NULL),
145         fProfileTruePrimaryEtaWeightsInvMassPt(NULL),
146         fHistoTruePrimaryPi0MCPtResolPt(NULL),
147         fHistoTruePrimaryEtaMCPtResolPt(NULL),
148         fHistoTrueSecondaryPi0InvMassPt(NULL),
149         fHistoTrueSecondaryEtaInvMassPt(NULL),
150         fHistoTrueSecondaryPi0FromK0sInvMassPt(NULL),
151         fHistoTrueK0sWithPi0DaughterMCPt(NULL),
152         fHistoTrueSecondaryPi0FromEtaInvMassPt(NULL),
153         fHistoTrueEtaWithPi0DaughterMCPt(NULL),
154         fHistoTrueSecondaryPi0FromLambdaInvMassPt(NULL),
155         fHistoTrueLambdaWithPi0DaughterMCPt(NULL),
156         fHistoTrueBckGGInvMassPt(NULL),
157         fHistoTrueBckContInvMassPt(NULL),
158         fHistoTruePi0PtY(NULL),
159         fHistoTrueEtaPtY(NULL),
160         fHistoTruePi0PtAlpha(NULL),
161         fHistoTrueEtaPtAlpha(NULL),
162         fHistoTruePi0PtOpenAngle(NULL),
163         fHistoTrueEtaPtOpenAngle(NULL),
164         fHistoClusPhotonBGPt(NULL),
165         fHistoClusPhotonPlusConvBGPt(NULL),
166         fHistoTrueClusGammaPt(NULL),
167         fHistoTrueClusUnConvGammaPt(NULL),
168         fHistoTrueClusUnConvGammaMCPt(NULL),
169         fHistoTrueClusElectronPt(NULL),
170         fHistoTrueClusConvGammaPt(NULL),
171         fHistoTrueClusConvGammaMCPt(NULL),
172         fHistoTrueClusConvGammaFullyPt(NULL),
173         fHistoTrueClusMergedGammaPt(NULL),
174         fHistoTrueClusMergedPartConvGammaPt(NULL),
175         fHistoTrueClusDalitzPt(NULL),
176         fHistoTrueClusDalitzMergedPt(NULL),
177         fHistoTrueClusPhotonFromElecMotherPt(NULL),
178         fHistoTrueClusShowerPt(NULL),
179         fHistoTrueClusSubLeadingPt(NULL),
180         fHistoTrueClusNParticles(NULL),
181         fHistoTrueClusEMNonLeadingPt(NULL),
182         fHistoTrueNLabelsInClus(NULL),
183         fHistoTruePrimaryClusGammaPt(NULL),
184         fHistoTruePrimaryClusGammaESDPtMCPt(NULL),
185         fHistoTruePrimaryClusConvGammaPt(NULL),
186         fHistoTruePrimaryClusConvGammaESDPtMCPt(NULL),
187         fHistoTrueSecondaryClusGammaPt(NULL),
188         fHistoTrueSecondaryClusConvGammaPt(NULL),
189         fHistoTrueSecondaryClusGammaFromXFromK0sPt(NULL),
190         fHistoTrueSecondaryClusConvGammaFromXFromK0sPt(NULL),
191         fHistoTrueSecondaryClusGammaFromXFromLambdaPt(NULL),
192         fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt(NULL),
193         fHistoTrueSecondaryClusGammaFromXFromEtasPt(NULL),
194         fHistoTrueSecondaryClusConvGammaFromXFromEtasPt(NULL),
195         fHistoNEvents(NULL),
196         fHistoNGoodESDTracks(NULL),
197         fHistoNGammaCandidates(NULL),
198         fHistoNGoodESDTracksVsNGammaCanditates(NULL),
199         fHistoNV0Tracks(NULL),
200         fProfileEtaShift(NULL),
201         fEventPlaneAngle(-100),
202         fRandom(0),
203         fnCuts(0),
204         fiCut(0),
205         fIsHeavyIon(0),
206         fDoMesonAnalysis(kTRUE),
207         fDoMesonQA(0),
208         fDoClusterQA(0),
209         fIsFromMBHeader(kTRUE),
210         fIsMC(kFALSE)
211 {
212   
213 }
214
215 //________________________________________________________________________
216 AliAnalysisTaskGammaCalo::AliAnalysisTaskGammaCalo(const char *name):
217         AliAnalysisTaskSE(name),
218         fV0Reader(NULL),
219         fBGHandler(NULL),
220         fInputEvent(NULL),
221         fMCEvent(NULL),
222         fMCStack(NULL),
223         fCutFolder(NULL),
224         fESDList(NULL),
225         fBackList(NULL),
226         fMotherList(NULL),
227         fTrueList(NULL),
228         fMCList(NULL),
229         fHeaderNameList(NULL),
230         fOutputContainer(0),
231         fClusterCandidates(NULL),
232         fEventCutArray(NULL),
233         fEventCuts(NULL),
234         fClusterCutArray(NULL),
235         fCaloPhotonCuts(NULL),
236         fMesonCutArray(NULL),
237         fMesonCuts(NULL),
238         fHistoMotherInvMassPt(NULL),
239         fHistoMotherInvMass3ClusterPt(NULL),
240         fSparseMotherInvMassPtZM(NULL),
241         fHistoMotherBackInvMassPt(NULL),
242         fSparseMotherBackInvMassPtZM(NULL),
243         fHistoMotherInvMassEalpha(NULL),
244         fHistoMotherPi0PtY(NULL),
245         fHistoMotherEtaPtY(NULL),
246         fHistoMotherPi0PtAlpha(NULL),
247         fHistoMotherEtaPtAlpha(NULL),
248         fHistoMotherPi0PtOpenAngle(NULL),
249         fHistoMotherEtaPtOpenAngle(NULL),
250         fHistoMotherInvMassECalib(NULL),
251         fHistoMotherInvMassECalibalpha(NULL),
252         fHistoClusGammaPt(NULL),
253         fHistoMCHeaders(NULL),
254         fHistoMCAllGammaPt(NULL),
255         fHistoMCDecayGammaPi0Pt(NULL),
256         fHistoMCDecayGammaRhoPt(NULL),
257         fHistoMCDecayGammaEtaPt(NULL),
258         fHistoMCDecayGammaOmegaPt(NULL),
259         fHistoMCDecayGammaEtapPt(NULL),
260         fHistoMCDecayGammaPhiPt(NULL),
261         fHistoMCDecayGammaSigmaPt(NULL),
262         fHistoMCPi0Pt(NULL),
263         fHistoMCPi0WOWeightPt(NULL),
264         fHistoMCEtaPt(NULL),
265         fHistoMCEtaWOWeightPt(NULL),
266         fHistoMCPi0InAccPt(NULL),
267         fHistoMCEtaInAccPt(NULL),
268         fHistoMCPi0PtY(NULL),
269         fHistoMCEtaPtY(NULL),
270         fHistoMCPi0PtAlpha(NULL),
271         fHistoMCEtaPtAlpha(NULL),
272         fHistoMCK0sPt(NULL),
273         fHistoMCK0sWOWeightPt(NULL),
274         fHistoMCK0sPtY(NULL),
275         fHistoMCSecPi0PtvsSource(NULL),
276         fHistoMCSecPi0Source(NULL),
277         fHistoMCSecEtaPt(NULL),
278         fHistoMCSecEtaSource(NULL),
279         fHistoTruePi0InvMassPt(NULL),
280         fHistoTrueEtaInvMassPt(NULL),
281         fHistoTruePi0CaloPhotonInvMassPt(NULL),
282         fHistoTrueEtaCaloPhotonInvMassPt(NULL),
283         fHistoTruePi0CaloConvertedPhotonInvMassPt(NULL),
284         fHistoTrueEtaCaloConvertedPhotonInvMassPt(NULL),
285         fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt(NULL),
286         fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt(NULL),
287         fHistoTruePi0CaloElectronInvMassPt(NULL),
288         fHistoTrueEtaCaloElectronInvMassPt(NULL),
289         fHistoTruePi0CaloMergedClusterInvMassPt(NULL),
290         fHistoTrueEtaCaloMergedClusterInvMassPt(NULL),
291         fHistoTruePi0CaloMergedClusterPartConvInvMassPt(NULL),
292         fHistoTrueEtaCaloMergedClusterPartConvInvMassPt(NULL),
293         fHistoTruePi0NonMergedElectronPhotonInvMassPt(NULL),
294         fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt(NULL),
295         fHistoTruePrimaryPi0InvMassPt(NULL),
296         fHistoTruePrimaryEtaInvMassPt(NULL),
297         fHistoTruePrimaryPi0W0WeightingInvMassPt(NULL),
298         fHistoTruePrimaryEtaW0WeightingInvMassPt(NULL),
299         fProfileTruePrimaryPi0WeightsInvMassPt(NULL),
300         fProfileTruePrimaryEtaWeightsInvMassPt(NULL),
301         fHistoTruePrimaryPi0MCPtResolPt(NULL),
302         fHistoTruePrimaryEtaMCPtResolPt(NULL),
303         fHistoTrueSecondaryPi0InvMassPt(NULL),
304         fHistoTrueSecondaryEtaInvMassPt(NULL),
305         fHistoTrueSecondaryPi0FromK0sInvMassPt(NULL),
306         fHistoTrueK0sWithPi0DaughterMCPt(NULL),
307         fHistoTrueSecondaryPi0FromEtaInvMassPt(NULL),
308         fHistoTrueEtaWithPi0DaughterMCPt(NULL),
309         fHistoTrueSecondaryPi0FromLambdaInvMassPt(NULL),
310         fHistoTrueLambdaWithPi0DaughterMCPt(NULL),
311         fHistoTrueBckGGInvMassPt(NULL),
312         fHistoTrueBckContInvMassPt(NULL),
313         fHistoTruePi0PtY(NULL),
314         fHistoTrueEtaPtY(NULL),
315         fHistoTruePi0PtAlpha(NULL),
316         fHistoTrueEtaPtAlpha(NULL),
317         fHistoTruePi0PtOpenAngle(NULL),
318         fHistoTrueEtaPtOpenAngle(NULL),
319         fHistoClusPhotonBGPt(NULL),
320         fHistoClusPhotonPlusConvBGPt(NULL),
321         fHistoTrueClusGammaPt(NULL),
322         fHistoTrueClusUnConvGammaPt(NULL),
323         fHistoTrueClusUnConvGammaMCPt(NULL),
324         fHistoTrueClusElectronPt(NULL),
325         fHistoTrueClusConvGammaPt(NULL),
326         fHistoTrueClusConvGammaMCPt(NULL),
327         fHistoTrueClusConvGammaFullyPt(NULL),
328         fHistoTrueClusMergedGammaPt(NULL),
329         fHistoTrueClusMergedPartConvGammaPt(NULL),
330         fHistoTrueClusDalitzPt(NULL),
331         fHistoTrueClusDalitzMergedPt(NULL),
332         fHistoTrueClusPhotonFromElecMotherPt(NULL),
333         fHistoTrueClusShowerPt(NULL),
334         fHistoTrueClusSubLeadingPt(NULL),
335         fHistoTrueClusNParticles(NULL),
336         fHistoTrueClusEMNonLeadingPt(NULL),
337         fHistoTrueNLabelsInClus(NULL),
338         fHistoTruePrimaryClusGammaPt(NULL),
339         fHistoTruePrimaryClusGammaESDPtMCPt(NULL),
340         fHistoTruePrimaryClusConvGammaPt(NULL),
341         fHistoTruePrimaryClusConvGammaESDPtMCPt(NULL),
342         fHistoTrueSecondaryClusGammaPt(NULL),
343         fHistoTrueSecondaryClusConvGammaPt(NULL),
344         fHistoTrueSecondaryClusGammaFromXFromK0sPt(NULL),
345         fHistoTrueSecondaryClusConvGammaFromXFromK0sPt(NULL),
346         fHistoTrueSecondaryClusGammaFromXFromLambdaPt(NULL),
347         fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt(NULL),
348         fHistoTrueSecondaryClusGammaFromXFromEtasPt(NULL),
349         fHistoTrueSecondaryClusConvGammaFromXFromEtasPt(NULL),
350         fHistoNEvents(NULL),
351         fHistoNGoodESDTracks(NULL),
352         fHistoNGammaCandidates(NULL),
353         fHistoNGoodESDTracksVsNGammaCanditates(NULL),
354         fHistoNV0Tracks(NULL),
355         fProfileEtaShift(NULL),
356         fEventPlaneAngle(-100),
357         fRandom(0),
358         fnCuts(0),
359         fiCut(0),
360         fIsHeavyIon(0),
361         fDoMesonAnalysis(kTRUE),
362         fDoMesonQA(0),
363         fDoClusterQA(0),
364         fIsFromMBHeader(kTRUE),
365         fIsMC(kFALSE)
366 {
367   // Define output slots here
368   DefineOutput(1, TList::Class());
369 }
370
371 AliAnalysisTaskGammaCalo::~AliAnalysisTaskGammaCalo()
372 {
373         if(fClusterCandidates){
374                 delete fClusterCandidates;
375                 fClusterCandidates = 0x0;
376         }
377         if(fBGHandler){
378                 delete[] fBGHandler;
379                 fBGHandler = 0x0;
380         }
381 }
382 //___________________________________________________________
383 void AliAnalysisTaskGammaCalo::InitBack(){
384         
385         const Int_t nDim = 4;
386         Int_t nBins[nDim] = {800,250,7,6};
387         Double_t xMin[nDim] = {0,0, 0,0};
388         Double_t xMax[nDim] = {0.8,25,7,6};
389         
390         fSparseMotherInvMassPtZM = new THnSparseF*[fnCuts];
391         fSparseMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
392         
393         fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
394
395         
396         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
397                 if (((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
398                         TString cutstringEvent  = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
399                         TString cutstringCalo   = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
400                         TString cutstringMeson  = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
401                         
402                         Int_t collisionSystem = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(0,1));
403                         Int_t centMin = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(1,1));
404                         Int_t centMax = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(2,1));
405                         
406                         if(collisionSystem == 1 || collisionSystem == 2 ||
407                                 collisionSystem == 5 || collisionSystem == 8 ||
408                                 collisionSystem == 9){
409                                 centMin = centMin*10;
410                                 centMax = centMax*10;
411                                 if(centMax ==0 && centMax!=centMin) centMax=100;
412                         } else if(collisionSystem == 3 || collisionSystem == 6){
413                                 centMin = centMin*5;
414                                 centMax = centMax*5;
415                         } else if(collisionSystem == 4 || collisionSystem == 7){
416                                 centMin = ((centMin*5)+45);
417                                 centMax = ((centMax*5)+45);
418                         }
419                         
420                         fBackList[iCut] = new TList();
421                         fBackList[iCut]->SetName(Form("%s_%s_%s Back histograms",cutstringEvent.Data(),cutstringCalo.Data(), cutstringMeson.Data()));
422                         fBackList[iCut]->SetOwner(kTRUE);
423                         fCutFolder[iCut]->Add(fBackList[iCut]);
424                         
425                         fSparseMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
426                         fBackList[iCut]->Add(fSparseMotherBackInvMassPtZM[iCut]);
427                         
428                         fMotherList[iCut] = new TList();
429                         fMotherList[iCut]->SetName(Form("%s_%s_%s Mother histograms",cutstringEvent.Data(),cutstringCalo.Data(),cutstringMeson.Data()));
430                         fMotherList[iCut]->SetOwner(kTRUE);
431                         fCutFolder[iCut]->Add(fMotherList[iCut]);
432                         
433                         fSparseMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
434                         fMotherList[iCut]->Add(fSparseMotherInvMassPtZM[iCut]);
435                         
436                         if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
437                                 fBGHandler[iCut] = new AliGammaConversionAODBGHandler(
438                                                                                                                                         collisionSystem,centMin,centMax,
439                                                                                                                                         ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents(),
440                                                                                                                                         ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity(),
441                                                                                                                                         4,8,7);
442                         }
443                 }
444         }
445 }
446 //________________________________________________________________________
447 void AliAnalysisTaskGammaCalo::UserCreateOutputObjects(){
448   
449         // Create histograms
450         if(fOutputContainer != NULL){
451                 delete fOutputContainer;
452                 fOutputContainer = NULL;
453         }
454         if(fOutputContainer == NULL){
455                 fOutputContainer = new TList();
456                 fOutputContainer->SetOwner(kTRUE);
457         }
458   
459         // Array of current cut's gammas
460         fClusterCandidates = new TList();
461   
462         fCutFolder = new TList*[fnCuts];
463         fESDList = new TList*[fnCuts];
464         fBackList = new TList*[fnCuts];
465         fMotherList = new TList*[fnCuts];
466         fHistoNEvents = new TH1I*[fnCuts];
467         fHistoNGoodESDTracks = new TH1I*[fnCuts];
468         fHistoNGammaCandidates = new TH1I*[fnCuts];
469         fHistoNGoodESDTracksVsNGammaCanditates = new TH2F*[fnCuts];
470         fHistoNV0Tracks = new TH1I*[fnCuts];
471         fProfileEtaShift = new TProfile*[fnCuts];
472         
473         if(fDoMesonAnalysis){
474                 fHistoMotherInvMassPt = new TH2F*[fnCuts];
475                 fHistoMotherInvMass3ClusterPt = new TH2F*[fnCuts];
476                 fHistoMotherBackInvMassPt = new TH2F*[fnCuts];
477                 fHistoMotherInvMassEalpha = new TH2F*[fnCuts];
478                 if (fDoMesonQA > 0){
479                         fHistoMotherPi0PtY =  new TH2F*[fnCuts];
480                         fHistoMotherEtaPtY =  new TH2F*[fnCuts];
481                         fHistoMotherPi0PtAlpha =  new TH2F*[fnCuts];
482                         fHistoMotherEtaPtAlpha =  new TH2F*[fnCuts];
483                         fHistoMotherPi0PtOpenAngle =  new TH2F*[fnCuts];
484                         fHistoMotherEtaPtOpenAngle =  new TH2F*[fnCuts];
485                 }
486                 if(fDoMesonQA == 1){
487                         fHistoMotherInvMassECalib = new TH2F*[fnCuts];
488                         fHistoMotherInvMassECalibalpha = new TH2F*[fnCuts];
489                 }
490         }
491                 
492         fHistoClusGammaPt = new TH1F*[fnCuts];
493         
494         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
495                 TString cutstringEvent  = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
496                 TString cutstringCalo   = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
497                 TString cutstringMeson  = "NoMesonCut";
498                 if(fDoMesonAnalysis)cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
499     
500                 fCutFolder[iCut] = new TList();
501                 fCutFolder[iCut]->SetName(Form("Cut Number %s_%s_%s",cutstringEvent.Data(),cutstringCalo.Data(),cutstringMeson.Data()));
502                 fCutFolder[iCut]->SetOwner(kTRUE);
503                 fOutputContainer->Add(fCutFolder[iCut]);
504                 fESDList[iCut] = new TList();
505                 fESDList[iCut]->SetName(Form("%s_%s_%s ESD histograms",cutstringEvent.Data(),cutstringCalo.Data(),cutstringMeson.Data()));
506                 fESDList[iCut]->SetOwner(kTRUE);
507                 fCutFolder[iCut]->Add(fESDList[iCut]);
508     
509                 fHistoNEvents[iCut] = new TH1I("NEvents","NEvents",10,-0.5,9.5);
510                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
511                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
512                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Missing MC");
513                 if (((AliConvEventCuts*)fEventCutArray->At(iCut))->IsSpecialTrigger() > 1 ){ 
514                         TString TriggerNames = "Not Trigger: ";
515                         TriggerNames = TriggerNames+ ( (AliConvEventCuts*)fEventCutArray->At(iCut))->GetSpecialTriggerName();
516                         fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(4,TriggerNames.Data());
517                 } else {
518                         fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
519                 }
520                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
521                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
522                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
523                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
524                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
525                 fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(10,"EMCAL problems");
526                 fESDList[iCut]->Add(fHistoNEvents[iCut]);
527                 
528                 if(fIsHeavyIon == 1) fHistoNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",4000,0,4000);
529                 else if(fIsHeavyIon == 2) fHistoNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",400,0,400);
530                 else fHistoNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
531                 fESDList[iCut]->Add(fHistoNGoodESDTracks[iCut]);
532                 if(fIsHeavyIon == 1) fHistoNGammaCandidates[iCut] = new TH1I("GammaCandidates","GammaCandidates",600,0,600);
533                 else if(fIsHeavyIon == 2) fHistoNGammaCandidates[iCut] = new TH1I("GammaCandidates","GammaCandidates",400,0,400);
534                 else fHistoNGammaCandidates[iCut] = new TH1I("GammaCandidates","GammaCandidates",100,0,100);
535                 fESDList[iCut]->Add(fHistoNGammaCandidates[iCut]);
536                 if(fIsHeavyIon == 1) fHistoNGoodESDTracksVsNGammaCanditates[iCut] = new TH2F("GoodESDTracksVsGammaCandidates","GoodESDTracksVsGammaCandidates",4000,0,4000,600,0,600);
537                 else if(fIsHeavyIon == 2) fHistoNGoodESDTracksVsNGammaCanditates[iCut] = new TH2F("GoodESDTracksVsGammaCandidates","GoodESDTracksVsGammaCandidates",400,0,400,400,0,400);
538                 else fHistoNGoodESDTracksVsNGammaCanditates[iCut] = new TH2F("GoodESDTracksVsGammaCandidates","GoodESDTracksVsGammaCandidates",200,0,200,100,0,100);
539                 fESDList[iCut]->Add(fHistoNGoodESDTracksVsNGammaCanditates[iCut]);
540     
541                 
542                 if(fIsHeavyIon == 1) fHistoNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
543                 else if(fIsHeavyIon == 2) fHistoNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2500,0,2500);
544                 else fHistoNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",1500,0,1500);
545                 fESDList[iCut]->Add(fHistoNV0Tracks[iCut]);
546                 fProfileEtaShift[iCut] = new TProfile("Eta Shift","Eta Shift",1, -0.5,0.5);
547                 fESDList[iCut]->Add(fProfileEtaShift[iCut]);
548     
549                 fHistoClusGammaPt[iCut] = new TH1F("ClusGamma_Pt","ClusGamma_Pt",250,0,25);
550                 fESDList[iCut]->Add(fHistoClusGammaPt[iCut]);
551
552                 
553                 if(fDoMesonAnalysis){
554                         fHistoMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt","ESD_Mother_InvMass_Pt",800,0,0.8,250,0,25);
555                         fESDList[iCut]->Add(fHistoMotherInvMassPt[iCut]);
556                         fHistoMotherInvMass3ClusterPt[iCut] = new TH2F("ESD_Mother_InvMass3Cluster_Pt","ESD_Mother_InvMass3Cluster_Pt",800,0,0.8,250,0,25);
557                         fESDList[iCut]->Add(fHistoMotherInvMass3ClusterPt[iCut]);
558                         fHistoMotherBackInvMassPt[iCut] = new TH2F("ESD_Background_InvMass_Pt","ESD_Background_InvMass_Pt",800,0,0.8,250,0,25);
559                         fESDList[iCut]->Add(fHistoMotherBackInvMassPt[iCut]);
560                         fHistoMotherInvMassEalpha[iCut] = new TH2F("ESD_Mother_InvMass_vs_E_alpha","ESD_Mother_InvMass_vs_E_alpha",800,0,0.8,250,0,25);
561                         fESDList[iCut]->Add(fHistoMotherInvMassEalpha[iCut]);
562                         if(fDoMesonQA == 1){
563                                 fHistoMotherInvMassECalib[iCut] = new TH2F("ESD_Mother_InvMass_Pt_Calib","ESD_Mother_InvMass_Pt_Calib",800,0,0.8,250,0,25);
564                                 fESDList[iCut]->Add(fHistoMotherInvMassECalib[iCut]);
565                                 fHistoMotherInvMassECalibalpha[iCut] = new TH2F("ESD_Mother_InvMass_vs_E_Calib_alpha","ESD_Mother_InvMass_vs_E_Calib_alpha",800,0,0.8,250,0,25);
566                                 fESDList[iCut]->Add(fHistoMotherInvMassECalibalpha[iCut]);
567                         }
568
569                         if (fDoMesonQA > 0 ){
570                                 fHistoMotherPi0PtY[iCut] = new TH2F("ESD_MotherPi0_Pt_Y","ESD_MotherPi0_Pt_Y",150,0.03,15.,150,-1.5,1.5);
571                                 SetLogBinningXTH2(fHistoMotherPi0PtY[iCut]);
572                                 fESDList[iCut]->Add(fHistoMotherPi0PtY[iCut]);
573                                 fHistoMotherEtaPtY[iCut] = new TH2F("ESD_MotherEta_Pt_Y","ESD_MotherEta_Pt_Y",150,0.03,15.,150,-1.5,1.5);
574                                 SetLogBinningXTH2(fHistoMotherEtaPtY[iCut]);
575                                 fESDList[iCut]->Add(fHistoMotherEtaPtY[iCut]);
576                                 fHistoMotherPi0PtAlpha[iCut] = new TH2F("ESD_MotherPi0_Pt_Alpha","ESD_MotherPi0_Pt_Alpha",150,0.03,15.,100,0,1);
577                                 SetLogBinningXTH2(fHistoMotherPi0PtAlpha[iCut]);
578                                 fESDList[iCut]->Add(fHistoMotherPi0PtAlpha[iCut]);
579                                 fHistoMotherEtaPtAlpha[iCut] = new TH2F("ESD_MotherEta_Pt_Alpha","ESD_MotherEta_Pt_Alpha",150,0.03,15.,100,0,1);
580                                 SetLogBinningXTH2(fHistoMotherEtaPtAlpha[iCut]);
581                                 fESDList[iCut]->Add(fHistoMotherEtaPtAlpha[iCut]);
582                                 fHistoMotherPi0PtOpenAngle[iCut] = new TH2F("ESD_MotherPi0_Pt_OpenAngle","ESD_MotherPi0_Pt_OpenAngle",150,0.03,15.,100,0,TMath::Pi());
583                                 SetLogBinningXTH2(fHistoMotherPi0PtOpenAngle[iCut]);
584                                 fESDList[iCut]->Add(fHistoMotherPi0PtOpenAngle[iCut]);
585                                 fHistoMotherEtaPtOpenAngle[iCut] = new TH2F("ESD_MotherEta_Pt_OpenAngle","ESD_MotherEta_Pt_OpenAngle",150,0.03,15.,100,0,TMath::Pi());
586                                 SetLogBinningXTH2(fHistoMotherEtaPtOpenAngle[iCut]);
587                                 fESDList[iCut]->Add(fHistoMotherEtaPtOpenAngle[iCut]);
588                         }
589                 }    
590         }
591         if(fDoMesonAnalysis){
592                 InitBack(); // Init Background Handler
593         }
594   
595         if(fIsMC){
596                 // MC Histogramms
597                 fMCList         = new TList*[fnCuts];
598                 // True Histogramms
599                 fTrueList       = new TList*[fnCuts];
600                 // Selected Header List
601                 fHeaderNameList                                         = new TList*[fnCuts];
602                 fHistoMCHeaders                                         = new TH1I*[fnCuts];
603                 fHistoMCAllGammaPt                                      = new TH1F*[fnCuts];
604                 fHistoMCDecayGammaPi0Pt                         = new TH1F*[fnCuts];
605                 fHistoMCDecayGammaRhoPt                         = new TH1F*[fnCuts];
606                 fHistoMCDecayGammaEtaPt                         = new TH1F*[fnCuts];
607                 fHistoMCDecayGammaOmegaPt                       = new TH1F*[fnCuts];
608                 fHistoMCDecayGammaEtapPt                        = new TH1F*[fnCuts];
609                 fHistoMCDecayGammaPhiPt                         = new TH1F*[fnCuts];
610                 fHistoMCDecayGammaSigmaPt                       = new TH1F*[fnCuts];
611         
612                 fHistoClusPhotonBGPt                                                    = new TH2F*[fnCuts];
613                 fHistoClusPhotonPlusConvBGPt                                    = new TH2F*[fnCuts];
614         
615                 fHistoTrueClusGammaPt                                                           = new TH1F*[fnCuts];
616                 fHistoTruePrimaryClusGammaPt                                            = new TH1F*[fnCuts];
617                 fHistoTruePrimaryClusGammaESDPtMCPt                             = new TH2F*[fnCuts];
618                 fHistoTruePrimaryClusConvGammaPt                                        = new TH1F*[fnCuts];
619                 fHistoTruePrimaryClusConvGammaESDPtMCPt                         = new TH2F*[fnCuts];
620                 fHistoTrueSecondaryClusGammaPt                                          = new TH1F*[fnCuts];
621                 fHistoTrueSecondaryClusConvGammaPt                                      = new TH1F*[fnCuts];
622                 fHistoTrueSecondaryClusGammaFromXFromK0sPt                      = new TH1F*[fnCuts];
623                 fHistoTrueSecondaryClusConvGammaFromXFromK0sPt          = new TH1F*[fnCuts];
624                 fHistoTrueSecondaryClusGammaFromXFromLambdaPt           = new TH1F*[fnCuts];
625                 fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt       = new TH1F*[fnCuts];
626                 fHistoTrueSecondaryClusGammaFromXFromEtasPt             = new TH1F*[fnCuts];
627                 fHistoTrueSecondaryClusConvGammaFromXFromEtasPt         = new TH1F*[fnCuts];
628     
629                 if (fDoClusterQA > 0){  
630                         fHistoTrueClusUnConvGammaPt             = new TH1F*[fnCuts];
631                         fHistoTrueClusUnConvGammaMCPt           = new TH1F*[fnCuts];
632                         fHistoTrueClusElectronPt                        = new TH1F*[fnCuts];
633                         fHistoTrueClusConvGammaPt                       = new TH1F*[fnCuts];
634                         fHistoTrueClusConvGammaMCPt                     = new TH1F*[fnCuts];
635                         fHistoTrueClusConvGammaFullyPt          = new TH1F*[fnCuts];
636                         fHistoTrueClusMergedGammaPt             = new TH1F*[fnCuts];
637                         fHistoTrueClusMergedPartConvGammaPt = new TH1F*[fnCuts];
638                         fHistoTrueClusDalitzPt                          = new TH1F*[fnCuts];
639                         fHistoTrueClusDalitzMergedPt            = new TH1F*[fnCuts];
640                         fHistoTrueClusPhotonFromElecMotherPt= new TH1F*[fnCuts];
641                         fHistoTrueClusShowerPt                          = new TH1F*[fnCuts];
642                         fHistoTrueClusSubLeadingPt                      = new TH1F*[fnCuts];
643                         fHistoTrueClusNParticles                        = new TH1I*[fnCuts];
644                         fHistoTrueClusEMNonLeadingPt            = new TH1F*[fnCuts];
645                         fHistoTrueNLabelsInClus                         = new TH1F*[fnCuts];                    
646                 }
647     
648                 if(fDoMesonAnalysis){
649                         fHistoMCPi0Pt                                   = new TH1F*[fnCuts];
650                         fHistoMCPi0WOWeightPt                   = new TH1F*[fnCuts];
651                         fHistoMCEtaPt                                   = new TH1F*[fnCuts];
652                         fHistoMCEtaWOWeightPt                   = new TH1F*[fnCuts];
653                         fHistoMCPi0InAccPt                              = new TH1F*[fnCuts];
654                         fHistoMCEtaInAccPt                              = new TH1F*[fnCuts];
655       
656                         fHistoTruePi0InvMassPt                                  = new TH2F*[fnCuts];
657                         fHistoTrueEtaInvMassPt                                  = new TH2F*[fnCuts];
658                         fHistoTruePrimaryPi0InvMassPt                   = new TH2F*[fnCuts];
659                         fHistoTruePrimaryEtaInvMassPt                   = new TH2F*[fnCuts];
660                         fHistoTruePrimaryPi0W0WeightingInvMassPt = new TH2F*[fnCuts];
661                         fHistoTruePrimaryEtaW0WeightingInvMassPt = new TH2F*[fnCuts];
662                         fProfileTruePrimaryPi0WeightsInvMassPt  = new TProfile2D*[fnCuts];
663                         fProfileTruePrimaryEtaWeightsInvMassPt  = new TProfile2D*[fnCuts];
664                         fHistoTrueSecondaryPi0InvMassPt                         = new TH2F*[fnCuts];
665                         fHistoTrueSecondaryEtaInvMassPt                         = new TH2F*[fnCuts];
666                         fHistoTrueSecondaryPi0FromK0sInvMassPt  = new TH2F*[fnCuts];
667                         fHistoTrueSecondaryPi0FromEtaInvMassPt  = new TH2F*[fnCuts];
668                         fHistoTrueSecondaryPi0FromLambdaInvMassPt = new TH2F*[fnCuts];
669                         if (fDoMesonQA > 0){
670                                 fHistoMCPi0PtY                                                          = new TH2F*[fnCuts];
671                                 fHistoMCEtaPtY                                                          = new TH2F*[fnCuts];
672                                 fHistoMCPi0PtAlpha                                                      = new TH2F*[fnCuts];
673                                 fHistoMCEtaPtAlpha                                                      = new TH2F*[fnCuts];
674                                 fHistoMCK0sPt                                                           = new TH1F*[fnCuts];
675                                 fHistoMCK0sWOWeightPt                                           = new TH1F*[fnCuts];
676                                 fHistoMCK0sPtY                                                          = new TH2F*[fnCuts];
677                                 fHistoMCSecPi0PtvsSource                                        = new TH2F*[fnCuts];
678                                 fHistoMCSecPi0Source                                            = new TH1F*[fnCuts];
679                                 fHistoMCSecEtaPt                                                        = new TH1F*[fnCuts];
680                                 fHistoMCSecEtaSource                                            = new TH1F*[fnCuts];
681                                 fHistoTruePi0CaloPhotonInvMassPt                        = new TH2F*[fnCuts];
682                                 fHistoTrueEtaCaloPhotonInvMassPt                        = new TH2F*[fnCuts];
683                                 fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt= new TH2F*[fnCuts];
684                                 fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt= new TH2F*[fnCuts];
685                                 fHistoTruePi0CaloConvertedPhotonInvMassPt       = new TH2F*[fnCuts];
686                                 fHistoTrueEtaCaloConvertedPhotonInvMassPt       = new TH2F*[fnCuts];
687                                 fHistoTruePi0CaloElectronInvMassPt              = new TH2F*[fnCuts];
688                                 fHistoTrueEtaCaloElectronInvMassPt              = new TH2F*[fnCuts];
689                                 fHistoTruePi0CaloMergedClusterInvMassPt         = new TH2F*[fnCuts];
690                                 fHistoTrueEtaCaloMergedClusterInvMassPt         = new TH2F*[fnCuts];
691                                 fHistoTruePi0CaloMergedClusterPartConvInvMassPt         = new TH2F*[fnCuts];
692                                 fHistoTrueEtaCaloMergedClusterPartConvInvMassPt         = new TH2F*[fnCuts];
693                                 fHistoTruePi0NonMergedElectronPhotonInvMassPt   = new TH2F*[fnCuts];
694                                 fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt     = new TH2F*[fnCuts];
695                                 fHistoTruePrimaryPi0MCPtResolPt                         = new TH2F*[fnCuts];
696                                 fHistoTruePrimaryEtaMCPtResolPt                         = new TH2F*[fnCuts];
697                                 fHistoTrueK0sWithPi0DaughterMCPt                        = new TH1F*[fnCuts];
698                                 fHistoTrueEtaWithPi0DaughterMCPt                        = new TH1F*[fnCuts];
699                                 fHistoTrueLambdaWithPi0DaughterMCPt             = new TH1F*[fnCuts];
700                                 fHistoTrueBckGGInvMassPt                                        = new TH2F*[fnCuts];
701                                 fHistoTrueBckContInvMassPt                                      = new TH2F*[fnCuts];
702                                 fHistoTruePi0PtY                                                        = new TH2F*[fnCuts];
703                                 fHistoTrueEtaPtY                                                        = new TH2F*[fnCuts];
704                                 fHistoTruePi0PtAlpha                                            = new TH2F*[fnCuts];
705                                 fHistoTrueEtaPtAlpha                                            = new TH2F*[fnCuts];
706                                 fHistoTruePi0PtOpenAngle                                        = new TH2F*[fnCuts];
707                                 fHistoTrueEtaPtOpenAngle                                        = new TH2F*[fnCuts];
708                         }
709                 }
710     
711     
712     
713                 for(Int_t iCut = 0; iCut<fnCuts;iCut++){
714                         TString cutstringEvent  = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
715                         TString cutstringCalo   = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
716                         TString cutstringMeson  = "NoMesonCut";
717                         if(fDoMesonAnalysis)cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
718       
719                         fMCList[iCut] = new TList();
720                         fMCList[iCut]->SetName(Form("%s_%s_%s MC histograms",cutstringEvent.Data(),cutstringCalo.Data(),cutstringMeson.Data()));
721                         fMCList[iCut]->SetOwner(kTRUE);
722                         fCutFolder[iCut]->Add(fMCList[iCut]);
723                         fHistoMCHeaders[iCut] = new TH1I("MC_Headers","MC_Headers",20,0,20);
724                         fMCList[iCut]->Add(fHistoMCHeaders[iCut]);
725                         fHistoMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
726                         fMCList[iCut]->Add(fHistoMCAllGammaPt[iCut]);
727                         fHistoMCDecayGammaPi0Pt[iCut] = new TH1F("MC_DecayGammaPi0_Pt","MC_DecayGammaPi0_Pt",250,0,25);
728                         fMCList[iCut]->Add(fHistoMCDecayGammaPi0Pt[iCut]);
729                         fHistoMCDecayGammaRhoPt[iCut] = new TH1F("MC_DecayGammaRho_Pt","MC_DecayGammaRho_Pt",250,0,25);
730                         fMCList[iCut]->Add(fHistoMCDecayGammaRhoPt[iCut]);
731                         fHistoMCDecayGammaEtaPt[iCut] = new TH1F("MC_DecayGammaEta_Pt","MC_DecayGammaEta_Pt",250,0,25);
732                         fMCList[iCut]->Add(fHistoMCDecayGammaEtaPt[iCut]);
733                         fHistoMCDecayGammaOmegaPt[iCut] = new TH1F("MC_DecayGammaOmega_Pt","MC_DecayGammaOmmega_Pt",250,0,25);
734                         fMCList[iCut]->Add(fHistoMCDecayGammaOmegaPt[iCut]);
735                         fHistoMCDecayGammaEtapPt[iCut] = new TH1F("MC_DecayGammaEtap_Pt","MC_DecayGammaEtap_Pt",250,0,25);
736                         fMCList[iCut]->Add(fHistoMCDecayGammaEtapPt[iCut]);
737                         fHistoMCDecayGammaPhiPt[iCut] = new TH1F("MC_DecayGammaPhi_Pt","MC_DecayGammaPhi_Pt",250,0,25);
738                         fMCList[iCut]->Add(fHistoMCDecayGammaPhiPt[iCut]);
739                         fHistoMCDecayGammaSigmaPt[iCut] = new TH1F("MC_DecayGammaSigma_Pt","MC_DecayGammaSigma_Pt",250,0,25);
740                         fMCList[iCut]->Add(fHistoMCDecayGammaSigmaPt[iCut]);
741                         
742                         if(fDoMesonAnalysis){
743                                 fHistoMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
744                                 fHistoMCPi0Pt[iCut]->Sumw2();
745                                 fMCList[iCut]->Add(fHistoMCPi0Pt[iCut]);
746                                 fHistoMCPi0WOWeightPt[iCut] = new TH1F("MC_Pi0_WOWeights_Pt","MC_Pi0_WOWeights_Pt",250,0,25);
747                                 fHistoMCPi0WOWeightPt[iCut]->Sumw2();
748                                 fMCList[iCut]->Add(fHistoMCPi0WOWeightPt[iCut]);
749                                 
750                                 fHistoMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
751                                 fHistoMCEtaPt[iCut]->Sumw2();
752                                 fMCList[iCut]->Add(fHistoMCEtaPt[iCut]);
753                                 fHistoMCEtaWOWeightPt[iCut] = new TH1F("MC_Eta_WOWeights_Pt","MC_Eta_WOWeights_Pt",250,0,25);
754                                 fHistoMCEtaWOWeightPt[iCut]->Sumw2();
755                                 fMCList[iCut]->Add(fHistoMCEtaWOWeightPt[iCut]);
756                                 fHistoMCPi0InAccPt[iCut] = new TH1F("MC_Pi0InAcc_Pt","MC_Pi0InAcc_Pt",250,0,25);
757                                 fHistoMCPi0InAccPt[iCut]->Sumw2();
758                                 fMCList[iCut]->Add(fHistoMCPi0InAccPt[iCut]);
759                                 fHistoMCEtaInAccPt[iCut] = new TH1F("MC_EtaInAcc_Pt","MC_EtaInAcc_Pt",250,0,25);
760                                 fHistoMCEtaInAccPt[iCut]->Sumw2();
761                                 fMCList[iCut]->Add(fHistoMCEtaInAccPt[iCut]);
762                                 if (fDoMesonQA > 0){
763                                         fHistoMCPi0PtY[iCut] = new TH2F("MC_Pi0_Pt_Y","MC_Pi0_Pt_Y",150,0.03,15.,150,-1.5,1.5);
764                                         fHistoMCPi0PtY[iCut]->Sumw2();
765                                         SetLogBinningXTH2(fHistoMCPi0PtY[iCut]);
766                                         fMCList[iCut]->Add(fHistoMCPi0PtY[iCut]);
767                                         fHistoMCEtaPtY[iCut] = new TH2F("MC_Eta_Pt_Y","MC_Eta_Pt_Y",150,0.03,15.,150,-1.5,1.5);
768                                         fHistoMCEtaPtY[iCut]->Sumw2();
769                                         SetLogBinningXTH2(fHistoMCEtaPtY[iCut]);
770                                         fMCList[iCut]->Add(fHistoMCEtaPtY[iCut]);
771                                         fHistoMCPi0PtAlpha[iCut] = new TH2F("MC_Pi0_Pt_Alpha","MC_Pi0_Pt_Alpha",150,0.03,15.,100,0,1);
772                                         SetLogBinningXTH2(fHistoMCPi0PtAlpha[iCut]);
773                                         fMCList[iCut]->Add(fHistoMCPi0PtAlpha[iCut]);
774                                         fHistoMCEtaPtAlpha[iCut] = new TH2F("MC_Eta_Pt_Alpha","MC_Eta_Pt_Alpha",150,0.03,15.,100,0,1);
775                                         SetLogBinningXTH2(fHistoMCEtaPtAlpha[iCut]);
776                                         fMCList[iCut]->Add(fHistoMCEtaPtAlpha[iCut]);
777
778                                         fHistoMCK0sPt[iCut] = new TH1F("MC_K0s_Pt","MC_K0s_Pt",150,0,15);
779                                         fHistoMCK0sPt[iCut]->Sumw2();
780                                         fMCList[iCut]->Add(fHistoMCK0sPt[iCut]);
781                                         fHistoMCK0sWOWeightPt[iCut] = new TH1F("MC_K0s_WOWeights_Pt","MC_K0s_WOWeights_Pt",150,0,15);
782                                         fHistoMCK0sWOWeightPt[iCut]->Sumw2();
783                                         fMCList[iCut]->Add(fHistoMCK0sWOWeightPt[iCut]);
784                                         fHistoMCK0sPtY[iCut] = new TH2F("MC_K0s_Pt_Y","MC_K0s_Pt_Y",150,0.03,15.,150,-1.5,1.5);
785                                         fHistoMCK0sPtY[iCut]->Sumw2();
786                                         SetLogBinningXTH2(fHistoMCK0sPtY[iCut]);
787                                         fMCList[iCut]->Add(fHistoMCK0sPtY[iCut]);
788                                         
789                                         fHistoMCSecPi0Source[iCut] = new TH1F("MC_SecPi0_Source","MC_SecPi0_Source",5000,0.,5000);
790                                         fMCList[iCut]->Add(fHistoMCSecPi0Source[iCut]);
791                                         fHistoMCSecEtaSource[iCut] = new TH1F("MC_SecEta_Source","MC_SecEta_Source",5000,0,5000);
792                                         fMCList[iCut]->Add(fHistoMCSecEtaSource[iCut]);
793                                         fHistoMCSecPi0PtvsSource[iCut] = new TH2F("MC_SecPi0_Pt_Source","MC_SecPi0_Pt_Source",250,0.0,25.,16,-0.5,15.5);
794                                         fHistoMCSecPi0PtvsSource[iCut]->Sumw2();
795                                         fMCList[iCut]->Add(fHistoMCSecPi0PtvsSource[iCut]);
796                                         fHistoMCSecEtaPt[iCut] = new TH1F("MC_SecEta_Pt","MC_SecEta_Pt",250,0,25);
797                                         fHistoMCSecEtaPt[iCut]->Sumw2();
798                                         fMCList[iCut]->Add(fHistoMCSecEtaPt[iCut]);
799                                 }
800         
801                         }
802                         fTrueList[iCut] = new TList();
803                         fTrueList[iCut]->SetName(Form("%s_%s_%s True histograms",cutstringEvent.Data(),cutstringCalo.Data(),cutstringMeson.Data()));
804                         fTrueList[iCut]->SetOwner(kTRUE);
805                         fCutFolder[iCut]->Add(fTrueList[iCut]);
806                   
807                         fHistoClusPhotonBGPt[iCut] = new TH2F("ESD_TrueClusPhotonBG_Pt","ESD_TrueClusPhotonBG_Pt",250,0,25,9,-0.5,8.5);
808                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 1,"Elec");
809                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 2,"Pion");
810                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 3,"Proton");
811                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 4,"Kaon");
812                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 5,"Neutron");
813                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 6,"K0s");
814                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 7,"Lambda");
815                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel( 8,"Muon");
816                         fHistoClusPhotonBGPt[iCut]->GetYaxis()->SetBinLabel(9,"Rest");
817                         fTrueList[iCut]->Add(fHistoClusPhotonBGPt[iCut]);
818                         fHistoClusPhotonPlusConvBGPt[iCut] = new TH2F("ESD_TrueClusPhotonPlusConvBG_Pt","ESD_TrueClusPhotonPlusConvBG_Pt",250,0,25,9,-0.5,8.5);
819                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 1,"Elec");
820                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 2,"Pion");
821                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 3,"Proton");
822                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 4,"Kaon");
823                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 5,"Neutron");
824                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 6,"K0s");
825                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 7,"Lambda");
826                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel( 8,"Muon");
827                         fHistoClusPhotonPlusConvBGPt[iCut]->GetYaxis()->SetBinLabel(9,"Rest");
828                         fTrueList[iCut]->Add(fHistoClusPhotonPlusConvBGPt[iCut]);
829                 
830                         fHistoTrueClusGammaPt[iCut] = new TH1F("TrueClusGamma_Pt","ESD_TrueClusGamma_Pt",250,0,25);
831                         fTrueList[iCut]->Add(fHistoTrueClusGammaPt[iCut]);
832                         fHistoTruePrimaryClusGammaPt[iCut] = new TH1F("TruePrimaryClusGamma_Pt","ESD_TruePrimaryClusGamma_Pt",250,0,25);
833                         fTrueList[iCut]->Add(fHistoTruePrimaryClusGammaPt[iCut]);
834                         fHistoTruePrimaryClusGammaESDPtMCPt[iCut] = new TH2F("TruePrimaryClusGamma_Pt_MCPt","ESD_TruePrimaryClusGamma_MCPt",250,0,25,250,0,25);
835                         fTrueList[iCut]->Add(fHistoTruePrimaryClusGammaESDPtMCPt[iCut]);
836                         fHistoTruePrimaryClusConvGammaPt[iCut] = new TH1F("TruePrimaryClusConvGamma_Pt","ESD_TruePrimaryClusConvGamma_Pt",250,0,25);
837                         fTrueList[iCut]->Add(fHistoTruePrimaryClusConvGammaPt[iCut]);
838                         fHistoTruePrimaryClusConvGammaESDPtMCPt[iCut] = new TH2F("TruePrimaryClusConvGamma_Pt_MCPt","ESD_TruePrimaryClusConvGamma_MCPt",250,0,25,250,0,25);
839                         fTrueList[iCut]->Add(fHistoTruePrimaryClusConvGammaESDPtMCPt[iCut]);
840                         fHistoTrueSecondaryClusGammaPt[iCut] = new TH1F("ESD_TrueSecondaryClusGamma_Pt","ESD_TrueSecondaryClusGamma_Pt",250,0,25);
841                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusGammaPt[iCut]);      
842                         fHistoTrueSecondaryClusConvGammaPt[iCut] = new TH1F("ESD_TrueSecondaryClusConvGamma_Pt","ESD_TrueSecondaryClusConvGamma_Pt",250,0,25);
843                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusConvGammaPt[iCut]);      
844
845                         fHistoTrueSecondaryClusGammaFromXFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryClusGammaFromXFromK0s_Pt", "ESD_TrueSecondaryClusGammaFromXFromK0s_Pt",250,0,25);
846                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusGammaFromXFromK0sPt[iCut]);
847                         fHistoTrueSecondaryClusConvGammaFromXFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryClusConvGammaFromXFromK0s_Pt", "ESD_TrueSecondaryClusConvGammaFromXFromK0s_Pt",250,0,25);
848                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusConvGammaFromXFromK0sPt[iCut]);
849                         fHistoTrueSecondaryClusGammaFromXFromLambdaPt[iCut] = new TH1F("ESD_TrueSecondaryClusGammaFromXFromLambda_Pt", "ESD_TrueSecondaryClusGammaFromXFromLambda_Pt",250,0,25);
850                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusGammaFromXFromLambdaPt[iCut]);
851                         fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt[iCut] = new TH1F("ESD_TrueSecondaryClusConvGammaFromXFromLambda_Pt", "ESD_TrueSecondaryClusConvGammaFromXFromLambda_Pt",250,0,25);
852                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt[iCut]);
853                         fHistoTrueSecondaryClusGammaFromXFromEtasPt[iCut] = new TH1F("ESD_TrueSecondaryClusGammaFromXFromEtas_Pt", "ESD_TrueSecondaryClusGammaFromXFromEtas_Pt",250,0,25);
854                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusGammaFromXFromEtasPt[iCut]);
855                         fHistoTrueSecondaryClusConvGammaFromXFromEtasPt[iCut] = new TH1F("ESD_TrueSecondaryClusConvGammaFromXFromEtas_Pt", "ESD_TrueSecondaryClusConvGammaFromXFromEtas_Pt",250,0,25);
856                         fTrueList[iCut]->Add(fHistoTrueSecondaryClusConvGammaFromXFromEtasPt[iCut]);
857
858                         
859                         if (fDoClusterQA > 0){  
860                                 fHistoTrueClusUnConvGammaPt[iCut] = new TH1F("TrueClusUnConvGamma_Pt","TrueClusUnConvGamma_Pt",250,0,25);
861                                 fTrueList[iCut]->Add(fHistoTrueClusUnConvGammaPt[iCut]);
862                                 fHistoTrueClusUnConvGammaMCPt[iCut] = new TH1F("TrueClusUnConvGamma_MCPt","TrueClusUnConvGamma_MCPt",250,0,25);
863                                 fTrueList[iCut]->Add(fHistoTrueClusUnConvGammaMCPt[iCut]);
864                                 fHistoTrueClusElectronPt[iCut] = new TH1F("TrueClusElectron_Pt","TrueElectronGamma_Pt",250,0,25);
865                                 fTrueList[iCut]->Add(fHistoTrueClusElectronPt[iCut]);
866                                 fHistoTrueClusConvGammaPt[iCut] = new TH1F("TrueClusConvGamma_Pt","TrueClusConvGamma_Pt",250,0,25);
867                                 fTrueList[iCut]->Add(fHistoTrueClusConvGammaPt[iCut]);
868                                 fHistoTrueClusConvGammaMCPt[iCut] = new TH1F("TrueClusConvGamma_MCPt","TrueClusConvGamma_MCPt",250,0,25);
869                                 fTrueList[iCut]->Add(fHistoTrueClusConvGammaMCPt[iCut]);
870                                 fHistoTrueClusConvGammaFullyPt[iCut] = new TH1F("TrueClusConvGammaFullyContained_Pt","TrueClusConvGammaFullyContained_Pt",250,0,25);
871                                 fTrueList[iCut]->Add(fHistoTrueClusConvGammaFullyPt[iCut]);
872                                 fHistoTrueClusMergedGammaPt[iCut] = new TH1F("TrueClusMergedGamma_Pt","TrueClusMergedGamma_Pt",250,0,25);
873                                 fTrueList[iCut]->Add(fHistoTrueClusMergedGammaPt[iCut]);
874                                 fHistoTrueClusMergedPartConvGammaPt[iCut] = new TH1F("TrueClusMergedPartConvGamma_Pt","TrueClusMergedPartConvGamma_Pt",250,0,25);
875                                 fTrueList[iCut]->Add(fHistoTrueClusMergedPartConvGammaPt[iCut]);
876                                 fHistoTrueClusDalitzPt[iCut] = new TH1F("TrueClusDalitz_Pt","TrueClusDalitz_Pt",250,0,25);
877                                 fTrueList[iCut]->Add(fHistoTrueClusDalitzPt[iCut]);
878                                 fHistoTrueClusDalitzMergedPt[iCut] = new TH1F("TrueClusDalitzMerged_Pt","TrueClusDalitzMerged_Pt",250,0,25);
879                                 fTrueList[iCut]->Add(fHistoTrueClusDalitzMergedPt[iCut]);
880                                 fHistoTrueClusPhotonFromElecMotherPt[iCut] = new TH1F("TrueClusPhotonFromElecMother_Pt","TrueClusPhotonFromElecMother_Pt",250,0,25);
881                                 fTrueList[iCut]->Add(fHistoTrueClusPhotonFromElecMotherPt[iCut]);
882                                 fHistoTrueClusShowerPt[iCut] = new TH1F("TrueClusShower_Pt","TrueClusShower_Pt",250,0,25);
883                                 fTrueList[iCut]->Add(fHistoTrueClusShowerPt[iCut]);
884                                 fHistoTrueClusSubLeadingPt[iCut] = new TH1F("TrueClusSubleading_Pt","TrueClusSubleading_Pt",250,0,25);
885                                 fTrueList[iCut]->Add(fHistoTrueClusSubLeadingPt[iCut]);
886                                 fHistoTrueClusNParticles[iCut] = new TH1I("TrueClusNParticles","TrueClusNParticles",20,0,20);
887                                 fTrueList[iCut]->Add(fHistoTrueClusNParticles[iCut]);
888                                 fHistoTrueClusEMNonLeadingPt[iCut] = new TH1F("TrueClusEMNonLeading_Pt","TrueClusEMNonLeading_Pt",250,0,25);
889                                 fTrueList[iCut]->Add(fHistoTrueClusEMNonLeadingPt[iCut]);
890                                 fHistoTrueNLabelsInClus[iCut] = new TH1F("TrueNLabelsInClus","TrueNLabelsInClus",100,-0.5,99.5);
891                                 fTrueList[iCut]->Add(fHistoTrueNLabelsInClus[iCut]);    
892                         }       
893
894                         if(fDoMesonAnalysis){
895                                 fHistoTruePi0InvMassPt[iCut] = new TH2F("ESD_TruePi0_InvMass_Pt","ESD_TruePi0_InvMass_Pt",800,0,0.8,250,0,25);
896                                 fTrueList[iCut]->Add(fHistoTruePi0InvMassPt[iCut]);
897                                 fHistoTrueEtaInvMassPt[iCut] = new TH2F("ESD_TrueEta_InvMass_Pt","ESD_TrueEta_InvMass_Pt",800,0,0.8,250,0,25);
898                                 fTrueList[iCut]->Add(fHistoTrueEtaInvMassPt[iCut]);
899
900                                 fHistoTruePrimaryPi0InvMassPt[iCut] = new TH2F("ESD_TruePrimaryPi0_InvMass_Pt", "ESD_TruePrimaryPi0_InvMass_Pt", 800,0,0.8,250,0,25);
901                                 fHistoTruePrimaryPi0InvMassPt[iCut]->Sumw2();
902                                 fTrueList[iCut]->Add(fHistoTruePrimaryPi0InvMassPt[iCut]);
903                                 fHistoTruePrimaryEtaInvMassPt[iCut] = new TH2F("ESD_TruePrimaryEta_InvMass_Pt", "ESD_TruePrimaryEta_InvMass_Pt", 800,0,0.8,250,0,25);
904                                 fHistoTruePrimaryEtaInvMassPt[iCut]->Sumw2();
905                                 fTrueList[iCut]->Add(fHistoTruePrimaryEtaInvMassPt[iCut]);
906
907                                 fHistoTruePrimaryPi0W0WeightingInvMassPt[iCut] = new TH2F("ESD_TruePrimaryPi0W0Weights_InvMass_Pt", "ESD_TruePrimaryPi0W0Weights_InvMass_Pt", 800,0,0.8,250,0,25);
908                                 fHistoTruePrimaryPi0W0WeightingInvMassPt[iCut]->Sumw2();
909                                 fTrueList[iCut]->Add(fHistoTruePrimaryPi0W0WeightingInvMassPt[iCut]);
910                                 fHistoTruePrimaryEtaW0WeightingInvMassPt[iCut] = new TH2F("ESD_TruePrimaryEtaW0Weights_InvMass_Pt", "ESD_TruePrimaryEtaW0Weights_InvMass_Pt", 800,0,0.8,250,0,25);
911                                 fHistoTruePrimaryEtaW0WeightingInvMassPt[iCut]->Sumw2();
912                                 fTrueList[iCut]->Add(fHistoTruePrimaryEtaW0WeightingInvMassPt[iCut]);
913
914                                 fProfileTruePrimaryPi0WeightsInvMassPt[iCut] = new TProfile2D("ESD_TruePrimaryPi0Weights_InvMass_Pt", "ESD_TruePrimaryPi0Weights_InvMass_Pt", 800,0,0.8,250,0,25);
915                                 fProfileTruePrimaryPi0WeightsInvMassPt[iCut]->Sumw2();
916                                 fTrueList[iCut]->Add(fProfileTruePrimaryPi0WeightsInvMassPt[iCut]);
917                                 fProfileTruePrimaryEtaWeightsInvMassPt[iCut] = new TProfile2D("ESD_TruePrimaryEtaWeights_InvMass_Pt", "ESD_TruePrimaryEtaWeights_InvMass_Pt", 800,0,0.8,250,0,25);
918                                 fProfileTruePrimaryEtaWeightsInvMassPt[iCut]->Sumw2();
919                                 fTrueList[iCut]->Add(fProfileTruePrimaryEtaWeightsInvMassPt[iCut]);
920
921                                 fHistoTrueSecondaryPi0InvMassPt[iCut] = new TH2F("ESD_TrueSecondaryPi0_InvMass_Pt", "ESD_TrueSecondaryPi0_InvMass_Pt", 800,0,0.8,250,0,25);
922                                 fHistoTrueSecondaryPi0InvMassPt[iCut]->Sumw2();
923                                 fTrueList[iCut]->Add(fHistoTrueSecondaryPi0InvMassPt[iCut]);
924                                 fHistoTrueSecondaryEtaInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryEta_InvMass_Pt", "ESD_TrueSecondaryEta_InvMass_Pt", 800,0,0.8,250,0,25);
925                                 fHistoTrueSecondaryEtaInvMassPt[iCut]->Sumw2();
926                                 fTrueList[iCut]->Add(fHistoTrueSecondaryEtaInvMassPt[iCut]);
927
928                                 fHistoTrueSecondaryPi0FromK0sInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryPi0FromK0s_InvMass_Pt","ESD_TrueSecondaryPi0FromK0s_InvMass_Pt",800,0,0.8,250,0,25);
929                                 fHistoTrueSecondaryPi0FromK0sInvMassPt[iCut]->Sumw2();
930                                 fTrueList[iCut]->Add(fHistoTrueSecondaryPi0FromK0sInvMassPt[iCut]);
931                                 fHistoTrueSecondaryPi0FromEtaInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryPi0FromEta_InvMass_Pt","ESD_TrueSecondaryPi0FromEta_InvMass_Pt",800,0,0.8,250,0,25);
932                                 fTrueList[iCut]->Add(fHistoTrueSecondaryPi0FromEtaInvMassPt[iCut]);
933                                 fHistoTrueSecondaryPi0FromLambdaInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryPi0FromLambda_InvMass_Pt","ESD_TrueSecondaryPi0FromLambda_InvMass_Pt",800,0,0.8,250,0,25);
934                                 fTrueList[iCut]->Add(fHistoTrueSecondaryPi0FromLambdaInvMassPt[iCut]);
935                                 if (fDoMesonQA > 0){
936                                         fHistoTruePi0CaloPhotonInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloPhoton_InvMass_Pt","ESD_TruePi0CaloPhoton_InvMass_Pt",800,0,0.8,250,0,25);
937                                         fTrueList[iCut]->Add(fHistoTruePi0CaloPhotonInvMassPt[iCut]);
938                                         fHistoTrueEtaCaloPhotonInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloPhoton_InvMass_Pt","ESD_TrueEtaCaloPhoton_InvMass_Pt",800,0,0.8,250,0,25);
939                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloPhotonInvMassPt[iCut]);
940
941                                         fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloMixedPhotonConvertedPhoton_InvMass_Pt","ESD_TruePi0CaloMixedPhotonConvertedPhoton_InvMass_Pt",800,0,0.8,250,0,25);
942                                         fTrueList[iCut]->Add(fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt[iCut]);
943                                         fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloMixedPhotonConvertedPhoton_InvMass_Pt","ESD_TrueEtaCaloMixedPhotonConvertedPhoton_InvMass_Pt",800,0,0.8,250,0,25);
944                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt[iCut]);
945
946                                         fHistoTruePi0CaloConvertedPhotonInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloConvertedPhoton_InvMass_Pt","ESD_TruePi0CaloConvertedPhoton_InvMass_Pt",800,0,0.8,250,0,25);
947                                         fTrueList[iCut]->Add(fHistoTruePi0CaloConvertedPhotonInvMassPt[iCut]);
948                                         fHistoTrueEtaCaloConvertedPhotonInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloConvertedPhoton_InvMass_Pt","ESD_TrueEtaCaloConvertedPhoton_InvMass_Pt",800,0,0.8,250,0,25);
949                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloConvertedPhotonInvMassPt[iCut]);
950
951                                         fHistoTruePi0CaloElectronInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloElectron_InvMass_Pt","ESD_TruePi0CaloElectron_InvMass_Pt",800,0,0.8,250,0,25);
952                                         fTrueList[iCut]->Add(fHistoTruePi0CaloElectronInvMassPt[iCut]);
953                                         fHistoTrueEtaCaloElectronInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloElectron_InvMass_Pt","ESD_TrueEtaCaloElectron_InvMass_Pt",800,0,0.8,250,0,25);
954                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloElectronInvMassPt[iCut]);
955
956                                         fHistoTruePi0CaloMergedClusterInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloMergedCluster_InvMass_Pt","ESD_TruePi0CaloMergedCluster_InvMass_Pt",800,0,0.8,250,0,25);
957                                         fTrueList[iCut]->Add(fHistoTruePi0CaloMergedClusterInvMassPt[iCut]);
958                                         fHistoTrueEtaCaloMergedClusterInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloMergedCluster_InvMass_Pt","ESD_TrueEtaCaloMergedCluster_InvMass_Pt",800,0,0.8,250,0,25);
959                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloMergedClusterInvMassPt[iCut]);
960
961                                         fHistoTruePi0CaloMergedClusterPartConvInvMassPt[iCut] = new TH2F("ESD_TruePi0CaloMergedClusterPartConv_InvMass_Pt","ESD_TruePi0CaloMergedClusterPartConv_InvMass_Pt",800,0,0.8,250,0,25);
962                                         fTrueList[iCut]->Add(fHistoTruePi0CaloMergedClusterPartConvInvMassPt[iCut]);
963                                         fHistoTrueEtaCaloMergedClusterPartConvInvMassPt[iCut] = new TH2F("ESD_TrueEtaCaloMergedClusterPartConv_InvMass_Pt","ESD_TrueEtaCaloMergedClusterPartConv_InvMass_Pt",800,0,0.8,250,0,25);
964                                         fTrueList[iCut]->Add(fHistoTrueEtaCaloMergedClusterPartConvInvMassPt[iCut]);
965
966                                         fHistoTruePi0NonMergedElectronPhotonInvMassPt[iCut] = new TH2F("ESD_TruePi0NonMergedElectronPhoton_InvMass_Pt","ESD_TruePi0NonMergedElectronPhoton_InvMass_Pt",800,0,0.8,250,0,25);
967                                         fTrueList[iCut]->Add(fHistoTruePi0NonMergedElectronPhotonInvMassPt[iCut]);
968                                         fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt[iCut] = new TH2F("ESD_TruePi0NonMergedElectronMergedPhoton_InvMass_Pt","ESD_TruePi0NonMergedElectronMergedPhoton_InvMass_Pt",800,0,0.8,250,0,25);
969                                         fTrueList[iCut]->Add(fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt[iCut]);
970                                         
971                                         fHistoTruePrimaryPi0MCPtResolPt[iCut] = new TH2F("ESD_TruePrimaryPi0_MCPt_ResolPt","ESD_TruePrimaryPi0_ResolPt_MCPt",500,0.03,25,1000,-1.,1.);
972                                         fHistoTruePrimaryPi0MCPtResolPt[iCut]->Sumw2();
973                                         SetLogBinningXTH2(fHistoTruePrimaryPi0MCPtResolPt[iCut]);
974                                         fTrueList[iCut]->Add(fHistoTruePrimaryPi0MCPtResolPt[iCut]);
975                                         fHistoTruePrimaryEtaMCPtResolPt[iCut]  = new TH2F("ESD_TruePrimaryEta_MCPt_ResolPt","ESD_TruePrimaryEta_ResolPt_MCPt",500,0.03,25,1000,-1.,1.);
976                                         fHistoTruePrimaryEtaMCPtResolPt[iCut]->Sumw2();
977                                         SetLogBinningXTH2(fHistoTruePrimaryEtaMCPtResolPt[iCut]);
978                                         fTrueList[iCut]->Add(fHistoTruePrimaryEtaMCPtResolPt[iCut]);
979                                         fHistoTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt","ESD_TrueBckGG_InvMass_Pt",800,0,0.8,250,0,25);
980                                         fTrueList[iCut]->Add(fHistoTrueBckGGInvMassPt[iCut]);
981                                         fHistoTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueBckCont_InvMass_Pt","ESD_TrueBckCont_InvMass_Pt",800,0,0.8,250,0,25);
982                                         fTrueList[iCut]->Add(fHistoTrueBckContInvMassPt[iCut]);
983                                         fHistoTrueK0sWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueK0sWithPi0Daughter_MCPt","ESD_TrueK0sWithPi0Daughter_MCPt",250,0,25);
984                                         fTrueList[iCut]->Add(fHistoTrueK0sWithPi0DaughterMCPt[iCut]);
985                                         fHistoTrueEtaWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueEtaWithPi0Daughter_MCPt","ESD_TrueEtaWithPi0Daughter_MCPt",250,0,25);
986                                         fTrueList[iCut]->Add(fHistoTrueEtaWithPi0DaughterMCPt[iCut]);
987                                         fHistoTrueLambdaWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueLambdaWithPi0Daughter_MCPt","ESD_TrueLambdaWithPi0Daughter_MCPt",250,0,25);
988                                         fTrueList[iCut]->Add(fHistoTrueLambdaWithPi0DaughterMCPt[iCut]);
989           
990                                         fHistoTruePi0PtY[iCut] = new TH2F("ESD_TruePi0_Pt_Y","ESD_TruePi0_Pt_Y",150,0.03,15.,150,-1.5,1.5);
991                                         SetLogBinningXTH2(fHistoTruePi0PtY[iCut]);
992                                         fTrueList[iCut]->Add(fHistoTruePi0PtY[iCut]);
993                                         fHistoTrueEtaPtY[iCut] = new TH2F("ESD_TrueEta_Pt_Y","ESD_TrueEta_Pt_Y",150,0.03,15.,150,-1.5,1.5);
994                                         SetLogBinningXTH2(fHistoTrueEtaPtY[iCut]);
995                                         fTrueList[iCut]->Add(fHistoTrueEtaPtY[iCut]);
996                                         fHistoTruePi0PtAlpha[iCut] = new TH2F("ESD_TruePi0_Pt_Alpha","ESD_TruePi0_Pt_Alpha",150,0.03,15.,100,0,1);
997                                         SetLogBinningXTH2(fHistoTruePi0PtAlpha[iCut]);
998                                         fTrueList[iCut]->Add(fHistoTruePi0PtAlpha[iCut]);
999                                         fHistoTrueEtaPtAlpha[iCut] = new TH2F("ESD_TrueEta_Pt_Alpha","ESD_TrueEta_Pt_Alpha",150,0.03,15.,100,0,1);
1000                                         SetLogBinningXTH2(fHistoTrueEtaPtAlpha[iCut]);
1001                                         fTrueList[iCut]->Add(fHistoTrueEtaPtAlpha[iCut]);
1002                                         
1003                                         fHistoTruePi0PtOpenAngle[iCut] = new TH2F("ESD_TruePi0_Pt_OpenAngle","ESD_TruePi0_Pt_OpenAngle",150,0.03,15.,200,0,2*TMath::Pi());
1004                                         SetLogBinningXTH2(fHistoTruePi0PtOpenAngle[iCut]);
1005                                         fTrueList[iCut]->Add(fHistoTruePi0PtOpenAngle[iCut]);
1006                                         fHistoTrueEtaPtOpenAngle[iCut] = new TH2F("ESD_TrueEta_Pt_OpenAngle","ESD_TrueEta_Pt_OpenAngle",150,0.03,15.,200,0,2*TMath::Pi());
1007                                         SetLogBinningXTH2(fHistoTrueEtaPtOpenAngle[iCut]);
1008                                         fTrueList[iCut]->Add(fHistoTrueEtaPtOpenAngle[iCut]);
1009                                 }
1010                         }
1011                 }
1012         }  
1013     
1014         fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
1015         if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
1016   
1017         if(fV0Reader)
1018                 if((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())
1019                         if(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms())
1020                                 fOutputContainer->Add(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
1021         if(fV0Reader)
1022                 if((AliConvEventCuts*)fV0Reader->GetEventCuts())
1023                         if(((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetCutHistograms())
1024                                 fOutputContainer->Add(((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetCutHistograms());
1025
1026                         
1027         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1028                 if(!((AliConvEventCuts*)fEventCutArray->At(iCut))) continue;
1029                 if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutHistograms()){
1030                         fCutFolder[iCut]->Add(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutHistograms());
1031                 }
1032                 if(!((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))) continue;
1033                 if(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutHistograms()){
1034                         fCutFolder[iCut]->Add(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutHistograms());
1035                 }
1036                 if(fDoMesonAnalysis){
1037                         if(!((AliConversionMesonCuts*)fMesonCutArray->At(iCut))) continue;
1038                         if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms()){
1039                                 fCutFolder[iCut]->Add(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms());
1040                         }
1041                 }
1042         }
1043         PostData(1, fOutputContainer);
1044 }
1045 //_____________________________________________________________________________
1046 Bool_t AliAnalysisTaskGammaCalo::Notify()
1047 {
1048         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1049                 if(!((AliConvEventCuts*)fEventCutArray->At(iCut))->GetDoEtaShift()){
1050                         fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1051                         continue; // No Eta Shift requested, continue
1052                 }
1053                 if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
1054                         ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
1055                         fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1056                         ((AliConvEventCuts*)fEventCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
1057                         continue;
1058                 }
1059                 else{
1060                         printf(" Gamma Conversion Task %s :: Eta Shift Manually Set to %f \n\n",
1061                                         (((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber()).Data(),((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift());
1062                         fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1063                         ((AliConvEventCuts*)fEventCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
1064                 }
1065         }
1066         
1067         return kTRUE;
1068 }
1069 //_____________________________________________________________________________
1070 void AliAnalysisTaskGammaCalo::UserExec(Option_t *)
1071 {
1072         //
1073         // Called for each event
1074         //
1075         Int_t eventQuality = ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEventQuality();
1076         if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
1077                 for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1078                 fHistoNEvents[iCut]->Fill(eventQuality);
1079                 }
1080                 return;
1081         }
1082         
1083         if(fIsMC) fMCEvent = MCEvent();
1084         if(fMCEvent == NULL) fIsMC = kFALSE;
1085         
1086         fInputEvent = InputEvent();
1087         
1088         if(fIsMC && fInputEvent->IsA()==AliESDEvent::Class()){
1089                 fMCStack = fMCEvent->Stack();
1090                 if(fMCStack == NULL) fIsMC = kFALSE;
1091         }
1092         
1093         // ------------------- BeginEvent ----------------------------
1094         
1095         AliEventplane *EventPlane = fInputEvent->GetEventplane();
1096         if(fIsHeavyIon ==1)fEventPlaneAngle = EventPlane->GetEventplane("V0",fInputEvent,2);
1097         else fEventPlaneAngle=0.0;
1098         
1099         for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1100                 
1101                 fiCut = iCut;
1102                 
1103                 Bool_t isRunningEMCALrelAna = kFALSE;
1104                 if (((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->GetClusterType() == 1) isRunningEMCALrelAna = kTRUE;
1105                 
1106                 Int_t eventNotAccepted = ((AliConvEventCuts*)fEventCutArray->At(iCut))->IsEventAcceptedByCut(fV0Reader->GetEventCuts(),fInputEvent,fMCEvent,fIsHeavyIon, isRunningEMCALrelAna);
1107                 
1108                 if(eventNotAccepted){
1109                 // cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
1110                         fHistoNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
1111                         continue;
1112                 }
1113
1114                 if(eventQuality != 0){// Event Not Accepted
1115                         //cout << "event rejected due to: " <<eventQuality << endl;
1116                         fHistoNEvents[iCut]->Fill(eventQuality);
1117                         continue;
1118                 }
1119
1120                 fHistoNEvents[iCut]->Fill(eventQuality); // Should be 0 here
1121                 fHistoNGoodESDTracks[iCut]->Fill(fV0Reader->GetNumberOfPrimaryTracks());
1122                 if(((AliConvEventCuts*)fEventCutArray->At(iCut))->IsHeavyIon() == 2)    fHistoNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A());
1123                         else fHistoNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
1124
1125                 if(fIsMC){
1126                         // Process MC Particle
1127                         if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection() != 0){
1128                                 if(fInputEvent->IsA()==AliESDEvent::Class()){
1129                                 ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetNotRejectedParticles(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection(),
1130                                                                                                                                                                         ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader(),
1131                                                                                                                                                                         fMCEvent);
1132                                 }
1133                                 else if(fInputEvent->IsA()==AliAODEvent::Class()){
1134                                 ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetNotRejectedParticles(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection(),
1135                                                                                                                                                                         ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader(),
1136                                                                                                                                                                         fInputEvent);
1137                                 }
1138
1139                                 if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader()){
1140                                         for(Int_t i = 0;i<(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader())->GetEntries();i++){
1141                                                 TString nameBin= fHistoMCHeaders[iCut]->GetXaxis()->GetBinLabel(i+1);
1142                                                 if (nameBin.CompareTo("")== 0){
1143                                                         TString nameHeader = ((TObjString*)((TList*)((AliConvEventCuts*)fEventCutArray->At(iCut))
1144                                                                                                                                 ->GetAcceptedHeader())->At(i))->GetString();
1145                                                         fHistoMCHeaders[iCut]->GetXaxis()->SetBinLabel(i+1,nameHeader.Data());
1146                                                 }
1147                                         }
1148                                 }
1149                         }
1150                 }
1151                 if(fIsMC){
1152                 if(fInputEvent->IsA()==AliESDEvent::Class())
1153                         ProcessMCParticles();
1154                 if(fInputEvent->IsA()==AliAODEvent::Class())
1155                         ProcessAODMCParticles();
1156                 }
1157                 
1158                 // it is in the loop to have the same conversion cut string (used also for MC stuff that should be same for V0 and Cluster)
1159                 ProcessClusters();                                      // process calo clusters
1160
1161                 fHistoNGammaCandidates[iCut]->Fill(fClusterCandidates->GetEntries());
1162                 fHistoNGoodESDTracksVsNGammaCanditates[iCut]->Fill(fV0Reader->GetNumberOfPrimaryTracks(),fClusterCandidates->GetEntries());
1163                 if(fDoMesonAnalysis){ // Meson Analysis
1164
1165                         
1166                         CalculatePi0Candidates(); // Combine Gammas from conversion and from calo
1167
1168                         if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
1169                                 if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
1170                                         
1171                                         CalculateBackground(); // Combinatorial Background
1172                                         UpdateEventByEventData(); // Store Event for mixed Events
1173                                 }
1174                                 
1175                         }
1176                 }
1177
1178                 fClusterCandidates->Clear(); // delete cluster candidates
1179         }
1180         
1181         PostData(1, fOutputContainer);
1182 }
1183
1184 //________________________________________________________________________
1185 void AliAnalysisTaskGammaCalo::ProcessClusters()
1186 {
1187         
1188         Int_t nclus = 0;
1189         nclus = fInputEvent->GetNumberOfCaloClusters();
1190         
1191 //      cout << nclus << endl;
1192         
1193         if(nclus == 0)  return;
1194         
1195         // vertex
1196         Double_t vertex[3] = {0};
1197         InputEvent()->GetPrimaryVertex()->GetXYZ(vertex);
1198         
1199         // Loop over EMCal clusters
1200         for(Long_t i = 0; i < nclus; i++){
1201                 
1202                 AliVCluster* clus = NULL;
1203                 clus = fInputEvent->GetCaloCluster(i);          
1204                 if (!clus) continue;
1205                 if(!((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelected(clus,fInputEvent,fIsMC)) continue;
1206                 // TLorentzvector with cluster
1207                 TLorentzVector clusterVector;
1208                 clus->GetMomentum(clusterVector,vertex);
1209                 
1210                 TLorentzVector* tmpvec = new TLorentzVector();
1211                 tmpvec->SetPxPyPzE(clusterVector.Px(),clusterVector.Py(),clusterVector.Pz(),clusterVector.E());
1212                 
1213                 // convert to AODConversionPhoton
1214                 AliAODConversionPhoton *PhotonCandidate=new AliAODConversionPhoton(tmpvec);
1215                 if(!PhotonCandidate) continue;
1216                 
1217                 // Flag Photon as CaloPhoton
1218                 PhotonCandidate->SetIsCaloPhoton();
1219                 PhotonCandidate->SetCaloClusterRef(i);
1220                 // get MC label
1221                 if(fIsMC){
1222                         Int_t* mclabelsCluster = clus->GetLabels();
1223                         PhotonCandidate->SetNCaloPhotonMCLabels(clus->GetNLabels());
1224 //                      cout << clus->GetNLabels() << endl;
1225                         if (clus->GetNLabels()>0){
1226                                 for (Int_t k =0; k< (Int_t)clus->GetNLabels(); k++){
1227                                         if (k< 20)PhotonCandidate->SetCaloPhotonMCLabel(k,mclabelsCluster[k]);
1228 //                                      Int_t pdgCode = fMCStack->Particle(mclabelsCluster[k])->GetPdgCode();
1229 //                                      cout << "label " << k << "\t" << mclabelsCluster[k] << " pdg code: " << pdgCode << endl;
1230                                 }       
1231                         }
1232                 }
1233                 
1234                 fIsFromMBHeader = kTRUE; 
1235                 // test whether largest contribution to cluster orginates in added signals
1236                 if (fIsMC && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetCaloPhotonMCLabel(0), fMCStack, fInputEvent) == 0) fIsFromMBHeader = kFALSE;
1237                 
1238                 if (fIsFromMBHeader)fHistoClusGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
1239                 fClusterCandidates->Add(PhotonCandidate); // if no second loop is required add to events good gammas
1240                 
1241                 if(fIsMC){
1242                         if(fInputEvent->IsA()==AliESDEvent::Class()){
1243                                 ProcessTrueClusterCandidates(PhotonCandidate);
1244                         } else {
1245                                 ProcessTrueClusterCandidatesAOD(PhotonCandidate);
1246                         }       
1247                 }
1248                 
1249                 delete tmpvec;
1250         }
1251         
1252 }
1253
1254 //________________________________________________________________________
1255 void AliAnalysisTaskGammaCalo::ProcessTrueClusterCandidates(AliAODConversionPhoton *TruePhotonCandidate)
1256 {
1257                 
1258         TParticle *Photon = NULL;
1259         if (!TruePhotonCandidate->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set task will abort");
1260         if (fDoClusterQA > 0) fHistoTrueNLabelsInClus[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMCLabels());
1261         
1262         if (TruePhotonCandidate->GetNCaloPhotonMCLabels()>0)Photon = fMCStack->Particle(TruePhotonCandidate->GetCaloPhotonMCLabel(0));
1263                 else return;
1264                 
1265         if(Photon == NULL){
1266         //    cout << "no photon" << endl;
1267                 return;
1268         }
1269
1270         Int_t pdgCodeParticle = Photon->GetPdgCode();
1271         TruePhotonCandidate->SetCaloPhotonMCFlags(fMCStack);
1272         
1273         // True Photon
1274         if(fIsFromMBHeader){
1275                 if (TruePhotonCandidate->IsLargestComponentPhoton() || TruePhotonCandidate->IsLargestComponentElectron() )fHistoTrueClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1276                         else fHistoTrueClusEMNonLeadingPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1277                 if (fDoClusterQA > 0){
1278                         if (TruePhotonCandidate->IsLargestComponentPhoton()){ 
1279                                 fHistoTrueClusUnConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1280                                 fHistoTrueClusUnConvGammaMCPt[fiCut]->Fill(Photon->Pt());
1281                         }       
1282                         if (TruePhotonCandidate->IsLargestComponentElectron()) 
1283                                 fHistoTrueClusElectronPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1284                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1285                                 fHistoTrueClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1286                                 fHistoTrueClusConvGammaMCPt[fiCut]->Fill(((TParticle*)fMCStack->Particle(Photon->GetMother(0)))->Pt());
1287                         }       
1288                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion() && TruePhotonCandidate->IsConversionFullyContained()) 
1289                                 fHistoTrueClusConvGammaFullyPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1290                         if (TruePhotonCandidate->IsMerged() || TruePhotonCandidate->IsMergedPartConv() || TruePhotonCandidate->IsDalitzMerged())
1291                                 fHistoTrueClusMergedGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1292                         if (TruePhotonCandidate->IsMergedPartConv())
1293                                 fHistoTrueClusMergedPartConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1294                         if (TruePhotonCandidate->IsDalitz()) 
1295                                 fHistoTrueClusDalitzPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1296                         if (TruePhotonCandidate->IsDalitzMerged()) 
1297                                 fHistoTrueClusDalitzMergedPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1298                         if (TruePhotonCandidate->IsPhotonWithElecMother()) 
1299                                 fHistoTrueClusPhotonFromElecMotherPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1300                         if (TruePhotonCandidate->IsShower()) 
1301                                 fHistoTrueClusShowerPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1302                         if (TruePhotonCandidate->IsSubLeadingEM())
1303                                 fHistoTrueClusSubLeadingPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1304                         fHistoTrueClusNParticles[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMotherMCLabels());
1305                         if (!TruePhotonCandidate->IsLargestComponentPhoton())
1306                                 FillPhotonBackgroundHist(TruePhotonCandidate,pdgCodeParticle);
1307                         if (!(TruePhotonCandidate->IsLargestComponentPhoton() || (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())) )
1308                                 FillPhotonPlusConversionBackgroundHist(TruePhotonCandidate,pdgCodeParticle);
1309                 }
1310                 
1311                 if(Photon->GetMother(0) <= fMCStack->GetNprimary()){
1312                         if (TruePhotonCandidate->IsLargestComponentPhoton()){
1313                                 fHistoTruePrimaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1314                                 fHistoTruePrimaryClusGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
1315                         }
1316                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1317                                 fHistoTruePrimaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1318                                 fHistoTruePrimaryClusConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
1319                         }
1320                         
1321                 } else {
1322                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1323                                 fHistoTrueSecondaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1324                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1325                                 fHistoTrueSecondaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1326                         if(fMCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1){
1327                                 if(fMCStack->Particle(fMCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 3122){
1328                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1329                                                 fHistoTrueSecondaryClusGammaFromXFromLambdaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1330                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1331                                                 fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1332                                 }
1333                                 if(fMCStack->Particle(fMCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
1334                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1335                                                 fHistoTrueSecondaryClusGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1336                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1337                                                 fHistoTrueSecondaryClusConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1338                                 }
1339                                 if(fMCStack->Particle(fMCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 221){
1340                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1341                                                 fHistoTrueSecondaryClusGammaFromXFromEtasPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1342                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1343                                                 fHistoTrueSecondaryClusConvGammaFromXFromEtasPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1344                                                 
1345                                 }       
1346                         }
1347                 }
1348         }
1349         return;
1350 }
1351
1352
1353 //________________________________________________________________________
1354 void AliAnalysisTaskGammaCalo::ProcessTrueClusterCandidatesAOD(AliAODConversionPhoton *TruePhotonCandidate)
1355 {
1356         AliAODMCParticle *Photon = NULL;
1357         TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
1358         if (fDoClusterQA > 0) fHistoTrueNLabelsInClus[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMCLabels());
1359         if (AODMCTrackArray){
1360                 if (!TruePhotonCandidate->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set task will abort");
1361                 if (TruePhotonCandidate->GetNCaloPhotonMCLabels()>0) Photon = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetCaloPhotonMCLabel(0));
1362                         else return;
1363         } else {
1364                 AliInfo("AODMCTrackArray could not be loaded");
1365                 return;
1366         }
1367
1368         if(Photon == NULL){
1369         //      cout << "no photon" << endl;
1370                 return;
1371         }
1372         Int_t pdgCodeParticle = Photon->GetPdgCode();
1373         TruePhotonCandidate->SetCaloPhotonMCFlagsAOD(fInputEvent);
1374         
1375         // True Photon
1376         if(fIsFromMBHeader){
1377                 if (TruePhotonCandidate->IsLargestComponentPhoton() || TruePhotonCandidate->IsLargestComponentElectron() )fHistoTrueClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1378                         else fHistoTrueClusEMNonLeadingPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1379                 if (fDoClusterQA > 0){
1380                         if (TruePhotonCandidate->IsLargestComponentPhoton()) {
1381                                 fHistoTrueClusUnConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1382                                 fHistoTrueClusUnConvGammaMCPt[fiCut]->Fill(Photon->Pt());
1383                         }       
1384                         if (TruePhotonCandidate->IsLargestComponentElectron()) 
1385                                 fHistoTrueClusElectronPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1386                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()) {
1387                                 fHistoTrueClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1388                                 AliAODMCParticle *Mother = (AliAODMCParticle*) AODMCTrackArray->At(Photon->GetMother());
1389                                 fHistoTrueClusConvGammaMCPt[fiCut]->Fill(Mother->Pt());
1390                         }       
1391                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion() && TruePhotonCandidate->IsConversionFullyContained()) 
1392                                 fHistoTrueClusConvGammaFullyPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1393                         if (TruePhotonCandidate->IsMerged() || TruePhotonCandidate->IsMergedPartConv() || TruePhotonCandidate->IsDalitzMerged())
1394                                 fHistoTrueClusMergedGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1395                         if (TruePhotonCandidate->IsMergedPartConv())
1396                                 fHistoTrueClusMergedPartConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1397                         if (TruePhotonCandidate->IsDalitz()) 
1398                                 fHistoTrueClusDalitzPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1399                         if (TruePhotonCandidate->IsDalitzMerged()) 
1400                                 fHistoTrueClusDalitzMergedPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1401                         if (TruePhotonCandidate->IsPhotonWithElecMother()) 
1402                                 fHistoTrueClusPhotonFromElecMotherPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1403                         if (TruePhotonCandidate->IsShower()) 
1404                                 fHistoTrueClusShowerPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1405                         if (TruePhotonCandidate->IsSubLeadingEM())
1406                                 fHistoTrueClusSubLeadingPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1407                         fHistoTrueClusNParticles[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMotherMCLabels());
1408                         
1409                         if (!TruePhotonCandidate->IsLargestComponentPhoton())
1410                                 FillPhotonBackgroundHist(TruePhotonCandidate,pdgCodeParticle);
1411                         if (!(TruePhotonCandidate->IsLargestComponentPhoton() || (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())) )
1412                                 FillPhotonPlusConversionBackgroundHist(TruePhotonCandidate,pdgCodeParticle);
1413                 }
1414                 
1415                 if(Photon->IsPrimary()){
1416                         if (TruePhotonCandidate->IsLargestComponentPhoton()){
1417                                 fHistoTruePrimaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1418                                 fHistoTruePrimaryClusGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
1419                         }
1420                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1421                                 fHistoTruePrimaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1422                                 fHistoTruePrimaryClusConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
1423                         }
1424                         
1425                 } else {
1426                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1427                                 fHistoTrueSecondaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1428                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1429                                 fHistoTrueSecondaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1430                         if(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother() > -1){
1431                                 if(((AliAODMCParticle*)AODMCTrackArray->At(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother()))->GetPdgCode() == 3122){
1432                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1433                                                 fHistoTrueSecondaryClusGammaFromXFromLambdaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1434                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1435                                                 fHistoTrueSecondaryClusConvGammaFromXFromLambdaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1436                                 }
1437                                 if(((AliAODMCParticle*)AODMCTrackArray->At(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother()))->GetPdgCode() == 310){
1438                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1439                                                 fHistoTrueSecondaryClusGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1440                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1441                                                 fHistoTrueSecondaryClusConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1442                                 }
1443                                 if(((AliAODMCParticle*)AODMCTrackArray->At(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother()))->GetPdgCode() == 221){
1444                                         if (TruePhotonCandidate->IsLargestComponentPhoton())
1445                                                 fHistoTrueSecondaryClusGammaFromXFromEtasPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1446                                         if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1447                                                 fHistoTrueSecondaryClusConvGammaFromXFromEtasPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1448                                                 
1449                                 }       
1450                         }
1451                 }       
1452         }
1453 }
1454
1455 //________________________________________________________________________
1456 void AliAnalysisTaskGammaCalo::ProcessAODMCParticles()
1457 {
1458         
1459         TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
1460         
1461         // Loop over all primary MC particle
1462         for(Int_t i = 0; i < AODMCTrackArray->GetEntriesFast(); i++) {
1463                 
1464                 AliAODMCParticle* particle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(i));
1465                 if (!particle) continue;
1466                 if (!particle->IsPrimary()) continue;
1467                 
1468                 Int_t isMCFromMBHeader = -1;
1469                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
1470                         isMCFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent);
1471                         if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
1472                 }
1473                 
1474                 if(((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(particle,AODMCTrackArray)){
1475                         fHistoMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
1476                         if(particle->GetMother() >-1){ // Meson Decay Gamma
1477                                 switch((static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetMother())))->GetPdgCode()){
1478                                 case 111: // Pi0
1479                                         fHistoMCDecayGammaPi0Pt[fiCut]->Fill(particle->Pt());
1480                                         break;
1481                                 case 113: // Rho0
1482                                         fHistoMCDecayGammaRhoPt[fiCut]->Fill(particle->Pt());
1483                                         break;
1484                                 case 221: // Eta
1485                                         fHistoMCDecayGammaEtaPt[fiCut]->Fill(particle->Pt());
1486                                         break;
1487                                 case 223: // Omega
1488                                         fHistoMCDecayGammaOmegaPt[fiCut]->Fill(particle->Pt());
1489                                         break;
1490                                 case 331: // Eta'
1491                                         fHistoMCDecayGammaEtapPt[fiCut]->Fill(particle->Pt());
1492                                         break;
1493                                 case 333: // Phi
1494                                         fHistoMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
1495                                         break;
1496                                 case 3212: // Sigma
1497                                         fHistoMCDecayGammaSigmaPt[fiCut]->Fill(particle->Pt());
1498                                         break;
1499                                 }
1500                         }
1501                 }
1502                 // Converted MC Gamma
1503                 if(fDoMesonAnalysis){
1504                         if(particle->GetPdgCode() == 310 && fDoMesonQA > 0){
1505                                 Double_t mesonY = 10.;
1506                                 if(particle->E() - particle->Pz() == 0 || particle->E() + particle->Pz() == 0){
1507                                         mesonY=10.-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1508                                 } else {
1509                                         mesonY = 0.5*(TMath::Log((particle->E()+particle->Pz()) / (particle->E()-particle->Pz())))-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1510                                 }
1511                                 Float_t weightedK0s= 1;
1512                                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
1513                                         if (particle->Pt()>0.005){
1514                                                 weightedK0s= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, 0x0, fInputEvent);
1515                                                 //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
1516                                         }
1517                                 }
1518                                 fHistoMCK0sPt[fiCut]->Fill(particle->Pt(),weightedK0s);
1519                                 fHistoMCK0sWOWeightPt[fiCut]->Fill(particle->Pt());
1520                                 fHistoMCK0sPtY[fiCut]->Fill(particle->Pt(),mesonY,weightedK0s);
1521                         }
1522                         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))
1523                                 ->MesonIsSelectedAODMC(particle,AODMCTrackArray,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
1524                                 AliAODMCParticle* daughter0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughter(0)));
1525                                 AliAODMCParticle* daughter1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughter(1)));
1526                                 Float_t weighted= 1;
1527                                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
1528                                         if (particle->Pt()>0.005){
1529                                                 weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, 0x0, fInputEvent);
1530                                         }
1531                                 }
1532                                 
1533                                 Double_t mesonY = 10.;
1534                                 if(particle->E() - particle->Pz() == 0 || particle->E() + particle->Pz() == 0){
1535                                         mesonY=10.-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1536                                 } else{
1537                                         mesonY = 0.5*(TMath::Log((particle->E()+particle->Pz()) / (particle->E()-particle->Pz())))-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1538                                 }
1539                                 Double_t alpha = -1;
1540                                 if (particle->GetPdgCode() == 111 || particle->GetPdgCode() == 221){
1541                                         alpha = TMath::Abs((daughter0->E() - daughter1->E()))/(daughter0->E() + daughter1->E());
1542                                 }
1543                                 
1544                                 if(particle->GetPdgCode() == 111){
1545                                         fHistoMCPi0Pt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
1546                                         fHistoMCPi0WOWeightPt[fiCut]->Fill(particle->Pt());
1547                                         if (fDoMesonQA > 0){
1548                                                 fHistoMCPi0PtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
1549                                                 fHistoMCPi0PtAlpha[fiCut]->Fill(particle->Pt(),alpha);
1550                                         }
1551                                 } else if(particle->GetPdgCode() == 221){
1552                                         fHistoMCEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Eta
1553                                         fHistoMCEtaWOWeightPt[fiCut]->Fill(particle->Pt());
1554                                         if (fDoMesonQA > 0){
1555                                                 fHistoMCEtaPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
1556                                                 fHistoMCEtaPtAlpha[fiCut]->Fill(particle->Pt(),alpha);
1557                                         }
1558                                 }
1559                                 
1560                                 // Check the acceptance for both gammas
1561                                 if(((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter0,AODMCTrackArray) &&
1562                                 ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter1,AODMCTrackArray) ){
1563                                         
1564                                         if(particle->GetPdgCode() == 111){
1565                                                 fHistoMCPi0InAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Pi0 with gamma in acc
1566                                         } else if(particle->GetPdgCode() == 221){
1567                                                 fHistoMCEtaInAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Eta with gamma in acc
1568                                         }
1569                                 }
1570                         }
1571                 }
1572         }
1573         
1574 }
1575 //________________________________________________________________________
1576 void AliAnalysisTaskGammaCalo::ProcessMCParticles()
1577 {
1578         // Loop over all primary MC particle
1579         for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
1580                 TParticle* particle = (TParticle *)fMCStack->Particle(i);
1581                 if (!particle) continue;
1582                 
1583                 Int_t isMCFromMBHeader = -1;
1584                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
1585                         isMCFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent);
1586                         if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
1587                 }
1588                 
1589                 if(((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(particle,fMCStack)){
1590                         fHistoMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma                        
1591                         if(particle->GetMother(0) >-1){ // Meson Decay Gamma
1592                                 switch(fMCStack->Particle(particle->GetMother(0))->GetPdgCode()){
1593                                 case 111: // Pi0
1594                                         fHistoMCDecayGammaPi0Pt[fiCut]->Fill(particle->Pt());
1595                                         break;
1596                                 case 113: // Rho0
1597                                         fHistoMCDecayGammaRhoPt[fiCut]->Fill(particle->Pt());
1598                                         break;
1599                                 case 221: // Eta
1600                                         fHistoMCDecayGammaEtaPt[fiCut]->Fill(particle->Pt());
1601                                         break;
1602                                 case 223: // Omega
1603                                         fHistoMCDecayGammaOmegaPt[fiCut]->Fill(particle->Pt());
1604                                         break;
1605                                 case 331: // Eta'
1606                                         fHistoMCDecayGammaEtapPt[fiCut]->Fill(particle->Pt());
1607                                         break;
1608                                 case 333: // Phi
1609                                         fHistoMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
1610                                         break;
1611                                 case 3212: // Sigma
1612                                         fHistoMCDecayGammaSigmaPt[fiCut]->Fill(particle->Pt());
1613                                         break;
1614                                 }
1615                         }
1616                 }
1617                 if(fDoMesonAnalysis){
1618                         if(particle->GetPdgCode() == 310 && fDoMesonQA > 0){
1619                                 Double_t mesonY = 10.;
1620                                 if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
1621                                         mesonY=10.-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1622                                 } else{
1623                                         mesonY = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())))-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1624                                 }
1625                                 Float_t weightedK0s= 1;
1626                                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
1627                                         if (particle->Pt()>0.005){
1628                                                 weightedK0s= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack, fInputEvent);
1629                                                 //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
1630                                         }
1631                                 }
1632                                 if (fMCStack->IsPhysicalPrimary(i)){
1633                                         fHistoMCK0sPt[fiCut]->Fill(particle->Pt(),weightedK0s);
1634                                         fHistoMCK0sWOWeightPt[fiCut]->Fill(particle->Pt());
1635                                         fHistoMCK0sPtY[fiCut]->Fill(particle->Pt(),mesonY,weightedK0s);
1636                                 }
1637                         }
1638                         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))
1639                                 ->MesonIsSelectedMC(particle,fMCStack,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
1640                                 TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
1641                                 TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
1642                                 
1643                                 Float_t weighted= 1;
1644                                 if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
1645                                         if (particle->Pt()>0.005){
1646                                                 weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack, fInputEvent);
1647                                                 //                   if(particle->GetPdgCode() == 221){
1648                                                 //                      cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
1649                                                 //                   }
1650                                         }
1651                                 }
1652                                 Double_t mesonY = 10.;
1653                                 if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
1654                                         mesonY=10.-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1655                                 } else{
1656                                         mesonY = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())))-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
1657                                 }
1658         
1659                                 Double_t alpha = -1;
1660                                 if (particle->GetPdgCode() == 111 || particle->GetPdgCode() == 221){
1661                                         alpha = TMath::Abs((daughter0->Energy() - daughter1->Energy()))/(daughter0->Energy() + daughter1->Energy());
1662                                 }
1663         
1664                                 if(particle->GetPdgCode() == 111){
1665                                         fHistoMCPi0Pt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
1666                                         fHistoMCPi0WOWeightPt[fiCut]->Fill(particle->Pt());
1667                                         if (fDoMesonQA > 0){
1668                                                 fHistoMCPi0PtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
1669                                                 fHistoMCPi0PtAlpha[fiCut]->Fill(particle->Pt(),alpha); // All MC Pi0
1670                                         }
1671                                 } else if(particle->GetPdgCode() == 221){
1672                                         fHistoMCEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Eta
1673                                         fHistoMCEtaWOWeightPt[fiCut]->Fill(particle->Pt());
1674                                         if (fDoMesonQA > 0){
1675                                                 fHistoMCEtaPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
1676                                                 fHistoMCEtaPtAlpha[fiCut]->Fill(particle->Pt(),alpha); // All MC Pi0
1677                                         }
1678                                 }
1679                                 
1680                                 // Check the acceptance for both gammas
1681                                 if(((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter0,fMCStack) &&
1682                                 ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter1,fMCStack) ){                                   
1683                                         if(particle->GetPdgCode() == 111){
1684                                                 fHistoMCPi0InAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Pi0 with gamma in acc
1685                                         } else if(particle->GetPdgCode() == 221){
1686                                                 fHistoMCEtaInAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Eta with gamma in acc
1687                                         }
1688                                 }
1689                         }
1690                 }
1691         }
1692   
1693         if (fDoMesonQA){
1694                 for(Int_t i = fMCStack->GetNprimary(); i < fMCStack->GetNtrack(); i++) {
1695                         TParticle* particle = (TParticle *)fMCStack->Particle(i);
1696                         if (!particle) continue;
1697       
1698                         Int_t isMCFromMBHeader = -1;
1699                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
1700                                 isMCFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent);
1701                                 if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
1702                         }
1703       
1704                         if(fDoMesonAnalysis){
1705                                 if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
1706                                         Float_t weighted= 1;
1707                                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
1708                                                 if (particle->Pt()>0.005){
1709                                                         weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack, fInputEvent);
1710               //                   if(particle->GetPdgCode() == 221){
1711               //                      cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
1712               //                   }
1713                                                 }
1714                                         }
1715                                         
1716                                         if(particle->GetPdgCode() == 111){
1717                                                 Int_t pdgCode = ((TParticle*)fMCStack->Particle( particle->GetFirstMother() ))->GetPdgCode();
1718                                                 Int_t source = GetSourceClassification(111,pdgCode);
1719                                                 fHistoMCSecPi0PtvsSource[fiCut]->Fill(particle->Pt(),source,weighted); // All MC Pi0
1720                                                 fHistoMCSecPi0Source[fiCut]->Fill(pdgCode);
1721                                         } else if(particle->GetPdgCode() == 221){
1722                                                 Int_t pdgCode = ((TParticle*)fMCStack->Particle( particle->GetFirstMother() ))->GetPdgCode();
1723                                                 fHistoMCSecEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
1724                                                 fHistoMCSecEtaSource[fiCut]->Fill(pdgCode);
1725                                         }
1726                                 }
1727                         }
1728                 }
1729         }
1730 }
1731
1732 //________________________________________________________________________
1733 void AliAnalysisTaskGammaCalo::CalculatePi0Candidates(){
1734         
1735         // Conversion Gammas
1736         if(fClusterCandidates->GetEntries()>0){
1737
1738                 // vertex
1739                 Double_t vertex[3] = {0};
1740                 InputEvent()->GetPrimaryVertex()->GetXYZ(vertex);
1741
1742                 for(Int_t firstGammaIndex=0;firstGammaIndex<fClusterCandidates->GetEntries();firstGammaIndex++){
1743                         AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(firstGammaIndex));
1744                         if (gamma0==NULL) continue;
1745                         
1746                         for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fClusterCandidates->GetEntries();secondGammaIndex++){
1747                                 AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(secondGammaIndex));
1748                                 if (gamma1==NULL) continue;
1749                                 
1750                                 AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma0,gamma1);
1751                                 pi0cand->SetLabels(firstGammaIndex,secondGammaIndex);
1752                                                                 
1753                                 if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
1754                                         fHistoMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
1755                                         // fill new histograms
1756                                         if(pi0cand->GetAlpha()<0.1)
1757                                                 fHistoMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
1758                                         
1759                                         if (fDoMesonQA > 0){
1760                                                 if ( pi0cand->M() > 0.05 && pi0cand->M() < 0.17){
1761                                                         fHistoMotherPi0PtY[fiCut]->Fill(pi0cand->Pt(),pi0cand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
1762                                                         fHistoMotherPi0PtAlpha[fiCut]->Fill(pi0cand->Pt(),pi0cand->GetAlpha());
1763                                                         fHistoMotherPi0PtOpenAngle[fiCut]->Fill(pi0cand->Pt(),pi0cand->GetOpeningAngle());      
1764                                                 }
1765                                                 if ( pi0cand->M() > 0.45 && pi0cand->M() < 0.65){
1766                                                         fHistoMotherEtaPtY[fiCut]->Fill(pi0cand->Pt(),pi0cand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
1767                                                         fHistoMotherEtaPtAlpha[fiCut]->Fill(pi0cand->Pt(),pi0cand->GetAlpha());
1768                                                         fHistoMotherEtaPtOpenAngle[fiCut]->Fill(pi0cand->Pt(),pi0cand->GetOpeningAngle());
1769                                                 }
1770                                         }
1771                                         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
1772                                                 Int_t zbin = 0;
1773                                                 Int_t mbin = 0;
1774                                                 
1775                                                 if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
1776                                                         zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
1777                                                         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1778                                                                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fV0Reader->GetNumberOfPrimaryTracks());
1779                                                         } else {
1780                                                                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fClusterCandidates->GetEntries());
1781                                                         }
1782                                                 } 
1783                                                 Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
1784                                                 fSparseMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
1785                                         }
1786                                 
1787                                         if(fIsMC){
1788                                                 if(fInputEvent->IsA()==AliESDEvent::Class())
1789                                                         ProcessTrueMesonCandidates(pi0cand,gamma0,gamma1);
1790                                                 if(fInputEvent->IsA()==AliAODEvent::Class())
1791                                                         ProcessTrueMesonCandidatesAOD(pi0cand,gamma0,gamma1);
1792                                         }
1793                                         
1794                                         if (fDoMesonQA == 1){
1795                                                 fHistoMotherInvMassECalib[fiCut]->Fill(pi0cand->M(),gamma1->E());
1796                                                 if(pi0cand->GetAlpha()<0.1)
1797                                                 fHistoMotherInvMassECalibalpha[fiCut]->Fill(pi0cand->M(),gamma1->E());            
1798                                         }
1799                                         
1800                                 }
1801                                 for (Int_t thirdGammaIndex=0;thirdGammaIndex<fClusterCandidates->GetEntries();thirdGammaIndex++){
1802                                         if (firstGammaIndex == thirdGammaIndex || secondGammaIndex == thirdGammaIndex ) continue;
1803                                         AliAODConversionPhoton *gamma2=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(thirdGammaIndex));
1804                                         if (gamma2==NULL) continue;
1805                                         
1806                                         AliAODConversionMother *pi0cand2 = new AliAODConversionMother(pi0cand,gamma2);
1807                                         if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(pi0cand2,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
1808                                                 fHistoMotherInvMass3ClusterPt[fiCut]->Fill(pi0cand2->M(),pi0cand2->Pt());
1809                                         }
1810                                         delete pi0cand2;
1811                                         pi0cand2=0x0;
1812                                         
1813                                 }
1814                                 
1815                                 delete pi0cand;
1816                                 pi0cand=0x0;
1817                         }
1818                 }
1819         }
1820 }
1821 //______________________________________________________________________
1822 void AliAnalysisTaskGammaCalo::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1)
1823 {
1824         // Process True Mesons
1825         AliStack *MCStack = fMCEvent->Stack();
1826         
1827         Bool_t isTruePi0 = kFALSE;
1828         Bool_t isTrueEta = kFALSE;
1829         Int_t gamma0MCLabel = TrueGammaCandidate0->GetCaloPhotonMCLabel(0);     // get most probable MC label
1830         Int_t gamma0MotherLabel = -1;
1831
1832         if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
1833                 TParticle * gammaMC0 = (TParticle*)MCStack->Particle(gamma0MCLabel);
1834                 if (TrueGammaCandidate0->IsLargestComponentPhoton() || TrueGammaCandidate0->IsLargestComponentElectron()){              // largest component is electro magnetic
1835                         // get mother of interest (pi0 or eta)
1836                         if (TrueGammaCandidate0->IsLargestComponentPhoton()){                                                                                                           // for photons its the direct mother 
1837                                 gamma0MotherLabel=gammaMC0->GetMother(0);
1838                         } else if (TrueGammaCandidate0->IsLargestComponentElectron()){                                                                                          // for electrons its either the direct mother or for conversions the grandmother
1839                                 if (TrueGammaCandidate0->IsConversion()) gamma0MotherLabel=MCStack->Particle(gammaMC0->GetMother(0))->GetMother(0);
1840                                 else gamma0MotherLabel=gammaMC0->GetMother(0); 
1841                         }
1842                 }       
1843         }
1844         if (!TrueGammaCandidate1->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set. Aborting");
1845         
1846         Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0);     // get most probable MC label
1847         Int_t gamma1MotherLabel = -1;
1848         // check if 
1849
1850         if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
1851                 // Daughters Gamma 1
1852                 TParticle * gammaMC1 = (TParticle*)MCStack->Particle(gamma1MCLabel);
1853                 if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){              // largest component is electro magnetic
1854                         // get mother of interest (pi0 or eta)
1855                         if (TrueGammaCandidate1->IsLargestComponentPhoton()){                                                                                                           // for photons its the direct mother 
1856                                 gamma1MotherLabel=gammaMC1->GetMother(0);
1857                         } else if (TrueGammaCandidate1->IsLargestComponentElectron()){                                                                                          // for electrons its either the direct mother or for conversions the grandmother
1858                                 if (TrueGammaCandidate1->IsConversion()) gamma1MotherLabel=MCStack->Particle(gammaMC1->GetMother(0))->GetMother(0);
1859                                 else gamma1MotherLabel=gammaMC1->GetMother(0); 
1860                         }
1861                 }       
1862         }
1863                         
1864         if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
1865                 if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 111){
1866                         isTruePi0=kTRUE;
1867                 }
1868                 if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 221){
1869                         isTrueEta=kTRUE;
1870                 }
1871         }
1872         
1873         if(isTruePi0 || isTrueEta){// True Pion or Eta
1874                 if (isTruePi0)  fHistoTruePi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1875                 if (isTrueEta)  fHistoTrueEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1876                 if (fDoMesonQA > 0){
1877                         // both gammas are real gammas
1878                         if (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentPhoton()) {
1879                                 if (isTruePi0) fHistoTruePi0CaloPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1880                                 if (isTrueEta) fHistoTrueEtaCaloPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1881                         }       
1882                         // both particles are electrons
1883                         if (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate1->IsLargestComponentElectron() ) {
1884                                 if (isTruePi0) fHistoTruePi0CaloElectronInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1885                                 if (isTrueEta) fHistoTrueEtaCaloElectronInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1886                         }       
1887                         // both particles are converted electrons
1888                         if ((TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion()) && (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ){
1889                                 if (isTruePi0 )fHistoTruePi0CaloConvertedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1890                                 if (isTrueEta )fHistoTrueEtaCaloConvertedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1891                         }
1892                         // 1 gamma is converted the other one is normals
1893                         if ( (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ||
1894                                  (TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion())
1895                         ) {
1896                                 if (isTruePi0) fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1897                                 if (isTrueEta) fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1898                         }
1899                         
1900                         if ( (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion() && TrueGammaCandidate1->IsLargestComponentPhoton() && !TrueGammaCandidate1->IsMerged()) ||
1901                                  (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion() && TrueGammaCandidate0->IsLargestComponentPhoton() && !TrueGammaCandidate0->IsMerged()) 
1902                         ) {
1903                                 if (isTruePi0) fHistoTruePi0NonMergedElectronPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1904                         }       
1905
1906                         if ( (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion() && TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate1->IsMerged()) ||
1907                                  (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion() && TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate0->IsMerged()) 
1908                         ) {
1909                                 if (isTruePi0) fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1910                         }       
1911                         
1912                         // at least one of the photon is merged
1913                         if (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv() || TrueGammaCandidate0->IsDalitzMerged() || TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged() ){
1914                                 if (isTruePi0) fHistoTruePi0CaloMergedClusterInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1915                                 if (isTrueEta) fHistoTruePi0CaloMergedClusterInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1916                         }       
1917                         // at least one of the photon is merged and part conv
1918                         if (TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate0->IsMergedPartConv()) {       
1919                                 if (isTruePi0) fHistoTruePi0CaloMergedClusterPartConvInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1920                                 if (isTrueEta) fHistoTrueEtaCaloMergedClusterPartConvInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1921                         }       
1922                 }
1923         
1924                 if (fDoMesonQA > 0){
1925                         if (isTruePi0){
1926                                 if ( Pi0Candidate->M() > 0.05 && Pi0Candidate->M() < 0.17){
1927                                         fHistoTruePi0PtY[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
1928                                         fHistoTruePi0PtAlpha[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetAlpha());
1929                                         fHistoTruePi0PtOpenAngle[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetOpeningAngle());
1930                                 }
1931                         } else if (isTrueEta){
1932                                 if ( Pi0Candidate->M() > 0.45 && Pi0Candidate->M() < 0.65){
1933                                         fHistoTrueEtaPtY[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
1934                                         fHistoTrueEtaPtAlpha[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetAlpha());
1935                                         fHistoTrueEtaPtOpenAngle[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetOpeningAngle());
1936                                 }
1937                         }
1938                 }
1939                 
1940                 if(gamma0MotherLabel >= MCStack->GetNprimary()){ // Secondary Meson
1941                         Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gamma0MotherLabel))->GetMother(0);
1942                         Float_t weightedSec= 1;
1943                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(secMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(secMotherLabel)->GetPdgCode()==310){
1944                                 weightedSec= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),secMotherLabel, fMCStack, fInputEvent)/2.; //invariant mass is additive thus the weight for the daughters has to be devide by two for the K0s at a certain pt
1945                                 //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
1946                         }
1947                         if (isTruePi0) fHistoTrueSecondaryPi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
1948                         if (isTrueEta) fHistoTrueSecondaryEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
1949                         if (secMotherLabel >-1){
1950                                 if(MCStack->Particle(secMotherLabel)->GetPdgCode()==310 && isTruePi0){
1951                                         fHistoTrueSecondaryPi0FromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
1952                                         if (fDoMesonQA > 0)fHistoTrueK0sWithPi0DaughterMCPt[fiCut]->Fill(MCStack->Particle(secMotherLabel)->Pt());
1953                                 }
1954                                 if(MCStack->Particle(secMotherLabel)->GetPdgCode()==221 && isTruePi0){
1955                                         fHistoTrueSecondaryPi0FromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
1956                                         if (fDoMesonQA > 0)fHistoTrueEtaWithPi0DaughterMCPt[fiCut]->Fill(MCStack->Particle(secMotherLabel)->Pt());
1957                                 }
1958                                 if(MCStack->Particle(secMotherLabel)->GetPdgCode()==3122 && isTruePi0){
1959                                         fHistoTrueSecondaryPi0FromLambdaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
1960                                         if (fDoMesonQA > 0)fHistoTrueLambdaWithPi0DaughterMCPt[fiCut]->Fill(MCStack->Particle(secMotherLabel)->Pt());
1961                                 }
1962                         }
1963                 } else { // Only primary pi0 for efficiency calculation
1964                         Float_t weighted= 1;
1965                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCStack, fInputEvent)){
1966                                 if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt()>0.005){
1967                                         weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, fMCStack, fInputEvent);
1968                                         //                      cout << "rec \t " <<gamma1MotherLabel << "\t" <<  weighted << endl;
1969                                 }
1970                         }
1971                         if (isTruePi0){
1972                                 fHistoTruePrimaryPi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
1973                                 fHistoTruePrimaryPi0W0WeightingInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1974                                 fProfileTruePrimaryPi0WeightsInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
1975                         } else if (isTrueEta){
1976                                 fHistoTruePrimaryEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
1977                                 fHistoTruePrimaryEtaW0WeightingInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1978                                 fProfileTruePrimaryEtaWeightsInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
1979                         }       
1980                                 
1981                         if (fDoMesonQA > 0){
1982                                 if(isTruePi0){ // Only primary pi0 for resolution
1983                                         fHistoTruePrimaryPi0MCPtResolPt[fiCut]->Fill(((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),(Pi0Candidate->Pt()-((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt())/((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),weighted);
1984                                 }
1985                                 if (isTrueEta){ // Only primary eta for resolution
1986                                         fHistoTruePrimaryEtaMCPtResolPt[fiCut]->Fill(((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),(Pi0Candidate->Pt()-((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt())/((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),weighted);
1987                                 }
1988                         }
1989                 }       
1990         } else if(!isTruePi0 && !isTrueEta){ // Background
1991                 if (fDoMesonQA > 0){
1992                         if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
1993                                 fHistoTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1994                         } else { // No photon or without mother
1995                                 fHistoTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1996                         }
1997                 }
1998         }
1999
2000 }
2001 //______________________________________________________________________
2002 void AliAnalysisTaskGammaCalo::ProcessTrueMesonCandidatesAOD(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1)
2003 {
2004         
2005         // Process True Mesons
2006         TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
2007         Bool_t isTruePi0 = kFALSE;
2008         Bool_t isTrueEta = kFALSE;
2009                 
2010         Int_t gamma0MCLabel = TrueGammaCandidate0->GetCaloPhotonMCLabel(0);     // get most probable MC label
2011         Int_t gamma0MotherLabel = -1;
2012                 // check if 
2013
2014         if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2015                 // Daughters Gamma 0
2016                 AliAODMCParticle * gammaMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MCLabel));
2017                 if (TrueGammaCandidate0->IsLargestComponentPhoton() || TrueGammaCandidate0->IsLargestComponentElectron()){              // largest component is electro magnetic
2018                         // get mother of interest (pi0 or eta)
2019                         if (TrueGammaCandidate0->IsLargestComponentPhoton()){                                                                                                           // for photons its the direct mother 
2020                                 gamma0MotherLabel=gammaMC0->GetMother();
2021                         } else if (TrueGammaCandidate0->IsLargestComponentElectron()){                                                                                          // for electrons its either the direct mother or for conversions the grandmother
2022                                 if (TrueGammaCandidate0->IsConversion()){
2023                                         AliAODMCParticle * gammaGrandMotherMC0 =  static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gammaMC0->GetMother()));
2024                                         gamma0MotherLabel=gammaGrandMotherMC0->GetMother();
2025                                 } else gamma0MotherLabel=gammaMC0->GetMother(); 
2026                         }
2027                 }       
2028         }
2029
2030         Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0);     // get most probable MC label
2031         Int_t gamma1MotherLabel = -1;
2032                 // check if 
2033
2034         if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2035                 // Daughters Gamma 1
2036                 AliAODMCParticle * gammaMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MCLabel));
2037                 if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){              // largest component is electro magnetic
2038                         // get mother of interest (pi0 or eta)
2039                         if (TrueGammaCandidate1->IsLargestComponentPhoton()){                                                                                                           // for photons its the direct mother 
2040                                 gamma1MotherLabel=gammaMC1->GetMother();
2041                         } else if (TrueGammaCandidate1->IsLargestComponentElectron()){                                                                                          // for electrons its either the direct mother or for conversions the grandmother
2042                                 if (TrueGammaCandidate1->IsConversion()){
2043                                         AliAODMCParticle * gammaGrandMotherMC1 =  static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gammaMC1->GetMother()));
2044                                         gamma1MotherLabel=gammaGrandMotherMC1->GetMother();
2045                                 } else gamma1MotherLabel=gammaMC1->GetMother(); 
2046                         }
2047                 }       
2048         }
2049                         
2050         if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
2051                 if(((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == 111){
2052                         isTruePi0=kTRUE;
2053                 }
2054                 if(((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == 221){
2055                         isTrueEta=kTRUE;
2056                 }
2057         }
2058         
2059         if(isTruePi0 || isTrueEta){// True Pion or Eta
2060                 if (isTruePi0)fHistoTruePi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2061                 if (isTrueEta)fHistoTrueEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2062                 if (fDoMesonQA > 0){
2063                         // both gammas are real gammas
2064                         if (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentPhoton()) {
2065                                 if (isTruePi0)fHistoTruePi0CaloPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2066                                 if (isTrueEta)fHistoTrueEtaCaloPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2067                         }       
2068                         // both particles are electrons
2069                         if (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate1->IsLargestComponentElectron() ) {
2070                                 if (isTruePi0) fHistoTruePi0CaloElectronInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2071                                 if (isTrueEta) fHistoTrueEtaCaloElectronInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2072                         }       
2073                         // both particles are converted electrons
2074                         if ((TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion()) && (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ){
2075                                 if (isTruePi0 )fHistoTruePi0CaloConvertedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2076                                 if (isTrueEta )fHistoTrueEtaCaloConvertedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2077                         }
2078                         // 1 gamma is converted the other one is normals
2079                         if ( (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ||
2080                                  (TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion())
2081                         ) {
2082                                 if (isTruePi0) fHistoTruePi0CaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2083                                 if (isTrueEta) fHistoTrueEtaCaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2084                         }
2085                         
2086                         if ( (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion() && TrueGammaCandidate1->IsLargestComponentPhoton() && !TrueGammaCandidate1->IsMerged()) ||
2087                                  (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion() && TrueGammaCandidate0->IsLargestComponentPhoton() && !TrueGammaCandidate0->IsMerged()) 
2088                         ) {
2089                                 if (isTruePi0) fHistoTruePi0NonMergedElectronPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2090                         }       
2091
2092                         if ( (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion() && TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate1->IsMerged()) ||
2093                                  (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion() && TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate0->IsMerged()) 
2094                         ) {
2095                                 if (isTruePi0) fHistoTruePi0NonMergedElectronMergedPhotonInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2096                         }       
2097
2098                         // at least one of the photon is merged
2099                         if (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv() || TrueGammaCandidate0->IsDalitzMerged() || TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged() ){
2100                                 if (isTruePi0) fHistoTruePi0CaloMergedClusterInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2101                                 if (isTrueEta) fHistoTrueEtaCaloMergedClusterInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2102                         }
2103                         // at least one of the photon is merged and part conv
2104                         if (TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate0->IsMergedPartConv()) {
2105                                 if (isTruePi0)fHistoTruePi0CaloMergedClusterPartConvInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2106                                 if (isTrueEta)fHistoTrueEtaCaloMergedClusterPartConvInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2107                         }       
2108                 }
2109
2110                 if (fDoMesonQA > 0){
2111                         if (isTruePi0){
2112                                 if ( Pi0Candidate->M() > 0.05 && Pi0Candidate->M() < 0.17){
2113                                 fHistoTruePi0PtY[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
2114                                 fHistoTruePi0PtAlpha[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetAlpha());
2115                                 fHistoTruePi0PtOpenAngle[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetOpeningAngle());
2116                                 }
2117                         } else if (isTrueEta){
2118                                 if ( Pi0Candidate->M() > 0.45 && Pi0Candidate->M() < 0.65){
2119                                 fHistoTrueEtaPtY[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
2120                                 fHistoTrueEtaPtAlpha[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetAlpha());
2121                                 fHistoTrueEtaPtOpenAngle[fiCut]->Fill(Pi0Candidate->Pt(),Pi0Candidate->GetOpeningAngle());
2122                                 }
2123                         }
2124                 }
2125                 if(!(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MotherLabel))->IsPrimary())){ // Secondary Meson
2126                         Int_t secMotherLabel = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->GetMother();
2127                         Float_t weightedSec= 1;
2128                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(secMotherLabel, 0x0, fInputEvent) && static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==310){
2129                                 weightedSec= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),secMotherLabel, 0x0, fInputEvent)/2.; //invariant mass is additive thus the weight for the daughters has to be devide by two for the K0s at a certain pt
2130                                 //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
2131                         }
2132                         if (isTruePi0) fHistoTrueSecondaryPi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2133                         if (isTrueEta) fHistoTrueSecondaryEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2134                         if (secMotherLabel >-1){
2135                                 if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==310 && isTruePi0 ){
2136                                         fHistoTrueSecondaryPi0FromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2137                                         if (fDoMesonQA > 0)fHistoTrueK0sWithPi0DaughterMCPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->Pt());
2138                                 }
2139                                 if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==221 && isTruePi0){
2140                                         fHistoTrueSecondaryPi0FromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2141                                         if (fDoMesonQA > 0)fHistoTrueEtaWithPi0DaughterMCPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->Pt());
2142                                 }
2143                                 if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==3122 && isTruePi0){
2144                                         fHistoTrueSecondaryPi0FromLambdaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2145                                         if (fDoMesonQA > 0)fHistoTrueLambdaWithPi0DaughterMCPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->Pt());
2146                                 }
2147                         }       
2148                 } else{ // Only primary pi0 for efficiency calculation
2149                         Float_t weighted= 1;
2150                         if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, 0x0, fInputEvent)){
2151                                 if (static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt()>0.005){
2152                                 weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, 0x0, fInputEvent);
2153                                 //                      cout << "rec \t " <<gamma1MotherLabel << "\t" <<  weighted << endl;
2154                                 }
2155                         }
2156                         if (isTruePi0){
2157                                 fHistoTruePrimaryPi0InvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2158                                 fHistoTruePrimaryPi0W0WeightingInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2159                                 fProfileTruePrimaryPi0WeightsInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2160                         } else if (isTrueEta){
2161                                 fHistoTruePrimaryEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2162                                 fHistoTruePrimaryEtaW0WeightingInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2163                                 fProfileTruePrimaryEtaWeightsInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);     
2164                         }       
2165                         if (fDoMesonQA > 0){
2166                                 if(isTruePi0){ // Only primary pi0 for resolution
2167                                         fHistoTruePrimaryPi0MCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
2168                                                                                                                         (Pi0Candidate->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted);
2169                                 
2170                                 }
2171                                 if (isTrueEta){ // Only primary eta for resolution
2172                                         fHistoTruePrimaryEtaMCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
2173                                                                                                                         (Pi0Candidate->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted);
2174                                 }
2175                         }
2176                 }
2177         } else if(!isTruePi0 && !isTrueEta) { // Background
2178                 if (fDoMesonQA > 0){
2179                         if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
2180                                 fHistoTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2181                         } else { // No photon or without mother
2182                                 fHistoTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2183                         }
2184                 }
2185         }
2186 }
2187
2188 //________________________________________________________________________
2189 void AliAnalysisTaskGammaCalo::CalculateBackground(){
2190         
2191         Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2192         Int_t mbin = 0;
2193         
2194         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2195                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fV0Reader->GetNumberOfPrimaryTracks());
2196         } else {
2197                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fClusterCandidates->GetEntries());
2198         }
2199         
2200         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2201                 for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2202                         AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2203                         for(Int_t iCurrent=0;iCurrent<fClusterCandidates->GetEntries();iCurrent++){
2204                                 AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fClusterCandidates->At(iCurrent));
2205                                 for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2206                                         AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2207                                         AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2208                                         backgroundCandidate->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
2209                                 
2210                                         if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))
2211                                                 ->MesonIsSelected(backgroundCandidate,kFALSE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2212                                                 fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2213                                                 Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2214                                                 fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2215                                         }
2216                                         delete backgroundCandidate;
2217                                         backgroundCandidate = 0x0;
2218                                 }
2219                         }
2220                 }
2221         } else {
2222                 for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2223                         AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2224                         if(previousEventV0s){
2225                                 for(Int_t iCurrent=0;iCurrent<fClusterCandidates->GetEntries();iCurrent++){
2226                                         AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fClusterCandidates->At(iCurrent));
2227                                         for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2228                                 
2229                                                 AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2230                                                 AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2231                                                 backgroundCandidate->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
2232                                 
2233                                                 if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2234                                                         fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2235                                                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2236                                                         fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2237                                                 }
2238                                                 delete backgroundCandidate;
2239                                                 backgroundCandidate = 0x0;
2240                                         }
2241                                 }
2242                         }
2243                 }
2244         }
2245 }
2246
2247 //________________________________________________________________________
2248 void AliAnalysisTaskGammaCalo::RotateParticle(AliAODConversionPhoton *gamma){
2249         Int_t fNDegreesPMBackground= ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->NDegreesRotation();
2250         Double_t nRadiansPM = fNDegreesPMBackground*TMath::Pi()/180;
2251         Double_t rotationValue = fRandom.Rndm()*2*nRadiansPM + TMath::Pi()-nRadiansPM;
2252         gamma->RotateZ(rotationValue);
2253 }
2254
2255 //________________________________________________________________________
2256 void AliAnalysisTaskGammaCalo::UpdateEventByEventData(){
2257         //see header file for documentation
2258         if(fClusterCandidates->GetEntries() >0 ){
2259                 if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2260                         fBGHandler[fiCut]->AddEvent(fClusterCandidates,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->GetPrimaryVertex()->GetZ(),fV0Reader->GetNumberOfPrimaryTracks(),fEventPlaneAngle);
2261                 } else { // means we use #V0s for multiplicity
2262                         fBGHandler[fiCut]->AddEvent(fClusterCandidates,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->GetPrimaryVertex()->GetZ(),fClusterCandidates->GetEntries(),fEventPlaneAngle);
2263                 }
2264         }
2265 }
2266
2267
2268 //________________________________________________________________________
2269 void AliAnalysisTaskGammaCalo::FillPhotonBackgroundHist(AliAODConversionPhoton *TruePhotonCandidate, Int_t pdgCode)
2270 {
2271         // Bck = 0 e+-, 1 pi+-, 2 p+-, 3 K+-, 4 n, 5 K0s, 6 Lambda, 7 mu+-, 8 rest
2272         if(fIsFromMBHeader){
2273                 if(abs(pdgCode) == 11)                  fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);
2274                 else if( abs(pdgCode)==211)     fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);
2275                 else if( abs(pdgCode)==2212)    fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);
2276                 else if( abs(pdgCode)==321)     fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);
2277                 else if( abs(pdgCode)==2112)    fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);
2278                 else if( abs(pdgCode)==310)     fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);   
2279                 else if( abs(pdgCode)==3122)    fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);
2280                 else if( abs(pdgCode)==13)              fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);
2281                 else                                                    fHistoClusPhotonBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);
2282         }       
2283 }
2284
2285 //________________________________________________________________________
2286 void AliAnalysisTaskGammaCalo::FillPhotonPlusConversionBackgroundHist(AliAODConversionPhoton *TruePhotonCandidate, Int_t pdgCode)
2287 {
2288         // Bck = 0 e+-, 1 pi+-, 2 p+-, 3 K+-, 4 n, 5 K0s, 6 Lambda, 7 mu+-, 8 rest
2289         if(fIsFromMBHeader){
2290                 if(abs(pdgCode) == 11)                  fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);
2291                 else if( abs(pdgCode)==211)     fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);
2292                 else if( abs(pdgCode)==2212)    fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);
2293                 else if( abs(pdgCode)==321)     fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);
2294                 else if( abs(pdgCode)==2112)    fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);
2295                 else if( abs(pdgCode)==310)     fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);   
2296                 else if( abs(pdgCode)==3122)    fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);
2297                 else if( abs(pdgCode)==13)              fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);
2298                 else                                                    fHistoClusPhotonPlusConvBGPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);
2299         }       
2300 }
2301
2302
2303 void AliAnalysisTaskGammaCalo::SetLogBinningXTH2(TH2* histoRebin){
2304         TAxis *axisafter = histoRebin->GetXaxis();
2305         Int_t bins = axisafter->GetNbins();
2306         Double_t from = axisafter->GetXmin();
2307         Double_t to = axisafter->GetXmax();
2308         Double_t *newbins = new Double_t[bins+1];
2309         newbins[0] = from;
2310         Double_t factor = TMath::Power(to/from, 1./bins);
2311         for(Int_t i=1; i<=bins; ++i) newbins[i] = factor * newbins[i-1];
2312         axisafter->Set(bins, newbins);
2313         delete [] newbins;
2314 }
2315
2316 //________________________________________________________________________
2317 void AliAnalysisTaskGammaCalo::Terminate(const Option_t *)
2318 {
2319   
2320   //fOutputContainer->Print(); // Will crash on GRID
2321 }
2322
2323 //________________________________________________________________________
2324 Int_t AliAnalysisTaskGammaCalo::GetSourceClassification(Int_t daughter, Int_t pdgCode){
2325   
2326         if (daughter == 111) {
2327                 if (abs(pdgCode) == 310) return 1; // k0s
2328                 else if (abs(pdgCode) == 3122) return 2; // Lambda
2329                 else if (abs(pdgCode) == 130) return 3; // K0L
2330                 else if (abs(pdgCode) == 2212) return 4; // proton
2331                 else if (abs(pdgCode) == 2112) return 5; // neutron
2332                 else if (abs(pdgCode) == 211) return 6; // pion
2333                 else if (abs(pdgCode) == 321) return 7; // kaon
2334                 else if (abs(pdgCode) == 113 || abs(pdgCode) == 213 ) return 8; // rho 0,+,-
2335                 else if (abs(pdgCode) == 3222 || abs(pdgCode) == 3212 || abs(pdgCode) == 3112  ) return 9; // Sigma
2336                 else if (abs(pdgCode) == 2224 || abs(pdgCode) == 2214 || abs(pdgCode) == 2114 || abs(pdgCode) == 1114  ) return 10; // Delta
2337                 else if (abs(pdgCode) == 313 || abs(pdgCode) == 323   ) return 11; // K*
2338                 else return 15;
2339         }
2340         return 15;
2341   
2342 }