changed addtask for PbPb
[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 };
90
91
92 //________________________________________________________________________
93 AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
94    AliAnalysisCuts(name,title),
95    fHistograms(NULL),
96    fHeaderList(NULL),
97    fPIDResponse(NULL),
98    fEventQuality(-1),
99    fMaxR(200),
100    fMinR(0),
101    fEtaCut(0.9),
102    fEtaCutMin(-0.1),
103    fPtCut(0.02),
104    fSinglePtCut(0),
105    fMaxZ(1000),
106    fMinClsTPC(0.),
107    fMinClsTPCToF(0.),
108    fLineCutZRSlope(0.),
109    fLineCutZValue(0),
110    fLineCutZRSlopeMin(0.),
111    fLineCutZValueMin(0),
112    fChi2CutConversion(1000),
113    fPIDProbabilityCutNegativeParticle(0),
114    fPIDProbabilityCutPositiveParticle(0),
115    fDodEdxSigmaCut(kTRUE),
116    fDoTOFsigmaCut(kFALSE),
117    fPIDTRDEfficiency(1),
118    fDoTRDPID(kFALSE),
119    fPIDnSigmaAboveElectronLine(100),
120    fPIDnSigmaBelowElectronLine(-100),
121    fTofPIDnSigmaAboveElectronLine(100),
122    fTofPIDnSigmaBelowElectronLine(-100),
123    fPIDnSigmaAbovePionLine(0),
124    fPIDnSigmaAbovePionLineHighPt(-100),
125    fPIDMinPnSigmaAbovePionLine(0),
126    fPIDMaxPnSigmaAbovePionLine(0),
127    fDoKaonRejectionLowP(kFALSE),
128    fDoProtonRejectionLowP(kFALSE),
129    fDoPionRejectionLowP(kFALSE),
130    fPIDnSigmaAtLowPAroundKaonLine(0),
131    fPIDnSigmaAtLowPAroundProtonLine(0),
132    fPIDnSigmaAtLowPAroundPionLine(0),
133    fPIDMinPKaonRejectionLowP(1.5),
134    fPIDMinPProtonRejectionLowP(2),
135    fPIDMinPPionRejectionLowP(0),
136    fDoQtGammaSelection(kTRUE),
137    fDoHighPtQtGammaSelection(kFALSE),
138    fQtMax(100),
139    fHighPtQtMax(0.),
140    fPtBorderForQt(0),
141    fXVertexCut(0.),
142    fYVertexCut(0.),
143    fZVertexCut(0.),
144    fNSigmaMass(0.),
145    fUseEtaMinCut(kFALSE),
146    fUseOnFlyV0Finder(kTRUE),
147    fDoPhotonAsymmetryCut(kTRUE),
148    fMinPPhotonAsymmetryCut(100.),
149    fMinPhotonAsymmetry(0.),
150    fIsHeavyIon(0),
151    fDetectorCentrality(0),
152    fModCentralityClass(0),
153    fMaxVertexZ(10),
154    fCentralityMin(0),
155    fCentralityMax(0),
156    fUseCorrectedTPCClsInfo(kFALSE),
157    fUseTOFpid(kFALSE),
158    fMultiplicityMethod(0),
159    fSpecialTrigger(0),
160    fRemovePileUp(kFALSE),
161    fOpeningAngle(0.005),
162    fPsiPairCut(10000),
163    fPsiPairDeltaPhiCut(10000),
164    fDo2DPsiPair(kFALSE),
165    fCosPAngleCut(10000),
166    fDoToCloseV0sCut(kFALSE),
167    fRejectExtraSignals(0),
168    fminV0Dist(200.),
169    fDoSharedElecCut(kFALSE),
170    fOfflineTriggerMask(0),
171    fHasV0AND(kTRUE),
172    fIsSDDFired(kTRUE),
173    fRandom(0),
174    fElectronArraySize(500),
175    fElectronLabelArray(NULL),
176    fDCAZPrimVtxCut(1000),
177    fDCARPrimVtxCut(1000),
178    fConversionPointXArray(0.0),
179    fConversionPointYArray(0.0),
180    fConversionPointZArray(0.0),
181    fnHeaders(0),
182    fNotRejectedStart(NULL),
183    fNotRejectedEnd(NULL),
184    fGeneratorNames(NULL),
185    fCutString(NULL),
186    fUtils(NULL),
187    fEtaShift(0.0),
188    fDoEtaShift(kFALSE),
189    fDoReweightHistoMCPi0(kFALSE),
190    fDoReweightHistoMCEta(kFALSE),
191    fDoReweightHistoMCK0s(kFALSE),
192    fPathTrFReweighting(""),
193    fNameHistoReweightingPi0(""),
194    fNameHistoReweightingEta(""),
195    fNameHistoReweightingK0s(""),
196    fNameFitDataPi0(""),
197    fNameFitDataEta(""),
198    fNameFitDataK0s(""),
199    hdEdxCuts(NULL),
200    hTPCdEdxbefore(NULL),
201    hTPCdEdxafter(NULL),
202    hTPCdEdxSigbefore(NULL),
203    hTPCdEdxSigafter(NULL),
204    hTOFbefore(NULL),
205    hTOFSigbefore(NULL),
206    hTOFSigafter(NULL),
207    hPsiPairDeltaPhiafter(NULL),
208    hTrackCuts(NULL),
209    hPhotonCuts(NULL),
210    hInvMassbefore(NULL),
211    hArmenterosbefore(NULL),
212    hInvMassafter(NULL),
213    hArmenterosafter(NULL),
214    hAcceptanceCuts(NULL),
215    hCutIndex(NULL),
216    hV0EventCuts(NULL),
217    hCentrality(NULL),
218    hCentralityVsNumberOfPrimaryTracks(NULL),
219    hVertexZ(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    fDoHighPtQtGammaSelection(ref.fDoHighPtQtGammaSelection),
291    fQtMax(ref.fQtMax),
292    fHighPtQtMax(ref.fHighPtQtMax),
293    fPtBorderForQt(ref.fPtBorderForQt),
294    fXVertexCut(ref.fXVertexCut),
295    fYVertexCut(ref.fYVertexCut),
296    fZVertexCut(ref.fZVertexCut),
297    fNSigmaMass(ref.fNSigmaMass),
298    fUseEtaMinCut(ref.fUseEtaMinCut),
299    fUseOnFlyV0Finder(ref.fUseOnFlyV0Finder),
300    fDoPhotonAsymmetryCut(ref.fDoPhotonAsymmetryCut),
301    fMinPPhotonAsymmetryCut(ref.fMinPPhotonAsymmetryCut),
302    fMinPhotonAsymmetry(ref.fMinPhotonAsymmetry),
303    fIsHeavyIon(ref.fIsHeavyIon),
304    fDetectorCentrality(ref.fDetectorCentrality),
305    fModCentralityClass(ref.fModCentralityClass),
306    fMaxVertexZ(ref.fMaxVertexZ),
307    fCentralityMin(ref.fCentralityMin),
308    fCentralityMax(ref.fCentralityMax),
309    fUseCorrectedTPCClsInfo(ref.fUseCorrectedTPCClsInfo),
310    fUseTOFpid(ref.fUseTOFpid),
311    fMultiplicityMethod(ref.fMultiplicityMethod),
312    fSpecialTrigger(ref.fSpecialTrigger),
313    fRemovePileUp(ref.fRemovePileUp),
314    fOpeningAngle(ref.fOpeningAngle),
315    fPsiPairCut(ref.fPsiPairCut),
316    fPsiPairDeltaPhiCut(ref.fPsiPairDeltaPhiCut),
317    fDo2DPsiPair(ref.fDo2DPsiPair),
318    fCosPAngleCut(ref.fCosPAngleCut),
319    fDoToCloseV0sCut(ref.fDoToCloseV0sCut),
320    fRejectExtraSignals(ref.fRejectExtraSignals),
321    fminV0Dist(ref.fminV0Dist),
322    fDoSharedElecCut(ref.fDoSharedElecCut),
323    fOfflineTriggerMask(ref.fOfflineTriggerMask),
324    fHasV0AND(ref.fHasV0AND),
325    fIsSDDFired(ref.fIsSDDFired),
326    fRandom(ref.fRandom),
327    fElectronArraySize(ref.fElectronArraySize),
328    fElectronLabelArray(NULL),
329    fDCAZPrimVtxCut(ref.fDCAZPrimVtxCut),
330    fDCARPrimVtxCut(ref.fDCAZPrimVtxCut),
331    fConversionPointXArray(ref.fConversionPointXArray),
332    fConversionPointYArray(ref.fConversionPointYArray),
333    fConversionPointZArray(ref.fConversionPointZArray),
334    fnHeaders(ref.fnHeaders),
335    fNotRejectedStart(NULL),
336    fNotRejectedEnd(NULL),
337    fGeneratorNames(ref.fGeneratorNames),
338    fCutString(NULL),
339    fUtils(NULL),
340    fEtaShift(ref.fEtaShift),
341    fDoEtaShift(ref.fDoEtaShift),
342    fDoReweightHistoMCPi0(ref.fDoReweightHistoMCPi0),
343    fDoReweightHistoMCEta(ref.fDoReweightHistoMCEta),
344    fDoReweightHistoMCK0s(ref.fDoReweightHistoMCK0s),
345    fPathTrFReweighting(ref.fPathTrFReweighting),
346    fNameHistoReweightingPi0(ref.fNameHistoReweightingPi0),
347    fNameHistoReweightingEta(ref.fNameHistoReweightingEta),
348    fNameHistoReweightingK0s(ref.fNameHistoReweightingK0s),
349    fNameFitDataPi0(ref.fNameFitDataPi0),
350    fNameFitDataEta(ref.fNameFitDataEta),
351    fNameFitDataK0s(ref.fNameFitDataK0s),
352    hdEdxCuts(NULL),
353    hTPCdEdxbefore(NULL),
354    hTPCdEdxafter(NULL),
355    hTPCdEdxSigbefore(NULL),
356    hTPCdEdxSigafter(NULL),
357    hTOFbefore(NULL),
358    hTOFSigbefore(NULL),
359    hTOFSigafter(NULL),
360    hPsiPairDeltaPhiafter(NULL),
361    hTrackCuts(NULL),
362    hPhotonCuts(NULL),
363    hInvMassbefore(NULL),
364    hArmenterosbefore(NULL),
365    hInvMassafter(NULL),
366    hArmenterosafter(NULL),
367    hAcceptanceCuts(NULL),
368    hCutIndex(NULL),
369    hV0EventCuts(NULL),
370    hCentrality(NULL),
371    hCentralityVsNumberOfPrimaryTracks(NULL),
372    hVertexZ(NULL),
373    hTriggerClass(NULL),
374    hTriggerClassSelected(NULL),
375    hReweightMCHistPi0(ref.hReweightMCHistPi0),
376    hReweightMCHistEta(ref.hReweightMCHistEta),
377    hReweightMCHistK0s(ref.hReweightMCHistK0s),
378    fFitDataPi0(ref.fFitDataPi0),
379    fFitDataEta(ref.fFitDataEta),
380    fFitDataK0s(ref.fFitDataK0s),
381    fPreSelCut(ref.fPreSelCut),
382    fTriggerSelectedManually(ref.fTriggerSelectedManually),
383    fSpecialTriggerName(ref.fSpecialTriggerName)
384 {
385    // Copy Constructor
386    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
387    fCutString=new TObjString((GetCutNumber()).Data());
388    fElectronLabelArray = new Int_t[fElectronArraySize];
389    fUtils = new AliAnalysisUtils();
390    // dont copy histograms (if you like histograms, call InitCutHistograms())
391
392 }
393
394
395 //________________________________________________________________________
396 AliConversionCuts::~AliConversionCuts() {
397    // Destructor
398    //Deleting fHistograms leads to seg fault it it's added to output collection of a task
399    // if(fHistograms)
400    //    delete fHistograms;
401    // fHistograms = NULL;
402    if(fCutString != NULL){
403       delete fCutString;
404       fCutString = NULL;
405    }
406    if(fElectronLabelArray){
407       delete fElectronLabelArray;
408       fElectronLabelArray = NULL;
409    }
410    if(fNotRejectedStart){
411       delete[] fNotRejectedStart;
412       fNotRejectedStart = NULL;
413    }
414    if(fNotRejectedEnd){
415       delete[] fNotRejectedEnd;
416       fNotRejectedEnd = NULL;
417    }
418    if(fGeneratorNames){
419       delete[] fGeneratorNames;
420       fGeneratorNames = NULL;
421    }
422    if(fUtils){
423      delete fUtils;
424      fUtils = NULL;
425    }
426
427 }
428
429 //________________________________________________________________________
430 void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
431
432    // Initialize Cut Histograms for QA (only initialized and filled if function is called)
433    TH1::AddDirectory(kFALSE);
434
435    if(fHistograms != NULL){
436       delete fHistograms;
437       fHistograms=NULL;
438    }
439    if(fHistograms==NULL){
440       fHistograms=new TList();
441       fHistograms->SetOwner(kTRUE);
442       if(name=="")fHistograms->SetName(Form("ConvCuts_%s",GetCutNumber().Data()));
443       else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
444    }
445
446    if (hReweightMCHistPi0){
447       hReweightMCHistPi0->SetName("MCInputForWeightingPi0");
448       fHistograms->Add(hReweightMCHistPi0);
449    }
450    if (hReweightMCHistEta){
451       hReweightMCHistEta->SetName("MCInputForWeightingEta");
452       fHistograms->Add(hReweightMCHistEta);
453    }
454    if (hReweightMCHistK0s){
455       hReweightMCHistK0s->SetName("MCInputForWeightingK0s");
456       fHistograms->Add(hReweightMCHistK0s);
457    }
458 //    if (fFitDataPi0){
459 //       fFitDataPi0->SetName("DataFitForWeightingPi0");
460 //       fHistograms->Add(fFitDataPi0);
461 //    }
462 //    if (fFitDataEta){
463 //       fFitDataEta->SetName("DataFitForWeightingEta");
464 //       fHistograms->Add(fFitDataEta);
465 //    }
466 //    if (fFitDataK0s){
467 //       fFitDataK0s->SetName("DataFitForWeightingK0s");
468 //       fHistograms->Add(fFitDataK0s);
469 //    }
470    // IsPhotonSelected
471    hCutIndex=new TH1F(Form("IsPhotonSelected %s",GetCutNumber().Data()),"IsPhotonSelected",10,-0.5,9.5);
472    hCutIndex->GetXaxis()->SetBinLabel(kPhotonIn+1,"in");
473    hCutIndex->GetXaxis()->SetBinLabel(kOnFly+1,"onfly");
474    hCutIndex->GetXaxis()->SetBinLabel(kNoTracks+1,"no tracks");
475    hCutIndex->GetXaxis()->SetBinLabel(kdEdxCuts+1,"dEdx");
476    hCutIndex->GetXaxis()->SetBinLabel(kTrackCuts+1,"Track cuts");
477    hCutIndex->GetXaxis()->SetBinLabel(kConvPointFail+1,"ConvPoint fail");
478    hCutIndex->GetXaxis()->SetBinLabel(kPhotonCuts+1,"PhotonCuts");
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    // Event Cuts and Info
600    if(preCut){
601       hV0EventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",7,-0.5,6.5);
602       hV0EventCuts->GetXaxis()->SetBinLabel(1,"in");
603       hV0EventCuts->GetXaxis()->SetBinLabel(2,"OfflineTrigger");
604       hV0EventCuts->GetXaxis()->SetBinLabel(3,"nvtxcontr");
605       hV0EventCuts->GetXaxis()->SetBinLabel(4,"VertexZ");
606       hV0EventCuts->GetXaxis()->SetBinLabel(5,"pileup");
607       hV0EventCuts->GetXaxis()->SetBinLabel(6,"centrsel");
608       hV0EventCuts->GetXaxis()->SetBinLabel(7,"out");
609       fHistograms->Add(hV0EventCuts);
610
611       hCentrality=new TH1F(Form("Centrality %s",GetCutNumber().Data()),"Centrality",1000,0,100);
612       fHistograms->Add(hCentrality);
613       hCentralityVsNumberOfPrimaryTracks=new TH2F(Form("Centrality vs Primary Tracks %s",GetCutNumber().Data()),"Centrality vs Primary Tracks ",100,0,100,4000,0,4000);
614       fHistograms->Add(hCentralityVsNumberOfPrimaryTracks);
615       hVertexZ=new TH1F(Form("VertexZ %s",GetCutNumber().Data()),"VertexZ",1000,-50,50);
616       fHistograms->Add(hVertexZ);
617
618       hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",35,-0.5,34.5);
619       hTriggerClass->GetXaxis()->SetBinLabel( 1,"kMB");
620       hTriggerClass->GetXaxis()->SetBinLabel( 2,"kINT7");
621       hTriggerClass->GetXaxis()->SetBinLabel( 3,"kMUON");
622       hTriggerClass->GetXaxis()->SetBinLabel( 4,"kHighMult");
623       hTriggerClass->GetXaxis()->SetBinLabel( 5,"kKEMC1");
624       hTriggerClass->GetXaxis()->SetBinLabel( 6,"kCINT5");
625       hTriggerClass->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
626       hTriggerClass->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
627       hTriggerClass->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
628       hTriggerClass->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
629       hTriggerClass->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
630       hTriggerClass->GetXaxis()->SetBinLabel(12,"kMUS7");
631       hTriggerClass->GetXaxis()->SetBinLabel(13,"kPHI1");
632       hTriggerClass->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
633       hTriggerClass->GetXaxis()->SetBinLabel(15,"kEMCEJE");
634       hTriggerClass->GetXaxis()->SetBinLabel(16,"kEMCEGA");
635       hTriggerClass->GetXaxis()->SetBinLabel(17,"kCentral");
636       hTriggerClass->GetXaxis()->SetBinLabel(18,"kSemiCentral");
637       hTriggerClass->GetXaxis()->SetBinLabel(19,"kDG5");
638       hTriggerClass->GetXaxis()->SetBinLabel(20,"kZED");
639       hTriggerClass->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
640       hTriggerClass->GetXaxis()->SetBinLabel(22,"kINT8");
641       hTriggerClass->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
642       hTriggerClass->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
643       hTriggerClass->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
644       hTriggerClass->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
645       hTriggerClass->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
646       hTriggerClass->GetXaxis()->SetBinLabel(28,"kUserDefined");
647       hTriggerClass->GetXaxis()->SetBinLabel(29,"kTRD");
648       hTriggerClass->GetXaxis()->SetBinLabel(30,"kFastOnly");
649       hTriggerClass->GetXaxis()->SetBinLabel(31,"kAnyINT");
650       hTriggerClass->GetXaxis()->SetBinLabel(32,"kAny");
651       hTriggerClass->GetXaxis()->SetBinLabel(33,"V0AND");
652       hTriggerClass->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
653       hTriggerClass->GetXaxis()->SetBinLabel(35,"failed Physics Selection");
654       fHistograms->Add(hTriggerClass);
655    }
656    if(!preCut){
657       hTriggerClassSelected= new TH1F(Form("OfflineTriggerSelected %s",GetCutNumber().Data()),"OfflineTriggerSelected",34,-0.5,33.5);
658       hTriggerClassSelected->GetXaxis()->SetBinLabel( 1,"kMB");
659       hTriggerClassSelected->GetXaxis()->SetBinLabel( 2,"kINT7");
660       hTriggerClassSelected->GetXaxis()->SetBinLabel( 3,"kMUON");
661       hTriggerClassSelected->GetXaxis()->SetBinLabel( 4,"kHighMult");
662       hTriggerClassSelected->GetXaxis()->SetBinLabel( 5,"kKEMC1");
663       hTriggerClassSelected->GetXaxis()->SetBinLabel( 6,"kCINT5");
664       hTriggerClassSelected->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
665       hTriggerClassSelected->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
666       hTriggerClassSelected->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
667       hTriggerClassSelected->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
668       hTriggerClassSelected->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
669       hTriggerClassSelected->GetXaxis()->SetBinLabel(12,"kMUS7");
670       hTriggerClassSelected->GetXaxis()->SetBinLabel(13,"kPHI1");
671       hTriggerClassSelected->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
672       hTriggerClassSelected->GetXaxis()->SetBinLabel(15,"kEMCEJE");
673       hTriggerClassSelected->GetXaxis()->SetBinLabel(16,"kEMCEGA");
674       hTriggerClassSelected->GetXaxis()->SetBinLabel(17,"kCentral");
675       hTriggerClassSelected->GetXaxis()->SetBinLabel(18,"kSemiCentral");
676       hTriggerClassSelected->GetXaxis()->SetBinLabel(19,"kDG5");
677       hTriggerClassSelected->GetXaxis()->SetBinLabel(20,"kZED");
678       hTriggerClassSelected->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
679       hTriggerClassSelected->GetXaxis()->SetBinLabel(22,"kINT8");
680       hTriggerClassSelected->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
681       hTriggerClassSelected->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
682       hTriggerClassSelected->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
683       hTriggerClassSelected->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
684       hTriggerClassSelected->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
685       hTriggerClassSelected->GetXaxis()->SetBinLabel(28,"kUserDefined");
686       hTriggerClassSelected->GetXaxis()->SetBinLabel(29,"kTRD");
687       hTriggerClassSelected->GetXaxis()->SetBinLabel(30,"kFastOnly");
688       hTriggerClassSelected->GetXaxis()->SetBinLabel(31,"kAnyINT");
689       hTriggerClassSelected->GetXaxis()->SetBinLabel(32,"kAny");
690       hTriggerClassSelected->GetXaxis()->SetBinLabel(33,"V0AND");
691       hTriggerClassSelected->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
692       fHistograms->Add(hTriggerClassSelected);
693    }
694    TH1::AddDirectory(kTRUE);
695 }
696
697 //________________________________________________________________________
698 Bool_t AliConversionCuts::InitPIDResponse(){
699    // Set Pointer to AliPIDResponse
700
701    AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
702    if(man) {
703       AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
704       fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
705       if(fPIDResponse)return kTRUE;
706
707    }
708
709
710    return kFALSE;
711 }
712 ///________________________________________________________________________
713 Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent){
714    // Process Event Selection
715
716    Int_t cutindex=0;
717    if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
718    cutindex++;
719
720    // Check for MC event
721    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
722       // Check if MC event is correctly loaded
723       AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
724       if (!mcHandler){
725          fEventQuality = 2;
726          return kFALSE;
727       }
728       if (!mcHandler->InitOk() ){
729          fEventQuality = 2;
730          return kFALSE;
731       }
732       if (!mcHandler->TreeK() ){
733          fEventQuality = 2;
734          return kFALSE;
735       }
736       if (!mcHandler->TreeTR() ) {
737          fEventQuality = 2;
738          return kFALSE;
739       }
740    }
741
742    // Event Trigger
743 //    cout << "before event trigger" << endl;
744    if(!IsTriggerSelected(fInputEvent)){
745       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
746       fEventQuality = 3;
747       return kFALSE;
748    }
749    cutindex++;
750
751    if(fInputEvent->IsA()==AliESDEvent::Class()){
752       AliTriggerAnalysis fTriggerAnalysis;// = new AliTriggerAnalysis;
753       fHasV0AND = fTriggerAnalysis.IsOfflineTriggerFired((AliESDEvent*)fInputEvent, AliTriggerAnalysis::kV0AND);
754       if(fHasV0AND&&hTriggerClass)hTriggerClass->Fill(32);
755    }
756 //   cout << "event number " << ((AliESDEvent*)fInputEvent)->GetEventNumberInFile() << " entered"<< endl;
757
758
759    // Number of Contributors Cut
760    if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
761       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
762       fEventQuality = 5;
763       return kFALSE;
764    }
765    cutindex++;
766
767    // Z Vertex Position Cut
768    if(!VertexZCut(fInputEvent)){
769       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
770       fEventQuality = 4;
771       return kFALSE;
772    }
773    cutindex++;
774
775    // Pile Up Rejection
776
777    if(fRemovePileUp){
778       if(fInputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
779          if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
780          fEventQuality = 6;
781          return kFALSE;
782       }
783    }
784    cutindex++;
785
786    // Centrality Selection
787    if(!IsCentralitySelected(fInputEvent,fMCEvent)){
788       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
789       fEventQuality = 1;
790       return kFALSE;
791    }
792    cutindex++;
793
794    // Fill Event Histograms
795    if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
796    if(hVertexZ)hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
797    if(hCentrality)hCentrality->Fill(GetCentrality(fInputEvent));
798    if(hCentralityVsNumberOfPrimaryTracks)
799       hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(fInputEvent),
800                                                ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
801                                                 ->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks());
802    fEventQuality = 0;
803    return kTRUE;
804 }
805
806 ///________________________________________________________________________
807 Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCStack,Bool_t checkForConvertedGamma){
808    // MonteCarlo Photon Selection
809
810    if(!fMCStack)return kFALSE;
811
812    if (particle->GetPdgCode() == 22){
813
814
815       if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )
816          return kFALSE;
817       if(fEtaCutMin>-0.1){
818          if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) )
819             return kFALSE;
820       }
821
822       if(particle->GetMother(0) >-1 && fMCStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
823          return kFALSE; // no photon as mothers!
824       }
825
826       if(particle->GetMother(0) >= fMCStack->GetNprimary()){
827          return kFALSE; // the gamma has a mother, and it is not a primary particle
828       }
829
830       if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
831
832       // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
833       TParticle* ePos = NULL;
834       TParticle* eNeg = NULL;
835
836       if(particle->GetNDaughters() >= 2){
837          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
838             TParticle *tmpDaughter = fMCStack->Particle(daughterIndex);
839             if(tmpDaughter->GetUniqueID() == 5){
840                if(tmpDaughter->GetPdgCode() == 11){
841                   eNeg = tmpDaughter;
842                } else if(tmpDaughter->GetPdgCode() == -11){
843                   ePos = tmpDaughter;
844                }
845             }
846          }
847       }
848
849       if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
850          return kFALSE;
851       }
852
853       if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
854          return kFALSE; // no reconstruction below the Pt cut
855       }
856
857       if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ||
858           eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) )
859          return kFALSE;
860
861       if(fEtaCutMin > -0.1){
862          if( (ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift)) ||
863              (eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift)) )
864             return kFALSE;
865       }
866
867       if(ePos->R()>fMaxR){
868          return kFALSE; // cuts on distance from collision point
869       }
870
871       if(abs(ePos->Vz()) > fMaxZ){
872          return kFALSE;  // outside material
873       }
874       if(abs(eNeg->Vz()) > fMaxZ){
875          return kFALSE;  // outside material
876       }
877
878       if( ePos->R() <= ((abs(ePos->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
879          return kFALSE;  // line cut to exclude regions where we do not reconstruct
880       } else if ( fEtaCutMin != -0.1 &&   ePos->R() >= ((abs(ePos->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
881          return kFALSE;
882       }
883
884       if( eNeg->R() <= ((abs(eNeg->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
885          return kFALSE; // line cut to exclude regions where we do not reconstruct
886       } else if ( fEtaCutMin != -0.1 &&   eNeg->R() >= ((abs(eNeg->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
887          return kFALSE;
888       }
889
890       return kTRUE;
891       //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
892    }
893    return kFALSE;
894 }
895 ///________________________________________________________________________
896 Bool_t AliConversionCuts::PhotonIsSelectedAODMC(AliAODMCParticle *particle,TClonesArray *aodmcArray,Bool_t checkForConvertedGamma){
897    // MonteCarlo Photon Selection
898
899    if(!aodmcArray)return kFALSE;
900
901    if (particle->GetPdgCode() == 22){
902       if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )
903          return kFALSE;
904       if(fEtaCutMin>-0.1){
905          if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) )
906             return kFALSE;
907       }
908
909       if(particle->GetMother() > -1){
910          if((static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother())))->GetPdgCode() == 22){
911             return kFALSE; // no photon as mothers!
912          }
913          if(!(static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother()))->IsPrimary())){
914             return kFALSE; // the gamma has a mother, and it is not a primary particle
915          }
916       }
917
918       if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
919
920       // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
921       AliAODMCParticle* ePos = NULL;
922       AliAODMCParticle* eNeg = NULL;
923
924       if(particle->GetNDaughters() >= 2){
925          for(Int_t daughterIndex=particle->GetDaughter(0);daughterIndex<=particle->GetDaughter(1);daughterIndex++){
926             AliAODMCParticle *tmpDaughter = static_cast<AliAODMCParticle*>(aodmcArray->At(daughterIndex));
927             if(!tmpDaughter) continue;
928             if(((tmpDaughter->GetMCProcessCode())) == 5){    // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
929                if(tmpDaughter->GetPdgCode() == 11){
930                   eNeg = tmpDaughter;
931                } else if(tmpDaughter->GetPdgCode() == -11){
932                   ePos = tmpDaughter;
933                }
934             }
935          }
936       }
937
938       if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
939          return kFALSE;
940       }
941
942       if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
943          return kFALSE; // no reconstruction below the Pt cut
944       }
945
946       if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ||
947           eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) )
948          return kFALSE;
949
950       if(fEtaCutMin > -0.1){
951          if( (ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift)) ||
952              (eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift)) )
953             return kFALSE;
954       }
955
956       Double_t rPos = sqrt( (ePos->Xv()*ePos->Xv()) + (ePos->Yv()*ePos->Yv()) );
957       Double_t rNeg = sqrt( (eNeg->Xv()*eNeg->Xv()) + (eNeg->Yv()*eNeg->Yv()) );
958
959       if(rPos>fMaxR){
960          return kFALSE; // cuts on distance from collision point
961       }
962       if(abs(ePos->Zv()) > fMaxZ){
963          return kFALSE;  // outside material
964       }
965       if(abs(eNeg->Zv()) > fMaxZ){
966          return kFALSE;  // outside material
967       }
968
969       if( rPos <= ((abs(ePos->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
970          return kFALSE;  // line cut to exclude regions where we do not reconstruct
971       } else if ( fEtaCutMin != -0.1 &&   rPos >= ((abs(ePos->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
972          return kFALSE;
973       }
974
975       if( rNeg <= ((abs(eNeg->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
976          return kFALSE; // line cut to exclude regions where we do not reconstruct
977       } else if ( fEtaCutMin != -0.1 &&   rNeg >= ((abs(eNeg->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
978          return kFALSE;
979       }
980
981       return kTRUE;
982       //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
983    }
984    return kFALSE;
985 }
986 ///________________________________________________________________________
987 Bool_t AliConversionCuts::PhotonCuts(AliConversionPhotonBase *photon,AliVEvent *event)
988 {   // Specific Photon Cuts
989
990    Int_t cutIndex = 0;
991    if(hPhotonCuts)hPhotonCuts->Fill(cutIndex);
992    cutIndex++;
993
994    // Fill Histos before Cuts
995    if(hInvMassbefore)hInvMassbefore->Fill(photon->GetMass());
996
997    if(hArmenterosbefore)hArmenterosbefore->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
998
999    // Gamma selection based on QT from Armenteros
1000    if(fDoQtGammaSelection == kTRUE){
1001       if(!ArmenterosQtCut(photon)){
1002          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //1
1003          return kFALSE;
1004       }
1005    }
1006    cutIndex++; //2
1007
1008    // Chi Cut
1009    if(photon->GetChi2perNDF() > fChi2CutConversion || photon->GetChi2perNDF() <=0){
1010       {
1011          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //2
1012          return kFALSE;
1013       }
1014    }
1015    cutIndex++;//3
1016
1017    // Reconstruction Acceptance Cuts
1018    if(!AcceptanceCuts(photon)){
1019       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //3
1020       return kFALSE;
1021    }
1022
1023    cutIndex++; //4
1024    // Asymmetry Cut
1025    if(fDoPhotonAsymmetryCut == kTRUE){
1026       if(!AsymmetryCut(photon,event)){
1027          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //4
1028          return kFALSE;
1029       }
1030    }
1031
1032    //Check the pid probability
1033    cutIndex++; //5
1034    if(!PIDProbabilityCut(photon, event)) {
1035       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //5
1036       return kFALSE;
1037    }
1038
1039    cutIndex++; //6
1040    if(!CorrectedTPCClusterCut(photon, event)) {
1041       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //6
1042       return kFALSE;
1043    }
1044
1045    Double_t magField = event->GetMagneticField();
1046    if( magField  < 0.0 ){
1047       magField =  1.0;
1048    } else {
1049       magField =  -1.0;
1050    }
1051    AliVTrack * electronCandidate = GetTrack(event,photon->GetTrackLabelNegative() );
1052    AliVTrack * positronCandidate = GetTrack(event,photon->GetTrackLabelPositive() );
1053    Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->Phi()-positronCandidate->Phi());
1054
1055    cutIndex++; //7
1056    if(!PsiPairCut(photon,deltaPhi)) {
1057       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //7
1058       return kFALSE;
1059    }
1060
1061    cutIndex++; //8
1062    if(!CosinePAngleCut(photon, event)) {
1063       if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //8
1064       return kFALSE;
1065    }
1066
1067    AliAODConversionPhoton* photonAOD = dynamic_cast<AliAODConversionPhoton*>(photon);
1068    if (photonAOD){
1069       photonAOD->CalculateDistanceOfClossetApproachToPrimVtx(event->GetPrimaryVertex());
1070
1071       cutIndex++; //9
1072       if(photonAOD->GetDCArToPrimVtx() > fDCARPrimVtxCut) { //DCA R cut of photon to primary vertex
1073          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //9
1074          return kFALSE;
1075       }
1076
1077       cutIndex++; //10
1078       if(abs(photonAOD->GetDCAzToPrimVtx()) > fDCAZPrimVtxCut) { //DCA Z cut of photon to primary vertex
1079          if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //10
1080          return kFALSE;
1081       }
1082    } else {
1083       cutIndex++; //9
1084       cutIndex++; //10
1085    }
1086    cutIndex++; //11
1087    if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //11
1088
1089    // Histos after Cuts
1090    if(hInvMassafter)hInvMassafter->Fill(photon->GetMass());
1091    if(hArmenterosafter)hArmenterosafter->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
1092    if(hPsiPairDeltaPhiafter)hPsiPairDeltaPhiafter->Fill(deltaPhi,photon->GetPsiPair());
1093    return kTRUE;
1094
1095 }
1096
1097 ///________________________________________________________________________
1098 Bool_t AliConversionCuts::CorrectedTPCClusterCut(AliConversionPhotonBase *photon, AliVEvent * event)
1099 {   //Cut on corrected TPC Cluster Info
1100
1101    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1102    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1103
1104    if(!negTrack||!posTrack)return kFALSE;
1105
1106    Double_t negclsToF=0;
1107
1108    if (!fUseCorrectedTPCClsInfo ){
1109       if(negTrack->GetTPCNclsF()!=0){
1110          negclsToF = (Double_t)negTrack->GetNcls(1)/(Double_t)negTrack->GetTPCNclsF();}// Ncluster/Nfindablecluster
1111    }
1112    else {
1113       negclsToF = negTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1114    }
1115
1116    Double_t posclsToF = 0.;
1117    if (!fUseCorrectedTPCClsInfo ){
1118       if(posTrack->GetTPCNclsF()!=0){
1119          posclsToF = (Double_t)posTrack->GetNcls(1)/(Double_t)posTrack->GetTPCNclsF();
1120       }
1121    }else{
1122       posclsToF = posTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1123    }
1124
1125    if( negclsToF < fMinClsTPCToF || posclsToF < fMinClsTPCToF ){
1126       return kFALSE;
1127    }
1128
1129    return kTRUE;
1130 }
1131
1132 ///________________________________________________________________________
1133 Bool_t AliConversionCuts::PhotonIsSelected(AliConversionPhotonBase *photon, AliVEvent * event)
1134 {
1135    //Selection of Reconstructed Photons
1136
1137    FillPhotonCutIndex(kPhotonIn);
1138
1139    if(event->IsA()==AliESDEvent::Class()) {
1140      if(!SelectV0Finder( ( ((AliESDEvent*)event)->GetV0(photon->GetV0Index()))->GetOnFlyStatus() ) ){
1141          FillPhotonCutIndex(kOnFly);
1142          return kFALSE;
1143       }
1144    }
1145    // else if(event->IsA()==AliAODEvent::Class()) {
1146    //    if(!SelectV0Finder( ( ((AliAODEvent*)event)->GetV0(photon->GetV0Index())) ) ){
1147    //       FillPhotonCutIndex(kOnFly);
1148    //       return kFALSE;
1149    //    }
1150    // }
1151
1152    // Get Tracks
1153    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1154    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1155
1156    if(!negTrack || !posTrack) {
1157       FillPhotonCutIndex(kNoTracks);
1158       return kFALSE;
1159    }
1160    photon->DeterminePhotonQuality(negTrack,posTrack);
1161    // Track Cuts
1162    if(!TracksAreSelected(negTrack, posTrack)){
1163       FillPhotonCutIndex(kTrackCuts);
1164       return kFALSE;
1165    }
1166
1167    // dEdx Cuts
1168    if(!dEdxCuts(negTrack) || !dEdxCuts(posTrack)) {
1169       FillPhotonCutIndex(kdEdxCuts);
1170       return kFALSE;
1171    }
1172
1173    // Photon Cuts
1174    if(!PhotonCuts(photon,event)){
1175       FillPhotonCutIndex(kPhotonCuts);
1176       return kFALSE;
1177    }
1178
1179    // Photon passed cuts
1180    FillPhotonCutIndex(kPhotonOut);
1181    return kTRUE;
1182 }
1183
1184 ///________________________________________________________________________
1185 Bool_t AliConversionCuts::ArmenterosQtCut(AliConversionPhotonBase *photon)
1186 {   // Armenteros Qt Cut
1187
1188    if(fDoHighPtQtGammaSelection){
1189       if(photon->GetPhotonPt() < fPtBorderForQt){
1190          if(photon->GetArmenterosQt()>fQtMax){
1191             return kFALSE;
1192          }
1193       } else {
1194          if(photon->GetArmenterosQt()>fHighPtQtMax){
1195             return kFALSE;
1196          }
1197       }
1198    } else {
1199
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    //PrintCuts();
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
1990    case kNCuts:
1991       AliError("Cut id out of range");
1992       return kFALSE;
1993    }
1994
1995    AliError("Cut id %d not recognized");
1996    return kFALSE;
1997
1998
1999 }
2000 ///________________________________________________________________________
2001 void AliConversionCuts::PrintCuts() {
2002    // Print out current Cut Selection
2003    for(Int_t ic = 0; ic < kNCuts; ic++) {
2004       printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
2005    }
2006 }
2007 ///________________________________________________________________________
2008 Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
2009 {   // Set Cut
2010    switch(isHeavyIon){
2011    case 0:
2012       fIsHeavyIon=0;
2013       break;
2014    case 1:
2015       fIsHeavyIon=1;
2016       fDetectorCentrality=0;
2017       break;
2018    case 2:
2019       fIsHeavyIon=1;
2020       fDetectorCentrality=1;
2021       break;
2022    case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
2023       fIsHeavyIon=1;
2024       fDetectorCentrality=0;
2025       fModCentralityClass=1;
2026       break;
2027    case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2028       fIsHeavyIon=1;
2029       fDetectorCentrality=0;
2030       fModCentralityClass=2;
2031       break;
2032    case 5: //strict cut on v0 tracks for MC
2033       fIsHeavyIon=1;
2034       fDetectorCentrality=0;
2035       fModCentralityClass=3;
2036       break;
2037    case 6: //allows to select centrality 0-45% in steps of 5% for track mult
2038       //strict cut on v0 tracks for MC
2039       fIsHeavyIon=1;
2040       fDetectorCentrality=0;
2041       fModCentralityClass=4;
2042       break;
2043    case 7: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2044       //strict cut on v0 tracks for MC
2045       fIsHeavyIon=1;
2046       fDetectorCentrality=0;
2047       fModCentralityClass=5;
2048       break;
2049    case 8:
2050       fIsHeavyIon=2;
2051       fDetectorCentrality=0;
2052       break;
2053    case 9:
2054       fIsHeavyIon=2;
2055       fDetectorCentrality=1;
2056       break;
2057    default:
2058       AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
2059       return kFALSE;
2060    }
2061    return kTRUE;
2062 }
2063
2064 //___________________________________________________________________
2065 Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
2066 {
2067    // Set Cut
2068    if(minCentrality<0||minCentrality>9){
2069       AliError(Form("minCentrality not defined %d",minCentrality));
2070       return kFALSE;
2071    }
2072
2073    fCentralityMin=minCentrality;
2074    return kTRUE;
2075 }
2076 //___________________________________________________________________
2077 Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
2078 {
2079    // Set Cut
2080    if(maxCentrality<0||maxCentrality>9){
2081       AliError(Form("maxCentrality not defined %d",maxCentrality));
2082       return kFALSE;
2083    }
2084    fCentralityMax=maxCentrality;
2085    return kTRUE;
2086 }
2087 ///________________________________________________________________________
2088 Int_t AliConversionCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
2089 {// Set Cut
2090
2091    switch(selectSpecialTrigger){
2092    case 0:
2093       fSpecialTrigger=0; // dont care
2094       break;
2095    case 1:
2096       fSpecialTrigger=1; // V0AND
2097       break;
2098    case 2:
2099       fSpecialTrigger=2; // with SDD requested
2100       break;
2101    case 3:
2102       fSpecialTrigger=3; // V0AND plus with SDD requested
2103       break;
2104    // allows to run MB & 6 other different trigger classes in parallel with the same photon cut
2105    case 4:
2106       fSpecialTrigger=4; // different trigger class as MB
2107       fTriggerSelectedManually = kTRUE;
2108       break;
2109    case 5:
2110       fSpecialTrigger=4; // different trigger class as MB
2111       fTriggerSelectedManually = kTRUE;
2112       break;
2113    case 6:
2114       fSpecialTrigger=4; // different trigger class as MB
2115       fTriggerSelectedManually = kTRUE;
2116       break;
2117    case 7:
2118       fSpecialTrigger=4; // different trigger class as MB
2119       fTriggerSelectedManually = kTRUE;
2120       break;
2121     case 8:
2122       fSpecialTrigger=4; // different trigger class as MB
2123       fTriggerSelectedManually = kTRUE;
2124       break;
2125     case 9:
2126       fSpecialTrigger=4; // different trigger class as MB
2127       fTriggerSelectedManually = kTRUE;
2128       break;
2129    default:
2130       AliError("Warning: Special Trigger Not known");
2131       return kFALSE;
2132    }
2133    return kTRUE;
2134 }
2135 ///________________________________________________________________________
2136 Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
2137 {
2138    // Set Cut
2139    fMultiplicityMethod=multiplicityMethod;
2140
2141    // 0 Photon Multiplicity
2142    // 1 TPC Track multiplicity
2143    // 2 V0 Mult
2144    // 3 SPD Mult
2145
2146    return kTRUE;
2147 }
2148 ///________________________________________________________________________
2149 Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
2150 {// Set Cut
2151    switch(removePileUp){
2152    case 0:
2153       fRemovePileUp=kFALSE;
2154       break;
2155    case 1:
2156       fRemovePileUp=kTRUE;
2157       break;
2158    default:
2159       AliError("RemovePileUpCut not defined");
2160       return kFALSE;
2161    }
2162    return kTRUE;
2163 }
2164 ///________________________________________________________________________
2165 Bool_t AliConversionCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
2166
2167    switch(extraSignal){
2168    case 0:
2169       fRejectExtraSignals = 0;
2170       break; // No Rejection
2171    case 1:
2172       fRejectExtraSignals = 1;
2173       break; // MinBias Header
2174    case 2:
2175       fRejectExtraSignals = 2;
2176       break; // User String Array
2177    case 3:
2178       fRejectExtraSignals = 3;
2179       break; // Rejection for Gamma Correction only
2180    default:
2181       AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
2182       return kFALSE;
2183    }
2184    return kTRUE;
2185 }
2186 ///________________________________________________________________________
2187 Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
2188 {   // Set Cut
2189    switch (v0FinderType){
2190    case 0:  // on fly V0 finder
2191       cout << "have chosen onfly V0" << endl;
2192       fUseOnFlyV0Finder=kTRUE;
2193       break;
2194    case 1:  // offline V0 finder
2195       cout << "have chosen offline V0" << endl;
2196       fUseOnFlyV0Finder=kFALSE;
2197       break;
2198    default:
2199       AliError(Form(" v0FinderType not defined %d",v0FinderType));
2200       return kFALSE;
2201    }
2202    return kTRUE;
2203 }
2204 ///________________________________________________________________________
2205 Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
2206 {   // Set Cut
2207
2208    //Set Standard LineCutZValues
2209    fLineCutZValueMin = -2;
2210    fLineCutZValue = 7.;
2211
2212    switch(etaCut){
2213    case 0: // 0.9
2214       fEtaCut     = 0.9;
2215       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2216       fEtaCutMin     = -0.1;
2217       fLineCutZRSlopeMin = 0.;
2218       break;
2219    case 1:  // 0.6  // changed from 1.2 to 0.6 on 2013.06.10
2220       fEtaCut     = 0.6;
2221       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2222       fEtaCutMin     = -0.1;
2223       fLineCutZRSlopeMin = 0.;
2224       break;
2225    case 2:  // 1.4
2226       fEtaCut     = 1.4;
2227       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2228       fEtaCutMin     = -0.1;
2229       fLineCutZRSlopeMin = 0.;
2230       break;
2231    case 3: // 0.65
2232       fEtaCut     = 0.65;
2233       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2234       fEtaCutMin     = -0.1;
2235       fLineCutZRSlopeMin = 0.;
2236       break;
2237    case 4: // 0.75
2238       fEtaCut     = 0.75;
2239       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2240       fEtaCutMin     = -0.1;
2241       fLineCutZRSlopeMin = 0.;
2242       break;
2243    case 5: // 0.5
2244       fEtaCut     = 0.5;
2245       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2246       fEtaCutMin     = -0.1;
2247       fLineCutZRSlopeMin = 0.;
2248       break;
2249    case 6: // 5.
2250       fEtaCut     = 5.;
2251       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2252       fEtaCutMin     = -0.1;
2253       fLineCutZRSlopeMin = 0.;
2254       break;
2255    case 7:
2256       if (fIsHeavyIon==1){
2257          fEtaCut     = 0.7;
2258          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2259          fEtaCutMin     = -0.1;
2260          fLineCutZRSlopeMin = 0.;
2261          break;
2262       } else {   
2263          fEtaCut     = 0.3;
2264          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2265          fEtaCutMin     = -0.1;
2266          fLineCutZRSlopeMin = 0.;
2267          break;
2268       }
2269    // case 8: // 0.1 - 0.8
2270    //    fEtaCut     = 0.9;
2271    //    fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2272    //    fEtaCutMin     = 0.1;
2273    //    fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2274    //    break;
2275    case 8: // 0.4
2276       fEtaCut     = 0.4;
2277       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2278       fEtaCutMin     = -0.1;
2279       fLineCutZRSlopeMin = 0.;
2280       break;
2281    case 9: // 10
2282       fEtaCut     = 10;
2283       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2284       fEtaCutMin     = -0.1;
2285       fLineCutZRSlopeMin = 0.;
2286       break;
2287    default:
2288       AliError(Form(" EtaCut not defined %d",etaCut));
2289       return kFALSE;
2290    }
2291    return kTRUE;
2292 }
2293 ///________________________________________________________________________
2294 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
2295    // Set Cut
2296    switch(RCut){
2297    case 0:
2298       fMinR=0;
2299       fMaxR = 180.;
2300       break;
2301    case 1:
2302       fMinR=2.8;
2303       fMaxR = 180.;
2304       break;
2305    case 2:
2306       fMinR=5.;
2307       fMaxR = 180.;
2308       break;
2309    case 3:
2310       fMaxR = 70.;
2311       fMinR = 10.;
2312       break;
2313    case 4:
2314       fMaxR = 70.;
2315       fMinR = 5.;
2316       break;
2317       // High purity cuts for PbPb (remove first layers of material)
2318    case 5:
2319       fMaxR = 180.;
2320       fMinR = 10.;
2321       break;
2322    case 6:
2323       fMaxR = 180.;
2324       fMinR = 20.;
2325       break;
2326    case 7:
2327       fMaxR = 180.;
2328       fMinR = 26.;
2329       break;
2330    case 8:
2331       fMaxR = 180.;
2332       fMinR = 12.5;
2333       break;
2334    case 9:
2335       fMaxR = 180.;
2336       fMinR = 7.5;
2337       break;
2338
2339    default:
2340       AliError("RCut not defined");
2341       return kFALSE;
2342    }
2343    return kTRUE;
2344 }
2345 ///________________________________________________________________________
2346 Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
2347 {   // Set Cut
2348    switch(singlePtCut){
2349    case 0: // 0.050 GeV
2350       fSinglePtCut = 0.050;
2351       break;
2352    case 1:  // 0.100 GeV
2353       fSinglePtCut = 0.100;
2354       break;
2355    case 2:  // 0.150 GeV
2356       fSinglePtCut = 0.150;
2357       break;
2358    case 3:  // 0.200 GeV
2359       fSinglePtCut = 0.200;
2360       break;
2361    case 4:  // 0.075 GeV
2362       fSinglePtCut = 0.075;
2363       break;
2364    case 5:  // 0.125 GeV
2365       fSinglePtCut = 0.125;
2366       break;
2367    case 6:  // 0.04 GeV
2368       fSinglePtCut = 0.040;
2369       break;
2370    case 7:  // 0.0 GeV
2371       fSinglePtCut = 0.0;
2372       break;
2373    default:
2374       AliError(Form("singlePtCut not defined %d",singlePtCut));
2375       return kFALSE;
2376    }
2377    return kTRUE;
2378 }
2379 ///________________________________________________________________________
2380 Bool_t AliConversionCuts::SetTPCClusterCut(Int_t clsTPCCut)
2381 {   // Set Cut
2382    switch(clsTPCCut){
2383    case 0: // 0
2384       fMinClsTPC= 0.;
2385       break;
2386    case 1:  // 60
2387       fMinClsTPC= 60.;
2388       break;
2389    case 2:  // 80
2390       fMinClsTPC= 80.;
2391       break;
2392    case 3:  // 100
2393       fMinClsTPC= 100.;
2394       break;
2395    case 4:  // 95% of findable clusters
2396       fMinClsTPCToF= 0.95;
2397       fUseCorrectedTPCClsInfo=1;
2398       break;
2399    case 5:  // 0% of findable clusters
2400       fMinClsTPCToF= 0.0;
2401       fUseCorrectedTPCClsInfo=1;
2402       break;
2403    case 6:  // 70% of findable clusters
2404       fMinClsTPCToF= 0.7;
2405       fUseCorrectedTPCClsInfo=1;
2406       break;
2407    case 7:  // 0% of findable clusters
2408       fMinClsTPCToF= 0.35;
2409       fUseCorrectedTPCClsInfo=0;
2410       break;
2411    case 8:
2412       fMinClsTPCToF= 0.35;
2413       fUseCorrectedTPCClsInfo=1;
2414       break;
2415    case 9:
2416       fMinClsTPCToF= 0.6;
2417       fUseCorrectedTPCClsInfo=1;
2418       break;
2419    default:
2420       AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
2421       return kFALSE;
2422    }
2423    return kTRUE;
2424 }
2425 ///________________________________________________________________________
2426 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
2427 {   // Set Cut
2428    switch(ededxSigmaCut){
2429    case 0: // -10,10
2430       fPIDnSigmaBelowElectronLine=-10;
2431       fPIDnSigmaAboveElectronLine=10;
2432       break;
2433    case 1: // -5,5
2434       fPIDnSigmaBelowElectronLine=-5;
2435       fPIDnSigmaAboveElectronLine=5;
2436       break;
2437    case 2: // -3,5
2438       fPIDnSigmaBelowElectronLine=-3;
2439       fPIDnSigmaAboveElectronLine=5;
2440       break;
2441    case 3: // -4,5
2442       fPIDnSigmaBelowElectronLine=-4;
2443       fPIDnSigmaAboveElectronLine=5;
2444       break;
2445    case 4: // -6,7
2446       fPIDnSigmaBelowElectronLine=-6;
2447       fPIDnSigmaAboveElectronLine=7;
2448       break;
2449    case 5: // -4,4
2450       fPIDnSigmaBelowElectronLine=-4;
2451       fPIDnSigmaAboveElectronLine=4;
2452       break;
2453    case 6: // -2.5,4
2454       fPIDnSigmaBelowElectronLine=-2.5;
2455       fPIDnSigmaAboveElectronLine=4;
2456       break;
2457    case 7: // -2,3.5
2458       fPIDnSigmaBelowElectronLine=-2;
2459       fPIDnSigmaAboveElectronLine=3.5;
2460       break;
2461    default:
2462       AliError("TPCdEdxCutElectronLine not defined");
2463       return kFALSE;
2464
2465    }
2466    return kTRUE;
2467 }
2468 ///________________________________________________________________________
2469 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
2470 {   // Set Cut
2471
2472    switch(pidedxSigmaCut){
2473    case 0:  // -10
2474       fPIDnSigmaAbovePionLine=-10;
2475       fPIDnSigmaAbovePionLineHighPt=-10;
2476       break;
2477    case 1:   // 0
2478       fPIDnSigmaAbovePionLine=0;
2479       fPIDnSigmaAbovePionLineHighPt=-10;
2480       break;
2481    case 2:  // 1
2482       fPIDnSigmaAbovePionLine=1;
2483       fPIDnSigmaAbovePionLineHighPt=-10;
2484       break;
2485    case 3:  // 1
2486       fPIDnSigmaAbovePionLine=2.5;
2487       fPIDnSigmaAbovePionLineHighPt=-10;
2488       break;
2489    case 4:  // 1
2490       fPIDnSigmaAbovePionLine=0.5;
2491       fPIDnSigmaAbovePionLineHighPt=-10;
2492       break;
2493    case 5:  // 1
2494       fPIDnSigmaAbovePionLine=2.;
2495       fPIDnSigmaAbovePionLineHighPt=-10;
2496       break;
2497    case 6:  // 1
2498       fPIDnSigmaAbovePionLine=2.;
2499       fPIDnSigmaAbovePionLineHighPt=0.5;
2500       break;
2501    case 7:  // 1
2502       fPIDnSigmaAbovePionLine=3.5;
2503       fPIDnSigmaAbovePionLineHighPt=-10;
2504       break;
2505    case 8:  // 1
2506       fPIDnSigmaAbovePionLine=2.;
2507       fPIDnSigmaAbovePionLineHighPt=1.;
2508       break;
2509    case 9:
2510       fPIDnSigmaAbovePionLine=3.0; // We need a bit less tight cut on dE/dx
2511       fPIDnSigmaAbovePionLineHighPt=-10;
2512       break;
2513    default:
2514       AliError(Form("Warning: pidedxSigmaCut not defined %d",pidedxSigmaCut));
2515       return kFALSE;
2516    }
2517    return kTRUE;
2518 }
2519 ///________________________________________________________________________
2520 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
2521 {   // Set Cut
2522    switch(piMomdedxSigmaCut){
2523    case 0:  // 0.5 GeV
2524       fPIDMinPnSigmaAbovePionLine=0.5;
2525       break;
2526    case 1:  // 1. GeV
2527       fPIDMinPnSigmaAbovePionLine=1.;
2528       break;
2529    case 2:  // 1.5 GeV
2530       fPIDMinPnSigmaAbovePionLine=1.5;
2531       break;
2532    case 3:  // 20.0 GeV
2533       fPIDMinPnSigmaAbovePionLine=20.;
2534       break;
2535    case 4:  // 50.0 GeV
2536       fPIDMinPnSigmaAbovePionLine=50.;
2537       break;
2538    case 5:  // 0.3 GeV
2539       fPIDMinPnSigmaAbovePionLine=0.3;
2540       break;
2541    case 6:  // 0.25 GeV
2542       fPIDMinPnSigmaAbovePionLine=0.25;
2543       break;
2544    case 7:  // 0.4 GeV
2545       fPIDMinPnSigmaAbovePionLine=0.4;
2546       break;
2547    case 8:  // 0.2 GeV
2548       fPIDMinPnSigmaAbovePionLine=0.2;
2549       break;
2550    default:
2551       AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
2552       return kFALSE;
2553    }
2554    return kTRUE;
2555 }
2556 ///________________________________________________________________________
2557 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
2558 {   // Set Cut
2559    switch(piMaxMomdedxSigmaCut){
2560    case 0:  // 100. GeV
2561       fPIDMaxPnSigmaAbovePionLine=100.;
2562       break;
2563    case 1:  // 5. GeV
2564       fPIDMaxPnSigmaAbovePionLine=5.;
2565       break;
2566    case 2:  // 4. GeV
2567       fPIDMaxPnSigmaAbovePionLine=4.;
2568       break;
2569    case 3:  // 3.5 GeV
2570       fPIDMaxPnSigmaAbovePionLine=3.5;
2571       break;
2572    case 4:  // 3. GeV
2573       fPIDMaxPnSigmaAbovePionLine=3.;
2574       break;
2575    case 5:  // 7. GeV
2576       fPIDMaxPnSigmaAbovePionLine=7.;
2577       break;
2578    default:
2579       AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
2580       return kFALSE;
2581    }
2582    return kTRUE;
2583 }
2584 ///________________________________________________________________________
2585 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
2586 {   // Set Cut
2587    switch(LowPRejectionSigmaCut){
2588    case 0:  //
2589       fPIDnSigmaAtLowPAroundKaonLine=0;
2590       fPIDnSigmaAtLowPAroundProtonLine=0;
2591       fPIDnSigmaAtLowPAroundPionLine=0;
2592       fDoKaonRejectionLowP = kFALSE;
2593       fDoProtonRejectionLowP = kFALSE;
2594       fDoPionRejectionLowP = kFALSE;
2595       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2596       break;
2597    case 1:  //
2598       fPIDnSigmaAtLowPAroundKaonLine=0.5;
2599       fPIDnSigmaAtLowPAroundProtonLine=0.5;
2600       fPIDnSigmaAtLowPAroundPionLine=0.5;
2601       fDoKaonRejectionLowP = kTRUE;
2602       fDoProtonRejectionLowP = kTRUE;
2603       fDoPionRejectionLowP = kTRUE;
2604       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2605       break;
2606    case 2:  //
2607       fPIDnSigmaAtLowPAroundKaonLine=1;
2608       fPIDnSigmaAtLowPAroundProtonLine=1;
2609       fPIDnSigmaAtLowPAroundPionLine=1;
2610       fDoKaonRejectionLowP = kTRUE;
2611       fDoProtonRejectionLowP = kTRUE;
2612       fDoPionRejectionLowP = kTRUE;
2613       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2614       break;
2615    case 3:  //
2616       fPIDnSigmaAtLowPAroundKaonLine=2.;
2617       fPIDnSigmaAtLowPAroundProtonLine=2.;
2618       fPIDnSigmaAtLowPAroundPionLine=2.;
2619       fDoKaonRejectionLowP = kTRUE;
2620       fDoProtonRejectionLowP = kTRUE;
2621       fDoPionRejectionLowP = kTRUE;
2622       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2623       break;
2624    case 4:  //
2625       fPIDnSigmaAtLowPAroundKaonLine=0.;
2626       fPIDnSigmaAtLowPAroundProtonLine=0.;
2627       fPIDnSigmaAtLowPAroundPionLine=1;
2628       fDoKaonRejectionLowP = kFALSE;
2629       fDoProtonRejectionLowP = kFALSE;
2630       fDoPionRejectionLowP = kTRUE;
2631       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2632       break;
2633    case 5:  //
2634       fPIDnSigmaAtLowPAroundKaonLine=0.;
2635       fPIDnSigmaAtLowPAroundProtonLine=0.;
2636       fPIDnSigmaAtLowPAroundPionLine=1.5;
2637       fDoKaonRejectionLowP = kFALSE;
2638       fDoProtonRejectionLowP = kFALSE;
2639       fDoPionRejectionLowP = kTRUE;
2640       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2641       break;
2642    case 6:  //
2643       fPIDnSigmaAtLowPAroundKaonLine=0.;
2644       fPIDnSigmaAtLowPAroundProtonLine=0.;
2645       fPIDnSigmaAtLowPAroundPionLine=2.;
2646       fDoKaonRejectionLowP = kFALSE;
2647       fDoProtonRejectionLowP = kFALSE;
2648       fDoPionRejectionLowP = kTRUE;
2649       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2650       break;
2651    case 7:  //
2652       fPIDnSigmaAtLowPAroundKaonLine=0.;
2653       fPIDnSigmaAtLowPAroundProtonLine=0.;
2654       fPIDnSigmaAtLowPAroundPionLine=0.5;
2655       fDoKaonRejectionLowP = kFALSE;
2656       fDoProtonRejectionLowP = kFALSE;
2657       fDoPionRejectionLowP = kTRUE;
2658       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2659       break;
2660    default:
2661       AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
2662       return kFALSE;
2663    }
2664    return kTRUE;
2665 }
2666 ///________________________________________________________________________
2667 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
2668    // Set Cut
2669    switch(TOFelectronPID){
2670    case 0: // no cut
2671       fUseTOFpid = kFALSE;
2672       fTofPIDnSigmaBelowElectronLine=-100;
2673       fTofPIDnSigmaAboveElectronLine=100;
2674       break;
2675    case 1: // -7,7
2676       fUseTOFpid = kTRUE;
2677       fTofPIDnSigmaBelowElectronLine=-7;
2678       fTofPIDnSigmaAboveElectronLine=7;
2679       break;
2680    case 2: // -5,5
2681       fUseTOFpid = kTRUE;
2682       fTofPIDnSigmaBelowElectronLine=-5;
2683       fTofPIDnSigmaAboveElectronLine=5;
2684       break;
2685    case 3: // -3,5
2686       fUseTOFpid = kTRUE;
2687       fTofPIDnSigmaBelowElectronLine=-3;
2688       fTofPIDnSigmaAboveElectronLine=5;
2689       break;
2690    case 4: // -2,3
2691       fUseTOFpid = kTRUE;
2692       fTofPIDnSigmaBelowElectronLine=-2;
2693       fTofPIDnSigmaAboveElectronLine=3;
2694       break;
2695    case 5: // -3,3
2696       fUseTOFpid = kTRUE;
2697       fTofPIDnSigmaBelowElectronLine=-3;
2698       fTofPIDnSigmaAboveElectronLine=3;
2699       break;
2700    default:
2701       AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
2702       return kFALSE;
2703    }
2704    return kTRUE;
2705 }
2706 ///________________________________________________________________________
2707 Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
2708 {   // Set Cut
2709    switch(QtMaxCut){
2710    case 0: //
2711       fQtMax=1.;
2712       fDoQtGammaSelection=kFALSE;
2713       fDoHighPtQtGammaSelection=kFALSE;
2714       fHighPtQtMax=100.;
2715       fPtBorderForQt=100.;
2716       break;
2717    case 1:
2718       fQtMax=0.1;
2719       fDoHighPtQtGammaSelection=kFALSE;
2720       fHighPtQtMax=100.;
2721       fPtBorderForQt=100.;
2722       break;
2723    case 2:
2724       fQtMax=0.07;
2725       fDoHighPtQtGammaSelection=kFALSE;
2726       fHighPtQtMax=100.;
2727       fPtBorderForQt=100.;
2728       break;
2729    case 3:
2730       fQtMax=0.05;
2731       fDoHighPtQtGammaSelection=kFALSE;
2732       fHighPtQtMax=100.;
2733       fPtBorderForQt=100.;
2734       break;
2735    case 4:
2736       fQtMax=0.03;
2737       fDoHighPtQtGammaSelection=kFALSE;
2738       fHighPtQtMax=100.;
2739       fPtBorderForQt=100.;
2740       break;
2741    case 5:
2742       fQtMax=0.02;
2743       fDoHighPtQtGammaSelection=kFALSE;
2744       fHighPtQtMax=100.;
2745       fPtBorderForQt=100.;
2746       break;
2747    case 6:
2748       fQtMax=0.02;
2749       fDoHighPtQtGammaSelection=kTRUE;
2750       fHighPtQtMax=0.06;
2751       fPtBorderForQt=2.5;
2752       break;
2753    case 7:
2754       fQtMax=0.15;
2755       fDoHighPtQtGammaSelection=kFALSE;
2756       fHighPtQtMax=100.;
2757       fPtBorderForQt=100.;
2758       break;
2759    default:
2760       AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
2761       return kFALSE;
2762    }
2763    return kTRUE;
2764 }
2765 ///________________________________________________________________________
2766 Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
2767 {   // Set Cut
2768
2769    switch(chi2GammaCut){
2770    case 0: // 100
2771       fChi2CutConversion = 100.;
2772       break;
2773    case 1:  // 50
2774       fChi2CutConversion = 50.;
2775       break;
2776    case 2:  // 30
2777       fChi2CutConversion = 30.;
2778       break;
2779    case 3:
2780       fChi2CutConversion = 200.;
2781       break;
2782    case 4:
2783       fChi2CutConversion = 500.;
2784       break;
2785    case 5:
2786       fChi2CutConversion = 100000.;
2787       break;
2788    case 6:
2789       fChi2CutConversion = 5.;
2790       break;
2791    case 7:
2792       fChi2CutConversion = 10.;
2793       break;
2794    case 8:
2795       fChi2CutConversion = 20.;
2796       break;
2797    case 9:
2798       fChi2CutConversion = 15.;
2799       break;
2800    default:
2801       AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
2802       return kFALSE;
2803    }
2804    return kTRUE;
2805 }
2806 ///________________________________________________________________________
2807 Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
2808
2809    switch(psiCut) {
2810    case 0:
2811       fPsiPairCut = 10000; //
2812       break;
2813    case 1:
2814       fPsiPairCut = 0.1; //
2815       break;
2816    case 2:
2817       fPsiPairCut = 0.05; // Standard
2818       break;
2819    case 3:
2820       fPsiPairCut = 0.035; //
2821       break;
2822    case 4:
2823       fPsiPairCut = 0.2; //
2824       break;   
2825    case 5:
2826       fPsiPairCut = 0.1; //
2827       fPsiPairDeltaPhiCut = 1;
2828       fDo2DPsiPair = kTRUE;
2829       break;
2830    case 6:
2831       fPsiPairCut = 0.05; //
2832       fPsiPairDeltaPhiCut = 1;
2833       fDo2DPsiPair = kTRUE;
2834       break;
2835    case 7:
2836       fPsiPairCut = 0.035; //
2837       fPsiPairDeltaPhiCut = 1;
2838       fDo2DPsiPair = kTRUE;
2839       break;
2840    case 8:
2841       fPsiPairCut = 0.2; //
2842       fPsiPairDeltaPhiCut = 1;
2843       fDo2DPsiPair = kTRUE; //
2844       break;
2845    case 9:
2846       fPsiPairCut = 0.5; //
2847       break;
2848    default:
2849       AliError(Form("PsiPairCut not defined %d",psiCut));
2850       return kFALSE;
2851    }
2852
2853    return kTRUE;
2854 }
2855 ///________________________________________________________________________
2856 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
2857    // Set Cut
2858    switch(doPhotonAsymmetryCut){
2859    case 0:
2860       fDoPhotonAsymmetryCut=0;
2861       fMinPPhotonAsymmetryCut=100.;
2862       fMinPhotonAsymmetry=0.;
2863       break;
2864    case 1:
2865       fDoPhotonAsymmetryCut=1;
2866       fMinPPhotonAsymmetryCut=3.5;
2867       fMinPhotonAsymmetry=0.04;
2868       break;
2869    case 2:
2870       fDoPhotonAsymmetryCut=1;
2871       fMinPPhotonAsymmetryCut=3.5;
2872       fMinPhotonAsymmetry=0.06;
2873       break;
2874    case 3:
2875       fDoPhotonAsymmetryCut=1;
2876       fMinPPhotonAsymmetryCut=0.0;
2877       fMinPhotonAsymmetry=0.05;
2878       break; 
2879    default:
2880       AliError(Form("PhotonAsymmetryCut not defined %d",doPhotonAsymmetryCut));
2881       return kFALSE;
2882    }
2883    fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
2884    return kTRUE;
2885 }
2886 ///________________________________________________________________________
2887 Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
2888
2889    switch(cosCut){
2890    case 0:
2891       fCosPAngleCut = TMath::Pi(); // -1
2892       break;
2893    case 1:
2894       fCosPAngleCut = 0.1; // 0.99500
2895       break;
2896    case 2:
2897       fCosPAngleCut = 0.05; // 0.99875
2898       break;
2899    case 3:
2900       fCosPAngleCut = 0.025; // 0.99969
2901       break;
2902    case 4:
2903       fCosPAngleCut = 0.01; // 0.99995
2904       break;
2905    case 5:
2906       fCosPAngleCut = 0.2; // 0.98007
2907       break;
2908    case 6:
2909       fCosPAngleCut = 0.5; // 0.87758
2910       break;
2911    case 7:
2912       fCosPAngleCut = 0.075; // 0.73169
2913       break;
2914    default:
2915       AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
2916       return kFALSE;
2917    }
2918
2919    return kTRUE;
2920 }
2921 ///________________________________________________________________________
2922 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
2923
2924    switch(sharedElec){
2925    case 0:
2926       fDoSharedElecCut = kFALSE;
2927       break;
2928    case 1:
2929       fDoSharedElecCut = kTRUE;
2930       break;
2931    default:
2932       AliError(Form("Shared Electron Cut not defined %d",sharedElec));
2933       return kFALSE;
2934    }
2935
2936    return kTRUE;
2937 }
2938 ///________________________________________________________________________
2939 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
2940
2941    switch(toClose){
2942    case 0:
2943       fDoToCloseV0sCut = kFALSE;
2944       fminV0Dist = 250;
2945       break;
2946    case 1:
2947       fDoToCloseV0sCut = kTRUE;
2948       fminV0Dist = 1;
2949       break;
2950    case 2:
2951       fDoToCloseV0sCut = kTRUE;
2952       fminV0Dist = 2;
2953       break;
2954    case 3:
2955       fDoToCloseV0sCut = kTRUE;
2956       fminV0Dist = 3;
2957       break;
2958    default:
2959       AliError(Form("Shared Electron Cut not defined %d",toClose));
2960       return kFALSE;
2961    }
2962    return kTRUE;
2963 }
2964 ///________________________________________________________________________
2965 Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
2966 {   // Set Cut
2967    switch(TRDElectronCut){
2968    case 0:
2969       fDoTRDPID=kFALSE;
2970       break;
2971    case 1:
2972       fDoTRDPID=kTRUE;
2973       fPIDTRDEfficiency=0.1;
2974       break;
2975    case 8:
2976       fDoTRDPID=kTRUE;
2977       fPIDTRDEfficiency=0.8;
2978       break;
2979    case 9:
2980       fDoTRDPID=kTRUE;
2981       fPIDTRDEfficiency=0.9;
2982       break;
2983    default:
2984       AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
2985       return kFALSE;
2986    }
2987
2988    return kTRUE;
2989 }
2990
2991 ///________________________________________________________________________
2992 Bool_t AliConversionCuts::SetDCAZPhotonPrimVtxCut(Int_t DCAZPhotonPrimVtx){
2993    // Set Cut
2994    switch(DCAZPhotonPrimVtx){
2995    case 0:  //
2996       fDCAZPrimVtxCut   = 1000;
2997       break;
2998    case 1:  //
2999       fDCAZPrimVtxCut   = 10;
3000       break;
3001    case 2:  //
3002       fDCAZPrimVtxCut   = 5;
3003       break;
3004    case 3:  //
3005       fDCAZPrimVtxCut   = 4;
3006       break;
3007    case 4:  //
3008       fDCAZPrimVtxCut   = 3;
3009       break;
3010    case 5:  //
3011       fDCAZPrimVtxCut   = 2.5;
3012       break;
3013    case 6:  //
3014       fDCAZPrimVtxCut   = 2;
3015       break;
3016    case 7:  //
3017       fDCAZPrimVtxCut   = 1.5;
3018       break;
3019    case 8:  //
3020       fDCAZPrimVtxCut   = 1;
3021       break;
3022    case 9:  //
3023       fDCAZPrimVtxCut   = 0.5;
3024       break;
3025    default:
3026       cout<<"Warning: DCAZPhotonPrimVtx not defined "<<DCAZPhotonPrimVtx<<endl;
3027       return kFALSE;
3028    }
3029    return kTRUE;
3030 }
3031
3032 ///________________________________________________________________________
3033 Bool_t AliConversionCuts::SetDCARPhotonPrimVtxCut(Int_t DCARPhotonPrimVtx){
3034    // Set Cut
3035    switch(DCARPhotonPrimVtx){
3036    case 0:  //
3037       fDCARPrimVtxCut   = 1000;
3038       break;
3039    case 1:  //
3040       fDCARPrimVtxCut   = 10;
3041       break;
3042    case 2:  //
3043       fDCARPrimVtxCut   = 5;
3044       break;
3045    case 3:  //
3046       fDCARPrimVtxCut   = 4;
3047       break;
3048    case 4:  //
3049       fDCARPrimVtxCut   = 3;
3050       break;
3051    case 5:  //
3052       fDCARPrimVtxCut   = 2.5;
3053       break;
3054    case 6:  //
3055       fDCARPrimVtxCut   = 2;
3056       break;
3057    case 7:  //
3058       fDCARPrimVtxCut   = 1.5;
3059       break;
3060    case 8:  //
3061       fDCARPrimVtxCut   = 1;
3062       break;
3063    case 9:  //
3064       fDCARPrimVtxCut   = 0.5;
3065       break;
3066    default:
3067       cout<<"Warning: DCARPhotonPrimVtx not defined "<<DCARPhotonPrimVtx<<endl;
3068       return kFALSE;
3069    }
3070    return kTRUE;
3071 }
3072
3073
3074 //-------------------------------------------------------------
3075 Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
3076 {   // Get Event Centrality
3077
3078    AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
3079    if(esdEvent){
3080       AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
3081
3082       if(fDetectorCentrality==0){
3083          if (fIsHeavyIon==2){
3084             return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
3085          } else{
3086             return fESDCentrality->GetCentralityPercentile("V0M"); // default
3087          }
3088       }
3089       if(fDetectorCentrality==1){
3090          return fESDCentrality->GetCentralityPercentile("CL1");
3091       }
3092    }
3093
3094    AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
3095    if(aodEvent){
3096       if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
3097    }
3098
3099    return -1;
3100 }
3101 //-------------------------------------------------------------
3102 Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
3103 {   // Centrality Selection
3104    if(!fIsHeavyIon)return kTRUE;
3105
3106    if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
3107    else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
3108
3109    Double_t centrality=GetCentrality(event);
3110    if(centrality<0)return kFALSE;
3111
3112    Int_t centralityC=0;
3113    if (fModCentralityClass == 0){
3114       centralityC= Int_t(centrality/10);
3115       if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3116          return kTRUE;
3117       else return kFALSE;
3118    }
3119    else if (fModCentralityClass ==1){
3120       centralityC= Int_t(centrality);
3121       if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3122          return kTRUE;
3123       } else return kFALSE;
3124    }
3125    else if (fModCentralityClass ==2){
3126       centralityC= Int_t(centrality);
3127       if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3128          return kTRUE;
3129       else return kFALSE;
3130    }
3131
3132    Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks();
3133    Int_t PrimaryTracks10[10][2] =
3134       {
3135          {9999,9999}, //  0
3136          {1210,2150}, // 10
3137          { 817,1435}, // 20
3138          { 536, 930}, // 30
3139          { 337, 570}, // 40
3140          { 197, 327}, // 50
3141          { 106, 173}, // 60
3142          {  51,  81}, // 70
3143          {  21,  34}, // 80
3144          {   0,   0}  // 90
3145       };
3146    Int_t PrimaryTracks5a[10][2] =
3147       {
3148          {9999,9999}, // 0
3149          {1485,2640}, // 5
3150          {1210,2150}, // 10
3151          { 995,1760}, // 15
3152          { 817,1435}, // 20
3153          { 666,1160}, // 25
3154          { 536, 930}, // 30
3155          { 428, 731}, // 35
3156          { 337, 570}, // 40
3157          { 260, 436}  // 45
3158       };
3159    Int_t PrimaryTracks5b[10][2] =
3160       {
3161          { 260, 436}, // 45
3162          { 197, 327}, // 50
3163          { 147, 239}, // 55
3164          { 106, 173}, // 60
3165          {  75, 120}, // 65
3166          {  51,  81}, // 70
3167          {  34,  53}, // 75
3168          {  21,  34}, // 80
3169          {  13,  19}, // 85
3170          {   0,   0}  // 90
3171       };
3172
3173    Int_t column = -1;
3174    if(event->IsA()==AliESDEvent::Class()) column = 0;
3175    if(event->IsA()==AliAODEvent::Class()) column = 1;
3176
3177    if (fModCentralityClass == 3){
3178       if(fMCEvent){
3179          if(nprimaryTracks > PrimaryTracks10[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks10[fCentralityMin][column])
3180             return kTRUE;
3181          else return kFALSE;
3182       }
3183       else{
3184          centralityC= Int_t(centrality/10);
3185          if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3186             return kTRUE;
3187          else return kFALSE;
3188       }
3189    }
3190    else if (fModCentralityClass ==4){
3191       if(fMCEvent){
3192          if(nprimaryTracks > PrimaryTracks5a[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5a[fCentralityMin][column])
3193             return kTRUE;
3194          else return kFALSE;
3195       }
3196       else{
3197          centralityC= Int_t(centrality);
3198          if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3199             return kTRUE;
3200          } else return kFALSE;
3201       }
3202    }
3203    else if (fModCentralityClass ==5){
3204       if(fMCEvent){
3205          if(nprimaryTracks > PrimaryTracks5b[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5b[fCentralityMin][column])
3206             return kTRUE;
3207          else return kFALSE;
3208       }
3209       else{
3210          centralityC= Int_t(centrality);
3211          if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3212             return kTRUE;
3213          else return kFALSE;
3214       }
3215    }
3216
3217    return kFALSE;
3218 }
3219 ///________________________________________________________________________
3220 Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
3221    // Cut on z position of primary vertex
3222    Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
3223
3224    if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
3225
3226    if (fIsHeavyIon == 2){
3227      if(fUtils->IsFirstEventInChunk(event)) return kFALSE;
3228      if(!fUtils->IsVertexSelected2013pA(event)) return kFALSE;
3229      if(fUtils->IsPileUpEvent(event)) return kFALSE;
3230    }
3231
3232    return kTRUE;
3233 }
3234 ///________________________________________________________________________
3235
3236 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
3237    // returns number of contributors to the vertex
3238
3239    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
3240    if(fESDEvent){
3241       if (fESDEvent->GetPrimaryVertex() != NULL){
3242          if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
3243 //     cout << "accepted global" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertex()->GetNContributors() << endl;
3244             return fESDEvent->GetPrimaryVertex()->GetNContributors();
3245          }
3246       }
3247
3248       if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
3249          if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3250 //     cout << "accepted SPD" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertexSPD()->GetNContributors() << endl;
3251             return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
3252          }  else {
3253             AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
3254 //            cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3255             return 0;
3256          }
3257       }
3258    }
3259
3260    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
3261    if(fAODEvent){
3262       if (fAODEvent->GetPrimaryVertex() != NULL){
3263          if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
3264             return fAODEvent->GetPrimaryVertex()->GetNContributors();
3265          }
3266       }
3267       if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
3268          if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3269             return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
3270          } else {
3271             AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
3272             return 0;
3273          }
3274       }
3275    }
3276   // cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3277    return 0;
3278 }
3279
3280 ///________________________________________________________________________
3281
3282 Bool_t AliConversionCuts::IsTriggerSelected(AliVEvent *fInputEvent)
3283 {
3284
3285    AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
3286
3287    UInt_t isSelected = AliVEvent::kAny;
3288    if (fInputHandler==NULL) return kFALSE;
3289    if( fInputHandler->GetEventSelection() || fInputEvent->IsA()==AliAODEvent::Class()) {
3290       if (!fTriggerSelectedManually){
3291          if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
3292          else {
3293             if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
3294                else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
3295                else fOfflineTriggerMask = AliVEvent::kMB;
3296          }
3297       }
3298       // Get the actual offline trigger mask for the event and AND it with the
3299       // requested mask. If no mask requested select by default the event.
3300 //       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
3301 //       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
3302
3303       if (fOfflineTriggerMask)
3304          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
3305    }
3306    fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
3307
3308    // Fill Histogram
3309    if(hTriggerClass){
3310       if (fIsSDDFired) hTriggerClass->Fill(33);
3311       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
3312       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
3313       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
3314       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
3315       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
3316       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
3317       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
3318       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
3319       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
3320       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
3321       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
3322       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
3323       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
3324       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
3325       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
3326       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
3327       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
3328       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
3329       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
3330       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
3331       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
3332       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
3333       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
3334       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
3335       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
3336       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
3337       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
3338       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
3339       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
3340       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
3341       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
3342       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
3343       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
3344       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
3345       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
3346       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
3347       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClass->Fill(28);
3348       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(29);
3349       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(30);
3350       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(31);
3351       if (!fInputHandler->IsEventSelected()) hTriggerClass->Fill(34);
3352    }
3353
3354    if(hTriggerClassSelected && isSelected){
3355       if (!fIsSDDFired) hTriggerClassSelected->Fill(33);
3356       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClassSelected->Fill(0);
3357       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClassSelected->Fill(1);
3358       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClassSelected->Fill(2);
3359       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClassSelected->Fill(3);
3360       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClassSelected->Fill(4);
3361       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClassSelected->Fill(5);
3362       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClassSelected->Fill(6);
3363       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClassSelected->Fill(6);
3364       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClassSelected->Fill(7);
3365       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClassSelected->Fill(7);
3366       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClassSelected->Fill(8);
3367       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClassSelected->Fill(8);
3368       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClassSelected->Fill(9);
3369       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClassSelected->Fill(9);
3370       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClassSelected->Fill(10);
3371       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClassSelected->Fill(10);
3372       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClassSelected->Fill(11);
3373       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClassSelected->Fill(12);
3374       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClassSelected->Fill(13);
3375       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClassSelected->Fill(13);
3376       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClassSelected->Fill(13);
3377       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClassSelected->Fill(14);
3378       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClassSelected->Fill(15);
3379       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClassSelected->Fill(16);
3380       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClassSelected->Fill(17);
3381       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClassSelected->Fill(18);
3382       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClassSelected->Fill(19);
3383       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClassSelected->Fill(20);
3384       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClassSelected->Fill(20);
3385       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClassSelected->Fill(21);
3386       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClassSelected->Fill(22);
3387       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClassSelected->Fill(23);
3388       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClassSelected->Fill(24);
3389       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClassSelected->Fill(25);
3390       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClassSelected->Fill(26);
3391       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClassSelected->Fill(27);
3392       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClassSelected->Fill(28);
3393       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClassSelected->Fill(29);
3394       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClassSelected->Fill(30);
3395       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClassSelected->Fill(31);
3396    }
3397
3398    if(!isSelected)return kFALSE;
3399
3400    return kTRUE;
3401
3402 }
3403
3404 ///________________________________________________________________________
3405 Int_t AliConversionCuts::GetFirstTPCRow(Double_t radius){
3406    // Get first TPC row
3407    Int_t firstTPCRow = 0;
3408    Double_t radiusI = 84.8;
3409    Double_t radiusO = 134.6;
3410    Double_t radiusOB = 198.;
3411    Double_t rSizeI = 0.75;
3412    Double_t rSizeO = 1.;
3413    Double_t rSizeOB = 1.5;
3414    Int_t nClsI = 63;
3415    Int_t nClsIO = 127;
3416
3417    if(radius <= radiusI){
3418       return firstTPCRow;
3419    }
3420    if(radius>radiusI && radius<=radiusO){
3421       firstTPCRow = (Int_t)((radius-radiusI)/rSizeI);
3422    }
3423    if(radius>radiusO && radius<=radiusOB){
3424       firstTPCRow = (Int_t)(nClsI+(radius-radiusO)/rSizeO);
3425    }
3426
3427    if(radius>radiusOB){
3428       firstTPCRow =(Int_t)(nClsIO+(radius-radiusOB)/rSizeOB);
3429    }
3430
3431    return firstTPCRow;
3432 }
3433
3434 Bool_t AliConversionCuts::CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const {
3435    ///Check if passes cosine of pointing angle cut
3436    if(GetCosineOfPointingAngle(photon, event) < (TMath::Cos(fCosPAngleCut))){
3437       return kFALSE;
3438    }
3439    return kTRUE;
3440 }
3441
3442 Double_t AliConversionCuts::GetCosineOfPointingAngle( const AliConversionPhotonBase * photon, AliVEvent * event) const{
3443    // calculates the pointing angle of the recalculated V0
3444
3445    Double_t momV0[3] = {0,0,0};
3446    if(event->IsA()==AliESDEvent::Class()){
3447       AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(event);
3448       if(!esdEvent) return -999;
3449       AliESDv0 *v0 = esdEvent->GetV0(photon->GetV0Index());
3450       if(!v0) return -999;
3451       v0->GetPxPyPz(momV0[0],momV0[1],momV0[2]);
3452    }
3453    if(event->IsA()==AliAODEvent::Class()){
3454       momV0[0] = photon->GetPx();
3455       momV0[1] = photon->GetPy();
3456       momV0[2] = photon->GetPz();
3457    }
3458
3459    //Double_t momV0[3] = { photon->GetPx(), photon->GetPy(), photon->GetPz() }; //momentum of the V0
3460    Double_t PosV0[3] = { photon->GetConversionX() - event->GetPrimaryVertex()->GetX(),
3461                          photon->GetConversionY() - event->GetPrimaryVertex()->GetY(),
3462                          photon->GetConversionZ() - event->GetPrimaryVertex()->GetZ() }; //Recalculated V0 Position vector
3463
3464    Double_t momV02 = momV0[0]*momV0[0] + momV0[1]*momV0[1] + momV0[2]*momV0[2];
3465    Double_t PosV02 = PosV0[0]*PosV0[0] + PosV0[1]*PosV0[1] + PosV0[2]*PosV0[2];
3466
3467
3468    Double_t cosinePointingAngle = -999;
3469    if(momV02*PosV02 > 0.0)
3470       cosinePointingAngle = (PosV0[0]*momV0[0] +  PosV0[1]*momV0[1] + PosV0[2]*momV0[2] ) / TMath::Sqrt(momV02 * PosV02);
3471
3472    return cosinePointingAngle;
3473 }
3474
3475 ///________________________________________________________________________
3476 Bool_t AliConversionCuts::PsiPairCut(const AliConversionPhotonBase * photon, Double_t deltaPhi) const {
3477
3478 //    cout << fDo2DPsiPair << "\t" << fPsiPairCut << "\t" << fPsiPairDeltaPhiCut << endl;
3479    
3480    if (fDo2DPsiPair){
3481       
3482       if ( (deltaPhi > 0  &&  deltaPhi < fPsiPairDeltaPhiCut) &&
3483         TMath::Abs(photon->GetPsiPair()) < ( fPsiPairCut - fPsiPairCut/fPsiPairDeltaPhiCut * deltaPhi ) ) return kTRUE;
3484       else return kFALSE;
3485    } else {
3486       if(abs(photon->GetPsiPair()) > fPsiPairCut){
3487          return kFALSE;}
3488       else{return kTRUE;}
3489    } 
3490 }
3491
3492 ///________________________________________________________________________
3493 TString AliConversionCuts::GetCutNumber(){
3494    // returns TString with current cut number
3495    TString a(kNCuts);
3496    for(Int_t ii=0;ii<kNCuts;ii++){
3497       a.Append(Form("%d",fCuts[ii]));
3498    }
3499    return a;
3500 }
3501
3502 ///________________________________________________________________________
3503 void AliConversionCuts::FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0){
3504
3505    Int_t posLabel = photon->GetTrackLabelPositive();
3506    Int_t negLabel = photon->GetTrackLabelNegative();
3507
3508    fElectronLabelArray[nV0*2] = posLabel;
3509    fElectronLabelArray[(nV0*2)+1] = negLabel;
3510 }
3511 ///________________________________________________________________________
3512 Bool_t AliConversionCuts::RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s){
3513
3514    Int_t posLabel = photon->GetTrackLabelPositive();
3515    Int_t negLabel = photon->GetTrackLabelNegative();
3516
3517    for(Int_t i = 0; i<nV0s*2;i++){
3518       if(i==nV0*2)     continue;
3519       if(i==(nV0*2)+1) continue;
3520       if(fElectronLabelArray[i] == posLabel){
3521          return kFALSE;}
3522       if(fElectronLabelArray[i] == negLabel){
3523          return kFALSE;}
3524    }
3525
3526    return kTRUE;
3527 }
3528 ///________________________________________________________________________
3529 Bool_t AliConversionCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0){
3530
3531
3532    Double_t posX = photon->GetConversionX();
3533    Double_t posY = photon->GetConversionY();
3534    Double_t posZ = photon->GetConversionZ();
3535
3536    for(Int_t i = 0;i<photons->GetEntries();i++){
3537       if(nV0 == i) continue;
3538       AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
3539       Double_t posCompX = photonComp->GetConversionX();
3540       Double_t posCompY = photonComp->GetConversionY();
3541       Double_t posCompZ = photonComp->GetConversionZ();
3542
3543       Double_t dist = pow((posX - posCompX),2)+pow((posY - posCompY),2)+pow((posZ - posCompZ),2);
3544
3545       if(dist < fminV0Dist*fminV0Dist){
3546          if(photon->GetChi2perNDF() < photonComp->GetChi2perNDF()) return kTRUE;
3547          else {
3548             return kFALSE;}
3549       }
3550
3551    }
3552    return kTRUE;
3553 }
3554 ///________________________________________________________________________
3555 void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent){
3556
3557
3558
3559    if(fNotRejectedStart){
3560       delete[] fNotRejectedStart;
3561       fNotRejectedStart = NULL;
3562    }
3563    if(fNotRejectedEnd){
3564       delete[] fNotRejectedEnd;
3565       fNotRejectedEnd = NULL;
3566    }
3567    if(fGeneratorNames){
3568       delete[] fGeneratorNames;
3569       fGeneratorNames = NULL;
3570    }
3571
3572    if(rejection == 0) return; // No Rejection
3573
3574    AliGenCocktailEventHeader *cHeader = 0x0;
3575    AliAODMCHeader *cHeaderAOD = 0x0;
3576    Bool_t headerFound = kFALSE;
3577
3578    if(MCEvent->IsA()==AliMCEvent::Class()){
3579       cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3580       if(cHeader) headerFound = kTRUE;
3581    }
3582    if(MCEvent->IsA()==AliAODEvent::Class()){ // MCEvent is a AODEvent in case of AOD
3583       cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
3584       if(cHeaderAOD) headerFound = kTRUE;
3585    }
3586
3587    if(headerFound){
3588       TList *genHeaders = 0x0;
3589       if(cHeader) genHeaders = cHeader->GetHeaders();
3590       if(cHeaderAOD){
3591          genHeaders = cHeaderAOD->GetCocktailHeaders();
3592          if(genHeaders->GetEntries()==1){
3593             SetRejectExtraSignalsCut(0);
3594             return;
3595          }
3596       }
3597       AliGenEventHeader* gh = 0;
3598       fnHeaders = 0;
3599       if(rejection == 1 || rejection == 3) fnHeaders = 1; // MinBiasHeader
3600       if(rejection == 2){ // TList of Headers Names
3601          for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3602             gh = (AliGenEventHeader*)genHeaders->At(i);
3603             TString GeneratorName = gh->GetName();
3604             for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3605                TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3606                if(GeneratorName.CompareTo(GeneratorInList) == 0){
3607                   fnHeaders++;
3608                   continue;
3609                }
3610             }
3611          }
3612       }
3613
3614       fNotRejectedStart = new Int_t[fnHeaders];
3615       fNotRejectedEnd = new Int_t[fnHeaders];
3616       fGeneratorNames = new TString[fnHeaders];
3617
3618       if(rejection == 1 || rejection == 3){
3619          fNotRejectedStart[0] = 0;
3620          fNotRejectedEnd[0] = ((AliGenEventHeader*)genHeaders->At(0))->NProduced()-1;
3621          fGeneratorNames[0] = ((AliGenEventHeader*)genHeaders->At(0))->GetName();
3622          return;
3623       }
3624
3625       Int_t firstindex = 0;
3626       Int_t lastindex =  -1;
3627       Int_t nummer = 0;
3628       for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3629          gh = (AliGenEventHeader*)genHeaders->At(i);
3630          TString GeneratorName = gh->GetName();
3631          lastindex = lastindex + gh->NProduced();
3632          for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3633             TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3634             if(GeneratorName.CompareTo(GeneratorInList) == 0){
3635                fNotRejectedStart[nummer] = firstindex;
3636                fNotRejectedEnd[nummer] = lastindex;
3637                fGeneratorNames[nummer] = GeneratorName;
3638                //cout << "Number of particles produced for: " << i << "\t" << GeneratorName.Data() << "\t" << lastindex-firstindex+1 << endl;
3639                nummer++;
3640                continue;
3641             }
3642          }
3643          firstindex = firstindex + gh->NProduced();
3644       }
3645    } else { // No Cocktail Header Found
3646       fNotRejectedStart = new Int_t[1];
3647       fNotRejectedEnd = new Int_t[1];
3648
3649       fnHeaders = 1;
3650       fNotRejectedStart[0] = 0;
3651       fNotRejectedEnd[0] = static_cast<AliMCEvent*>(MCEvent)->Stack()->GetNprimary()-1;
3652       fGeneratorNames = new TString[1];
3653       fGeneratorNames[0] = "NoCocktailGeneratorFound";
3654
3655       AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3656       if (mcHeaderPythia) fGeneratorNames[0] = "NoCocktailGeneratorFound_Pythia";
3657       AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3658       if (mcHeaderPhojet) fGeneratorNames[0] = "NoCocktailGeneratorFound_Phojet";
3659       AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3660       if (mcHeaderHijing) fGeneratorNames[0] = "NoCocktailGeneratorFound_Hijing";
3661
3662       SetRejectExtraSignalsCut(0);
3663    }
3664
3665 }
3666 //_________________________________________________________________________
3667 Int_t AliConversionCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
3668
3669    // Not Accepted == kFALSE == 0
3670    //     Accepted ==  kTRUE == 1
3671    //  FirstHeader ==  kTRUE == 3
3672    if(index < 0) return 0; // No Particle
3673
3674    Int_t accepted = 0;
3675    if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
3676       if( index >= MCStack->GetNprimary()){ // Secondary Particle
3677          if( ((TParticle*)MCStack->Particle(index))->GetMother(0) < 0) return 1; // Secondary Particle without Mother??
3678          return IsParticleFromBGEvent(((TParticle*)MCStack->Particle(index))->GetMother(0),MCStack,InputEvent);
3679       }
3680       for(Int_t i = 0;i<fnHeaders;i++){
3681          if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
3682             accepted = 1;
3683             if(i == 0) accepted = 2; // MB Header
3684          }
3685       }
3686    }
3687    else if(InputEvent->IsA()==AliAODEvent::Class()){
3688       TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3689       AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
3690       if(!aodMCParticle) return 1; // Photon Without a Mother ? --> Accepted
3691       if(!aodMCParticle->IsPrimary()){
3692          if( aodMCParticle->GetMother() < 0) return 1;// Secondary Particle without Mother??
3693          return IsParticleFromBGEvent(aodMCParticle->GetMother(),MCStack,InputEvent);
3694       }
3695       index = abs(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index))->GetLabel());
3696       for(Int_t i = 0;i<fnHeaders;i++){
3697          if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
3698             accepted = 1;
3699             if(i == 0) accepted = 2; // MB Header
3700          }
3701       }
3702    }
3703
3704    return accepted;
3705 }
3706 //_________________________________________________________________________
3707 Int_t AliConversionCuts::IsEventAcceptedByConversionCut(AliConversionCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Bool_t isHeavyIon){
3708
3709    if ( !IsTriggerSelected(InputEvent) )
3710       return 3;
3711
3712    if(isHeavyIon && !(IsCentralitySelected(InputEvent,MCEvent)))
3713       return 1; // Check Centrality --> Not Accepted => eventQuality = 1
3714
3715    if(!isHeavyIon && GetIsFromPileup()){
3716       if(InputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
3717
3718          return 6; // Check Pileup --> Not Accepted => eventQuality = 6
3719       }
3720    }
3721
3722    Bool_t hasV0And = ReaderCuts->HasV0AND();
3723    Bool_t isSDDFired = ReaderCuts->IsSDDFired();
3724    if( (IsSpecialTrigger() == 2 || IsSpecialTrigger() == 3) && !isSDDFired && !MCEvent)
3725       return 7; // With SDD requested but no fired
3726
3727    if( (IsSpecialTrigger() == 1 || IsSpecialTrigger() == 3) && !hasV0And)
3728       return 8; // V0AND requested but no fired
3729
3730
3731    return 0;
3732 }
3733 //_________________________________________________________________________
3734 Float_t AliConversionCuts::GetWeightForMeson(TString period, Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
3735    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"))) return 1.;
3736
3737    Int_t kCaseGen = 0;
3738    for (Int_t i = 0; i < fnHeaders; i++){
3739       if (index >= fNotRejectedStart[i] && index < fNotRejectedEnd[i]+1){
3740          if (fGeneratorNames[i].CompareTo("Pythia") == 0){
3741             kCaseGen = 1;
3742          } else if (fGeneratorNames[i].CompareTo("DPMJET") == 0){
3743             kCaseGen = 2;
3744          } else if (fGeneratorNames[i].CompareTo("HIJING") == 0 ||
3745                     fGeneratorNames[i].CompareTo("Hijing") == 0 ||
3746                     fGeneratorNames[i].Contains("hijing")){
3747             kCaseGen = 3;
3748          } else if (fGeneratorNames[i].CompareTo("BOX") == 0){
3749              kCaseGen = 4;
3750          } else if (fGeneratorNames[i].CompareTo("PARAM") == 0){
3751             kCaseGen = 5;
3752          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound") == 0){
3753             kCaseGen = 6;
3754          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Pythia") == 0){
3755             kCaseGen = 1;
3756          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Phojet") == 0){
3757             kCaseGen = 2;
3758          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Hijing") == 0){
3759             kCaseGen = 3;
3760          }
3761          if (period.Contains("LHC13d2")){
3762             kCaseGen = 3;
3763          }
3764       }
3765    }
3766    if (kCaseGen == 0) return 1;
3767
3768
3769    Double_t mesonPt = 0;
3770    Double_t mesonMass = 0;
3771    Int_t PDGCode = 0;
3772    if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
3773       mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
3774       mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
3775       PDGCode = ((TParticle*)MCStack->Particle(index))->GetPdgCode();
3776    }
3777    else if(InputEvent->IsA()==AliAODEvent::Class()){
3778       TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3779       AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
3780       mesonPt = aodMCParticle->Pt();
3781       mesonMass = aodMCParticle->GetCalcMass();
3782       PDGCode = aodMCParticle->GetPdgCode();
3783    }
3784
3785    Float_t functionResultMC = 1.;
3786    if (kCaseGen == 1){ // Pythia 6
3787       Float_t dNdyMC = 2.1462;
3788       Float_t nMC = 7.06055;
3789       Float_t tMC = 0.12533;
3790       if ( PDGCode ==  111){
3791          dNdyMC = 2.1462;
3792          nMC = 7.06055;
3793          tMC = 0.12533;
3794       } else if ( PDGCode ==  221){
3795          dNdyMC = 0.2357;
3796          nMC = 5.9105;
3797          tMC = 0.1525;
3798       }
3799       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);
3800    } else if (kCaseGen == 2){ // Phojet
3801       Float_t dNdyMC = 2.35978;
3802       Float_t nMC = 6.81795;
3803       Float_t tMC = 0.11492;
3804       if ( PDGCode ==  111){
3805          dNdyMC = 2.35978;
3806          nMC = 6.81795;
3807          tMC = 0.11492;
3808       } else if ( PDGCode ==  221){
3809          dNdyMC = 0.3690;
3810          nMC = 5.55809;
3811          tMC = 0.13387;
3812       }
3813       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);
3814    } else if (kCaseGen == 4){ // BOX generators pp
3815 //       functionResultMC = 1./sqrt(1.-mesonMass*mesonMass/((mesonMass*mesonMass+mesonPt*mesonPt)*cosh(mesonY)*cosh(mesonY)));
3816       Float_t a = 0.23437;
3817       Float_t b = 5.6661;
3818       Float_t c = -1430.5863;
3819       Float_t d = -0.6966624;
3820       Float_t e = 252.3742;
3821       if ( PDGCode ==  111){
3822          a = 0.23437;
3823          b = 5.6661;
3824          c = -1430.5863;
3825          d = -0.6966624;
3826          e = 252.3742;
3827       } else if ( PDGCode ==  221){
3828          a = 0.10399;
3829          b = 4.35311;
3830          c = -12.17723;
3831          d = -0.01172;
3832          e =1.85140;
3833       }
3834       functionResultMC = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
3835 //       cout << functionResultMC << endl;
3836    } else if (kCaseGen == 3 ){ // HIJING
3837       if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0){
3838          functionResultMC = hReweightMCHistPi0->Interpolate(mesonPt);
3839       }
3840       if ( PDGCode ==  221 && fDoReweightHistoMCEta && hReweightMCHistEta!= 0x0){
3841          functionResultMC = hReweightMCHistEta->Interpolate(mesonPt);
3842       }
3843       if ( PDGCode ==  310 && fDoReweightHistoMCK0s && hReweightMCHistK0s!= 0x0){
3844          functionResultMC = hReweightMCHistK0s->Interpolate(mesonPt);
3845       }
3846    }
3847
3848    Float_t functionResultData = 1;
3849    if (kCaseGen == 1 || kCaseGen == 2 || kCaseGen == 4 ){
3850       Float_t dNdyData = 2.2328;
3851       Float_t nData = 7.1473;
3852       Float_t tData = 0.1346;
3853       if ( PDGCode ==  111){
3854          dNdyData = 2.2328;
3855          nData = 7.1473;
3856          tData = 0.1346;
3857       } else if ( PDGCode ==  221){
3858          dNdyData = 0.38992; //be careful this fit is not optimal, eta in data still has problems
3859          nData = 5.72778;
3860          tData = 0.13835;
3861       }
3862       functionResultData = dNdyData / ( 2 * TMath::Pi())*(nData-1.)*(nData-2.) / (nData*tData*(nData*tData+mesonMass*(nData-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nData*tData), -nData);
3863 //       cout << functionResultData << endl;
3864    } else {
3865       if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && fFitDataPi0!= 0x0){
3866          functionResultData = fFitDataPi0->Eval(mesonPt);
3867       }
3868       if ( PDGCode ==  221 && fDoReweightHistoMCEta && fFitDataEta!= 0x0){
3869          functionResultData = fFitDataEta->Eval(mesonPt);
3870       }
3871       if ( PDGCode ==  310 && fDoReweightHistoMCK0s && fFitDataK0s!= 0x0){
3872          functionResultData = fFitDataK0s->Eval(mesonPt);
3873       }
3874
3875    }
3876
3877    Double_t weight = 1;
3878    if (PDGCode ==  111 || PDGCode ==  221){
3879       if (functionResultData != 0. && functionResultMC != 0. && isfinite(functionResultData) && isfinite(functionResultMC)){
3880          weight = functionResultData/functionResultMC;
3881          if ( kCaseGen == 3){
3882             if (!(fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0 && PDGCode ==  111)){
3883                weight = 1.;
3884             }
3885          }
3886          if (!isfinite(functionResultData)) weight = 1.;
3887          if (!isfinite(weight)) weight = 1.;
3888       }
3889    } else if (PDGCode ==  310 && functionResultMC != 0 && isfinite(functionResultMC)){
3890         weight = functionResultMC;
3891    }
3892
3893 //    if (fModCentralityClass == 0 && fCentralityMin == 4 && fCentralityMax == 6 && PDGCode ==  111){
3894 //        cout << period.Data() << "\t" << kCaseGen << "\t" <<fModCentralityClass<< "\t" <<fCentralityMin<< "\t" <<fCentralityMax << "\t" << mesonPt << "\t" <<mesonMass<< "\t"<<functionResultData << "\t"<< functionResultMC << "\t" << weight <<endl;
3895 //    }
3896    return weight;
3897 }
3898 ///________________________________________________________________________
3899 AliConversionCuts* AliConversionCuts::GetStandardCuts2010PbPb(){
3900     //Create and return standard 2010 PbPb cuts
3901     AliConversionCuts *cuts=new AliConversionCuts("StandardCuts2010PbPb","StandardCuts2010PbPb");
3902     if(!cuts->InitializeCutsFromCutString("100000204209297002322000000")){
3903    cout<<"Warning: Initialization of Standardcuts2010PbPb failed"<<endl;}
3904     return cuts;
3905 }
3906
3907 ///________________________________________________________________________
3908 AliConversionCuts* AliConversionCuts::GetStandardCuts2010pp(){
3909     //Create and return standard 2010 PbPb cuts
3910     AliConversionCuts *cuts=new AliConversionCuts("StandardCuts2010pp","StandardCuts2010pp");
3911     if(!cuts->InitializeCutsFromCutString("000001100209366300380000000")){
3912    cout<<"Warning: Initialization of Standardcuts2010pp failed"<<endl;}
3913     return cuts;
3914 }
3915 ///________________________________________________________________________
3916 void AliConversionCuts::GetCorrectEtaShiftFromPeriod(TString periodName){
3917
3918    if(periodName.CompareTo("LHC12g") == 0 || //pilot run 2012
3919       periodName.CompareTo("LHC13b") == 0 || //mainly minimum bias
3920       periodName.CompareTo("LHC13c") == 0 || //mainly minimum bias
3921       periodName.CompareTo("LHC13d") == 0 || //mainly triggered
3922       periodName.CompareTo("LHC13e") == 0 || //mainly triggered
3923       periodName.CompareTo("LHC13c3") == 0 || //MC Starlight, anchor LHC13d+e
3924       periodName.CompareTo("LHC13c2") == 0 || //MC Starlight, coherent J/Psi, UPC muon anchor LHC13d+e
3925       periodName.CompareTo("LHC13b4") == 0 || //MC Pythia 6 (Jet-Jet), anchor LHC13b
3926       periodName.CompareTo("LHC13b2_fix_1") == 0 || //MC DPMJET, anchr LHC13b+c
3927       periodName.CompareTo("LHC13b2_efix_p1") == 0 || //MC DPMJET, anchr LHC13b+c
3928       periodName.CompareTo("LHC13b2_efix_p2") == 0 || //MC DPMJET, anchr LHC13b+c
3929       periodName.CompareTo("LHC13b2_efix_p3") == 0 || //MC DPMJET, anchr LHC13b+c
3930       periodName.CompareTo("LHC13b2_efix_p4") == 0 || //MC DPMJET, anchr LHC13b+c
3931       periodName.CompareTo("LHC13b3") == 0 || //MC HIJING, weighted to number of events per run, anchor LHC13b
3932       periodName.CompareTo("LHC13b2") == 0 ||  // MC DPMJET, wrong energy, anchor LHC13b
3933       periodName.CompareTo("LHC13b2_plus") == 0 || // MC DPMJET, weighted to number event per run, anchor LHC13b
3934       periodName.CompareTo("LHC13c1_bis") == 0 || // MC AMPT fast generation, pT hardbin, anchor ?
3935       periodName.CompareTo("LHC13c1") == 0 || // MC AMPT fast generation, anchor ?
3936       periodName.CompareTo("LHC13b1") == 0 || // MC DPMJET, fragments, with fixed label 0, anchor LHC12g
3937       periodName.CompareTo("LHC12g4b_fix") == 0 || // MC DPMJET, with fixed label 0, anchor LHC12g
3938       periodName.CompareTo("LHC12g1_fix") == 0 || // MC ?, with fixed label 0, anchor LHC12g
3939       periodName.CompareTo("LHC12g4c") == 0 || // MC DPMJET, shifted vertex runs, anchor LHC12g
3940       periodName.CompareTo("LHC12h6") == 0 || // MC muon cocktail, anchor LHC12g
3941       periodName.CompareTo("LHC12g4b") == 0 || // MC DPMJET 3rd iteration, anchor LHC12g
3942       periodName.CompareTo("LHC12g4a") == 0 || // MC DPMJET improved, anchor LHC12g
3943       periodName.CompareTo("LHC12g4") == 0 || // MC DPMJET, anchor LHC12g
3944       periodName.CompareTo("LHC12g5") == 0 || // MC PHOJET, anchor LHC12g
3945       periodName.CompareTo("LHC12g2") == 0 || // MC Starlight background, anchor LHC12g
3946       periodName.CompareTo("LHC12g1") == 0 ) // MC ?, anchor LHC12g
3947       {
3948          printf(" Gamma Conversion Cuts %s :: pPb Run doing Eta Shift of %f \n\n",(GetCutNumber()).Data(),-0.465);
3949          SetEtaShift(-0.465);
3950       }
3951    else if(periodName.CompareTo("LHC13f") == 0 ||
3952            periodName.CompareTo("LHC13c6b") == 0 ||// MC Jpsi -> mumu, anchor LHC13f