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