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