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