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