31a3a0bfaa9598e0cb8060f5f85db655130007cb
[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    fCutGammaArray(NULL),
84    fCutElectronArray(NULL),
85    fCutMesonArray(NULL),
86    fGammasPool(NULL),
87    fConversionCuts(NULL),
88    hESDConvGammaPt(NULL),
89    hESDConvGammaEta(NULL),
90    hESDConvGammaZR(NULL),
91    hESDDalitzElectronPt(NULL),
92    hESDDalitzPositronPt(NULL),
93    hESDDalitzElectronPhi(NULL),
94    hESDDalitzPositronPhi(NULL),
95    hESDDalitzElectronAfterPt(NULL),
96    hESDDalitzPositronAfterPt(NULL),
97    hESDDalitzElectronAfterEta(NULL),
98    hESDDalitzPositronAfterEta(NULL),
99    hESDDalitzElectronAfterPhi(NULL),
100    hESDDalitzPositronAfterPhi(NULL),
101    hESDDalitzElectronAfterNClsITS(NULL),
102    hESDDalitzPositronAfterNClsITS(NULL),
103    hESDDalitzElectronAfterNFindClsTPC(NULL),
104    hESDDalitzPositronAfterNFindClsTPC(NULL),
105    hESDDalitzElectronAfterNClsTPC(NULL),
106    hESDDalitzPositronAfterNClsTPC(NULL),
107    hESDDalitzElectronAfterNCrossedRowsTPC(NULL),
108    hESDDalitzPositronAfterNCrossedRowsTPC(NULL),
109    hESDDalitzPosEleAfterDCAxy(NULL),
110    hESDDalitzPosEleAfterDCAz(NULL),
111    hESDDalitzElectronAfterTPCdEdxVsP(NULL),
112    hESDDalitzPositronAfterTPCdEdxVsP(NULL),
113    hESDDalitzElectronAfterTPCdEdxSignalVsP(NULL),
114    hESDDalitzPositronAfterTPCdEdxSignalVsP(NULL),
115    hESDDalitzElectronAfterTPCdEdxVsEta(NULL),
116    hESDDalitzPositronAfterTPCdEdxVsEta(NULL),
117    hESDDalitzElectronAfterTPCdEdxVsPhi(NULL),
118    hESDDalitzPositronAfterTPCdEdxVsPhi(NULL),
119    hESDMotherPhi(NULL),
120    hESDEposEnegPsiPairDPhi(NULL),
121    hESDEposEnegInvMassPt(NULL),
122    hESDEposEnegAfterMassCutInvMassPi0Pt(NULL),
123    hESDEposEnegLikeSignBackInvMassPt(NULL),
124    hESDMotherInvMassPt(NULL),
125    hESDPi0MotherInvMassPt(NULL),
126    hESDPi0MotherDiffInvMassPt(NULL),
127    hESDPi0MotherDiffLimInvMassPt(NULL),
128    sESDMotherInvMassPtZM(NULL),
129    hESDMotherBackInvMassPt(NULL),
130    sESDMotherBackInvMassPtZM(NULL),
131    hMCAllGammaPt(NULL),
132    hMCConvGammaPt(NULL),
133    hMCConvGammaRSPt(NULL),
134    hMCAllPositronsPt(NULL),
135    hMCAllElectronsPt(NULL),
136    hMCConvGammaEta(NULL),
137    hMCAllPositronsEta(NULL),
138    hMCAllElectronsEta(NULL),
139    hMCPi0DalitzGammaPt(NULL),
140    hMCPi0DalitzElectronPt(NULL),
141    hMCPi0DalitzPositronPt(NULL),
142    hMCPi0Pt(NULL),
143    hMCPi0GGPt(NULL),
144    hMCEtaPt(NULL),
145    hMCEtaGGPt(NULL), 
146    hMCPi0InAccPt(NULL),
147    hMCEtaInAccPt(NULL),
148    hMCChiCPt(NULL),
149    hMCChiCInAccPt(NULL),
150    hMCPi0EposEnegInvMassPt(NULL),
151    hMCEtaEposEnegInvMassPt(NULL),
152    hESDEposEnegTruePi0DalitzInvMassPt(NULL),
153    hESDEposEnegTruePrimPi0DalitzInvMass(NULL),
154    hESDEposEnegTruePi0DalitzPsiPairDPhi(NULL),
155    hESDEposEnegTrueEtaDalitzInvMassPt(NULL),
156    hESDEposEnegTruePrimEtaDalitzInvMass(NULL),
157    hESDEposEnegTrueEtaDalitzPsiPairDPhi(NULL),
158    hESDEposEnegTruePhotonInvMassPt(NULL),
159    hESDEposEnegTrueInvMassPt(NULL),
160    hESDEposEnegTruePhotonPsiPairDPhi(NULL),
161    hESDEposEnegTruePhotonPsiPairDPhiPtCut(NULL),
162    hESDEposEnegTrueJPsiInvMassPt(NULL),
163    hESDTrueMotherChiCInvMassPt(NULL),
164    hESDTrueMotherChiCDiffInvMassPt(NULL),
165    hESDTrueMotherInvMassPt(NULL),
166    hESDTrueMotherDalitzInvMassPt(NULL),
167    hESDTrueMotherPi0GGInvMassPt(NULL),
168    hESDTruePrimaryMotherPi0GGInvMassPt(NULL),
169    hESDTrueSecondaryMotherPi0GGInvMassPt(NULL),
170    hESDTruePrimaryMotherInvMassMCPt(NULL),
171    hESDTruePrimaryMotherInvMassPt(NULL),
172    hESDTruePrimaryMotherW0WeightingInvMassPt(NULL),
173    hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
174    hESDTrueSecondaryMotherInvMassPt(NULL),
175    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
176    hESDTrueBckGGInvMassPt(NULL),
177    hESDTrueBckContInvMassPt(NULL),
178    hESDTrueMotherGGInvMassPt(NULL),
179    hESDTrueConvGammaPt(NULL),
180    hESDTruePositronPt(NULL),
181    hESDTrueElectronPt(NULL),
182    hESDTrueSecConvGammaPt(NULL),
183    hESDTrueSecPositronPt(NULL),
184    hESDTrueSecElectronPt(NULL),
185    hESDTruePi0DalitzConvGammaPt(NULL),
186    hESDTruePi0DalitzPositronPt(NULL),
187    hESDTruePi0DalitzElectronPt(NULL),
188    hESDTruePi0DalitzSecConvGammaPt(NULL),
189    hESDTruePi0DalitzSecPositronPt(NULL),
190    hESDTruePi0DalitzSecElectronPt(NULL),
191    hNEvents(NULL),
192    hNGoodESDTracks(NULL),
193    hNGoodESDTracksVsNGoodGammas(NULL),
194    hNGoodESDTracksVsNGoodVGammas(NULL),
195    hNV0Tracks(NULL),
196    hEtaShift(NULL),
197    fRandom(0),
198    fUnsmearedPx(NULL),
199    fUnsmearedPy(NULL),
200    fUnsmearedPz(NULL),
201    fUnsmearedE(NULL),
202    fUnsmearedVPx(NULL),
203    fUnsmearedVPy(NULL),
204    fUnsmearedVPz(NULL),
205    fUnsmearedVE(NULL),
206    fnCuts(0),
207    fiCut(0),
208    fNumberOfESDTracks(0),
209    fNumberOfESDTrackskBoth(0),
210    fMoveParticleAccordingToVertex(kFALSE),
211    fIsHeavyIon(kFALSE),
212    fDoMesonAnalysis(kTRUE),
213    fDoChicAnalysis(kFALSE),
214    fDoMesonQA(kFALSE),
215    fSetProductionVertextoVGamma(kTRUE),
216    fIsFromMBHeader(kTRUE),
217    fIsMC(kFALSE)
218 {
219
220 }
221
222 //-----------------------------------------------------------------------------------------------
223 AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char* name ):
224    AliAnalysisTaskSE(name),
225    fV0Reader(NULL),
226    fElecSelector(NULL),
227    fBGHandler(NULL),
228    fESDEvent(NULL),
229    fMCEvent(NULL),
230    fMCStack(NULL),
231    fCutFolder(NULL),
232    fESDList(NULL),
233    fBackList(NULL),
234    fMotherList(NULL),
235    fTrueList(NULL),
236    fMCList(NULL),
237    fQAFolder(NULL),
238    fOutputContainer(0),
239    fReaderGammas(NULL),
240    fSelectorElectronIndex(0),
241    fSelectorPositronIndex(0),
242    fGoodGammas(NULL),
243    fGoodVirtualGammas(NULL),
244    fGoodElectrons(NULL),
245    fGoodPositrons(NULL),
246    fCutGammaArray(NULL),
247    fCutElectronArray(NULL),
248    fCutMesonArray(NULL),
249    fGammasPool(NULL),
250    fConversionCuts(NULL),
251    hESDConvGammaPt(NULL),
252    hESDConvGammaEta(NULL),
253    hESDConvGammaZR(NULL),
254    hESDDalitzElectronPt(NULL),
255    hESDDalitzPositronPt(NULL),
256    hESDDalitzElectronPhi(NULL),
257    hESDDalitzPositronPhi(NULL),
258    hESDDalitzElectronAfterPt(NULL),
259    hESDDalitzPositronAfterPt(NULL),
260    hESDDalitzElectronAfterEta(NULL),
261    hESDDalitzPositronAfterEta(NULL),
262    hESDDalitzElectronAfterPhi(NULL),
263    hESDDalitzPositronAfterPhi(NULL),
264    hESDDalitzElectronAfterNClsITS(NULL),
265    hESDDalitzPositronAfterNClsITS(NULL),
266    hESDDalitzElectronAfterNFindClsTPC(NULL),
267    hESDDalitzPositronAfterNFindClsTPC(NULL),
268    hESDDalitzElectronAfterNClsTPC(NULL),
269    hESDDalitzPositronAfterNClsTPC(NULL),
270    hESDDalitzElectronAfterNCrossedRowsTPC(NULL),
271    hESDDalitzPositronAfterNCrossedRowsTPC(NULL),
272    hESDDalitzPosEleAfterDCAxy(NULL),
273    hESDDalitzPosEleAfterDCAz(NULL),
274    hESDDalitzElectronAfterTPCdEdxVsP(NULL),
275    hESDDalitzPositronAfterTPCdEdxVsP(NULL),
276    hESDDalitzElectronAfterTPCdEdxSignalVsP(NULL),
277    hESDDalitzPositronAfterTPCdEdxSignalVsP(NULL),
278    hESDDalitzElectronAfterTPCdEdxVsEta(NULL),
279    hESDDalitzPositronAfterTPCdEdxVsEta(NULL),
280    hESDDalitzElectronAfterTPCdEdxVsPhi(NULL),
281    hESDDalitzPositronAfterTPCdEdxVsPhi(NULL),
282    hESDMotherPhi(NULL),
283    hESDEposEnegPsiPairDPhi(NULL),
284    hESDEposEnegInvMassPt(NULL),
285    hESDEposEnegAfterMassCutInvMassPi0Pt(NULL),
286    hESDEposEnegLikeSignBackInvMassPt(NULL),
287    hESDMotherInvMassPt(NULL),
288    hESDPi0MotherInvMassPt(NULL),
289    hESDPi0MotherDiffInvMassPt(NULL),
290    hESDPi0MotherDiffLimInvMassPt(NULL),
291    sESDMotherInvMassPtZM(NULL),
292    hESDMotherBackInvMassPt(NULL),
293    sESDMotherBackInvMassPtZM(NULL),
294    hMCAllGammaPt(NULL),
295    hMCConvGammaPt(NULL),
296    hMCConvGammaRSPt(NULL),
297    hMCAllPositronsPt(NULL),
298    hMCAllElectronsPt(NULL),
299    hMCConvGammaEta(NULL),
300    hMCAllPositronsEta(NULL),
301    hMCAllElectronsEta(NULL),
302    hMCPi0DalitzGammaPt(NULL),
303    hMCPi0DalitzElectronPt(NULL),
304    hMCPi0DalitzPositronPt(NULL),
305    hMCPi0Pt(NULL),
306    hMCPi0GGPt(NULL),
307    hMCEtaPt(NULL),
308    hMCEtaGGPt(NULL),
309    hMCPi0InAccPt(NULL),
310    hMCEtaInAccPt(NULL),
311    hMCChiCPt(NULL),
312    hMCChiCInAccPt(NULL),
313    hMCPi0EposEnegInvMassPt(NULL),
314    hMCEtaEposEnegInvMassPt(NULL),
315    hESDEposEnegTruePi0DalitzInvMassPt(NULL),
316    hESDEposEnegTruePrimPi0DalitzInvMass(NULL),
317    hESDEposEnegTruePi0DalitzPsiPairDPhi(NULL),
318    hESDEposEnegTrueEtaDalitzInvMassPt(NULL),
319    hESDEposEnegTruePrimEtaDalitzInvMass(NULL),
320    hESDEposEnegTrueEtaDalitzPsiPairDPhi(NULL),
321    hESDEposEnegTruePhotonInvMassPt(NULL),
322    hESDEposEnegTrueInvMassPt(NULL),
323    hESDEposEnegTruePhotonPsiPairDPhi(NULL),
324    hESDEposEnegTruePhotonPsiPairDPhiPtCut(NULL),
325    hESDEposEnegTrueJPsiInvMassPt(NULL),
326    hESDTrueMotherChiCInvMassPt(NULL),
327    hESDTrueMotherChiCDiffInvMassPt(NULL),
328    hESDTrueMotherInvMassPt(NULL),
329    hESDTrueMotherDalitzInvMassPt(NULL),
330    hESDTrueMotherPi0GGInvMassPt(NULL),
331    hESDTruePrimaryMotherPi0GGInvMassPt(NULL),
332    hESDTrueSecondaryMotherPi0GGInvMassPt(NULL),
333    hESDTruePrimaryMotherInvMassMCPt(NULL),
334    hESDTruePrimaryMotherInvMassPt(NULL),
335    hESDTruePrimaryMotherW0WeightingInvMassPt(NULL),
336    hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
337    hESDTrueSecondaryMotherInvMassPt(NULL),
338    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
339    hESDTrueBckGGInvMassPt(NULL),
340    hESDTrueBckContInvMassPt(NULL),
341    hESDTrueMotherGGInvMassPt(NULL),
342    hESDTrueConvGammaPt(NULL),
343    hESDTruePositronPt(NULL),
344    hESDTrueElectronPt(NULL),
345    hESDTrueSecConvGammaPt(NULL),
346    hESDTrueSecPositronPt(NULL),
347    hESDTrueSecElectronPt(NULL),
348    hESDTruePi0DalitzConvGammaPt(NULL),
349    hESDTruePi0DalitzPositronPt(NULL),
350    hESDTruePi0DalitzElectronPt(NULL),
351    hESDTruePi0DalitzSecConvGammaPt(NULL),
352    hESDTruePi0DalitzSecPositronPt(NULL),
353    hESDTruePi0DalitzSecElectronPt(NULL),
354    hNEvents(NULL),
355    hNGoodESDTracks(NULL),
356    hNGoodESDTracksVsNGoodGammas(NULL),
357    hNGoodESDTracksVsNGoodVGammas(NULL),
358    hNV0Tracks(NULL),
359    hEtaShift(NULL),
360    fRandom(0),
361    fUnsmearedPx(NULL),
362    fUnsmearedPy(NULL),
363    fUnsmearedPz(NULL),
364    fUnsmearedE(NULL),
365    fUnsmearedVPx(NULL),
366    fUnsmearedVPy(NULL),
367    fUnsmearedVPz(NULL),
368    fUnsmearedVE(NULL),
369    fnCuts(0),
370    fiCut(0),
371    fNumberOfESDTracks(0),
372    fNumberOfESDTrackskBoth(0),
373    fMoveParticleAccordingToVertex(kFALSE),
374    fIsHeavyIon(kFALSE),
375    fDoMesonAnalysis(kTRUE),
376    fDoChicAnalysis(kFALSE),
377    fDoMesonQA(kFALSE),
378    fSetProductionVertextoVGamma(kTRUE),
379    fIsFromMBHeader(kTRUE),
380    fIsMC(kFALSE)
381 {
382    DefineOutput(1, TList::Class());
383 }
384
385 //-----------------------------------------------------------------------------------------------
386 AliAnalysisTaskGammaConvDalitzV1::~AliAnalysisTaskGammaConvDalitzV1()
387 {
388    //
389    // virtual destructor
390    //
391
392    cout<<"Destructor"<<endl;
393
394    if(fGoodGammas){
395       delete fGoodGammas;
396       fGoodGammas = 0x0;
397    }
398    if(fGoodVirtualGammas){
399       delete fGoodVirtualGammas;
400       fGoodGammas = 0x0;
401    }
402    if(fGoodElectrons){
403       delete fGoodGammas;
404       fGoodGammas = 0x0;
405    }
406    if(fGoodPositrons){
407       delete fGoodGammas;
408       fGoodGammas = 0x0;
409    }
410    if(fBGHandler){
411       delete[] fBGHandler;
412       fBGHandler = 0x0;
413    }
414    if( fGammasPool ){
415       delete[] fGammasPool;
416       fGammasPool = 0x0;
417    }
418 }
419 //___________________________________________________________
420 void AliAnalysisTaskGammaConvDalitzV1::InitBack(){
421
422    const Int_t nDim = 4;
423    Int_t nBins[nDim] = {800,250,7,4};
424    Double_t xMin[nDim] = {0,0, 0,0};
425    Double_t xMax[nDim] = {0.8,25,7,4};
426    
427    sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
428    sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
429
430    fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
431    //fBGHandlerRP = new AliConversionAODBGHandlerRP*[fnCuts];
432    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
433       //if (((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->DoBGCalculation()){
434
435          
436          TString cutstringElectron     =   ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
437          TString cutstringMeson        =   ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
438          TString cutstringGamma        =   ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
439
440
441          
442          Int_t collisionSystem = atoi((TString)(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber())(0,1));
443          Int_t centMin = atoi((TString)(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber())(1,1));
444          Int_t centMax = atoi((TString)(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber())(2,1));
445          
446          if(collisionSystem == 1 || collisionSystem == 2 ||
447             collisionSystem == 5 || collisionSystem == 8 ||
448             collisionSystem == 9){
449             centMin = centMin*10;
450             centMax = centMax*10; 
451          }
452          else if(collisionSystem == 3 || collisionSystem == 6){
453             centMin = centMin*5;
454             centMax = centMax*5;
455          }
456          else if(collisionSystem == 4 || collisionSystem == 7){
457             centMin = ((centMin*5)+45);
458             centMax = ((centMax*5)+45);
459          }
460
461
462          fBackList[iCut] = new TList();
463          fBackList[iCut]->SetName(Form("%s_%s_%s Back histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
464          fBackList[iCut]->SetOwner(kTRUE);
465          fCutFolder[iCut]->Add(fBackList[iCut]);
466
467          sESDMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
468          fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
469
470          fMotherList[iCut] = new TList();
471          fMotherList[iCut]->SetName(Form("%s_%s_%s Mother histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
472          fMotherList[iCut]->SetOwner(kTRUE);
473          fCutFolder[iCut]->Add(fMotherList[iCut]);
474
475          sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
476          fMotherList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
477
478          
479          fBGHandler[iCut] = new AliGammaConversionAODBGHandler(
480                                                                   collisionSystem,centMin,centMax,
481                                                                   ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->NumberOfRotationEvents(),
482                                                                   ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->UseTrackMultiplicity());
483         
484         if( ( (AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetBKGMethod() == 3 ){
485          fGammasPool[iCut] = new TList();
486         }
487
488       //}
489    }
490 }
491
492 //______________________________________________________________________
493 void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
494 {
495    //
496    // Create ouput objects
497    //
498
499    // Create the output container
500    if(fOutputContainer != NULL){
501       delete fOutputContainer;
502       fOutputContainer = NULL;
503    }
504    if(fOutputContainer == NULL){
505       fOutputContainer = new TList();
506       fOutputContainer->SetOwner(kTRUE);
507    }
508
509    fGoodGammas = new TList();
510    //fGoodGammas->SetOwner(kTRUE);
511
512
513    fGoodVirtualGammas = new TList();
514    //fGoodVirtualGammas->SetOwner(kTRUE);
515
516
517
518    fGammasPool                     = new TList*[fnCuts];
519    fCutFolder                      = new TList*[fnCuts];
520    fESDList                        = new TList*[fnCuts];
521    fBackList                       = new TList*[fnCuts];
522    fMotherList                     = new TList*[fnCuts];
523    //fQAFolder                       = new TList*[fnCuts];
524    hNEvents                        = new TH1I*[fnCuts];
525    hNGoodESDTracks                 = new TH1I*[fnCuts];
526    hNV0Tracks                      = new TH1I*[fnCuts];
527    hEtaShift                       = new TProfile*[fnCuts];
528    hESDConvGammaPt                 = new TH1F*[fnCuts];
529    hESDConvGammaEta                = new TH1F*[fnCuts];
530    
531    hESDDalitzElectronPt            = new TH1F*[fnCuts];
532    hESDDalitzPositronPt            = new TH1F*[fnCuts];
533    hESDDalitzElectronPhi           = new TH1F*[fnCuts];
534    hESDDalitzPositronPhi           = new TH1F*[fnCuts];
535    
536    if( fDoMesonQA ) {
537      
538    fQAFolder  = new TList*[fnCuts];  
539    
540    hNGoodESDTracksVsNGoodGammas    = new TH2F*[fnCuts];
541    hNGoodESDTracksVsNGoodVGammas   = new TH2F*[fnCuts]; 
542    hESDDalitzElectronAfterPt       = new TH1F*[fnCuts];
543    hESDDalitzPositronAfterPt       = new TH1F*[fnCuts];
544    hESDDalitzElectronAfterEta      = new TH1F*[fnCuts];
545    hESDDalitzPositronAfterEta      = new TH1F*[fnCuts];
546    hESDDalitzElectronAfterPhi      = new TH1F*[fnCuts];
547    hESDDalitzPositronAfterPhi      = new TH1F*[fnCuts];
548    hESDDalitzElectronAfterNClsITS  = new TH1F*[fnCuts];
549    hESDDalitzPositronAfterNClsITS  = new TH1F*[fnCuts];
550    hESDDalitzElectronAfterNFindClsTPC = new TH2F*[fnCuts];
551    hESDDalitzPositronAfterNFindClsTPC = new TH2F*[fnCuts];
552    hESDDalitzElectronAfterNClsTPC     = new TH2F*[fnCuts];
553    hESDDalitzPositronAfterNClsTPC     = new TH2F*[fnCuts];
554    hESDDalitzElectronAfterNCrossedRowsTPC = new TH2F*[fnCuts];
555    hESDDalitzPositronAfterNCrossedRowsTPC = new TH2F*[fnCuts];
556    hESDDalitzPosEleAfterDCAxy      = new TH2F*[fnCuts];
557    hESDDalitzPosEleAfterDCAz       = new TH2F*[fnCuts];
558    hESDDalitzElectronAfterTPCdEdxVsP    = new TH2F*[fnCuts];
559    hESDDalitzPositronAfterTPCdEdxVsP = new TH2F*[fnCuts];
560    hESDDalitzElectronAfterTPCdEdxSignalVsP = new TH2F*[fnCuts];
561    hESDDalitzPositronAfterTPCdEdxSignalVsP = new TH2F*[fnCuts];
562    hESDDalitzElectronAfterTPCdEdxVsEta = new TH2F*[fnCuts];
563    hESDDalitzPositronAfterTPCdEdxVsEta = new TH2F*[fnCuts];
564    hESDDalitzElectronAfterTPCdEdxVsPhi = new TH2F*[fnCuts];
565    hESDDalitzPositronAfterTPCdEdxVsPhi = new TH2F*[fnCuts];
566    hESDMotherPhi                   = new TH1F*[fnCuts];
567    hESDEposEnegPsiPairDPhi         = new TH2F*[fnCuts];
568    hESDEposEnegInvMassPt           = new TH2F*[fnCuts];
569    hESDEposEnegAfterMassCutInvMassPi0Pt = new TH2F*[fnCuts];
570    hESDEposEnegLikeSignBackInvMassPt = new TH2F*[fnCuts];
571    hESDConvGammaZR                 = new TH2F*[fnCuts];
572    
573    }
574    
575    
576    
577    hESDMotherInvMassPt             = new TH2F*[fnCuts];
578    
579    if(fDoChicAnalysis) {
580    hESDPi0MotherInvMassPt          = new TH2F*[fnCuts];
581    hESDPi0MotherDiffInvMassPt      = new TH2F*[fnCuts];
582    hESDPi0MotherDiffLimInvMassPt   = new TH2F*[fnCuts];
583    }
584    
585    
586    hESDMotherBackInvMassPt         = new TH2F*[fnCuts];
587
588
589    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
590
591
592       TString cutstringElectron =((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
593       TString cutstringMeson= ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
594       TString cutstringGamma = ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
595
596       fCutFolder[iCut] = new TList();
597       fCutFolder[iCut]->SetName(Form("Cut Number %s_%s_%s",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
598       fCutFolder[iCut]->SetOwner(kTRUE);
599       fOutputContainer->Add(fCutFolder[iCut]);
600
601       fESDList[iCut] = new TList();
602       fESDList[iCut]->SetName(Form("%s_%s_%s ESD histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
603       fESDList[iCut]->SetOwner(kTRUE);
604       
605      
606       hNEvents[iCut] = new TH1I("NEvents","NEvents",9,-0.5,8.5);
607       hNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
608       hNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
609       hNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Missing MC");
610       hNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
611       hNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
612       hNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
613       hNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
614       hNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
615       hNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
616       fESDList[iCut]->Add(hNEvents[iCut]);
617
618
619
620       if(fIsHeavyIon) hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
621       else hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
622       fESDList[iCut]->Add(hNGoodESDTracks[iCut]);
623       
624       
625       if(fIsHeavyIon == 1) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
626       else if(fIsHeavyIon == 2) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2500,0,2500);
627       else hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",1500,0,1500);
628       fESDList[iCut]->Add(hNV0Tracks[iCut]);
629       
630
631       hEtaShift[iCut] = new TProfile("Eta Shift","Eta Shift",1, -0.5,0.5);
632       fESDList[iCut]->Add(hEtaShift[iCut]);
633
634       hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
635       fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
636       
637       hESDConvGammaEta[iCut] = new TH1F("ESD_ConvGamma_Eta","ESD_ConvGamma_Eta",600,-1.5,1.5);
638       fESDList[iCut]->Add(hESDConvGammaEta[iCut]);
639       
640       hESDDalitzElectronPt[iCut] = new TH1F("ESD_DalitzElectron_Pt","ESD_DalitzElectron_Pt",1000,0,25);
641       fESDList[iCut]->Add(hESDDalitzElectronPt[iCut]);
642
643       hESDDalitzPositronPt[iCut] = new TH1F("ESD_DalitzPositron_Pt","ESD_DalitzPositron_Pt",1000,0,25);
644       fESDList[iCut]->Add(hESDDalitzPositronPt[iCut]);
645       
646       
647       hESDDalitzElectronPhi[iCut] = new TH1F("ESD_DalitzElectron_Phi","ESD_DalitzElectron_Phi",360,0,2*TMath::Pi());
648       fESDList[iCut]->Add(hESDDalitzElectronPhi[iCut]);
649
650       hESDDalitzPositronPhi[iCut] = new TH1F("ESD_DalitzPositron_Phi","ESD_DalitzPositron_Phi",360,0,2*TMath::Pi());
651       fESDList[iCut]->Add(hESDDalitzPositronPhi[iCut]);
652       
653      
654       
655       if ( fDoMesonQA ) {
656
657       fQAFolder[iCut] = new TList();
658       fQAFolder[iCut]->SetName(Form("%s_%s_%s QA histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
659       fQAFolder[iCut]->SetOwner(kTRUE);
660          
661               
662         
663       //const Int_t kDCABins=62;
664       //Double_t binsDCADummy[63]={-3.0,-2.7,-2.4,-2.1,-1.8,-1.5,-1.2,-0.9,-0.6,-0.3,-0.25,-0.2,-0.19,-0.18,-0.17,-0.16,-0.15,-0.14,-0.13,-0.12,-0.11,-0.10,-0.09,-0.08,-0.07,-0.06,-0.05,-0.04,-0.03,-0.02,-0.01,0.0,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.2,0.25,0.3,0.6,0.9,1.2,1.5,1.8,2.1,2.4,2.7,3.0};
665
666       const Int_t kPtBins=110;
667       Double_t binsPtDummy[kPtBins+1];
668       const Int_t kPBins = 109;
669       Double_t binsPDummy[kPBins+1];
670       binsPtDummy[0]=0.0;
671       binsPDummy[0]=0.05;
672      
673         for(Int_t i=1;i<kPtBins+1;i++)
674         {
675                 if(binsPtDummy[i-1]+0.05<1.01)
676                         binsPtDummy[i]=binsPtDummy[i-1]+0.05;
677                 else
678                         binsPtDummy[i]=binsPtDummy[i-1]+0.1;
679                 
680         }
681         for(Int_t i=1; i<kPBins+1;i++){
682                   
683                   if( binsPDummy[i-1]+0.05<1.01)
684                         binsPDummy[i] = binsPDummy[i-1]+0.05;
685                   else
686                         binsPDummy[i] = binsPDummy[i-1]+0.1;
687                 
688         }
689         
690       hNGoodESDTracksVsNGoodGammas[iCut] = new TH2F("hNGoodESDTracksVsNGoodGammas","hNGoodESDTracksVsNGoodGammas",200,-0.5,199.5,100,-0.5,99.5);
691       fQAFolder[iCut]->Add(hNGoodESDTracksVsNGoodGammas[iCut]);
692      
693       hNGoodESDTracksVsNGoodVGammas[iCut] = new TH2F("hNGoodESDTracksVsNVGoodVGammas","hNGoodESDTracksVsNGoodVGammas",200,-0.5,199.5,100,-0.5,99.5);
694       fQAFolder[iCut]->Add(hNGoodESDTracksVsNGoodVGammas[iCut]);
695              
696       hESDConvGammaZR[iCut]= new TH2F("ESD_ConvGamma_ConversionPoint_ZR","ESD_ConvGamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
697       fQAFolder[iCut]->Add(hESDConvGammaZR[iCut]);
698      
699       hESDDalitzElectronAfterPt[iCut] = new TH1F("ESD_DalitzElectron_After_Pt","ESD_DalitzElectron_After_Pt",1000,0,25);
700       fQAFolder[iCut]->Add(hESDDalitzElectronAfterPt[iCut]);
701
702       hESDDalitzPositronAfterPt[iCut] = new TH1F("ESD_DalitzPositron_After_Pt","ESD_DalitzPositron_After_Pt",1000,0,25);
703       fQAFolder[iCut]->Add(hESDDalitzPositronAfterPt[iCut]);
704         
705       hESDDalitzElectronAfterEta[iCut] = new TH1F("ESD_DalitzElectron_After_Eta","ESD_DalitzElectron_After_Eta",600,-1.5,1.5);
706       fQAFolder[iCut]->Add(hESDDalitzElectronAfterEta[iCut]);
707       
708       hESDDalitzPositronAfterEta[iCut] = new TH1F("ESD_DalitzPositron_After_Eta","ESD_DalitzElectron_After_Eta",600,-1.5,1.5);
709       fQAFolder[iCut]->Add(hESDDalitzPositronAfterEta[iCut]);
710       
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       
725       hESDDalitzElectronAfterNFindClsTPC[iCut]  = new TH2F("ESD_DalitzElectron_After_NFindClsTPC","ESD_DalitzElectron_After_NFindClsTPC",60,0,1.5,kPtBins,binsPtDummy);
726       fQAFolder[iCut]->Add(hESDDalitzElectronAfterNFindClsTPC[iCut]);
727       
728       hESDDalitzPositronAfterNFindClsTPC[iCut]  = new TH2F("ESD_DalitzPositron_After_NFindClsTPC","ESD_DalitzPositron_After_NFindClsTPC",60,0,1.5,kPtBins,binsPtDummy);
729       fQAFolder[iCut]->Add(hESDDalitzPositronAfterNFindClsTPC[iCut]);
730       
731       
732       hESDDalitzElectronAfterNClsTPC[iCut]  = new TH2F("ESD_DalitzElectron_After_NClsTPC","ESD_DalitzElectron_After_NClsTPC",200,0,200,kPtBins,binsPtDummy);
733       fQAFolder[iCut]->Add(hESDDalitzElectronAfterNClsTPC[iCut]);
734       
735       hESDDalitzPositronAfterNClsTPC[iCut]  = new TH2F("ESD_DalitzPositron_After_NClsTPC","ESD_DalitzPositron_After_NClsTPC",200,0,200,kPtBins,binsPtDummy);
736       fQAFolder[iCut]->Add(hESDDalitzPositronAfterNClsTPC[iCut]);
737                
738       hESDDalitzPositronAfterNCrossedRowsTPC[iCut] =  new TH2F("ESD_DalitzPositron_After_NCrossedRowsTPC","ESD_DalitzPositron_After_NCrossedRowsTPC",165,-0.5,164.5,kPtBins,binsPtDummy);
739       fQAFolder[iCut]->Add(hESDDalitzPositronAfterNCrossedRowsTPC[iCut]);
740       
741       hESDDalitzElectronAfterNCrossedRowsTPC[iCut] =  new TH2F("ESD_DalitzElectron_After_NCrossedRowsTPC","ESD_DalitzElectron_After_NCrossedRowsTPC",165,-0.5,164.5,kPtBins,binsPtDummy);
742       fQAFolder[iCut]->Add(hESDDalitzElectronAfterNCrossedRowsTPC[iCut]);
743             
744       hESDDalitzPosEleAfterDCAxy[iCut] = new TH2F("ESD_DalitzPosEle_After_DCAxy","ESD_DalitzPosEle_After_DCAxy",124,-0.62,0.62,kPtBins,binsPtDummy);
745       fQAFolder[iCut]->Add(hESDDalitzPosEleAfterDCAxy[iCut]);
746       
747       hESDDalitzPosEleAfterDCAz[iCut]  = new TH2F("ESD_DalitzPosEle_After_DCAz","ESD_DalitzPosEle_After_DCAz",200,-1.0,1.0,kPtBins,binsPtDummy);
748       fQAFolder[iCut]->Add(hESDDalitzPosEleAfterDCAz[iCut]);
749       
750       hESDDalitzElectronAfterTPCdEdxVsP[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsP","ESD_DalitzElectron_After_TPCdEdxVsP_After_TPCdEdx",kPBins,binsPDummy,200,-10,10);
751       fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsP[iCut]);
752       
753       hESDDalitzPositronAfterTPCdEdxVsP[iCut] = new TH2F("ESD_DalitzPositron_After_TPCdEdxVsP","ESD_DalitzPositron_After_TPCdEdxVsP",kPBins,binsPDummy,200,-10,10);
754       fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsP[iCut]);
755       
756       hESDDalitzElectronAfterTPCdEdxSignalVsP[iCut] =new TH2F("ESD_DalitzElectron_After_TPCdEdxSignalVsP","ESD_DalitzElectron_After_TPCdEdxSignalVsP" ,kPBins,binsPDummy,200,0.0,200);
757       fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxSignalVsP[iCut]);  
758       
759       hESDDalitzPositronAfterTPCdEdxSignalVsP[iCut] =new TH2F("ESD_DalitzPositron_After_TPCdEdxSignalVsP","ESD_DalitzPositron_After_TPCdEdxSignalVsP" ,kPBins,binsPDummy,200,0.0,200);
760       fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxSignalVsP[iCut]); 
761       
762       hESDDalitzElectronAfterTPCdEdxVsEta[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsEta","ESD_DalitzElectron_After_TPCdEdxVsEta",140,-1.4,1.4,200,-10,10);
763       fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsEta[iCut]);
764       
765       hESDDalitzPositronAfterTPCdEdxVsEta[iCut] = new  TH2F("ESD_DalitzPositron_After_TPCdEdxVsEta","ESD_DalitzPositron_After_TPCdEdxVsEta",140,-1.4,1.4,200,-10,10);
766       fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsEta[iCut]);
767       
768       hESDDalitzElectronAfterTPCdEdxVsPhi[iCut] = new TH2F("ESD_DalitzElectron_After_TPCdEdxVsPhi","ESD_DalitzElectron_After_TPCdEdxVsPhi",180,0,2*TMath::Pi(),200,-10,10);
769       fQAFolder[iCut]->Add(hESDDalitzElectronAfterTPCdEdxVsPhi[iCut]);
770       
771       hESDDalitzPositronAfterTPCdEdxVsPhi[iCut] = new TH2F("ESD_DalitzPositron_After_TPCdEdxVsPhi","ESD_DalitzPositron_After_TPCdEdxVsPhi",180,0,2*TMath::Pi(),200,-10,10);
772       fQAFolder[iCut]->Add(hESDDalitzPositronAfterTPCdEdxVsPhi[iCut]);
773             
774       hESDMotherPhi[iCut] = new TH1F("ESD_DalitzMother_Phi","ESD_DalitzMother_Phi",360,0,2*TMath::Pi());
775       fQAFolder[iCut]->Add(hESDMotherPhi[iCut]);
776       
777       hESDEposEnegPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_PsiPair_DPhi","ESD_EposEneg_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
778       fQAFolder[iCut]->Add(hESDEposEnegPsiPairDPhi[iCut]);
779
780       hESDEposEnegInvMassPt[iCut] = new TH2F("ESD_EposEneg_InvMassPt","ESD_EposEneg_InvMassPt",4000,0.0,2.0,100,0.,10.);
781       fQAFolder[iCut]->Add(hESDEposEnegInvMassPt[iCut]);
782       
783       hESDEposEnegAfterMassCutInvMassPi0Pt[iCut] = new TH2F("ESD_EposEneg_AfterMassCut_InvMassPi0Pt","ESD_EposEneg_AfterMassCut_InvMassPi0Pt",4000,0.0,2.0,100,0.,10.);
784       fQAFolder[iCut]->Add(hESDEposEnegAfterMassCutInvMassPi0Pt[iCut]);
785       
786       hESDEposEnegLikeSignBackInvMassPt[iCut]  = new TH2F("ESD_EposEneg_LikeSignBack_InvMassPt","ESD_EposEneg_LikeSignBack_InvMassPt",4000,0.0,2.,100,0.,10.);
787       fQAFolder[iCut]->Add(hESDEposEnegLikeSignBackInvMassPt[iCut]);
788       
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       
810
811       delete [] newBins;
812       
813       
814       /*TAxis *MassAxisAfter = hESDEposEnegInvMassPt[iCut]->GetXaxis(); 
815       bins = MassAxisAfter->GetNbins();
816       
817       from = MassAxisAfter->GetXmin();
818       to   = MassAxisAfter->GetXmax();
819       Double_t *MassnewBins = new Double_t[bins+1];
820       MassnewBins[0] = from;
821       
822      // cout<<"from: "<<from<<"to: "<<to<<endl;
823       factor = TMath::Power(to/from, 1./bins);
824       
825       for(Int_t i=1; i<=bins; ++i) MassnewBins[i] = factor * MassnewBins[i-1];
826       
827       
828       MassAxisAfter->Set(bins,MassnewBins);
829       
830       
831       MassAxisAfter = hESDEposEnegLikeSignBackInvMassPt[iCut]->GetXaxis();
832       MassAxisAfter->Set(bins,MassnewBins);
833       
834       
835       delete [] MassnewBins;*/
836       
837       
838       
839       
840      
841       
842       
843       
844       fCutFolder[iCut]->Add(fQAFolder[iCut]);
845       
846            
847       
848       }
849       
850       
851              
852      
853
854       hESDMotherInvMassPt[iCut] = new TH2F("ESD_DalitzMother_InvMass_Pt","ESD_DalitzMother_InvMass_Pt",800,0,0.8,250,0,25);
855       fESDList[iCut]->Add(hESDMotherInvMassPt[iCut]);
856                                                                                   
857        
858       if( fDoChicAnalysis) {
859                   
860       hESDPi0MotherInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_InvMass_Pt","ESD_Pi0Mother_InvMass_Pt",4000,0,4,250,0,25);
861       fESDList[iCut]->Add(hESDPi0MotherInvMassPt[iCut]);
862   
863       hESDPi0MotherDiffInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffInvMass_Pt","ESD_Pi0Mother_DiffInvMass_Pt",2000,0,2,250,0,25);
864       fESDList[iCut]->Add(hESDPi0MotherDiffInvMassPt[iCut]);
865
866       hESDPi0MotherDiffLimInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffLimInvMass_Pt","ESD_Pi0Mother_DiffLimInvMass_Pt",2000,0,2,250,0,25);
867       fESDList[iCut]->Add(hESDPi0MotherDiffLimInvMassPt[iCut]);
868       
869       }
870
871
872       hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_DalitzBackground_InvMass_Pt","ESD_DalitzBackground_InvMass_Pt",800,0,0.8,250,0,25);
873       fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
874
875            
876       
877       fCutFolder[iCut]->Add(fESDList[iCut]);
878       
879       
880
881    }
882
883
884    InitBack(); // Init Background Handler
885
886
887    //if(MCEvent()){
888     if( fIsMC ){
889       // MC Histogramms
890       fMCList = new TList*[fnCuts];
891       // True Histogramms
892       fTrueList = new TList*[fnCuts];
893       hESDTrueConvGammaPt = new TH1F*[fnCuts];
894       hESDTruePositronPt  = new TH1F*[fnCuts];
895       hESDTrueElectronPt  = new TH1F*[fnCuts];
896       hESDTrueSecConvGammaPt = new TH1F*[fnCuts];
897       hESDTrueSecPositronPt  = new TH1F*[fnCuts];
898       hESDTrueSecElectronPt  = new TH1F*[fnCuts];
899       hESDTruePi0DalitzConvGammaPt = new TH1F*[fnCuts];
900       hESDTruePi0DalitzPositronPt  = new TH1F*[fnCuts];
901       hESDTruePi0DalitzElectronPt  = new TH1F*[fnCuts];
902       hESDTruePi0DalitzSecConvGammaPt = new TH1F*[fnCuts];
903       hESDTruePi0DalitzSecPositronPt  = new TH1F*[fnCuts];
904       hESDTruePi0DalitzSecElectronPt  = new TH1F*[fnCuts];
905       //if(fDoMesonAnalysis){
906       hMCAllGammaPt  = new TH1F*[fnCuts];
907       hMCConvGammaPt = new TH1F*[fnCuts];
908       hMCConvGammaRSPt = new TH1F*[fnCuts];
909       hMCAllPositronsPt = new TH1F*[fnCuts];
910       hMCAllElectronsPt = new TH1F*[fnCuts];
911       
912       if( fDoMesonQA ) {
913
914         hMCConvGammaEta    = new TH1F*[fnCuts];
915         hMCAllPositronsEta = new TH1F*[fnCuts];
916         hMCAllElectronsEta = new TH1F*[fnCuts];
917         
918       }
919       hMCPi0DalitzGammaPt    = new TH1F*[fnCuts];
920       hMCPi0DalitzElectronPt = new TH1F*[fnCuts];
921       hMCPi0DalitzPositronPt = new TH1F*[fnCuts];
922  
923       hMCPi0Pt = new TH1F*[fnCuts];
924       hMCPi0GGPt =  new TH1F*[fnCuts];
925       hMCEtaPt = new TH1F*[fnCuts];
926       hMCEtaGGPt = new TH1F*[fnCuts];
927       hMCPi0InAccPt = new TH1F*[fnCuts];
928       hMCEtaInAccPt = new TH1F*[fnCuts];
929                         hMCChiCPt = new TH1F*[fnCuts];
930                         hMCChiCInAccPt = new TH1F*[fnCuts];
931                         
932                         
933       if ( fDoMesonQA ) {
934         
935         hMCPi0EposEnegInvMassPt                      = new TH2F*[fnCuts];       
936         hMCEtaEposEnegInvMassPt                      = new TH2F*[fnCuts];
937         
938         hESDEposEnegTruePi0DalitzInvMassPt           = new TH2F*[fnCuts];
939         hESDEposEnegTruePrimPi0DalitzInvMass         = new TH1F*[fnCuts];
940         hESDEposEnegTruePi0DalitzPsiPairDPhi         = new TH2F*[fnCuts];
941         hESDEposEnegTrueEtaDalitzInvMassPt           = new TH2F*[fnCuts];
942         hESDEposEnegTruePrimEtaDalitzInvMass         = new TH1F*[fnCuts];
943         hESDEposEnegTrueEtaDalitzPsiPairDPhi         = new TH2F*[fnCuts];
944         hESDEposEnegTruePhotonInvMassPt              = new TH2F*[fnCuts];
945         hESDEposEnegTrueInvMassPt                    = new TH2F*[fnCuts];
946         hESDEposEnegTruePhotonPsiPairDPhi            = new TH2F*[fnCuts];
947         hESDEposEnegTruePhotonPsiPairDPhiPtCut       = new TH2F*[fnCuts];
948         hESDEposEnegTrueJPsiInvMassPt                = new TH2F*[fnCuts];
949       }
950       
951       
952       if( fDoChicAnalysis ){
953       hESDTrueMotherChiCInvMassPt = new TH2F*[fnCuts];
954       hESDTrueMotherChiCDiffInvMassPt = new TH2F*[fnCuts];
955       }
956       
957       
958       hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
959       hESDTrueMotherDalitzInvMassPt = new TH2F*[fnCuts];
960       hESDTrueMotherPi0GGInvMassPt = new TH2F*[fnCuts];
961       hESDTruePrimaryMotherPi0GGInvMassPt = new TH2F*[fnCuts];
962       hESDTrueSecondaryMotherPi0GGInvMassPt = new TH2F*[fnCuts];
963       hESDTruePrimaryPi0DalitzESDPtMCPt = new TH2F*[fnCuts];
964       hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
965       hESDTruePrimaryMotherInvMassPt   = new TH2F*[fnCuts];
966       hESDTruePrimaryMotherW0WeightingInvMassPt = new TH2F*[fnCuts];
967       hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
968       hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
969       hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
970       hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
971       hESDTrueMotherGGInvMassPt = new TH2F*[fnCuts];
972       //}
973
974       for(Int_t iCut = 0; iCut<fnCuts;iCut++){
975          TString cutstringElectron =((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
976          TString cutstringMeson= ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
977          TString cutstringGamma = ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
978
979          fMCList[iCut] = new TList();
980          fMCList[iCut]->SetName(Form("%s_%s_%s MC histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
981          fMCList[iCut]->SetOwner(kTRUE);
982          fCutFolder[iCut]->Add(fMCList[iCut]);
983
984
985         hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
986         fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
987         
988         hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
989         fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
990         
991         
992         hMCConvGammaRSPt[iCut] = new TH1F("MC_ConvGamma_RS_Pt","MC_ConvGamma_RS_Pt",250,0,25);
993         fMCList[iCut]->Add(hMCConvGammaRSPt[iCut]);
994         
995                                  
996         hMCAllPositronsPt[iCut] = new TH1F("MC_AllPositrons_Pt","MC_AllPositrons_Pt",1000,0,25);
997         fMCList[iCut]->Add(hMCAllPositronsPt[iCut]);
998                                  
999                                  hMCAllElectronsPt[iCut] = new TH1F("MC_AllElectrons_Pt","MC_AllElectrons_Pt",1000,0,25);
1000                                  fMCList[iCut]->Add(hMCAllElectronsPt[iCut]);
1001                                  
1002                                  hMCPi0DalitzGammaPt[iCut] = new TH1F("MC_Pi0DalitzGamma_Pt","MC_Pi0DalitzGamma_Pt",250,0,25);
1003                                  hMCPi0DalitzGammaPt[iCut]->Sumw2();
1004                                  fMCList[iCut]->Add(hMCPi0DalitzGammaPt[iCut]);
1005                                  
1006                                  if ( fDoMesonQA ){
1007                                   
1008                                   hMCConvGammaEta[iCut] = new TH1F("MC_ConvGamma_Eta","MC_ConvGamma_Eta",600,-1.5,1.5);
1009                                   fMCList[iCut]->Add(hMCConvGammaEta[iCut]);
1010          
1011                                   hMCAllPositronsEta[iCut] = new TH1F("MC_AllPositrons_Eta","MC_AllPositrons_Eta",600,-1.5,1.5);
1012                                   fMCList[iCut]->Add(hMCAllPositronsEta[iCut]);
1013                                  
1014                                   hMCAllElectronsEta[iCut] = new TH1F("MC_AllElectrons_Eta","MC_AllElectrons_Eta",600,-1.5,1.5);
1015                                   fMCList[iCut]->Add(hMCAllElectronsEta[iCut]);
1016                                  
1017                                  
1018                                  }
1019                                  
1020                                  
1021                                  hMCPi0DalitzPositronPt[iCut] = new TH1F("MC_Pi0DalitzPositron_Pt","MC_Pi0DalitzPositron_Pt",1000,0,25);
1022                                  hMCPi0DalitzPositronPt[iCut]->Sumw2();
1023                                  fMCList[iCut]->Add(hMCPi0DalitzPositronPt[iCut]);
1024                                  
1025                                  hMCPi0DalitzElectronPt[iCut] = new TH1F("MC_Pi0DalitzElectron_Pt","MC_Pi0DalitzElectron_Pt",1000,0,25);
1026                                  hMCPi0DalitzElectronPt[iCut]->Sumw2();
1027                                  fMCList[iCut]->Add(hMCPi0DalitzElectronPt[iCut]);
1028                                  
1029                                  
1030                                  hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
1031                                  hMCPi0Pt[iCut]->Sumw2();
1032                                  fMCList[iCut]->Add(hMCPi0Pt[iCut]);
1033                                  
1034                                  hMCPi0GGPt[iCut] = new TH1F("MC_Pi0_GG_Pt","MC_Pi0_GG_Pt",250,0,25);
1035                                  hMCPi0GGPt[iCut]->Sumw2();
1036                                  fMCList[iCut]->Add(hMCPi0GGPt[iCut]);
1037                                  
1038                                  hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
1039                                  hMCEtaPt[iCut]->Sumw2();
1040                                  fMCList[iCut]->Add(hMCEtaPt[iCut]);
1041
1042                                  hMCEtaGGPt[iCut] = new TH1F("MC_Eta_GG_Pt","MC_Eta_GG_Pt",250,0,25);
1043                                  hMCEtaGGPt[iCut]->Sumw2();
1044                                  fMCList[iCut]->Add(hMCEtaGGPt[iCut]);
1045                                  
1046                                  hMCPi0InAccPt[iCut] = new TH1F("MC_Pi0DalitzInAcc_Pt","MC_Pi0DalitzInAcc_Pt",250,0,25);
1047                                  hMCPi0InAccPt[iCut]->Sumw2();
1048                                  fMCList[iCut]->Add(hMCPi0InAccPt[iCut]);
1049
1050                                  hMCEtaInAccPt[iCut] = new TH1F("MC_EtaDalitzInAcc_Pt","MC_EtaDalitzInAcc_Pt",250,0,25);
1051                                  hMCEtaInAccPt[iCut]->Sumw2();
1052                                  fMCList[iCut]->Add(hMCEtaInAccPt[iCut]);
1053                                  
1054                                 
1055
1056                                  hMCChiCPt[iCut] = new TH1F("MC_ChiC_Pt","MC_ChiC_Pt",250,0,25);
1057                                  fMCList[iCut]->Add(hMCChiCPt[iCut]);
1058
1059                                  hMCChiCInAccPt[iCut] = new TH1F("MC_ChiCInAcc_Pt","MC_ChiCInAcc_Pt",250,0,25);
1060                                  fMCList[iCut]->Add(hMCChiCInAccPt[iCut]);
1061                                  
1062                                   if ( fDoMesonQA ) {
1063
1064                                   hMCPi0EposEnegInvMassPt[iCut] = new TH2F("MC_Pi0EposEneg_InvMassPt","MC_Pi0EposEneg_InvMassPt",1000,0.0,0.5,100,0.,10.);
1065                                   fMCList[iCut]->Add(hMCPi0EposEnegInvMassPt[iCut]);
1066
1067                                   hMCEtaEposEnegInvMassPt[iCut] = new TH2F("MC_EtaEposEneg_InvMassPt","MC_EtaEposEneg_InvMassPt",1400,0.,0.7,100,0.,10.);
1068                                   fMCList[iCut]->Add(hMCEtaEposEnegInvMassPt[iCut]);
1069                                   
1070                                   
1071                                   
1072                                   /*TAxis *MassMCAxisAfter = hMCPi0EposEnegInvMassPt[iCut]->GetXaxis(); 
1073                                   Int_t bins = MassMCAxisAfter->GetNbins();
1074                                   Double_t from = MassMCAxisAfter->GetXmin();
1075                                   Double_t to   = MassMCAxisAfter->GetXmax();
1076                                   Double_t *MassMCnewBins = new Double_t[bins+1];
1077                                   MassMCnewBins[0] = from;
1078                                   Double_t factor = TMath::Power(to/from, 1./bins);
1079       
1080                                   for(Int_t i=1; i<=bins; ++i) MassMCnewBins[i] = factor * MassMCnewBins[i-1];
1081                                   MassMCAxisAfter->Set(bins,MassMCnewBins);
1082                                   //MassMCAxisAfter = hMCEtaEposEnegInvMassPt[iCut]->GetXaxis();
1083                                   //MassMCAxisAfter->Set(bins,MassMCnewBins);
1084                                   delete [] MassMCnewBins;*/
1085       
1086                                   
1087                                   
1088                                   
1089                                   
1090                                   
1091                                   }
1092                                  
1093                                  
1094
1095          fTrueList[iCut] = new TList();
1096          fTrueList[iCut]->SetName(Form("%s_%s_%s True histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
1097          fTrueList[iCut]->SetOwner(kTRUE);
1098          fCutFolder[iCut]->Add(fTrueList[iCut]);
1099
1100          if ( fDoMesonQA ) {
1101
1102
1103          hESDEposEnegTruePi0DalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_InvMassPt","ESD_EposEneg_TruePi0Dalitz_InvMassPt",1000,0.0,0.5,100,0.,10.);
1104          fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzInvMassPt[iCut]);
1105          
1106          hESDEposEnegTruePrimPi0DalitzInvMass[iCut] = new TH1F("ESD_EposEneg_TruePrimPi0Dalitz_InvMass","ESD_EposEneg_TruePrimPi0Dalitz_InvMass",500,0.,0.5);
1107          fTrueList[iCut]->Add(hESDEposEnegTruePrimPi0DalitzInvMass[iCut]);
1108
1109          hESDEposEnegTruePi0DalitzPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_PsiPair_DPhi","ESD_EposEneg_TruePi0Dalitz_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1110          fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzPsiPairDPhi[iCut]);
1111
1112          
1113          hESDEposEnegTrueEtaDalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_InvMassPt","ESD_EposEneg_TrueEtaDalitz_InvMassPt",700,0.,0.7,100,0.,10.);
1114          fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzInvMassPt[iCut]);
1115          
1116          hESDEposEnegTruePrimEtaDalitzInvMass[iCut] = new TH1F("ESD_EposEneg_TruePrimEtaDalitz_InvMass","ESD_EposEneg_TruePrimEtaDalitz_InvMass",700,0.,0.7);
1117          fTrueList[iCut]->Add(hESDEposEnegTruePrimEtaDalitzInvMass[iCut]);
1118
1119          hESDEposEnegTrueEtaDalitzPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_PsiPair_DPhi","ESD_EposEneg_TrueEtaDalitz_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1120          fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzPsiPairDPhi[iCut]);
1121          
1122          hESDEposEnegTruePhotonInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePhoton_InvMassPt","ESD_EposEneg_TruePhoton_InvMassPt",500,0.,0.5,100,0.,10.);
1123          fTrueList[iCut]->Add(hESDEposEnegTruePhotonInvMassPt[iCut]);
1124          
1125          hESDEposEnegTrueInvMassPt[iCut] = new TH2F("ESD_EposEneg_True_InvMassPt","ESD_EposEneg_True_InvMassPt",5000,0.,5.,100,0.,10.);
1126          fTrueList[iCut]->Add(hESDEposEnegTrueInvMassPt[iCut]);
1127         
1128          hESDEposEnegTruePhotonPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_TruePhoton_PsiPair_DPhi","ESD_EposEneg_TruePhoton_PsiPair_DPhi", 100, -1.0,1.0,100,-1.0,1.0 );
1129          fTrueList[iCut]->Add(hESDEposEnegTruePhotonPsiPairDPhi[iCut]);
1130          
1131          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 );
1132          fTrueList[iCut]->Add(hESDEposEnegTruePhotonPsiPairDPhiPtCut[iCut]);
1133          
1134          
1135  
1136          hESDEposEnegTrueJPsiInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueJPsi_InvMassPt","ESD_EposEneg_TrueJPsi_InvMassPt",5000,0.,5.,100,0.,10.);
1137          fTrueList[iCut]->Add(hESDEposEnegTrueJPsiInvMassPt[iCut]);
1138          
1139          
1140          
1141          /*TAxis *MassTrueAxisAfter = hESDEposEnegTruePi0DalitzInvMassPt[iCut]->GetXaxis(); 
1142          Int_t bins = MassTrueAxisAfter->GetNbins();
1143          Double_t from = MassTrueAxisAfter->GetXmin();
1144          Double_t to   = MassTrueAxisAfter->GetXmax();
1145          Double_t *MassMCnewBins = new Double_t[bins+1];
1146          
1147          MassMCnewBins[0] = from;
1148          Double_t factor = TMath::Power(to/from, 1./bins);
1149       
1150          for(Int_t i=1; i<=bins; ++i) MassMCnewBins[i] = factor * MassMCnewBins[i-1];
1151          MassTrueAxisAfter->Set(bins,MassMCnewBins);
1152          //MassTrueAxisAfter = hMCEtaEposEnegInvMassPt[iCut]->GetXaxis();
1153          //MassTrueAxisAfter->Set(bins,MassMCnewBins);
1154         
1155          delete [] MassMCnewBins;*/
1156
1157
1158
1159          }
1160
1161
1162          hESDTruePositronPt[iCut] = new TH1F("ESD_TruePositron_Pt","ESD_TruePositron_Pt",1000,0,25);
1163          fTrueList[iCut]->Add(hESDTruePositronPt[iCut]);
1164
1165          hESDTrueElectronPt[iCut] = new TH1F("ESD_TrueElectron_Pt","ESD_TrueElectron_Pt",1000,0,25);
1166          fTrueList[iCut]->Add(hESDTrueElectronPt[iCut]);
1167          
1168          hESDTrueSecPositronPt[iCut] = new TH1F("ESD_TrueSecPositron_Pt","ESD_TrueSecPositron_Pt",1000,0,25);
1169          fTrueList[iCut]->Add(hESDTrueSecPositronPt[iCut]);
1170
1171          hESDTrueSecElectronPt[iCut] = new TH1F("ESD_TrueSecElectron_Pt","ESD_TrueSecElectron_Pt",1000,0,25);
1172          fTrueList[iCut]->Add(hESDTrueSecElectronPt[iCut]); 
1173
1174          hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
1175          fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
1176          
1177          hESDTrueSecConvGammaPt[iCut] = new TH1F("ESD_TrueSecConvGamma_Pt","ESD_TrueSecConvGamma_Pt",250,0,25);
1178          fTrueList[iCut]->Add(hESDTrueSecConvGammaPt[iCut]);
1179
1180          hESDTruePi0DalitzConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzConvGamma_Pt","ESD_TruePi0DalitzConvGamma_Pt",250,0,25);
1181          fTrueList[iCut]->Add(hESDTruePi0DalitzConvGammaPt[iCut]);
1182
1183          hESDTruePi0DalitzElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzElectron_Pt","ESD_TruePi0DalitzElectron_Pt",1000,0,25);
1184          fTrueList[iCut]->Add(hESDTruePi0DalitzElectronPt[iCut]);
1185
1186          hESDTruePi0DalitzPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzPositron_Pt","ESD_TruePi0DalitzPositron_Pt",1000,0,25);
1187          fTrueList[iCut]->Add(hESDTruePi0DalitzPositronPt[iCut]);
1188          
1189          hESDTruePi0DalitzSecConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzSecConvGamma_Pt","ESD_TruePi0DalitzSecConvGamma_Pt",250,0,25);
1190          fTrueList[iCut]->Add(hESDTruePi0DalitzSecConvGammaPt[iCut]);
1191          
1192          hESDTruePi0DalitzSecElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecElectron_Pt","ESD_TruePi0DalitzSecElectron_Pt",1000,0,25);
1193          fTrueList[iCut]->Add(hESDTruePi0DalitzSecElectronPt[iCut]);
1194
1195          hESDTruePi0DalitzSecPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecPositron_Pt","ESD_TruePi0DalitzSecPositron_Pt",1000,0,25);
1196          fTrueList[iCut]->Add(hESDTruePi0DalitzSecPositronPt[iCut]);
1197
1198          if( fDoChicAnalysis) { 
1199            
1200          hESDTrueMotherChiCInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiC_InvMass_Pt","ESD_TrueMotherChiC_InvMass_Pt",4000,0,4,250,0,25);
1201          fTrueList[iCut]->Add(hESDTrueMotherChiCInvMassPt[iCut]);
1202
1203          hESDTrueMotherChiCDiffInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiCDiff_InvMass_Pt","ESD_TrueMotherChiCDiff_InvMass_Pt",2000,0,2,250,0,25);
1204          fTrueList[iCut]->Add(hESDTrueMotherChiCDiffInvMassPt[iCut]);
1205          
1206          }
1207
1208          hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",800,0,0.8,250,0,25);
1209          hESDTrueMotherInvMassPt[iCut]->Sumw2();
1210          fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
1211          
1212          hESDTrueMotherDalitzInvMassPt[iCut] = new TH2F("ESD_TrueMother_Dalitz_InvMass_Pt","ESD_TrueMother_Dalitz_InvMass_Pt",800,0,0.8,250,0,25);
1213          hESDTrueMotherDalitzInvMassPt[iCut]->Sumw2();
1214          fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPt[iCut]);
1215          
1216          
1217          
1218          
1219
1220          hESDTrueMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TrueMotherPi0GG_InvMass_Pt","ESD_TrueMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1221          hESDTrueMotherPi0GGInvMassPt[iCut]->Sumw2();
1222          fTrueList[iCut]->Add(hESDTrueMotherPi0GGInvMassPt[iCut]);
1223
1224          hESDTruePrimaryMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMotherPi0GG_InvMass_Pt","ESD_TruePrimaryMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1225          hESDTruePrimaryMotherPi0GGInvMassPt[iCut]->Sumw2();
1226          fTrueList[iCut]->Add(hESDTruePrimaryMotherPi0GGInvMassPt[iCut]);
1227
1228          hESDTrueSecondaryMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryMotherPi0GG_InvMass_Pt","ESD_TrueSecondaryMotherPi0GG_InvMass_Pt",800,0,0.8,250,0,25);
1229          hESDTrueSecondaryMotherPi0GGInvMassPt[iCut]->Sumw2();
1230          fTrueList[iCut]->Add(hESDTrueSecondaryMotherPi0GGInvMassPt[iCut]);
1231
1232          hESDTruePrimaryPi0DalitzESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt","ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt",250,0,25,250,0,25);
1233          hESDTruePrimaryPi0DalitzESDPtMCPt[iCut]->Sumw2();
1234          fTrueList[iCut]->Add(hESDTruePrimaryPi0DalitzESDPtMCPt[iCut]);
1235          hESDTruePrimaryMotherInvMassMCPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt","ESD_TrueDalitzPrimaryMother_InvMass_MCPt",800,0,0.8,250,0,25);
1236          hESDTruePrimaryMotherInvMassMCPt[iCut]->Sumw2();
1237          fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
1238          hESDTruePrimaryMotherInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_Pt","ESD_TruePrimaryMother_InvMass_Pt",800,0,0.8,250,0,25);
1239          hESDTruePrimaryMotherInvMassPt[iCut]->Sumw2();
1240          fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassPt[iCut]);
1241          hESDTruePrimaryMotherW0WeightingInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMotherW0Weighting_InvMass_Pt","ESD_TruePrimaryMotherW0Weighting_InvMass_Pt",800,0,0.8,250,0,25);
1242          hESDTruePrimaryMotherW0WeightingInvMassPt[iCut]->Sumw2();
1243          fTrueList[iCut]->Add(hESDTruePrimaryMotherW0WeightingInvMassPt[iCut]); 
1244
1245          hESDTrueSecondaryMotherInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMother_InvMass_Pt","ESD_TrueDalitzSecondaryMother_InvMass_Pt",800,0,0.8,250,0,25);
1246          hESDTrueSecondaryMotherInvMassPt[iCut]->Sumw2();
1247          fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
1248          //                             hESDTrueSecondaryMotherFromK0sInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt",1000,0,1,250,0,25);
1249          //                             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
1250          hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckGG_InvMass_Pt","ESD_TrueDalitzBckGG_InvMass_Pt",800,0,0.8,250,0,25);
1251          fTrueList[iCut]->Add(hESDTrueBckGGInvMassPt[iCut]);
1252          hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckCont_InvMass_Pt","ESD_TrueDalitzBckCont_InvMass_Pt",800,0,0.8,250,0,25);
1253          fTrueList[iCut]->Add(hESDTrueBckContInvMassPt[iCut]);
1254          //                             hESDTrueMotherGGInvMassPt[iCut] = new TH2F("ESD_TrueGammaGamma_InvMass_Pt","ESD_TrueGammaGamma_InvMass_Pt",1000,0,1,250,0,25);
1255          //                             fTrueList[iCut]->Add(hESDTrueMotherGGInvMassPt[iCut]);
1256
1257       }
1258    }
1259    
1260    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
1261    if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
1262      
1263    if(fV0Reader)
1264       if((AliConversionCuts*)fV0Reader->GetConversionCuts())
1265          if(((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms())
1266             fOutputContainer->Add(((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
1267          
1268          
1269          
1270    fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
1271    if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
1272      
1273     if( fElecSelector ){
1274
1275       if ( ((AliDalitzElectronCuts*)fElecSelector->GetDalitzElectronCuts())->GetCutHistograms() ){
1276          fOutputContainer->Add( ((AliDalitzElectronCuts*)fElecSelector->GetDalitzElectronCuts())->GetCutHistograms() );
1277       }
1278    }  
1279
1280    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1281
1282       if( fCutElectronArray ){
1283          if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() ) {
1284             fCutFolder[iCut]->Add( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() );
1285          }
1286       }
1287
1288       if( fCutMesonArray  ) {
1289          if( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms() ) {
1290             fCutFolder[iCut]->Add( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms());
1291          }
1292       }
1293
1294       if( fCutGammaArray ) {
1295          if( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutHistograms() ) {
1296             fCutFolder[iCut]->Add( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutHistograms()  );
1297          }
1298       }
1299    }
1300
1301    PostData(1, fOutputContainer);
1302
1303 }
1304
1305 //______________________________________________________________________
1306 void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
1307 {
1308
1309    //
1310    // Execute analysis for current event
1311    //
1312
1313    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
1314    if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
1315
1316
1317    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
1318
1319    if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
1320         for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1321            hNEvents[iCut]->Fill(eventQuality);
1322         }
1323       return;
1324    }
1325
1326
1327    fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
1328    if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
1329
1330
1331    if(fIsMC)          fMCEvent        =  MCEvent();
1332    fESDEvent        = (AliESDEvent*)InputEvent();
1333    fReaderGammas    = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
1334    fSelectorElectronIndex = fElecSelector->GetReconstructedElectronsIndex(); // Electrons from default Cut
1335    fSelectorPositronIndex = fElecSelector->GetReconstructedPositronsIndex(); // Positrons from default Cut
1336
1337    CountESDTracks(); // Estimate Event Multiplicity
1338    fNumberOfESDTracks = fV0Reader->GetNumberOfPrimaryTracks();
1339    //AddTaskContainers(); //Add conatiner
1340
1341    for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1342       fiCut = iCut;
1343
1344       Int_t eventNotAccepted =
1345          ((AliConversionCuts*)fCutGammaArray->At(iCut))
1346          ->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
1347          
1348       if(eventNotAccepted){
1349          //                     cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
1350          hNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
1351          continue;
1352       }
1353
1354       if(eventQuality != 0){// Event Not Accepted
1355          //                     cout << "event rejected due to: " <<eventQuality << endl;
1356          hNEvents[iCut]->Fill(eventQuality);
1357          continue;
1358       }
1359
1360       hNEvents[iCut]->Fill(eventQuality);
1361
1362       hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
1363       
1364       if(((AliConversionCuts*)fCutGammaArray->At(iCut))->IsHeavyIon() == 2) hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A());
1365       else hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
1366
1367
1368       if(fMCEvent){ // Process MC Particle
1369          
1370         
1371         
1372         fMCStack = fMCEvent->Stack();
1373          
1374           if(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetSignalRejection() != 0){
1375              ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetSignalRejection(),
1376                                                                                      ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetAcceptedHeader(),
1377                                                                                        fMCEvent);
1378           } 
1379          
1380          ProcessMCParticles();
1381       }
1382
1383       ProcessPhotonCandidates(); // Process this cuts gammas
1384       ProcessElectronCandidates(); // Process this cuts gammas
1385       
1386       if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1387         
1388             fUnsmearedPx = new Double_t[fGoodGammas->GetEntries()]; // Store unsmeared Momenta
1389             fUnsmearedPy = new Double_t[fGoodGammas->GetEntries()];
1390             fUnsmearedPz = new Double_t[fGoodGammas->GetEntries()];
1391             fUnsmearedE =  new Double_t[fGoodGammas->GetEntries()];
1392
1393             for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
1394               
1395                fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Px();
1396                fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Py();
1397                fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Pz();
1398                fUnsmearedE[gamma] =  ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->E();
1399                ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(gamma)));
1400                
1401             }           
1402        }
1403        
1404        if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetUseVPhotonMCPmearing() && ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1405          
1406             cout<<"Entro virtual photon smearing"<<endl;
1407         
1408             fUnsmearedVPx = new Double_t[fGoodVirtualGammas->GetEntries()]; // Store unsmeared Momenta
1409             fUnsmearedVPy = new Double_t[fGoodVirtualGammas->GetEntries()];
1410             fUnsmearedVPz = new Double_t[fGoodVirtualGammas->GetEntries()];
1411             fUnsmearedVE =  new Double_t[fGoodVirtualGammas->GetEntries()];
1412
1413             for(Int_t Vgamma=0;Vgamma<fGoodVirtualGammas->GetEntries();Vgamma++){ // Smear the AODPhotons in MC
1414               
1415                fUnsmearedVPx[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Px();
1416                fUnsmearedVPy[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Py();
1417                fUnsmearedVPz[Vgamma] = ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->Pz();
1418                fUnsmearedVE[Vgamma] =  ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->E();
1419                ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(Vgamma)));
1420                
1421             }           
1422        }
1423        
1424       ProcessVirtualGammasCandidates();
1425       CalculatePi0DalitzCandidates();
1426       CalculateBackground();
1427       UpdateEventByEventData();
1428       
1429       if ( fDoMesonQA ) {
1430         
1431       hNGoodESDTracksVsNGoodGammas[iCut]->Fill(fNumberOfESDTrackskBoth,fGoodGammas->GetEntries());
1432       hNGoodESDTracksVsNGoodVGammas[iCut]->Fill(fNumberOfESDTrackskBoth,fGoodVirtualGammas->GetEntries());
1433       
1434       
1435       }
1436       
1437       
1438       if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1439         
1440            for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
1441                ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
1442                ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPy(fUnsmearedPy[gamma]);
1443                ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPz(fUnsmearedPz[gamma]);
1444                ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetE(fUnsmearedE[gamma]);
1445             }
1446             delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
1447             delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
1448             delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
1449             delete[] fUnsmearedE;  fUnsmearedE  = 0x0;
1450             
1451       }
1452        
1453        if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetUseVPhotonMCPmearing() && ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
1454         
1455            for(Int_t Vgamma=0;Vgamma<fGoodVirtualGammas->GetEntries();Vgamma++){ // Smear the AODPhotons in MC
1456                ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPx(fUnsmearedVPx[Vgamma]); // Reset Unsmeared Momenta
1457                ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPy(fUnsmearedVPy[Vgamma]);
1458                ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetPz(fUnsmearedVPz[Vgamma]);
1459                ((AliAODConversionPhoton*)fGoodVirtualGammas->At(Vgamma))->SetE(fUnsmearedVE[Vgamma]);
1460             }
1461             
1462              //cout<<"Entro virtual photon smearing2"<<endl;
1463             
1464             delete[] fUnsmearedVPx; fUnsmearedVPx = 0x0;
1465             delete[] fUnsmearedVPy; fUnsmearedVPy = 0x0;
1466             delete[] fUnsmearedVPz; fUnsmearedVPz = 0x0;
1467             delete[] fUnsmearedVE;  fUnsmearedVE  = 0x0;
1468             
1469        }
1470
1471      
1472
1473       fGoodGammas->Clear(); // delete this cuts good gammas
1474       fGoodVirtualGammas->Clear(); // delete this cuts good gammas
1475    }
1476
1477    fSelectorElectronIndex.clear();
1478    fSelectorPositronIndex.clear();
1479
1480    PostData( 1, fOutputContainer );
1481 }
1482
1483 Bool_t AliAnalysisTaskGammaConvDalitzV1::Notify()
1484 {
1485    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1486       
1487
1488       if( !((AliConversionCuts*)fCutGammaArray->At(iCut))->GetDoEtaShift() ){
1489
1490          /*if (((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() != 0.){
1491             printf("Error: Gamma Conversion Dalitz Task %s :: Eta Shift not requested but set to %f, reset to 00. \n\n",
1492                    (((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber()).Data(),((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift());
1493             ((AliConversionCuts*)fCutGammaArray->At(iCut))->SetEtaShift(0.);
1494             ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->SetEtaShift(0.);
1495       
1496             
1497          }*/
1498          hEtaShift[iCut]->Fill(0.,0.);
1499          continue; // No Eta Shift requested, continue
1500       }
1501     
1502       
1503       if( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
1504          ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
1505          ((AliConversionCuts*)fCutGammaArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
1506          ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->SetEtaShift( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() );
1507          hEtaShift[iCut]->Fill(0.,(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift()));
1508          continue;
1509       }
1510       else{
1511          printf(" Gamma Conversion Dalitz Task %s :: Eta Shift Manually Set to %f \n\n",
1512          (((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber()).Data(),((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift());
1513          ((AliConversionCuts*)fCutGammaArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
1514          ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->SetEtaShift( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() );
1515           hEtaShift[iCut]->Fill(0.,(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift()));
1516       }
1517    }
1518    
1519    return kTRUE;
1520 }
1521
1522
1523 void AliAnalysisTaskGammaConvDalitzV1::Terminate(const Option_t *)
1524 {
1525
1526 ///Grid
1527
1528 }
1529 //________________________________________________________________________
1530 void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
1531 {
1532    Int_t nV0 = 0;
1533    TList *GoodGammasStepOne = new TList();
1534    TList *GoodGammasStepTwo = new TList();
1535    // Loop over Photon Candidates allocated by ReaderV1
1536    
1537    for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
1538       AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
1539       if(!PhotonCandidate) continue;
1540       
1541       fIsFromMBHeader = kTRUE;
1542       
1543       if( fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0 ){
1544         
1545          Int_t isPosFromMBHeader
1546             = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
1547          if(isPosFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
1548          
1549          Int_t isNegFromMBHeader
1550             = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1551          if(isNegFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
1552          
1553          if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1554          
1555       }
1556       
1557       if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
1558
1559       if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
1560          !((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // if no post reader loop is required add to events good gammas
1561          
1562          fGoodGammas->Add(PhotonCandidate);
1563       
1564          if(fIsFromMBHeader){
1565               hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
1566               hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1567               if( fDoMesonQA ) hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1568          }
1569          
1570          if(fMCEvent){
1571             ProcessTruePhotonCandidates(PhotonCandidate);
1572          }
1573       }
1574       else if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
1575          ((AliConversionCuts*)fCutGammaArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
1576          nV0++;
1577          GoodGammasStepOne->Add(PhotonCandidate);
1578       }
1579       else if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
1580                ((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
1581          GoodGammasStepTwo->Add(PhotonCandidate);
1582       }
1583    }
1584    
1585    
1586    if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){
1587       for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
1588          AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
1589          if(!PhotonCandidate) continue;
1590          
1591          
1592          fIsFromMBHeader = kTRUE;
1593          if(fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0){
1594             Int_t isPosFromMBHeader
1595                = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
1596             Int_t isNegFromMBHeader
1597                = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1598             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1599          }
1600          
1601          
1602          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GoodGammasStepOne->GetEntries())) continue;
1603          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed
1604             fGoodGammas->Add(PhotonCandidate);
1605             
1606              if(fIsFromMBHeader){
1607                 hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
1608                 hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1609                 if( fDoMesonQA )hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1610              }
1611              
1612             if(fMCEvent){
1613                ProcessTruePhotonCandidates(PhotonCandidate);
1614             }
1615          }
1616          else GoodGammasStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
1617       }
1618    }
1619    if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){
1620       for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
1621          AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
1622          if(!PhotonCandidate) continue;
1623          
1624          if(fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0){
1625             Int_t isPosFromMBHeader
1626                = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
1627             Int_t isNegFromMBHeader
1628                = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
1629             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
1630          }
1631          
1632          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GoodGammasStepTwo,i)) continue;
1633          fGoodGammas->Add(PhotonCandidate); // Add gamma to current cut TList
1634          
1635           if(fIsFromMBHeader){
1636               hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
1637               hESDConvGammaEta[fiCut]->Fill(PhotonCandidate->Eta());
1638               if(fDoMesonQA)hESDConvGammaZR[fiCut]->Fill(PhotonCandidate->GetConversionZ(),PhotonCandidate->GetConversionRadius());
1639           }
1640          
1641          if(fMCEvent){
1642             ProcessTruePhotonCandidates(PhotonCandidate);
1643          }
1644       }
1645    }
1646
1647    delete GoodGammasStepOne;
1648    GoodGammasStepOne = 0x0;
1649    delete GoodGammasStepTwo;
1650    GoodGammasStepTwo = 0x0;
1651 }
1652
1653 //________________________________________________________________________
1654 void AliAnalysisTaskGammaConvDalitzV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
1655 {
1656    // Process True Photons
1657    AliStack *MCStack = fMCEvent->Stack();
1658    TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
1659    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
1660
1661    if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
1662    if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){  // Not Same Mother == Combinatorial Bck
1663       return;
1664    }
1665    
1666    else if (posDaughter->GetMother(0) == -1){
1667       return;
1668    }
1669    
1670    if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
1671    if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
1672    if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
1673
1674    TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
1675    if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
1676
1677    // True Photon
1678   
1679   Int_t labelGamma = TruePhotonCandidate->GetMCParticleLabel(MCStack);
1680   
1681   if( labelGamma < MCStack->GetNprimary() ){
1682     if( fIsFromMBHeader ){
1683       hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1684     }
1685   }
1686   else {
1687     if( fIsFromMBHeader){
1688       hESDTrueSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1689     }
1690   }
1691  
1692   if( IsPi0DalitzDaughter(labelGamma) == kTRUE ) {
1693         if( labelGamma < MCStack->GetNprimary() ) {
1694           if( fIsFromMBHeader ){
1695             hESDTruePi0DalitzConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1696           }
1697         }
1698         else {
1699           if( fIsFromMBHeader ) {
1700             hESDTruePi0DalitzSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
1701           }
1702         }
1703   }
1704    
1705  
1706 }
1707 //________________________________________________________________________
1708 void AliAnalysisTaskGammaConvDalitzV1::ProcessVirtualGammasCandidates(){
1709   
1710   
1711   Double_t magField = fInputEvent->GetMagneticField();
1712
1713
1714   if( magField  < 0.0 ){
1715       magField =  1.0;
1716    }
1717    else {
1718       magField =  -1.0;
1719    }
1720   
1721    AliStack *MCStack = 0x0;
1722    
1723    if( fMCEvent ){
1724      
1725     MCStack = fMCEvent->Stack();
1726     
1727    }
1728   
1729   
1730   for(Int_t virtualGammaIndex=0; virtualGammaIndex < fGoodVirtualGammas->GetEntries();  virtualGammaIndex++ ){
1731     
1732     
1733      AliAODConversionPhoton *Vgamma=dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(virtualGammaIndex));
1734       
1735     
1736     
1737      AliESDtrack* positronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelPositive() );
1738      AliESDtrack* electronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelNegative() );
1739      
1740      
1741      Bool_t isPhoton         = kFALSE;
1742      Bool_t isPi0Dalitz      = kFALSE;
1743      Bool_t isEtaDalitz      = kFALSE;
1744      Bool_t isJPsi           = kFALSE;
1745      Bool_t isTrueEposENeg   = kFALSE;
1746      Bool_t isMotherPrimary  = kFALSE;
1747
1748      Double_t psiPair = GetPsiPair(positronVgamma,electronVgamma);
1749      Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronVgamma->GetConstrainedParam()->Phi()-positronVgamma->GetConstrainedParam()->Phi());
1750      
1751      
1752       if ( fDoMesonQA ) {
1753         
1754         
1755               
1756            
1757              hESDEposEnegPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);   
1758              hESDEposEnegInvMassPt[fiCut]->Fill(Vgamma->GetMass(),Vgamma->Pt());
1759                          
1760              
1761               if( fMCEvent ) {
1762
1763               
1764               
1765               Int_t virtualGammaMCLabel = Vgamma->GetMCParticleLabel(MCStack);
1766               
1767               TParticle * negativeMC = 0x0; /*= (TParticle*)Vgamma->GetNegativeMCDaughter(MCStack);*/
1768               TParticle * positiveMC = 0x0;/*= (TParticle*)Vgamma->GetPositiveMCDaughter(MCStack);*/   
1769               TParticle * mcVgamma   = 0x0;
1770               
1771               if( virtualGammaMCLabel != -1 ){
1772                 
1773                    mcVgamma = (TParticle*)MCStack->Particle(virtualGammaMCLabel);
1774                    
1775               
1776               }
1777               
1778               negativeMC = (TParticle*)Vgamma->GetNegativeMCDaughter(MCStack);
1779               positiveMC = (TParticle*)Vgamma->GetPositiveMCDaughter(MCStack);
1780               
1781             
1782               
1783               
1784                if( negativeMC && positiveMC ) {
1785                 
1786                 if( positiveMC->GetPdgCode() == ::kPositron && negativeMC->GetPdgCode() == ::kElectron ) isTrueEposENeg = kTRUE;
1787                
1788                 if( positiveMC->GetMother(0) > -1 && positiveMC->GetMother(0) < fMCStack->GetNprimary() )
1789                 isMotherPrimary = kTRUE;
1790               
1791                }
1792               
1793
1794               if(mcVgamma){
1795               // Check if it is a true photon
1796               if(mcVgamma->GetPdgCode() == 22){
1797                 isPhoton = kTRUE;
1798               }else if(mcVgamma->GetPdgCode() == 443){
1799                 isJPsi = kTRUE;
1800               }
1801               else if( IsDalitz( mcVgamma ) ){
1802                 if     ( mcVgamma->GetPdgCode() == 111 ) isPi0Dalitz = kTRUE;
1803                 else if( mcVgamma->GetPdgCode() == 221 ) isEtaDalitz = kTRUE;
1804               }
1805               }
1806
1807               if(isPhoton){
1808                     hESDEposEnegTruePhotonInvMassPt[fiCut]->Fill(Vgamma->GetMass(),Vgamma->Pt());
1809                     
1810                     hESDEposEnegTruePhotonPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1811                     if( Vgamma->Pt() > 1.5 ){
1812                         hESDEposEnegTruePhotonPsiPairDPhiPtCut[fiCut]->Fill(deltaPhi,psiPair);
1813                     }
1814               }
1815               else if(isJPsi){
1816                     hESDEposEnegTrueJPsiInvMassPt[fiCut]->Fill(Vgamma->GetMass(),Vgamma->Pt());
1817               }
1818               else if(isPi0Dalitz){
1819                     hESDEposEnegTruePi0DalitzInvMassPt[fiCut]->Fill(Vgamma->GetMass(),Vgamma->Pt());
1820                     hESDEposEnegTruePi0DalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1821                     if( isMotherPrimary ) hESDEposEnegTruePrimPi0DalitzInvMass[fiCut]->Fill( Vgamma->GetMass() );
1822               }
1823               else if(isEtaDalitz){
1824                     hESDEposEnegTrueEtaDalitzInvMassPt[fiCut]->Fill(Vgamma->GetMass(),Vgamma->Pt());
1825                     hESDEposEnegTrueEtaDalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
1826                     if( isMotherPrimary ) hESDEposEnegTruePrimEtaDalitzInvMass[fiCut]->Fill( Vgamma->GetMass() );
1827               }
1828               
1829               if( isTrueEposENeg ) hESDEposEnegTrueInvMassPt[fiCut]->Fill(Vgamma->GetMass(), Vgamma->Pt());         
1830               
1831             }
1832         
1833       }
1834         
1835      
1836     
1837     
1838   }
1839     
1840   
1841      
1842   
1843   
1844 }  
1845   
1846 //________________________________________________________________________
1847 void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
1848
1849    Double_t magField = fInputEvent->GetMagneticField();
1850
1851
1852    if( magField  < 0.0 ){
1853       magField =  1.0;
1854    }
1855    else {
1856       magField =  -1.0;
1857    }
1858
1859
1860    vector<Int_t> lGoodElectronIndexPrev(0);
1861    vector<Int_t> lGoodPositronIndexPrev(0);
1862    
1863    
1864   
1865
1866    for(UInt_t i = 0; i < fSelectorElectronIndex.size(); i++){
1867      
1868     AliESDtrack* electronCandidate = fESDEvent->GetTrack(fSelectorElectronIndex[i]);
1869     
1870     if( fMCEvent ) {
1871       
1872           Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
1873           Int_t isMCFromMBHeader = -1;
1874           if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0) {
1875             isMCFromMBHeader
1876             = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(labelelectron,fMCStack,fInputEvent);
1877             if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
1878           }    
1879     }
1880         
1881     if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(electronCandidate) ) continue;
1882     
1883     lGoodElectronIndexPrev.push_back(   fSelectorElectronIndex[i] );
1884     hESDDalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
1885     hESDDalitzElectronPhi[fiCut]->Fill(electronCandidate->Phi());
1886     
1887         
1888     if( fMCEvent ) {
1889             
1890           Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
1891             if( labelelectron < fMCStack->GetNtrack() ){
1892               TParticle* electron = fMCStack->Particle(labelelectron);
1893                 if( electron->GetPdgCode() ==  11 ){
1894                     if( labelelectron < fMCStack->GetNprimary() ){
1895                       hESDTrueElectronPt[fiCut]->Fill(electronCandidate->Pt());    //primary electron
1896                     }
1897                     else{
1898                       hESDTrueSecElectronPt[fiCut]->Fill(electronCandidate->Pt()); //secondary electron
1899                     }
1900                     if( IsPi0DalitzDaughter(labelelectron) == kTRUE ) {
1901                         if( labelelectron < fMCStack->GetNprimary() ) {
1902                           hESDTruePi0DalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
1903                         }
1904                         else{
1905                           hESDTruePi0DalitzSecElectronPt[fiCut]->Fill(electronCandidate->Pt());
1906                         }
1907                     }
1908                 }
1909             }
1910         }
1911         
1912         
1913    }
1914
1915    for(UInt_t i = 0; i < fSelectorPositronIndex.size(); i++){
1916
1917       AliESDtrack* positronCandidate = fESDEvent->GetTrack( fSelectorPositronIndex[i] );
1918       
1919       if( fMCEvent ) {
1920         
1921          Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
1922          Int_t isMCFromMBHeader = -1;
1923           
1924           if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0) {
1925             isMCFromMBHeader
1926             = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(labelpositron,fMCStack,fInputEvent);
1927           if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
1928           
1929           }  
1930       }
1931   
1932       
1933       
1934       if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(positronCandidate) ) continue;
1935       
1936       lGoodPositronIndexPrev.push_back( fSelectorPositronIndex[i] );
1937       hESDDalitzPositronPt[fiCut]->Fill( positronCandidate->Pt() );
1938       hESDDalitzPositronPhi[fiCut]->Fill( positronCandidate->Phi() );
1939        
1940       
1941        if( fMCEvent ) {
1942           
1943           Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
1944           
1945           if( labelpositron < fMCStack->GetNtrack() ) {
1946             TParticle* positron = fMCStack->Particle(labelpositron);
1947             if( positron->GetPdgCode() ==  -11 ){
1948               if( labelpositron < fMCStack->GetNprimary() ){
1949                 hESDTruePositronPt[fiCut]->Fill(positronCandidate->Pt());
1950               }
1951               else{
1952                 hESDTrueSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
1953               }
1954               if( IsPi0DalitzDaughter(labelpositron) == kTRUE ) {
1955                 if( labelpositron < fMCStack->GetNprimary() ){
1956                   hESDTruePi0DalitzPositronPt[fiCut]->Fill(positronCandidate->Pt());
1957                 }
1958                 else{
1959                   hESDTruePi0DalitzSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
1960                 }
1961               }
1962             }
1963           }
1964         }
1965        }
1966
1967
1968    vector<Bool_t> lElectronPsiIndex(lGoodElectronIndexPrev.size(), kTRUE);
1969    vector<Bool_t> lPositronPsiIndex(lGoodPositronIndexPrev.size(), kTRUE);
1970
1971
1972    if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->DoPsiPairCut() == kTRUE ){
1973
1974       for( UInt_t i = 0; i < lGoodElectronIndexPrev.size(); i++ ) {
1975
1976          AliESDtrack *electronCandidate = fESDEvent->GetTrack(lGoodElectronIndexPrev[i]);
1977
1978          for(UInt_t j = 0; j <  lGoodPositronIndexPrev.size(); j++){
1979             AliESDtrack *positronCandidate = fESDEvent->GetTrack(lGoodPositronIndexPrev[j]);
1980             Double_t psiPair = GetPsiPair(positronCandidate,electronCandidate);
1981             Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->GetConstrainedParam()->Phi()-positronCandidate->GetConstrainedParam()->Phi());
1982
1983             if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->IsFromGammaConversion(psiPair,deltaPhi ) ){
1984                lElectronPsiIndex[i] = kFALSE;
1985                lPositronPsiIndex[j] = kFALSE;
1986             }
1987          }
1988       }
1989    }
1990
1991
1992    vector<Int_t> lGoodElectronIndex(0);
1993    vector<Int_t> lGoodPositronIndex(0);
1994    
1995
1996    for( UInt_t i = 0; i < lGoodElectronIndexPrev.size(); i++ ) {
1997
1998         if(  lElectronPsiIndex[i] == kTRUE )
1999         lGoodElectronIndex.push_back(   lGoodElectronIndexPrev[i]  );
2000    }
2001
2002    for( UInt_t i = 0; i < lGoodPositronIndexPrev.size(); i++ ) {
2003
2004          if(  lPositronPsiIndex[i] == kTRUE )
2005          lGoodPositronIndex.push_back(   lGoodPositronIndexPrev[i]  );
2006    }
2007
2008
2009
2010     
2011    
2012    for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
2013
2014       //if( lElectronPsiIndex[i] == kFALSE ) continue;
2015
2016
2017       AliESDtrack *electronCandidate = fESDEvent->GetTrack(lGoodElectronIndex[i]);
2018
2019       AliKFParticle electronCandidateKF( *electronCandidate->GetConstrainedParam(), ::kElectron );
2020
2021       for(UInt_t j = 0; j < lGoodPositronIndex.size(); j++){
2022
2023          //if( lPositronPsiIndex[j] == kFALSE ) continue;
2024
2025          AliESDtrack *positronCandidate = fESDEvent->GetTrack(lGoodPositronIndex[j]);
2026          AliKFParticle positronCandidateKF( *positronCandidate->GetConstrainedParam(), ::kPositron );
2027          
2028                                  /*Bool_t isPhoton    = kFALSE;
2029                                  Bool_t isPi0Dalitz = kFALSE;
2030                                  Bool_t isEtaDalitz = kFALSE;
2031                                  Bool_t isJPsi      = kFALSE;
2032                                  Bool_t isTrueEposENeg = kFALSE;*/
2033
2034          //Double_t psiPair = GetPsiPair(positronCandidate,electronCandidate);
2035          //Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->GetConstrainedParam()->Phi()-positronCandidate->GetConstrainedParam()->Phi());
2036          
2037
2038          AliKFConversionPhoton* virtualPhoton = NULL;
2039          virtualPhoton = new AliKFConversionPhoton(electronCandidateKF,positronCandidateKF);
2040
2041          if( fSetProductionVertextoVGamma == kTRUE ){
2042            
2043               AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
2044               primaryVertexImproved+=*virtualPhoton;
2045               virtualPhoton->SetProductionVertex(primaryVertexImproved);
2046          
2047          }
2048
2049          virtualPhoton->SetTrackLabels( lGoodPositronIndex[j], lGoodElectronIndex[i]);
2050          
2051          //Bool_t isMotherPrimary = kFALSE;
2052          
2053           
2054          if( fMCEvent ) {
2055            
2056           Int_t labeln=TMath::Abs(electronCandidate->GetLabel());
2057           Int_t labelp=TMath::Abs(positronCandidate->GetLabel());
2058           TParticle *fNegativeMCParticle = fMCStack->Particle(labeln);
2059           TParticle *fPositiveMCParticle = fMCStack->Particle(labelp);
2060           
2061           
2062             if( fPositiveMCParticle && fNegativeMCParticle) {
2063               
2064               
2065               
2066                virtualPhoton->SetMCLabelPositive(labelp);
2067                virtualPhoton->SetMCLabelNegative(labeln);
2068                
2069                //if( fPositiveMCParticle->GetPdgCode() == ::kPositron && fNegativeMCParticle->GetPdgCode() == ::kElectron ) isTrueEposENeg = kTRUE;
2070                
2071                //if( fPositiveMCParticle->GetMother(0) > -1 && fPositiveMCParticle->GetMother(0) < fMCStack->GetNprimary() )
2072                //isMotherPrimary = kTRUE;
2073                
2074             }
2075             
2076             
2077               
2078          }
2079          
2080           AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); //To Apply PsiPairCut
2081             
2082           /*if ( fDoMesonQA ) {
2083
2084               if( fMCEvent ) {
2085
2086               TParticle *mcVgamma=virtualPhoton->GetMCParticle(fMCStack);
2087
2088               if(mcVgamma){
2089               // Check if it is a true photon
2090               if(mcVgamma->GetPdgCode() == 22){
2091                 isPhoton = kTRUE;
2092               }else if(mcVgamma->GetPdgCode() == 443){
2093                 isJPsi = kTRUE;
2094               }
2095               else if( IsDalitz( mcVgamma ) ){
2096                 if     ( mcVgamma->GetPdgCode() == 111 ) isPi0Dalitz = kTRUE;
2097                 else if( mcVgamma->GetPdgCode() == 221 ) isEtaDalitz = kTRUE;
2098               }
2099               }
2100
2101               if(isPhoton){
2102                     hESDEposEnegTruePhotonInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2103                     
2104                     hESDEposEnegTruePhotonPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
2105               }
2106               else if(isJPsi){
2107                     hESDEposEnegTrueJPsiInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2108               }
2109               else if(isPi0Dalitz){
2110                     hESDEposEnegTruePi0DalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2111                     hESDEposEnegTruePi0DalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
2112                     if( isMotherPrimary ) hESDEposEnegTruePrimPi0DalitzInvMass[fiCut]->Fill( vphoton->GetMass() );
2113               }
2114               else if(isEtaDalitz){
2115                     hESDEposEnegTrueEtaDalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2116                     hESDEposEnegTrueEtaDalitzPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
2117                     if( isMotherPrimary ) hESDEposEnegTruePrimEtaDalitzInvMass[fiCut]->Fill( vphoton->GetMass() );
2118               }
2119               
2120               if( isTrueEposENeg ) hESDEposEnegTrueInvMassPt[fiCut]->Fill(vphoton->GetMass(), vphoton->Pt());       
2121               
2122             }
2123           }*/
2124          
2125       
2126          
2127          //if ( fDoMesonQA ) {
2128            
2129          //hESDEposEnegPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);   
2130          //hESDEposEnegInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2131                          
2132          //}
2133                                  
2134          /*if( ! fDoChicAnalysis ) {
2135         
2136                   if (  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE )  {
2137                     
2138                      Double_t MassCutMax = 1000.0;
2139                      if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCutLowPt() >= ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCutHighPt() ){
2140                        MassCutMax = ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCutLowPt();
2141                      }
2142                      else {
2143                        MassCutMax = ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCutHighPt();
2144                      }
2145                      
2146                      Bool_t DoMassMinCut = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->DoMassMinCut();
2147                      Double_t MassMinCut = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetMassMinCut();
2148                      
2149                      if( vphoton->GetMass() > MassCutMax || (  DoMassMinCut && vphoton->GetMass() < MassMinCut )  ) {
2150                        
2151                        
2152                        delete vphoton;
2153                        vphoton = 0x0;
2154                        delete virtualPhoton;
2155                        virtualPhoton = 0x0;
2156                        continue;
2157                        
2158                      }
2159                      
2160                   }
2161          }*/
2162         
2163         
2164          fGoodVirtualGammas->Add(  vphoton );
2165          delete virtualPhoton;
2166          virtualPhoton=NULL;
2167                                  
2168       }
2169    }
2170    
2171  
2172    //Computing mixing event
2173    
2174    if(  fDoMesonQA ) {
2175
2176       for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
2177          
2178          //if( lElectronPsiIndex[i] == kFALSE ) continue;
2179          
2180           AliESDtrack *electronCandidate1 = fESDEvent->GetTrack(lGoodElectronIndex[i]);
2181
2182           AliKFParticle electronCandidate1KF( *electronCandidate1->GetConstrainedParam(), ::kElectron );
2183          
2184         
2185           for(UInt_t j = i+1; j < lGoodElectronIndex.size(); j++){
2186             
2187                //if( lElectronPsiIndex[j] == kFALSE ) continue;
2188                
2189                
2190                 AliESDtrack *electronCandidate2 = fESDEvent->GetTrack(lGoodElectronIndex[j]);
2191
2192                 AliKFParticle electronCandidate2KF( *electronCandidate2->GetConstrainedParam(), ::kElectron );
2193                
2194                 AliKFConversionPhoton* virtualPhoton = new AliKFConversionPhoton(electronCandidate1KF,electronCandidate2KF);
2195                 
2196                 //AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
2197                 //primaryVertexImproved+=*virtualPhoton;
2198                 //virtualPhoton->SetProductionVertex(primaryVertexImproved);
2199
2200                     
2201                 AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); 
2202                 hESDEposEnegLikeSignBackInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2203                 delete vphoton;
2204                 delete virtualPhoton;
2205                 vphoton = 0x0;
2206                 virtualPhoton = 0x0;            
2207            
2208           }
2209    }   
2210    
2211    
2212       for(UInt_t i = 0; i < lGoodPositronIndex.size(); i++){
2213      
2214    
2215          
2216          //if( lPositronPsiIndex[i] == kFALSE ) continue;
2217          
2218           AliESDtrack *positronCandidate1 = fESDEvent->GetTrack(lGoodPositronIndex[i]);
2219
2220           AliKFParticle positronCandidate1KF( *positronCandidate1->GetConstrainedParam(), ::kPositron );
2221          
2222         
2223           for(UInt_t j = i+1; j < lGoodPositronIndex.size(); j++){
2224             
2225               // if( lPositronPsiIndex[j] == kFALSE ) continue;
2226                
2227                 AliESDtrack *positronCandidate2 = fESDEvent->GetTrack(lGoodPositronIndex[j]);
2228
2229                 AliKFParticle positronCandidate2KF( *positronCandidate2->GetConstrainedParam(), ::kPositron );
2230                
2231                 AliKFConversionPhoton* virtualPhoton = new AliKFConversionPhoton(positronCandidate1KF,positronCandidate2KF);
2232                 //AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
2233                 //primaryVertexImproved+=*virtualPhoton;
2234                 //virtualPhoton->SetProductionVertex(primaryVertexImproved);
2235                
2236                 AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); 
2237                 hESDEposEnegLikeSignBackInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
2238                 
2239                 
2240                 delete vphoton;
2241                 delete virtualPhoton;  
2242                 vphoton = 0x0;
2243                 virtualPhoton = 0x0;
2244            
2245           }
2246       }   
2247
2248    }
2249 }
2250
2251 //________________________________________________________________________
2252 void AliAnalysisTaskGammaConvDalitzV1::CalculatePi0DalitzCandidates(){
2253
2254    // Conversion Gammas
2255
2256
2257
2258
2259    if( fGoodGammas->GetEntries() > 0 && fGoodVirtualGammas->GetEntries() > 0 ){
2260
2261       vector<Bool_t> lGoodVirtualGamma(fGoodVirtualGammas->GetEntries(), kFALSE);
2262      
2263       for(Int_t GammaIndex=0; GammaIndex<fGoodGammas->GetEntries(); GammaIndex++){
2264
2265          AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(GammaIndex));
2266          if (gamma==NULL) continue;
2267          for(Int_t virtualGammaIndex=0;virtualGammaIndex<fGoodVirtualGammas->GetEntries();virtualGammaIndex++){
2268
2269             AliAODConversionPhoton *Vgamma=dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(virtualGammaIndex));
2270             if (Vgamma==NULL) continue;
2271             //Check for same Electron ID
2272             if(gamma->GetTrackLabelPositive() == Vgamma->GetTrackLabelPositive() ||
2273                gamma->GetTrackLabelNegative() == Vgamma->GetTrackLabelNegative() ||
2274                gamma->GetTrackLabelNegative() == Vgamma->GetTrackLabelPositive() ||
2275                gamma->GetTrackLabelPositive() == Vgamma->GetTrackLabelNegative() ) continue;
2276
2277             AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma,Vgamma);
2278             pi0cand->SetLabels(GammaIndex,virtualGammaIndex);
2279                       
2280
2281             if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift())) ){
2282               
2283               //cout<< "Meson Accepted "<<endl;
2284               
2285                Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
2286                Int_t mbin = 0;
2287                if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ){
2288                   mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
2289                } else {
2290                   mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
2291                }
2292               
2293                       
2294               
2295               if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2296                 
2297                 
2298                  if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( pi0cand->Pt() , Vgamma->GetMass() ) == kTRUE ){
2299           
2300                  hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
2301                 
2302                  Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
2303                  sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
2304                  
2305                  
2306                     if ( fDoMesonQA ) {
2307                     
2308                        hESDMotherPhi[fiCut]->Fill(pi0cand->Phi());
2309                  
2310                         if( lGoodVirtualGamma[virtualGammaIndex] == kFALSE ) {
2311                  
2312                           FillElectronQAHistos(pi0cand,Vgamma);
2313                           
2314                           lGoodVirtualGamma[virtualGammaIndex] = kTRUE;
2315                       }
2316                    }
2317                 }
2318               }
2319               else {
2320                  hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
2321                  Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
2322                  sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
2323                  
2324                  
2325                    if ( fDoMesonQA ) {
2326                  
2327                     hESDMotherPhi[fiCut]->Fill(pi0cand->Phi());
2328                  
2329                     if( lGoodVirtualGamma[virtualGammaIndex] == kFALSE ) {
2330                       
2331                       FillElectronQAHistos(pi0cand,Vgamma);
2332                  
2333                       lGoodVirtualGamma[virtualGammaIndex] = kTRUE;
2334                  
2335                     }
2336                  }
2337               }
2338                
2339                if( fDoChicAnalysis) {
2340                
2341                hESDPi0MotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
2342                 
2343                Double_t diffMass = pi0cand->M() - Vgamma->GetMass();
2344     
2345                hESDPi0MotherDiffInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
2346         
2347                 if( Vgamma->GetMass() > 2.5 && Vgamma->GetMass() < 3.4){
2348                 hESDPi0MotherDiffLimInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
2349                 }
2350                }
2351                
2352               if(fMCEvent){
2353                   ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
2354               }
2355             }
2356             delete pi0cand;
2357             pi0cand=0x0;
2358          }
2359       }
2360    }
2361 }
2362
2363 //________________________________________________________________________
2364 void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
2365
2366    Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
2367    Int_t mbin = 0;
2368
2369    Int_t method = 0;
2370
2371    method = ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetBKGMethod();
2372
2373
2374    if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
2375       mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
2376    } else {
2377       mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
2378    }
2379
2380    if( method == 1 || method == 2 ) {
2381
2382       AliGammaConversionAODBGHandler::GammaConversionVertex *bgEventVertex = NULL;
2383
2384       if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ) {
2385
2386          for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2387
2388             AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2389
2390             if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
2391                bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
2392             }
2393
2394             for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2395                AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2396
2397                for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2398                   AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2399
2400                   if(fMoveParticleAccordingToVertex == kTRUE && method == 1 ){
2401                      MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
2402                   }
2403
2404                   AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2405                             
2406
2407                   if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE, ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift()))){
2408                       if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2409                         
2410                         if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.GetMass() ) == kTRUE ){
2411                           
2412                          // cout<<" Mass dalitz: "<<currentEventGoodV0.GetMass()<<endl;
2413                           hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2414                           Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2415                           sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2416                          }
2417                       }
2418                       else {
2419                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2420                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2421                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2422                       }       
2423                   }
2424                   delete backgroundCandidate;
2425                   backgroundCandidate = 0x0;
2426                }
2427             }
2428          }
2429       }
2430       else{
2431          for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
2432             AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
2433             if(previousEventV0s){
2434                if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
2435                   bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
2436                }
2437                for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2438
2439                   AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2440
2441                   for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
2442
2443                      AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
2444
2445                      if(fMoveParticleAccordingToVertex == kTRUE && method ==1){
2446                         MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
2447                      }
2448
2449                      AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2450                                
2451                      if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift()))){
2452                        
2453                        if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2454                         
2455                           if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.GetMass() ) == kTRUE ){
2456                         
2457                        
2458                           hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2459                           Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2460                           sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2461                         }
2462                        }
2463                        else {
2464                           hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2465                           Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2466                           sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2467                        }
2468                      }
2469                      delete backgroundCandidate;
2470                      backgroundCandidate = 0x0;
2471                   }
2472                }
2473             }
2474          }
2475       }
2476    }
2477
2478    else if( method == 3 ){
2479
2480       for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
2481
2482          AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
2483
2484          for(Int_t iPrevious=0;iPrevious<fGammasPool[fiCut]->GetEntries();iPrevious++){
2485
2486             AliAODConversionPhoton previousGoodV0 = *(AliAODConversionPhoton*)((fGammasPool[fiCut]->At(iPrevious) ));
2487
2488
2489             AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
2490                       
2491
2492             if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE, ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift()))){
2493               
2494                if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2495                 
2496                     if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( backgroundCandidate->Pt() , currentEventGoodV0.GetMass() ) == kTRUE ){
2497                   
2498                       
2499                   hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2500                   Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2501                   sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
2502                   
2503                   }
2504                }
2505                else{
2506                  
2507                  hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
2508                  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
2509                  sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1); 
2510                  
2511                }
2512             }
2513             delete backgroundCandidate;
2514             backgroundCandidate = 0x0;
2515          }
2516       }
2517    }
2518
2519 }
2520 //________________________________________________________________________
2521 void AliAnalysisTaskGammaConvDalitzV1::UpdateEventByEventData(){
2522    //see header file for documentation
2523
2524    Int_t method = 0;
2525
2526    method = ( (AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetBKGMethod();
2527
2528    
2529
2530
2531    if( method == 1 ) {
2532
2533       if(fGoodGammas->GetEntries() > 0 ){
2534
2535          if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ){
2536             fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
2537          }
2538
2539          else{ // means we use #V0s for multiplicity
2540             fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
2541          }
2542       }
2543    }
2544
2545    else if ( method == 2 ){
2546
2547       if(fGoodVirtualGammas->GetEntries() > 0 ){
2548          if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
2549             fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
2550          }
2551          else{ // means we use #V0s for multiplicity
2552             fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodVirtualGammas->GetEntries());
2553          }
2554       }
2555    }
2556    else if ( method  == 3 ) {
2557
2558
2559
2560       for(Int_t index = 0; index < fGoodGammas->GetEntries(); index++){
2561
2562
2563          if ( fGammasPool[fiCut]->GetEntries() > ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->NumberOfRotationEvents() ){
2564             fGammasPool[fiCut]->RemoveLast();
2565          }
2566          fGammasPool[fiCut]->AddFirst( new AliAODConversionPhoton(*(AliAODConversionPhoton*)(fGoodGammas->At(index)) ) );
2567
2568       }
2569    }
2570 }
2571 //______________________________________________________________________
2572 void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate, AliAODConversionPhoton *TrueVirtualGammaCandidate)
2573 {
2574
2575    // Process True Mesons
2576
2577    AliStack *MCStack = fMCEvent->Stack();
2578
2579    if(  TrueGammaCandidate->GetV0Index()<fESDEvent->GetNumberOfV0s()    ){
2580      
2581      
2582      //cout<<"Entro True Meson"<<endl;
2583
2584
2585       Bool_t isTruePi0 = kFALSE;
2586       Bool_t isTrueEta = kFALSE;
2587       Bool_t massCutAccept = kFALSE;
2588       //Bool_t isTrueChiC = kFALSE;
2589       Int_t gammaMCLabel = TrueGammaCandidate->GetMCParticleLabel(MCStack);
2590       Int_t gammaMotherLabel = -1;
2591
2592
2593       if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
2594            
2595             if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->MassCut( Pi0Candidate->Pt() , TrueVirtualGammaCandidate->GetMass() ) == kTRUE ){
2596               
2597                massCutAccept = kTRUE;
2598             }
2599       }
2600       else {
2601               massCutAccept  = kTRUE;
2602       }
2603       
2604       
2605       
2606
2607
2608       if(gammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2609
2610
2611          // Daughters Gamma 0
2612          TParticle * negativeMC = (TParticle*)TrueGammaCandidate->GetNegativeMCDaughter(MCStack);
2613          TParticle * positiveMC = (TParticle*)TrueGammaCandidate->GetPositiveMCDaughter(MCStack);
2614          TParticle * gammaMC = (TParticle*)MCStack->Particle(gammaMCLabel);
2615
2616
2617          if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
2618
2619             if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
2620
2621                if(gammaMC->GetPdgCode() == 22){ // ... with Gamma Mother
2622                   gammaMotherLabel=gammaMC->GetFirstMother();
2623                }
2624             }
2625          }
2626       }
2627
2628
2629       Int_t virtualGammaMCLabel = TrueVirtualGammaCandidate->GetMCParticleLabel(MCStack);
2630       Int_t virtualGammaMotherLabel = -1;
2631       Int_t virtualGamma = 1;
2632       Int_t virtualGammaGrandMotherLabel =-1;
2633
2634
2635       if(virtualGammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2636          // Daughters Gamma 1
2637          TParticle * negativeMC = (TParticle*)TrueVirtualGammaCandidate->GetNegativeMCDaughter(MCStack);
2638          TParticle * positiveMC = (TParticle*)TrueVirtualGammaCandidate->GetPositiveMCDaughter(MCStack);
2639          TParticle * virtualGammaMotherMC = (TParticle*)MCStack->Particle(virtualGammaMCLabel);
2640
2641          if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
2642
2643             if( virtualGammaMotherMC->GetPdgCode() != 22 ){
2644                virtualGammaMotherLabel=virtualGammaMCLabel;
2645             if(virtualGammaMotherMC->GetPdgCode() == 443){
2646                virtualGammaGrandMotherLabel=virtualGammaMotherMC->GetFirstMother();
2647             }
2648            }
2649
2650             else if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
2651                virtualGammaMotherLabel=virtualGammaMotherMC->GetFirstMother();
2652                virtualGamma = 0; //no virtual gamma
2653             }
2654          }
2655       }
2656
2657
2658       if(gammaMotherLabel >= 0 && ( gammaMotherLabel == virtualGammaMotherLabel) ){
2659
2660          if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 111){
2661             isTruePi0=kTRUE;
2662          }
2663
2664          if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 221){
2665             isTrueEta=kTRUE;
2666          }
2667          
2668          
2669         }
2670
2671        if( fDoChicAnalysis) {
2672         if(gammaMotherLabel>=0 && ( gammaMotherLabel == virtualGammaGrandMotherLabel) ){
2673           if(((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 445 ||
2674             ((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 10443 ||
2675             ((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 20443 ){
2676               //isTrueChiC=kTRUE;
2677               hESDTrueMotherChiCInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2678               hESDTrueMotherChiCDiffInvMassPt[fiCut]->Fill(Pi0Candidate->M()-TrueVirtualGammaCandidate->GetMass(),Pi0Candidate->Pt());
2679              }
2680           }  
2681        }
2682
2683       if( ( isTruePi0 || isTrueEta) && massCutAccept ){ // True Pion or Eta
2684         
2685          if ( virtualGamma == 1 ) { //True Dalitz       
2686
2687             Float_t weighted= 1;
2688             
2689             if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2690                 if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack,fInputEvent)){
2691                     if (((TParticle*)MCStack->Particle(gammaMotherLabel))->Pt()>0.005){
2692                         weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gammaMotherLabel,fMCStack,fInputEvent);
2693                     }
2694                 }
2695             }
2696
2697             hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2698             hESDTrueMotherDalitzInvMassPt[fiCut]->Fill( TrueVirtualGammaCandidate->GetMass(),Pi0Candidate->Pt(),weighted);
2699
2700             if(gammaMotherLabel < MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
2701               
2702                
2703                hESDTruePrimaryMotherInvMassPt[fiCut]->Fill( Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2704                hESDTruePrimaryMotherW0WeightingInvMassPt[fiCut]->Fill( Pi0Candidate->M(), Pi0Candidate->Pt() );
2705                
2706                hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
2707                if(isTruePi0){ // Only primaries for unfolding
2708                   hESDTruePrimaryPi0DalitzESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
2709                }
2710             }
2711             else { // Secondary Meson
2712               Float_t weightedSec= 1;
2713
2714               if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2715                   Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gammaMotherLabel))->GetMother(0);
2716                   if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(gammaMotherLabel)->GetPdgCode()==310){
2717                     weightedSec= ((AliConversionCuts*)fCutGammaArray->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
2718                   }
2719               }
2720
2721               hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec); 
2722             }
2723          }
2724
2725          
2726          else if ( virtualGamma == 0 ){
2727
2728               Float_t weighted= 1;
2729
2730              if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) {
2731               if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack,fInputEvent)){
2732                 if (((TParticle*)MCStack->Particle(gammaMotherLabel))->Pt()>0.005){
2733                     weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gammaMotherLabel,fMCStack,fInputEvent);
2734                 }
2735               }
2736             }
2737
2738             hESDTrueMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted); // Pi0 from GG
2739
2740             if( gammaMotherLabel < MCStack->GetNprimary() ){
2741                 hESDTruePrimaryMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
2742             }
2743             else {
2744             
2745             Float_t weightedSec= 1;
2746            
2747             if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2748                 Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gammaMotherLabel))->GetMother(0);
2749                    if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(gammaMotherLabel)->GetPdgCode()==310){
2750                             weightedSec= ((AliConversionCuts*)fCutGammaArray->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
2751                    }
2752             }
2753                     hESDTrueSecondaryMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
2754             }
2755          }
2756       }
2757
2758       if(!isTruePi0 && !isTrueEta && massCutAccept ){ // Background
2759          if(gammaMotherLabel>-1 && virtualGammaMotherLabel>-1 && virtualGamma == 0){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
2760             hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2761          } else { // No photon or without mother
2762             hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
2763          }
2764       }
2765    }
2766 }
2767
2768
2769 //________________________________________________________________________
2770 void AliAnalysisTaskGammaConvDalitzV1::MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex){
2771    //see header file for documentation
2772
2773    Double_t dx = vertex->fX - fESDEvent->GetPrimaryVertex()->GetX();
2774    Double_t dy = vertex->fY - fESDEvent->GetPrimaryVertex()->GetY();
2775    Double_t dz = vertex->fZ - fESDEvent->GetPrimaryVertex()->GetZ();
2776
2777    Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
2778    particle->SetConversionPoint(movedPlace);
2779 }
2780
2781
2782 //________________________________________________________________________
2783 void AliAnalysisTaskGammaConvDalitzV1::CountESDTracks(){
2784
2785    // Using standard function for setting Cuts
2786    Bool_t selectPrimaries=kTRUE;
2787    AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
2788    EsdTrackCuts->SetMaxDCAToVertexZ(2);
2789    EsdTrackCuts->SetEtaRange(-0.8, 0.8);
2790    EsdTrackCuts->SetPtRange(0.15);
2791    EsdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kBoth);
2792
2793    fNumberOfESDTrackskBoth = 0;
2794    for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
2795       AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
2796       if(!curTrack) continue;
2797       if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTrackskBoth++;
2798    }
2799    delete EsdTrackCuts;
2800    EsdTrackCuts=0x0;
2801
2802    return;
2803 }
2804
2805 //_____________________________________________________________________________
2806 void AliAnalysisTaskGammaConvDalitzV1::ProcessMCParticles()
2807 {
2808
2809    // Loop over all primary MC particle
2810
2811    for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
2812      
2813      
2814       TParticle* particle = (TParticle *)fMCStack->Particle(i);
2815       if (!particle) continue;
2816       
2817       
2818       Bool_t mcIsFromMB = kTRUE;
2819       Int_t isMCFromMBHeader = -1;
2820            
2821       if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0) {
2822          isMCFromMBHeader
2823             = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i,fMCStack,fInputEvent);
2824          if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
2825          if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
2826       }    
2827     
2828       if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
2829           hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
2830       }
2831       
2832       if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kTRUE)){
2833          hMCConvGammaPt[fiCut]->Fill(particle->Pt());
2834          if(fDoMesonQA) hMCConvGammaEta[fiCut]->Fill( particle->Eta());
2835          
2836          if(mcIsFromMB){
2837             hMCConvGammaRSPt[fiCut]->Fill(particle->Pt());
2838          }
2839       } // Converted MC Gamma
2840         
2841       if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(i,fMCStack)){
2842                         if( particle->GetPdgCode() == -11) {
2843                           hMCAllPositronsPt[fiCut]->Fill(particle->Pt()); // All positrons
2844                           if(fDoMesonQA) hMCAllPositronsEta[fiCut]->Fill( particle->Eta() );
2845                         }
2846                         if( particle->GetPdgCode() ==  11){
2847                           hMCAllElectronsPt[fiCut]->Fill(particle->Pt()); // All electrons
2848                           if (fDoMesonQA)  hMCAllElectronsEta[fiCut]->Fill(particle->Eta()); // All electrons
2849                         }
2850                           
2851       }
2852         
2853       if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMC( particle,fMCStack,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift() ) ){
2854         
2855                 Float_t weighted= 1;
2856                     
2857                     if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2858                         if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
2859                           if (particle->Pt()>0.005){
2860                             weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack,fInputEvent);
2861                           }
2862                         }
2863                     }
2864
2865                         if(particle->GetPdgCode() == 111)hMCPi0GGPt[fiCut]->Fill( particle->Pt() , weighted); // All MC Pi0 GG decay
2866                         if(particle->GetPdgCode() == 221)hMCEtaGGPt[fiCut]->Fill( particle->Pt() , weighted); // All MC Eta GG decay
2867       }
2868       
2869       
2870       Int_t labelgamma    = -1;
2871       Int_t labelelectron = -1;
2872       Int_t labelpositron = -1;
2873
2874
2875       if( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCDalitz(particle,fMCStack,labelelectron,labelpositron,labelgamma,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift())  )
2876       {
2877         
2878         
2879                     Float_t weighted= 1;
2880                    if( ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoWeights() ) { 
2881                         if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack,fInputEvent)){
2882                           if (particle->Pt()>0.005){
2883                             weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack,fInputEvent);
2884                           }
2885                         }
2886                    }
2887                         if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt(), weighted); // All MC Pi0
2888                         if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt(), weighted); // All MC Eta
2889                         
2890                         // Check the acceptance for gamma and electrons
2891                         
2892                                          
2893                                 TParticle *gamma    = fMCStack->Particle(labelgamma);
2894                                 TParticle *electron = fMCStack->Particle(labelelectron);
2895                                 TParticle *positron = fMCStack->Particle(labelpositron);
2896                                 
2897            
2898                                 if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(gamma,fMCStack,kFALSE) &&
2899                                    ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelelectron,fMCStack) &&
2900                                    ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelpositron,fMCStack) ) {
2901                                     
2902                                      Double_t massDalitz = -1;
2903                                     
2904                                       if( fDoMesonQA){
2905                                         
2906                                         TLorentzVector TLVEpos,TLVEneg,TLVDalitz;       
2907                                         Double_t electronMass = TDatabasePDG::Instance()->GetParticle(  ::kElectron   )->Mass();
2908                                         
2909                                         TLVEpos.SetXYZM(positron->Px(),positron->Py(),positron->Pz(),electronMass);
2910                                         TLVEneg.SetXYZM(electron->Px(),electron->Py(),electron->Pz(),electronMass);
2911                                         TLVDalitz =  TLVEpos + TLVEneg ;
2912                                         massDalitz = TLVDalitz.M();
2913                                       }
2914                                   
2915                                   
2916                                   
2917                                    
2918                                         if(particle->GetPdgCode() == 111){ 
2919                                           
2920                                                 hMCPi0InAccPt[fiCut]->Fill(particle->Pt() , weighted); // MC Pi0Dalitz with gamma and e+e- in acc
2921                                                 hMCPi0DalitzGammaPt[fiCut]->Fill( gamma->Pt() );
2922                                                 hMCPi0DalitzPositronPt[fiCut]->Fill( positron->Pt()  );
2923                                                 hMCPi0DalitzElectronPt[fiCut]->Fill( electron->Pt()  );
2924                                                 
2925                                                 if ( fDoMesonQA )hMCPi0EposEnegInvMassPt[fiCut]->Fill(massDalitz,particle->Pt());
2926                                                 
2927                                                 
2928                                         }
2929                                         if(particle->GetPdgCode() == 221){ 
2930                                               hMCEtaInAccPt[fiCut]->Fill(particle->Pt(), weighted ); // MC EtaDalitz with gamma and e+e- in acc
2931                                               if( fDoMesonQA ) hMCEtaEposEnegInvMassPt[fiCut]->Fill( massDalitz, particle->Pt());
2932                                         }
2933                                 }
2934                 
2935                         
2936         }
2937                 Int_t labelgammaChiC=-1;
2938                 Int_t labelpositronChiC=-1;
2939                 Int_t labelelectronChiC=-1;
2940
2941                 if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCChiC(particle,fMCStack,labelelectronChiC,labelpositronChiC,labelgammaChiC,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift())){
2942                   
2943                         hMCChiCPt[fiCut]->Fill(particle->Pt()); // All MC ChiC
2944                         TParticle * gammaChiC  =fMCStack->Particle(labelgammaChiC);
2945
2946                         if( ((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC( gammaChiC,fMCStack,kFALSE) &&
2947                             ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelelectronChiC,fMCStack) && 
2948                             ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelpositronChiC,fMCStack) ){
2949                                 hMCChiCInAccPt[fiCut]->Fill(particle->Pt()); // All MC ChiC
2950                         } 
2951                 }
2952         }
2953 }
2954 //_____________________________________________________________________________
2955 Bool_t AliAnalysisTaskGammaConvDalitzV1::IsDalitz(TParticle *fMCMother) const
2956 {
2957
2958         if( fMCMother->GetNDaughters() != 3 ) return kFALSE;
2959         if( fMCMother->GetPdgCode() != 111 && fMCMother->GetPdgCode() != 221 ) return kFALSE;
2960         
2961         
2962         TParticle *positron = 0x0;
2963         TParticle *electron = 0x0;
2964         TParticle *gamma    = 0x0;
2965         
2966         for(Int_t index= fMCMother->GetFirstDaughter();index<= fMCMother->GetLastDaughter();index++){                           
2967
2968                 TParticle* temp = (TParticle*)fMCStack->Particle( index );
2969                 
2970                 switch( temp->GetPdgCode() ) {
2971                 case ::kPositron:
2972                         positron =  temp;
2973                         break;
2974                 case ::kElectron:
2975                         electron =  temp;
2976                         break;
2977                 case ::kGamma:
2978                         gamma    =  temp;
2979                         break;
2980                 }
2981         }
2982   
2983         if( positron && electron && gamma) return kTRUE;
2984         
2985         return kFALSE;
2986 }
2987 //_____________________________________________________________________________________
2988 Bool_t AliAnalysisTaskGammaConvDalitzV1::IsPi0DalitzDaughter( Int_t label ) const
2989 {
2990 //
2991 // Returns true if the particle comes from Pi0 -> e+ e- gamma
2992 //
2993         
2994         Int_t motherLabel = fMCStack->Particle( label )->GetMother(0);
2995         
2996         if( motherLabel < 0 || motherLabel >= fMCStack->GetNtrack() ) return kFALSE;
2997         
2998         TParticle* mother = fMCStack->Particle( motherLabel );
2999         
3000         if( mother->GetPdgCode() != 111 ) return kFALSE;
3001         
3002         if( IsDalitz( mother ) ) return kTRUE;
3003         
3004         
3005         return kFALSE;
3006         
3007        
3008 }
3009
3010 void AliAnalysisTaskGammaConvDalitzV1::FillElectronQAHistos(AliAODConversionMother *Pi0Candidate,AliAODConversionPhoton *Vgamma) const
3011 {
3012   
3013
3014               AliESDtrack *positronVgamma = 0;
3015               AliESDtrack *electronVgamma = 0;
3016               
3017               Double_t clsToFPos = -1.0;
3018               Double_t clsToFNeg = -1.0;
3019               
3020              
3021               Double_t NumClsITSPos = -1.0;
3022               Double_t NumClsITSNeg = -1.0;
3023               Double_t NumClsTPCPos = -1.0;
3024               Double_t NumClsTPCNeg = -1.0;
3025               Double_t nCrossedRowsTPCPos = -1.0;
3026               Double_t nCrossedRowsTPCNeg = -1.0;
3027               
3028               
3029                       
3030               Float_t dcaToVertexXYPos = -1.0;
3031               Float_t dcaToVertexZPos  = -1.0;
3032               Float_t dcaToVertexXYNeg = -1.0;
3033               Float_t dcaToVertexZNeg  = -1.0;
3034               
3035               Double_t nSigmaPosTPC = -999.;
3036               Double_t nSigmaNegTPC = -999.;
3037               
3038               positronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelPositive() );
3039               electronVgamma = fESDEvent->GetTrack( Vgamma->GetTrackLabelNegative() );
3040               clsToFPos = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetNFindableClustersTPC(positronVgamma);
3041               clsToFNeg = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetNFindableClustersTPC(electronVgamma);
3042               
3043               nSigmaPosTPC = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetPIDResponse()->NumberOfSigmasTPC(positronVgamma, AliPID::kElectron) ;
3044               nSigmaNegTPC = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetPIDResponse()->NumberOfSigmasTPC(electronVgamma, AliPID::kElectron) ;
3045                
3046               
3047               
3048               NumClsITSPos =  positronVgamma->GetNcls(0); //Get number of ITS clusters
3049               NumClsITSNeg =  electronVgamma->GetNcls(0);
3050               NumClsTPCPos =  positronVgamma->GetNcls(1);  //Get number of TPC clusters
3051               NumClsTPCNeg =  electronVgamma->GetNcls(1);
3052               
3053               nCrossedRowsTPCPos = positronVgamma->GetTPCCrossedRows();
3054               nCrossedRowsTPCNeg = electronVgamma->GetTPCCrossedRows();
3055  
3056               if( Pi0Candidate->M() > 0.1 && Pi0Candidate->M() < 0.145 ){
3057               
3058                   hESDEposEnegAfterMassCutInvMassPi0Pt[fiCut]->Fill(Vgamma->GetMass(),Pi0Candidate->Pt());
3059                   
3060               }
3061               
3062               
3063               Float_t bPos[2];
3064               Float_t bCovPos[3];
3065               positronVgamma->GetImpactParameters(bPos,bCovPos);
3066               
3067               if (bCovPos[0]<=0 || bCovPos[2]<=0) {
3068                   AliDebug(1, "Estimated b resolution lower or equal zero!");
3069                   bCovPos[0]=0; bCovPos[2]=0;
3070                }
3071               
3072                Float_t bNeg[2];
3073                Float_t bCovNeg[3];
3074                positronVgamma->GetImpactParameters(bNeg,bCovNeg);
3075                
3076                if (bCovNeg[0]<=0 || bCovNeg[2]<=0) {
3077                   AliDebug(1, "Estimated b resolution lower or equal zero!");
3078                   bCovNeg[0]=0; bCovNeg[2]=0;
3079                 }
3080               
3081                dcaToVertexXYPos = bPos[0];
3082                dcaToVertexZPos  = bPos[1];
3083                dcaToVertexXYNeg = bNeg[0];
3084                dcaToVertexZNeg  = bNeg[1];
3085               
3086                hESDDalitzElectronAfterPt[fiCut]->Fill(  electronVgamma->Pt()  );
3087                hESDDalitzPositronAfterPt[fiCut]->Fill(  positronVgamma->Pt()  );
3088                           
3089                hESDDalitzElectronAfterEta[fiCut]->Fill( electronVgamma->Eta() );
3090                hESDDalitzPositronAfterEta[fiCut]->Fill( positronVgamma->Eta() );
3091                  
3092                hESDDalitzElectronAfterPhi[fiCut]->Fill( electronVgamma->Phi() );
3093                hESDDalitzPositronAfterPhi[fiCut]->Fill( positronVgamma->Phi() );
3094                       
3095                hESDDalitzElectronAfterNFindClsTPC[fiCut]->Fill(clsToFNeg,electronVgamma->Pt());
3096                hESDDalitzPositronAfterNFindClsTPC[fiCut]->Fill(clsToFPos,positronVgamma->Pt());
3097                
3098                hESDDalitzElectronAfterNClsTPC[fiCut]->Fill(  NumClsTPCNeg,electronVgamma->Pt());
3099                hESDDalitzPositronAfterNClsTPC[fiCut]->Fill(  NumClsTPCPos,positronVgamma->Pt());
3100                
3101                hESDDalitzElectronAfterNCrossedRowsTPC[fiCut]->Fill( nCrossedRowsTPCNeg, electronVgamma->Pt() );
3102                hESDDalitzPositronAfterNCrossedRowsTPC[fiCut]->Fill( nCrossedRowsTPCPos, positronVgamma->Pt() );
3103                
3104                hESDDalitzElectronAfterNClsITS[fiCut]->Fill( NumClsITSNeg);
3105                hESDDalitzPositronAfterNClsITS[fiCut]->Fill( NumClsITSPos);
3106                
3107                hESDDalitzPosEleAfterDCAxy[fiCut]->Fill(  dcaToVertexXYNeg, electronVgamma->Pt() );
3108                hESDDalitzPosEleAfterDCAz[fiCut]->Fill(   dcaToVertexZNeg,  electronVgamma->Pt() );
3109                hESDDalitzPosEleAfterDCAxy[fiCut]->Fill(  dcaToVertexXYPos, positronVgamma->Pt() );
3110                hESDDalitzPosEleAfterDCAz[fiCut]->Fill(   dcaToVertexZPos,  positronVgamma->Pt() );
3111                       
3112                hESDDalitzElectronAfterTPCdEdxVsP[fiCut]->Fill( electronVgamma->P(),nSigmaNegTPC);
3113                hESDDalitzPositronAfterTPCdEdxVsP[fiCut]->Fill( positronVgamma->P(), nSigmaPosTPC);
3114                
3115                hESDDalitzElectronAfterTPCdEdxVsEta[fiCut]->Fill( electronVgamma->Eta(),nSigmaNegTPC);
3116                hESDDalitzPositronAfterTPCdEdxVsEta[fiCut]->Fill( positronVgamma->Eta(),nSigmaPosTPC);
3117                
3118                hESDDalitzElectronAfterTPCdEdxVsPhi[fiCut]->Fill( electronVgamma->Phi(),nSigmaNegTPC);
3119                hESDDalitzPositronAfterTPCdEdxVsPhi[fiCut]->Fill( positronVgamma->Phi(),nSigmaPosTPC);
3120                
3121                               
3122                hESDDalitzElectronAfterTPCdEdxSignalVsP[fiCut]->Fill( electronVgamma->P(), TMath::Abs(electronVgamma->GetTPCsignal()));
3123                hESDDalitzPositronAfterTPCdEdxSignalVsP[fiCut]->Fill( positronVgamma->P(), TMath::Abs(positronVgamma->GetTPCsignal()));
3124                     
3125                
3126   
3127 }
3128
3129
3130 //_____________________________________________________________________________
3131 Double_t AliAnalysisTaskGammaConvDalitzV1::GetPsiPair( const AliESDtrack *trackPos, const AliESDtrack *trackNeg ) const
3132 {
3133    //
3134    // This angle is a measure for the contribution of the opening in polar
3135    // direction ?0 to the opening angle ? Pair
3136    //
3137    // Ref. Measurement of photons via conversion pairs with the PHENIX experiment at RHIC
3138    //      Mas   ter Thesis. Thorsten Dahms. 2005
3139    // https://twiki.cern.ch/twiki/pub/ALICE/GammaPhysicsPublications/tdahms_thesis.pdf
3140    //
3141    Double_t momPos[3];
3142    Double_t momNeg[3];
3143    if( trackPos->GetConstrainedPxPyPz(momPos) == 0 ) trackPos->GetPxPyPz( momPos );
3144    if( trackNeg->GetConstrainedPxPyPz(momNeg) == 0 ) trackNeg->GetPxPyPz( momNeg );
3145
3146    TVector3 posDaughter;
3147    TVector3 negDaughter;
3148
3149    posDaughter.SetXYZ( momPos[0], momPos[1], momPos[2] );
3150    negDaughter.SetXYZ( momNeg[0], momNeg[1], momNeg[2] );
3151
3152    Double_t deltaTheta = negDaughter.Theta() - posDaughter.Theta();
3153    Double_t openingAngle =  posDaughter.Angle( negDaughter );  //TMath::ACos( posDaughter.Dot(negDaughter)/(negDaughter.Mag()*posDaughter.Mag()) );
3154
3155    if( openingAngle < 1e-20 ) return 0.;
3156
3157    Double_t psiAngle = TMath::ASin( deltaTheta/openingAngle );
3158
3159    return psiAngle;
3160 }