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