589befe9ff0972a5b0843c03efe1df7cae202222
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliConversionCuts.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Svein Lindal, 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 handling all kinds of selection cuts for
19 // Gamma Conversion analysis
20 //---------------------------------------------
21 ////////////////////////////////////////////////
22
23 #include "AliConversionCuts.h"
24
25 #include "AliKFVertex.h"
26 #include "AliAODTrack.h"
27 #include "AliESDtrack.h"
28 #include "AliAnalysisManager.h"
29 #include "AliInputEventHandler.h"
30 #include "AliMCEventHandler.h"
31 #include "AliAODHandler.h"
32 #include "AliPIDResponse.h"
33 #include "TH1.h"
34 #include "TH2.h"
35 #include "TF1.h"
36 #include "AliStack.h"
37 #include "AliAODConversionMother.h"
38 #include "TObjString.h"
39 #include "AliAODEvent.h"
40 #include "AliESDEvent.h"
41 #include "AliCentrality.h"
42 #include "TList.h"
43 #include "TFile.h"
44 #include "AliLog.h"
45 #include "AliGenCocktailEventHeader.h"
46 #include "AliGenDPMjetEventHeader.h"
47 #include "AliGenPythiaEventHeader.h"
48 #include "AliGenHijingEventHeader.h"
49 #include "AliTriggerAnalysis.h"
50 #include "AliV0ReaderV1.h"
51 #include "AliAODMCParticle.h"
52 #include "AliAODMCHeader.h"
53
54 class iostream;
55
56 using namespace std;
57
58 ClassImp(AliConversionCuts)
59
60
61 const char* AliConversionCuts::fgkCutNames[AliConversionCuts::kNCuts] = {
62    "HeavyIon",//0
63    "CentralityMin",//1
64    "CentralityMax",//2
65    "SelectV0AND",//3
66    "MultiplicityMethod",//4
67    "RemovePileUp",//5
68    "RejectExtraSignals",//6
69    "V0FinderType",//7
70    "EtaCut",//8
71    "MinRCut",//9
72    "SinglePtCut",//10
73    "ClsTPCCut", //11
74    "ededxSigmaCut",//12
75    "pidedxSigmaCut",//13
76    "piMomdedxSigmaCut",//14
77    "piMaxMomdedxSigmaCut",//15
78    "LowPRejectionSigmaCut",//16
79    "TOFelectronPID",//17
80    "QtMaxCut",//18
81    "Chi2GammaCut", //19
82    "PsiPair", //20
83    "DoPhotonAsymmetryCut",//21
84    "CosinePointingAngle", //22
85    "SharedElectronCuts", //23
86    "RejectToCloseV0s", //24
87    "DcaRPrimVtx", //25
88    "DcaZPrimVtx" //26
89    "EvetPlane" //27
90 };
91
92
93 //________________________________________________________________________
94 AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
95    AliAnalysisCuts(name,title),
96    fHistograms(NULL),
97    fHeaderList(NULL),
98    fPIDResponse(NULL),
99    fEventQuality(-1),
100    fMaxR(200),
101    fMinR(0),
102    fEtaCut(0.9),
103    fEtaCutMin(-0.1),
104    fPtCut(0.02),
105    fSinglePtCut(0),
106    fMaxZ(1000),
107    fMinClsTPC(0.),
108    fMinClsTPCToF(0.),
109    fLineCutZRSlope(0.),
110    fLineCutZValue(0),
111    fLineCutZRSlopeMin(0.),
112    fLineCutZValueMin(0),
113    fChi2CutConversion(1000),
114    fPIDProbabilityCutNegativeParticle(0),
115    fPIDProbabilityCutPositiveParticle(0),
116    fDodEdxSigmaCut(kTRUE),
117    fDoTOFsigmaCut(kFALSE),
118    fPIDTRDEfficiency(1),
119    fDoTRDPID(kFALSE),
120    fPIDnSigmaAboveElectronLine(100),
121    fPIDnSigmaBelowElectronLine(-100),
122    fTofPIDnSigmaAboveElectronLine(100),
123    fTofPIDnSigmaBelowElectronLine(-100),
124    fPIDnSigmaAbovePionLine(0),
125    fPIDnSigmaAbovePionLineHighPt(-100),
126    fPIDMinPnSigmaAbovePionLine(0),
127    fPIDMaxPnSigmaAbovePionLine(0),
128    fDoKaonRejectionLowP(kFALSE),
129    fDoProtonRejectionLowP(kFALSE),
130    fDoPionRejectionLowP(kFALSE),
131    fPIDnSigmaAtLowPAroundKaonLine(0),
132    fPIDnSigmaAtLowPAroundProtonLine(0),
133    fPIDnSigmaAtLowPAroundPionLine(0),
134    fPIDMinPKaonRejectionLowP(1.5),
135    fPIDMinPProtonRejectionLowP(2),
136    fPIDMinPPionRejectionLowP(0),
137    fDoQtGammaSelection(kTRUE),
138    fDo2DQt(kFALSE),
139    fQtMax(100),
140    fXVertexCut(0.),
141    fYVertexCut(0.),
142    fZVertexCut(0.),
143    fNSigmaMass(0.),
144    fUseEtaMinCut(kFALSE),
145    fUseOnFlyV0Finder(kTRUE),
146    fDoPhotonAsymmetryCut(kTRUE),
147    fMinPPhotonAsymmetryCut(100.),
148    fMinPhotonAsymmetry(0.),
149    fIsHeavyIon(0),
150    fDetectorCentrality(0),
151    fModCentralityClass(0),
152    fMaxVertexZ(10),
153    fCentralityMin(0),
154    fCentralityMax(0),
155    fUseCorrectedTPCClsInfo(kFALSE),
156    fUseTOFpid(kFALSE),
157    fMultiplicityMethod(0),
158    fSpecialTrigger(0),
159    fRemovePileUp(kFALSE),
160    fOpeningAngle(0.005),
161    fPsiPairCut(10000),
162    fDo2DPsiPairChi2(kFALSE),
163    fCosPAngleCut(10000),
164    fDoToCloseV0sCut(kFALSE),
165    fRejectExtraSignals(0),
166    fminV0Dist(200.),
167    fDoSharedElecCut(kFALSE),
168    fOfflineTriggerMask(0),
169    fHasV0AND(kTRUE),
170    fIsSDDFired(kTRUE),
171    fRandom(0),
172    fElectronArraySize(500),
173    fElectronLabelArray(NULL),
174    fDCAZPrimVtxCut(1000),
175    fDCARPrimVtxCut(1000),
176    fInPlaneOutOfPlane(0),
177    fConversionPointXArray(0.0),
178    fConversionPointYArray(0.0),
179    fConversionPointZArray(0.0),
180    fnHeaders(0),
181    fNotRejectedStart(NULL),
182    fNotRejectedEnd(NULL),
183    fGeneratorNames(NULL),
184    fCutString(NULL),
185    fUtils(NULL),
186    fEtaShift(0.0),
187    fDoEtaShift(kFALSE),
188    fDoReweightHistoMCPi0(kFALSE),
189    fDoReweightHistoMCEta(kFALSE),
190    fDoReweightHistoMCK0s(kFALSE),
191    fPathTrFReweighting(""),
192    fNameHistoReweightingPi0(""),
193    fNameHistoReweightingEta(""),
194    fNameHistoReweightingK0s(""),
195    fNameFitDataPi0(""),
196    fNameFitDataEta(""),
197    fNameFitDataK0s(""),
198    hdEdxCuts(NULL),
199    hTPCdEdxbefore(NULL),
200    hTPCdEdxafter(NULL),
201    hTPCdEdxSigbefore(NULL),
202    hTPCdEdxSigafter(NULL),
203    hTOFbefore(NULL),
204    hTOFSigbefore(NULL),
205    hTOFSigafter(NULL),
206    hPsiPairDeltaPhiafter(NULL),
207    hTrackCuts(NULL),
208    hPhotonCuts(NULL),
209    hInvMassbefore(NULL),
210    hArmenterosbefore(NULL),
211    hInvMassafter(NULL),
212    hArmenterosafter(NULL),
213    hAcceptanceCuts(NULL),
214    hCutIndex(NULL),
215    hV0EventCuts(NULL),
216    hCentrality(NULL),
217    hCentralityVsNumberOfPrimaryTracks(NULL),
218    hVertexZ(NULL),
219    hEventPlanePhi(NULL),
220    hTriggerClass(NULL),
221    hTriggerClassSelected(NULL),
222    hReweightMCHistPi0(NULL),
223    hReweightMCHistEta(NULL),
224    hReweightMCHistK0s(NULL),
225    fFitDataPi0(NULL),
226    fFitDataEta(NULL),
227    fFitDataK0s(NULL),
228    fPreSelCut(kFALSE),
229    fTriggerSelectedManually(kFALSE),
230    fSpecialTriggerName("")
231
232 {
233    InitPIDResponse();
234    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
235    fCutString=new TObjString((GetCutNumber()).Data());
236
237    fElectronLabelArray = new Int_t[fElectronArraySize];
238    fUtils = new AliAnalysisUtils();
239    //if you do not want to apply the cut on the distance between the SPD and TRK vertex:
240    //fUtils->SetCutOnZVertexSPD(kFALSE);
241
242
243 }
244
245 //________________________________________________________________________
246 AliConversionCuts::AliConversionCuts(const AliConversionCuts &ref) :
247    AliAnalysisCuts(ref),
248    fHistograms(NULL),
249    fHeaderList(ref.fHeaderList),
250    fPIDResponse(NULL),
251    fEventQuality(ref.fEventQuality),
252    fMaxR(ref.fMaxR),
253    fMinR(ref.fMinR),
254    fEtaCut(ref.fEtaCut),
255    fEtaCutMin(ref.fEtaCutMin),
256    fPtCut(ref.fPtCut),
257    fSinglePtCut(ref.fSinglePtCut),
258    fMaxZ(ref.fMaxZ),
259    fMinClsTPC(ref.fMinClsTPC),
260    fMinClsTPCToF(ref.fMinClsTPCToF),
261    fLineCutZRSlope(ref.fLineCutZRSlope),
262    fLineCutZValue(ref.fLineCutZValue),
263    fLineCutZRSlopeMin(ref.fLineCutZRSlopeMin),
264    fLineCutZValueMin(ref.fLineCutZValueMin),
265    fChi2CutConversion(ref.fChi2CutConversion),
266    fPIDProbabilityCutNegativeParticle(ref.fPIDProbabilityCutNegativeParticle),
267    fPIDProbabilityCutPositiveParticle(ref.fPIDProbabilityCutPositiveParticle),
268    fDodEdxSigmaCut(ref. fDodEdxSigmaCut),
269    fDoTOFsigmaCut(ref.fDoTOFsigmaCut),
270    fPIDTRDEfficiency(ref.fPIDTRDEfficiency),
271    fDoTRDPID(ref.fDoTRDPID),
272    fPIDnSigmaAboveElectronLine(ref.fPIDnSigmaAboveElectronLine),
273    fPIDnSigmaBelowElectronLine(ref.fPIDnSigmaBelowElectronLine),
274    fTofPIDnSigmaAboveElectronLine(ref.fTofPIDnSigmaAboveElectronLine),
275    fTofPIDnSigmaBelowElectronLine(ref.fTofPIDnSigmaBelowElectronLine),
276    fPIDnSigmaAbovePionLine(ref.fPIDnSigmaAbovePionLine),
277    fPIDnSigmaAbovePionLineHighPt(ref.fPIDnSigmaAbovePionLineHighPt),
278    fPIDMinPnSigmaAbovePionLine(ref.fPIDMinPnSigmaAbovePionLine),
279    fPIDMaxPnSigmaAbovePionLine(ref.fPIDMaxPnSigmaAbovePionLine),
280    fDoKaonRejectionLowP(ref.fDoKaonRejectionLowP),
281    fDoProtonRejectionLowP(ref.fDoProtonRejectionLowP),
282    fDoPionRejectionLowP(ref.fDoPionRejectionLowP),
283    fPIDnSigmaAtLowPAroundKaonLine(ref.fPIDnSigmaAtLowPAroundKaonLine),
284    fPIDnSigmaAtLowPAroundProtonLine(ref.fPIDnSigmaAtLowPAroundProtonLine),
285    fPIDnSigmaAtLowPAroundPionLine(ref.fPIDnSigmaAtLowPAroundPionLine),
286    fPIDMinPKaonRejectionLowP(ref.fPIDMinPKaonRejectionLowP),
287    fPIDMinPProtonRejectionLowP(ref.fPIDMinPProtonRejectionLowP),
288    fPIDMinPPionRejectionLowP(ref.fPIDMinPPionRejectionLowP),
289    fDoQtGammaSelection(ref.fDoQtGammaSelection),
290    fDo2DQt(ref.fDo2DQt),
291    fQtMax(ref.fQtMax),
292    fXVertexCut(ref.fXVertexCut),
293    fYVertexCut(ref.fYVertexCut),
294    fZVertexCut(ref.fZVertexCut),
295    fNSigmaMass(ref.fNSigmaMass),
296    fUseEtaMinCut(ref.fUseEtaMinCut),
297    fUseOnFlyV0Finder(ref.fUseOnFlyV0Finder),
298    fDoPhotonAsymmetryCut(ref.fDoPhotonAsymmetryCut),
299    fMinPPhotonAsymmetryCut(ref.fMinPPhotonAsymmetryCut),
300    fMinPhotonAsymmetry(ref.fMinPhotonAsymmetry),
301    fIsHeavyIon(ref.fIsHeavyIon),
302    fDetectorCentrality(ref.fDetectorCentrality),
303    fModCentralityClass(ref.fModCentralityClass),
304    fMaxVertexZ(ref.fMaxVertexZ),
305    fCentralityMin(ref.fCentralityMin),
306    fCentralityMax(ref.fCentralityMax),
307    fUseCorrectedTPCClsInfo(ref.fUseCorrectedTPCClsInfo),
308    fUseTOFpid(ref.fUseTOFpid),
309    fMultiplicityMethod(ref.fMultiplicityMethod),
310    fSpecialTrigger(ref.fSpecialTrigger),
311    fRemovePileUp(ref.fRemovePileUp),
312    fOpeningAngle(ref.fOpeningAngle),
313    fPsiPairCut(ref.fPsiPairCut),
314    fDo2DPsiPairChi2(ref.fDo2DPsiPairChi2),
315    fCosPAngleCut(ref.fCosPAngleCut),
316    fDoToCloseV0sCut(ref.fDoToCloseV0sCut),
317    fRejectExtraSignals(ref.fRejectExtraSignals),
318    fminV0Dist(ref.fminV0Dist),
319    fDoSharedElecCut(ref.fDoSharedElecCut),
320    fOfflineTriggerMask(ref.fOfflineTriggerMask),
321    fHasV0AND(ref.fHasV0AND),
322    fIsSDDFired(ref.fIsSDDFired),
323    fRandom(ref.fRandom),
324    fElectronArraySize(ref.fElectronArraySize),
325    fElectronLabelArray(NULL),
326    fDCAZPrimVtxCut(ref.fDCAZPrimVtxCut),
327    fDCARPrimVtxCut(ref.fDCAZPrimVtxCut),
328    fInPlaneOutOfPlane(ref.fInPlaneOutOfPlane),
329    fConversionPointXArray(ref.fConversionPointXArray),
330    fConversionPointYArray(ref.fConversionPointYArray),
331    fConversionPointZArray(ref.fConversionPointZArray),
332    fnHeaders(ref.fnHeaders),
333    fNotRejectedStart(NULL),
334    fNotRejectedEnd(NULL),
335    fGeneratorNames(ref.fGeneratorNames),
336    fCutString(NULL),
337    fUtils(NULL),
338    fEtaShift(ref.fEtaShift),
339    fDoEtaShift(ref.fDoEtaShift),
340    fDoReweightHistoMCPi0(ref.fDoReweightHistoMCPi0),
341    fDoReweightHistoMCEta(ref.fDoReweightHistoMCEta),
342    fDoReweightHistoMCK0s(ref.fDoReweightHistoMCK0s),
343    fPathTrFReweighting(ref.fPathTrFReweighting),
344    fNameHistoReweightingPi0(ref.fNameHistoReweightingPi0),
345    fNameHistoReweightingEta(ref.fNameHistoReweightingEta),
346    fNameHistoReweightingK0s(ref.fNameHistoReweightingK0s),
347    fNameFitDataPi0(ref.fNameFitDataPi0),
348    fNameFitDataEta(ref.fNameFitDataEta),
349    fNameFitDataK0s(ref.fNameFitDataK0s),
350    hdEdxCuts(NULL),
351    hTPCdEdxbefore(NULL),
352    hTPCdEdxafter(NULL),
353    hTPCdEdxSigbefore(NULL),
354    hTPCdEdxSigafter(NULL),
355    hTOFbefore(NULL),
356    hTOFSigbefore(NULL),
357    hTOFSigafter(NULL),
358    hPsiPairDeltaPhiafter(NULL),
359    hTrackCuts(NULL),
360    hPhotonCuts(NULL),
361    hInvMassbefore(NULL),
362    hArmenterosbefore(NULL),
363    hInvMassafter(NULL),
364    hArmenterosafter(NULL),
365    hAcceptanceCuts(NULL),
366    hCutIndex(NULL),
367    hV0EventCuts(NULL),
368    hCentrality(NULL),
369    hCentralityVsNumberOfPrimaryTracks(NULL),
370    hVertexZ(NULL),
371    hEventPlanePhi(NULL),
372    hTriggerClass(NULL),
373    hTriggerClassSelected(NULL),
374    hReweightMCHistPi0(ref.hReweightMCHistPi0),
375    hReweightMCHistEta(ref.hReweightMCHistEta),
376    hReweightMCHistK0s(ref.hReweightMCHistK0s),
377    fFitDataPi0(ref.fFitDataPi0),
378    fFitDataEta(ref.fFitDataEta),
379    fFitDataK0s(ref.fFitDataK0s),
380    fPreSelCut(ref.fPreSelCut),
381    fTriggerSelectedManually(ref.fTriggerSelectedManually),
382    fSpecialTriggerName(ref.fSpecialTriggerName)
383 {
384    // Copy Constructor
385    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
386    fCutString=new TObjString((GetCutNumber()).Data());
387    fElectronLabelArray = new Int_t[fElectronArraySize];
388    fUtils = new AliAnalysisUtils();
389    // dont copy histograms (if you like histograms, call InitCutHistograms())
390
391 }
392
393
394 //________________________________________________________________________
395 AliConversionCuts::~AliConversionCuts() {
396    // Destructor
397    //Deleting fHistograms leads to seg fault it it's added to output collection of a task
398    // if(fHistograms)
399    //    delete fHistograms;
400    // fHistograms = NULL;
401    if(fCutString != NULL){
402       delete fCutString;
403       fCutString = NULL;
404    }
405    if(fElectronLabelArray){
406       delete fElectronLabelArray;
407       fElectronLabelArray = NULL;
408    }
409    if(fNotRejectedStart){
410       delete[] fNotRejectedStart;
411       fNotRejectedStart = NULL;
412    }
413    if(fNotRejectedEnd){
414       delete[] fNotRejectedEnd;
415       fNotRejectedEnd = NULL;
416    }
417    if(fGeneratorNames){
418       delete[] fGeneratorNames;
419       fGeneratorNames = NULL;
420    }
421    if(fUtils){
422      delete fUtils;
423      fUtils = NULL;
424    }
425
426 }
427
428 //________________________________________________________________________
429 void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
430
431    // Initialize Cut Histograms for QA (only initialized and filled if function is called)
432    TH1::AddDirectory(kFALSE);
433
434    if(fHistograms != NULL){
435       delete fHistograms;
436       fHistograms=NULL;
437    }
438    if(fHistograms==NULL){
439       fHistograms=new TList();
440       fHistograms->SetOwner(kTRUE);
441       if(name=="")fHistograms->SetName(Form("ConvCuts_%s",GetCutNumber().Data()));
442       else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
443    }
444
445    if (hReweightMCHistPi0){
446       hReweightMCHistPi0->SetName("MCInputForWeightingPi0");
447       fHistograms->Add(hReweightMCHistPi0);
448    }
449    if (hReweightMCHistEta){
450       hReweightMCHistEta->SetName("MCInputForWeightingEta");
451       fHistograms->Add(hReweightMCHistEta);
452    }
453    if (hReweightMCHistK0s){
454       hReweightMCHistK0s->SetName("MCInputForWeightingK0s");
455       fHistograms->Add(hReweightMCHistK0s);
456    }
457 //    if (fFitDataPi0){
458 //       fFitDataPi0->SetName("DataFitForWeightingPi0");
459 //       fHistograms->Add(fFitDataPi0);
460 //    }
461 //    if (fFitDataEta){
462 //       fFitDataEta->SetName("DataFitForWeightingEta");
463 //       fHistograms->Add(fFitDataEta);
464 //    }
465 //    if (fFitDataK0s){
466 //       fFitDataK0s->SetName("DataFitForWeightingK0s");
467 //       fHistograms->Add(fFitDataK0s);
468 //    }
469    // IsPhotonSelected
470    hCutIndex=new TH1F(Form("IsPhotonSelected %s",GetCutNumber().Data()),"IsPhotonSelected",11,-0.5,10.5);
471    hCutIndex->GetXaxis()->SetBinLabel(kPhotonIn+1,"in");
472    hCutIndex->GetXaxis()->SetBinLabel(kOnFly+1,"onfly");
473    hCutIndex->GetXaxis()->SetBinLabel(kNoTracks+1,"no tracks");
474    hCutIndex->GetXaxis()->SetBinLabel(kdEdxCuts+1,"dEdx");
475    hCutIndex->GetXaxis()->SetBinLabel(kTrackCuts+1,"Track cuts");
476    hCutIndex->GetXaxis()->SetBinLabel(kConvPointFail+1,"ConvPoint fail");
477    hCutIndex->GetXaxis()->SetBinLabel(kPhotonCuts+1,"PhotonCuts");
478    hCutIndex->GetXaxis()->SetBinLabel(kEventPlane+1,"EventPlane");
479    hCutIndex->GetXaxis()->SetBinLabel(kPhotonOut+1,"out");
480    fHistograms->Add(hCutIndex);
481
482    // Track Cuts
483    hTrackCuts=new TH1F(Form("TrackCuts %s",GetCutNumber().Data()),"TrackCuts",9,-0.5,8.5);
484    hTrackCuts->GetXaxis()->SetBinLabel(1,"in");
485    hTrackCuts->GetXaxis()->SetBinLabel(2,"likesign");
486    hTrackCuts->GetXaxis()->SetBinLabel(3,"ntpccl");
487    hTrackCuts->GetXaxis()->SetBinLabel(4,"acceptance");
488    hTrackCuts->GetXaxis()->SetBinLabel(5,"singlept");
489    hTrackCuts->GetXaxis()->SetBinLabel(6,"TPCrefit");
490    hTrackCuts->GetXaxis()->SetBinLabel(7,"kink");
491    hTrackCuts->GetXaxis()->SetBinLabel(8,"out");
492    fHistograms->Add(hTrackCuts);
493
494    // Photon Cuts
495    hPhotonCuts=new TH1F(Form("PhotonCuts %s",GetCutNumber().Data()),"PhotonCuts",14,-0.5,13.5);
496    hPhotonCuts->GetXaxis()->SetBinLabel(1,"in");
497    hPhotonCuts->GetXaxis()->SetBinLabel(2,"qtcut");
498    hPhotonCuts->GetXaxis()->SetBinLabel(3,"chi2");
499    hPhotonCuts->GetXaxis()->SetBinLabel(4,"acceptance");
500    hPhotonCuts->GetXaxis()->SetBinLabel(5,"asymmetry");
501    hPhotonCuts->GetXaxis()->SetBinLabel(6,"pidprob");
502    hPhotonCuts->GetXaxis()->SetBinLabel(7,"cortpcclinfo");
503    hPhotonCuts->GetXaxis()->SetBinLabel(8,"PsiPair");
504    hPhotonCuts->GetXaxis()->SetBinLabel(9,"CosPAngle");
505    hPhotonCuts->GetXaxis()->SetBinLabel(10,"DCA R");
506    hPhotonCuts->GetXaxis()->SetBinLabel(11,"DCA Z");
507    hPhotonCuts->GetXaxis()->SetBinLabel(12,"out");
508    fHistograms->Add(hPhotonCuts);
509
510    if(preCut){
511       hInvMassbefore=new TH1F(Form("InvMass_before %s",GetCutNumber().Data()),"InvMass_before",1000,0,0.3);
512       fHistograms->Add(hInvMassbefore);
513       hArmenterosbefore=new TH2F(Form("Armenteros_before %s",GetCutNumber().Data()),"Armenteros_before",200,-1,1,1000,0,1.);
514       fHistograms->Add(hArmenterosbefore);
515    }
516    hInvMassafter=new TH1F(Form("InvMass_after %s",GetCutNumber().Data()),"InvMass_after",1000,0,0.3);
517    fHistograms->Add(hInvMassafter);
518    hArmenterosafter=new TH2F(Form("Armenteros_after %s",GetCutNumber().Data()),"Armenteros_after",200,-1,1,250,0,0.25);
519    fHistograms->Add(hArmenterosafter);
520
521    hAcceptanceCuts=new TH1F(Form("PhotonAcceptanceCuts %s",GetCutNumber().Data()),"PhotonAcceptanceCuts",10,-0.5,9.5);
522    hAcceptanceCuts->GetXaxis()->SetBinLabel(1,"in");
523    hAcceptanceCuts->GetXaxis()->SetBinLabel(2,"maxR");
524    hAcceptanceCuts->GetXaxis()->SetBinLabel(3,"minR");
525    hAcceptanceCuts->GetXaxis()->SetBinLabel(4,"line");
526    hAcceptanceCuts->GetXaxis()->SetBinLabel(5,"maxZ");
527    hAcceptanceCuts->GetXaxis()->SetBinLabel(6,"eta");
528    hAcceptanceCuts->GetXaxis()->SetBinLabel(7,"minpt");
529    hAcceptanceCuts->GetXaxis()->SetBinLabel(8,"out");
530    fHistograms->Add(hAcceptanceCuts);
531
532    // dEdx Cuts
533    hdEdxCuts=new TH1F(Form("dEdxCuts %s",GetCutNumber().Data()),"dEdxCuts",10,-0.5,9.5);
534    hdEdxCuts->GetXaxis()->SetBinLabel(1,"in");
535    hdEdxCuts->GetXaxis()->SetBinLabel(2,"TPCelectron");
536    hdEdxCuts->GetXaxis()->SetBinLabel(3,"TPCpion");
537    hdEdxCuts->GetXaxis()->SetBinLabel(4,"TPCpionhighp");
538    hdEdxCuts->GetXaxis()->SetBinLabel(5,"TPCkaonlowprej");
539    hdEdxCuts->GetXaxis()->SetBinLabel(6,"TPCprotonlowprej");
540    hdEdxCuts->GetXaxis()->SetBinLabel(7,"TPCpionlowprej");
541    hdEdxCuts->GetXaxis()->SetBinLabel(8,"TOFelectron");
542    hdEdxCuts->GetXaxis()->SetBinLabel(9,"TRDelectron");
543    hdEdxCuts->GetXaxis()->SetBinLabel(10,"out");
544    fHistograms->Add(hdEdxCuts);
545
546    TAxis *AxisBeforedEdx = NULL;
547    TAxis *AxisBeforedEdxSig = NULL;
548    TAxis *AxisBeforeTOF = NULL;
549    TAxis *AxisBeforeTOFSig = NULL;
550    if(preCut){
551       hTPCdEdxbefore=new TH2F(Form("Gamma_dEdx_before %s",GetCutNumber().Data()),"dEdx Gamma before" ,150,0.03,20,800,0,200);
552       fHistograms->Add(hTPCdEdxbefore);
553       AxisBeforedEdx = hTPCdEdxbefore->GetXaxis();
554       hTPCdEdxSigbefore=new TH2F(Form("Gamma_dEdxSig_before %s",GetCutNumber().Data()),"dEdx Sigma Gamma before" ,150,0.03,20,400,-10,10);
555       fHistograms->Add(hTPCdEdxSigbefore);
556       AxisBeforedEdxSig = hTPCdEdxSigbefore->GetXaxis();
557
558       hTOFbefore=new TH2F(Form("Gamma_TOF_before %s",GetCutNumber().Data()),"TOF Gamma before" ,150,0.03,20,11000,-1000,10000);
559       fHistograms->Add(hTOFbefore);
560       AxisBeforeTOF = hTOFbefore->GetXaxis();
561       hTOFSigbefore=new TH2F(Form("Gamma_TOFSig_before %s",GetCutNumber().Data()),"TOF Sigma Gamma before" ,150,0.03,20,400,-6,10);
562       fHistograms->Add(hTOFSigbefore);
563       AxisBeforeTOFSig = hTOFSigbefore->GetXaxis();
564
565    }
566    hTPCdEdxSigafter=new TH2F(Form("Gamma_dEdxSig_after %s",GetCutNumber().Data()),"dEdx Sigma Gamma after" ,150,0.03,20,400, -10,10);
567    fHistograms->Add(hTPCdEdxSigafter);
568
569    hTPCdEdxafter=new TH2F(Form("Gamma_dEdx_after %s",GetCutNumber().Data()),"dEdx Gamma after" ,150,0.03,20,800,0,200);
570    fHistograms->Add(hTPCdEdxafter);
571
572    hTOFSigafter=new TH2F(Form("Gamma_TOFSig_after %s",GetCutNumber().Data()),"TOF Sigma Gamma after" ,150,0.03,20,400,-6,10);
573    fHistograms->Add(hTOFSigafter);
574
575    hPsiPairDeltaPhiafter=new TH2F(Form("Gamma_PsiPairDeltaPhi_after %s",GetCutNumber().Data()),"Psi Pair vs Delta Phi Gamma after" ,200,-2,2,200,-2,2);
576    fHistograms->Add(hPsiPairDeltaPhiafter);
577
578    TAxis *AxisAfter = hTPCdEdxSigafter->GetXaxis();
579    Int_t bins = AxisAfter->GetNbins();
580    Double_t from = AxisAfter->GetXmin();
581    Double_t to = AxisAfter->GetXmax();
582    Double_t *newBins = new Double_t[bins+1];
583    newBins[0] = from;
584    Double_t factor = TMath::Power(to/from, 1./bins);
585    for(Int_t i=1; i<=bins; ++i) newBins[i] = factor * newBins[i-1];
586    AxisAfter->Set(bins, newBins);
587    AxisAfter = hTOFSigafter->GetXaxis();
588    AxisAfter->Set(bins, newBins);
589    AxisAfter = hTPCdEdxafter->GetXaxis();
590    AxisAfter->Set(bins, newBins);
591    if(preCut){
592       AxisBeforedEdx->Set(bins, newBins);
593       AxisBeforeTOF->Set(bins, newBins);
594       AxisBeforedEdxSig->Set(bins, newBins);
595       AxisBeforeTOFSig->Set(bins, newBins);
596    }
597    delete [] newBins;
598
599    hCentrality=new TH1F(Form("Centrality %s",GetCutNumber().Data()),"Centrality",100,0,100);
600    fHistograms->Add(hCentrality);
601    hCentralityVsNumberOfPrimaryTracks=new TH2F(Form("Centrality vs Primary Tracks %s",GetCutNumber().Data()),"Centrality vs Primary Tracks ",100,0,100,4000,0,4000);
602    fHistograms->Add(hCentralityVsNumberOfPrimaryTracks);
603
604    // Event Cuts and Info
605    if(preCut){
606       hV0EventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",7,-0.5,6.5);
607       hV0EventCuts->GetXaxis()->SetBinLabel(1,"in");
608       hV0EventCuts->GetXaxis()->SetBinLabel(2,"OfflineTrigger");
609       hV0EventCuts->GetXaxis()->SetBinLabel(3,"nvtxcontr");
610       hV0EventCuts->GetXaxis()->SetBinLabel(4,"VertexZ");
611       hV0EventCuts->GetXaxis()->SetBinLabel(5,"pileup");
612       hV0EventCuts->GetXaxis()->SetBinLabel(6,"centrsel");
613       hV0EventCuts->GetXaxis()->SetBinLabel(7,"out");
614       fHistograms->Add(hV0EventCuts);
615
616       hVertexZ=new TH1F(Form("VertexZ %s",GetCutNumber().Data()),"VertexZ",1000,-50,50);
617       fHistograms->Add(hVertexZ);
618
619       hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",35,-0.5,34.5);
620       hTriggerClass->GetXaxis()->SetBinLabel( 1,"kMB");
621       hTriggerClass->GetXaxis()->SetBinLabel( 2,"kINT7");
622       hTriggerClass->GetXaxis()->SetBinLabel( 3,"kMUON");
623       hTriggerClass->GetXaxis()->SetBinLabel( 4,"kHighMult");
624       hTriggerClass->GetXaxis()->SetBinLabel( 5,"kKEMC1");
625       hTriggerClass->GetXaxis()->SetBinLabel( 6,"kCINT5");
626       hTriggerClass->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
627       hTriggerClass->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
628       hTriggerClass->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
629       hTriggerClass->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
630       hTriggerClass->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
631       hTriggerClass->GetXaxis()->SetBinLabel(12,"kMUS7");
632       hTriggerClass->GetXaxis()->SetBinLabel(13,"kPHI1");
633       hTriggerClass->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
634       hTriggerClass->GetXaxis()->SetBinLabel(15,"kEMCEJE");
635       hTriggerClass->GetXaxis()->SetBinLabel(16,"kEMCEGA");
636       hTriggerClass->GetXaxis()->SetBinLabel(17,"kCentral");
637       hTriggerClass->GetXaxis()->SetBinLabel(18,"kSemiCentral");
638       hTriggerClass->GetXaxis()->SetBinLabel(19,"kDG5");
639       hTriggerClass->GetXaxis()->SetBinLabel(20,"kZED");
640       hTriggerClass->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
641       hTriggerClass->GetXaxis()->SetBinLabel(22,"kINT8");
642       hTriggerClass->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
643       hTriggerClass->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
644       hTriggerClass->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
645       hTriggerClass->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
646       hTriggerClass->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
647       hTriggerClass->GetXaxis()->SetBinLabel(28,"kUserDefined");
648       hTriggerClass->GetXaxis()->SetBinLabel(29,"kTRD");
649       hTriggerClass->GetXaxis()->SetBinLabel(30,"kFastOnly");
650       hTriggerClass->GetXaxis()->SetBinLabel(31,"kAnyINT");
651       hTriggerClass->GetXaxis()->SetBinLabel(32,"kAny");
652       hTriggerClass->GetXaxis()->SetBinLabel(33,"V0AND");
653       hTriggerClass->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
654       hTriggerClass->GetXaxis()->SetBinLabel(35,"failed Physics Selection");
655       fHistograms->Add(hTriggerClass);
656    }
657    if(!preCut){
658       hTriggerClassSelected= new TH1F(Form("OfflineTriggerSelected %s",GetCutNumber().Data()),"OfflineTriggerSelected",34,-0.5,33.5);
659       hTriggerClassSelected->GetXaxis()->SetBinLabel( 1,"kMB");
660       hTriggerClassSelected->GetXaxis()->SetBinLabel( 2,"kINT7");
661       hTriggerClassSelected->GetXaxis()->SetBinLabel( 3,"kMUON");
662       hTriggerClassSelected->GetXaxis()->SetBinLabel( 4,"kHighMult");
663       hTriggerClassSelected->GetXaxis()->SetBinLabel( 5,"kKEMC1");
664       hTriggerClassSelected->GetXaxis()->SetBinLabel( 6,"kCINT5");
665       hTriggerClassSelected->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
666       hTriggerClassSelected->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
667       hTriggerClassSelected->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
668       hTriggerClassSelected->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
669       hTriggerClassSelected->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
670       hTriggerClassSelected->GetXaxis()->SetBinLabel(12,"kMUS7");
671       hTriggerClassSelected->GetXaxis()->SetBinLabel(13,"kPHI1");
672       hTriggerClassSelected->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
673       hTriggerClassSelected->GetXaxis()->SetBinLabel(15,"kEMCEJE");
674       hTriggerClassSelected->GetXaxis()->SetBinLabel(16,"kEMCEGA");
675       hTriggerClassSelected->GetXaxis()->SetBinLabel(17,"kCentral");
676       hTriggerClassSelected->GetXaxis()->SetBinLabel(18,"kSemiCentral");
677       hTriggerClassSelected->GetXaxis()->SetBinLabel(19,"kDG5");
678       hTriggerClassSelected->GetXaxis()->SetBinLabel(20,"kZED");
679       hTriggerClassSelected->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
680       hTriggerClassSelected->GetXaxis()->SetBinLabel(22,"kINT8");
681       hTriggerClassSelected->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
682       hTriggerClassSelected->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
683       hTriggerClassSelected->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
684       hTriggerClassSelected->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
685       hTriggerClassSelected->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
686       hTriggerClassSelected->GetXaxis()->SetBinLabel(28,"kUserDefined");
687       hTriggerClassSelected->GetXaxis()->SetBinLabel(29,"kTRD");
688       hTriggerClassSelected->GetXaxis()->SetBinLabel(30,"kFastOnly");
689       hTriggerClassSelected->GetXaxis()->SetBinLabel(31,"kAnyINT");
690       hTriggerClassSelected->GetXaxis()->SetBinLabel(32,"kAny");
691       hTriggerClassSelected->GetXaxis()->SetBinLabel(33,"V0AND");
692       hTriggerClassSelected->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
693       fHistograms->Add(hTriggerClassSelected);
694       
695       hEventPlanePhi=new TH1F(Form("EventPlaneMinusPhotonAngle %s",GetCutNumber().Data()),"EventPlaneMinusPhotonAngle",360,-TMath::Pi(),TMath::Pi());
696       fHistograms->Add(hEventPlanePhi);
697
698       
699    }
700    TH1::AddDirectory(kTRUE);
701 }
702
703 //________________________________________________________________________
704 Bool_t AliConversionCuts::InitPIDResponse(){
705    // Set Pointer to AliPIDResponse
706
707    AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
708    if(man) {
709       AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
710       fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
711       if(fPIDResponse)return kTRUE;
712
713    }
714
715
716    return kFALSE;
717 }
718 ///________________________________________________________________________
719 Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent){
720    // Process Event Selection
721
722    Int_t cutindex=0;
723    if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
724    cutindex++;
725
726    // Check for MC event
727    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
728       // Check if MC event is correctly loaded
729       AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
730       if (!mcHandler){
731          fEventQuality = 2;
732          return kFALSE;
733       }
734       if (!mcHandler->InitOk() ){
735          fEventQuality = 2;
736          return kFALSE;
737       }
738       if (!mcHandler->TreeK() ){
739          fEventQuality = 2;
740          return kFALSE;
741       }
742       if (!mcHandler->TreeTR() ) {
743          fEventQuality = 2;
744          return kFALSE;
745       }
746    }
747
748    // Event Trigger
749 //    cout << "before event trigger" << endl;
750    if(!IsTriggerSelected(fInputEvent)){
751       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
752       fEventQuality = 3;
753       return kFALSE;
754    }
755    cutindex++;
756
757    if(fInputEvent->IsA()==AliESDEvent::Class()){
758       AliTriggerAnalysis fTriggerAnalysis;// = new AliTriggerAnalysis;
759       fHasV0AND = fTriggerAnalysis.IsOfflineTriggerFired((AliESDEvent*)fInputEvent, AliTriggerAnalysis::kV0AND);
760       if(fHasV0AND&&hTriggerClass)hTriggerClass->Fill(32);
761    }
762 //   cout << "event number " << ((AliESDEvent*)fInputEvent)->GetEventNumberInFile() << " entered"<< endl;
763
764
765    // Number of Contributors Cut
766    if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
767       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
768       fEventQuality = 5;
769       return kFALSE;
770    }
771    cutindex++;
772
773    // Z Vertex Position Cut
774    if(!VertexZCut(fInputEvent)){
775       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
776       fEventQuality = 4;
777       return kFALSE;
778    }
779    cutindex++;
780
781    // Pile Up Rejection
782
783    if(fRemovePileUp){
784       if(fInputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
785          if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
786          fEventQuality = 6;
787          return kFALSE;
788       }
789    }
790    cutindex++;
791
792    // Centrality Selection
793    if(!IsCentralitySelected(fInputEvent,fMCEvent)){
794       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
795       fEventQuality = 1;
796       return kFALSE;
797    }
798    cutindex++;
799
800    // Fill Event Histograms
801    if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
802    if(hVertexZ)hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
803    if(hCentrality)hCentrality->Fill(GetCentrality(fInputEvent));
804    if(hCentralityVsNumberOfPrimaryTracks)
805       hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(fInputEvent),
806                                                ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
807                                                 ->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks());
808    fEventQuality = 0;
809    return kTRUE;
810 }
811
812 ///________________________________________________________________________
813 Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCStack,Bool_t checkForConvertedGamma){
814    // MonteCarlo Photon Selection
815
816    if(!fMCStack)return kFALSE;
817
818    if (particle->GetPdgCode() == 22){
819
820
821       if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )
822          return kFALSE;
823       if(fEtaCutMin>-0.1){
824          if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) )
825             return kFALSE;
826       }
827
828       if(particle->GetMother(0) >-1 && fMCStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
829          return kFALSE; // no photon as mothers!
830       }
831
832       if(particle->GetMother(0) >= fMCStack->GetNprimary()){
833          return kFALSE; // the gamma has a mother, and it is not a primary particle
834       }
835
836       if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
837
838       // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
839       TParticle* ePos = NULL;
840       TParticle* eNeg = NULL;
841
842       if(particle->GetNDaughters() >= 2){
843          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
844             TParticle *tmpDaughter = fMCStack->Particle(daughterIndex);
845             if(tmpDaughter->GetUniqueID() == 5){
846                if(tmpDaughter->GetPdgCode() == 11){
847                   eNeg = tmpDaughter;
848                } else if(tmpDaughter->GetPdgCode() == -11){
849                   ePos = tmpDaughter;
850                }
851             }
852          }
853       }
854
855       if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
856          return kFALSE;
857       }
858
859       if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
860          return kFALSE; // no reconstruction below the Pt cut
861       }
862
863       if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ||
864           eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) )
865          return kFALSE;
866
867       if(fEtaCutMin > -0.1){
868          if( (ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift)) ||
869              (eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift)) )
870             return kFALSE;
871       }
872
873       if(ePos->R()>fMaxR){
874          return kFALSE; // cuts on distance from collision point
875       }
876
877       if(abs(ePos->Vz()) > fMaxZ){
878          return kFALSE;  // outside material
879       }
880       if(abs(eNeg->Vz()) > fMaxZ){
881          return kFALSE;  // outside material
882       }
883
884       if( ePos->R() <= ((abs(ePos->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
885          return kFALSE;  // line cut to exclude regions where we do not reconstruct
886       } else if ( fEtaCutMin != -0.1 &&   ePos->R() >= ((abs(ePos->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
887          return kFALSE;
888       }
889
890       if( eNeg->R() <= ((abs(eNeg->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
891          return kFALSE; // line cut to exclude regions where we do not reconstruct
892       } else if ( fEtaCutMin != -0.1 &&   eNeg->R() >= ((abs(eNeg->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
893          return kFALSE;
894       }
895
896       return kTRUE;
897       //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
898    }
899    return kFALSE;
900 }
901 ///________________________________________________________________________
902 Bool_t AliConversionCuts::PhotonIsSelectedAODMC(AliAODMCParticle *particle,TClonesArray *aodmcArray,Bool_t checkForConvertedGamma){
903    // MonteCarlo Photon Selection
904
905    if(!aodmcArray)return kFALSE;
906
907    if (particle->GetPdgCode() == 22){
908       if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )
909          return kFALSE;
910       if(fEtaCutMin>-0.1){
911          if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) )
912             return kFALSE;
913       }
914
915       if(particle->GetMother() > -1){
916          if((static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother())))->GetPdgCode() == 22){
917             return kFALSE; // no photon as mothers!
918          }
919          if(!(static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother()))->IsPrimary())){
920             return kFALSE; // the gamma has a mother, and it is not a primary particle
921          }
922       }
923
924       if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
925
926       // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
927       AliAODMCParticle* ePos = NULL;
928       AliAODMCParticle* eNeg = NULL;
929
930       if(particle->GetNDaughters() >= 2){
931          for(Int_t daughterIndex=particle->GetDaughter(0);daughterIndex<=particle->GetDaughter(1);daughterIndex++){
932             AliAODMCParticle *tmpDaughter = static_cast<AliAODMCParticle*>(aodmcArray->At(daughterIndex));
933             if(!tmpDaughter) continue;
934             if(((tmpDaughter->GetMCProcessCode())) == 5){    // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
935                if(tmpDaughter->GetPdgCode() == 11){
936                   eNeg = tmpDaughter;
937                } else if(tmpDaughter->GetPdgCode() == -11){
938                   ePos = tmpDaughter;
939                }
940             }
941          }
942       }
943
944       if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
945          return kFALSE;
946       }
947
948       if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
949          return kFALSE; // no reconstruction below the Pt cut
950       }
951
952       if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ||
953           eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) )
954          return kFALSE;
955
956       if(fEtaCutMin > -0.1){
957          if( (ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift)) ||
958              (eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift)) )
959             return kFALSE;
960       }
961
962       Double_t rPos = sqrt( (ePos->Xv()*ePos->Xv()) + (ePos->Yv()*ePos->Yv()) );
963       Double_t rNeg = sqrt( (eNeg->Xv()*eNeg->Xv()) + (eNeg->Yv()*eNeg->Yv()) );
964
965       if(rPos>fMaxR){
966          return kFALSE; // cuts on distance from collision point
967       }
968       if(abs(ePos->Zv()) > fMaxZ){
969          return kFALSE;  // outside material
970       }
971       if(abs(eNeg->Zv()) > fMaxZ){
972          return kFALSE;  // outside material
973       }
974
975       if( rPos <= ((abs(ePos->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
976          return kFALSE;  // line cut to exclude regions where we do not reconstruct
977       } else if ( fEtaCutMin != -0.1 &&   rPos >= ((abs(ePos->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
978          return kFALSE;
979       }
980
981       if( rNeg <= ((abs(eNeg->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
982          return kFALSE; // line cut to exclude regions where we do not reconstruct
983       } else if ( fEtaCutMin != -0.1 &&   rNeg >= ((abs(eNeg->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
984          return kFALSE;
985       }
986
987       return kTRUE;
988       //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
989    }
990    return kFALSE;
991 }
992 ///________________________________________________________________________
993 Bool_t AliConversionCuts::PhotonCuts(AliConversionPhotonBase *photon,AliVEvent *event)
994 {   // Specific Photon Cuts
995
996    Int_t cutIndex = 0;
997    if(hPhotonCuts)hPhotonCuts->Fill(cutIndex);
998    cutIndex++;
999
1000    // Fill Histos before Cuts
1001    if(hInvMassbefore)hInvMassbefore->Fill(photon->GetMass());
1002
1003    if(hArmenterosbefore)hArmenterosbefore->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
1004
1005    // Gamma selection based on QT from Armenteros
1006    if(fDoQtGammaSelection == kTRUE){
1007       if(!ArmenterosQtCut(photon)){
1008          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //1
1009          return kFALSE;
1010       }
1011    }
1012    cutIndex++; //2
1013
1014    // Chi Cut
1015    if(photon->GetChi2perNDF() > fChi2CutConversion || photon->GetChi2perNDF() <=0){
1016       {
1017          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //2
1018          return kFALSE;
1019       }
1020    }
1021    cutIndex++;//3
1022
1023    // Reconstruction Acceptance Cuts
1024    if(!AcceptanceCuts(photon)){
1025       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //3
1026       return kFALSE;
1027    }
1028
1029    cutIndex++; //4
1030    // Asymmetry Cut
1031    if(fDoPhotonAsymmetryCut == kTRUE){
1032       if(!AsymmetryCut(photon,event)){
1033          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //4
1034          return kFALSE;
1035       }
1036    }
1037
1038    //Check the pid probability
1039    cutIndex++; //5
1040    if(!PIDProbabilityCut(photon, event)) {
1041       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //5
1042       return kFALSE;
1043    }
1044
1045    cutIndex++; //6
1046    if(!CorrectedTPCClusterCut(photon, event)) {
1047       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //6
1048       return kFALSE;
1049    }
1050
1051    Double_t magField = event->GetMagneticField();
1052    if( magField  < 0.0 ){
1053       magField =  1.0;
1054    } else {
1055       magField =  -1.0;
1056    }
1057    
1058    AliVTrack * electronCandidate = GetTrack(event,photon->GetTrackLabelNegative() );
1059    AliVTrack * positronCandidate = GetTrack(event,photon->GetTrackLabelPositive() );
1060    Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->Phi()-positronCandidate->Phi());
1061
1062    cutIndex++; //7
1063    if(!PsiPairCut(photon)) {
1064       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //7
1065       return kFALSE;
1066    }
1067
1068    cutIndex++; //8
1069    if(!CosinePAngleCut(photon, event)) {
1070       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //8
1071       return kFALSE;
1072    }
1073
1074    AliAODConversionPhoton* photonAOD = dynamic_cast<AliAODConversionPhoton*>(photon);
1075    if (photonAOD){
1076       photonAOD->CalculateDistanceOfClossetApproachToPrimVtx(event->GetPrimaryVertex());
1077
1078       cutIndex++; //9
1079       if(photonAOD->GetDCArToPrimVtx() > fDCARPrimVtxCut) { //DCA R cut of photon to primary vertex
1080          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //9
1081          return kFALSE;
1082       }
1083
1084       cutIndex++; //10
1085       if(abs(photonAOD->GetDCAzToPrimVtx()) > fDCAZPrimVtxCut) { //DCA Z cut of photon to primary vertex
1086          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //10
1087          return kFALSE;
1088       }
1089    } else {
1090       cutIndex++; //9
1091       cutIndex++; //10
1092    }
1093    cutIndex++; //11
1094    if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //11
1095
1096    // Histos after Cuts
1097    if(hInvMassafter)hInvMassafter->Fill(photon->GetMass());
1098    if(hArmenterosafter)hArmenterosafter->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
1099    if(hPsiPairDeltaPhiafter)hPsiPairDeltaPhiafter->Fill(deltaPhi,photon->GetPsiPair());
1100    return kTRUE;
1101
1102 }
1103
1104 ///________________________________________________________________________
1105 Bool_t AliConversionCuts::CorrectedTPCClusterCut(AliConversionPhotonBase *photon, AliVEvent * event)
1106 {   //Cut on corrected TPC Cluster Info
1107
1108    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1109    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1110
1111    if(!negTrack||!posTrack)return kFALSE;
1112
1113    Double_t negclsToF=0;
1114
1115    if (!fUseCorrectedTPCClsInfo ){
1116       if(negTrack->GetTPCNclsF()!=0){
1117          negclsToF = (Double_t)negTrack->GetNcls(1)/(Double_t)negTrack->GetTPCNclsF();}// Ncluster/Nfindablecluster
1118    }
1119    else {
1120       negclsToF = negTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1121    }
1122
1123    Double_t posclsToF = 0.;
1124    if (!fUseCorrectedTPCClsInfo ){
1125       if(posTrack->GetTPCNclsF()!=0){
1126          posclsToF = (Double_t)posTrack->GetNcls(1)/(Double_t)posTrack->GetTPCNclsF();
1127       }
1128    }else{
1129       posclsToF = posTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1130    }
1131
1132    if( negclsToF < fMinClsTPCToF || posclsToF < fMinClsTPCToF ){
1133       return kFALSE;
1134    }
1135
1136    return kTRUE;
1137 }
1138
1139 ///________________________________________________________________________
1140 Bool_t AliConversionCuts::PhotonIsSelected(AliConversionPhotonBase *photon, AliVEvent * event)
1141 {
1142    //Selection of Reconstructed Photons
1143
1144    FillPhotonCutIndex(kPhotonIn);
1145
1146    if(event->IsA()==AliESDEvent::Class()) {
1147      if(!SelectV0Finder( ( ((AliESDEvent*)event)->GetV0(photon->GetV0Index()))->GetOnFlyStatus() ) ){
1148          FillPhotonCutIndex(kOnFly);
1149          return kFALSE;
1150       }
1151    }
1152    // else if(event->IsA()==AliAODEvent::Class()) {
1153    //    if(!SelectV0Finder( ( ((AliAODEvent*)event)->GetV0(photon->GetV0Index())) ) ){
1154    //       FillPhotonCutIndex(kOnFly);
1155    //       return kFALSE;
1156    //    }
1157    // }
1158
1159    // Get Tracks
1160    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1161    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1162
1163    if(!negTrack || !posTrack) {
1164       FillPhotonCutIndex(kNoTracks);
1165       return kFALSE;
1166    }
1167    photon->DeterminePhotonQuality(negTrack,posTrack);
1168    // Track Cuts
1169    if(!TracksAreSelected(negTrack, posTrack)){
1170       FillPhotonCutIndex(kTrackCuts);
1171       return kFALSE;
1172    }
1173
1174    // dEdx Cuts
1175    if(!dEdxCuts(negTrack) || !dEdxCuts(posTrack)) {
1176       FillPhotonCutIndex(kdEdxCuts);
1177       return kFALSE;
1178    }
1179
1180    // Photon Cuts
1181    if(!PhotonCuts(photon,event)){
1182       FillPhotonCutIndex(kPhotonCuts);
1183       return kFALSE;
1184    }
1185
1186    // Photon passed cuts
1187    FillPhotonCutIndex(kPhotonOut);
1188    return kTRUE;
1189 }
1190
1191 ///________________________________________________________________________
1192 Bool_t AliConversionCuts::ArmenterosQtCut(AliConversionPhotonBase *photon)
1193 {   // Armenteros Qt Cut
1194
1195    if(fDo2DQt){
1196       if ( !(TMath::Power(photon->GetArmenterosAlpha()/0.95,2)+TMath::Power(photon->GetArmenterosQt()/fQtMax,2) < 1) ){
1197          return kFALSE;
1198       }
1199    } else {
1200       if(photon->GetArmenterosQt()>fQtMax){
1201          return kFALSE;
1202       }
1203    }
1204    return kTRUE;
1205 }
1206
1207
1208 ///________________________________________________________________________
1209 Bool_t AliConversionCuts::AcceptanceCuts(AliConversionPhotonBase *photon) {
1210    // Exclude certain areas for photon reconstruction
1211
1212    Int_t cutIndex=0;
1213    if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1214    cutIndex++;
1215
1216    if(photon->GetConversionRadius()>fMaxR){ // cuts on distance from collision point
1217       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1218       return kFALSE;
1219    }
1220    cutIndex++;
1221
1222    if(photon->GetConversionRadius()<fMinR){ // cuts on distance from collision point
1223       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1224       return kFALSE;
1225    }
1226    cutIndex++;
1227
1228    if(photon->GetConversionRadius() <= ((abs(photon->GetConversionZ())*fLineCutZRSlope)-fLineCutZValue)){
1229       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1230       return kFALSE;
1231    }
1232    else if (fUseEtaMinCut &&  photon->GetConversionRadius() >= ((abs(photon->GetConversionZ())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
1233       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1234       return kFALSE;
1235    }
1236    cutIndex++;
1237
1238    if(abs(photon->GetConversionZ()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1239       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1240       return kFALSE;
1241    }
1242    cutIndex++;
1243
1244
1245    if( photon->GetPhotonEta() > (fEtaCut + fEtaShift)    || photon->GetPhotonEta() < (-fEtaCut + fEtaShift) ){
1246       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1247       return kFALSE;
1248    }
1249    if(fEtaCutMin>-0.1){
1250       if( photon->GetPhotonEta() < (fEtaCutMin + fEtaShift) && photon->GetPhotonEta() > (-fEtaCutMin + fEtaShift) ){
1251          if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1252          return kFALSE;
1253       }
1254    }
1255    cutIndex++;
1256
1257    if(photon->GetPhotonPt()<fPtCut){
1258       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1259       return kFALSE;
1260    }
1261    cutIndex++;
1262
1263    if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1264
1265    return kTRUE;
1266 }
1267
1268
1269 ///________________________________________________________________________
1270 Bool_t AliConversionCuts::SpecificTrackCuts(AliAODTrack * negTrack, AliAODTrack * posTrack,Int_t &cutIndex) {
1271    // Track Cuts which require AOD/ESD specific implementation
1272
1273    if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
1274       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1275       return kFALSE;
1276    }
1277    cutIndex++;
1278
1279    AliAODVertex * NegVtxType=negTrack->GetProdVertex();
1280    AliAODVertex * PosVtxType=posTrack->GetProdVertex();
1281    if( (NegVtxType->GetType())==AliAODVertex::kKink || (PosVtxType->GetType())==AliAODVertex::kKink) {
1282       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1283       return kFALSE;
1284    }
1285    return kTRUE;
1286
1287 }
1288
1289
1290 ///________________________________________________________________________
1291 Bool_t AliConversionCuts::SpecificTrackCuts(AliESDtrack * negTrack, AliESDtrack * posTrack,Int_t &cutIndex) {
1292    // Track Cuts which require AOD/ESD specific implementation
1293
1294    if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
1295       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1296       return kFALSE;
1297    }
1298    cutIndex++;
1299
1300    if(negTrack->GetKinkIndex(0) > 0  || posTrack->GetKinkIndex(0) > 0 ) {
1301       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1302       return kFALSE;
1303    }
1304    return kTRUE;
1305 }
1306
1307
1308
1309 ///________________________________________________________________________
1310 Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * posTrack) {
1311    // Track Selection for Photon Reconstruction
1312
1313    Int_t cutIndex=0;
1314    if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1315    cutIndex++;
1316
1317    // avoid like sign
1318    if(negTrack->Charge() == posTrack->Charge()) {
1319       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1320       return kFALSE;
1321    }
1322    cutIndex++;
1323
1324    // Number of TPC Clusters
1325
1326
1327    if( negTrack->GetNcls(1) < fMinClsTPC || posTrack->GetNcls(1) < fMinClsTPC ) {
1328       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1329       return kFALSE;
1330    }
1331    cutIndex++;
1332
1333    // Acceptance
1334    if( posTrack->Eta() > (fEtaCut + fEtaShift) || posTrack->Eta() < (-fEtaCut + fEtaShift) ||
1335        negTrack->Eta() > (fEtaCut + fEtaShift) || negTrack->Eta() < (-fEtaCut + fEtaShift) ){
1336       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1337       return kFALSE;
1338    }
1339    if(fEtaCutMin>-0.1){
1340       if( (posTrack->Eta() < (fEtaCutMin + fEtaShift) && posTrack->Eta() > (-fEtaCutMin + fEtaShift)) ||
1341           (negTrack->Eta() < (fEtaCutMin + fEtaShift) && negTrack->Eta() > (-fEtaCutMin + fEtaShift)) ){
1342          if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1343          return kFALSE;
1344       }
1345    }
1346    cutIndex++;
1347
1348    // Single Pt Cut
1349    if( negTrack->Pt()< fSinglePtCut || posTrack->Pt()< fSinglePtCut){
1350       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1351       return kFALSE;
1352    }
1353    cutIndex++;
1354
1355    // AOD ESD specific cuts
1356    Bool_t passCuts = kTRUE;
1357
1358    if(negTrack->IsA()==AliAODTrack::Class()) {
1359       passCuts = passCuts * SpecificTrackCuts(static_cast<AliAODTrack*>(negTrack), static_cast<AliAODTrack*>(posTrack),cutIndex);
1360    } else {
1361       passCuts = passCuts * SpecificTrackCuts(static_cast<AliESDtrack*>(negTrack), static_cast<AliESDtrack*>(posTrack),cutIndex);
1362    }
1363
1364    if(!passCuts){
1365       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1366       return kFALSE;
1367    }
1368    cutIndex++;
1369
1370    if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1371
1372    return kTRUE;
1373
1374 }
1375
1376 ///________________________________________________________________________
1377 Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
1378    // Electron Identification Cuts for Photon reconstruction
1379
1380    if(!fPIDResponse){InitPIDResponse();}// Try to reinitialize PID Response
1381    if(!fPIDResponse){AliError("No PID Response"); return kTRUE;}// if still missing fatal error
1382
1383    Int_t cutIndex=0;
1384    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1385    if(hTPCdEdxSigbefore)hTPCdEdxSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1386    if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
1387    cutIndex++;
1388
1389
1390    if(fDodEdxSigmaCut == kTRUE){
1391       // TPC Electron Line
1392       if( fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaBelowElectronLine ||
1393           fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaAboveElectronLine){
1394
1395          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1396          return kFALSE;
1397       }
1398       cutIndex++;
1399
1400       // TPC Pion Line
1401       if( fCurrentTrack->P()>fPIDMinPnSigmaAbovePionLine && fCurrentTrack->P()<fPIDMaxPnSigmaAbovePionLine ){
1402          if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1403             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine&&
1404             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLine){
1405
1406             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1407             return kFALSE;
1408          }
1409       }
1410       cutIndex++;
1411
1412       // High Pt Pion rej
1413       if( fCurrentTrack->P()>fPIDMaxPnSigmaAbovePionLine ){
1414          if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1415             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine &&
1416             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineHighPt){
1417
1418             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1419             return kFALSE;
1420          }
1421       }
1422       cutIndex++;
1423    }
1424    else{cutIndex+=3;}
1425
1426    if(fDoKaonRejectionLowP == kTRUE){
1427       if(fCurrentTrack->P()<fPIDMinPKaonRejectionLowP ){
1428          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
1429
1430             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1431             return kFALSE;
1432          }
1433       }
1434    }
1435    cutIndex++;
1436
1437    if(fDoProtonRejectionLowP == kTRUE){
1438       if( fCurrentTrack->P()<fPIDMinPProtonRejectionLowP ){
1439          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
1440
1441             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1442             return kFALSE;
1443          }
1444       }
1445    }
1446    cutIndex++;
1447
1448    if(fDoPionRejectionLowP == kTRUE){
1449       if( fCurrentTrack->P()<fPIDMinPPionRejectionLowP ){
1450          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion))<fPIDnSigmaAtLowPAroundPionLine){
1451
1452             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1453             return kFALSE;
1454          }
1455       }
1456    }
1457    cutIndex++;
1458
1459
1460    // cout<<"Start"<<endl;
1461    // AliPIDResponse::EDetPidStatus status=fPIDResponse->CheckPIDStatus(AliPIDResponse::kTOF,fCurrentTrack);
1462
1463    // if( ( (status & AliVTrack::kTOFout) == AliVTrack::kTOFout ) && ( (status & AliVTrack::kTIME) == AliVTrack::kTIME ))
1464    //    {cout<<"TOF DA"<<endl;}
1465    // if(status == AliPIDResponse::kDetPidOk){
1466    //    Float_t probMis = fPIDResponse->GetTOFMismatchProbability(fCurrentTrack);
1467    //    cout<<"--> "<<probMis<<endl;
1468    //    if(probMis > 0.01){
1469
1470    //    }
1471    // }
1472
1473    if((fCurrentTrack->GetStatus() & AliESDtrack::kTOFpid) && !(fCurrentTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
1474       if(hTOFbefore){
1475          Double_t t0 = fPIDResponse->GetTOFResponse().GetStartTime(fCurrentTrack->P());
1476          Double_t times[5];
1477          fCurrentTrack->GetIntegratedTimes(times);
1478          Double_t TOFsignal = fCurrentTrack->GetTOFsignal();
1479          Double_t dT = TOFsignal - t0 - times[0];
1480          hTOFbefore->Fill(fCurrentTrack->P(),dT);
1481       }
1482       if(hTOFSigbefore) hTOFSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1483       if(fUseTOFpid){
1484          if(fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)>fTofPIDnSigmaAboveElectronLine ||
1485             fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)<fTofPIDnSigmaBelowElectronLine ){
1486             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1487             return kFALSE;
1488          }
1489       }
1490       if(hTOFSigafter)hTOFSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1491    }
1492    cutIndex++;
1493
1494    // Apply TRD PID
1495    if(fDoTRDPID){
1496       if(!fPIDResponse->IdentifiedAsElectronTRD(fCurrentTrack,fPIDTRDEfficiency)){
1497          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1498          return kFALSE;
1499       }
1500    }
1501    cutIndex++;
1502
1503    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1504    if(hTPCdEdxSigafter)hTPCdEdxSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1505    if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
1506   
1507    return kTRUE;
1508 }
1509
1510 ///________________________________________________________________________
1511 Bool_t AliConversionCuts::AsymmetryCut(AliConversionPhotonBase * photon,AliVEvent *event) {
1512    // Cut on Energy Assymetry
1513
1514    for(Int_t ii=0;ii<2;ii++){
1515
1516       AliVTrack *track=GetTrack(event,photon->GetTrackLabel(ii));
1517
1518       if( track->P() > fMinPPhotonAsymmetryCut ){
1519          Double_t trackNegAsy=0;
1520          if (photon->GetPhotonP()!=0.){
1521             trackNegAsy= track->P()/photon->GetPhotonP();
1522          }
1523
1524          if( trackNegAsy<fMinPhotonAsymmetry ||trackNegAsy>(1.- fMinPhotonAsymmetry)){
1525             return kFALSE;
1526          }
1527       }
1528
1529    }
1530    return kTRUE;
1531 }
1532
1533 ///________________________________________________________________________
1534 AliVTrack *AliConversionCuts::GetTrack(AliVEvent * event, Int_t label){
1535    //Returns pointer to the track with given ESD label
1536    //(Important for AOD implementation, since Track array in AOD data is different
1537    //from ESD array, but ESD tracklabels are stored in AOD Tracks)
1538
1539    AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1540    if(esdEvent) {
1541       if(label > event->GetNumberOfTracks() ) return NULL;
1542       AliESDtrack * track = esdEvent->GetTrack(label);
1543       return track;
1544
1545    } else {
1546       AliVTrack * track = 0x0;
1547       if(((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->AreAODsRelabeled()){
1548          track = dynamic_cast<AliVTrack*>(event->GetTrack(label));
1549          return track;
1550       }
1551       else{
1552          for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
1553             track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
1554             if(track){
1555                if(track->GetID() == label) {
1556                   return track;
1557                }
1558             }
1559          }
1560       }
1561    }
1562    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
1563    return NULL;
1564 }
1565
1566 ///________________________________________________________________________
1567 AliESDtrack *AliConversionCuts::GetESDTrack(AliESDEvent * event, Int_t label){
1568    //Returns pointer to the track with given ESD label
1569    //(Important for AOD implementation, since Track array in AOD data is different
1570    //from ESD array, but ESD tracklabels are stored in AOD Tracks)
1571
1572    if(event) {
1573       if(label > event->GetNumberOfTracks() ) return NULL;
1574       AliESDtrack * track = event->GetTrack(label);
1575       return track;
1576    }
1577    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
1578    return NULL;
1579 }
1580
1581
1582
1583 ///________________________________________________________________________
1584 Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, AliVEvent * event){
1585    // Cut on Electron Probability for Photon Reconstruction
1586
1587    AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1588
1589    if(esdEvent){
1590
1591       Bool_t iResult=kFALSE;
1592
1593       Double_t *posProbArray = new Double_t[AliPID::kSPECIES];
1594       Double_t *negProbArray = new Double_t[AliPID::kSPECIES];
1595
1596       AliESDtrack* negTrack   = esdEvent->GetTrack(photon->GetTrackLabelNegative());
1597       AliESDtrack* posTrack   = esdEvent->GetTrack(photon->GetTrackLabelPositive());
1598
1599       if(negProbArray && posProbArray){
1600
1601          negTrack->GetTPCpid(negProbArray);
1602          posTrack->GetTPCpid(posProbArray);
1603
1604          if(negProbArray[AliPID::kElectron]>=fPIDProbabilityCutNegativeParticle && posProbArray[AliPID::kElectron]>=fPIDProbabilityCutPositiveParticle){
1605             iResult=kTRUE;
1606          }
1607       }
1608
1609       delete [] posProbArray;
1610       delete [] negProbArray;
1611       return iResult;
1612
1613    } else {
1614       ///Not possible for AODs
1615       return kTRUE;
1616    }
1617
1618
1619
1620
1621 }
1622
1623
1624 ///________________________________________________________________________
1625 Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TParticle* eNeg){
1626    // MC Acceptance Cuts
1627    //(Certain areas were excluded for photon reconstruction)
1628
1629    if(particle->R()>fMaxR){
1630       return kFALSE;}
1631
1632    if(ePos->R()>fMaxR){
1633       return kFALSE;
1634    }
1635
1636    if(ePos->R()<fMinR){
1637       return kFALSE;
1638    }
1639
1640    if( ePos->R() <= ((abs(ePos->Vz())*fLineCutZRSlope)-fLineCutZValue)){
1641       return kFALSE;
1642    }
1643    else if (fUseEtaMinCut &&  ePos->R() >= ((abs(ePos->Vz())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
1644       return kFALSE;
1645    }
1646
1647    if(abs(eNeg->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1648       return kFALSE;
1649    }
1650
1651    if(eNeg->Vz()!=ePos->Vz()||eNeg->R()!=ePos->R()){
1652       return kFALSE;
1653    }
1654
1655    if(abs(ePos->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1656       return kFALSE;
1657    }
1658
1659
1660    if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) ){
1661       return kFALSE;
1662    }
1663    if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ){
1664       return kFALSE;
1665    }
1666    if( eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) ){
1667       return kFALSE;
1668    }
1669    if(fEtaCutMin>-0.1){
1670       if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) ){
1671          return kFALSE;
1672       }
1673       if( ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift) ){
1674          return kFALSE;
1675       }
1676       if( eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift) ){
1677          return kFALSE;
1678       }
1679    }
1680
1681    if( ePos->Pt()< fSinglePtCut ||  eNeg->Pt()< fSinglePtCut){
1682       return kFALSE;
1683    }
1684
1685    if(particle->Pt()<fPtCut){
1686       return kFALSE;
1687    }
1688
1689    return kTRUE;
1690 }
1691 ///________________________________________________________________________
1692 Bool_t AliConversionCuts::UpdateCutString() {
1693    ///Update the cut string (if it has been created yet)
1694
1695    if(fCutString && fCutString->GetString().Length() == kNCuts) {
1696       fCutString->SetString(GetCutNumber());
1697    } else {
1698       return kFALSE;
1699    }
1700    return kTRUE;
1701 }
1702 ///________________________________________________________________________
1703 void AliConversionCuts::LoadReweightingHistosMCFromFile() {
1704
1705   AliInfo("Entering loading of histograms for weighting");
1706   TFile *f = TFile::Open(fPathTrFReweighting.Data());
1707   if(!f){
1708      AliError(Form("file for weighting %s not found",fPathTrFReweighting.Data()));
1709      return;
1710   }
1711   if (fNameHistoReweightingPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
1712      TH1D *hReweightMCHistPi0temp = (TH1D*)f->Get(fNameHistoReweightingPi0.Data());
1713      hReweightMCHistPi0 = new TH1D(*hReweightMCHistPi0temp);
1714      hReweightMCHistPi0->SetDirectory(0);
1715      if (hReweightMCHistPi0) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingPi0.Data(),fPathTrFReweighting.Data() ));
1716      else AliWarning(Form("%s not found in %s", fNameHistoReweightingPi0.Data() ,fPathTrFReweighting.Data()));
1717   }
1718   if (fNameFitDataPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
1719      TF1 *fFitDataPi0temp = (TF1*)f->Get(fNameFitDataPi0.Data());
1720      fFitDataPi0 = new TF1(*fFitDataPi0temp);
1721      if (fFitDataPi0) AliInfo(Form("%s has been loaded from %s", fNameFitDataPi0.Data(),fPathTrFReweighting.Data() ));
1722      else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameFitDataPi0.Data() ));
1723   }
1724
1725   if (fNameHistoReweightingEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
1726      TH1D *hReweightMCHistEtatemp = (TH1D*)f->Get(fNameHistoReweightingEta.Data());
1727      hReweightMCHistEta = new TH1D(*hReweightMCHistEtatemp);
1728      hReweightMCHistEta->SetDirectory(0);
1729      if (hReweightMCHistEta) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
1730      else AliWarning(Form("%s not found in %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
1731   }
1732
1733   if (fNameFitDataEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
1734      TF1 *fFitDataEtatemp = (TF1*)f->Get(fNameFitDataEta.Data());
1735      fFitDataEta = new TF1(*fFitDataEtatemp);
1736      if (fFitDataEta) AliInfo(Form("%s has been loaded from %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
1737      else AliWarning(Form("%s not found in %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
1738
1739   }
1740   if (fNameHistoReweightingK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
1741      TH1D *hReweightMCHistK0stemp = (TH1D*)f->Get(fNameHistoReweightingK0s.Data());
1742      hReweightMCHistK0s = new TH1D(*hReweightMCHistK0stemp);
1743      hReweightMCHistK0s->SetDirectory(0);
1744      if (hReweightMCHistK0s) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
1745      else AliWarning(Form("%s not found in %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
1746   }
1747
1748   if (fNameFitDataK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
1749      TF1 *fFitDataK0stemp = (TF1*)f->Get(fNameFitDataK0s.Data());
1750      fFitDataK0s = new TF1(*fFitDataK0stemp);
1751      if (fFitDataK0s) AliInfo(Form("%s has been loaded from %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
1752      else AliWarning(Form("%s not found in %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
1753   }
1754   f->Close();
1755   delete f;
1756   
1757 }
1758
1759
1760 ///________________________________________________________________________
1761 Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
1762    // Initialize Cuts from a given Cut string
1763    if(fDoReweightHistoMCPi0 || fDoReweightHistoMCEta || fDoReweightHistoMCK0s) {
1764       AliInfo("Weighting was enabled");
1765       LoadReweightingHistosMCFromFile();
1766    }
1767
1768    AliInfo(Form("Set Photoncut Number: %s",analysisCutSelection.Data()));
1769    if(analysisCutSelection.Length()!=kNCuts) {
1770       AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
1771       return kFALSE;
1772    }
1773    if(!analysisCutSelection.IsDigit()){
1774       AliError("Cut selection contains characters");
1775       return kFALSE;
1776    }
1777
1778    const char *cutSelection = analysisCutSelection.Data();
1779 #define ASSIGNARRAY(i)  fCuts[i] = cutSelection[i] - '0'
1780    for(Int_t ii=0;ii<kNCuts;ii++){
1781       ASSIGNARRAY(ii);
1782    }
1783
1784    // Set Individual Cuts
1785    for(Int_t ii=0;ii<kNCuts;ii++){
1786       if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
1787    }
1788
1789    PrintCutsWithValues();
1790
1791    return kTRUE;
1792 }
1793 ///________________________________________________________________________
1794 Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
1795    ///Set individual cut ID
1796
1797    switch (cutID) {
1798
1799    case kv0FinderType:
1800       if( SetV0Finder(value)) {
1801          fCuts[kv0FinderType] = value;
1802          UpdateCutString();
1803          return kTRUE;
1804       } else return kFALSE;
1805
1806    case kededxSigmaCut:
1807       if( SetTPCdEdxCutElectronLine(value)) {
1808          fCuts[kededxSigmaCut] = value;
1809          UpdateCutString();
1810          return kTRUE;
1811       } else return kFALSE;
1812
1813    case kpidedxSigmaCut:
1814       if( SetTPCdEdxCutPionLine(value)) {
1815          fCuts[kpidedxSigmaCut] = value;
1816          UpdateCutString();
1817          return kTRUE;
1818       } else return kFALSE;
1819
1820    case kpiMomdedxSigmaCut:
1821       if( SetMinMomPiondEdxCut(value)) {
1822          fCuts[kpiMomdedxSigmaCut] = value;
1823          UpdateCutString();
1824          return kTRUE;
1825       } else return kFALSE;
1826
1827    case kchi2GammaCut:
1828       if( SetChi2GammaCut(value)) {
1829          fCuts[kchi2GammaCut] = value;
1830          UpdateCutString();
1831          return kTRUE;
1832       } else return kFALSE;
1833
1834    case ksinglePtCut:
1835       if( SetSinglePtCut(value)) {
1836          fCuts[ksinglePtCut] = value;
1837          UpdateCutString();
1838          return kTRUE;
1839       } else return kFALSE;
1840
1841    case kclsTPCCut:
1842       if( SetTPCClusterCut(value)) {
1843          fCuts[kclsTPCCut] = value;
1844          UpdateCutString();
1845          return kTRUE;
1846       } else return kFALSE;
1847
1848    case ketaCut:
1849       if( SetEtaCut(value)) {
1850          fCuts[ketaCut] = value;
1851          UpdateCutString();
1852          return kTRUE;
1853       } else return kFALSE;
1854
1855    case kLowPRejectionSigmaCut:
1856       if( SetLowPRejectionCuts(value)) {
1857          fCuts[kLowPRejectionSigmaCut] = value;
1858          UpdateCutString();
1859          return kTRUE;
1860       } else return kFALSE;
1861
1862    case kQtMaxCut:
1863       if( SetQtMaxCut(value)) {
1864          fCuts[kQtMaxCut] = value;
1865          UpdateCutString();
1866          return kTRUE;
1867       } else return kFALSE;
1868
1869    case kpiMaxMomdedxSigmaCut:
1870       if( SetMaxMomPiondEdxCut(value)) {
1871          fCuts[kpiMaxMomdedxSigmaCut] = value;
1872          UpdateCutString();
1873          return kTRUE;
1874       } else return kFALSE;
1875
1876    case kRCut:
1877       if( SetRCut(value)) {
1878          fCuts[kRCut] = value;
1879          UpdateCutString();
1880          return kTRUE;
1881       } else return kFALSE;
1882
1883    case kremovePileUp:
1884       if( SetRemovePileUp(value)) {
1885          fCuts[kremovePileUp] = value;
1886          UpdateCutString();
1887          return kTRUE;
1888       } else return kFALSE;
1889
1890    case kselectV0AND:
1891       if( SetSelectSpecialTrigger(value)) {
1892          fCuts[kselectV0AND] = value;
1893          UpdateCutString();
1894          return kTRUE;
1895       } else return kFALSE;
1896
1897    case kmultiplicityMethod:
1898       if( SetMultiplicityMethod(value)) {
1899          fCuts[kmultiplicityMethod] = value;
1900          UpdateCutString();
1901          return kTRUE;
1902       } else return kFALSE;
1903
1904    case kisHeavyIon:
1905       if( SetIsHeavyIon(value)) {
1906          fCuts[kisHeavyIon] = value;
1907          UpdateCutString();
1908          return kTRUE;
1909       } else return kFALSE;
1910
1911    case kCentralityMin:
1912       if( SetCentralityMin(value)) {
1913          fCuts[kCentralityMin] = value;
1914          UpdateCutString();
1915          return kTRUE;
1916       } else return kFALSE;
1917
1918    case kCentralityMax:
1919       if( SetCentralityMax(value)) {
1920          fCuts[kCentralityMax] = value;
1921          UpdateCutString();
1922          return kTRUE;
1923       } else return kFALSE;
1924
1925    case kTOFelectronPID:
1926       if( SetTOFElectronPIDCut(value)) {
1927          fCuts[kTOFelectronPID] = value;
1928          UpdateCutString();
1929          return kTRUE;
1930       } else return kFALSE;
1931
1932    case kdoPhotonAsymmetryCut:
1933       if( SetPhotonAsymmetryCut(value)) {
1934          fCuts[kdoPhotonAsymmetryCut] = value;
1935          UpdateCutString();
1936          return kTRUE;
1937       } else return kFALSE;
1938
1939    case kPsiPair:
1940       if( SetPsiPairCut(value)) {
1941          fCuts[kPsiPair] = value;
1942          UpdateCutString();
1943          return kTRUE;
1944       } else return kFALSE;
1945
1946    case kCosPAngle:
1947       if( SetCosPAngleCut(value)) {
1948          fCuts[kCosPAngle] = value;
1949          UpdateCutString();
1950          return kTRUE;
1951       } else return kFALSE;
1952
1953
1954    case kElecShare:
1955       if( SetSharedElectronCut(value)) {
1956          fCuts[kElecShare] = value;
1957          UpdateCutString();
1958          return kTRUE;
1959       } else return kFALSE;
1960
1961    case kToCloseV0s:
1962       if( SetToCloseV0sCut(value)) {
1963          fCuts[kToCloseV0s] = value;
1964          UpdateCutString();
1965          return kTRUE;
1966       } else return kFALSE;
1967
1968    case kExtraSignals:
1969       if( SetRejectExtraSignalsCut(value)) {
1970          fCuts[kExtraSignals] = value;
1971          UpdateCutString();
1972          return kTRUE;
1973       } else return kFALSE;
1974
1975    case kDcaRPrimVtx:
1976       if( SetDCARPhotonPrimVtxCut(value)) {
1977          fCuts[kDcaRPrimVtx] = value;
1978          UpdateCutString();
1979          return kTRUE;
1980       } else return kFALSE;
1981
1982    case kDcaZPrimVtx:
1983       if( SetDCAZPhotonPrimVtxCut(value)) {
1984          fCuts[kDcaZPrimVtx] = value;
1985          UpdateCutString();
1986          return kTRUE;
1987       } else return kFALSE;
1988
1989    case kInPlaneOutOfPlane:
1990    if( SetInPlaneOutOfPlane(value)) {
1991       fCuts[kInPlaneOutOfPlane] = value;
1992       UpdateCutString();
1993       return kTRUE;
1994    } else return kFALSE;
1995
1996
1997       
1998
1999    case kNCuts:
2000       AliError("Cut id out of range");
2001       return kFALSE;
2002    }
2003
2004    AliError("Cut id %d not recognized");
2005    return kFALSE;
2006
2007
2008 }
2009 ///________________________________________________________________________
2010 void AliConversionCuts::PrintCuts() {
2011    // Print out current Cut Selection
2012    for(Int_t ic = 0; ic < kNCuts; ic++) {
2013       printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
2014    }
2015 }
2016
2017 void AliConversionCuts::PrintCutsWithValues() {
2018    // Print out current Cut Selection with value
2019    if (fIsHeavyIon == 0) {
2020       printf("Running in pp mode \n");
2021       if (fSpecialTrigger == 0){
2022         printf("\t only events triggered by V0OR will be analysed \n");
2023       } else if (fSpecialTrigger == 1){
2024         printf("\t only events triggered by V0AND will be analysed \n");
2025       } else if (fSpecialTrigger == 2){
2026          printf("\t only events where SDD was present will be analysed \n");
2027       } else if (fSpecialTrigger == 3){
2028          printf("\t only events where SDD was present will be analysed and triggered by VOAND\n");
2029       } else if (fSpecialTrigger > 3){   
2030          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2031       }
2032    } else if (fIsHeavyIon == 1){ 
2033       printf("Running in PbPb mode \n");
2034       if (fDetectorCentrality == 0){
2035          printf("\t centrality selection based on V0M \n");
2036       } else if (fDetectorCentrality == 1){
2037          printf("\t centrality selection based on Cl1 \n");
2038       }   
2039       if (fModCentralityClass == 0){
2040         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
2041       } else if ( fModCentralityClass == 1){ 
2042         printf("\t %d - %d \n", fCentralityMin*5, fCentralityMax*5);
2043       } else if ( fModCentralityClass == 2){ 
2044         printf("\t %d - %d \n", fCentralityMin*5+45, fCentralityMax*5+45);
2045       } else if (fModCentralityClass == 3){
2046         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*10, fCentralityMax*10);
2047       } else if ( fModCentralityClass == 4){ 
2048         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5, fCentralityMax*5);
2049       } else if ( fModCentralityClass == 5){ 
2050         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5+45, fCentralityMax*5+45);
2051       }
2052       if (fSpecialTrigger == 0){
2053         printf("\t only events triggered by kMB, kCentral, kSemiCentral will be analysed \n");
2054       } else if (fSpecialTrigger > 4){   
2055          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2056       }
2057    } else if (fIsHeavyIon == 2){
2058       printf("Running in pPb mode \n");
2059       if (fDetectorCentrality == 0){
2060          printf("\t centrality selection based on V0A \n");
2061       } else if (fDetectorCentrality == 1){
2062          printf("\t centrality selection based on Cl1 \n");
2063       }   
2064       if (fModCentralityClass == 0){
2065         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
2066       }
2067       if (fSpecialTrigger == 0){
2068         printf("\t only events triggered by kINT7 will be analysed \n");
2069       } else if (fSpecialTrigger > 4){   
2070          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2071       }
2072    }   
2073    
2074    
2075    
2076    
2077 }
2078
2079 ///________________________________________________________________________
2080 Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
2081 {   // Set Cut
2082    switch(isHeavyIon){
2083    case 0:
2084       fIsHeavyIon=0;
2085       break;
2086    case 1:
2087       fIsHeavyIon=1;
2088       fDetectorCentrality=0;
2089       break;
2090    case 2:
2091       fIsHeavyIon=1;
2092       fDetectorCentrality=1;
2093       break;
2094    case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
2095       fIsHeavyIon=1;
2096       fDetectorCentrality=0;
2097       fModCentralityClass=1;
2098       break;
2099    case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2100       fIsHeavyIon=1;
2101       fDetectorCentrality=0;
2102       fModCentralityClass=2;
2103       break;
2104    case 5: //strict cut on v0 tracks for MC
2105       fIsHeavyIon=1;
2106       fDetectorCentrality=0;
2107       fModCentralityClass=3;
2108       break;
2109    case 6: //allows to select centrality 0-45% in steps of 5% for track mult
2110       //strict cut on v0 tracks for MC
2111       fIsHeavyIon=1;
2112       fDetectorCentrality=0;
2113       fModCentralityClass=4;
2114       break;
2115    case 7: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2116       //strict cut on v0 tracks for MC
2117       fIsHeavyIon=1;
2118       fDetectorCentrality=0;
2119       fModCentralityClass=5;
2120       break;
2121    case 8:
2122       fIsHeavyIon=2;
2123       fDetectorCentrality=0;
2124       break;
2125    case 9:
2126       fIsHeavyIon=2;
2127       fDetectorCentrality=1;
2128       break;
2129    default:
2130       AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
2131       return kFALSE;
2132    }
2133    return kTRUE;
2134 }
2135
2136 //___________________________________________________________________
2137 Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
2138 {
2139    // Set Cut
2140    if(minCentrality<0||minCentrality>9){
2141       AliError(Form("minCentrality not defined %d",minCentrality));
2142       return kFALSE;
2143    }
2144
2145    fCentralityMin=minCentrality;
2146    return kTRUE;
2147 }
2148 //___________________________________________________________________
2149 Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
2150 {
2151    // Set Cut
2152    if(maxCentrality<0||maxCentrality>9){
2153       AliError(Form("maxCentrality not defined %d",maxCentrality));
2154       return kFALSE;
2155    }
2156    fCentralityMax=maxCentrality;
2157    return kTRUE;
2158 }
2159 ///________________________________________________________________________
2160 Int_t AliConversionCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
2161 {// Set Cut
2162
2163    switch(selectSpecialTrigger){
2164    case 0:
2165       fSpecialTrigger=0; // dont care
2166       break;
2167    case 1:
2168       fSpecialTrigger=1; // V0AND
2169       break;
2170    case 2:
2171       fSpecialTrigger=2; // with SDD requested
2172       break;
2173    case 3:
2174       fSpecialTrigger=3; // V0AND plus with SDD requested
2175       break;
2176    // allows to run MB & 6 other different trigger classes in parallel with the same photon cut
2177    case 4:
2178       fSpecialTrigger=4; // different trigger class as MB
2179       fTriggerSelectedManually = kTRUE;
2180       break;
2181    case 5:
2182       fSpecialTrigger=4; // different trigger class as MB
2183       fTriggerSelectedManually = kTRUE;
2184       break;
2185    case 6:
2186       fSpecialTrigger=4; // different trigger class as MB
2187       fTriggerSelectedManually = kTRUE;
2188       break;
2189    case 7:
2190       fSpecialTrigger=4; // different trigger class as MB
2191       fTriggerSelectedManually = kTRUE;
2192       break;
2193     case 8:
2194       fSpecialTrigger=4; // different trigger class as MB
2195       fTriggerSelectedManually = kTRUE;
2196       break;
2197     case 9:
2198       fSpecialTrigger=4; // different trigger class as MB
2199       fTriggerSelectedManually = kTRUE;
2200       break;
2201    default:
2202       AliError("Warning: Special Trigger Not known");
2203       return kFALSE;
2204    }
2205    return kTRUE;
2206 }
2207 ///________________________________________________________________________
2208 Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
2209 {
2210    // Set Cut
2211    fMultiplicityMethod=multiplicityMethod;
2212
2213    // 0 Photon Multiplicity
2214    // 1 TPC Track multiplicity
2215    // 2 V0 Mult
2216    // 3 SPD Mult
2217
2218    return kTRUE;
2219 }
2220 ///________________________________________________________________________
2221 Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
2222 {// Set Cut
2223    switch(removePileUp){
2224    case 0:
2225       fRemovePileUp=kFALSE;
2226       break;
2227    case 1:
2228       fRemovePileUp=kTRUE;
2229       break;
2230    default:
2231       AliError("RemovePileUpCut not defined");
2232       return kFALSE;
2233    }
2234    return kTRUE;
2235 }
2236 ///________________________________________________________________________
2237 Bool_t AliConversionCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
2238
2239    switch(extraSignal){
2240    case 0:
2241       fRejectExtraSignals = 0;
2242       break; // No Rejection
2243    case 1:
2244       fRejectExtraSignals = 1;
2245       break; // MinBias Header
2246    case 2:
2247       fRejectExtraSignals = 2;
2248       break; // User String Array
2249    case 3:
2250       fRejectExtraSignals = 3;
2251       break; // Rejection for Gamma Correction only
2252    default:
2253       AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
2254       return kFALSE;
2255    }
2256    return kTRUE;
2257 }
2258 ///________________________________________________________________________
2259 Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
2260 {   // Set Cut
2261    switch (v0FinderType){
2262    case 0:  // on fly V0 finder
2263       cout << "have chosen onfly V0" << endl;
2264       fUseOnFlyV0Finder=kTRUE;
2265       break;
2266    case 1:  // offline V0 finder
2267       cout << "have chosen offline V0" << endl;
2268       fUseOnFlyV0Finder=kFALSE;
2269       break;
2270    default:
2271       AliError(Form(" v0FinderType not defined %d",v0FinderType));
2272       return kFALSE;
2273    }
2274    return kTRUE;
2275 }
2276 ///________________________________________________________________________
2277 Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
2278 {   // Set Cut
2279
2280    //Set Standard LineCutZValues
2281    fLineCutZValueMin = -2;
2282    fLineCutZValue = 7.;
2283
2284    switch(etaCut){
2285    case 0: // 0.9
2286       fEtaCut     = 0.9;
2287       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2288       fEtaCutMin     = -0.1;
2289       fLineCutZRSlopeMin = 0.;
2290       break;
2291    case 1:  // 0.6  // changed from 1.2 to 0.6 on 2013.06.10
2292       fEtaCut     = 0.6;
2293       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2294       fEtaCutMin     = -0.1;
2295       fLineCutZRSlopeMin = 0.;
2296       break;
2297    case 2:  // 1.4
2298       fEtaCut     = 1.4;
2299       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2300       fEtaCutMin     = -0.1;
2301       fLineCutZRSlopeMin = 0.;
2302       break;
2303    case 3: // 0.65
2304       fEtaCut     = 0.65;
2305       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2306       fEtaCutMin     = -0.1;
2307       fLineCutZRSlopeMin = 0.;
2308       break;
2309    case 4: // 0.75
2310       fEtaCut     = 0.75;
2311       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2312       fEtaCutMin     = -0.1;
2313       fLineCutZRSlopeMin = 0.;
2314       break;
2315    case 5: // 0.5
2316       fEtaCut     = 0.5;
2317       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2318       fEtaCutMin     = -0.1;
2319       fLineCutZRSlopeMin = 0.;
2320       break;
2321    case 6: // 5.
2322       fEtaCut     = 5.;
2323       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2324       fEtaCutMin     = -0.1;
2325       fLineCutZRSlopeMin = 0.;
2326       break;
2327    case 7:
2328       if (fIsHeavyIon==1){
2329          fEtaCut     = 0.7;
2330          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2331          fEtaCutMin     = -0.1;
2332          fLineCutZRSlopeMin = 0.;
2333          break;
2334       } else {   
2335          fEtaCut     = 0.3;
2336          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2337          fEtaCutMin     = -0.1;
2338          fLineCutZRSlopeMin = 0.;
2339          break;
2340       }
2341    // case 8: // 0.1 - 0.8
2342    //    fEtaCut     = 0.9;
2343    //    fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2344    //    fEtaCutMin     = 0.1;
2345    //    fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2346    //    break;
2347    case 8: // 0.4
2348       fEtaCut     = 0.4;
2349       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2350       fEtaCutMin     = -0.1;
2351       fLineCutZRSlopeMin = 0.;
2352       break;
2353    case 9: // 10
2354       fEtaCut     = 10;
2355       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2356       fEtaCutMin     = -0.1;
2357       fLineCutZRSlopeMin = 0.;
2358       break;
2359    default:
2360       AliError(Form(" EtaCut not defined %d",etaCut));
2361       return kFALSE;
2362    }
2363    return kTRUE;
2364 }
2365 ///________________________________________________________________________
2366 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
2367    // Set Cut
2368    switch(RCut){
2369    case 0:
2370       fMinR=0;
2371       fMaxR = 180.;
2372       break;
2373    case 1:
2374       fMinR=2.8;
2375       fMaxR = 180.;
2376       break;
2377    case 2:
2378       fMinR=5.;
2379       fMaxR = 180.;
2380       break;
2381    case 3:
2382       fMaxR = 70.;
2383       fMinR = 10.;
2384       break;
2385    case 4:
2386       fMaxR = 70.;
2387       fMinR = 5.;
2388       break;
2389       // High purity cuts for PbPb (remove first layers of material)
2390    case 5:
2391       fMaxR = 180.;
2392       fMinR = 10.;
2393       break;
2394    case 6:
2395       fMaxR = 180.;
2396       fMinR = 20.;
2397       break;
2398    case 7:
2399       fMaxR = 180.;
2400       fMinR = 26.;
2401       break;
2402    case 8:
2403       fMaxR = 180.;
2404       fMinR = 12.5;
2405       break;
2406    case 9:
2407       fMaxR = 180.;
2408       fMinR = 7.5;
2409       break;
2410
2411    default:
2412       AliError("RCut not defined");
2413       return kFALSE;
2414    }
2415    return kTRUE;
2416 }
2417 ///________________________________________________________________________
2418 Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
2419 {   // Set Cut
2420    switch(singlePtCut){
2421    case 0: // 0.050 GeV
2422       fSinglePtCut = 0.050;
2423       break;
2424    case 1:  // 0.100 GeV
2425       fSinglePtCut = 0.100;
2426       break;
2427    case 2:  // 0.150 GeV
2428       fSinglePtCut = 0.150;
2429       break;
2430    case 3:  // 0.200 GeV
2431       fSinglePtCut = 0.200;
2432       break;
2433    case 4:  // 0.075 GeV
2434       fSinglePtCut = 0.075;
2435       break;
2436    case 5:  // 0.125 GeV
2437       fSinglePtCut = 0.125;
2438       break;
2439    case 6:  // 0.04 GeV
2440       fSinglePtCut = 0.040;
2441       break;
2442    case 7:  // 0.0 GeV
2443       fSinglePtCut = 0.0;
2444       break;
2445    default:
2446       AliError(Form("singlePtCut not defined %d",singlePtCut));
2447       return kFALSE;
2448    }
2449    return kTRUE;
2450 }
2451 ///________________________________________________________________________
2452 Bool_t AliConversionCuts::SetTPCClusterCut(Int_t clsTPCCut)
2453 {   // Set Cut
2454    switch(clsTPCCut){
2455    case 0: // 0
2456       fMinClsTPC= 0.;
2457       break;
2458    case 1:  // 60
2459       fMinClsTPC= 60.;
2460       break;
2461    case 2:  // 80
2462       fMinClsTPC= 80.;
2463       break;
2464    case 3:  // 100
2465       fMinClsTPC= 100.;
2466       break;
2467    case 4:  // 95% of findable clusters
2468       fMinClsTPCToF= 0.95;
2469       fUseCorrectedTPCClsInfo=1;
2470       break;
2471    case 5:  // 0% of findable clusters
2472       fMinClsTPCToF= 0.0;
2473       fUseCorrectedTPCClsInfo=1;
2474       break;
2475    case 6:  // 70% of findable clusters
2476       fMinClsTPCToF= 0.7;
2477       fUseCorrectedTPCClsInfo=1;
2478       break;
2479    case 7:  // 0% of findable clusters
2480       fMinClsTPCToF= 0.35;
2481       fUseCorrectedTPCClsInfo=0;
2482       break;
2483    case 8:
2484       fMinClsTPCToF= 0.35;
2485       fUseCorrectedTPCClsInfo=1;
2486       break;
2487    case 9:
2488       fMinClsTPCToF= 0.6;
2489       fUseCorrectedTPCClsInfo=1;
2490       break;
2491    default:
2492       AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
2493       return kFALSE;
2494    }
2495    return kTRUE;
2496 }
2497 ///________________________________________________________________________
2498 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
2499 {   // Set Cut
2500    switch(ededxSigmaCut){
2501    case 0: // -10,10
2502       fPIDnSigmaBelowElectronLine=-10;
2503       fPIDnSigmaAboveElectronLine=10;
2504       break;
2505    case 1: // -5,5
2506       fPIDnSigmaBelowElectronLine=-5;
2507       fPIDnSigmaAboveElectronLine=5;
2508       break;
2509    case 2: // -3,5
2510       fPIDnSigmaBelowElectronLine=-3;
2511       fPIDnSigmaAboveElectronLine=5;
2512       break;
2513    case 3: // -4,5
2514       fPIDnSigmaBelowElectronLine=-4;
2515       fPIDnSigmaAboveElectronLine=5;
2516       break;
2517    case 4: // -6,7
2518       fPIDnSigmaBelowElectronLine=-6;
2519       fPIDnSigmaAboveElectronLine=7;
2520       break;
2521    case 5: // -4,4
2522       fPIDnSigmaBelowElectronLine=-4;
2523       fPIDnSigmaAboveElectronLine=4;
2524       break;
2525    case 6: // -2.5,4
2526       fPIDnSigmaBelowElectronLine=-2.5;
2527       fPIDnSigmaAboveElectronLine=4;
2528       break;
2529    case 7: // -2,3.5
2530       fPIDnSigmaBelowElectronLine=-2;
2531       fPIDnSigmaAboveElectronLine=3.5;
2532       break;
2533    default:
2534       AliError("TPCdEdxCutElectronLine not defined");
2535       return kFALSE;
2536
2537    }
2538    return kTRUE;
2539 }
2540 ///________________________________________________________________________
2541 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
2542 {   // Set Cut
2543
2544    switch(pidedxSigmaCut){
2545    case 0:  // -10
2546       fPIDnSigmaAbovePionLine=-10;
2547       fPIDnSigmaAbovePionLineHighPt=-10;
2548       break;
2549    case 1:   // 0
2550       fPIDnSigmaAbovePionLine=0;
2551       fPIDnSigmaAbovePionLineHighPt=-10;
2552       break;
2553    case 2:  // 1
2554       fPIDnSigmaAbovePionLine=1;
2555       fPIDnSigmaAbovePionLineHighPt=-10;
2556       break;
2557    case 3:  // 1
2558       fPIDnSigmaAbovePionLine=2.5;
2559       fPIDnSigmaAbovePionLineHighPt=-10;
2560       break;
2561    case 4:  // 1
2562       fPIDnSigmaAbovePionLine=0.5;
2563       fPIDnSigmaAbovePionLineHighPt=-10;
2564       break;
2565    case 5:  // 1
2566       fPIDnSigmaAbovePionLine=2.;
2567       fPIDnSigmaAbovePionLineHighPt=-10;
2568       break;
2569    case 6:  // 1
2570       fPIDnSigmaAbovePionLine=2.;
2571       fPIDnSigmaAbovePionLineHighPt=0.5;
2572       break;
2573    case 7:  // 1
2574       fPIDnSigmaAbovePionLine=3.5;
2575       fPIDnSigmaAbovePionLineHighPt=-10;
2576       break;
2577    case 8:  // 1
2578       fPIDnSigmaAbovePionLine=2.;
2579       fPIDnSigmaAbovePionLineHighPt=1.;
2580       break;
2581    case 9:
2582       fPIDnSigmaAbovePionLine=3.0; // We need a bit less tight cut on dE/dx
2583       fPIDnSigmaAbovePionLineHighPt=-10;
2584       break;
2585    default:
2586       AliError(Form("Warning: pidedxSigmaCut not defined %d",pidedxSigmaCut));
2587       return kFALSE;
2588    }
2589    return kTRUE;
2590 }
2591 ///________________________________________________________________________
2592 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
2593 {   // Set Cut
2594    switch(piMomdedxSigmaCut){
2595    case 0:  // 0.5 GeV
2596       fPIDMinPnSigmaAbovePionLine=0.5;
2597       break;
2598    case 1:  // 1. GeV
2599       fPIDMinPnSigmaAbovePionLine=1.;
2600       break;
2601    case 2:  // 1.5 GeV
2602       fPIDMinPnSigmaAbovePionLine=1.5;
2603       break;
2604    case 3:  // 20.0 GeV
2605       fPIDMinPnSigmaAbovePionLine=20.;
2606       break;
2607    case 4:  // 50.0 GeV
2608       fPIDMinPnSigmaAbovePionLine=50.;
2609       break;
2610    case 5:  // 0.3 GeV
2611       fPIDMinPnSigmaAbovePionLine=0.3;
2612       break;
2613    case 6:  // 0.25 GeV
2614       fPIDMinPnSigmaAbovePionLine=0.25;
2615       break;
2616    case 7:  // 0.4 GeV
2617       fPIDMinPnSigmaAbovePionLine=0.4;
2618       break;
2619    case 8:  // 0.2 GeV
2620       fPIDMinPnSigmaAbovePionLine=0.2;
2621       break;
2622    default:
2623       AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
2624       return kFALSE;
2625    }
2626    return kTRUE;
2627 }
2628 ///________________________________________________________________________
2629 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
2630 {   // Set Cut
2631    switch(piMaxMomdedxSigmaCut){
2632    case 0:  // 100. GeV
2633       fPIDMaxPnSigmaAbovePionLine=100.;
2634       break;
2635    case 1:  // 5. GeV
2636       fPIDMaxPnSigmaAbovePionLine=5.;
2637       break;
2638    case 2:  // 4. GeV
2639       fPIDMaxPnSigmaAbovePionLine=4.;
2640       break;
2641    case 3:  // 3.5 GeV
2642       fPIDMaxPnSigmaAbovePionLine=3.5;
2643       break;
2644    case 4:  // 3. GeV
2645       fPIDMaxPnSigmaAbovePionLine=3.;
2646       break;
2647    case 5:  // 7. GeV
2648       fPIDMaxPnSigmaAbovePionLine=7.;
2649       break;
2650    default:
2651       AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
2652       return kFALSE;
2653    }
2654    return kTRUE;
2655 }
2656 ///________________________________________________________________________
2657 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
2658 {   // Set Cut
2659    switch(LowPRejectionSigmaCut){
2660    case 0:  //
2661       fPIDnSigmaAtLowPAroundKaonLine=0;
2662       fPIDnSigmaAtLowPAroundProtonLine=0;
2663       fPIDnSigmaAtLowPAroundPionLine=0;
2664       fDoKaonRejectionLowP = kFALSE;
2665       fDoProtonRejectionLowP = kFALSE;
2666       fDoPionRejectionLowP = kFALSE;
2667       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2668       break;
2669    case 1:  //
2670       fPIDnSigmaAtLowPAroundKaonLine=0.5;
2671       fPIDnSigmaAtLowPAroundProtonLine=0.5;
2672       fPIDnSigmaAtLowPAroundPionLine=0.5;
2673       fDoKaonRejectionLowP = kTRUE;
2674       fDoProtonRejectionLowP = kTRUE;
2675       fDoPionRejectionLowP = kTRUE;
2676       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2677       break;
2678    case 2:  //
2679       fPIDnSigmaAtLowPAroundKaonLine=1;
2680       fPIDnSigmaAtLowPAroundProtonLine=1;
2681       fPIDnSigmaAtLowPAroundPionLine=1;
2682       fDoKaonRejectionLowP = kTRUE;
2683       fDoProtonRejectionLowP = kTRUE;
2684       fDoPionRejectionLowP = kTRUE;
2685       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2686       break;
2687    case 3:  //
2688       fPIDnSigmaAtLowPAroundKaonLine=2.;
2689       fPIDnSigmaAtLowPAroundProtonLine=2.;
2690       fPIDnSigmaAtLowPAroundPionLine=2.;
2691       fDoKaonRejectionLowP = kTRUE;
2692       fDoProtonRejectionLowP = kTRUE;
2693       fDoPionRejectionLowP = kTRUE;
2694       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2695       break;
2696    case 4:  //
2697       fPIDnSigmaAtLowPAroundKaonLine=0.;
2698       fPIDnSigmaAtLowPAroundProtonLine=0.;
2699       fPIDnSigmaAtLowPAroundPionLine=1;
2700       fDoKaonRejectionLowP = kFALSE;
2701       fDoProtonRejectionLowP = kFALSE;
2702       fDoPionRejectionLowP = kTRUE;
2703       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2704       break;
2705    case 5:  //
2706       fPIDnSigmaAtLowPAroundKaonLine=0.;
2707       fPIDnSigmaAtLowPAroundProtonLine=0.;
2708       fPIDnSigmaAtLowPAroundPionLine=1.5;
2709       fDoKaonRejectionLowP = kFALSE;
2710       fDoProtonRejectionLowP = kFALSE;
2711       fDoPionRejectionLowP = kTRUE;
2712       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2713       break;
2714    case 6:  //
2715       fPIDnSigmaAtLowPAroundKaonLine=0.;
2716       fPIDnSigmaAtLowPAroundProtonLine=0.;
2717       fPIDnSigmaAtLowPAroundPionLine=2.;
2718       fDoKaonRejectionLowP = kFALSE;
2719       fDoProtonRejectionLowP = kFALSE;
2720       fDoPionRejectionLowP = kTRUE;
2721       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2722       break;
2723    case 7:  //
2724       fPIDnSigmaAtLowPAroundKaonLine=0.;
2725       fPIDnSigmaAtLowPAroundProtonLine=0.;
2726       fPIDnSigmaAtLowPAroundPionLine=0.5;
2727       fDoKaonRejectionLowP = kFALSE;
2728       fDoProtonRejectionLowP = kFALSE;
2729       fDoPionRejectionLowP = kTRUE;
2730       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2731       break;
2732    default:
2733       AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
2734       return kFALSE;
2735    }
2736    return kTRUE;
2737 }
2738 ///________________________________________________________________________
2739 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
2740    // Set Cut
2741    switch(TOFelectronPID){
2742    case 0: // no cut
2743       fUseTOFpid = kFALSE;
2744       fTofPIDnSigmaBelowElectronLine=-100;
2745       fTofPIDnSigmaAboveElectronLine=100;
2746       break;
2747    case 1: // -7,7
2748       fUseTOFpid = kTRUE;
2749       fTofPIDnSigmaBelowElectronLine=-7;
2750       fTofPIDnSigmaAboveElectronLine=7;
2751       break;
2752    case 2: // -5,5
2753       fUseTOFpid = kTRUE;
2754       fTofPIDnSigmaBelowElectronLine=-5;
2755       fTofPIDnSigmaAboveElectronLine=5;
2756       break;
2757    case 3: // -3,5
2758       fUseTOFpid = kTRUE;
2759       fTofPIDnSigmaBelowElectronLine=-3;
2760       fTofPIDnSigmaAboveElectronLine=5;
2761       break;
2762    case 4: // -2,3
2763       fUseTOFpid = kTRUE;
2764       fTofPIDnSigmaBelowElectronLine=-2;
2765       fTofPIDnSigmaAboveElectronLine=3;
2766       break;
2767    case 5: // -3,3
2768       fUseTOFpid = kTRUE;
2769       fTofPIDnSigmaBelowElectronLine=-3;
2770       fTofPIDnSigmaAboveElectronLine=3;
2771       break;
2772    default:
2773       AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
2774       return kFALSE;
2775    }
2776    return kTRUE;
2777 }
2778 ///________________________________________________________________________
2779 Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
2780 {   // Set Cut
2781    switch(QtMaxCut){
2782    case 0: //
2783       fQtMax=1.;
2784       fDoQtGammaSelection=kFALSE;
2785       fDo2DQt=kFALSE;
2786       break;
2787    case 1:
2788       fQtMax=0.1;
2789       fDo2DQt=kFALSE;
2790       break;
2791    case 2:
2792       fQtMax=0.07;
2793       fDo2DQt=kFALSE;
2794       break;
2795    case 3:
2796       fQtMax=0.05;
2797       fDo2DQt=kFALSE;
2798       break;
2799    case 4:
2800       fQtMax=0.03;
2801       fDo2DQt=kFALSE;
2802       break;
2803    case 5:
2804       fQtMax=0.02;
2805       fDo2DQt=kFALSE;
2806       break;
2807    case 6:
2808       fQtMax=0.02;
2809       fDo2DQt=kTRUE;
2810       break;
2811    case 7:
2812       fQtMax=0.15;
2813       fDo2DQt=kFALSE;
2814       break;
2815    case 8:
2816       fQtMax=0.05;
2817       fDo2DQt=kTRUE;
2818       break;   
2819    case 9:
2820       fQtMax=0.03;
2821       fDo2DQt=kTRUE;
2822       break;      
2823    default:
2824       AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
2825       return kFALSE;
2826    }
2827    return kTRUE;
2828 }
2829 ///________________________________________________________________________
2830 Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
2831 {   // Set Cut
2832
2833    switch(chi2GammaCut){
2834    case 0: // 100
2835       fChi2CutConversion = 100.;
2836       break;
2837    case 1:  // 50
2838       fChi2CutConversion = 50.;
2839       break;
2840    case 2:  // 30
2841       fChi2CutConversion = 30.;
2842       break;
2843    case 3:
2844       fChi2CutConversion = 200.;
2845       break;
2846    case 4:
2847       fChi2CutConversion = 500.;
2848       break;
2849    case 5:
2850       fChi2CutConversion = 100000.;
2851       break;
2852    case 6:
2853       fChi2CutConversion = 5.;
2854       break;
2855    case 7:
2856       fChi2CutConversion = 10.;
2857       break;
2858    case 8:
2859       fChi2CutConversion = 20.;
2860       break;
2861    case 9:
2862       fChi2CutConversion = 15.;
2863       break;
2864    default:
2865       AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
2866       return kFALSE;
2867    }
2868    return kTRUE;
2869 }
2870 ///________________________________________________________________________
2871 Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
2872
2873    switch(psiCut) {
2874    case 0:
2875       fPsiPairCut = 10000; //
2876       break;
2877    case 1:
2878       fPsiPairCut = 0.1; //
2879       break;
2880    case 2:
2881       fPsiPairCut = 0.05; // Standard
2882       break;
2883    case 3:
2884       fPsiPairCut = 0.035; //
2885       break;
2886    case 4:
2887       fPsiPairCut = 0.2; //
2888       break;   
2889    case 5:
2890       fPsiPairCut = 0.1; //
2891       fDo2DPsiPairChi2 = kTRUE;
2892       break;
2893    case 6:
2894       fPsiPairCut = 0.05; //
2895       fDo2DPsiPairChi2 = kTRUE;
2896       break;
2897    case 7:
2898       fPsiPairCut = 0.035; //
2899       fDo2DPsiPairChi2 = kTRUE;
2900       break;
2901    case 8:
2902       fPsiPairCut = 0.2; //
2903       fDo2DPsiPairChi2 = kTRUE; //
2904       break;
2905    case 9:
2906       fPsiPairCut = 0.5; //
2907       break;
2908    default:
2909       AliError(Form("PsiPairCut not defined %d",psiCut));
2910       return kFALSE;
2911    }
2912
2913    return kTRUE;
2914 }
2915 ///________________________________________________________________________
2916 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
2917    // Set Cut
2918    switch(doPhotonAsymmetryCut){
2919    case 0:
2920       fDoPhotonAsymmetryCut=0;
2921       fMinPPhotonAsymmetryCut=100.;
2922       fMinPhotonAsymmetry=0.;
2923       break;
2924    case 1:
2925       fDoPhotonAsymmetryCut=1;
2926       fMinPPhotonAsymmetryCut=3.5;
2927       fMinPhotonAsymmetry=0.04;
2928       break;
2929    case 2:
2930       fDoPhotonAsymmetryCut=1;
2931       fMinPPhotonAsymmetryCut=3.5;
2932       fMinPhotonAsymmetry=0.06;
2933       break;
2934    case 3:
2935       fDoPhotonAsymmetryCut=1;
2936       fMinPPhotonAsymmetryCut=0.0;
2937       fMinPhotonAsymmetry=0.05;
2938       break; 
2939    default:
2940       AliError(Form("PhotonAsymmetryCut not defined %d",doPhotonAsymmetryCut));
2941       return kFALSE;
2942    }
2943    fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
2944    return kTRUE;
2945 }
2946 ///________________________________________________________________________
2947 Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
2948
2949    switch(cosCut){
2950    case 0:
2951       fCosPAngleCut = -1; 
2952       break;
2953    case 1:
2954       fCosPAngleCut = 0; 
2955       break;
2956    case 2:
2957       fCosPAngleCut = 0.5; 
2958       break;
2959    case 3:
2960       fCosPAngleCut = 0.75; 
2961       break;
2962    case 4:
2963       fCosPAngleCut = 0.85; 
2964       break;
2965    case 5:
2966       fCosPAngleCut = 0.88; 
2967       break;
2968    case 6:
2969       fCosPAngleCut = 0.9;
2970       break;
2971    case 7:
2972       fCosPAngleCut = 0.95;
2973       break;
2974    default:
2975       AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
2976       return kFALSE;
2977    }
2978
2979    return kTRUE;
2980 }
2981 ///________________________________________________________________________
2982 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
2983
2984    switch(sharedElec){
2985    case 0:
2986       fDoSharedElecCut = kFALSE;
2987       break;
2988    case 1:
2989       fDoSharedElecCut = kTRUE;
2990       break;
2991    default:
2992       AliError(Form("Shared Electron Cut not defined %d",sharedElec));
2993       return kFALSE;
2994    }
2995
2996    return kTRUE;
2997 }
2998 ///________________________________________________________________________
2999 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
3000
3001    switch(toClose){
3002    case 0:
3003       fDoToCloseV0sCut = kFALSE;
3004       fminV0Dist = 250;
3005       break;
3006    case 1:
3007       fDoToCloseV0sCut = kTRUE;
3008       fminV0Dist = 1;
3009       break;
3010    case 2:
3011       fDoToCloseV0sCut = kTRUE;
3012       fminV0Dist = 2;
3013       break;
3014    case 3:
3015       fDoToCloseV0sCut = kTRUE;
3016       fminV0Dist = 3;
3017       break;
3018    default:
3019       AliError(Form("Shared Electron Cut not defined %d",toClose));
3020       return kFALSE;
3021    }
3022    return kTRUE;
3023 }
3024 ///________________________________________________________________________
3025 Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
3026 {   // Set Cut
3027    switch(TRDElectronCut){
3028    case 0:
3029       fDoTRDPID=kFALSE;
3030       break;
3031    case 1:
3032       fDoTRDPID=kTRUE;
3033       fPIDTRDEfficiency=0.1;
3034       break;
3035    case 8:
3036       fDoTRDPID=kTRUE;
3037       fPIDTRDEfficiency=0.8;
3038       break;
3039    case 9:
3040       fDoTRDPID=kTRUE;
3041       fPIDTRDEfficiency=0.9;
3042       break;
3043    default:
3044       AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
3045       return kFALSE;
3046    }
3047
3048    return kTRUE;
3049 }
3050
3051 ///________________________________________________________________________
3052 Bool_t AliConversionCuts::SetDCAZPhotonPrimVtxCut(Int_t DCAZPhotonPrimVtx){
3053    // Set Cut
3054    switch(DCAZPhotonPrimVtx){
3055    case 0:  //
3056       fDCAZPrimVtxCut   = 1000;
3057       break;
3058    case 1:  //
3059       fDCAZPrimVtxCut   = 10;
3060       break;
3061    case 2:  //
3062       fDCAZPrimVtxCut   = 5;
3063       break;
3064    case 3:  //
3065       fDCAZPrimVtxCut   = 4;
3066       break;
3067    case 4:  //
3068       fDCAZPrimVtxCut   = 3;
3069       break;
3070    case 5:  //
3071       fDCAZPrimVtxCut   = 2.5;
3072       break;
3073    case 6:  //
3074       fDCAZPrimVtxCut   = 2;
3075       break;
3076    case 7:  //
3077       fDCAZPrimVtxCut   = 1.5;
3078       break;
3079    case 8:  //
3080       fDCAZPrimVtxCut   = 1;
3081       break;
3082    case 9:  //
3083       fDCAZPrimVtxCut   = 0.5;
3084       break;
3085    default:
3086       cout<<"Warning: DCAZPhotonPrimVtx not defined "<<DCAZPhotonPrimVtx<<endl;
3087       return kFALSE;
3088    }
3089    return kTRUE;
3090 }
3091
3092 ///________________________________________________________________________
3093 Bool_t AliConversionCuts::SetDCARPhotonPrimVtxCut(Int_t DCARPhotonPrimVtx){
3094    // Set Cut
3095    switch(DCARPhotonPrimVtx){
3096    case 0:  //
3097       fDCARPrimVtxCut   = 1000;
3098       break;
3099    case 1:  //
3100       fDCARPrimVtxCut   = 10;
3101       break;
3102    case 2:  //
3103       fDCARPrimVtxCut   = 5;
3104       break;
3105    case 3:  //
3106       fDCARPrimVtxCut   = 4;
3107       break;
3108    case 4:  //
3109       fDCARPrimVtxCut   = 3;
3110       break;
3111    case 5:  //
3112       fDCARPrimVtxCut   = 2.5;
3113       break;
3114    case 6:  //
3115       fDCARPrimVtxCut   = 2;
3116       break;
3117    case 7:  //
3118       fDCARPrimVtxCut   = 1.5;
3119       break;
3120    case 8:  //
3121       fDCARPrimVtxCut   = 1;
3122       break;
3123    case 9:  //
3124       fDCARPrimVtxCut   = 0.5;
3125       break;
3126    default:
3127       cout<<"Warning: DCARPhotonPrimVtx not defined "<<DCARPhotonPrimVtx<<endl;
3128       return kFALSE;
3129    }
3130    return kTRUE;
3131 }
3132
3133 ///________________________________________________________________________
3134 Bool_t AliConversionCuts::SetInPlaneOutOfPlane(Int_t inOutPlane){
3135    // Set Cut
3136    switch(inOutPlane){
3137    case 0:  //
3138       fInPlaneOutOfPlane = 0; // No Event Plane
3139       break;
3140    case 1:  //
3141       fInPlaneOutOfPlane = 1; // In-Plane
3142       break;
3143    case 2:  //
3144       fInPlaneOutOfPlane = 2; // Out-Of-Plane
3145       break;
3146    default:
3147       cout<<"Warning: In-Plane or Out-Of-Plane not defined "<<inOutPlane<<endl;
3148       return kFALSE;
3149    }
3150    return kTRUE;
3151 }
3152
3153
3154 //-------------------------------------------------------------
3155 Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
3156 {   // Get Event Centrality
3157
3158    AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
3159    if(esdEvent){
3160       AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
3161
3162       if(fDetectorCentrality==0){
3163          if (fIsHeavyIon==2){
3164             return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
3165          } else{
3166             return fESDCentrality->GetCentralityPercentile("V0M"); // default
3167          }
3168       }
3169       if(fDetectorCentrality==1){
3170          return fESDCentrality->GetCentralityPercentile("CL1");
3171       }
3172    }
3173
3174    AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
3175    if(aodEvent){
3176       if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
3177    }
3178
3179    return -1;
3180 }
3181 //-------------------------------------------------------------
3182 Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
3183 {   // Centrality Selection
3184    if(!fIsHeavyIon)return kTRUE;
3185
3186    if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
3187    else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
3188
3189    Double_t centrality=GetCentrality(event);
3190    if(centrality<0)return kFALSE;
3191
3192    Int_t centralityC=0;
3193    if (fModCentralityClass == 0){
3194       centralityC= Int_t(centrality/10);
3195       if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3196          return kTRUE;
3197       else return kFALSE;
3198    }
3199    else if (fModCentralityClass ==1){
3200       centralityC= Int_t(centrality);
3201       if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3202          return kTRUE;
3203       } else return kFALSE;
3204    }
3205    else if (fModCentralityClass ==2){
3206       centralityC= Int_t(centrality);
3207       if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3208          return kTRUE;
3209       else return kFALSE;
3210    }
3211
3212    Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks();
3213    Int_t PrimaryTracks10[10][2] =
3214       {
3215          {9999,9999}, //  0
3216          {1210,2150}, // 10
3217          { 817,1435}, // 20
3218          { 536, 930}, // 30
3219          { 337, 570}, // 40
3220          { 197, 327}, // 50
3221          { 106, 173}, // 60
3222          {  51,  81}, // 70
3223          {  21,  34}, // 80
3224          {   0,   0}  // 90
3225       };
3226    Int_t PrimaryTracks5a[10][2] =
3227       {
3228          {9999,9999}, // 0
3229          {1485,2640}, // 5
3230          {1210,2150}, // 10
3231          { 995,1760}, // 15
3232          { 817,1435}, // 20
3233          { 666,1160}, // 25
3234          { 536, 930}, // 30
3235          { 428, 731}, // 35
3236          { 337, 570}, // 40
3237          { 260, 436}  // 45
3238       };
3239    Int_t PrimaryTracks5b[10][2] =
3240       {
3241          { 260, 436}, // 45
3242          { 197, 327}, // 50
3243          { 147, 239}, // 55
3244          { 106, 173}, // 60
3245          {  75, 120}, // 65
3246          {  51,  81}, // 70
3247          {  34,  53}, // 75
3248          {  21,  34}, // 80
3249          {  13,  19}, // 85
3250          {   0,   0}  // 90
3251       };
3252
3253    Int_t column = -1;
3254    if(event->IsA()==AliESDEvent::Class()) column = 0;
3255    if(event->IsA()==AliAODEvent::Class()) column = 1;
3256
3257    if (fModCentralityClass == 3){
3258       if(fMCEvent){
3259          if(nprimaryTracks > PrimaryTracks10[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks10[fCentralityMin][column])
3260             return kTRUE;
3261          else return kFALSE;
3262       }
3263       else{
3264          centralityC= Int_t(centrality/10);
3265          if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3266             return kTRUE;
3267          else return kFALSE;
3268       }
3269    }
3270    else if (fModCentralityClass ==4){
3271       if(fMCEvent){
3272          if(nprimaryTracks > PrimaryTracks5a[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5a[fCentralityMin][column])
3273             return kTRUE;
3274          else return kFALSE;
3275       }
3276       else{
3277          centralityC= Int_t(centrality);
3278          if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3279             return kTRUE;
3280          } else return kFALSE;
3281       }
3282    }
3283    else if (fModCentralityClass ==5){
3284       if(fMCEvent){
3285          if(nprimaryTracks > PrimaryTracks5b[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5b[fCentralityMin][column])
3286             return kTRUE;
3287          else return kFALSE;
3288       }
3289       else{
3290          centralityC= Int_t(centrality);
3291          if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3292             return kTRUE;
3293          else return kFALSE;
3294       }
3295    }
3296
3297    return kFALSE;
3298 }
3299 ///________________________________________________________________________
3300 Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
3301    // Cut on z position of primary vertex
3302    Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
3303
3304    if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
3305
3306    if (fIsHeavyIon == 2){
3307      if(fUtils->IsFirstEventInChunk(event)) return kFALSE;
3308      if(!fUtils->IsVertexSelected2013pA(event)) return kFALSE;
3309      if(fUtils->IsPileUpEvent(event)) return kFALSE;
3310    }
3311
3312    return kTRUE;
3313 }
3314 ///________________________________________________________________________
3315
3316 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
3317    // returns number of contributors to the vertex
3318
3319    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
3320    if(fESDEvent){
3321       if (fESDEvent->GetPrimaryVertex() != NULL){
3322          if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
3323 //     cout << "accepted global" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertex()->GetNContributors() << endl;
3324             return fESDEvent->GetPrimaryVertex()->GetNContributors();
3325          }
3326       }
3327
3328       if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
3329          if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3330 //     cout << "accepted SPD" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertexSPD()->GetNContributors() << endl;
3331             return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
3332          }  else {
3333             AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
3334 //            cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3335             return 0;
3336          }
3337       }
3338    }
3339
3340    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
3341    if(fAODEvent){
3342       if (fAODEvent->GetPrimaryVertex() != NULL){
3343          if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
3344             return fAODEvent->GetPrimaryVertex()->GetNContributors();
3345          }
3346       }
3347       if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
3348          if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3349             return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
3350          } else {
3351             AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
3352             return 0;
3353          }
3354       }
3355    }
3356   // cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3357    return 0;
3358 }
3359
3360 ///________________________________________________________________________
3361
3362 Bool_t AliConversionCuts::IsTriggerSelected(AliVEvent *fInputEvent)
3363 {
3364
3365    AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
3366
3367    UInt_t isSelected = AliVEvent::kAny;
3368    if (fInputHandler==NULL) return kFALSE;
3369    if( fInputHandler->GetEventSelection() || fInputEvent->IsA()==AliAODEvent::Class()) {
3370       if (!fTriggerSelectedManually){
3371          if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
3372          else {
3373             if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
3374                else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
3375                else fOfflineTriggerMask = AliVEvent::kMB;
3376          }
3377       }
3378       // Get the actual offline trigger mask for the event and AND it with the
3379       // requested mask. If no mask requested select by default the event.
3380 //       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
3381 //       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
3382
3383       if (fOfflineTriggerMask)
3384          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
3385    }
3386    fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
3387
3388    // Fill Histogram
3389    if(hTriggerClass){
3390       if (fIsSDDFired) hTriggerClass->Fill(33);
3391       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
3392       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
3393       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
3394       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
3395       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
3396       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
3397       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
3398       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
3399       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
3400       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
3401       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
3402       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
3403       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
3404       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
3405       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
3406       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
3407       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
3408       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
3409       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
3410       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
3411       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
3412       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
3413       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
3414       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
3415       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
3416       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
3417       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
3418       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
3419       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
3420       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
3421       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
3422       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
3423       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
3424       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
3425       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
3426       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
3427       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClass->Fill(28);
3428       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(29);
3429       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(30);
3430       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(31);
3431       if (!fInputHandler->IsEventSelected()) hTriggerClass->Fill(34);
3432    }
3433
3434    if(hTriggerClassSelected && isSelected){
3435       if (!fIsSDDFired) hTriggerClassSelected->Fill(33);
3436       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClassSelected->Fill(0);
3437       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClassSelected->Fill(1);
3438       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClassSelected->Fill(2);
3439       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClassSelected->Fill(3);
3440       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClassSelected->Fill(4);
3441       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClassSelected->Fill(5);
3442       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClassSelected->Fill(6);
3443       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClassSelected->Fill(6);
3444       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClassSelected->Fill(7);
3445       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClassSelected->Fill(7);
3446       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClassSelected->Fill(8);
3447       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClassSelected->Fill(8);
3448       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClassSelected->Fill(9);
3449       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClassSelected->Fill(9);
3450       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClassSelected->Fill(10);
3451       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClassSelected->Fill(10);
3452       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClassSelected->Fill(11);
3453       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClassSelected->Fill(12);
3454       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClassSelected->Fill(13);
3455       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClassSelected->Fill(13);
3456       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClassSelected->Fill(13);
3457       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClassSelected->Fill(14);
3458       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClassSelected->Fill(15);
3459       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClassSelected->Fill(16);
3460       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClassSelected->Fill(17);
3461       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClassSelected->Fill(18);
3462       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClassSelected->Fill(19);
3463       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClassSelected->Fill(20);
3464       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClassSelected->Fill(20);
3465       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClassSelected->Fill(21);
3466       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClassSelected->Fill(22);
3467       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClassSelected->Fill(23);
3468       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClassSelected->Fill(24);
3469       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClassSelected->Fill(25);
3470       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClassSelected->Fill(26);
3471       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClassSelected->Fill(27);
3472       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClassSelected->Fill(28);
3473       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClassSelected->Fill(29);
3474       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClassSelected->Fill(30);
3475       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClassSelected->Fill(31);
3476    }
3477
3478    if(!isSelected)return kFALSE;
3479
3480    return kTRUE;
3481
3482 }
3483
3484 ///________________________________________________________________________
3485 Int_t AliConversionCuts::GetFirstTPCRow(Double_t radius){
3486    // Get first TPC row
3487    Int_t firstTPCRow = 0;
3488    Double_t radiusI = 84.8;
3489    Double_t radiusO = 134.6;
3490    Double_t radiusOB = 198.;
3491    Double_t rSizeI = 0.75;
3492    Double_t rSizeO = 1.;
3493    Double_t rSizeOB = 1.5;
3494    Int_t nClsI = 63;
3495    Int_t nClsIO = 127;
3496
3497    if(radius <= radiusI){
3498       return firstTPCRow;
3499    }
3500    if(radius>radiusI && radius<=radiusO){
3501       firstTPCRow = (Int_t)((radius-radiusI)/rSizeI);
3502    }
3503    if(radius>radiusO && radius<=radiusOB){
3504       firstTPCRow = (Int_t)(nClsI+(radius-radiusO)/rSizeO);
3505    }
3506
3507    if(radius>radiusOB){
3508       firstTPCRow =(Int_t)(nClsIO+(radius-radiusOB)/rSizeOB);
3509    }
3510
3511    return firstTPCRow;
3512 }
3513
3514 Bool_t AliConversionCuts::CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const {
3515    ///Check if passes cosine of pointing angle cut
3516    if(GetCosineOfPointingAngle(photon, event) < fCosPAngleCut){
3517       return kFALSE;
3518    }
3519    return kTRUE;
3520 }
3521
3522 Double_t AliConversionCuts::GetCosineOfPointingAngle( const AliConversionPhotonBase * photon, AliVEvent * event) const{
3523    // calculates the pointing angle of the recalculated V0
3524
3525    Double_t momV0[3] = {0,0,0};
3526    if(event->IsA()==AliESDEvent::Class()){
3527       AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(event);
3528       if(!esdEvent) return -999;
3529       AliESDv0 *v0 = esdEvent->GetV0(photon->GetV0Index());
3530       if(!v0) return -999;
3531       v0->GetPxPyPz(momV0[0],momV0[1],momV0[2]);
3532    }
3533    if(event->IsA()==AliAODEvent::Class()){
3534       momV0[0] = photon->GetPx();
3535       momV0[1] = photon->GetPy();
3536       momV0[2] = photon->GetPz();
3537    }
3538
3539    //Double_t momV0[3] = { photon->GetPx(), photon->GetPy(), photon->GetPz() }; //momentum of the V0
3540    Double_t PosV0[3] = { photon->GetConversionX() - event->GetPrimaryVertex()->GetX(),
3541                          photon->GetConversionY() - event->GetPrimaryVertex()->GetY(),
3542                          photon->GetConversionZ() - event->GetPrimaryVertex()->GetZ() }; //Recalculated V0 Position vector
3543
3544    Double_t momV02 = momV0[0]*momV0[0] + momV0[1]*momV0[1] + momV0[2]*momV0[2];
3545    Double_t PosV02 = PosV0[0]*PosV0[0] + PosV0[1]*PosV0[1] + PosV0[2]*PosV0[2];
3546
3547
3548    Double_t cosinePointingAngle = -999;
3549    if(momV02*PosV02 > 0.0)
3550       cosinePointingAngle = (PosV0[0]*momV0[0] +  PosV0[1]*momV0[1] + PosV0[2]*momV0[2] ) / TMath::Sqrt(momV02 * PosV02);
3551
3552    return cosinePointingAngle;
3553 }
3554
3555 ///________________________________________________________________________
3556 Bool_t AliConversionCuts::PsiPairCut(const AliConversionPhotonBase * photon) const {
3557
3558    if (fDo2DPsiPairChi2){
3559       if (abs(photon->GetPsiPair()) < -fPsiPairCut/fChi2CutConversion*photon->GetChi2perNDF() + fPsiPairCut ){  
3560          return kTRUE;
3561       } else {
3562          return kFALSE;
3563       }    
3564    } else {
3565       if(abs(photon->GetPsiPair()) > fPsiPairCut){
3566          return kFALSE;}
3567       else{return kTRUE;}
3568    } 
3569 }
3570
3571 ///________________________________________________________________________
3572 TString AliConversionCuts::GetCutNumber(){
3573    // returns TString with current cut number
3574    TString a(kNCuts);
3575    for(Int_t ii=0;ii<kNCuts;ii++){
3576       a.Append(Form("%d",fCuts[ii]));
3577    }
3578    return a;
3579 }
3580
3581 ///________________________________________________________________________
3582 void AliConversionCuts::FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0){
3583
3584    Int_t posLabel = photon->GetTrackLabelPositive();
3585    Int_t negLabel = photon->GetTrackLabelNegative();
3586
3587    fElectronLabelArray[nV0*2] = posLabel;
3588    fElectronLabelArray[(nV0*2)+1] = negLabel;
3589 }
3590 ///________________________________________________________________________
3591 Bool_t AliConversionCuts::RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s){
3592
3593    Int_t posLabel = photon->GetTrackLabelPositive();
3594    Int_t negLabel = photon->GetTrackLabelNegative();
3595
3596    for(Int_t i = 0; i<nV0s*2;i++){
3597       if(i==nV0*2)     continue;
3598       if(i==(nV0*2)+1) continue;
3599       if(fElectronLabelArray[i] == posLabel){
3600          return kFALSE;}
3601       if(fElectronLabelArray[i] == negLabel){
3602          return kFALSE;}
3603    }
3604
3605    return kTRUE;
3606 }
3607 ///________________________________________________________________________
3608 Bool_t AliConversionCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0){
3609
3610
3611    Double_t posX = photon->GetConversionX();
3612    Double_t posY = photon->GetConversionY();
3613    Double_t posZ = photon->GetConversionZ();
3614
3615    for(Int_t i = 0;i<photons->GetEntries();i++){
3616       if(nV0 == i) continue;
3617       AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
3618       Double_t posCompX = photonComp->GetConversionX();
3619       Double_t posCompY = photonComp->GetConversionY();
3620       Double_t posCompZ = photonComp->GetConversionZ();
3621
3622       Double_t dist = pow((posX - posCompX),2)+pow((posY - posCompY),2)+pow((posZ - posCompZ),2);
3623
3624       if(dist < fminV0Dist*fminV0Dist){
3625          if(photon->GetChi2perNDF() < photonComp->GetChi2perNDF()) return kTRUE;
3626          else {
3627             return kFALSE;}
3628       }
3629
3630    }
3631    return kTRUE;
3632 }
3633 ///________________________________________________________________________
3634 void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent){
3635
3636
3637
3638    if(fNotRejectedStart){
3639       delete[] fNotRejectedStart;
3640       fNotRejectedStart = NULL;
3641    }
3642    if(fNotRejectedEnd){
3643       delete[] fNotRejectedEnd;
3644       fNotRejectedEnd = NULL;
3645    }
3646    if(fGeneratorNames){
3647       delete[] fGeneratorNames;
3648       fGeneratorNames = NULL;
3649    }
3650
3651    if(rejection == 0) return; // No Rejection
3652
3653    AliGenCocktailEventHeader *cHeader = 0x0;
3654    AliAODMCHeader *cHeaderAOD = 0x0;
3655    Bool_t headerFound = kFALSE;
3656    AliStack *fMCStack = 0x0;
3657    TClonesArray *fMCStackAOD = 0x0;
3658    if(MCEvent->IsA()==AliMCEvent::Class()){
3659       cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3660       if(cHeader) headerFound = kTRUE;
3661       fMCStack = dynamic_cast<AliStack*>(dynamic_cast<AliMCEvent*>(MCEvent)->Stack());
3662    }
3663    if(MCEvent->IsA()==AliAODEvent::Class()){ // MCEvent is a AODEvent in case of AOD
3664       cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
3665       fMCStackAOD = dynamic_cast<TClonesArray*>(MCEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3666       
3667       
3668       if(cHeaderAOD) headerFound = kTRUE;
3669    }
3670
3671    if(headerFound){
3672       TList *genHeaders = 0x0;
3673       if(cHeader) genHeaders = cHeader->GetHeaders();
3674       if(cHeaderAOD){
3675          genHeaders = cHeaderAOD->GetCocktailHeaders();
3676          if(genHeaders->GetEntries()==1){
3677             SetRejectExtraSignalsCut(0);
3678             return;
3679          }
3680       }
3681       AliGenEventHeader* gh = 0;
3682       fnHeaders = 0;
3683       Int_t firstindexA = 0;
3684       Int_t lastindexA =  -1;
3685       if(rejection == 1 || rejection == 3) fnHeaders = 1; // MinBiasHeader
3686       if(rejection == 2){ // TList of Headers Names
3687          for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3688             gh = (AliGenEventHeader*)genHeaders->At(i);
3689             TString GeneratorName = gh->GetName();
3690             lastindexA = lastindexA + gh->NProduced();
3691 //             cout << i << "\t" << GeneratorName.Data() << endl;
3692             for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3693                TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3694                if(GeneratorName.CompareTo(GeneratorInList) == 0){
3695                   if (GeneratorInList.CompareTo("PARAM") == 0){
3696                      if(fMCStack){
3697                         if (fMCStack->Particle(firstindexA)->GetPdgCode() == 111 || fMCStack->Particle(firstindexA)->GetPdgCode() == 221 ) {
3698                            fnHeaders++;
3699                            continue;
3700                         }
3701                      }   
3702                      if ( fMCStackAOD){
3703                         AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA));
3704                         if (  aodMCParticle->GetPdgCode() == 111 || aodMCParticle->GetPdgCode() == 221 ){
3705                            fnHeaders++;
3706                            continue;
3707                        }   
3708                      }
3709                   }
3710                   fnHeaders++;
3711                   continue;
3712                }
3713             }
3714             firstindexA = firstindexA + gh->NProduced();
3715          }
3716       }
3717
3718       fNotRejectedStart = new Int_t[fnHeaders];
3719       fNotRejectedEnd = new Int_t[fnHeaders];
3720       fGeneratorNames = new TString[fnHeaders];
3721
3722       if(rejection == 1 || rejection == 3){
3723          fNotRejectedStart[0] = 0;
3724          fNotRejectedEnd[0] = ((AliGenEventHeader*)genHeaders->At(0))->NProduced()-1;
3725          fGeneratorNames[0] = ((AliGenEventHeader*)genHeaders->At(0))->GetName();
3726          return;
3727       }
3728
3729       Int_t firstindex = 0;
3730       Int_t lastindex =  -1;
3731       Int_t number = 0;
3732       for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3733          gh = (AliGenEventHeader*)genHeaders->At(i);
3734          TString GeneratorName = gh->GetName();
3735          lastindex = lastindex + gh->NProduced();
3736          for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3737             TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3738             if(GeneratorName.CompareTo(GeneratorInList) == 0){
3739                if (GeneratorInList.CompareTo("PARAM") == 0){
3740                   if(fMCStack){
3741                      if (fMCStack->Particle(firstindex)->GetPdgCode() == 111 || fMCStack->Particle(firstindex)->GetPdgCode() == 221 ) {
3742                         fNotRejectedStart[number] = firstindex;
3743                         fNotRejectedEnd[number] = lastindex;
3744                         fGeneratorNames[number] = GeneratorName;
3745                         number++;
3746                         continue;
3747                      }
3748                   }   
3749                   if ( fMCStackAOD){
3750                      AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindex));
3751                      if (  aodMCParticle->GetPdgCode() == 111 || aodMCParticle->GetPdgCode() == 221 ){
3752                         fNotRejectedStart[number] = firstindex;
3753                         fNotRejectedEnd[number] = lastindex;
3754                         fGeneratorNames[number] = GeneratorName;
3755                         number++;
3756                         continue;
3757                      }   
3758                   }
3759                      
3760                } else {
3761                   fNotRejectedStart[number] = firstindex;
3762                   fNotRejectedEnd[number] = lastindex;
3763                   fGeneratorNames[number] = GeneratorName;
3764    //                cout << "Number of particles produced for: " << i << "\t" << GeneratorName.Data() << "\t" << lastindex-firstindex+1 << endl;
3765                    number++;
3766                   continue;
3767                }
3768             }
3769          }
3770          firstindex = firstindex + gh->NProduced();
3771       }
3772    } else { // No Cocktail Header Found
3773       fNotRejectedStart = new Int_t[1];
3774       fNotRejectedEnd = new Int_t[1];
3775
3776       fnHeaders = 1;
3777       fNotRejectedStart[0] = 0;
3778       fNotRejectedEnd[0] = static_cast<AliMCEvent*>(MCEvent)->Stack()->GetNprimary()-1;
3779       fGeneratorNames = new TString[1];
3780       fGeneratorNames[0] = "NoCocktailGeneratorFound";
3781
3782       AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3783       if (mcHeaderPythia) fGeneratorNames[0] = "NoCocktailGeneratorFound_Pythia";
3784       AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3785       if (mcHeaderPhojet) fGeneratorNames[0] = "NoCocktailGeneratorFound_Phojet";
3786       AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3787       if (mcHeaderHijing) fGeneratorNames[0] = "NoCocktailGeneratorFound_Hijing";
3788
3789       SetRejectExtraSignalsCut(0);
3790    }
3791
3792 }
3793 //_________________________________________________________________________
3794 Int_t AliConversionCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
3795
3796    // Not Accepted == kFALSE == 0
3797    //     Accepted ==  kTRUE == 1
3798    //  FirstHeader ==  kTRUE == 3
3799    if(index < 0) return 0; // No Particle
3800
3801    Int_t accepted = 0;
3802    if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
3803       if( index >= MCStack->GetNprimary()){ // Secondary Particle
3804          if( ((TParticle*)MCStack->Particle(index))->GetMother(0) < 0) return 1; // Secondary Particle without Mother??
3805          return IsParticleFromBGEvent(((TParticle*)MCStack->Particle(index))->GetMother(0),MCStack,InputEvent);
3806       }
3807       for(Int_t i = 0;i<fnHeaders;i++){
3808          if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
3809             accepted = 1;
3810             if(i == 0) accepted = 2; // MB Header
3811          }
3812       }
3813    }
3814    else if(InputEvent->IsA()==AliAODEvent::Class()){
3815       TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3816       AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
3817       if(!aodMCParticle) return 1; // Photon Without a Mother ? --> Accepted
3818       if(!aodMCParticle->IsPrimary()){
3819          if( aodMCParticle->GetMother() < 0) return 1;// Secondary Particle without Mother??
3820          return IsParticleFromBGEvent(aodMCParticle->GetMother(),MCStack,InputEvent);
3821       }
3822       index = abs(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index))->GetLabel());
3823       for(Int_t i = 0;i<fnHeaders;i++){
3824          if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
3825             accepted = 1;
3826             if(i == 0) accepted = 2; // MB Header
3827          }
3828       }
3829    }
3830
3831    return accepted;
3832 }
3833 //_________________________________________________________________________
3834 Int_t AliConversionCuts::IsEventAcceptedByConversionCut(AliConversionCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Bool_t isHeavyIon){
3835
3836    if ( !IsTriggerSelected(InputEvent) )
3837       return 3;
3838
3839    if(isHeavyIon && !(IsCentralitySelected(InputEvent,MCEvent)))
3840       return 1; // Check Centrality --> Not Accepted => eventQuality = 1
3841       
3842       
3843    if(!isHeavyIon && GetIsFromPileup()){
3844       if(InputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
3845
3846          return 6; // Check Pileup --> Not Accepted => eventQuality = 6
3847       }
3848    }
3849
3850    Bool_t hasV0And = ReaderCuts->HasV0AND();
3851    Bool_t isSDDFired = ReaderCuts->IsSDDFired();
3852    if( (IsSpecialTrigger() == 2 || IsSpecialTrigger() == 3) && !isSDDFired && !MCEvent)
3853       return 7; // With SDD requested but no fired
3854
3855    if( (IsSpecialTrigger() == 1 || IsSpecialTrigger() == 3) && !hasV0And)
3856       return 8; // V0AND requested but no fired
3857
3858    if(hCentrality)hCentrality->Fill(GetCentrality(InputEvent));
3859    if(hCentralityVsNumberOfPrimaryTracks)
3860       hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(InputEvent),
3861                                              ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
3862                                                 ->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks());     
3863
3864    return 0;
3865 }
3866 //_________________________________________________________________________
3867 Float_t AliConversionCuts::GetWeightForMeson(TString period, Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
3868    if (!(period.CompareTo("LHC12f1a") == 0 || period.CompareTo("LHC12f1b") == 0  || period.CompareTo("LHC12i3") == 0 || period.CompareTo("LHC11a10a") == 0 || period.CompareTo("LHC11a10b") == 0 || period.CompareTo("LHC11a10b_bis") == 0 || period.CompareTo("LHC11a10a_bis") == 0 || period.CompareTo("LHC11a10b_plus") == 0 || period.Contains("LHC13d2") || 
3869    period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix"))) return 1.;
3870
3871    Int_t kCaseGen = 0;
3872    for (Int_t i = 0; i < fnHeaders; i++){
3873       if (index >= fNotRejectedStart[i] && index < fNotRejectedEnd[i]+1){
3874          if (fGeneratorNames[i].CompareTo("Pythia") == 0){
3875             kCaseGen = 1;
3876          } else if (fGeneratorNames[i].CompareTo("DPMJET") == 0){
3877             kCaseGen = 2;
3878          } else if (fGeneratorNames[i].CompareTo("HIJING") == 0 ||
3879                     fGeneratorNames[i].CompareTo("Hijing") == 0 ||
3880                     fGeneratorNames[i].Contains("hijing")){
3881             kCaseGen = 3;
3882          } else if (fGeneratorNames[i].CompareTo("BOX") == 0){
3883              kCaseGen = 4;
3884          } else if (fGeneratorNames[i].CompareTo("PARAM") == 0){
3885             kCaseGen = 5;
3886          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound") == 0){
3887             kCaseGen = 6;
3888          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Pythia") == 0){
3889             kCaseGen = 1;
3890          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Phojet") == 0){
3891             kCaseGen = 2;
3892          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Hijing") == 0){
3893             kCaseGen = 3;
3894          }
3895          if (period.Contains("LHC13d2") || period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix") ){
3896             kCaseGen = 3;
3897          }
3898       }
3899    }
3900    if (kCaseGen == 0) return 1;
3901
3902
3903    Double_t mesonPt = 0;
3904    Double_t mesonMass = 0;
3905    Int_t PDGCode = 0;
3906    if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
3907       mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
3908       mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
3909       PDGCode = ((TParticle*)MCStack->Particle(index))->GetPdgCode();
3910    }
3911    else if(InputEvent->IsA()==AliAODEvent::Class()){
3912       TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3913       AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
3914       mesonPt = aodMCParticle->Pt();
3915       mesonMass = aodMCParticle->GetCalcMass();
3916       PDGCode = aodMCParticle->GetPdgCode();
3917    }
3918
3919    Float_t functionResultMC = 1.;
3920    if (kCaseGen == 1){ // Pythia 6
3921       Float_t dNdyMC = 2.1462;
3922       Float_t nMC = 7.06055;
3923       Float_t tMC = 0.12533;
3924       if ( PDGCode ==  111){
3925          dNdyMC = 2.1462;
3926          nMC = 7.06055;
3927          tMC = 0.12533;
3928       } else if ( PDGCode ==  221){
3929          dNdyMC = 0.2357;
3930          nMC = 5.9105;
3931          tMC = 0.1525;
3932       }
3933       functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
3934    } else if (kCaseGen == 2){ // Phojet
3935       Float_t dNdyMC = 2.35978;
3936       Float_t nMC = 6.81795;
3937       Float_t tMC = 0.11492;
3938       if ( PDGCode ==  111){
3939          dNdyMC = 2.35978;
3940          nMC = 6.81795;
3941          tMC = 0.11492;
3942       } else if ( PDGCode ==  221){
3943          dNdyMC = 0.3690;
3944          nMC = 5.55809;
3945          tMC = 0.13387;
3946       }
3947       functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
3948    } else if (kCaseGen == 4){ // BOX generators pp
3949 //       functionResultMC = 1./sqrt(1.-mesonMass*mesonMass/((mesonMass*mesonMass+mesonPt*mesonPt)*cosh(mesonY)*cosh(mesonY)));
3950       Float_t a = 0.23437;
3951       Float_t b = 5.6661;
3952       Float_t c = -1430.5863;
3953       Float_t d = -0.6966624;
3954       Float_t e = 252.3742;
3955       if ( PDGCode ==  111){
3956          a = 0.23437;
3957          b = 5.6661;
3958          c = -1430.5863;
3959          d = -0.6966624;
3960          e = 252.3742;
3961       } else if ( PDGCode ==  221){
3962          a = 0.10399;
3963          b = 4.35311;
3964          c = -12.17723;
3965          d = -0.01172;
3966          e =1.85140;
3967       }
3968       functionResultMC = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
3969 //       cout <<