Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliAnalysisTaskGammaConvDalitzV1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: Pedro Gonz??lez, Pedro Ladr??n de Guevara, Ernesto L??pez Torres, *
5  *         Eulogio Serradilla, Ana Marin, Friederike Bock                 *
6  * Version 2                                                              *
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 // Analysis task for pi0->e+e-gamma (Dalitz decay)
18 // Analysis task for chic->JPsi+gamma
19
20 #include <vector>
21
22 #include "TParticle.h"
23 #include "TPDGCode.h"
24 #include "TMCProcess.h"
25 #include "TDatabasePDG.h"
26 #include "TList.h"
27 #include "TChain.h"
28 #include "TDirectory.h"
29 #include "TTree.h"
30 #include "TH1.h"
31 #include "TH1F.h"
32 #include "THnSparse.h"
33 #include "TH2F.h"
34 #include "AliStack.h"
35 #include "AliAnalysisManager.h"
36 #include "AliESDInputHandler.h"
37 #include "AliESDtrack.h"
38 #include "AliMCEvent.h"
39 #include "AliStack.h"
40 #include "AliMCEventHandler.h"
41 #include "AliPID.h"
42 #include "AliLog.h"
43 #include "AliESDtrackCuts.h"
44 #include "AliESDpidCuts.h"
45 #include "AliMCEvent.h"
46 #include "AliESDv0.h"
47 #include "AliESDEvent.h"
48 #include "AliESDpid.h"
49 #include "AliKFParticle.h"
50 #include "AliMCEventHandler.h"
51 #include "AliKFVertex.h"
52 #include "AliTriggerAnalysis.h"
53 #include "AliCentrality.h"
54 #include "AliMultiplicity.h"
55 #include "AliAnalysisTaskGammaConvDalitzV1.h"
56
57
58 ClassImp( AliAnalysisTaskGammaConvDalitzV1 )
59
60 //-----------------------------------------------------------------------------------------------
61 AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1():
62         fV0Reader(NULL),
63         fElecSelector(NULL),
64         fBGHandler(NULL),
65         fESDEvent(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         fQAFolder(NULL),
75         fOutputContainer(0),
76         fReaderGammas(NULL),
77         fSelectorElectronIndex(0),
78         fSelectorPositronIndex(0),
79         fGoodGammas(NULL),
80         fGoodVirtualGammas(NULL),
81         fGoodElectrons(NULL),
82         fGoodPositrons(NULL),
83         fCutEventArray(NULL),
84         fCutGammaArray(NULL),
85         fCutElectronArray(NULL),
86         fCutMesonArray(NULL),
87         fGammasPool(NULL),
88         fEventCuts(NULL),
89         fConversionCuts(NULL),
90         hESDConvGammaPt(NULL),
91         hESDConvGammaEta(NULL),
92         hESDConvGammaZR(NULL),
93         hESDDalitzElectronPt(NULL),
94         hESDDalitzPositronPt(NULL),
95         hESDDalitzElectronPhi(NULL),
96         hESDDalitzPositronPhi(NULL),
97         hESDDalitzElectronAfterPt(NULL),
98         hESDDalitzPositronAfterPt(NULL),
99         hESDDalitzElectronAfterEta(NULL),
100         hESDDalitzElectronAfterEtaPCut(NULL),
101         hESDDalitzPositronAfterEta(NULL),
102         hESDDalitzPositronAfterEtaPCut(NULL),
103         hESDDalitzElectronAfterPhi(NULL),
104         hESDDalitzPositronAfterPhi(NULL),
105         hESDDalitzElectronAfterNClsITS(NULL),
106         hESDDalitzPositronAfterNClsITS(NULL),
107         hESDDalitzElectronAfterNFindClsTPC(NULL),
108         hESDDalitzPositronAfterNFindClsTPC(NULL),
109         hESDDalitzElectronAfterNClsTPC(NULL),
110         hESDDalitzPositronAfterNClsTPC(NULL),
111         hESDDalitzElectronAfterNCrossedRowsTPC(NULL),
112         hESDDalitzPositronAfterNCrossedRowsTPC(NULL),
113         hESDDalitzPosEleAfterDCAxy(NULL),
114         hESDDalitzPosEleAfterDCAz(NULL),
115         hESDDalitzElectronAfterTPCdEdxVsP(NULL),
116         hESDDalitzPositronAfterTPCdEdxVsP(NULL),
117         hESDDalitzElectronAfterTPCdEdxSignalVsP(NULL),
118         hESDDalitzPositronAfterTPCdEdxSignalVsP(NULL),
119         hESDDalitzElectronAfterTPCdEdxVsEta(NULL),
120         hESDDalitzPositronAfterTPCdEdxVsEta(NULL),
121         hESDDalitzElectronAfterTPCdEdxVsPhi(NULL),
122         hESDDalitzPositronAfterTPCdEdxVsPhi(NULL),
123         hESDMotherPhi(NULL),
124         hESDEposEnegPsiPairDPhi(NULL),
125         hESDEposEnegInvMassPt(NULL),
126         hESDEposEnegAfterMassCutInvMassPi0Pt(NULL),
127         hESDEposEnegInvMassPi0Pt(NULL),
128         hESDEposEnegLikeSignBackInvMassPt(NULL),
129         hESDMotherInvMassPt(NULL),
130         hESDPi0MotherInvMassPt(NULL),
131         hESDPi0MotherDiffInvMassPt(NULL),
132         hESDPi0MotherDiffLimInvMassPt(NULL),
133         sESDMotherInvMassPtZM(NULL),
134         hESDMotherBackInvMassPt(NULL),
135         sESDMotherBackInvMassPtZM(NULL),
136         hMCAllGammaPt(NULL),
137         hMCConvGammaPt(NULL),
138         hMCConvGammaRSPt(NULL),
139         hMCAllPositronsPt(NULL),
140         hMCAllElectronsPt(NULL),
141         hMCConvGammaEta(NULL),
142         hMCConvGammaR(NULL),
143         hMCAllPositronsEta(NULL),
144         hMCAllElectronsEta(NULL),
145         hMCPi0DalitzGammaPt(NULL),
146         hMCPi0DalitzElectronPt(NULL),
147         hMCPi0DalitzPositronPt(NULL),
148         hMCPi0Pt(NULL),
149         hMCPi0GGPt(NULL),
150         hMCEtaPt(NULL),
151         hMCEtaGGPt(NULL), 
152         hMCPi0InAccPt(NULL),
153         hMCEtaInAccPt(NULL),
154         hMCChiCPt(NULL),
155         hMCChiCInAccPt(NULL),
156         hMCPi0EposEnegInvMassPt(NULL),
157         hMCEtaEposEnegInvMassPt(NULL),
158         hESDEposEnegTruePi0DalitzInvMassPt(NULL),
159         hESDEposEnegTruePrimPi0DalitzInvMass(NULL),
160         hESDEposEnegTruePi0DalitzPsiPairDPhi(NULL),
161         hESDEposEnegTrueEtaDalitzInvMassPt(NULL),
162         hESDEposEnegTruePrimEtaDalitzInvMass(NULL),
163         hESDEposEnegTrueEtaDalitzPsiPairDPhi(NULL),
164         hESDEposEnegTruePhotonInvMassPt(NULL),
165         hESDEposEnegTrueInvMassPt(NULL),
166         hESDEposEnegTruePhotonPsiPairDPhi(NULL),
167         hESDEposEnegTruePhotonPsiPairDPhiPtCut(NULL),
168         hESDEposEnegTrueJPsiInvMassPt(NULL),
169         hESDTrueMotherChiCInvMassPt(NULL),
170         hESDTrueMotherChiCDiffInvMassPt(NULL),
171         hESDTrueMotherInvMassPt(NULL),
172         hESDTrueMotherDalitzInvMassPt(NULL),
173         hESDTrueMotherPi0GGInvMassPt(NULL),
174         hESDTruePrimaryMotherPi0GGInvMassPt(NULL),
175         hESDTrueSecondaryMotherPi0GGInvMassPt(NULL),
176         hESDTruePrimaryMotherInvMassMCPt(NULL),
177         hESDTruePrimaryMotherInvMassPt(NULL),
178         hESDTruePrimaryMotherW0WeightingInvMassPt(NULL),
179         hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
180         hESDTrueSecondaryMotherInvMassPt(NULL),
181         hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
182         hESDTrueBckGGInvMassPt(NULL),
183         hESDTrueBckContInvMassPt(NULL),
184         hESDTrueMotherGGInvMassPt(NULL),
185         hESDTrueConvGammaPt(NULL),
186         hESDTrueConvGammaR(NULL),
187         hESDTruePositronPt(NULL),
188         hESDTrueElectronPt(NULL),
189         hESDTrueSecConvGammaPt(NULL),
190         hESDTrueSecPositronPt(NULL),
191         hESDTrueSecElectronPt(NULL),
192         hESDTruePi0DalitzConvGammaPt(NULL),
193         hESDTruePi0DalitzPositronPt(NULL),
194         hESDTruePi0DalitzElectronPt(NULL),
195         hESDTruePi0DalitzSecConvGammaPt(NULL),
196         hESDTruePi0DalitzSecPositronPt(NULL),
197         hESDTruePi0DalitzSecElectronPt(NULL),
198         hNEvents(NULL),
199         hNGoodESDTracks(NULL),
200         hNGoodESDTracksVsNGoodGammas(NULL),
201         hNGoodESDTracksVsNGoodVGammas(NULL),
202         hNV0Tracks(NULL),
203         hEtaShift(NULL),
204         fRandom(0),
205         fUnsmearedPx(NULL),
206         fUnsmearedPy(NULL),
207         fUnsmearedPz(NULL),
208         fUnsmearedE(NULL),
209         fUnsmearedVPx(NULL),
210         fUnsmearedVPy(NULL),
211         fUnsmearedVPz(NULL),
212         fUnsmearedVE(NULL),
213         fnCuts(0),
214         fiCut(0),
215         fNumberOfESDTracks(0),
216         fNumberOfESDTrackskBoth(0),
217         fNVirtualGammas(0),
218         fMoveParticleAccordingToVertex(kFALSE),
219         fIsHeavyIon(0),
220         fDoMesonAnalysis(kTRUE),
221         fDoChicAnalysis(kFALSE),
222         fDoMesonQA(kFALSE),
223         fSetProductionVertextoVGamma(kTRUE),
224         fIsFromMBHeader(kTRUE),
225         fIsMC(kFALSE)
226 {
227
228 }
229
230 //-----------------------------------------------------------------------------------------------
231 AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char* name ):
232         AliAnalysisTaskSE(name),
233         fV0Reader(NULL),
234         fElecSelector(NULL),
235         fBGHandler(NULL),
236         fESDEvent(NULL),
237         fMCEvent(NULL),
238         fMCStack(NULL),
239         fCutFolder(NULL),
240         fESDList(NULL),
241         fBackList(NULL),
242         fMotherList(NULL),
243         fTrueList(NULL),
244         fMCList(NULL),
245         fQAFolder(NULL),
246         fOutputContainer(0),
247         fReaderGammas(NULL),
248         fSelectorElectronIndex(0),
249         fSelectorPositronIndex(0),
250         fGoodGammas(NULL),
251         fGoodVirtualGammas(NULL),
252         fGoodElectrons(NULL),
253         fGoodPositrons(NULL),
254         fCutEventArray(NULL),
255         fCutGammaArray(NULL),
256         fCutElectronArray(NULL),
257         fCutMesonArray(NULL),
258         fGammasPool(NULL),
259         fEventCuts(NULL),
260         fConversionCuts(NULL),
261         hESDConvGammaPt(NULL),
262         hESDConvGammaEta(NULL),
263         hESDConvGammaZR(NULL),
264         hESDDalitzElectronPt(NULL),
265         hESDDalitzPositronPt(NULL),
266         hESDDalitzElectronPhi(NULL),
267         hESDDalitzPositronPhi(NULL),
268         hESDDalitzElectronAfterPt(NULL),
269         hESDDalitzPositronAfterPt(NULL),
270         hESDDalitzElectronAfterEta(NULL),
271         hESDDalitzElectronAfterEtaPCut(NULL),
272         hESDDalitzPositronAfterEta(NULL),
273         hESDDalitzPositronAfterEtaPCut(NULL),
274         hESDDalitzElectronAfterPhi(NULL),
275         hESDDalitzPositronAfterPhi(NULL),
276         hESDDalitzElectronAfterNClsITS(NULL),
277         hESDDalitzPositronAfterNClsITS(NULL),
278         hESDDalitzElectronAfterNFindClsTPC(NULL),
279         hESDDalitzPositronAfterNFindClsTPC(NULL),
280         hESDDalitzElectronAfterNClsTPC(NULL),
281         hESDDalitzPositronAfterNClsTPC(NULL),
282         hESDDalitzElectronAfterNCrossedRowsTPC(NULL),
283         hESDDalitzPositronAfterNCrossedRowsTPC(NULL),
284         hESDDalitzPosEleAfterDCAxy(NULL),
285         hESDDalitzPosEleAfterDCAz(NULL),
286         hESDDalitzElectronAfterTPCdEdxVsP(NULL),
287         hESDDalitzPositronAfterTPCdEdxVsP(NULL),
288         hESDDalitzElectronAfterTPCdEdxSignalVsP(NULL),
289         hESDDalitzPositronAfterTPCdEdxSignalVsP(NULL),
290         hESDDalitzElectronAfterTPCdEdxVsEta(NULL),
291         hESDDalitzPositronAfterTPCdEdxVsEta(NULL),
292         hESDDalitzElectronAfterTPCdEdxVsPhi(NULL),
293         hESDDalitzPositronAfterTPCdEdxVsPhi(NULL),
294         hESDMotherPhi(NULL),
295         hESDEposEnegPsiPairDPhi(NULL),
296         hESDEposEnegInvMassPt(NULL),
297         hESDEposEnegAfterMassCutInvMassPi0Pt(NULL),
298         hESDEposEnegInvMassPi0Pt(NULL),
299         hESDEposEnegLikeSignBackInvMassPt(NULL),
300         hESDMotherInvMassPt(NULL),
301         hESDPi0MotherInvMassPt(NULL),
302         hESDPi0MotherDiffInvMassPt(NULL),
303         hESDPi0MotherDiffLimInvMassPt(NULL),
304         sESDMotherInvMassPtZM(NULL),
305         hESDMotherBackInvMassPt(NULL),
306         sESDMotherBackInvMassPtZM(NULL),
307         hMCAllGammaPt(NULL),
308         hMCConvGammaPt(NULL),
309         hMCConvGammaRSPt(NULL),
310         hMCAllPositronsPt(NULL),
311         hMCAllElectronsPt(NULL),
312         hMCConvGammaEta(NULL),
313         hMCConvGammaR(NULL),
314         hMCAllPositronsEta(NULL),
315         hMCAllElectronsEta(NULL),
316         hMCPi0DalitzGammaPt(NULL),
317         hMCPi0DalitzElectronPt(NULL),
318         hMCPi0DalitzPositronPt(NULL),
319         hMCPi0Pt(NULL),
320         hMCPi0GGPt(NULL),
321         hMCEtaPt(NULL),
322         hMCEtaGGPt(NULL),
323         hMCPi0InAccPt(NULL),
324         hMCEtaInAccPt(NULL),
325         hMCChiCPt(NULL),
326         hMCChiCInAccPt(NULL),
327         hMCPi0EposEnegInvMassPt(NULL),
328         hMCEtaEposEnegInvMassPt(NULL),
329         hESDEposEnegTruePi0DalitzInvMassPt(NULL),
330         hESDEposEnegTruePrimPi0DalitzInvMass(NULL),
331         hESDEposEnegTruePi0DalitzPsiPairDPhi(NULL),
332         hESDEposEnegTrueEtaDalitzInvMassPt(NULL),
333         hESDEposEnegTruePrimEtaDalitzInvMass(NULL),
334         hESDEposEnegTrueEtaDalitzPsiPairDPhi(NULL),
335         hESDEposEnegTruePhotonInvMassPt(NULL),
336         hESDEposEnegTrueInvMassPt(NULL),
337         hESDEposEnegTruePhotonPsiPairDPhi(NULL),
338         hESDEposEnegTruePhotonPsiPairDPhiPtCut(NULL),
339         hESDEposEnegTrueJPsiInvMassPt(NULL),
340         hESDTrueMotherChiCInvMassPt(NULL),
341         hESDTrueMotherChiCDiffInvMassPt(NULL),
342         hESDTrueMotherInvMassPt(NULL),
343         hESDTrueMotherDalitzInvMassPt(NULL),
344         hESDTrueMotherPi0GGInvMassPt(NULL),
345         hESDTruePrimaryMotherPi0GGInvMassPt(NULL),
346         hESDTrueSecondaryMotherPi0GGInvMassPt(NULL),
347         hESDTruePrimaryMotherInvMassMCPt(NULL),
348         hESDTruePrimaryMotherInvMassPt(NULL),
349         hESDTruePrimaryMotherW0WeightingInvMassPt(NULL),
350         hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
351         hESDTrueSecondaryMotherInvMassPt(NULL),
352         hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
353         hESDTrueBckGGInvMassPt(NULL),
354         hESDTrueBckContInvMassPt(NULL),
355         hESDTrueMotherGGInvMassPt(NULL),
356         hESDTrueConvGammaPt(NULL),
357         hESDTrueConvGammaR(NULL),
358         hESDTruePositronPt(NULL),
359         hESDTrueElectronPt(NULL),
360         hESDTrueSecConvGammaPt(NULL),
361         hESDTrueSecPositronPt(NULL),
362         hESDTrueSecElectronPt(NULL),
363         hESDTruePi0DalitzConvGammaPt(NULL),
364         hESDTruePi0DalitzPositronPt(NULL),
365         hESDTruePi0DalitzElectronPt(NULL),
366         hESDTruePi0DalitzSecConvGammaPt(NULL),
367         hESDTruePi0DalitzSecPositronPt(NULL),
368         hESDTruePi0DalitzSecElectronPt(NULL),
369         hNEvents(NULL),
370         hNGoodESDTracks(NULL),
371         hNGoodESDTracksVsNGoodGammas(NULL),
372         hNGoodESDTracksVsNGoodVGammas(NULL),
373         hNV0Tracks(NULL),
374         hEtaShift(NULL),
375         fRandom(0),
376         fUnsmearedPx(NULL),
377         fUnsmearedPy(NULL),
378         fUnsmearedPz(NULL),
379         fUnsmearedE(NULL),
380         fUnsmearedVPx(NULL),
381         fUnsmearedVPy(NULL),
382         fUnsmearedVPz(NULL),
383         fUnsmearedVE(NULL),
384         fnCuts(0),
385         fiCut(0),
386         fNumberOfESDTracks(0),
387         fNumberOfESDTrackskBoth(0),
388         fNVirtualGammas(0),
389         fMoveParticleAccordingToVertex(kFALSE),
390         fIsHeavyIon(0),
391         fDoMesonAnalysis(kTRUE),
392         fDoChicAnalysis(kFALSE),
393         fDoMesonQA(kFALSE),
394         fSetProductionVertextoVGamma(kTRUE),
395         fIsFromMBHeader(kTRUE),
396         fIsMC(kFALSE)
397 {
398         DefineOutput(1, TList::Class());
399 }
400
401 //-----------------------------------------------------------------------------------------------
402 AliAnalysisTaskGammaConvDalitzV1::~AliAnalysisTaskGammaConvDalitzV1()
403 {
404         //
405         // virtual destructor
406         //
407
408         cout<<"Destructor"<<endl;
409
410         if(fGoodGammas){
411                 delete fGoodGammas;
412                 fGoodGammas = 0x0;
413         }
414         if(fGoodVirtualGammas){
415                 delete fGoodVirtualGammas;
416                 fGoodVirtualGammas = 0x0;
417         }
418         if(fGoodElectrons){
419                 delete fGoodElectrons;
420                 fGoodElectrons = 0x0;
421         }
422         if(fGoodPositrons){
423                 delete fGoodPositrons;
424                 fGoodPositrons = 0x0;
425         }
426         if(fBGHandler){
427                 delete[] fBGHandler;
428                 fBGHandler = 0x0;
429         }
430         if( fGammasPool ){
431                 delete[] fGammasPool;
432                 fGammasPool = 0x0;
433         }
434 }
435
436 //___________________________________________________________
437 void AliAnalysisTaskGammaConvDalitzV1::InitBack(){
438
439         const Int_t nDim = 4;
440         Int_t nBins[nDim] = {800,250,7,4};
441         Double_t xMin[nDim] = {0,0, 0,0};
442         Double_t xMax[nDim] = {0.8,25,7,4};
443         
444         sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
445         sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
446
447         fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
448         
449         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
450         
451                 TString cutstringEvent          = ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber();
452                 TString cutstringElectron       = ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
453                 TString cutstringMeson          = ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
454                 TString cutstringGamma          = ((AliConversionPhotonCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
455                 
456                 Int_t collisionSystem = atoi((TString)(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber())(0,1));
457                 Int_t centMin = atoi((TString)(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber())(1,1));
458                 Int_t centMax = atoi((TString)(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber())(2,1));
459                 
460                 if(collisionSystem == 1 || collisionSystem == 2 ||
461                         collisionSystem == 5 || collisionSystem == 8 ||
462                         collisionSystem == 9){
463                         centMin = centMin*10;
464                         centMax = centMax*10; 
465                 }
466                 else if(collisionSystem == 3 || collisionSystem == 6){
467                         centMin = centMin*5;
468                         centMax = centMax*5;
469                 }
470                 else if(collisionSystem == 4 || collisionSystem == 7){
471                         centMin = ((centMin*5)+45);
472                         centMax = ((centMax*5)+45);
473                 }
474
475
476                 fBackList[iCut] = new TList();
477                 fBackList[iCut]->SetName(Form("%s_%s_%s_%s Back histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
478                 fBackList[iCut]->SetOwner(kTRUE);
479                 fCutFolder[iCut]->Add(fBackList[iCut]);
480
481                 sESDMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
482                 fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
483
484                 fMotherList[iCut] = new TList();
485                 fMotherList[iCut]->SetName(Form("%s_%s_%s_%s Mother histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
486                 fMotherList[iCut]->SetOwner(kTRUE);
487                 fCutFolder[iCut]->Add(fMotherList[iCut]);
488
489                 sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
490                 fMotherList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
491
492                 
493                 fBGHandler[iCut] = new AliGammaConversionAODBGHandler(
494                                                                                                                                 collisionSystem,centMin,centMax,
495                                                                                                                                 ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->NumberOfRotationEvents(),
496                                                                                                                                 ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->UseTrackMultiplicity(),
497                                                                                                                                 1,8,5);
498                 
499                 if( ( (AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetBKGMethod() == 3 ){
500                         fGammasPool[iCut] = new TList();
501                 }
502                         
503         }
504 }
505
506 //______________________________________________________________________
507 void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
508 {
509         //
510         // Create ouput objects
511         //
512
513         // Create the output container
514         if(fOutputContainer != NULL){
515                 delete fOutputContainer;
516                 fOutputContainer = NULL;
517         }
518         if(fOutputContainer == NULL){
519                 fOutputContainer = new TList();
520                 fOutputContainer->SetOwner(kTRUE);
521         }
522
523         fGoodGammas = new TList();
524         //fGoodGammas->SetOwner(kTRUE);
525
526         fGoodVirtualGammas = new TList();
527         fGoodVirtualGammas->SetOwner(kTRUE);
528
529         fGammasPool                             = new TList*[fnCuts];
530         fCutFolder                              = new TList*[fnCuts];
531         fESDList                                = new TList*[fnCuts];
532         fBackList                               = new TList*[fnCuts];
533         fMotherList                             = new TList*[fnCuts];
534         hNEvents                                = new TH1I*[fnCuts];
535         hNGoodESDTracks                 = new TH1I*[fnCuts];
536         hNV0Tracks                              = new TH1I*[fnCuts];
537         hEtaShift                               = new TProfile*[fnCuts];
538         hESDConvGammaPt                 = new TH1F*[fnCuts];
539         hESDConvGammaEta                = new TH1F*[fnCuts];
540         
541         hESDDalitzElectronPt    = new TH1F*[fnCuts];
542         hESDDalitzPositronPt    = new TH1F*[fnCuts];
543         hESDDalitzElectronPhi   = new TH1F*[fnCuts];
544         hESDDalitzPositronPhi   = new TH1F*[fnCuts];
545         
546         if( fDoMesonQA ) {
547                 fQAFolder                                                               = new TList*[fnCuts];  
548                 hNGoodESDTracksVsNGoodGammas                    = new TH2F*[fnCuts];
549                 hNGoodESDTracksVsNGoodVGammas                   = new TH2F*[fnCuts]; 
550                 hESDDalitzElectronAfterPt                               = new TH1F*[fnCuts];
551                 hESDDalitzPositronAfterPt                               = new TH1F*[fnCuts];
552                 hESDDalitzElectronAfterEta                              = new TH1F*[fnCuts];
553                 hESDDalitzElectronAfterEtaPCut                  = new TH1F*[fnCuts];
554                 hESDDalitzPositronAfterEta                              = new TH1F*[fnCuts];
555                 hESDDalitzPositronAfterEtaPCut                  = new TH1F*[fnCuts];
556                 hESDDalitzElectronAfterPhi                              = new TH1F*[fnCuts];
557                 hESDDalitzPositronAfterPhi                              = new TH1F*[fnCuts];
558                 hESDDalitzElectronAfterNClsITS                  = new TH1F*[fnCuts];
559                 hESDDalitzPositronAfterNClsITS                  = new TH1F*[fnCuts];
560                 hESDDalitzElectronAfterNFindClsTPC              = new TH2F*[fnCuts];
561                 hESDDalitzPositronAfterNFindClsTPC              = new TH2F*[fnCuts];
562                 hESDDalitzElectronAfterNClsTPC                  = new TH2F*[fnCuts];
563                 hESDDalitzPositronAfterNClsTPC                  = new TH2F*[fnCuts];
564                 hESDDalitzElectronAfterNCrossedRowsTPC  = new TH2F*[fnCuts];
565                 hESDDalitzPositronAfterNCrossedRowsTPC  = new TH2F*[fnCuts];
566                 hESDDalitzPosEleAfterDCAxy                              = new TH2F*[fnCuts];
567                 hESDDalitzPosEleAfterDCAz                               = new TH2F*[fnCuts];
568                 hESDDalitzElectronAfterTPCdEdxVsP               = new TH2F*[fnCuts];
569                 hESDDalitzPositronAfterTPCdEdxVsP               = new TH2F*[fnCuts];
570                 hESDDalitzElectronAfterTPCdEdxSignalVsP = new TH2F*[fnCuts];
571                 hESDDalitzPositronAfterTPCdEdxSignalVsP = new TH2F*[fnCuts];
572                 hESDDalitzElectronAfterTPCdEdxVsEta     = new TH2F*[fnCuts];
573                 hESDDalitzPositronAfterTPCdEdxVsEta     = new TH2F*[fnCuts];
574                 hESDDalitzElectronAfterTPCdEdxVsPhi     = new TH2F*[fnCuts];
575                 hESDDalitzPositronAfterTPCdEdxVsPhi     = new TH2F*[fnCuts];
576                 hESDMotherPhi                                                   = new TH1F*[fnCuts];
577                 hESDEposEnegPsiPairDPhi                                 = new TH2F*[fnCuts];
578                 hESDEposEnegInvMassPt                                   = new TH2F*[fnCuts];
579                 hESDEposEnegAfterMassCutInvMassPi0Pt    = new TH2F*[fnCuts];
580                 hESDEposEnegInvMassPi0Pt                                = new TH2F*[fnCuts];
581                 hESDEposEnegLikeSignBackInvMassPt               = new TH2F*[fnCuts];
582                 hESDConvGammaZR                                                 = new TH2F*[fnCuts];
583         }
584         
585         
586         
587         hESDMotherInvMassPt             = new TH2F*[fnCuts];
588         if(fDoChicAnalysis) {
589                 hESDPi0MotherInvMassPt                                  = new TH2F*[fnCuts];
590                 hESDPi0MotherDiffInvMassPt                              = new TH2F*[fnCuts];
591                 hESDPi0MotherDiffLimInvMassPt                   = new TH2F*[fnCuts];
592         }
593         hESDMotherBackInvMassPt = new TH2F*[fnCuts];
594
595
596         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
597
598                 TString cutstringEvent          = ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber();
599                 TString cutstringElectron       = ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
600                 TString cutstringMeson          = ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
601                 TString cutstringGamma          = ((AliConversionPhotonCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
602
603                 fCutFolder[iCut] = new TList();
604                 fCutFolder[iCut]->SetName(Form("Cut Number %s_%s_%s_%s",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
605                 fCutFolder[iCut]->SetOwner(kTRUE);
606                 fOutputContainer->Add(fCutFolder[iCut]);
607
608                 fESDList[iCut] = new TList();
609                 fESDList[iCut]->SetName(Form("%s_%s_%s_%s ESD histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
610                 fESDList[iCut]->SetOwner(kTRUE);
611                 
612                 hNEvents[iCut] = new TH1I("NEvents","NEvents",10,-0.5,9.5);
613                 hNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
614                 hNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
615                 hNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Missing MC");
616                 hNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
617                 hNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
618                 hNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
619                 hNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
620                 hNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
621                 hNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
622                 hNEvents[iCut]->GetXaxis()->SetBinLabel(10,"EMCAL problem");
623                 fESDList[iCut]->Add(hNEvents[iCut]);
624
625                 if(fIsHeavyIon == 1 || fIsHeavyIon == 2) hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
626                 else hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
627                 fESDList[iCut]->Add(hNGoodESDTracks[iCut]);
628                 
629                 
630                 if(fIsHeavyIon == 1) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
631                 else if(fIsHeavyIon == 2) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2500,0,2500);
632                 else hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",1500,0,1500);
633                 fESDList[iCut]->Add(hNV0Tracks[iCut]);
634                 
635                 hEtaShift[iCut] = new TProfile("Eta Shift","Eta Shift",1, -0.5,0.5);
636                 fESDList[iCut]->Add(hEtaShift[iCut]);
637
638                 hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
639                 fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
640                 
641                 hESDConvGammaEta[iCut] = new TH1F("ESD_ConvGamma_Eta","ESD_ConvGamma_Eta",600,-1.5,1.5);
642                 fESDList[iCut]->Add(hESDConvGammaEta[iCut]);
643                 
644                 hESDDalitzElectronPt[iCut] = new TH1F("ESD_DalitzElectron_Pt","ESD_DalitzElectron_Pt",1000,0,25);
645                 fESDList[iCut]->Add(hESDDalitzElectronPt[iCut]);
646
647                 hESDDalitzPositronPt[iCut] = new TH1F("ESD_DalitzPositron_Pt","ESD_DalitzPositron_Pt",1000,0,25);
648                 fESDList[iCut]->Add(hESDDalitzPositronPt[iCut]);
649                 
650                 
651                 hESDDalitzElectronPhi[iCut] = new TH1F("ESD_DalitzElectron_Phi","ESD_DalitzElectron_Phi",360,0,2*TMath::Pi());
652                 fESDList[iCut]->Add(hESDDalitzElectronPhi[iCut]);
653
654                 hESDDalitzPositronPhi[iCut] = new TH1F("ESD_DalitzPositron_Phi","ESD_DalitzPositron_Phi",360,0,2*TMath::Pi());
655                 fESDList[iCut]->Add(hESDDalitzPositronPhi[iCut]);
656                 
657                 
658                 
659                 if ( fDoMesonQA ) {
660
661                         fQAFolder[iCut] = new TList();
662                         fQAFolder[iCut]->SetName(Form("%s_%s_%s_%s QA histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
663                         fQAFolder[iCut]->SetOwner(kTRUE);
664                                 
665                         const Int_t kPtBins=110;
666                         Double_t binsPtDummy[kPtBins+1];
667                         const Int_t kPBins = 109;
668                         Double_t binsPDummy[kPBins+1];
669                         binsPtDummy[0]=0.0;
670                         binsPDummy[0]=0.05;
671                         
672                         for(Int_t i=1;i<kPtBins+1;i++){
673                                 if(binsPtDummy[i-1]+0.05<1.01)
674                                                 binsPtDummy[i]=binsPtDummy[i-1]+0.05;
675                                 else
676                                                 binsPtDummy[i]=binsPtDummy[i-1]+0.1;            
677                         }
678                         for(Int_t i=1; i<kPBins+1;i++){ 
679                                 if( binsPDummy[i-1]+0.05<1.01)
680                                                 binsPDummy[i] = binsPDummy[i-1]+0.05;
681                                 else
682                                         binsPDummy[i] = binsPDummy[i-1]+0.1;
683                         }
684                                 
685                         hNGoodESDTracksVsNGoodGammas[iCut] = new TH2F("hNGoodESDTracksVsNGoodGammas","hNGoodESDTracksVsNGoodGammas",200,-0.5,199.5,100,-0.5,99.5);
686                         fQAFolder[iCut]->Add(hNGoodESDTracksVsNGoodGammas[iCut]);
687                         
688                         hNGoodESDTracksVsNGoodVGammas[iCut] = new TH2F("hNGoodESDTracksVsNVGoodVGammas","hNGoodESDTracksVsNGoodVGammas",200,-0.5,199.5,100,-0.5,99.5);
689                         fQAFolder[iCut]->Add(hNGoodESDTracksVsNGoodVGammas[iCut]);
690                                         
691                         hESDConvGammaZR[iCut]= new TH2F("ESD_ConvGamma_ConversionPoint_ZR","ESD_ConvGamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
692                         fQAFolder[iCut]->Add(hESDConvGammaZR[iCut]);
693                         
694                         hESDDalitzElectronAfterPt[iCut] = new TH1F("ESD_DalitzElectron_After_Pt","ESD_DalitzElectron_After_Pt",1000,0,25);
695                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterPt[iCut]);
696
697                         hESDDalitzPositronAfterPt[iCut] = new TH1F("ESD_DalitzPositron_After_Pt","ESD_DalitzPositron_After_Pt",1000,0,25);
698                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterPt[iCut]);
699                                 
700                         hESDDalitzElectronAfterEta[iCut] = new TH1F("ESD_DalitzElectron_After_Eta","ESD_DalitzElectron_After_Eta",600,-1.5,1.5);
701                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterEta[iCut]);
702                         
703                         hESDDalitzElectronAfterEtaPCut[iCut] = new TH1F("ESD_DalitzElectron_After_Eta_PCut","ESD_DalitzElectron_After_Eta_PCut",600,-1.5,1.5);
704                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterEtaPCut[iCut]);
705                         
706                         hESDDalitzPositronAfterEta[iCut] = new TH1F("ESD_DalitzPositron_After_Eta","ESD_DalitzElectron_After_Eta",600,-1.5,1.5);
707                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterEta[iCut]);
708                         
709                         hESDDalitzPositronAfterEtaPCut[iCut] = new TH1F("ESD_DalitzPositron_After_Eta_PCut","ESD_DalitzElectron_After_Eta_PCut",600,-1.5,1.5);
710                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterEtaPCut[iCut]);
711                         
712                         hESDDalitzElectronAfterPhi[iCut] = new TH1F("ESD_DalitzElectron_After_Phi","ESD_DalitzElectron_After_Phi",360,0,2*TMath::Pi());
713                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterPhi[iCut]);
714
715                         hESDDalitzPositronAfterPhi[iCut] = new TH1F("ESD_DalitzPositron_After_Phi","ESD_DalitzPositron_After_Phi",360,0,2*TMath::Pi());
716                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterPhi[iCut]);
717                         
718                         hESDDalitzElectronAfterNClsITS[iCut]  = new TH1F("ESD_DalitzElectron_After_NClsITS","ESD_DalitzElectron_After_NClsITS",7,0.,7.);
719                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterNClsITS[iCut]);
720                         
721                         hESDDalitzPositronAfterNClsITS[iCut]  = new TH1F("ESD_DalitzPositron_After_NClsITS","ESD_DalitzPositron_After_NClsITS",7,0.,7.);
722                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterNClsITS[iCut]);
723                         
724                         hESDDalitzElectronAfterNFindClsTPC[iCut]  = new TH2F("ESD_DalitzElectron_After_NFindClsTPC","ESD_DalitzElectron_After_NFindClsTPC",60,0,1.5,kPtBins,binsPtDummy);
725                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterNFindClsTPC[iCut]);
726                         
727                         hESDDalitzPositronAfterNFindClsTPC[iCut]  = new TH2F("ESD_DalitzPositron_After_NFindClsTPC","ESD_DalitzPositron_After_NFindClsTPC",60,0,1.5,kPtBins,binsPtDummy);
728                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterNFindClsTPC[iCut]);
729                         
730                         hESDDalitzElectronAfterNClsTPC[iCut]  = new TH2F("ESD_DalitzElectron_After_NClsTPC","ESD_DalitzElectron_After_NClsTPC",200,0,200,kPtBins,binsPtDummy);
731                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterNClsTPC[iCut]);
732                         
733                         hESDDalitzPositronAfterNClsTPC[iCut]  = new TH2F("ESD_DalitzPositron_After_NClsTPC","ESD_DalitzPositron_After_NClsTPC",200,0,200,kPtBins,binsPtDummy);
734                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterNClsTPC[iCut]);
735                                         
736                         hESDDalitzPositronAfterNCrossedRowsTPC[iCut] =  new TH2F("ESD_DalitzPositron_After_NCrossedRowsTPC","ESD_DalitzPositron_After_NCrossedRowsTPC",165,-0.5,164.5,kPtBins,binsPtDummy);
737                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterNCrossedRowsTPC[iCut]);
738                         
739                         hESDDalitzElectronAfterNCrossedRowsTPC[iCut] =  new TH2F("ESD_DalitzElectron_After_NCrossedRowsTPC","ESD_DalitzElectron_After_NCrossedRowsTPC",165,-0.5,164.5,kPtBins,binsPtDummy);
740                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterNCrossedRowsTPC[iCut]);
741                                         
742                         hESDDalitzPosEleAfterDCAxy[iCut] = new TH2F("ESD_DalitzPosEle_After_DCAxy","ESD_DalitzPosEle_After_DCAxy",124,-0.62,0.62,kPtBins,binsPtDummy);
743                         fQAFolder[iCut]->Add(hESDDalitzPosEleAfterDCAxy[iCut]);
744                         
745                         hESDDalitzPosEleAfterDCAz[iCut]  = new TH2F("ESD_DalitzPosEle_After_DCAz","ESD_DalitzPosEle_After_DCAz",200,-1.0,1.0,kPtBins,binsPtDummy);
746                         fQAFolder[iCut]->Add(hESDDalitzPosEleAfterDCAz[iCut]);
747                         
748                         hESDDalitzElectronAfterTPCdEdxVsP[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsP","ESD_DalitzElectron_After_TPCdEdxVsP_After_TPCdEdx",kPBins,binsPDummy,200,-10,10);
749                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsP[iCut]);
750                         
751                         hESDDalitzPositronAfterTPCdEdxVsP[iCut] = new TH2F("ESD_DalitzPositron_After_TPCdEdxVsP","ESD_DalitzPositron_After_TPCdEdxVsP",kPBins,binsPDummy,200,-10,10);
752                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsP[iCut]);
753                         
754                         hESDDalitzElectronAfterTPCdEdxSignalVsP[iCut] =new TH2F("ESD_DalitzElectron_After_TPCdEdxSignalVsP","ESD_DalitzElectron_After_TPCdEdxSignalVsP" ,kPBins,binsPDummy,200,0.0,200);
755                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxSignalVsP[iCut]);  
756                         
757                         hESDDalitzPositronAfterTPCdEdxSignalVsP[iCut] =new TH2F("ESD_DalitzPositron_After_TPCdEdxSignalVsP","ESD_DalitzPositron_After_TPCdEdxSignalVsP" ,kPBins,binsPDummy,200,0.0,200);
758                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxSignalVsP[iCut]); 
759                         
760                         hESDDalitzElectronAfterTPCdEdxVsEta[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsEta","ESD_DalitzElectron_After_TPCdEdxVsEta",140,-1.4,1.4,200,-10,10);
761                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsEta[iCut]);
762                         
763                         hESDDalitzPositronAfterTPCdEdxVsEta[iCut] = new  TH2F("ESD_DalitzPositron_After_TPCdEdxVsEta","ESD_DalitzPositron_After_TPCdEdxVsEta",140,-1.4,1.4,200,-10,10);
764                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsEta[iCut]);
765                         
766                         hESDDalitzElectronAfterTPCdEdxVsPhi[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsPhi","ESD_DalitzElectron_After_TPCdEdxVsPhi",180,0,2*TMath::Pi(),200,-10,10);
767                         fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsPhi[iCut]);
768                         
769                         hESDDalitzPositronAfterTPCdEdxVsPhi[iCut] = new TH2F("ESD_DalitzPositron_After_TPCdEdxVsPhi","ESD_DalitzPositron_After_TPCdEdxVsPhi",180,0,2*TMath::Pi(),200,-10,10);
770                         fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsPhi[iCut]);
771                                         
772                         hESDMotherPhi[iCut] = new TH1F("ESD_DalitzMother_Phi","ESD_DalitzMother_Phi",360,0,2*TMath::Pi());
773                         fQAFolder[iCut]->Add(hESDMotherPhi[iCut]);
774                         
775                         hESDEposEnegPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_PsiPair_DPhi","ESD_EposEneg_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
776                         fQAFolder[iCut]->Add(hESDEposEnegPsiPairDPhi[iCut]);
777
778                         hESDEposEnegInvMassPt[iCut] = new TH2F("ESD_EposEneg_InvMassPt","ESD_EposEneg_InvMassPt",4000,0.0,2.0,100,0.,10.);
779                         fQAFolder[iCut]->Add(hESDEposEnegInvMassPt[iCut]);
780                         
781                         hESDEposEnegAfterMassCutInvMassPi0Pt[iCut] = new TH2F("ESD_EposEneg_AfterMassCut_InvMassPi0Pt","ESD_EposEneg_AfterMassCut_InvMassPi0Pt",4000,0.0,2.0,100,0.,10.);
782                         fQAFolder[iCut]->Add(hESDEposEnegAfterMassCutInvMassPi0Pt[iCut]);
783                         
784                         hESDEposEnegInvMassPi0Pt[iCut] = new TH2F("ESD_EposEneg_InvMassPi0Pt","ESD_EposEneg_InvMassPi0Pt",1000,0.0,0.5,100,0.,10.);
785                         fQAFolder[iCut]->Add(hESDEposEnegInvMassPi0Pt[iCut]);
786                         
787                         hESDEposEnegLikeSignBackInvMassPt[iCut]  = new TH2F("ESD_EposEneg_LikeSignBack_InvMassPt","ESD_EposEneg_LikeSignBack_InvMassPt",4000,0.0,2.,100,0.,10.);
788                         fQAFolder[iCut]->Add(hESDEposEnegLikeSignBackInvMassPt[iCut]);
789                         
790                         TAxis *AxisAfter = hESDDalitzElectronAfterTPCdEdxVsP[iCut]->GetXaxis(); 
791                         Int_t bins = AxisAfter->GetNbins();
792                         Double_t from = AxisAfter->GetXmin();
793                         Double_t to = AxisAfter->GetXmax();
794                         Double_t *newBins = new Double_t[bins+1];
795                         newBins[0] = from;
796                         Double_t factor = TMath::Power(to/from, 1./bins);
797                         for(Int_t i=1; i<=bins; ++i) newBins[i] = factor * newBins[i-1];
798
799                         AxisAfter->Set(bins, newBins);
800                         AxisAfter = hESDDalitzElectronAfterTPCdEdxSignalVsP[iCut]->GetXaxis(); 
801                         AxisAfter->Set(bins, newBins);
802                         
803                         AxisAfter = hESDDalitzPositronAfterTPCdEdxVsP[iCut]->GetXaxis();
804                         AxisAfter->Set(bins, newBins);
805                         
806                         AxisAfter = hESDDalitzPositronAfterTPCdEdxSignalVsP[iCut]->GetXaxis();
807                         AxisAfter->Set(bins,newBins);
808                         
809                         delete [] newBins;
810                         
811                         fCutFolder[iCut]->Add(fQAFolder[iCut]);
812                 }
813                 
814                 hESDMotherInvMassPt[iCut] = new TH2F("ESD_DalitzMother_InvMass_Pt","ESD_DalitzMother_InvMass_Pt",800,0,0.8,250,0,25);
815                 fESDList[iCut]->Add(hESDMotherInvMassPt[iCut]);
816                                                                                         
817                 
818                 if( fDoChicAnalysis) {
819                         hESDPi0MotherInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_InvMass_Pt","ESD_Pi0Mother_InvMass_Pt",4000,0,4,250,0,25);
820                         fESDList[iCut]->Add(hESDPi0MotherInvMassPt[iCut]);
821                         hESDPi0MotherDiffInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffInvMass_Pt","ESD_Pi0Mother_DiffInvMass_Pt",2000,0,2,250,0,25);
822                         fESDList[iCut]->Add(hESDPi0MotherDiffInvMassPt[iCut]);
823                         hESDPi0MotherDiffLimInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffLimInvMass_Pt","ESD_Pi0Mother_DiffLimInvMass_Pt",2000,0,2,250,0,25);
824                         fESDList[iCut]->Add(hESDPi0MotherDiffLimInvMassPt[iCut]);
825                 }
826
827                 hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_DalitzBackground_InvMass_Pt","ESD_DalitzBackground_InvMass_Pt",800,0,0.8,250,0,25);
828                 fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
829
830                 fCutFolder[iCut]->Add(fESDList[iCut]);          
831         }
832
833
834         InitBack(); // Init Background Handler
835
836
837         if( fIsMC ){
838                 // MC Histogramms
839                 fMCList = new TList*[fnCuts];
840                 // True Histogramms
841                 fTrueList = new TList*[fnCuts];
842                 hESDTrueConvGammaPt = new TH1F*[fnCuts];
843                 hESDTruePositronPt  = new TH1F*[fnCuts];
844                 hESDTrueElectronPt  = new TH1F*[fnCuts];
845                 hESDTrueSecConvGammaPt = new TH1F*[fnCuts];
846                 hESDTrueSecPositronPt  = new TH1F*[fnCuts];
847                 hESDTrueSecElectronPt  = new TH1F*[fnCuts];
848                 hESDTruePi0DalitzConvGammaPt = new TH1F*[fnCuts];
849                 hESDTruePi0DalitzPositronPt  = new TH1F*[fnCuts];
850                 hESDTruePi0DalitzElectronPt  = new TH1F*[fnCuts];
851                 hESDTruePi0DalitzSecConvGammaPt = new TH1F*[fnCuts];
852                 hESDTruePi0DalitzSecPositronPt  = new TH1F*[fnCuts];
853                 hESDTruePi0DalitzSecElectronPt  = new TH1F*[fnCuts];
854                 //if(fDoMesonAnalysis){
855                 hMCAllGammaPt  = new TH1F*[fnCuts];
856                 hMCConvGammaPt = new TH1F*[fnCuts];
857                 hMCConvGammaRSPt = new TH1F*[fnCuts];
858                 hMCAllPositronsPt = new TH1F*[fnCuts];
859                 hMCAllElectronsPt = new TH1F*[fnCuts];
860                 
861                 if( fDoMesonQA ) {
862
863                 hMCConvGammaEta    = new TH1F*[fnCuts];
864                 hMCConvGammaR      = new TH1F*[fnCuts];
865                 hMCAllPositronsEta = new TH1F*[fnCuts];
866                 hMCAllElectronsEta = new TH1F*[fnCuts];
867                 
868                 
869                 }
870                 hMCPi0DalitzGammaPt    = new TH1F*[fnCuts];
871                 hMCPi0DalitzElectronPt = new TH1F*[fnCuts];
872                 hMCPi0DalitzPositronPt = new TH1F*[fnCuts];
873         
874                 hMCPi0Pt = new TH1F*[fnCuts];
875                 hMCPi0GGPt =  new TH1F*[fnCuts];
876                 hMCEtaPt = new TH1F*[fnCuts];
877                 hMCEtaGGPt = new TH1F*[fnCuts];
878                 hMCPi0InAccPt = new TH1F*[fnCuts];
879                 hMCEtaInAccPt = new TH1F*[fnCuts];
880                 hMCChiCPt = new TH1F*[fnCuts];
881                 hMCChiCInAccPt = new TH1F*[fnCuts];
882                                 
883                                 
884                 if ( fDoMesonQA ) {
885                 
886                 hMCPi0EposEnegInvMassPt                      = new TH2F*[fnCuts];       
887                 hMCEtaEposEnegInvMassPt                      = new TH2F*[fnCuts];
888                 hESDEposEnegTruePi0DalitzInvMassPt           = new TH2F*[fnCuts];
889                 hESDEposEnegTruePrimPi0DalitzInvMass         = new TH1F*[fnCuts];
890                 hESDEposEnegTruePi0DalitzPsiPairDPhi         = new TH2F*[fnCuts];
891                 hESDEposEnegTrueEtaDalitzInvMassPt           = new TH2F*[fnCuts];
892                 hESDEposEnegTruePrimEtaDalitzInvMass         = new TH1F*[fnCuts];
893                 hESDEposEnegTrueEtaDalitzPsiPairDPhi         = new TH2F*[fnCuts];
894                 hESDEposEnegTruePhotonInvMassPt              = new TH2F*[fnCuts];
895                 hESDEposEnegTrueInvMassPt                    = new TH2F*[fnCuts];
896                 hESDEposEnegTruePhotonPsiPairDPhi            = new TH2F*[fnCuts];
897                 hESDEposEnegTruePhotonPsiPairDPhiPtCut       = new TH2F*[fnCuts];
898                 hESDEposEnegTrueJPsiInvMassPt                = new TH2F*[fnCuts];
899                 hESDTrueConvGammaR                           = new TH1F*[fnCuts];
900                 }
901                 
902                 
903                 if( fDoChicAnalysis ){
904                 hESDTrueMotherChiCInvMassPt = new TH2F*[fnCuts];
905                 hESDTrueMotherChiCDiffInvMassPt = new TH2F*[fnCuts];
906                 }
907                 
908                 
909                 hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
910                 hESDTrueMotherDalitzInvMassPt = new TH2F*[fnCuts];
911                 hESDTrueMotherPi0GGInvMassPt = new TH2F*[fnCuts];
912                 hESDTruePrimaryMotherPi0GGInvMassPt = new TH2F*[fnCuts];
913                 hESDTrueSecondaryMotherPi0GGInvMassPt = new TH2F*[fnCuts];
914                 hESDTruePrimaryPi0DalitzESDPtMCPt = new TH2F*[fnCuts];
915                 hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
916                 hESDTruePrimaryMotherInvMassPt   = new TH2F*[fnCuts];
917                 hESDTruePrimaryMotherW0WeightingInvMassPt = new TH2F*[fnCuts];
918                 hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
919                 hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
920                 hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
921                 hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
922                 hESDTrueMotherGGInvMassPt = new TH2F*[fnCuts];
923                 //}
924
925                 for(Int_t iCut = 0; iCut<fnCuts;iCut++){
926                         TString cutstringEvent          = ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber();
927                         TString cutstringElectron       = ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
928                         TString cutstringMeson          = ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
929                         TString cutstringGamma          = ((AliConversionPhotonCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
930
931                         fMCList[iCut] = new TList();
932                         fMCList[iCut]->SetName(Form("%s_%s_%s_%s MC histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
933                         fMCList[iCut]->SetOwner(kTRUE);
934                         fCutFolder[iCut]->Add(fMCList[iCut]);
935
936                         hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
937                         fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
938                         
939                         hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
940                         fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
941                         
942                         hMCConvGammaRSPt[iCut] = new TH1F("MC_ConvGamma_RS_Pt","MC_ConvGamma_RS_Pt",250,0,25);
943                         fMCList[iCut]->Add(hMCConvGammaRSPt[iCut]);
944                                                                                 
945                         hMCAllPositronsPt[iCut] = new TH1F("MC_AllPositrons_Pt","MC_AllPositrons_Pt",1000,0,25);
946                         fMCList[iCut]->Add(hMCAllPositronsPt[iCut]);
947                                 
948                         hMCAllElectronsPt[iCut] = new TH1F("MC_AllElectrons_Pt","MC_AllElectrons_Pt",1000,0,25);
949                         fMCList[iCut]->Add(hMCAllElectronsPt[iCut]);
950                         
951                         hMCPi0DalitzGammaPt[iCut] = new TH1F("MC_Pi0DalitzGamma_Pt","MC_Pi0DalitzGamma_Pt",250,0,25);
952                         hMCPi0DalitzGammaPt[iCut]->Sumw2();
953                         fMCList[iCut]->Add(hMCPi0DalitzGammaPt[iCut]);
954                                 
955                         if ( fDoMesonQA ){
956                                 hMCConvGammaEta[iCut] = new TH1F("MC_ConvGamma_Eta","MC_ConvGamma_Eta",600,-1.5,1.5);
957                                 fMCList[iCut]->Add(hMCConvGammaEta[iCut]);
958                                 hMCConvGammaR[iCut] = new TH1F("MC_ConvGamma_R","MC_ConvGamma_R",800,0,200);
959                                 fMCList[iCut]->Add(hMCConvGammaR[iCut]);
960                                 hMCAllPositronsEta[iCut] = new TH1F("MC_AllPositrons_Eta","MC_AllPositrons_Eta",600,-1.5,1.5);
961                                 fMCList[iCut]->Add(hMCAllPositronsEta[iCut]);
962                                 hMCAllElectronsEta[iCut] = new TH1F("MC_AllElectrons_Eta","MC_AllElectrons_Eta",600,-1.5,1.5);
963                                 fMCList[iCut]->Add(hMCAllElectronsEta[iCut]);
964                         }
965                                 
966                         hMCPi0DalitzPositronPt[iCut] = new TH1F("MC_Pi0DalitzPositron_Pt","MC_Pi0DalitzPositron_Pt",1000,0,25);
967                         hMCPi0DalitzPositronPt[iCut]->Sumw2();
968                         fMCList[iCut]->Add(hMCPi0DalitzPositronPt[iCut]);
969                         
970                         hMCPi0DalitzElectronPt[iCut] = new TH1F("MC_Pi0DalitzElectron_Pt","MC_Pi0DalitzElectron_Pt",1000,0,25);
971                         hMCPi0DalitzElectronPt[iCut]->Sumw2();
972                         fMCList[iCut]->Add(hMCPi0DalitzElectronPt[iCut]);
973                         
974                         hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
975                         hMCPi0Pt[iCut]->Sumw2();
976                         fMCList[iCut]->Add(hMCPi0Pt[iCut]);
977                         
978                         hMCPi0GGPt[iCut] = new TH1F("MC_Pi0_GG_Pt","MC_Pi0_GG_Pt",250,0,25);
979                         hMCPi0GGPt[iCut]->Sumw2();
980                         fMCList[iCut]->Add(hMCPi0GGPt[iCut]);
981                         
982                         hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
983                         hMCEtaPt[iCut]->Sumw2();
984                         fMCList[iCut]->Add(hMCEtaPt[iCut]);
985
986                         hMCEtaGGPt[iCut] = new TH1F("MC_Eta_GG_Pt","MC_Eta_GG_Pt",250,0,25);
987                         hMCEtaGGPt[iCut]->Sumw2();
988                         fMCList[iCut]->Add(hMCEtaGGPt[iCut]);
989                         
990                         hMCPi0InAccPt[iCut] = new TH1F("MC_Pi0DalitzInAcc_Pt","MC_Pi0DalitzInAcc_Pt",250,0,25);
991                         hMCPi0InAccPt[iCut]->Sumw2();
992                         fMCList[iCut]->Add(hMCPi0InAccPt[iCut]);
993
994                         hMCEtaInAccPt[iCut] = new TH1F("MC_EtaDalitzInAcc_Pt","MC_EtaDalitzInAcc_Pt",250,0,25);
995                         hMCEtaInAccPt[iCut]->Sumw2();
996                         fMCList[iCut]->Add(hMCEtaInAccPt[iCut]);
997                         
998                         hMCChiCPt[iCut] = new TH1F("MC_ChiC_Pt","MC_ChiC_Pt",250,0,25);
999                         fMCList[iCut]->Add(hMCChiCPt[iCut]);
1000
1001                         hMCChiCInAccPt[iCut] = new TH1F("MC_ChiCInAcc_Pt","MC_ChiCInAcc_Pt",250,0,25);
1002                         fMCList[iCut]->Add(hMCChiCInAccPt[iCut]);
1003                         
1004                         if ( fDoMesonQA ) {
1005                                 hMCPi0EposEnegInvMassPt[iCut] = new TH2F("MC_Pi0EposEneg_InvMassPt","MC_Pi0EposEneg_InvMassPt",1000,0.0,0.5,100,0.,10.);
1006                                 fMCList[iCut]->Add(hMCPi0EposEnegInvMassPt[iCut]);
1007                                 hMCEtaEposEnegInvMassPt[iCut] = new TH2F("MC_EtaEposEneg_InvMassPt","MC_EtaEposEneg_InvMassPt",1400,0.,0.7,100,0.,10.);
1008                                 fMCList[iCut]->Add(hMCEtaEposEnegInvMassPt[iCut]);      
1009                         }
1010                                 
1011                         fTrueList[iCut] = new TList();
1012                         fTrueList[iCut]->SetName(Form("%s_%s_%s_%s True histograms",cutstringEvent.Data(),cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
1013                         fTrueList[iCut]->SetOwner(kTRUE);
1014                         fCutFolder[iCut]->Add(fTrueList[iCut]);
1015
1016                         if ( fDoMesonQA ) {
1017                                 hESDEposEnegTruePi0DalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_InvMassPt","ESD_EposEneg_TruePi0Dalitz_InvMassPt",1000,0.0,0.5,100,0.,10.);
1018                                 fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzInvMassPt[iCut]);
1019                                 
1020                                 hESDEposEnegTruePrimPi0DalitzInvMass[iCut] = new TH1F("ESD_EposEneg_TruePrimPi0Dalitz_InvMass","ESD_EposEneg_TruePrimPi0Dalitz_InvMass",500,0.,0.5);
1021                                 fTrueList[iCut]->Add(hESDEposEnegTruePrimPi0DalitzInvMass[iCut]);
1022
1023                                 hESDEposEnegTruePi0DalitzPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_PsiPair_DPhi","ESD_EposEneg_TruePi0Dalitz_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1024                                 fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzPsiPairDPhi[iCut]);
1025                         
1026                                 hESDEposEnegTrueEtaDalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_InvMassPt","ESD_EposEneg_TrueEtaDalitz_InvMassPt",700,0.,0.7,100,0.,10.);
1027                                 fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzInvMassPt[iCut]);
1028                                 
1029                                 hESDEposEnegTruePrimEtaDalitzInvMass[iCut] = new TH1F("ESD_EposEneg_TruePrimEtaDalitz_InvMass","ESD_EposEneg_TruePrimEtaDalitz_InvMass",700,0.,0.7);
1030                                 fTrueList[iCut]->Add(hESDEposEnegTruePrimEtaDalitzInvMass[iCut]);
1031
1032                                 hESDEposEnegTrueEtaDalitzPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_PsiPair_DPhi","ESD_EposEneg_TrueEtaDalitz_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1033                                 fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzPsiPairDPhi[iCut]);
1034                         
1035                                 hESDEposEnegTruePhotonInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePhoton_InvMassPt","ESD_EposEneg_TruePhoton_InvMassPt",500,0.,0.5,100,0.,10.);
1036                                 fTrueList[iCut]->Add(hESDEposEnegTruePhotonInvMassPt[iCut]);
1037                                 
1038                                 hESDEposEnegTrueInvMassPt[iCut] = new TH2F("ESD_EposEneg_True_InvMassPt","ESD_EposEneg_True_InvMassPt",5000,0.,5.,100,0.,10.);
1039                                 fTrueList[iCut]->Add(hESDEposEnegTrueInvMassPt[iCut]);
1040                                 
1041                                 hESDEposEnegTruePhotonPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TruePhoton_PsiPair_DPhi","ESD_EposEneg_TruePhoton_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1042                                 fTrueList[iCut]->Add(hESDEposEnegTruePhotonPsiPairDPhi[iCut]);
1043                         
1044                                 hESDEposEnegTruePhotonPsiPairDPhiPtCut[iCut] = new TH2F("ESD_EposEneg_TruePhoton_PsiPair_DPhi_PtCut","ESD_EposEneg_TruePhoton_PsiPair_DPhi_PtCut", 100, -1.0,1.0,100,-1.0,1.0 );
1045                                 fTrueList[iCut]->Add(hESDEposEnegTruePhotonPsiPairDPhiPtCut[iCut]);
1046                         
1047                                 hESDEposEnegTrueJPsiInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueJPsi_InvMassPt","ESD_EposEneg_TrueJPsi_InvMassPt",5000,0.,5.,100,0.,10.);
1048                                 fTrueList[iCut]->Add(hESDEposEnegTrueJPsiInvMassPt[iCut]);
1049                                 
1050                                 hESDTrueConvGammaR[iCut] = new TH1F("ESD_TrueConvGamma_R","ESD_TrueConvGamma_R",800,0,200);
1051                                 fTrueList[iCut]->Add(hESDTrueConvGammaR[iCut]);
1052                         }
1053
1054                         hESDTruePositronPt[iCut] = new TH1F("ESD_TruePositron_Pt","ESD_TruePositron_Pt",1000,0,25);
1055                         fTrueList[iCut]->Add(hESDTruePositronPt[iCut]);
1056
1057                         hESDTrueElectronPt[iCut] = new TH1F("ESD_TrueElectron_Pt","ESD_TrueElectron_Pt",1000,0,25);
1058                         fTrueList[iCut]->Add(hESDTrueElectronPt[iCut]);
1059                 
1060                         hESDTrueSecPositronPt[iCut] = new TH1F("ESD_TrueSecPositron_Pt","ESD_TrueSecPositron_Pt",1000,0,25);
1061                         fTrueList[iCut]->Add(hESDTrueSecPositronPt[iCut]);
1062
1063                         hESDTrueSecElectronPt[iCut] = new TH1F("ESD_TrueSecElectron_Pt","ESD_TrueSecElectron_Pt",1000,0,25);
1064                         fTrueList[iCut]->Add(hESDTrueSecElectronPt[iCut]); 
1065
1066                         hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
1067                         fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
1068                 
1069                         hESDTrueSecConvGammaPt[iCut] = new TH1F("ESD_TrueSecConvGamma_Pt","ESD_TrueSecConvGamma_Pt",250,0,25);
1070                         fTrueList[iCut]->Add(hESDTrueSecConvGammaPt[iCut]);
1071
1072                         hESDTruePi0DalitzConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzConvGamma_Pt","ESD_TruePi0DalitzConvGamma_Pt",250,0,25);
1073                         fTrueList[iCut]->Add(hESDTruePi0DalitzConvGammaPt[iCut]);
1074
1075                         hESDTruePi0DalitzElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzElectron_Pt","ESD_TruePi0DalitzElectron_Pt",1000,0,25);
1076                         fTrueList[iCut]->Add(hESDTruePi0DalitzElectronPt[iCut]);
1077
1078                         hESDTruePi0DalitzPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzPositron_Pt","ESD_TruePi0DalitzPositron_Pt",1000,0,25);
1079                         fTrueList[iCut]->Add(hESDTruePi0DalitzPositronPt[iCut]);
1080                 
1081                         hESDTruePi0DalitzSecConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzSecConvGamma_Pt","ESD_TruePi0DalitzSecConvGamma_Pt",250,0,25);
1082                         fTrueList[iCut]->Add(hESDTruePi0DalitzSecConvGammaPt[iCut]);
1083                 
1084                         hESDTruePi0DalitzSecElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecElectron_Pt","ESD_TruePi0DalitzSecElectron_Pt",1000,0,25);
1085                         fTrueList[iCut]->Add(hESDTruePi0DalitzSecElectronPt[iCut]);
1086
1087                         hESDTruePi0DalitzSecPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecPositron_Pt","ESD_TruePi0DalitzSecPositron_Pt",1000,0,25);
1088                         fTrueList[iCut]->Add(hESDTruePi0DalitzSecPositronPt[iCut]);
1089
1090                         if( fDoChicAnalysis) { 
1091                                 hESDTrueMotherChiCInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiC_InvMass_Pt","ESD_TrueMotherChiC_InvMass_Pt",4000,0,4,250,0,25);
1092                                 fTrueList[iCut]->Add(hESDTrueMotherChiCInvMassPt[iCut]);
1093                                 hESDTrueMotherChiCDiffInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiCDiff_InvMass_Pt","ESD_TrueMotherChiCDiff_InvMass_Pt",2000,0,2,250,0,25);
1094                                 fTrueList[iCut]->Add(hESDTrueMotherChiCDiffInvMassPt[iCut]);
1095                         }
1096
1097                         hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",800,0,0.8,250,0,25);
1098                         hESDTrueMotherInvMassPt[iCut]->Sumw2();
1099                         fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
1100                 
1101                         hESDTrueMotherDalitzInvMassPt[iCut] = new TH2F("ESD_TrueMother_Dalitz_InvMass_Pt","ESD_TrueMother_Dalitz_InvMass_Pt",800,0,0.8,250,0,25);
1102                         hESDTrueMotherDalitzInvMassPt[iCut]->Sumw2();
1103                         fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPt[iCut]);
1104                 
1105                 
1106                 
1107                 
1108
1109                         hESDTrueMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TrueMotherPi0GG_InvMass_Pt","ESD_TrueMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1110                         hESDTrueMotherPi0GGInvMassPt[iCut]->Sumw2();
1111                         fTrueList[iCut]->Add(hESDTrueMotherPi0GGInvMassPt[iCut]);
1112
1113                         hESDTruePrimaryMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMotherPi0GG_InvMass_Pt","ESD_TruePrimaryMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1114                         hESDTruePrimaryMotherPi0GGInvMassPt[iCut]->Sumw2();
1115                         fTrueList[iCut]->Add(hESDTruePrimaryMotherPi0GGInvMassPt[iCut]);
1116
1117                         hESDTrueSecondaryMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryMotherPi0GG_InvMass_Pt","ESD_TrueSecondaryMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1118                         hESDTrueSecondaryMotherPi0GGInvMassPt[iCut]->Sumw2();
1119                         fTrueList[iCut]->Add(hESDTrueSecondaryMotherPi0GGInvMassPt[iCut]);
1120
1121                         hESDTruePrimaryPi0DalitzESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt","ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt",250,0,25,250,0,25);
1122                         hESDTruePrimaryPi0DalitzESDPtMCPt[iCut]->Sumw2();
1123                         fTrueList[iCut]->Add(hESDTruePrimaryPi0DalitzESDPtMCPt[iCut]);
1124                         hESDTruePrimaryMotherInvMassMCPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt","ESD_TrueDalitzPrimaryMother_InvMass_MCPt",800,0,0.8,250,0,25);
1125                         hESDTruePrimaryMotherInvMassMCPt[iCut]->Sumw2();
1126                         fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
1127                         hESDTruePrimaryMotherInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_Pt","ESD_TruePrimaryMother_InvMass_Pt",800,0,0.8,250,0,25);
1128                         hESDTruePrimaryMotherInvMassPt[iCut]->Sumw2();
1129                         fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassPt[iCut]);
1130                         hESDTruePrimaryMotherW0WeightingInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMotherW0Weighting_InvMass_Pt","ESD_TruePrimaryMotherW0Weighting_InvMass_Pt",800,0,0.8,250,0,25);
1131                         hESDTruePrimaryMotherW0WeightingInvMassPt[iCut]->Sumw2();
1132                         fTrueList[iCut]->Add(hESDTruePrimaryMotherW0WeightingInvMassPt[iCut]); 
1133
1134                         hESDTrueSecondaryMotherInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMother_InvMass_Pt","ESD_TrueDalitzSecondaryMother_InvMass_Pt",800,0,0.8,250,0,25);
1135                         hESDTrueSecondaryMotherInvMassPt[iCut]->Sumw2();
1136                         fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
1137                         //                              hESDTrueSecondaryMotherFromK0sInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt",1000,0,1,250,0,25);
1138                         //                              fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
1139                         hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckGG_InvMass_Pt","ESD_TrueDalitzBckGG_InvMass_Pt",800,0,0.8,250,0,25);
1140                         fTrueList[iCut]->Add(hESDTrueBckGGInvMassPt[iCut]);
1141                         hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckCont_InvMass_Pt","ESD_TrueDalitzBckCont_InvMass_Pt",800,0,0.8,250,0,25);
1142                         fTrueList[iCut]->Add(hESDTrueBckContInvMassPt[iCut]);
1143                 //                              hESDTrueMotherGGInvMassPt[iCut] = new TH2F("ESD_TrueGammaGamma_InvMass_Pt","ESD_TrueGammaGamma_InvMass_Pt",1000,0,1,250,0,25);
1144                 //                              fTrueList[iCut]->Add(hESDTrueMotherGGInvMassPt[iCut]);
1145
1146                 }
1147         }
1148
1149         fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
1150         if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
1151         
1152         if(fV0Reader)
1153                 if((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())
1154                         if(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms())
1155                                 fOutputContainer->Add(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
1156         
1157         
1158         
1159         fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
1160         if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
1161                 
1162         if( fElecSelector ){
1163                 if ( ((AliDalitzElectronCuts*)fElecSelector->GetDalitzElectronCuts())->GetCutHistograms() ){
1164                                 fOutputContainer->Add( ((AliDalitzElectronCuts*)fElecSelector->GetDalitzElectronCuts())->GetCutHistograms() );
1165                 }
1166         }  
1167
1168         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1169
1170                 if( fCutElectronArray ){
1171                         if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() ) {
1172                                 fCutFolder[iCut]->Add( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() );
1173                         }
1174                 }
1175
1176                 if( fCutMesonArray  ) {
1177                         if( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms() ) {
1178                                 fCutFolder[iCut]->Add( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms());
1179                         }
1180                 }
1181
1182                 if( fCutGammaArray ) {
1183                         if( ((AliConversionPhotonCuts*)fCutGammaArray->At(iCut))->GetCutHistograms() ) {
1184                                 fCutFolder[iCut]->Add( ((AliConversionPhotonCuts*)fCutGammaArray->At(iCut))->GetCutHistograms()  );
1185                         }
1186                 }
1187                 
1188                 if( fCutEventArray )
1189                 if( ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutHistograms()){
1190                         fCutFolder[iCut]->Add(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutHistograms());
1191                 }
1192         }
1193
1194         PostData(1, fOutputContainer);
1195
1196 }
1197
1198 //______________________________________________________________________
1199 void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
1200 {
1201
1202         //
1203         // Execute analysis for current event
1204         //
1205
1206         fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
1207         if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
1208
1209
1210         Int_t eventQuality = ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEventQuality();
1211
1212         if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
1213                         for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1214                 hNEvents[iCut]->Fill(eventQuality);
1215                         }
1216                 return;
1217         }
1218
1219         fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
1220         if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
1221
1222
1223         if(fIsMC)             fMCEvent        =  MCEvent();
1224         fESDEvent        = (AliESDEvent*)InputEvent();
1225         fReaderGammas    = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
1226         fSelectorElectronIndex = fElecSelector->GetReconstructedElectronsIndex(); // Electrons from default Cut
1227         fSelectorPositronIndex = fElecSelector->GetReconstructedPositronsIndex(); // Positrons from default Cut
1228
1229         CountESDTracks(); // Estimate Event Multiplicity
1230         fNumberOfESDTracks = fV0Reader->GetNumberOfPrimaryTracks();
1231         //AddTaskContainers(); //Add conatiner
1232
1233         for(Int_t iCut = 0; iCut<fnCuts; iCut++){               
1234                 fiCut = iCut;
1235                 fNVirtualGammas = 0;
1236
1237                 Int_t eventNotAccepted =
1238                         ((AliConvEventCuts*)fCutEventArray->At(iCut))
1239                         ->IsEventAcceptedByCut(fV0Reader->GetEventCuts(),fInputEvent,fMCEvent,fIsHeavyIon,kFALSE);
1240                 
1241                 
1242                 //Int_t eventNotAccepted = ((AliConvEventCuts*)fCutGammaArray->At(iCut))->IsEventAcceptedByCut(fV0Reader->GetEventCuts(),fInputEvent,fMCEvent,fIsHeavyIon,kFALSE);
1243                 
1244                 if(eventNotAccepted){
1245                         //                      cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
1246                         hNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
1247                         continue;
1248                 }
1249
1250                 if(eventQuality != 0){// Event Not Accepted
1251                         //                      cout << "event rejected due to: " <<eventQuality << endl;
1252                         hNEvents[iCut]->Fill(eventQuality);
1253                         continue;
1254                 }
1255
1256                 hNEvents[iCut]->Fill(eventQuality);
1257                 hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
1258                 
1259                 if(((AliConvEventCuts*)fCutEventArray->At(iCut))->IsHeavyIon() == 2) hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A());
1260                 else hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
1261
1262                 if(fMCEvent){ // Process MC Particle
1263                         fMCStack = fMCEvent->Stack();
1264                         if(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetSignalRejection() != 0){
1265                                         ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetNotRejectedParticles( ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetSignalRejection(),
1266                                                                                                                                                                                         ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetAcceptedHeader(),
1267                                                                                                                                                                                         fMCEvent);
1268                         } 
1269                         ProcessMCParticles();
1270                 }
1271
1272                 ProcessPhotonCandidates(); // Process this cuts gammas
1273                 ProcessElectronCandidates(); // Process this cuts gammas
1274                 
1275                 if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1276                 
1277                         fUnsmearedPx = new Double_t[fGoodGammas->GetEntries()]; // Store unsmeared Momenta
1278                         fUnsmearedPy = new Double_t[fGoodGammas->GetEntries()];
1279                         fUnsmearedPz = new Double_t[fGoodGammas->GetEntries()];
1280                         fUnsmearedE =  new Double_t[fGoodGammas->GetEntries()];
1281
1282                         for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
1283                                 fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Px();
1284                                 fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Py();
1285                                 fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Pz();
1286                                 fUnsmearedE[gamma] =  ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->E();
1287                                 ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(gamma)));
1288                         }           
1289                 }
1290                 
1291                 if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetUseVPhotonMCPmearing() && ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1292                         // cout<<"Entro virtual photon smearing"<<endl;
1293                         fUnsmearedVPx = new Double_t[fGoodVirtualGammas->GetEntries()]; // Store unsmeared Momenta
1294                         fUnsmearedVPy = new Double_t[fGoodVirtualGammas->GetEntries()];
1295                         fUnsmearedVPz = new Double_t[fGoodVirtualGammas->GetEntries()];
1296                         fUnsmearedVE =  new Double_t[fGoodVirtualGammas->GetEntries()];
1297
1298                         for(Int_t Vgamma=0;Vgamma<fGoodVirtualGammas->GetEntries();Vgamma++){ // Smear the AODPhotons in MC
1299                                 fUnsmearedVPx[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Px();
1300                                 fUnsmearedVPy[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Py();
1301                                 fUnsmearedVPz[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Pz();
1302                                 fUnsmearedVE[Vgamma] =  ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->E();
1303                                 ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->SmearVirtualPhoton(dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(Vgamma)));
1304                         }           
1305                 }
1306                 
1307                 ProcessVirtualGammasCandidates();
1308                 CalculatePi0DalitzCandidates();
1309                 CalculateBackground();
1310                 UpdateEventByEventData();
1311                 
1312                 if ( fDoMesonQA ) {
1313                         hNGoodESDTracksVsNGoodGammas[iCut]->Fill(fNumberOfESDTrackskBoth,fGoodGammas->GetEntries());
1314                         hNGoodESDTracksVsNGoodVGammas[iCut]->Fill(fNumberOfESDTrackskBoth,fNVirtualGammas);             
1315                 }
1316                 
1317                 
1318                 if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1319                 
1320                         for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
1321                                 ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
1322                                 ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPy(fUnsmearedPy[gamma]);
1323                                 ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPz(fUnsmearedPz[gamma]);
1324                                 ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetE(fUnsmearedE[gamma]);
1325                         }
1326                         delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
1327                         delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
1328                         delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
1329                         delete[] fUnsmearedE;  fUnsmearedE  = 0x0;
1330                 }
1331                 
1332                 if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetUseVPhotonMCPmearing() && ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1333                 
1334                         for(Int_t Vgamma=0;Vgamma<fGoodVirtualGammas->GetEntries();Vgamma++){ // Smear the AODPhotons in MC
1335                                 ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPx(fUnsmearedVPx[Vgamma]); // Reset Unsmeared Momenta
1336                                 ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPy(fUnsmearedVPy[Vgamma]);
1337                                 ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPz(fUnsmearedVPz[Vgamma]);
1338                                 ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetE(fUnsmearedVE[Vgamma]);
1339                         } 
1340                         delete[] fUnsmearedVPx; fUnsmearedVPx = 0x0;
1341                         delete[] fUnsmearedVPy; fUnsmearedVPy = 0x0;
1342                         delete[] fUnsmearedVPz; fUnsmearedVPz = 0x0;
1343                         delete[] fUnsmearedVE;  fUnsmearedVE  = 0x0;
1344                 }
1345                 fGoodGammas->Clear(); // delete this cuts good gammas
1346                 fGoodVirtualGammas->Clear(); // delete this cuts good gammas
1347         }
1348
1349         fSelectorElectronIndex.clear();
1350         fSelectorPositronIndex.clear();
1351
1352         PostData( 1, fOutputContainer );
1353 }
1354
1355 Bool_t AliAnalysisTaskGammaConvDalitzV1::Notify()
1356 {
1357         for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1358           
1359                 if( !((AliConvEventCuts*)fCutEventArray->At(iCut))->GetDoEtaShift() ){
1360
1361                         hEtaShift[iCut]->Fill(0.,0.);
1362                         continue; // No Eta Shift requested, continue
1363                 }
1364                 
1365                 
1366                 if( ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
1367                         ((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
1368                         ((AliConvEventCuts*)fCutEventArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
1369                          hEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetEtaShift()));
1370                         continue;
1371                 } else {
1372                         printf(" Gamma Conversion Dalitz Task %s :: Eta Shift Manually Set to %f \n\n",
1373                         (((AliConvEventCuts*)fCutEventArray->At(iCut))->GetCutNumber()).Data(),((AliConvEventCuts*)fCutEventArray->At(iCut))->GetEtaShift());
1374                         ((AliConvEventCuts*)fCutEventArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
1375                         hEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fCutEventArray->At(iCut))->GetEtaShift()));
1376                 }
1377         }
1378         
1379         return kTRUE;
1380 }
1381
1382 //________________________________________________________________________
1383 void AliAnalysisTaskGammaConvDalitzV1::Terminate(const Option_t *)
1384 {
1385         ///Grid
1386 }
1387
1388 //________________________________________________________________________
1389 void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
1390 {
1391         Int_t nV0 = 0;
1392         TList *GoodGammasStepOne = new TList();
1393         TList *GoodGammasStepTwo = new TList();
1394         // Loop over Photon Candidates allocated by ReaderV1
1395         
1396         for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
1397                 AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
1398                 if(!PhotonCandidate) continue;
1399                 fIsFromMBHeader = kTRUE;
1400                 if( fMCEvent && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0 ){
1401                         Int_t isPosFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
1402                         if(isPosFromMBHeader == 0 && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 3) continue;
1403                         Int_t isNegFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1404                         if(isNegFromMBHeader == 0 && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 3) continue;
1405                         if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1406                 }
1407                 
1408                 if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
1409
1410                 if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
1411                         !((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // if no post reader loop is required add to events good gammas
1412                         
1413                         fGoodGammas->Add(PhotonCandidate);
1414                         if(fIsFromMBHeader){
1415                                 hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
1416                                 hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1417                                 if( fDoMesonQA ) hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1418                         }
1419                         if(fMCEvent){
1420                                 ProcessTruePhotonCandidates(PhotonCandidate);
1421                         }
1422                 } else if(((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
1423                         ((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
1424                         nV0++;
1425                         GoodGammasStepOne->Add(PhotonCandidate);
1426                 } else if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
1427                                 ((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
1428                         GoodGammasStepTwo->Add(PhotonCandidate);
1429                 }
1430         }
1431         
1432         
1433         if(((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){
1434                 for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
1435                         AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
1436                         if(!PhotonCandidate) continue;  
1437                         fIsFromMBHeader = kTRUE;
1438                         if(fMCEvent && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0){
1439                                 Int_t isPosFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
1440                                 Int_t isNegFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1441                                 if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1442                         }
1443                         
1444                         if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GoodGammasStepOne->GetEntries())) continue;
1445                         if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed
1446                                 fGoodGammas->Add(PhotonCandidate);
1447                         
1448                                 if(fIsFromMBHeader){
1449                                         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
1450                                         hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1451                                         if( fDoMesonQA )hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1452                                 }
1453                         
1454                                 if(fMCEvent){
1455                                         ProcessTruePhotonCandidates(PhotonCandidate);
1456                                 }
1457                         } else GoodGammasStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
1458                 }
1459         }
1460         if(((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){
1461                 for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
1462                         AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
1463                         if(!PhotonCandidate) continue;
1464                         if(fMCEvent && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0){
1465                                 Int_t isPosFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
1466                                 Int_t isNegFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1467                                 if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1468                         }
1469                         if(!((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GoodGammasStepTwo,i)) continue;
1470                         fGoodGammas->Add(PhotonCandidate); // Add gamma to current cut TList
1471                 
1472                         if(fIsFromMBHeader){
1473                                 hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
1474                                 hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1475                                 if(fDoMesonQA)hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1476                         }
1477                 
1478                         if(fMCEvent){
1479                                 ProcessTruePhotonCandidates(PhotonCandidate);
1480                         }
1481                 }
1482         }
1483
1484         delete GoodGammasStepOne;
1485         GoodGammasStepOne = 0x0;
1486         delete GoodGammasStepTwo;
1487         GoodGammasStepTwo = 0x0;
1488 }
1489
1490 //________________________________________________________________________
1491 void AliAnalysisTaskGammaConvDalitzV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
1492 {
1493         // Process True Photons
1494         AliStack *MCStack = fMCEvent->Stack();
1495         TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
1496         TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
1497
1498         if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
1499         if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){  // Not Same Mother == Combinatorial Bck
1500                 return;
1501         } else if (posDaughter->GetMother(0) == -1){
1502                 return;
1503         }
1504         
1505         if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
1506         if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
1507         if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
1508
1509         TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
1510         if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
1511
1512         // True Photon
1513         
1514         Int_t labelGamma = TruePhotonCandidate->GetMCParticleLabel(MCStack);
1515         
1516         if( labelGamma < MCStack->GetNprimary() ){
1517                 if( fIsFromMBHeader ){
1518                         hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1519                         if(fDoMesonQA) hESDTrueConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
1520                 }
1521         } else {
1522                 if( fIsFromMBHeader){
1523                         hESDTrueSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1524                 }
1525         }
1526         
1527         if( IsPi0DalitzDaughter(labelGamma) == kTRUE ) {
1528                 if( labelGamma < MCStack->GetNprimary() ) {
1529                         if( fIsFromMBHeader ){
1530                                 hESDTruePi0DalitzConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1531                         }
1532                 } else {
1533                         if( fIsFromMBHeader ) {
1534                                 hESDTruePi0DalitzSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1535                         }
1536                 }
1537         }
1538    
1539  
1540 }
1541 //________________________________________________________________________
1542 void AliAnalysisTaskGammaConvDalitzV1::ProcessVirtualGammasCandidates(){
1543         
1544         Double_t magField = fInputEvent->GetMagneticField();
1545
1546
1547         if( magField  < 0.0 ){
1548                 magField =  1.0;
1549         }
1550         else {
1551                 magField =  -1.0;
1552         }
1553         
1554         AliStack *MCStack = 0x0;
1555         
1556         if( fMCEvent ){
1557                 MCStack = fMCEvent->Stack();
1558         }
1559         
1560         
1561         for(Int_t virtualGammaIndex=0; virtualGammaIndex < fGoodVirtualGammas->GetEntries();  virtualGammaIndex++ ){
1562                 AliAODConversionPhoton *Vgamma=dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(virtualGammaIndex));
1563                 
1564                 AliESDtrack* positronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelPositive() );
1565                 AliESDtrack* electronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelNegative() );
1566                 
1567                 Bool_t isPhoton         = kFALSE;
1568                 Bool_t isPi0Dalitz      = kFALSE;
1569                 Bool_t isEtaDalitz      = kFALSE;
1570                 Bool_t isJPsi           = kFALSE;
1571                 Bool_t isTrueEposENeg   = kFALSE;
1572                 Bool_t isMotherPrimary  = kFALSE;
1573
1574                 Double_t psiPair = GetPsiPair(positronVgamma,electronVgamma);
1575                 Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronVgamma->GetConstrainedParam()->Phi()-positronVgamma->GetConstrainedParam()->Phi());
1576                 
1577                 if ( fDoMesonQA ) {
1578                 
1579                         hESDEposEnegPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);   
1580                         hESDEposEnegInvMassPt[fiCut]->Fill(Vgamma->M(),Vgamma->Pt());
1581                         
1582                         //cout<<"GetMass() "<<Vgamma->GetMass()<<" M "<<Vgamma->M()<<endl;
1583                         if( fMCEvent ) {
1584
1585                                 Int_t virtualGammaMCLabel = Vgamma->GetMCParticleLabel(MCStack);
1586                                 
1587                                 TParticle * negativeMC = 0x0; 
1588                                 TParticle * positiveMC = 0x0;   
1589                                 TParticle * mcVgamma   = 0x0;
1590                                 
1591                                 if( virtualGammaMCLabel != -1 ){
1592                                         mcVgamma = (TParticle*)MCStack->Particle(virtualGammaMCLabel);
1593                                 }
1594                                 
1595                                 negativeMC = (TParticle*)Vgamma->GetNegativeMCDaughter(MCStack);
1596                                 positiveMC = (TParticle*)Vgamma->GetPositiveMCDaughter(MCStack);
1597                                 
1598                                                 
1599                                 if( negativeMC && positiveMC ) {
1600                                         if( positiveMC->GetPdgCode() == ::kPositron && negativeMC->GetPdgCode() == ::kElectron ) 
1601                                                 isTrueEposENeg = kTRUE;
1602                                         if( positiveMC->GetMother(0) > -1 && positiveMC->GetMother(0) < fMCStack->GetNprimary() )
1603                                                 isMotherPrimary = kTRUE;
1604                                 }
1605                                 if(mcVgamma){
1606                                         // Check if it is a true photon
1607                                         if(mcVgamma->GetPdgCode() == 22){
1608                                                 isPhoton = kTRUE;
1609                                         } else if(mcVgamma->GetPdgCode() == 443){
1610                                                 isJPsi = kTRUE;
1611                                         } else if( IsDalitz( mcVgamma ) ){
1612                                                 if     ( mcVgamma->GetPdgCode() == 111 ) isPi0Dalitz = kTRUE;
1613                                                 else if( mcVgamma->GetPdgCode() == 221 ) isEtaDalitz = kTRUE;
1614                                         }
1615                                 }
1616
1617                                 if(isPhoton){
1618                                         hESDEposEnegTruePhotonInvMassPt[fiCut]->Fill(Vgamma->M(),Vgamma->Pt());
1619                                         hESDEposEnegTruePhotonPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1620                                         if( Vgamma->Pt() > 1.5 ){
1621                                                 hESDEposEnegTruePhotonPsiPairDPhiPtCut[fiCut]->Fill(deltaPhi,psiPair);
1622                                         }
1623                                 } else if(isJPsi){
1624                                         hESDEposEnegTrueJPsiInvMassPt[fiCut]->Fill(Vgamma->M(),Vgamma->Pt());
1625                                 } else if(isPi0Dalitz){
1626                                         hESDEposEnegTruePi0DalitzInvMassPt[fiCut]->Fill(Vgamma->M(),Vgamma->Pt());
1627                                         hESDEposEnegTruePi0DalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1628                                         if( isMotherPrimary ) hESDEposEnegTruePrimPi0DalitzInvMass[fiCut]->Fill( Vgamma->M() );
1629                                 } else if(isEtaDalitz){
1630                                         hESDEposEnegTrueEtaDalitzInvMassPt[fiCut]->Fill(Vgamma->M(),Vgamma->Pt());
1631                                         hESDEposEnegTrueEtaDalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1632                                         if( isMotherPrimary ) hESDEposEnegTruePrimEtaDalitzInvMass[fiCut]->Fill( Vgamma->M() );
1633                                 }
1634                                         
1635                                 if( isTrueEposENeg ) hESDEposEnegTrueInvMassPt[fiCut]->Fill(Vgamma->M(), Vgamma->Pt());     
1636                                 
1637                         }
1638                 }
1639         }
1640 }  
1641   
1642 //________________________________________________________________________
1643 void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
1644
1645         Double_t magField = fInputEvent->GetMagneticField();
1646
1647         if( magField  < 0.0 ){
1648                 magField =  1.0;
1649         } else {
1650                 magField =  -1.0;
1651         }
1652
1653         vector<Int_t> lGoodElectronIndexPrev(0);
1654         vector<Int_t> lGoodPositronIndexPrev(0);
1655         
1656         for(UInt_t i = 0; i < fSelectorElectronIndex.size(); i++){
1657                 
1658                 AliESDtrack* electronCandidate = fESDEvent->GetTrack(fSelectorElectronIndex[i]);
1659                 
1660                 if( fMCEvent ) {
1661                         Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
1662                         Int_t isMCFromMBHeader = -1;
1663                         if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0) {
1664                                 isMCFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(labelelectron,fMCStack,fInputEvent);
1665                                 if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 3) continue;
1666                         }    
1667                 }
1668                         
1669                 if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(electronCandidate) ) continue;
1670                 
1671                 lGoodElectronIndexPrev.push_back(   fSelectorElectronIndex[i] );
1672                 hESDDalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
1673                 hESDDalitzElectronPhi[fiCut]->Fill(electronCandidate->Phi());
1674                 
1675                 
1676                 if( fMCEvent ) {
1677                         
1678                         Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
1679                         if( labelelectron < fMCStack->GetNtrack() ){
1680                                 TParticle* electron = fMCStack->Particle(labelelectron);
1681                                 if( electron->GetPdgCode() ==  11 ){
1682                                         if( labelelectron < fMCStack->GetNprimary() ){
1683                                                 hESDTrueElectronPt[fiCut]->Fill(electronCandidate->Pt());    //primary electron
1684                                         } else {
1685                                                 hESDTrueSecElectronPt[fiCut]->Fill(electronCandidate->Pt()); //secondary electron
1686                                         }
1687                                         if( IsPi0DalitzDaughter(labelelectron) == kTRUE ) {
1688                                                 if( labelelectron < fMCStack->GetNprimary() ) {
1689                                                         hESDTruePi0DalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
1690                                                 } else {
1691                                                         hESDTruePi0DalitzSecElectronPt[fiCut]->Fill(electronCandidate->Pt());
1692                                                 }
1693                                         }
1694                                 }
1695                         }
1696                 }
1697         }
1698
1699         for(UInt_t i = 0; i < fSelectorPositronIndex.size(); i++){
1700
1701                 AliESDtrack* positronCandidate = fESDEvent->GetTrack( fSelectorPositronIndex[i] );
1702                 
1703                 if( fMCEvent ) {
1704                 
1705                         Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
1706                         Int_t isMCFromMBHeader = -1;
1707                         
1708                         if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0) {
1709                                 isMCFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(labelpositron,fMCStack,fInputEvent);
1710                                 if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 3) continue;
1711                         }  
1712                 }
1713         
1714                 if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(positronCandidate) ) continue;
1715                 
1716                 lGoodPositronIndexPrev.push_back( fSelectorPositronIndex[i] );
1717                 hESDDalitzPositronPt[fiCut]->Fill( positronCandidate->Pt() );
1718                 hESDDalitzPositronPhi[fiCut]->Fill( positronCandidate->Phi() );
1719                         
1720                 if( fMCEvent ) {
1721                         Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
1722                         
1723                         if( labelpositron < fMCStack->GetNtrack() ) {
1724                                 TParticle* positron = fMCStack->Particle(labelpositron);
1725                                 if( positron->GetPdgCode() ==  -11 ){
1726                                         if( labelpositron < fMCStack->GetNprimary() ){
1727                                                 hESDTruePositronPt[fiCut]->Fill(positronCandidate->Pt());
1728                                         } else {
1729                                                 hESDTrueSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
1730                                         }
1731                                         if( IsPi0DalitzDaughter(labelpositron) == kTRUE ) {
1732                                                 if( labelpositron < fMCStack->GetNprimary() ){
1733                                                         hESDTruePi0DalitzPositronPt[fiCut]->Fill(positronCandidate->Pt());
1734                                                 } else {
1735                                                         hESDTruePi0DalitzSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
1736                                                 }
1737                                         }
1738                                 }
1739                         }
1740                 }
1741         }
1742
1743         vector<Bool_t> lElectronPsiIndex(lGoodElectronIndexPrev.size(), kTRUE);
1744         vector<Bool_t> lPositronPsiIndex(lGoodPositronIndexPrev.size(), kTRUE);
1745
1746         if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->DoPsiPairCut() == kTRUE ){
1747                 for( UInt_t i = 0; i < lGoodElectronIndexPrev.size(); i++ ) {
1748                         AliESDtrack *electronCandidate = fESDEvent->GetTrack(lGoodElectronIndexPrev[i]);
1749                         for(UInt_t j = 0; j <  lGoodPositronIndexPrev.size(); j++){
1750                                 AliESDtrack *positronCandidate = fESDEvent->GetTrack(lGoodPositronIndexPrev[j]);
1751                                 Double_t psiPair = GetPsiPair(positronCandidate,electronCandidate);
1752                                 Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->GetConstrainedParam()->Phi()-positronCandidate->GetConstrainedParam()->Phi());
1753
1754                                 if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->IsFromGammaConversion(psiPair,deltaPhi ) ){
1755                                         lElectronPsiIndex[i] = kFALSE;
1756                                         lPositronPsiIndex[j] = kFALSE;
1757                                 }
1758                         }
1759                 }
1760         }
1761
1762         vector<Int_t> lGoodElectronIndex(0);
1763         vector<Int_t> lGoodPositronIndex(0);
1764         
1765         for( UInt_t i = 0; i < lGoodElectronIndexPrev.size(); i++ ) {
1766                 if(  lElectronPsiIndex[i] == kTRUE )
1767                 lGoodElectronIndex.push_back(   lGoodElectronIndexPrev[i]  );
1768         }
1769
1770         for( UInt_t i = 0; i < lGoodPositronIndexPrev.size(); i++ ) {
1771                 if(  lPositronPsiIndex[i] == kTRUE )
1772                 lGoodPositronIndex.push_back(   lGoodPositronIndexPrev[i]  );
1773         }
1774
1775         for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
1776                 AliESDtrack *electronCandidate = fESDEvent->GetTrack(lGoodElectronIndex[i]);
1777                 AliKFParticle electronCandidateKF( *electronCandidate->GetConstrainedParam(), ::kElectron );
1778                 TLorentzVector electronCandidateTLV;
1779                 electronCandidateTLV.SetXYZM(electronCandidate->GetConstrainedParam()->Px(),electronCandidate->GetConstrainedParam()->Py(),electronCandidate->GetConstrainedParam()->Pz(),TDatabasePDG::Instance()->GetParticle(  ::kElectron   )->Mass());
1780                 
1781
1782                 for(UInt_t j = 0; j < lGoodPositronIndex.size(); j++){
1783
1784                         AliESDtrack *positronCandidate = fESDEvent->GetTrack(lGoodPositronIndex[j]);
1785                         AliKFParticle positronCandidateKF( *positronCandidate->GetConstrainedParam(), ::kPositron );
1786                         TLorentzVector positronCandidateTLV;
1787                 
1788                         positronCandidateTLV.SetXYZM(positronCandidate->GetConstrainedParam()->Px(),positronCandidate->GetConstrainedParam()->Py(),positronCandidate->GetConstrainedParam()->Pz(),TDatabasePDG::Instance()->GetParticle(  ::kPositron   )->Mass());
1789                         TLorentzVector *virtualPhotonTLV = 0;
1790                         AliKFConversionPhoton* virtualPhoton = NULL;
1791                         AliAODConversionPhoton *vphoton;
1792                         
1793                         if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetUseElectronMCSmearing() && ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->UseMCPSmearing() && fMCEvent){
1794                                 TLorentzVector smearelectronCandidateTLV = ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->SmearElectron(electronCandidateTLV);
1795                                 TLorentzVector smearpositronCandidateTLV = ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->SmearElectron(positronCandidateTLV);
1796                                 virtualPhotonTLV = new TLorentzVector( smearelectronCandidateTLV + smearpositronCandidateTLV );
1797                                 //TLorentzVector temp = electronCandidateTLV + positronCandidateTLV;
1798                                 //cout<<"Mass:  "<<"NoSmearElectrons  "<<temp.M() <<"   SmearElectrons  "<<virtualPhotonTLV->M()<<endl;
1799                                 vphoton= new AliAODConversionPhoton(virtualPhotonTLV); 
1800                                 vphoton->SetMass(virtualPhotonTLV->M());
1801                         } else {
1802                                 virtualPhoton = new AliKFConversionPhoton(electronCandidateKF,positronCandidateKF);
1803                                 if( fSetProductionVertextoVGamma == kTRUE ){
1804                                         AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
1805                                         primaryVertexImproved+=*virtualPhoton;
1806                                         virtualPhoton->SetProductionVertex(primaryVertexImproved);                      
1807                                 }
1808
1809                                 vphoton= new AliAODConversionPhoton(virtualPhoton);
1810                         }
1811                         //virtualPhoton->SetTrackLabels( lGoodPositronIndex[j], lGoodElectronIndex[i]);
1812                         vphoton->SetTrackLabels( lGoodPositronIndex[j], lGoodElectronIndex[i]);
1813                         
1814                         if( fMCEvent ) {
1815                                 Int_t labeln=TMath::Abs(electronCandidate->GetLabel());
1816                                 Int_t labelp=TMath::Abs(positronCandidate->GetLabel());
1817                                 TParticle *fNegativeMCParticle = fMCStack->Particle(labeln);
1818                                 TParticle *fPositiveMCParticle = fMCStack->Particle(labelp);
1819                                 if( fPositiveMCParticle && fNegativeMCParticle) {               
1820                                         //virtualPhoton->SetMCLabelPositive(labelp);
1821                                         //virtualPhoton->SetMCLabelNegative(labeln);
1822                                         vphoton->SetMCLabelPositive(labelp);
1823                                         vphoton->SetMCLabelNegative(labeln);
1824                                                 
1825                                 }               
1826                         }
1827                         
1828                                         
1829                         fGoodVirtualGammas->Add(  vphoton );
1830                         
1831                         if( virtualPhoton ){
1832                                 delete virtualPhoton;
1833                                 virtualPhoton=NULL;
1834                         }
1835                         if ( virtualPhotonTLV ){
1836                                 delete virtualPhotonTLV;
1837                                 virtualPhotonTLV=NULL;
1838                         }
1839                                         
1840                 }
1841         }
1842         
1843         //Computing mixing event
1844         if(  fDoMesonQA ) {
1845                 for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
1846                         AliESDtrack *electronCandidate1 = fESDEvent->GetTrack(lGoodElectronIndex[i]);
1847                         AliKFParticle electronCandidate1KF( *electronCandidate1->GetConstrainedParam(), ::kElectron );
1848                         
1849                         for(UInt_t j = i+1; j < lGoodElectronIndex.size(); j++){
1850                         
1851                                 AliESDtrack *electronCandidate2 = fESDEvent->GetTrack(lGoodElectronIndex[j]);
1852                                 AliKFParticle electronCandidate2KF( *electronCandidate2->GetConstrainedParam(), ::kElectron );
1853                                 AliKFConversionPhoton* virtualPhoton = new AliKFConversionPhoton(electronCandidate1KF,electronCandidate2KF);
1854                                 
1855                                 //AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
1856                                 //primaryVertexImproved+=*virtualPhoton;
1857                                 //virtualPhoton->SetProductionVertex(primaryVertexImproved);
1858
1859                                 AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); 
1860                                 hESDEposEnegLikeSignBackInvMassPt[fiCut]->Fill(vphoton->M(),vphoton->Pt());
1861                                 delete vphoton;
1862                                 delete virtualPhoton;
1863                                 vphoton = 0x0;
1864                                 virtualPhoton = 0x0;            
1865                         }
1866                 }   
1867         
1868         
1869                 for(UInt_t i = 0; i < lGoodPositronIndex.size(); i++){
1870                         AliESDtrack *positronCandidate1 = fESDEvent->GetTrack(lGoodPositronIndex[i]);
1871                         AliKFParticle positronCandidate1KF( *positronCandidate1->GetConstrainedParam(), ::kPositron );
1872                         
1873                         for(UInt_t j = i+1; j < lGoodPositronIndex.size(); j++){
1874                         
1875                                 AliESDtrack *positronCandidate2 = fESDEvent->GetTrack(lGoodPositronIndex[j]);
1876                                 AliKFParticle positronCandidate2KF( *positronCandidate2->GetConstrainedParam(), ::kPositron );
1877                                 AliKFConversionPhoton* virtualPhoton = new AliKFConversionPhoton(positronCandidate1KF,positronCandidate2KF);
1878                                 //AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
1879                                 //primaryVertexImproved+=*virtualPhoton;
1880                                 //virtualPhoton->SetProductionVertex(primaryVertexImproved);
1881                                 
1882                                 AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); 
1883                                 hESDEposEnegLikeSignBackInvMassPt[fiCut]->Fill(vphoton->M(),vphoton->Pt());     
1884                                 delete vphoton;
1885                                 delete virtualPhoton;  
1886                                 vphoton = 0x0;
1887                                 virtualPhoton = 0x0;
1888                 
1889                         }
1890                 }   
1891         }
1892 }
1893
1894 //________________________________________________________________________
1895 void AliAnalysisTaskGammaConvDalitzV1::CalculatePi0DalitzCandidates(){
1896
1897         // Conversion Gammas
1898         if( fGoodGammas->GetEntries() > 0 && fGoodVirtualGammas->GetEntries() > 0 ){
1899                 vector<Bool_t> lGoodVirtualGamma(fGoodVirtualGammas->GetEntries(), kFALSE);
1900                 
1901                 for(Int_t GammaIndex=0; GammaIndex<fGoodGammas->GetEntries(); GammaIndex++){
1902                         AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(GammaIndex));
1903                         if (gamma==NULL) continue;
1904                         for(Int_t virtualGammaIndex=0;virtualGammaIndex<fGoodVirtualGammas->GetEntries();virtualGammaIndex++){
1905                                 AliAODConversionPhoton *Vgamma=dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(virtualGammaIndex));
1906                                 if (Vgamma==NULL) continue;
1907                                 //Check for same Electron ID
1908                              if(gamma->GetTrackLabelPositive()    == Vgamma->GetTrackLabelPositive() ||
1909                                 gamma->GetTrackLabelNegative()    == Vgamma->GetTrackLabelNegative() ||
1910                                 gamma->GetTrackLabelNegative()    == Vgamma->GetTrackLabelPositive() ||
1911                                 gamma->GetTrackLabelPositive()    == Vgamma->GetTrackLabelNegative() ) continue;
1912
1913                                 AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma,Vgamma);
1914                                 pi0cand->SetLabels(GammaIndex,virtualGammaIndex);
1915                                                 
1916
1917                                 if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE,((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetEtaShift())) ){
1918                         
1919                                         //cout<< "Meson Accepted "<<endl;
1920                                         
1921                                         Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
1922                                                 Int_t mbin = 0;
1923                                                 if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ){
1924                                                         mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
1925                                                 } else {
1926                                                         mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
1927                                                 }
1928                                         
1929                                         if ( fDoMesonQA ) {
1930                                                 hESDEposEnegInvMassPi0Pt[fiCut]->Fill( Vgamma->M(), pi0cand->Pt() );                                    
1931                                                 if( pi0cand->M() > 0.1 && pi0cand->M() < 0.145 ){
1932                                                         hESDEposEnegAfterMassCutInvMassPi0Pt[fiCut]->Fill(Vgamma->M(),pi0cand->Pt());
1933                                                 }
1934                                         }
1935                         
1936                                         if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
1937                                                 if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( pi0cand->Pt() , Vgamma->M() ) == kTRUE ){
1938
1939                                                         hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());   
1940                                                         Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
1941                                                         sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
1942                                                         
1943                                                         if(fMCEvent){
1944                                                           ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
1945                                                         }
1946                                                 
1947                                                         if ( fDoMesonQA ) {
1948                                                                 hESDMotherPhi[fiCut]->Fill(pi0cand->Phi());
1949                                                                 if( lGoodVirtualGamma[virtualGammaIndex] == kFALSE ) {
1950                                                         
1951                                                                         FillElectronQAHistos(Vgamma);
1952                                                                         
1953                                                                         lGoodVirtualGamma[virtualGammaIndex] = kTRUE;
1954                                                                         fNVirtualGammas++;
1955                                                                 }
1956                                                         }
1957                                                 }
1958                                         } else {
1959                                                 hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
1960                                                 Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
1961                                                 sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
1962                                                 
1963                                                 if(fMCEvent){
1964                                                           ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
1965                                                 }
1966                                                 
1967                                                 if ( fDoMesonQA ) {
1968                                                         hESDMotherPhi[fiCut]->Fill(pi0cand->Phi());
1969                                                         if( lGoodVirtualGamma[virtualGammaIndex] == kFALSE ) {
1970                                                                 FillElectronQAHistos(Vgamma);
1971                                                                 lGoodVirtualGamma[virtualGammaIndex] = kTRUE;
1972                                                                 fNVirtualGammas++;
1973                                                         }
1974                                                 }
1975                                         }
1976                                 
1977                                         if( fDoChicAnalysis) {
1978                                         
1979                                                 hESDPi0MotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());                                                
1980                                                 Double_t diffMass = pi0cand->M() - Vgamma->M();
1981                                                 hESDPi0MotherDiffInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
1982                                 
1983                                                 if( Vgamma->M() > 2.5 && Vgamma->M() < 3.4){
1984                                                         hESDPi0MotherDiffLimInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
1985                                                 }
1986                                                 
1987                                                 if(fMCEvent){
1988                                                   ProcessTrueChicCandidates(pi0cand,gamma,Vgamma);
1989                                                 }
1990                                                 
1991                                                 
1992                                         }
1993                                         
1994                                         
1995                                 }
1996                                 delete pi0cand;
1997                                 pi0cand=0x0;
1998                         }
1999                 }
2000         }
2001 }
2002
2003 //________________________________________________________________________
2004 void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
2005
2006         Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
2007         Int_t mbin = 0;
2008
2009         Int_t method = 0;
2010
2011         method = ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetBKGMethod();
2012
2013         if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
2014                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
2015         } else {
2016                 mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
2017         }
2018
2019         if( method == 1 || method == 2 ) {
2020
2021                 AliGammaConversionAODBGHandler::GammaConversionVertex *bgEventVertex = NULL;
2022
2023                 if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ) {
2024                         for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2025
2026                                 AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2027                                 if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
2028                                         bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
2029                                 }
2030
2031                                 for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2032                                         AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2033
2034                                         for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2035                                                 AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2036
2037                                                 if(fMoveParticleAccordingToVertex == kTRUE && method == 1 ){
2038                                                         MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
2039                                                 }
2040
2041                                                 AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2042                                                 
2043                                                 if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE, ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetEtaShift()))){
2044                                                         if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2045                                                         
2046                                                                 if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.M() ) == kTRUE ){
2047                                                         
2048                                                                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2049                                                                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2050                                                                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2051                                                                 }
2052                                                         } else {
2053                                                                 hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2054                                                                 Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2055                                                                 sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2056                                                         }       
2057                                                 }
2058                                                 delete backgroundCandidate;
2059                                                 backgroundCandidate = 0x0;
2060                                         }
2061                                 }
2062                         }
2063                 } else {
2064                         for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2065                                 AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2066                                 if(previousEventV0s){
2067                                         if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
2068                                                 bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
2069                                         }
2070                                         for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2071                                                 AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2072                                                 for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2073                                                         AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2074                                                         if(fMoveParticleAccordingToVertex == kTRUE && method ==1){
2075                                                                 MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
2076                                                         }
2077
2078                                                         AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2079                                                         if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE,((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetEtaShift()))){
2080                                                                 if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2081                                                                         if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.M() ) == kTRUE ){
2082                                                                                 hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2083                                                                                 Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2084                                                                                 sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2085                                                                         }
2086                                                                 } else {
2087                                                                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2088                                                                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2089                                                                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2090                                                                 }
2091                                                         }
2092                                                         delete backgroundCandidate;
2093                                                         backgroundCandidate = 0x0;
2094                                                 }
2095                                         }
2096                                 }
2097                         }
2098                 }
2099         } else if( method == 3 ){
2100                 for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2101                         AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2102
2103                         for(Int_t iPrevious=0;iPrevious<fGammasPool[fiCut]->GetEntries();iPrevious++){
2104                                 AliAODConversionPhoton previousGoodV0 = *(AliAODConversionPhoton*)((fGammasPool[fiCut]->At(iPrevious) ));
2105                                 AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2106                                 
2107                                 if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE, ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetEtaShift()))){
2108                                         if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2109                                                 if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.M() ) == kTRUE ){
2110                                                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2111                                                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2112                                                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);   
2113                                                 }
2114                                         } else {        
2115                                                 hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2116                                                 Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2117                                                 sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1); 
2118                                         }
2119                                 }
2120                                 delete backgroundCandidate;
2121                                 backgroundCandidate = 0x0;
2122                         }
2123                 }
2124         }
2125 }
2126
2127 //________________________________________________________________________
2128 void AliAnalysisTaskGammaConvDalitzV1::UpdateEventByEventData(){
2129         //see header file for documentation
2130
2131         Int_t method = 0;
2132
2133         method = ( (AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetBKGMethod();
2134         
2135         if( method == 1 ) {
2136                 if(fGoodGammas->GetEntries() > 0 ){
2137                         if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ){
2138                                 fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
2139                         } else { // means we use #V0s for multiplicity
2140                                 fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
2141                         }
2142                 }
2143         } else if ( method == 2 ){
2144                 if(fGoodVirtualGammas->GetEntries() > 0 ){
2145                         if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
2146                                 fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
2147                         } else {  // means we use #V0s for multiplicity
2148                                 fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodVirtualGammas->GetEntries());
2149                         }
2150                 }
2151         } else if ( method  == 3 ) {
2152                 for(Int_t index = 0; index < fGoodGammas->GetEntries(); index++){
2153                         if ( fGammasPool[fiCut]->GetEntries() > ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->NumberOfRotationEvents() ){
2154                                 fGammasPool[fiCut]->RemoveLast();
2155                         }
2156                         fGammasPool[fiCut]->AddFirst( new AliAODConversionPhoton(*(AliAODConversionPhoton*)(fGoodGammas->At(index)) ) );
2157                 }
2158         }
2159 }
2160
2161 //______________________________________________________________________
2162 void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate, AliAODConversionPhoton *TrueVirtualGammaCandidate)
2163 {
2164
2165         // Process True Mesons
2166         AliStack *MCStack = fMCEvent->Stack();
2167         
2168         if( TrueGammaCandidate->GetV0Index() < fESDEvent->GetNumberOfV0s() ){
2169                 
2170           
2171
2172                 Bool_t isTruePi0 = kFALSE;
2173                 Bool_t isTrueEta = kFALSE;
2174                 
2175                 Int_t gammaMCLabel = TrueGammaCandidate->GetMCParticleLabel(MCStack);
2176                 Int_t gammaMotherLabel = -1;
2177                 
2178                 
2179
2180                 
2181                 
2182                 //Checking if the gamma candidate is a real gamma
2183                 
2184                 
2185                 if(gammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2186                         // Daughters Gamma 0
2187                         TParticle * negativeMC = (TParticle*)TrueGammaCandidate->GetNegativeMCDaughter(MCStack);
2188                         TParticle * positiveMC = (TParticle*)TrueGammaCandidate->GetPositiveMCDaughter(MCStack);
2189                         TParticle * gammaMC = (TParticle*)MCStack->Particle(gammaMCLabel);
2190
2191                         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
2192                                 if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
2193                                         if(gammaMC->GetPdgCode() == 22){ // ... with Gamma Mother
2194                                                 gammaMotherLabel=gammaMC->GetFirstMother();
2195                                         }
2196                                 }
2197                         }
2198                 }
2199
2200
2201                 
2202                 //Checking if the virtual gamma is a real virtual gamma
2203                 
2204                 Int_t virtualGammaMCLabel = TrueVirtualGammaCandidate->GetMCParticleLabel(MCStack);
2205                 Int_t virtualGammaMotherLabel = -1;
2206                 Int_t virtualGamma = -1;
2207                 
2208
2209
2210                 if( virtualGammaMCLabel != -1 ){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2211                         // Daughters Gamma 1
2212                         TParticle * negativeMC = (TParticle*)TrueVirtualGammaCandidate->GetNegativeMCDaughter(MCStack);
2213                         TParticle * positiveMC = (TParticle*)TrueVirtualGammaCandidate->GetPositiveMCDaughter(MCStack);
2214                         TParticle * virtualGammaMotherMC = (TParticle*)MCStack->Particle(virtualGammaMCLabel);
2215
2216                         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
2217
2218                                 if( virtualGammaMotherMC->GetPdgCode() != 22 ){
2219                                         virtualGammaMotherLabel=virtualGammaMCLabel;
2220                                         virtualGamma = 1;
2221                                         
2222                                 } else if (negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
2223                                         virtualGammaMotherLabel=virtualGammaMotherMC->GetFirstMother();
2224                                         virtualGamma = 0; //no virtual gamma
2225                                 }
2226                         }
2227                 }
2228
2229                 
2230                 //Checking if both gamma and virtual gamma comming from Pi0 or Eta
2231                 
2232
2233                 if( gammaMotherLabel >= 0 && ( gammaMotherLabel == virtualGammaMotherLabel) ){
2234                         if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 111){
2235                                 isTruePi0=kTRUE;
2236                         }
2237                         if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 221){
2238                                 isTrueEta=kTRUE;
2239                         }
2240                 }
2241
2242                 
2243
2244                 if(  isTruePi0 || isTrueEta ){ // True Pion or Eta
2245                         if ( virtualGamma == 1 ) { //True Dalitz        
2246                                 Float_t weighted= 1;
2247                                 
2248                                 if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2249                                         if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack,fInputEvent)){
2250                                                 if (((TParticle*)MCStack->Particle(gammaMotherLabel))->Pt()>0.005){
2251                                                         weighted= ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gammaMotherLabel,fMCStack,fInputEvent);
2252                                                 }
2253                                         }
2254                                 }
2255
2256                                 hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2257                                 hESDTrueMotherDalitzInvMassPt[fiCut]->Fill( TrueVirtualGammaCandidate->M(),Pi0Candidate->Pt(),weighted);
2258
2259                                 if(gammaMotherLabel < MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
2260                                         hESDTruePrimaryMotherInvMassPt[fiCut]->Fill( Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2261                                         hESDTruePrimaryMotherW0WeightingInvMassPt[fiCut]->Fill( Pi0Candidate->M(), Pi0Candidate->Pt() );
2262                                 
2263                                         hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
2264                                         if(isTruePi0){ // Only primaries for unfolding
2265                                                 hESDTruePrimaryPi0DalitzESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
2266                                         }
2267                                 } else { // Secondary Meson
2268                                         Float_t weightedSec= 1;
2269                                         if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2270                                                 Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gammaMotherLabel))->GetMother(0);
2271                                                 if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(gammaMotherLabel)->GetPdgCode()==310){
2272                                                         weightedSec= ((AliConvEventCuts*)fCutEventArray->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
2273                                                 }
2274                                         }
2275                                         hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec); 
2276                                 }
2277                         } else if ( virtualGamma == 0 ){
2278                                 Float_t weighted= 1;
2279                                 if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) {
2280                                         if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack,fInputEvent)){
2281                                                 if (((TParticle*)MCStack->Particle(gammaMotherLabel))->Pt()>0.005){
2282                                                         weighted= ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gammaMotherLabel,fMCStack,fInputEvent);
2283                                                 }
2284                                         }
2285                                 }
2286                                 hESDTrueMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted); // Pi0 from GG
2287                                 if( gammaMotherLabel < MCStack->GetNprimary() ){
2288                                         hESDTruePrimaryMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2289                                 } else {
2290                                         Float_t weightedSec= 1;
2291                                         if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2292                                                 Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gammaMotherLabel))->GetMother(0);
2293                                                 if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(gammaMotherLabel)->GetPdgCode()==310){
2294                                                         weightedSec= ((AliConvEventCuts*)fCutEventArray->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
2295                                                 }
2296                                         }
2297                                         hESDTrueSecondaryMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2298                                 }
2299                         }
2300                 }
2301
2302                 if( !isTruePi0 && !isTrueEta ){ // Background
2303                         if( gammaMotherLabel > -1 && virtualGammaMotherLabel > -1 && virtualGamma == 0 ){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
2304                                 hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2305                         } else { // No photon or without mother
2306                                 hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2307                         }
2308                 }
2309         }
2310 }
2311
2312 //______________________________________________________________________
2313 void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueChicCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate, AliAODConversionPhoton *TruejpsiCandidate)
2314 {
2315
2316         
2317         AliStack *MCStack = fMCEvent->Stack();
2318         
2319         
2320         if(     TrueGammaCandidate->GetV0Index() < fESDEvent->GetNumberOfV0s()  ){
2321                 
2322           
2323           
2324                 //Checking gamma
2325                 
2326                 Int_t gammaMCLabel = TrueGammaCandidate->GetMCParticleLabel(MCStack);
2327                 Int_t gammaMotherLabel = -1;
2328
2329                 
2330                 
2331                 if( gammaMCLabel != -1){// Gamma is Combinatorial; MC Particles don't belong to the same Mother
2332                         // Daughters Gamma 0
2333                         
2334                         TParticle * negativeMC = (TParticle*)TrueGammaCandidate->GetNegativeMCDaughter(MCStack);
2335                         TParticle * positiveMC = (TParticle*)TrueGammaCandidate->GetPositiveMCDaughter(MCStack);
2336                         TParticle * gammaMC = (TParticle*)MCStack->Particle(gammaMCLabel);
2337
2338                         if( TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11 ){  // Electrons ...
2339                                 if( negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() == 5 ){ // ... From Conversion ...
2340                                         if(gammaMC->GetPdgCode() == 22){ // ... with Gamma Mother
2341                                                 gammaMotherLabel=gammaMC->GetFirstMother();
2342                                         }
2343                                 }
2344                         }
2345                 }
2346
2347
2348                 
2349                 //Checking jpsi
2350                 
2351                 Int_t jpsiMCLabel               = TruejpsiCandidate->GetMCParticleLabel(MCStack);
2352                 Int_t jpsiMotherLabel           = -1;
2353
2354                 
2355
2356                 if( jpsiMCLabel != -1 ){ 
2357                         
2358                         TParticle * negativeMC = (TParticle*)TruejpsiCandidate->GetNegativeMCDaughter(MCStack);
2359                         TParticle * positiveMC = (TParticle*)TruejpsiCandidate->GetPositiveMCDaughter(MCStack);
2360                         TParticle * jpsiMC = (TParticle*)MCStack->Particle(jpsiMCLabel);
2361
2362                         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
2363
2364                                                                         
2365                                 if(jpsiMC->GetPdgCode() == 443){
2366                                   
2367                                                 jpsiMotherLabel=jpsiMC->GetFirstMother();
2368                                                 
2369                                 }
2370                                  
2371                                                                 
2372                         }
2373                 }
2374
2375
2376                 if( gammaMotherLabel>=0 && ( gammaMotherLabel == jpsiMotherLabel) ){
2377                   if(                   ((TParticle*)MCStack->Particle(jpsiMotherLabel))->GetPdgCode() == 445   ||
2378                                         ((TParticle*)MCStack->Particle(jpsiMotherLabel))->GetPdgCode() == 10443 ||
2379                                         ((TParticle*)MCStack->Particle(jpsiMotherLabel))->GetPdgCode() == 20443 ){
2380                                 
2381                                         hESDTrueMotherChiCInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2382                                         hESDTrueMotherChiCDiffInvMassPt[fiCut]->Fill(Pi0Candidate->M()-TruejpsiCandidate->M(),Pi0Candidate->Pt());
2383                   }
2384                 }  
2385                 
2386         }
2387 }
2388
2389
2390
2391
2392
2393 //________________________________________________________________________
2394 void AliAnalysisTaskGammaConvDalitzV1::MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex){
2395    //see header file for documentation
2396
2397         Double_t dx = vertex->fX - fESDEvent->GetPrimaryVertex()->GetX();
2398         Double_t dy = vertex->fY - fESDEvent->GetPrimaryVertex()->GetY();
2399         Double_t dz = vertex->fZ - fESDEvent->GetPrimaryVertex()->GetZ();
2400
2401         Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
2402         particle->SetConversionPoint(movedPlace);
2403 }
2404
2405
2406 //________________________________________________________________________
2407 void AliAnalysisTaskGammaConvDalitzV1::CountESDTracks(){
2408
2409         // Using standard function for setting Cuts
2410         Bool_t selectPrimaries=kTRUE;
2411         AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
2412         EsdTrackCuts->SetMaxDCAToVertexZ(2);
2413         EsdTrackCuts->SetEtaRange(-0.8, 0.8);
2414         EsdTrackCuts->SetPtRange(0.15);
2415         EsdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kBoth);
2416
2417         fNumberOfESDTrackskBoth = 0;
2418         for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
2419                 AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
2420                 if(!curTrack) continue;
2421                 if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTrackskBoth++;
2422         }
2423         delete EsdTrackCuts;
2424         EsdTrackCuts=0x0;
2425
2426         return;
2427 }
2428
2429 //_____________________________________________________________________________
2430 void AliAnalysisTaskGammaConvDalitzV1::ProcessMCParticles()
2431 {
2432
2433 // Loop over all primary MC particle
2434
2435         for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
2436         
2437                 TParticle* particle = (TParticle *)fMCStack->Particle(i);
2438                 if (!particle) continue;
2439         
2440                 Bool_t mcIsFromMB = kTRUE;
2441                 Int_t isMCFromMBHeader = -1;
2442                         
2443                 if(((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 0) {
2444                         isMCFromMBHeader = ((AliConvEventCuts*)fCutEventArray->At(fiCut))->IsParticleFromBGEvent(i,fMCStack,fInputEvent);
2445                         if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fCutEventArray->At(fiCut))->GetSignalRejection() != 3) continue;
2446                         if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
2447                 }    
2448                 
2449                 if(((AliConversionPhotonCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
2450                         hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
2451                 }