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