updated task to make it possible to run on the grid
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliAnalysisTaskGammaConvV1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: Martin Wilde, Daniel Lohner                                    *
5  * Version 1.0                                                            *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////
17 //---------------------------------------------
18 // Class used to do analysis on conversion pairs
19 //---------------------------------------------
20 ///////////////////////////////////////////////
21 #include "TChain.h"
22 #include "TTree.h"
23 #include "TH1F.h"
24 #include "TH2F.h"
25 #include "TH3F.h"
26 #include "THnSparse.h"
27 #include "TCanvas.h"
28 #include "TNtuple.h"
29 #include "AliAnalysisTask.h"
30 #include "AliAnalysisManager.h"
31 #include "AliESDEvent.h"
32 #include "AliESDInputHandler.h"
33 #include "AliMCEventHandler.h"
34 #include "AliMCEvent.h"
35 #include "AliMCParticle.h"
36 #include "AliCentrality.h"
37 #include "AliESDVZERO.h"
38 #include "AliESDpid.h"
39 #include "AliAnalysisTaskGammaConvV1.h"
40 #include "AliVParticle.h"
41 #include "AliESDtrackCuts.h"
42 #include "AliKFVertex.h"
43 #include "AliV0ReaderV1.h"
44 #include "AliGenCocktailEventHeader.h"
45 #include "AliConversionAODBGHandlerRP.h"
46
47 ClassImp(AliAnalysisTaskGammaConvV1)
48
49 //________________________________________________________________________
50 AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
51    fV0Reader(NULL),
52    fBGHandler(NULL),
53    fBGHandlerRP(NULL),
54    fInputEvent(NULL),
55    fMCEvent(NULL),
56    fMCStack(NULL),
57    fCutFolder(NULL),
58    fESDList(NULL),
59    fBackList(NULL),
60    fMotherList(NULL),
61    fTrueList(NULL),
62    fMCList(NULL),
63    fHeaderNameList(NULL),
64    fOutputContainer(0),
65    fReaderGammas(NULL),
66    fGammaCandidates(NULL),
67    fCutArray(NULL),
68    fConversionCuts(NULL),
69    fMesonCutArray(NULL),
70    fMesonCuts(NULL),
71    hESDConvGammaPt(NULL),
72    hESDConvGammaR(NULL),
73    hESDMotherInvMassPt(NULL),
74    sESDMotherInvMassPtZM(NULL),
75    hESDMotherBackInvMassPt(NULL),
76    sESDMotherBackInvMassPtZM(NULL),
77    hESDMotherInvMassEalpha(NULL),
78    hMCAllGammaPt(NULL),
79    hMCDecayGammaPi0Pt(NULL),
80    hMCDecayGammaRhoPt(NULL),
81    hMCDecayGammaEtaPt(NULL),
82    hMCDecayGammaOmegaPt(NULL),
83    hMCDecayGammaEtapPt(NULL),
84    hMCDecayGammaPhiPt(NULL),
85    hMCDecayGammaSigmaPt(NULL),
86    hMCConvGammaPt(NULL),
87    hMCConvGammaR(NULL),
88    hMCConvGammaEta(NULL),
89    hMCConvGammaRSPt(NULL),
90    hMCConvGammaRSR(NULL),
91    hMCConvGammaRSEta(NULL),
92    hMCPi0Pt(NULL),
93    hMCEtaPt(NULL),
94    hMCPi0InAccPt(NULL),
95    hMCEtaInAccPt(NULL),
96    hESDTrueMotherInvMassPt(NULL),
97    hESDTruePi0FromEtaInvMassPt(NULL),
98    hESDTruePrimaryMotherInvMassPt(NULL),
99    hESDTruePrimaryMotherInvMassMCPt(NULL),
100    hESDTruePrimaryPi0ESDPtMCPt(NULL),
101    hESDTruePrimaryEtaESDPtMCPt(NULL),
102    hESDTrueSecondaryMotherInvMassPt(NULL),
103    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
104    hESDTrueK0sWithPi0DaughterMCPt(NULL),
105    hESDTrueSecondaryMotherFromEtaInvMassPt(NULL),
106    hESDTrueEtaWithPi0DaughterMCPt(NULL),
107    hESDTrueBckGGInvMassPt(NULL),
108    hESDTrueBckContInvMassPt(NULL),
109    hESDTrueMotherDalitzInvMassPt(NULL),
110    hESDTrueConvGammaPt(NULL),
111    hESDCombinatorialPt(NULL),
112    hESDTruePrimaryConvGammaPt(NULL),
113    hESDTruePrimaryConvGammaR(NULL),
114    hESDTruePrimaryConvGammaEta(NULL),
115    hESDTruePrimaryConvGammaESDPtMCPt(NULL),
116    hESDTruePrimaryConvGammaRSESDPtMCPt(NULL),
117    hESDTrueSecondaryConvGammaPt(NULL),
118    hESDTrueSecondaryConvGammaR(NULL),
119    hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
120    hNEvents(NULL),
121    hNGoodESDTracks(NULL),
122    hNGammaCandidates(NULL),
123    hNV0Tracks(NULL),
124    fRandom(0),
125    fnGammaCandidates(0),
126    fUnsmearedPx(NULL),
127    fUnsmearedPy(NULL),
128    fUnsmearedPz(NULL),
129    fUnsmearedE(NULL),
130    fnCuts(0),
131    fiCut(0),
132    fNumberOfESDTracks(0),
133    fMoveParticleAccordingToVertex(kTRUE),
134    fIsHeavyIon(kFALSE),
135    fDoMesonAnalysis(kTRUE),
136    fIsFromMBHeader(kTRUE)
137 {
138
139 }
140
141 //________________________________________________________________________
142 AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
143    AliAnalysisTaskSE(name),
144    fV0Reader(NULL),
145    fBGHandler(NULL),
146    fBGHandlerRP(NULL),
147    fInputEvent(NULL),
148    fMCEvent(NULL),
149    fMCStack(NULL),
150    fCutFolder(NULL),
151    fESDList(NULL),
152    fBackList(NULL),
153    fMotherList(NULL),
154    fTrueList(NULL),
155    fMCList(NULL),
156    fHeaderNameList(NULL),
157    fOutputContainer(0),
158    fReaderGammas(NULL),
159    fGammaCandidates(NULL),
160    fCutArray(NULL),
161    fConversionCuts(NULL),
162    fMesonCutArray(NULL),
163    fMesonCuts(NULL),
164    hESDConvGammaPt(NULL),
165    hESDConvGammaR(NULL),
166    hESDMotherInvMassPt(NULL),
167    sESDMotherInvMassPtZM(NULL),
168    hESDMotherBackInvMassPt(NULL),
169    sESDMotherBackInvMassPtZM(NULL),
170    hESDMotherInvMassEalpha(NULL),
171    hMCAllGammaPt(NULL),
172    hMCDecayGammaPi0Pt(NULL),
173    hMCDecayGammaRhoPt(NULL),
174    hMCDecayGammaEtaPt(NULL),
175    hMCDecayGammaOmegaPt(NULL),
176    hMCDecayGammaEtapPt(NULL),
177    hMCDecayGammaPhiPt(NULL),
178    hMCDecayGammaSigmaPt(NULL),
179    hMCConvGammaPt(NULL),
180    hMCConvGammaR(NULL),
181    hMCConvGammaEta(NULL),
182    hMCConvGammaRSPt(NULL),
183    hMCConvGammaRSR(NULL),
184    hMCConvGammaRSEta(NULL),
185    hMCPi0Pt(NULL),
186    hMCEtaPt(NULL),
187    hMCPi0InAccPt(NULL),
188    hMCEtaInAccPt(NULL),
189    hESDTrueMotherInvMassPt(NULL),
190    hESDTruePi0FromEtaInvMassPt(NULL),
191    hESDTruePrimaryMotherInvMassPt(NULL),
192    hESDTruePrimaryMotherInvMassMCPt(NULL),
193    hESDTruePrimaryPi0ESDPtMCPt(NULL),
194    hESDTruePrimaryEtaESDPtMCPt(NULL),
195    hESDTrueSecondaryMotherInvMassPt(NULL),
196    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
197    hESDTrueK0sWithPi0DaughterMCPt(NULL),
198    hESDTrueSecondaryMotherFromEtaInvMassPt(NULL),
199    hESDTrueEtaWithPi0DaughterMCPt(NULL),
200    hESDTrueBckGGInvMassPt(NULL),
201    hESDTrueBckContInvMassPt(NULL),
202    hESDTrueMotherDalitzInvMassPt(NULL),
203    hESDTrueConvGammaPt(NULL),
204    hESDCombinatorialPt(NULL),
205    hESDTruePrimaryConvGammaPt(NULL),
206    hESDTruePrimaryConvGammaR(NULL),
207    hESDTruePrimaryConvGammaEta(NULL),
208    hESDTruePrimaryConvGammaESDPtMCPt(NULL),
209    hESDTruePrimaryConvGammaRSESDPtMCPt(NULL),
210    hESDTrueSecondaryConvGammaPt(NULL),
211    hESDTrueSecondaryConvGammaR(NULL),
212    hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
213    hNEvents(NULL),
214    hNGoodESDTracks(NULL),
215    hNGammaCandidates(NULL),
216    hNV0Tracks(NULL),
217    fRandom(0),
218    fnGammaCandidates(0),
219    fUnsmearedPx(NULL),
220    fUnsmearedPy(NULL),
221    fUnsmearedPz(NULL),
222    fUnsmearedE(NULL),
223    fnCuts(0),
224    fiCut(0),
225    fNumberOfESDTracks(0),
226    fMoveParticleAccordingToVertex(kTRUE),
227    fIsHeavyIon(kFALSE),
228    fDoMesonAnalysis(kTRUE),
229    fIsFromMBHeader(kTRUE)
230 {
231    // Define output slots here
232    DefineOutput(1, TList::Class());
233 }
234
235 AliAnalysisTaskGammaConvV1::~AliAnalysisTaskGammaConvV1()
236 {
237    if(fGammaCandidates){
238       delete fGammaCandidates;
239       fGammaCandidates = 0x0;
240    }
241    if(fBGHandler){
242       delete[] fBGHandler;
243       fBGHandler = 0x0;
244    }
245    if(fBGHandlerRP){
246       delete[] fBGHandlerRP;
247       fBGHandlerRP = 0x0;
248    }
249 }
250 //___________________________________________________________
251 void AliAnalysisTaskGammaConvV1::InitBack(){
252
253    Double_t *zBinLimitsArray = new Double_t[9];
254    zBinLimitsArray[0] = -50.00;
255    zBinLimitsArray[1] = -3.375;
256    zBinLimitsArray[2] = -1.605;
257    zBinLimitsArray[3] = -0.225;
258    zBinLimitsArray[4] = 1.065;
259    zBinLimitsArray[5] = 2.445;
260    zBinLimitsArray[6] = 4.245;
261    zBinLimitsArray[7] = 50.00;
262    zBinLimitsArray[8] = 1000.00;
263
264    Double_t *multiplicityBinLimitsArrayTracks = new Double_t[6];
265    multiplicityBinLimitsArrayTracks[0] = 0;
266    multiplicityBinLimitsArrayTracks[1] = 8.5;
267    multiplicityBinLimitsArrayTracks[2] = 16.5;
268    multiplicityBinLimitsArrayTracks[3] = 27.5;
269    multiplicityBinLimitsArrayTracks[4] = 41.5;
270    multiplicityBinLimitsArrayTracks[5] = 200.;
271    if(fIsHeavyIon){
272       multiplicityBinLimitsArrayTracks[0] = 0;
273       multiplicityBinLimitsArrayTracks[1] = 200.;
274       multiplicityBinLimitsArrayTracks[2] = 500.;
275       multiplicityBinLimitsArrayTracks[3] = 1000.;
276       multiplicityBinLimitsArrayTracks[4] = 1500.;
277       multiplicityBinLimitsArrayTracks[5] = 5000.;
278    }
279
280    Double_t *multiplicityBinLimitsArrayV0s = new Double_t[5];
281    multiplicityBinLimitsArrayV0s[0] = 2;
282    multiplicityBinLimitsArrayV0s[1] = 3;
283    multiplicityBinLimitsArrayV0s[2] = 4;
284    multiplicityBinLimitsArrayV0s[3] = 5;
285    multiplicityBinLimitsArrayV0s[4] = 9999;
286    if(fIsHeavyIon){
287       multiplicityBinLimitsArrayV0s[0] = 2;
288       multiplicityBinLimitsArrayV0s[1] = 10;
289       multiplicityBinLimitsArrayV0s[2] = 30;
290       multiplicityBinLimitsArrayV0s[3] = 50;
291       multiplicityBinLimitsArrayV0s[4] = 9999;
292    }
293
294    const Int_t nDim = 4;
295    Int_t nBins[nDim] = {800,250,8,5};
296    Double_t xMin[nDim] = {0,0, 0,0};
297    Double_t xMax[nDim] = {0.8,25,8,5};
298
299    sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
300    sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
301
302    fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
303    fBGHandlerRP = new AliConversionAODBGHandlerRP*[fnCuts];
304    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
305       if (((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
306          TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
307          TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
308          fBackList[iCut] = new TList();
309          fBackList[iCut]->SetName(Form("%s_%s Back histograms",cutstring.Data(),cutstringMeson.Data()));
310          fBackList[iCut]->SetOwner(kTRUE);
311          fCutFolder[iCut]->Add(fBackList[iCut]);
312
313          sESDMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
314          sESDMotherBackInvMassPtZM[iCut]->Sumw2();
315          fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
316
317          fMotherList[iCut] = new TList();
318          fMotherList[iCut]->SetName(Form("%s_%s Mother histograms",cutstring.Data(),cutstringMeson.Data()));
319          fMotherList[iCut]->SetOwner(kTRUE);
320          fCutFolder[iCut]->Add(fMotherList[iCut]);
321
322          sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
323          sESDMotherInvMassPtZM[iCut]->Sumw2();
324          fMotherList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
325
326          if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
327             if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity()){
328                fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
329                fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
330                fBGHandlerRP[iCut] = NULL;
331             }
332             else{
333                fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
334                fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
335                fBGHandlerRP[iCut] = NULL;
336             }
337          }
338          else{
339             fBGHandlerRP[iCut] = new AliConversionAODBGHandlerRP(
340                                                                  ((AliConversionCuts*)fCutArray->At(fiCut))->IsHeavyIon(),
341                                                                  ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity(),
342                                                                  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
343             fBGHandler[iCut] = NULL;
344          }
345       }
346    }
347 }
348 //________________________________________________________________________
349 void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
350 {
351    TH1::SetDefaultSumw2(kTRUE);
352
353    // Create histograms
354    if(fOutputContainer != NULL){
355       delete fOutputContainer;
356       fOutputContainer = NULL;
357    }
358    if(fOutputContainer == NULL){
359       fOutputContainer = new TList();
360       fOutputContainer->SetOwner(kTRUE);
361    }
362
363    // Array of current cut's gammas
364    fGammaCandidates = new TList();
365
366    fCutFolder = new TList*[fnCuts];
367    fESDList = new TList*[fnCuts];
368    fBackList = new TList*[fnCuts];
369    fMotherList = new TList*[fnCuts];
370    hESDConvGammaPt = new TH1F*[fnCuts];
371    hESDConvGammaR = new TH1F*[fnCuts];
372    hNEvents = new TH1I*[fnCuts];
373    hNGoodESDTracks = new TH1I*[fnCuts];
374    hNGammaCandidates = new TH1I*[fnCuts];
375    hNV0Tracks = new TH1I*[fnCuts];
376
377    if(fDoMesonAnalysis){
378       hESDMotherInvMassPt = new TH2F*[fnCuts];
379       hESDMotherBackInvMassPt = new TH2F*[fnCuts];
380       hESDMotherInvMassEalpha = new TH2F*[fnCuts];
381    }
382    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
383
384       TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
385       TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
386
387       fCutFolder[iCut] = new TList();
388       fCutFolder[iCut]->SetName(Form("Cut Number %s_%s",cutstring.Data(),cutstringMeson.Data()));
389       fCutFolder[iCut]->SetOwner(kTRUE);
390       fOutputContainer->Add(fCutFolder[iCut]);
391       fESDList[iCut] = new TList();
392       fESDList[iCut]->SetName(Form("%s_%s ESD histograms",cutstring.Data(),cutstringMeson.Data()));
393       fESDList[iCut]->SetOwner(kTRUE);
394       fCutFolder[iCut]->Add(fESDList[iCut]);
395
396       hNEvents[iCut] = new TH1I("NEvents","NEvents",9,-0.5,8.5);
397       hNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
398       hNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
399       hNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Missing MC");
400       hNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
401       hNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
402       hNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
403       hNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
404       hNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
405       hNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
406       fESDList[iCut]->Add(hNEvents[iCut]);
407       if(fIsHeavyIon) hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
408       else hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
409       fESDList[iCut]->Add(hNGoodESDTracks[iCut]);
410       if(fIsHeavyIon) hNGammaCandidates[iCut] = new TH1I("GammaCandidates","GammaCandidates",100,0,100);
411       else hNGammaCandidates[iCut] = new TH1I("GammaCandidates","GammaCandidates",50,0,50);
412       fESDList[iCut]->Add(hNGammaCandidates[iCut]);
413       if(fIsHeavyIon) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
414       else hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2000,0,2000);
415       fESDList[iCut]->Add(hNV0Tracks[iCut]);
416
417       hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
418       fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
419       hESDConvGammaR[iCut] = new TH1F("ESD_ConvGamma_R","ESD_ConvGamma_R",800,0,200);
420       fESDList[iCut]->Add(hESDConvGammaR[iCut]);
421
422       if(fDoMesonAnalysis){
423          hESDMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt","ESD_Mother_InvMass_Pt",800,0,0.8,250,0,25);
424          fESDList[iCut]->Add(hESDMotherInvMassPt[iCut]);
425          hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_Background_InvMass_Pt","ESD_Background_InvMass_Pt",800,0,0.8,250,0,25);
426          fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
427          hESDMotherInvMassEalpha[iCut] = new TH2F("ESD_Mother_InvMass_vs_E_alpha","ESD_Mother_InvMass_vs_E_alpha",800,0,0.8,250,0,25);
428          fESDList[iCut]->Add(hESDMotherInvMassEalpha[iCut]);
429       }
430
431    }
432    if(fDoMesonAnalysis){
433       InitBack(); // Init Background Handler
434    }
435
436    if(MCEvent()){
437       // MC Histogramms
438       fMCList = new TList*[fnCuts];
439       // True Histogramms
440       fTrueList = new TList*[fnCuts];
441       // Selected Header List
442       fHeaderNameList = new TList*[fnCuts];
443
444       hMCAllGammaPt = new TH1F*[fnCuts];
445       hMCDecayGammaPi0Pt = new TH1F*[fnCuts];
446       hMCDecayGammaRhoPt = new TH1F*[fnCuts];
447       hMCDecayGammaEtaPt = new TH1F*[fnCuts];
448       hMCDecayGammaOmegaPt = new TH1F*[fnCuts];
449       hMCDecayGammaEtapPt = new TH1F*[fnCuts];
450       hMCDecayGammaPhiPt = new TH1F*[fnCuts];
451       hMCDecayGammaSigmaPt = new TH1F*[fnCuts];
452       hMCConvGammaPt = new TH1F*[fnCuts];
453       hMCConvGammaR = new TH1F*[fnCuts];
454       hMCConvGammaEta = new TH1F*[fnCuts];
455       hMCConvGammaRSPt = new TH1F*[fnCuts];
456       hMCConvGammaRSR = new TH1F*[fnCuts];
457       hMCConvGammaRSEta = new TH1F*[fnCuts];
458       hESDTrueConvGammaPt = new TH1F*[fnCuts];
459
460       hESDCombinatorialPt = new TH2F*[fnCuts];
461       hESDTruePrimaryConvGammaPt = new TH1F*[fnCuts];
462       hESDTruePrimaryConvGammaR = new TH1F*[fnCuts];
463       hESDTruePrimaryConvGammaEta = new TH1F*[fnCuts];
464       hESDTruePrimaryConvGammaESDPtMCPt = new TH2F*[fnCuts];
465       hESDTruePrimaryConvGammaRSESDPtMCPt = new TH2F*[fnCuts];
466       hESDTrueSecondaryConvGammaPt = new TH1F*[fnCuts];
467       hESDTrueSecondaryConvGammaR = new TH1F*[fnCuts];
468       hESDTrueSecondaryConvGammaFromXFromK0sPt = new TH1F*[fnCuts];
469
470       if(fDoMesonAnalysis){
471          hMCPi0Pt = new TH1F*[fnCuts];
472          hMCEtaPt = new TH1F*[fnCuts];
473          hMCPi0InAccPt = new TH1F*[fnCuts];
474          hMCEtaInAccPt = new TH1F*[fnCuts];
475
476          hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
477          hESDTruePrimaryPi0ESDPtMCPt = new TH2F*[fnCuts];
478          hESDTruePrimaryEtaESDPtMCPt = new TH2F*[fnCuts];
479          hESDTruePrimaryMotherInvMassPt = new TH2F*[fnCuts];
480          hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
481          hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
482          hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
483          hESDTrueK0sWithPi0DaughterMCPt = new TH1F*[fnCuts];
484          hESDTrueSecondaryMotherFromEtaInvMassPt = new TH2F*[fnCuts];
485          hESDTrueEtaWithPi0DaughterMCPt = new TH1F*[fnCuts];
486          hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
487          hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
488          hESDTrueMotherDalitzInvMassPt = new TH2F*[fnCuts];
489       }
490
491       for(Int_t iCut = 0; iCut<fnCuts;iCut++){
492          TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
493          TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
494
495          fMCList[iCut] = new TList();
496          fMCList[iCut]->SetName(Form("%s_%s MC histograms",cutstring.Data(),cutstringMeson.Data()));
497          fMCList[iCut]->SetOwner(kTRUE);
498          fCutFolder[iCut]->Add(fMCList[iCut]);
499
500          hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
501          fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
502          hMCDecayGammaPi0Pt[iCut] = new TH1F("MC_DecayGammaPi0_Pt","MC_DecayGammaPi0_Pt",250,0,25);
503          fMCList[iCut]->Add(hMCDecayGammaPi0Pt[iCut]);
504          hMCDecayGammaRhoPt[iCut] = new TH1F("MC_DecayGammaRho_Pt","MC_DecayGammaRho_Pt",250,0,25);
505          fMCList[iCut]->Add(hMCDecayGammaRhoPt[iCut]);
506          hMCDecayGammaEtaPt[iCut] = new TH1F("MC_DecayGammaEta_Pt","MC_DecayGammaEta_Pt",250,0,25);
507          fMCList[iCut]->Add(hMCDecayGammaEtaPt[iCut]);
508          hMCDecayGammaOmegaPt[iCut] = new TH1F("MC_DecayGammaOmega_Pt","MC_DecayGammaOmmega_Pt",250,0,25);
509          fMCList[iCut]->Add(hMCDecayGammaOmegaPt[iCut]);
510          hMCDecayGammaEtapPt[iCut] = new TH1F("MC_DecayGammaEtap_Pt","MC_DecayGammaEtap_Pt",250,0,25);
511          fMCList[iCut]->Add(hMCDecayGammaEtapPt[iCut]);
512          hMCDecayGammaPhiPt[iCut] = new TH1F("MC_DecayGammaPhi_Pt","MC_DecayGammaPhi_Pt",250,0,25);
513          fMCList[iCut]->Add(hMCDecayGammaPhiPt[iCut]);
514          hMCDecayGammaSigmaPt[iCut] = new TH1F("MC_DecayGammaSigma_Pt","MC_DecayGammaSigma_Pt",250,0,25);
515          fMCList[iCut]->Add(hMCDecayGammaSigmaPt[iCut]);
516          hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
517          fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
518          hMCConvGammaR[iCut] = new TH1F("MC_ConvGamma_R","MC_ConvGamma_R",800,0,200);
519          fMCList[iCut]->Add(hMCConvGammaR[iCut]);
520          hMCConvGammaEta[iCut] = new TH1F("MC_ConvGamma_Eta","MC_ConvGamma_Eta",100,-4,4);
521          fMCList[iCut]->Add(hMCConvGammaEta[iCut]);
522          hMCConvGammaRSPt[iCut] = new TH1F("MC_ConvGamma_RS_Pt","MC_ConvGamma_RS_Pt",250,0,25);
523          fMCList[iCut]->Add(hMCConvGammaRSPt[iCut]);
524          hMCConvGammaRSR[iCut] = new TH1F("MC_ConvGamma_RS_R","MC_ConvGamma_RS_R",800,0,200);
525          fMCList[iCut]->Add(hMCConvGammaRSR[iCut]);
526          hMCConvGammaRSEta[iCut] = new TH1F("MC_ConvGamma_RS_Eta","MC_ConvGamma_RS_Eta",100,-4,4);
527          fMCList[iCut]->Add(hMCConvGammaRSEta[iCut]);
528
529          if(fDoMesonAnalysis){
530             hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
531             fMCList[iCut]->Add(hMCPi0Pt[iCut]);
532             hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
533             fMCList[iCut]->Add(hMCEtaPt[iCut]);
534             hMCPi0InAccPt[iCut] = new TH1F("MC_Pi0InAcc_Pt","MC_Pi0InAcc_Pt",250,0,25);
535             fMCList[iCut]->Add(hMCPi0InAccPt[iCut]);
536             hMCEtaInAccPt[iCut] = new TH1F("MC_EtaInAcc_Pt","MC_EtaInAcc_Pt",250,0,25);
537             fMCList[iCut]->Add(hMCEtaInAccPt[iCut]);
538          }
539          fTrueList[iCut] = new TList();
540          fTrueList[iCut]->SetName(Form("%s_%s True histograms",cutstring.Data(),cutstringMeson.Data()));
541          fTrueList[iCut]->SetOwner(kTRUE);
542          fCutFolder[iCut]->Add(fTrueList[iCut]);
543
544          hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
545          fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
546
547          hESDCombinatorialPt[iCut] = new TH2F("ESD_TrueCombinatorial_Pt","ESD_TrueCombinatorial_Pt",250,0,25,16,-0.5,15.5);
548          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 1,"Elec+Elec");
549          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 2,"Elec+Pion");
550          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 3,"Elec+Kaon");
551          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 4,"Elec+Proton");
552          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 5,"Elec+Muon");
553          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 6,"Pion+Pion");
554          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 7,"Pion+Kaon");
555          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 8,"Pion+Proton");
556          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 9,"Pion+Muon");
557          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(10,"Kaon+Kaon");
558          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(11,"Kaon+Proton");
559          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(12,"Kaon+Muon");
560          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(13,"Proton+Proton");
561          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(14,"Proton+Muon");
562          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(15,"Muon+Muon");
563          hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(16,"Rest");
564          fTrueList[iCut]->Add(hESDCombinatorialPt[iCut]);
565          hESDTruePrimaryConvGammaPt[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Pt","ESD_TruePrimaryConvGamma_Pt",250,0,25);
566          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaPt[iCut]);
567          hESDTruePrimaryConvGammaR[iCut] = new TH1F("ESD_TruePrimaryConvGamma_R","ESD_TruePrimaryConvGamma_R",800,0,200);
568          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaR[iCut]);
569          hESDTruePrimaryConvGammaEta[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Eta","ESD_TruePrimaryConvGamma_Eta",100,-4,4);
570          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaEta[iCut]);
571          hESDTrueSecondaryConvGammaPt[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_Pt","ESD_TrueSecondaryConvGamma_Pt",250,0,25);
572          fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaPt[iCut]);
573          hESDTrueSecondaryConvGammaR[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_R","ESD_TrueSecondaryConvGamma_R",800,0,200);
574          fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaR[iCut]);
575          hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut]
576             = new TH1F("ESD_TrueSecondaryConvGammaFromXFromK0s_Pt", "ESD_TrueSecondaryConvGammaFromXFromK0s_Pt",250,0,25);
577          fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut]);
578          hESDTruePrimaryConvGammaESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryConvGammaESD_PtMCPt", "ESD_TruePrimaryConvGammaESD_PtMCPt",250,0,25,250,0,25);
579          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaESDPtMCPt[iCut]);
580          hESDTruePrimaryConvGammaRSESDPtMCPt[iCut]
581             = new TH2F("ESD_TruePrimaryConvGammaESD_RS_PtMCPt", "ESD_TruePrimaryConvGammaESD_RS_PtMCPt",250,0,25,250,0,25);
582          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaRSESDPtMCPt[iCut]);
583
584
585          if(fDoMesonAnalysis){
586             hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",800,0,0.8,250,0,25);
587             fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
588             hESDTruePrimaryPi0ESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0_ESDPt_MCPt","ESD_TruePrimaryPi0_ESDPt_MCPt",250,0,25,250,0,25);
589             fTrueList[iCut]->Add(hESDTruePrimaryPi0ESDPtMCPt[iCut]);
590             hESDTruePrimaryEtaESDPtMCPt[iCut]  = new TH2F("ESD_TruePrimaryPi0_ESDPt_MCPt","ESD_TruePrimaryPi0_ESDPt_MCPt",250,0,25,250,0,25);
591             fTrueList[iCut]->Add(hESDTruePrimaryEtaESDPtMCPt[iCut]);
592             hESDTruePrimaryMotherInvMassMCPt[iCut]
593                = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt", "ESD_TruePrimaryMother_InvMass_MCPt", 800,0,0.8,250,0,25);
594             fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
595             hESDTruePrimaryMotherInvMassPt[iCut]
596                = new TH2F("ESD_TruePrimaryMother_InvMass_Pt", "ESD_TruePrimaryMother_InvMass_Pt", 800,0,0.8,250,0,25);
597             fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassPt[iCut]);
598             hESDTrueSecondaryMotherInvMassPt[iCut]
599                = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt", "ESD_TrueSecondaryMother_InvMass_Pt", 800,0,0.8,250,0,25);
600             fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
601             hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]
602                = new TH2F("ESD_TrueSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueSecondaryMotherFromK0s_InvMass_Pt",800,0,0.8,250,0,25);
603             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
604             hESDTrueK0sWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueK0sWithPi0Daughter_MCPt","ESD_TrueK0sWithPi0Daughter_MCPt",250,0,25);
605             fTrueList[iCut]->Add(hESDTrueK0sWithPi0DaughterMCPt[iCut]);
606             hESDTrueSecondaryMotherFromEtaInvMassPt[iCut]
607                = new TH2F("ESD_TrueSecondaryMotherFromEta_InvMass_Pt","ESD_TrueSecondaryMotherFromEta_InvMass_Pt",800,0,0.8,250,0,25);
608             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromEtaInvMassPt[iCut]);
609             hESDTrueEtaWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueEtaWithPi0Daughter_MCPt","ESD_TrueEtaWithPi0Daughter_MCPt",250,0,25);
610             fTrueList[iCut]->Add(hESDTrueEtaWithPi0DaughterMCPt[iCut]);
611             hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt","ESD_TrueBckGG_InvMass_Pt",800,0,0.8,250,0,25);
612             fTrueList[iCut]->Add(hESDTrueBckGGInvMassPt[iCut]);
613             hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueBckCont_InvMass_Pt","ESD_TrueBckCont_InvMass_Pt",800,0,0.8,250,0,25);
614             fTrueList[iCut]->Add(hESDTrueBckContInvMassPt[iCut]);
615             hESDTrueMotherDalitzInvMassPt[iCut] = new TH2F("ESD_TrueDalitz_InvMass_Pt","ESD_TrueDalitz_InvMass_Pt",800,0,0.8,250,0,25);
616             fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPt[iCut]);
617          }
618       }
619    }
620
621
622
623    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
624    if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
625
626    if(fV0Reader)
627       if((AliConversionCuts*)fV0Reader->GetConversionCuts())
628          if(((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms())
629             fOutputContainer->Add(((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
630
631    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
632       if(!((AliConversionCuts*)fCutArray->At(iCut))) continue;
633       if(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms()){
634          fCutFolder[iCut]->Add(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms());
635       }
636       if(!((AliConversionMesonCuts*)fMesonCutArray->At(iCut))) continue;
637       if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms()){
638          fCutFolder[iCut]->Add(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms());
639       }
640    }
641
642    TH1::SetDefaultSumw2(kFALSE);
643
644    PostData(1, fOutputContainer);
645 }
646
647 //_____________________________________________________________________________
648 void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
649 {
650    //
651    // Called for each event
652    //
653    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
654    if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
655       for(Int_t iCut = 0; iCut<fnCuts; iCut++){
656          hNEvents[iCut]->Fill(eventQuality);
657       }
658       return;
659    }
660
661    fMCEvent = MCEvent();
662    if(fMCEvent){
663       fMCStack = fMCEvent->Stack();
664    }
665    fInputEvent = InputEvent();
666
667    fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
668    CountESDTracks(); // Estimate Event Multiplicity
669
670    // ------------------- BeginEvent ----------------------------
671
672    for(Int_t iCut = 0; iCut<fnCuts; iCut++){
673       fiCut = iCut;
674
675       Int_t eventNotAccepted =
676          ((AliConversionCuts*)fCutArray->At(iCut))
677          ->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
678       if(eventNotAccepted){
679          //                     cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
680          hNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
681          continue;
682       }
683
684       if(eventQuality != 0){// Event Not Accepted
685          //          cout << "event rejected due to: " <<eventQuality << endl;
686          hNEvents[iCut]->Fill(eventQuality);
687          continue;
688       }
689
690       hNEvents[iCut]->Fill(eventQuality); // Should be 0 here
691       hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
692       hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
693
694       if(fMCEvent){ // Process MC Particle
695          if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() != 0){
696             ((AliConversionCuts*)fCutArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection(),
697                                                                                ((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader(),
698                                                                                fMCEvent);
699          }
700          ProcessMCParticles();
701       }
702
703       ProcessPhotonCandidates(); // Process this cuts gammas
704
705       hNGammaCandidates[iCut]->Fill(fGammaCandidates->GetEntries());
706       if(fDoMesonAnalysis){ // Meson Analysis
707          if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseMCPSmearing() && fMCEvent){
708             fUnsmearedPx = new Double_t[fGammaCandidates->GetEntries()]; // Store unsmeared Momenta
709             fUnsmearedPy = new Double_t[fGammaCandidates->GetEntries()];
710             fUnsmearedPz = new Double_t[fGammaCandidates->GetEntries()];
711             fUnsmearedE =  new Double_t[fGammaCandidates->GetEntries()];
712
713             for(Int_t gamma=0;gamma<fGammaCandidates->GetEntries();gamma++){ // Smear the AODPhotons in MC
714                fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Px();
715                fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Py();
716                fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Pz();
717                fUnsmearedE[gamma] =  ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->E();
718                ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(gamma)));
719             }
720          }
721
722          CalculatePi0Candidates(); // Combine Gammas
723          if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
724             if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
725                CalculateBackground(); // Combinatorial Background
726                UpdateEventByEventData(); // Store Event for mixed Events
727             }
728             else{
729                CalculateBackgroundRP(); // Combinatorial Background
730                fBGHandlerRP[iCut]->AddEvent(fGammaCandidates,fInputEvent); // Store Event for mixed Events
731             }
732          }
733          if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseMCPSmearing() && fMCEvent){
734             for(Int_t gamma=0;gamma<fGammaCandidates->GetEntries();gamma++){ // Smear the AODPhotons in MC
735                ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
736                ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPy(fUnsmearedPy[gamma]);
737                ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPz(fUnsmearedPz[gamma]);
738                ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetE(fUnsmearedE[gamma]);
739             }
740             delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
741             delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
742             delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
743             delete[] fUnsmearedE;  fUnsmearedE  = 0x0;
744          }
745       }
746       fGammaCandidates->Clear(); // delete this cuts good gammas
747
748    }
749
750    PostData(1, fOutputContainer);
751 }
752 //________________________________________________________________________
753 void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
754 {
755    Int_t nV0 = 0;
756    TList *GammaCandidatesStepOne = new TList();
757    TList *GammaCandidatesStepTwo = new TList();
758    // Loop over Photon Candidates allocated by ReaderV1
759    for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
760       AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
761       if(!PhotonCandidate) continue;
762       fIsFromMBHeader = kTRUE;
763       if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
764          Int_t isPosFromMBHeader
765             = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
766          if(isPosFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
767          Int_t isNegFromMBHeader
768             = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
769          if(isNegFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
770
771          if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
772       }
773
774       if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fInputEvent)) continue;
775       if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut() &&
776          !((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
777          fGammaCandidates->Add(PhotonCandidate); // if no second loop is required add to events good gammas
778
779          if(fIsFromMBHeader){
780             hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
781             hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
782          }
783          if(fMCEvent){
784             ProcessTruePhotonCandidates(PhotonCandidate);
785          }
786       }
787       else if(((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
788          ((AliConversionCuts*)fCutArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
789          nV0++;
790          GammaCandidatesStepOne->Add(PhotonCandidate);
791       }
792       else if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut() &&
793               ((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
794          GammaCandidatesStepTwo->Add(PhotonCandidate);
795       }
796    }
797    if(((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){
798       for(Int_t i = 0;i<GammaCandidatesStepOne->GetEntries();i++){
799          AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GammaCandidatesStepOne->At(i);
800          if(!PhotonCandidate) continue;
801          fIsFromMBHeader = kTRUE;
802          if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
803             Int_t isPosFromMBHeader
804                = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
805             Int_t isNegFromMBHeader
806                = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
807             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
808          }
809          if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GammaCandidatesStepOne->GetEntries())) continue;
810          if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed
811             fGammaCandidates->Add(PhotonCandidate);
812             if(fIsFromMBHeader){
813                hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
814                hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
815             }
816             if(fMCEvent){
817                ProcessTruePhotonCandidates(PhotonCandidate);
818             }
819          }
820          else GammaCandidatesStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
821       }
822    }
823    if(((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
824       for(Int_t i = 0;i<GammaCandidatesStepTwo->GetEntries();i++){
825          AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GammaCandidatesStepTwo->At(i);
826          if(!PhotonCandidate) continue;
827          fIsFromMBHeader = kTRUE;
828          if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
829             Int_t isPosFromMBHeader
830                = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
831             Int_t isNegFromMBHeader
832                = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
833             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
834          }
835          if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GammaCandidatesStepTwo,i)) continue;
836          fGammaCandidates->Add(PhotonCandidate); // Add gamma to current cut TList
837          if(fIsFromMBHeader){
838             hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
839             hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
840          }
841          if(fMCEvent){
842             ProcessTruePhotonCandidates(PhotonCandidate);
843          }
844       }
845    }
846
847    delete GammaCandidatesStepOne;
848    GammaCandidatesStepOne = 0x0;
849    delete GammaCandidatesStepTwo;
850    GammaCandidatesStepTwo = 0x0;
851
852 }
853 //________________________________________________________________________
854 void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
855 {
856    // Process True Photons
857    AliStack *MCStack = fMCEvent->Stack();
858    TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
859    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
860
861    if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
862
863    Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
864
865    if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){
866       // Combinatorial Bck = 0 ee, 1 ep,i 2 ek, 3 ep, 4 emu, 5 pipi, 6 pik, 7 pip, 8 pimu, 9 kk, 10 kp, 11 kmu, 12 pp, 13 pmu, 14 mumu, 15 Rest
867       if(pdgCode[0]==11   && pdgCode[1]==11){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
868       else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
869          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
870       else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
871          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
872       else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
873          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
874       else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
875          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
876       else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
877       else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
878          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
879       else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
880          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
881       else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
882          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
883       else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
884       else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
885          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
886       else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
887          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
888       else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
889       else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
890          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
891       else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
892       else {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
893       return;
894    }
895    else if(posDaughter->GetMother(0) == -1){
896       if(pdgCode[0]==11   && pdgCode[1]==11){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
897       else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
898          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
899       else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
900          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
901       else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
902          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
903       else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
904          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
905       else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
906       else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
907          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
908       else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
909          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
910       else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
911          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
912       else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
913       else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
914          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
915       else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
916          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
917       else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
918       else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
919          {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
920       else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
921       else {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
922       return;
923    }
924
925    if(pdgCode[0]!=11 || pdgCode[1]!=11) return; //One Particle is not a electron
926
927    if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
928
929    if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
930
931    TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
932    if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
933
934    // True Photon
935    if(fIsFromMBHeader)hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
936
937    if(posDaughter->GetMother(0) <= MCStack->GetNprimary()){
938       // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
939       if(fIsFromMBHeader){
940          hESDTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
941          hESDTruePrimaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
942          hESDTruePrimaryConvGammaEta[fiCut]->Fill(TruePhotonCandidate->Eta());
943          hESDTruePrimaryConvGammaRSESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
944       }
945       hESDTruePrimaryConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
946       // (Not Filled for i6, Extra Signal Gamma (parambox) are secondary)
947    }
948    else{
949       if(fIsFromMBHeader){
950          hESDTrueSecondaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
951          hESDTrueSecondaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
952          if(MCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1 &&
953             MCStack->Particle(MCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
954             hESDTrueSecondaryConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
955          }
956       }
957    }
958 }
959 //________________________________________________________________________
960 void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
961 {
962    // Loop over all primary MC particle
963    for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
964       TParticle* particle = (TParticle *)fMCStack->Particle(i);
965       if (!particle) continue;
966
967       Bool_t mcIsFromMB = kTRUE;
968       Int_t isMCFromMBHeader = -1;
969       if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
970          isMCFromMBHeader
971             = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack);
972          if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
973          if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
974       }
975
976       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
977          hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
978          if(particle->GetMother(0) >-1){ // Meson Decay Gamma
979             switch(fMCStack->Particle(particle->GetMother(0))->GetPdgCode()){
980             case 111: // Pi0
981                hMCDecayGammaPi0Pt[fiCut]->Fill(particle->Pt());
982                break;
983             case 113: // Rho0
984                hMCDecayGammaRhoPt[fiCut]->Fill(particle->Pt());
985                break;
986             case 221: // Eta
987                hMCDecayGammaEtaPt[fiCut]->Fill(particle->Pt());
988                break;
989             case 223: // Omega
990                hMCDecayGammaOmegaPt[fiCut]->Fill(particle->Pt());
991                break;
992             case 331: // Eta'
993                hMCDecayGammaEtapPt[fiCut]->Fill(particle->Pt());
994                break;
995             case 333: // Phi
996                hMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
997                break;
998             case 3212: // Sigma
999                hMCDecayGammaSigmaPt[fiCut]->Fill(particle->Pt());
1000                break;
1001             }
1002          }
1003       }
1004       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kTRUE)){
1005          hMCConvGammaPt[fiCut]->Fill(particle->Pt());
1006          hMCConvGammaR[fiCut]->Fill(((TParticle*)fMCStack->Particle(particle->GetFirstDaughter()))->R());
1007          hMCConvGammaEta[fiCut]->Fill(particle->Eta());
1008          if(mcIsFromMB){
1009             hMCConvGammaRSPt[fiCut]->Fill(particle->Pt());
1010             hMCConvGammaRSR[fiCut]->Fill(((TParticle*)fMCStack->Particle(particle->GetFirstDaughter()))->R());
1011             hMCConvGammaRSEta[fiCut]->Fill(particle->Eta());
1012          }
1013       } // Converted MC Gamma
1014       if(fDoMesonAnalysis){
1015          if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack)){
1016             TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
1017             TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
1018
1019             Float_t weighted= 1;
1020             if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack)){
1021                if (particle->Pt()>0.005){
1022                   weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack);
1023                }
1024             }
1025             if(particle->GetPdgCode() == 111){
1026                hMCPi0Pt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
1027             } else if(particle->GetPdgCode() == 221){
1028                hMCEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Eta
1029             }
1030
1031             // Check the acceptance for both gammas
1032             if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCStack,kFALSE) &&
1033                ((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter1,fMCStack,kFALSE) ){
1034                if(particle->GetPdgCode() == 111){
1035                   hMCPi0InAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Pi0 with gamma in acc
1036                } else if(particle->GetPdgCode() == 221){
1037                   hMCEtaInAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Eta with gamma in acc
1038                }
1039             }
1040          }
1041       }
1042    }
1043 }
1044 //________________________________________________________________________
1045 void AliAnalysisTaskGammaConvV1::CalculatePi0Candidates(){
1046
1047    // Conversion Gammas
1048    if(fGammaCandidates->GetEntries()>1){
1049       for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries()-1;firstGammaIndex++){
1050          AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
1051          for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fGammaCandidates->GetEntries();secondGammaIndex++){
1052             AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(secondGammaIndex));
1053             //Check for same Electron ID
1054             if(gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelPositive() ||
1055                gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelNegative() ||
1056                gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelPositive() ||
1057                gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelNegative() ) continue;
1058
1059             AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma0,gamma1);
1060             pi0cand->SetLabels(firstGammaIndex,secondGammaIndex);
1061
1062             if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE))){
1063                hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
1064
1065                if(pi0cand->GetAlpha()<0.1)
1066                   hESDMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
1067
1068                if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
1069                   Int_t zbin = 0;
1070                   Int_t mbin = 0;
1071
1072                   if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
1073                      zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
1074                      if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1075                         mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
1076                      } else {
1077                         mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
1078                      }
1079                   }
1080                   else{
1081                      zbin = fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
1082                      if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1083                         mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
1084                      } else {
1085                         mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
1086                      }
1087                   }
1088                   Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
1089                   sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
1090                }
1091                if(fMCEvent){
1092                   ProcessTrueMesonCandidates(pi0cand,gamma0,gamma1);
1093                }
1094             }
1095             delete pi0cand;
1096             pi0cand=0x0;
1097          }
1098       }
1099    }
1100 }
1101 //______________________________________________________________________
1102 void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1)
1103 {
1104    // Process True Mesons
1105    AliStack *MCStack = fMCEvent->Stack();
1106
1107    if(TrueGammaCandidate0->GetV0Index()<fInputEvent->GetNumberOfV0s()){
1108       Bool_t isTruePi0 = kFALSE;
1109       Bool_t isTrueEta = kFALSE;
1110       Int_t gamma0MCLabel = TrueGammaCandidate0->GetMCParticleLabel(MCStack);
1111       Int_t gamma0MotherLabel = -1;
1112       if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
1113          // Daughters Gamma 0
1114          TParticle * negativeMC = (TParticle*)TrueGammaCandidate0->GetNegativeMCDaughter(MCStack);
1115          TParticle * positiveMC = (TParticle*)TrueGammaCandidate0->GetPositiveMCDaughter(MCStack);
1116          TParticle * gammaMC0 = (TParticle*)MCStack->Particle(gamma0MCLabel);
1117          if(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
1118             if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
1119                if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
1120                   gamma0MotherLabel=gammaMC0->GetFirstMother();
1121                }
1122             }
1123             if(gammaMC0->GetPdgCode() ==111){ // Conversion but Pi0 Mother
1124                gamma0MotherLabel=-111;
1125             }
1126             if(gammaMC0->GetPdgCode() ==221){ // Conversion but Eta Mother
1127                gamma0MotherLabel=-221;
1128             }
1129          }
1130       }
1131       if(TrueGammaCandidate1->GetV0Index()<fInputEvent->GetNumberOfV0s()){
1132          Int_t gamma1MCLabel = TrueGammaCandidate1->GetMCParticleLabel(MCStack);
1133          Int_t gamma1MotherLabel = -1;
1134          if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
1135             // Daughters Gamma 1
1136             TParticle * negativeMC = (TParticle*)TrueGammaCandidate1->GetNegativeMCDaughter(MCStack);
1137             TParticle * positiveMC = (TParticle*)TrueGammaCandidate1->GetPositiveMCDaughter(MCStack);
1138             TParticle * gammaMC1 = (TParticle*)MCStack->Particle(gamma1MCLabel);
1139             if(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
1140                if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
1141                   if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
1142                      gamma1MotherLabel=gammaMC1->GetFirstMother();
1143                   }
1144                }
1145                if(gammaMC1->GetPdgCode() ==111){ // Conversion but Pi0 Mother
1146                   gamma1MotherLabel=-111;
1147                }
1148                if(gammaMC1->GetPdgCode() ==221){ // Conversion but Eta Mother
1149                   gamma1MotherLabel=-221;
1150                }
1151             }
1152          }
1153          if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
1154             if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 111){
1155                isTruePi0=kTRUE;
1156             }
1157             if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 221){
1158                isTrueEta=kTRUE;
1159             }
1160          }
1161          if(isTruePi0 || isTrueEta){// True Pion or Eta
1162             hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1163
1164             if(gamma0MotherLabel >= MCStack->GetNprimary()){ // Secondary Meson
1165                hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1166                if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0) >-1){
1167                   if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
1168                      hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1169                      hESDTrueK0sWithPi0DaughterMCPt[fiCut]
1170                         ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
1171                   }
1172                   if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==221){
1173                      hESDTrueSecondaryMotherFromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1174                      hESDTrueEtaWithPi0DaughterMCPt[fiCut]
1175                         ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
1176                   }
1177                }
1178             }
1179             else{ // Only primary pi0 for efficiency calculation
1180                Float_t weighted= 1;
1181                if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCStack)){
1182                   if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt()>0.005){
1183                      weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, fMCStack);
1184                   }
1185                }
1186                hESDTruePrimaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
1187                hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),weighted);
1188                if(isTruePi0){ // Only primary pi0 for unfolding
1189                   hESDTruePrimaryPi0ESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),weighted);
1190                }
1191                if (isTrueEta){ // Only primary eta for unfolding
1192                   hESDTruePrimaryEtaESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt(),weighted);
1193                }
1194             }
1195          }
1196          else if(!isTruePi0 && !isTrueEta){ // Background
1197             if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
1198                hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1199             } else { // No photon or without mother
1200                hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1201             }
1202             if((gamma0MotherLabel==-111 || gamma1MotherLabel==-111 || gamma0MotherLabel==-221 || gamma1MotherLabel==-221) ){
1203                // Dalitz
1204                hESDTrueMotherDalitzInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
1205             }
1206          }
1207       }
1208    }
1209 }
1210
1211 //________________________________________________________________________
1212 void AliAnalysisTaskGammaConvV1::CalculateBackground(){
1213
1214    Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
1215    Int_t mbin = 0;
1216
1217    if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1218       mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
1219    } else {
1220       mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
1221    }
1222
1223    if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseRotationMethod()){
1224
1225       for(Int_t iCurrent=0;iCurrent<fGammaCandidates->GetEntries();iCurrent++){
1226          AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGammaCandidates->At(iCurrent));
1227          for(Int_t iCurrent2=iCurrent+1;iCurrent2<fGammaCandidates->GetEntries();iCurrent2++){
1228             for(Int_t nRandom=0;nRandom<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents();nRandom++){
1229                AliAODConversionPhoton currentEventGoodV02 = *(AliAODConversionPhoton*)(fGammaCandidates->At(iCurrent2));
1230
1231                if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGProbability()){
1232                   AliAODConversionMother *backgroundCandidateProb = new AliAODConversionMother(&currentEventGoodV0,&currentEventGoodV02);
1233                   Double_t massBGprob = backgroundCandidateProb->M();
1234                   if(massBGprob>0.1 && massBGprob<0.14){
1235                      if(fRandom.Rndm()>fBGHandler[fiCut]->GetBGProb(zbin,mbin)){
1236                         delete backgroundCandidateProb;
1237                         continue;
1238                      }
1239                   }
1240                   delete backgroundCandidateProb;
1241                   backgroundCandidateProb = 0x0;
1242                }
1243
1244                RotateParticle(&currentEventGoodV02);
1245                AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&currentEventGoodV02);
1246                if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
1247                   hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
1248                   Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
1249                   sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
1250                }
1251                delete backgroundCandidate;
1252                backgroundCandidate = 0x0;
1253             }
1254          }
1255       }
1256    }else{
1257       AliGammaConversionAODBGHandler::GammaConversionVertex *bgEventVertex = NULL;
1258
1259       if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1260          for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
1261             AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
1262             if(fMoveParticleAccordingToVertex == kTRUE){
1263                bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
1264             }
1265
1266             for(Int_t iCurrent=0;iCurrent<fGammaCandidates->GetEntries();iCurrent++){
1267                AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGammaCandidates->At(iCurrent));
1268                for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
1269                   AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
1270                   if(fMoveParticleAccordingToVertex == kTRUE){
1271                      MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
1272                   }
1273
1274                   AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
1275                   if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
1276                      hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
1277                      Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
1278                      sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
1279                   }
1280                   delete backgroundCandidate;
1281                   backgroundCandidate = 0x0;
1282                }
1283             }
1284          }
1285       }
1286       else{
1287          for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
1288             AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
1289             if(previousEventV0s){
1290                if(fMoveParticleAccordingToVertex == kTRUE){
1291                   bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
1292                }
1293                for(Int_t iCurrent=0;iCurrent<fGammaCandidates->GetEntries();iCurrent++){
1294                   AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGammaCandidates->At(iCurrent));
1295                   for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
1296
1297                      AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
1298
1299                      if(fMoveParticleAccordingToVertex == kTRUE){
1300                         MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
1301                      }
1302
1303                      AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
1304
1305                      if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
1306                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
1307                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
1308                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
1309                      }
1310                      delete backgroundCandidate;
1311                      backgroundCandidate = 0x0;
1312                   }
1313                }
1314             }
1315          }
1316       }
1317    }
1318 }
1319 //________________________________________________________________________
1320 void AliAnalysisTaskGammaConvV1::CalculateBackgroundRP(){
1321
1322    Int_t zbin= fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
1323    Int_t mbin = 0;
1324    if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1325       mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
1326    } else {
1327       mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
1328    }
1329
1330
1331    //Rotation Method
1332    if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseRotationMethod()){
1333       // Correct for the number of rotations
1334       // BG is for rotation the same, except for factor NRotations
1335       Double_t weight=1./Double_t(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents());
1336
1337       for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries();firstGammaIndex++){
1338
1339          AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
1340
1341          for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fGammaCandidates->GetEntries();secondGammaIndex++){
1342             AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(secondGammaIndex));
1343             if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(gamma1,fInputEvent))continue;
1344             for(Int_t nRandom=0;nRandom<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents();nRandom++){
1345
1346                RotateParticle(gamma1);
1347
1348                AliAODConversionMother backgroundCandidate(gamma0,gamma1);
1349
1350                if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(&backgroundCandidate,kFALSE)){
1351                   hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt());
1352                   Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
1353                   sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
1354                }
1355             }
1356          }
1357       }
1358    }
1359    else{
1360       // Do Event Mixing
1361       for(Int_t nEventsInBG=0;nEventsInBG <fBGHandlerRP[fiCut]->GetNBGEvents(fGammaCandidates,fInputEvent);nEventsInBG++){
1362
1363          AliGammaConversionPhotonVector *previousEventGammas = fBGHandlerRP[fiCut]->GetBGGoodGammas(fGammaCandidates,fInputEvent,nEventsInBG);
1364
1365          if(previousEventGammas){
1366             // test weighted background
1367             Double_t weight=1.0;
1368             // Correct for the number of eventmixing:
1369             // N gammas -> (N-1) + (N-2) +(N-3) ...+ (N-(N-1))  using sum formula sum(i)=N*(N-1)/2  -> N*(N-1)/2
1370             // real combinations (since you cannot combine a photon with its own)
1371             // but BG leads to N_{a}*N_{b} combinations
1372             weight*=0.5*(Double_t(fGammaCandidates->GetEntries()-1))/Double_t(previousEventGammas->size());
1373
1374             for(Int_t iCurrent=0;iCurrent<fGammaCandidates->GetEntries();iCurrent++){
1375
1376                AliAODConversionPhoton *gamma0 = (AliAODConversionPhoton*)(fGammaCandidates->At(iCurrent));
1377
1378                for(UInt_t iPrevious=0;iPrevious<previousEventGammas->size();iPrevious++){
1379
1380                   AliAODConversionPhoton *gamma1 = (AliAODConversionPhoton*)(previousEventGammas->at(iPrevious));
1381
1382                   AliAODConversionMother backgroundCandidate(gamma0,gamma1);
1383
1384                   if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(&backgroundCandidate,kFALSE)){
1385                      hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt());
1386                      Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
1387                      sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
1388                   }
1389                }
1390             }
1391          }
1392       }
1393    }
1394 }
1395 //________________________________________________________________________
1396 void AliAnalysisTaskGammaConvV1::RotateParticle(AliAODConversionPhoton *gamma){
1397    Int_t fNDegreesPMBackground= ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->NDegreesRotation();
1398    Double_t nRadiansPM = fNDegreesPMBackground*TMath::Pi()/180;
1399    Double_t rotationValue = fRandom.Rndm()*2*nRadiansPM + TMath::Pi()-nRadiansPM;
1400    gamma->RotateZ(rotationValue);
1401 }
1402 //________________________________________________________________________
1403 void AliAnalysisTaskGammaConvV1::MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex){
1404    //see header file for documentation
1405
1406    Double_t dx = vertex->fX - fInputEvent->GetPrimaryVertex()->GetX();
1407    Double_t dy = vertex->fY - fInputEvent->GetPrimaryVertex()->GetY();
1408    Double_t dz = vertex->fZ - fInputEvent->GetPrimaryVertex()->GetZ();
1409
1410    Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
1411    particle->SetConversionPoint(movedPlace);
1412 }
1413 //________________________________________________________________________
1414 void AliAnalysisTaskGammaConvV1::UpdateEventByEventData(){
1415    //see header file for documentation
1416    if(fGammaCandidates->GetEntries() >0 ){
1417       if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
1418          fBGHandler[fiCut]->AddEvent(fGammaCandidates,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
1419       }
1420       else{ // means we use #V0s for multiplicity
1421          fBGHandler[fiCut]->AddEvent(fGammaCandidates,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->GetPrimaryVertex()->GetZ(),fGammaCandidates->GetEntries());
1422       }
1423    }
1424 }
1425
1426 //________________________________________________________________________
1427 void AliAnalysisTaskGammaConvV1::CountESDTracks(){
1428
1429    AliESDtrackCuts *EsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
1430    // Using standard function for setting Cuts
1431    Bool_t selectPrimaries=kTRUE;
1432    EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
1433    EsdTrackCuts->SetMaxDCAToVertexZ(2);
1434    EsdTrackCuts->SetEtaRange(-0.8, 0.8);
1435    EsdTrackCuts->SetPtRange(0.15);
1436
1437    fNumberOfESDTracks = 0;
1438
1439    for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
1440       AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
1441       if(!curTrack) continue;
1442       // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
1443       //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
1444       // }
1445       if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
1446    }
1447    delete EsdTrackCuts;
1448    EsdTrackCuts=0x0;
1449
1450    return;
1451 }
1452 //________________________________________________________________________
1453 void AliAnalysisTaskGammaConvV1::Terminate(const Option_t *)
1454 {
1455
1456    // Not Executed by GRID on SubJobLevel
1457    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1458       if(!((AliConversionCuts*)fCutArray->At(iCut))) continue;
1459       if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() == 2 && fMCEvent){
1460          fHeaderNameList[iCut] = new TList();
1461          TString HeaderNames = "Header:";
1462          for(Int_t i = 0;i<(((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader())->GetEntries();i++){
1463             HeaderNames = HeaderNames+"_"+ ((TObjString*)((TList*) ( (AliConversionCuts*)fCutArray->At(iCut))
1464                                                           ->GetAcceptedHeader())->At(i))->GetString();
1465          }
1466          fHeaderNameList[iCut]->SetName(HeaderNames);
1467          fHeaderNameList[iCut]->SetOwner(kTRUE);
1468          fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
1469       }
1470       else if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() == 0 &&
1471               (((AliConversionCuts*)fCutArray->At(iCut))->GetFoundHeader()) && fMCEvent){
1472          fHeaderNameList[iCut] = new TList();
1473          TString HeaderNames = (((AliConversionCuts*)fCutArray->At(iCut))->GetFoundHeader())[0];
1474          fHeaderNameList[iCut]->SetName(HeaderNames);
1475          fHeaderNameList[iCut]->SetOwner(kTRUE);
1476          fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
1477       }
1478    }
1479
1480    //fOutputContainer->Print(); // Will crash on GRID
1481 }