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