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