768bf211059c23901a69076ce880354c202a6946
[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:  // 1.2  // 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.8
2232       fEtaCut     = 0.8;
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       fEtaCut     = 0.3;
2257       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2258       fEtaCutMin     = -0.1;
2259       fLineCutZRSlopeMin = 0.;
2260       break;
2261    // case 8: // 0.1 - 0.8
2262    //    fEtaCut     = 0.9;
2263    //    fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2264    //    fEtaCutMin     = 0.1;
2265    //    fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2266    //    break;
2267    case 8: // 0.4
2268       fEtaCut     = 0.4;
2269       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2270       fEtaCutMin     = -0.1;
2271       fLineCutZRSlopeMin = 0.;
2272       break;
2273    case 9: // 10
2274       fEtaCut     = 10;
2275       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2276       fEtaCutMin     = -0.1;
2277       fLineCutZRSlopeMin = 0.;
2278       break;
2279    default:
2280       AliError(Form(" EtaCut not defined %d",etaCut));
2281       return kFALSE;
2282    }
2283    return kTRUE;
2284 }
2285 ///________________________________________________________________________
2286 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
2287    // Set Cut
2288    switch(RCut){
2289    case 0:
2290       fMinR=0;
2291       fMaxR = 180.;
2292       break;
2293    case 1:
2294       fMinR=2.8;
2295       fMaxR = 180.;
2296       break;
2297    case 2:
2298       fMinR=5.;
2299       fMaxR = 180.;
2300       break;
2301    case 3:
2302       fMaxR = 70.;
2303       fMinR = 10.;
2304       break;
2305    case 4:
2306       fMaxR = 70.;
2307       fMinR = 5.;
2308       break;
2309       // High purity cuts for PbPb (remove first layers of material)
2310    case 5:
2311       fMaxR = 180.;
2312       fMinR = 10.;
2313       break;
2314    case 6:
2315       fMaxR = 180.;
2316       fMinR = 20.;
2317       break;
2318    case 7:
2319       fMaxR = 180.;
2320       fMinR = 26.;
2321       break;
2322    case 8:
2323       fMaxR = 180.;
2324       fMinR = 12.5;
2325       break;
2326    case 9:
2327       fMaxR = 180.;
2328       fMinR = 7.5;
2329       break;
2330
2331    default:
2332       AliError("RCut not defined");
2333       return kFALSE;
2334    }
2335    return kTRUE;
2336 }
2337 ///________________________________________________________________________
2338 Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
2339 {   // Set Cut
2340    switch(singlePtCut){
2341    case 0: // 0.050 GeV
2342       fSinglePtCut = 0.050;
2343       break;
2344    case 1:  // 0.100 GeV
2345       fSinglePtCut = 0.100;
2346       break;
2347    case 2:  // 0.150 GeV
2348       fSinglePtCut = 0.150;
2349       break;
2350    case 3:  // 0.200 GeV
2351       fSinglePtCut = 0.200;
2352       break;
2353    case 4:  // 0.075 GeV
2354       fSinglePtCut = 0.075;
2355       break;
2356    case 5:  // 0.125 GeV
2357       fSinglePtCut = 0.125;
2358       break;
2359    case 6:  // 0.04 GeV
2360       fSinglePtCut = 0.040;
2361       break;
2362    case 7:  // 0.0 GeV
2363       fSinglePtCut = 0.0;
2364       break;
2365    default:
2366       AliError(Form("singlePtCut not defined %d",singlePtCut));
2367       return kFALSE;
2368    }
2369    return kTRUE;
2370 }
2371 ///________________________________________________________________________
2372 Bool_t AliConversionCuts::SetTPCClusterCut(Int_t clsTPCCut)
2373 {   // Set Cut
2374    switch(clsTPCCut){
2375    case 0: // 0
2376       fMinClsTPC= 0.;
2377       break;
2378    case 1:  // 60
2379       fMinClsTPC= 60.;
2380       break;
2381    case 2:  // 80
2382       fMinClsTPC= 80.;
2383       break;
2384    case 3:  // 100
2385       fMinClsTPC= 100.;
2386       break;
2387    case 4:  // 95% of findable clusters
2388       fMinClsTPCToF= 0.95;
2389       fUseCorrectedTPCClsInfo=1;
2390       break;
2391    case 5:  // 0% of findable clusters
2392       fMinClsTPCToF= 0.0;
2393       fUseCorrectedTPCClsInfo=1;
2394       break;
2395    case 6:  // 70% of findable clusters
2396       fMinClsTPCToF= 0.7;
2397       fUseCorrectedTPCClsInfo=1;
2398       break;
2399    case 7:  // 0% of findable clusters
2400       fMinClsTPCToF= 0.35;
2401       fUseCorrectedTPCClsInfo=0;
2402       break;
2403    case 8:
2404       fMinClsTPCToF= 0.35;
2405       fUseCorrectedTPCClsInfo=1;
2406       break;
2407    case 9:
2408       fMinClsTPCToF= 0.6;
2409       fUseCorrectedTPCClsInfo=1;
2410       break;
2411    default:
2412       AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
2413       return kFALSE;
2414    }
2415    return kTRUE;
2416 }
2417 ///________________________________________________________________________
2418 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
2419 {   // Set Cut
2420    switch(ededxSigmaCut){
2421    case 0: // -10,10
2422       fPIDnSigmaBelowElectronLine=-10;
2423       fPIDnSigmaAboveElectronLine=10;
2424       break;
2425    case 1: // -5,5
2426       fPIDnSigmaBelowElectronLine=-5;
2427       fPIDnSigmaAboveElectronLine=5;
2428       break;
2429    case 2: // -3,5
2430       fPIDnSigmaBelowElectronLine=-3;
2431       fPIDnSigmaAboveElectronLine=5;
2432       break;
2433    case 3: // -4,5
2434       fPIDnSigmaBelowElectronLine=-4;
2435       fPIDnSigmaAboveElectronLine=5;
2436       break;
2437    case 4: // -6,7
2438       fPIDnSigmaBelowElectronLine=-6;
2439       fPIDnSigmaAboveElectronLine=7;
2440       break;
2441    case 5: // -4,4
2442       fPIDnSigmaBelowElectronLine=-4;
2443       fPIDnSigmaAboveElectronLine=4;
2444       break;
2445    case 6: // -2.5,4
2446       fPIDnSigmaBelowElectronLine=-2.5;
2447       fPIDnSigmaAboveElectronLine=4;
2448       break;
2449    case 7: // -2,3.5
2450       fPIDnSigmaBelowElectronLine=-2;
2451       fPIDnSigmaAboveElectronLine=3.5;
2452       break;
2453    default:
2454       AliError("TPCdEdxCutElectronLine not defined");
2455       return kFALSE;
2456
2457    }
2458    return kTRUE;
2459 }
2460 ///________________________________________________________________________
2461 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
2462 {   // Set Cut
2463
2464    switch(pidedxSigmaCut){
2465    case 0:  // -10
2466       fPIDnSigmaAbovePionLine=-10;
2467       fPIDnSigmaAbovePionLineHighPt=-10;
2468       break;
2469    case 1:   // 0
2470       fPIDnSigmaAbovePionLine=0;
2471       fPIDnSigmaAbovePionLineHighPt=-10;
2472       break;
2473    case 2:  // 1
2474       fPIDnSigmaAbovePionLine=1;
2475       fPIDnSigmaAbovePionLineHighPt=-10;
2476       break;
2477    case 3:  // 1
2478       fPIDnSigmaAbovePionLine=2.5;
2479       fPIDnSigmaAbovePionLineHighPt=-10;
2480       break;
2481    case 4:  // 1
2482       fPIDnSigmaAbovePionLine=0.5;
2483       fPIDnSigmaAbovePionLineHighPt=-10;
2484       break;
2485    case 5:  // 1
2486       fPIDnSigmaAbovePionLine=2.;
2487       fPIDnSigmaAbovePionLineHighPt=-10;
2488       break;
2489    case 6:  // 1
2490       fPIDnSigmaAbovePionLine=2.;
2491       fPIDnSigmaAbovePionLineHighPt=0.5;
2492       break;
2493    case 7:  // 1
2494       fPIDnSigmaAbovePionLine=3.5;
2495       fPIDnSigmaAbovePionLineHighPt=-10;
2496       break;
2497    case 8:  // 1
2498       fPIDnSigmaAbovePionLine=2.;
2499       fPIDnSigmaAbovePionLineHighPt=1.;
2500       break;
2501    case 9:
2502       fPIDnSigmaAbovePionLine=3.0; // We need a bit less tight cut on dE/dx
2503       fPIDnSigmaAbovePionLineHighPt=-10;
2504       break;
2505    default:
2506       AliError(Form("Warning: pidedxSigmaCut not defined %d",pidedxSigmaCut));
2507       return kFALSE;
2508    }
2509    return kTRUE;
2510 }
2511 ///________________________________________________________________________
2512 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
2513 {   // Set Cut
2514    switch(piMomdedxSigmaCut){
2515    case 0:  // 0.5 GeV
2516       fPIDMinPnSigmaAbovePionLine=0.5;
2517       break;
2518    case 1:  // 1. GeV
2519       fPIDMinPnSigmaAbovePionLine=1.;
2520       break;
2521    case 2:  // 1.5 GeV
2522       fPIDMinPnSigmaAbovePionLine=1.5;
2523       break;
2524    case 3:  // 20.0 GeV
2525       fPIDMinPnSigmaAbovePionLine=20.;
2526       break;
2527    case 4:  // 50.0 GeV
2528       fPIDMinPnSigmaAbovePionLine=50.;
2529       break;
2530    case 5:  // 0.3 GeV
2531       fPIDMinPnSigmaAbovePionLine=0.3;
2532       break;
2533    case 6:  // 0.25 GeV
2534       fPIDMinPnSigmaAbovePionLine=0.25;
2535       break;
2536    case 7:  // 0.4 GeV
2537       fPIDMinPnSigmaAbovePionLine=0.4;
2538       break;
2539    case 8:  // 0.2 GeV
2540       fPIDMinPnSigmaAbovePionLine=0.2;
2541       break;
2542    default:
2543       AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
2544       return kFALSE;
2545    }
2546    return kTRUE;
2547 }
2548 ///________________________________________________________________________
2549 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
2550 {   // Set Cut
2551    switch(piMaxMomdedxSigmaCut){
2552    case 0:  // 100. GeV
2553       fPIDMaxPnSigmaAbovePionLine=100.;
2554       break;
2555    case 1:  // 5. GeV
2556       fPIDMaxPnSigmaAbovePionLine=5.;
2557       break;
2558    case 2:  // 4. GeV
2559       fPIDMaxPnSigmaAbovePionLine=4.;
2560       break;
2561    case 3:  // 3.5 GeV
2562       fPIDMaxPnSigmaAbovePionLine=3.5;
2563       break;
2564    case 4:  // 3. GeV
2565       fPIDMaxPnSigmaAbovePionLine=3.;
2566       break;
2567    case 5:  // 7. GeV
2568       fPIDMaxPnSigmaAbovePionLine=7.;
2569       break;
2570    default:
2571       AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
2572       return kFALSE;
2573    }
2574    return kTRUE;
2575 }
2576 ///________________________________________________________________________
2577 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
2578 {   // Set Cut
2579    switch(LowPRejectionSigmaCut){
2580    case 0:  //
2581       fPIDnSigmaAtLowPAroundKaonLine=0;
2582       fPIDnSigmaAtLowPAroundProtonLine=0;
2583       fPIDnSigmaAtLowPAroundPionLine=0;
2584       fDoKaonRejectionLowP = kFALSE;
2585       fDoProtonRejectionLowP = kFALSE;
2586       fDoPionRejectionLowP = kFALSE;
2587       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2588       break;
2589    case 1:  //
2590       fPIDnSigmaAtLowPAroundKaonLine=0.5;
2591       fPIDnSigmaAtLowPAroundProtonLine=0.5;
2592       fPIDnSigmaAtLowPAroundPionLine=0.5;
2593       fDoKaonRejectionLowP = kTRUE;
2594       fDoProtonRejectionLowP = kTRUE;
2595       fDoPionRejectionLowP = kTRUE;
2596       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2597       break;
2598    case 2:  //
2599       fPIDnSigmaAtLowPAroundKaonLine=1;
2600       fPIDnSigmaAtLowPAroundProtonLine=1;
2601       fPIDnSigmaAtLowPAroundPionLine=1;
2602       fDoKaonRejectionLowP = kTRUE;
2603       fDoProtonRejectionLowP = kTRUE;
2604       fDoPionRejectionLowP = kTRUE;
2605       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2606       break;
2607    case 3:  //
2608       fPIDnSigmaAtLowPAroundKaonLine=2.;
2609       fPIDnSigmaAtLowPAroundProtonLine=2.;
2610       fPIDnSigmaAtLowPAroundPionLine=2.;
2611       fDoKaonRejectionLowP = kTRUE;
2612       fDoProtonRejectionLowP = kTRUE;
2613       fDoPionRejectionLowP = kTRUE;
2614       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2615       break;
2616    case 4:  //
2617       fPIDnSigmaAtLowPAroundKaonLine=0.;
2618       fPIDnSigmaAtLowPAroundProtonLine=0.;
2619       fPIDnSigmaAtLowPAroundPionLine=1;
2620       fDoKaonRejectionLowP = kFALSE;
2621       fDoProtonRejectionLowP = kFALSE;
2622       fDoPionRejectionLowP = kTRUE;
2623       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2624       break;
2625    case 5:  //
2626       fPIDnSigmaAtLowPAroundKaonLine=0.;
2627       fPIDnSigmaAtLowPAroundProtonLine=0.;
2628       fPIDnSigmaAtLowPAroundPionLine=1.5;
2629       fDoKaonRejectionLowP = kFALSE;
2630       fDoProtonRejectionLowP = kFALSE;
2631       fDoPionRejectionLowP = kTRUE;
2632       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2633       break;
2634    case 6:  //
2635       fPIDnSigmaAtLowPAroundKaonLine=0.;
2636       fPIDnSigmaAtLowPAroundProtonLine=0.;
2637       fPIDnSigmaAtLowPAroundPionLine=2.;
2638       fDoKaonRejectionLowP = kFALSE;
2639       fDoProtonRejectionLowP = kFALSE;
2640       fDoPionRejectionLowP = kTRUE;
2641       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2642       break;
2643    case 7:  //
2644       fPIDnSigmaAtLowPAroundKaonLine=0.;
2645       fPIDnSigmaAtLowPAroundProtonLine=0.;
2646       fPIDnSigmaAtLowPAroundPionLine=0.5;
2647       fDoKaonRejectionLowP = kFALSE;
2648       fDoProtonRejectionLowP = kFALSE;
2649       fDoPionRejectionLowP = kTRUE;
2650       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2651       break;
2652    default:
2653       AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
2654       return kFALSE;
2655    }
2656    return kTRUE;
2657 }
2658 ///________________________________________________________________________
2659 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
2660    // Set Cut
2661    switch(TOFelectronPID){
2662    case 0: // no cut
2663       fUseTOFpid = kFALSE;
2664       fTofPIDnSigmaBelowElectronLine=-100;
2665       fTofPIDnSigmaAboveElectronLine=100;
2666       break;
2667    case 1: // -7,7
2668       fUseTOFpid = kTRUE;
2669       fTofPIDnSigmaBelowElectronLine=-7;
2670       fTofPIDnSigmaAboveElectronLine=7;
2671       break;
2672    case 2: // -5,5
2673       fUseTOFpid = kTRUE;
2674       fTofPIDnSigmaBelowElectronLine=-5;
2675       fTofPIDnSigmaAboveElectronLine=5;
2676       break;
2677    case 3: // -3,5
2678       fUseTOFpid = kTRUE;
2679       fTofPIDnSigmaBelowElectronLine=-3;
2680       fTofPIDnSigmaAboveElectronLine=5;
2681       break;
2682    case 4: // -2,3
2683       fUseTOFpid = kTRUE;
2684       fTofPIDnSigmaBelowElectronLine=-2;
2685       fTofPIDnSigmaAboveElectronLine=3;
2686       break;
2687    case 5: // -3,3
2688       fUseTOFpid = kTRUE;
2689       fTofPIDnSigmaBelowElectronLine=-3;
2690       fTofPIDnSigmaAboveElectronLine=3;
2691       break;
2692    default:
2693       AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
2694       return kFALSE;
2695    }
2696    return kTRUE;
2697 }
2698 ///________________________________________________________________________
2699 Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
2700 {   // Set Cut
2701    switch(QtMaxCut){
2702    case 0: //
2703       fQtMax=1.;
2704       fDoQtGammaSelection=kFALSE;
2705       fDoHighPtQtGammaSelection=kFALSE;
2706       fHighPtQtMax=100.;
2707       fPtBorderForQt=100.;
2708       break;
2709    case 1:
2710       fQtMax=0.1;
2711       fDoHighPtQtGammaSelection=kFALSE;
2712       fHighPtQtMax=100.;
2713       fPtBorderForQt=100.;
2714       break;
2715    case 2:
2716       fQtMax=0.07;
2717       fDoHighPtQtGammaSelection=kFALSE;
2718       fHighPtQtMax=100.;
2719       fPtBorderForQt=100.;
2720       break;
2721    case 3:
2722       fQtMax=0.05;
2723       fDoHighPtQtGammaSelection=kFALSE;
2724       fHighPtQtMax=100.;
2725       fPtBorderForQt=100.;
2726       break;
2727    case 4:
2728       fQtMax=0.03;
2729       fDoHighPtQtGammaSelection=kFALSE;
2730       fHighPtQtMax=100.;
2731       fPtBorderForQt=100.;
2732       break;
2733    case 5:
2734       fQtMax=0.02;
2735       fDoHighPtQtGammaSelection=kFALSE;
2736       fHighPtQtMax=100.;
2737       fPtBorderForQt=100.;
2738       break;
2739    case 6:
2740       fQtMax=0.02;
2741       fDoHighPtQtGammaSelection=kTRUE;
2742       fHighPtQtMax=0.06;
2743       fPtBorderForQt=2.5;
2744       break;
2745    case 7:
2746       fQtMax=0.15;
2747       fDoHighPtQtGammaSelection=kFALSE;
2748       fHighPtQtMax=100.;
2749       fPtBorderForQt=100.;
2750       break;
2751    default:
2752       AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
2753       return kFALSE;
2754    }
2755    return kTRUE;
2756 }
2757 ///________________________________________________________________________
2758 Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
2759 {   // Set Cut
2760
2761    switch(chi2GammaCut){
2762    case 0: // 100
2763       fChi2CutConversion = 100.;
2764       break;
2765    case 1:  // 50
2766       fChi2CutConversion = 50.;
2767       break;
2768    case 2:  // 30
2769       fChi2CutConversion = 30.;
2770       break;
2771    case 3:
2772       fChi2CutConversion = 200.;
2773       break;
2774    case 4:
2775       fChi2CutConversion = 500.;
2776       break;
2777    case 5:
2778       fChi2CutConversion = 100000.;
2779       break;
2780    case 6:
2781       fChi2CutConversion = 5.;
2782       break;
2783    case 7:
2784       fChi2CutConversion = 10.;
2785       break;
2786    case 8:
2787       fChi2CutConversion = 20.;
2788       break;
2789    case 9:
2790       fChi2CutConversion = 15.;
2791       break;
2792    default:
2793       AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
2794       return kFALSE;
2795    }
2796    return kTRUE;
2797 }
2798 ///________________________________________________________________________
2799 Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
2800
2801    switch(psiCut) {
2802    case 0:
2803       fPsiPairCut = 10000; //
2804       break;
2805    case 1:
2806       fPsiPairCut = 0.1; //
2807       break;
2808    case 2:
2809       fPsiPairCut = 0.05; // Standard
2810       break;
2811    case 3:
2812       fPsiPairCut = 0.035; //
2813       break;
2814    case 4:
2815       fPsiPairCut = 0.2; //
2816       break;   
2817    case 5:
2818       fPsiPairCut = 0.1; //
2819       fPsiPairDeltaPhiCut = 1;
2820       fDo2DPsiPair = kTRUE;
2821       break;
2822    case 6:
2823       fPsiPairCut = 0.05; //
2824       fPsiPairDeltaPhiCut = 1;
2825       fDo2DPsiPair = kTRUE;
2826       break;
2827    case 7:
2828       fPsiPairCut = 0.035; //
2829       fPsiPairDeltaPhiCut = 1;
2830       fDo2DPsiPair = kTRUE;
2831       break;
2832    case 8:
2833       fPsiPairCut = 0.2; //
2834       fPsiPairDeltaPhiCut = 1;
2835       fDo2DPsiPair = kTRUE; //
2836       break;
2837    case 9:
2838       fPsiPairCut = 0.5; //
2839       break;
2840    default:
2841       AliError(Form("PsiPairCut not defined %d",psiCut));
2842       return kFALSE;
2843    }
2844
2845    return kTRUE;
2846 }
2847 ///________________________________________________________________________
2848 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
2849    // Set Cut
2850    switch(doPhotonAsymmetryCut){
2851    case 0:
2852       fDoPhotonAsymmetryCut=0;
2853       fMinPPhotonAsymmetryCut=100.;
2854       fMinPhotonAsymmetry=0.;
2855       break;
2856    case 1:
2857       fDoPhotonAsymmetryCut=1;
2858       fMinPPhotonAsymmetryCut=3.5;
2859       fMinPhotonAsymmetry=0.04;
2860       break;
2861    case 2:
2862       fDoPhotonAsymmetryCut=1;
2863       fMinPPhotonAsymmetryCut=3.5;
2864       fMinPhotonAsymmetry=0.06;
2865       break;
2866    case 3:
2867       fDoPhotonAsymmetryCut=1;
2868       fMinPPhotonAsymmetryCut=0.0;
2869       fMinPhotonAsymmetry=0.05;
2870       break; 
2871    default:
2872       AliError(Form("PhotonAsymmetryCut not defined %d",doPhotonAsymmetryCut));
2873       return kFALSE;
2874    }
2875    fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
2876    return kTRUE;
2877 }
2878 ///________________________________________________________________________
2879 Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
2880
2881    switch(cosCut){
2882    case 0:
2883       fCosPAngleCut = TMath::Pi(); // -1
2884       break;
2885    case 1:
2886       fCosPAngleCut = 0.1; // 0.99500
2887       break;
2888    case 2:
2889       fCosPAngleCut = 0.05; // 0.99875
2890       break;
2891    case 3:
2892       fCosPAngleCut = 0.025; // 0.99969
2893       break;
2894    case 4:
2895       fCosPAngleCut = 0.01; // 0.99995
2896       break;
2897    case 5:
2898       fCosPAngleCut = 0.2; // 0.98007
2899       break;
2900    case 6:
2901       fCosPAngleCut = 0.5; // 0.87758
2902       break;
2903    case 7:
2904       fCosPAngleCut = 0.075; // 0.73169
2905       break;
2906    default:
2907       AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
2908       return kFALSE;
2909    }
2910
2911    return kTRUE;
2912 }
2913 ///________________________________________________________________________
2914 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
2915
2916    switch(sharedElec){
2917    case 0:
2918       fDoSharedElecCut = kFALSE;
2919       break;
2920    case 1:
2921       fDoSharedElecCut = kTRUE;
2922       break;
2923    default:
2924       AliError(Form("Shared Electron Cut not defined %d",sharedElec));
2925       return kFALSE;
2926    }
2927
2928    return kTRUE;
2929 }
2930 ///________________________________________________________________________
2931 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
2932
2933    switch(toClose){
2934    case 0:
2935       fDoToCloseV0sCut = kFALSE;
2936       fminV0Dist = 250;
2937       break;
2938    case 1:
2939       fDoToCloseV0sCut = kTRUE;
2940       fminV0Dist = 1;
2941       break;
2942    case 2:
2943       fDoToCloseV0sCut = kTRUE;
2944       fminV0Dist = 2;
2945       break;
2946    case 3:
2947       fDoToCloseV0sCut = kTRUE;
2948       fminV0Dist = 3;
2949       break;
2950    default:
2951       AliError(Form("Shared Electron Cut not defined %d",toClose));
2952       return kFALSE;
2953    }
2954    return kTRUE;
2955 }
2956 ///________________________________________________________________________
2957 Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
2958 {   // Set Cut
2959    switch(TRDElectronCut){
2960    case 0:
2961       fDoTRDPID=kFALSE;
2962       break;
2963    case 1:
2964       fDoTRDPID=kTRUE;
2965       fPIDTRDEfficiency=0.1;
2966       break;
2967    case 8:
2968       fDoTRDPID=kTRUE;
2969       fPIDTRDEfficiency=0.8;
2970       break;
2971    case 9:
2972       fDoTRDPID=kTRUE;
2973       fPIDTRDEfficiency=0.9;
2974       break;
2975    default:
2976       AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
2977       return kFALSE;
2978    }
2979
2980    return kTRUE;
2981 }
2982
2983 ///________________________________________________________________________
2984 Bool_t AliConversionCuts::SetDCAZPhotonPrimVtxCut(Int_t DCAZPhotonPrimVtx){
2985    // Set Cut
2986    switch(DCAZPhotonPrimVtx){
2987    case 0:  //
2988       fDCAZPrimVtxCut   = 1000;
2989       break;
2990    case 1:  //
2991       fDCAZPrimVtxCut   = 10;
2992       break;
2993    case 2:  //
2994       fDCAZPrimVtxCut   = 5;
2995       break;
2996    case 3:  //
2997       fDCAZPrimVtxCut   = 4;
2998       break;
2999    case 4:  //
3000       fDCAZPrimVtxCut   = 3;
3001       break;
3002    case 5:  //
3003       fDCAZPrimVtxCut   = 2.5;
3004       break;
3005    case 6:  //
3006       fDCAZPrimVtxCut   = 2;
3007       break;
3008    case 7:  //
3009       fDCAZPrimVtxCut   = 1.5;
3010       break;
3011    case 8:  //
3012       fDCAZPrimVtxCut   = 1;
3013       break;
3014    case 9:  //
3015       fDCAZPrimVtxCut   = 0.5;
3016       break;
3017    default:
3018       cout<<"Warning: DCAZPhotonPrimVtx not defined "<<DCAZPhotonPrimVtx<<endl;
3019       return kFALSE;
3020    }
3021    return kTRUE;
3022 }
3023
3024 ///________________________________________________________________________
3025 Bool_t AliConversionCuts::SetDCARPhotonPrimVtxCut(Int_t DCARPhotonPrimVtx){
3026    // Set Cut
3027    switch(DCARPhotonPrimVtx){
3028    case 0:  //
3029       fDCARPrimVtxCut   = 1000;
3030       break;
3031    case 1:  //
3032       fDCARPrimVtxCut   = 10;
3033       break;
3034    case 2:  //
3035       fDCARPrimVtxCut   = 5;
3036       break;
3037    case 3:  //
3038       fDCARPrimVtxCut   = 4;
3039       break;
3040    case 4:  //
3041       fDCARPrimVtxCut   = 3;
3042       break;
3043    case 5:  //
3044       fDCARPrimVtxCut   = 2.5;
3045       break;
3046    case 6:  //
3047       fDCARPrimVtxCut   = 2;
3048       break;
3049    case 7:  //
3050       fDCARPrimVtxCut   = 1.5;
3051       break;
3052    case 8:  //
3053       fDCARPrimVtxCut   = 1;
3054       break;
3055    case 9:  //
3056       fDCARPrimVtxCut   = 0.5;
3057       break;
3058    default:
3059       cout<<"Warning: DCARPhotonPrimVtx not defined "<<DCARPhotonPrimVtx<<endl;
3060       return kFALSE;
3061    }
3062    return kTRUE;
3063 }
3064
3065
3066 //-------------------------------------------------------------
3067 Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
3068 {   // Get Event Centrality
3069
3070    AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
3071    if(esdEvent){
3072       AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
3073
3074       if(fDetectorCentrality==0){
3075          if (fIsHeavyIon==2){
3076             return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
3077          } else{
3078             return fESDCentrality->GetCentralityPercentile("V0M"); // default
3079          }
3080       }
3081       if(fDetectorCentrality==1){
3082          return fESDCentrality->GetCentralityPercentile("CL1");
3083       }
3084    }
3085
3086    AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
3087    if(aodEvent){
3088       if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
3089    }
3090
3091    return -1;
3092 }
3093 //-------------------------------------------------------------
3094 Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
3095 {   // Centrality Selection
3096    if(!fIsHeavyIon)return kTRUE;
3097
3098    if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
3099    else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
3100
3101    Double_t centrality=GetCentrality(event);
3102    if(centrality<0)return kFALSE;
3103
3104    Int_t centralityC=0;
3105    if (fModCentralityClass == 0){
3106       centralityC= Int_t(centrality/10);
3107       if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3108          return kTRUE;
3109       else return kFALSE;
3110    }
3111    else if (fModCentralityClass ==1){
3112       centralityC= Int_t(centrality);
3113       if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3114          return kTRUE;
3115       } else return kFALSE;
3116    }
3117    else if (fModCentralityClass ==2){
3118       centralityC= Int_t(centrality);
3119       if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3120          return kTRUE;
3121       else return kFALSE;
3122    }
3123
3124    Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks();
3125    Int_t PrimaryTracks10[10][2] =
3126       {
3127          {9999,9999}, //  0
3128          {1210,2150}, // 10
3129          { 817,1435}, // 20
3130          { 536, 930}, // 30
3131          { 337, 570}, // 40
3132          { 197, 327}, // 50
3133          { 106, 173}, // 60
3134          {  51,  81}, // 70
3135          {  21,  34}, // 80
3136          {   0,   0}  // 90
3137       };
3138    Int_t PrimaryTracks5a[10][2] =
3139       {
3140          {9999,9999}, // 0
3141          {1485,2640}, // 5
3142          {1210,2150}, // 10
3143          { 995,1760}, // 15
3144          { 817,1435}, // 20
3145          { 666,1160}, // 25
3146          { 536, 930}, // 30
3147          { 428, 731}, // 35
3148          { 337, 570}, // 40
3149          { 260, 436}  // 45
3150       };
3151    Int_t PrimaryTracks5b[10][2] =
3152       {
3153          { 260, 436}, // 45
3154          { 197, 327}, // 50
3155          { 147, 239}, // 55
3156          { 106, 173}, // 60
3157          {  75, 120}, // 65
3158          {  51,  81}, // 70
3159          {  34,  53}, // 75
3160          {  21,  34}, // 80
3161          {  13,  19}, // 85
3162          {   0,   0}  // 90
3163       };
3164
3165    Int_t column = -1;
3166    if(event->IsA()==AliESDEvent::Class()) column = 0;
3167    if(event->IsA()==AliAODEvent::Class()) column = 1;
3168
3169    if (fModCentralityClass == 3){
3170       if(fMCEvent){
3171          if(nprimaryTracks > PrimaryTracks10[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks10[fCentralityMin][column])
3172             return kTRUE;
3173          else return kFALSE;
3174       }
3175       else{
3176          centralityC= Int_t(centrality/10);
3177          if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3178             return kTRUE;
3179          else return kFALSE;
3180       }
3181    }
3182    else if (fModCentralityClass ==4){
3183       if(fMCEvent){
3184          if(nprimaryTracks > PrimaryTracks5a[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5a[fCentralityMin][column])
3185             return kTRUE;
3186          else return kFALSE;
3187       }
3188       else{
3189          centralityC= Int_t(centrality);
3190          if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3191             return kTRUE;
3192          } else return kFALSE;
3193       }
3194    }
3195    else if (fModCentralityClass ==5){
3196       if(fMCEvent){
3197          if(nprimaryTracks > PrimaryTracks5b[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5b[fCentralityMin][column])
3198             return kTRUE;
3199          else return kFALSE;
3200       }
3201       else{
3202          centralityC= Int_t(centrality);
3203          if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3204             return kTRUE;
3205          else return kFALSE;
3206       }
3207    }
3208
3209    return kFALSE;
3210 }
3211 ///________________________________________________________________________
3212 Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
3213    // Cut on z position of primary vertex
3214    Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
3215
3216    if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
3217
3218    if (fIsHeavyIon == 2){
3219      if(fUtils->IsFirstEventInChunk(event)) return kFALSE;
3220      if(!fUtils->IsVertexSelected2013pA(event)) return kFALSE;
3221
3222    }
3223
3224    return kTRUE;
3225 }
3226 ///________________________________________________________________________
3227
3228 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
3229    // returns number of contributors to the vertex
3230
3231    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
3232    if(fESDEvent){
3233       if (fESDEvent->GetPrimaryVertex() != NULL){
3234          if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
3235 //     cout << "accepted global" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertex()->GetNContributors() << endl;
3236             return fESDEvent->GetPrimaryVertex()->GetNContributors();
3237          }
3238       }
3239
3240       if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
3241          if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3242 //     cout << "accepted SPD" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertexSPD()->GetNContributors() << endl;
3243             return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
3244          }  else {
3245             AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
3246 //            cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3247             return 0;
3248          }
3249       }
3250    }
3251
3252    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
3253    if(fAODEvent){
3254       if (fAODEvent->GetPrimaryVertex() != NULL){
3255          if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
3256             return fAODEvent->GetPrimaryVertex()->GetNContributors();
3257          }
3258       }
3259       if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
3260          if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3261             return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
3262          } else {
3263             AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
3264             return 0;
3265          }
3266       }
3267    }
3268   // cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3269    return 0;
3270 }
3271
3272 ///________________________________________________________________________
3273
3274 Bool_t AliConversionCuts::IsTriggerSelected(AliVEvent *fInputEvent)
3275 {
3276
3277    AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
3278
3279    UInt_t isSelected = AliVEvent::kAny;
3280    if (fInputHandler==NULL) return kFALSE;
3281    if( fInputHandler->GetEventSelection() || fInputEvent->IsA()==AliAODEvent::Class()) {
3282       if (!fTriggerSelectedManually){
3283          if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
3284          else {
3285             if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
3286                else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
3287                else fOfflineTriggerMask = AliVEvent::kMB;
3288          }
3289       }
3290       // Get the actual offline trigger mask for the event and AND it with the
3291       // requested mask. If no mask requested select by default the event.
3292 //       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
3293 //       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
3294
3295       if (fOfflineTriggerMask)
3296          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
3297    }
3298    fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
3299
3300    // Fill Histogram
3301    if(hTriggerClass){
3302       if (fIsSDDFired) hTriggerClass->Fill(33);
3303       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
3304       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
3305       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
3306       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
3307       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
3308       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
3309       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
3310       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
3311       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
3312       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
3313       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
3314       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
3315       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
3316       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
3317       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
3318       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
3319       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
3320       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
3321       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
3322       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
3323       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
3324       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
3325       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
3326       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
3327       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
3328       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
3329       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
3330       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
3331       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
3332       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
3333       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
3334       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
3335       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
3336       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
3337       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
3338       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
3339       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClass->Fill(28);
3340       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(29);
3341       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(30);
3342       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(31);
3343       if (!fInputHandler->IsEventSelected()) hTriggerClass->Fill(34);
3344    }
3345
3346    if(hTriggerClassSelected && isSelected){
3347       if (!fIsSDDFired) hTriggerClassSelected->Fill(33);
3348       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClassSelected->Fill(0);
3349       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClassSelected->Fill(1);
3350       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClassSelected->Fill(2);
3351       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClassSelected->Fill(3);
3352       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClassSelected->Fill(4);
3353       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClassSelected->Fill(5);
3354       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClassSelected->Fill(6);
3355       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClassSelected->Fill(6);
3356       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClassSelected->Fill(7);
3357       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClassSelected->Fill(7);
3358       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClassSelected->Fill(8);
3359       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClassSelected->Fill(8);
3360       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClassSelected->Fill(9);
3361       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClassSelected->Fill(9);
3362       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClassSelected->Fill(10);
3363       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClassSelected->Fill(10);
3364       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClassSelected->Fill(11);
3365       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClassSelected->Fill(12);
3366       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClassSelected->Fill(13);
3367       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClassSelected->Fill(13);
3368       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClassSelected->Fill(13);
3369       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClassSelected->Fill(14);
3370       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClassSelected->Fill(15);
3371       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClassSelected->Fill(16);
3372       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClassSelected->Fill(17);
3373       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClassSelected->Fill(18);
3374       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClassSelected->Fill(19);
3375       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClassSelected->Fill(20);
3376       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClassSelected->Fill(20);
3377       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClassSelected->Fill(21);
3378       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClassSelected->Fill(22);
3379       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClassSelected->Fill(23);
3380       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClassSelected->Fill(24);
3381       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClassSelected->Fill(25);
3382       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClassSelected->Fill(26);
3383       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClassSelected->Fill(27);
3384       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClassSelected->Fill(28);
3385       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClassSelected->Fill(29);
3386       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClassSelected->Fill(30);
3387       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClassSelected->Fill(31);
3388    }
3389
3390    if(!isSelected)return kFALSE;
3391
3392    return kTRUE;
3393
3394 }
3395
3396 ///________________________________________________________________________
3397 Int_t AliConversionCuts::GetFirstTPCRow(Double_t radius){
3398    // Get first TPC row
3399    Int_t firstTPCRow = 0;
3400    Double_t radiusI = 84.8;
3401    Double_t radiusO = 134.6;
3402    Double_t radiusOB = 198.;
3403    Double_t rSizeI = 0.75;
3404    Double_t rSizeO = 1.;
3405    Double_t rSizeOB = 1.5;
3406    Int_t nClsI = 63;
3407    Int_t nClsIO = 127;
3408
3409    if(radius <= radiusI){
3410       return firstTPCRow;
3411    }
3412    if(radius>radiusI && radius<=radiusO){
3413       firstTPCRow = (Int_t)((radius-radiusI)/rSizeI);
3414    }
3415    if(radius>radiusO && radius<=radiusOB){
3416       firstTPCRow = (Int_t)(nClsI+(radius-radiusO)/rSizeO);
3417    }
3418
3419    if(radius>radiusOB){
3420       firstTPCRow =(Int_t)(nClsIO+(radius-radiusOB)/rSizeOB);
3421    }
3422
3423    return firstTPCRow;
3424 }
3425
3426 Bool_t AliConversionCuts::CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const {
3427    ///Check if passes cosine of pointing angle cut
3428    if(GetCosineOfPointingAngle(photon, event) < (TMath::Cos(fCosPAngleCut))){
3429       return kFALSE;
3430    }
3431    return kTRUE;
3432 }
3433
3434 Double_t AliConversionCuts::GetCosineOfPointingAngle( const AliConversionPhotonBase * photon, AliVEvent * event) const{
3435    // calculates the pointing angle of the recalculated V0
3436
3437    Double_t momV0[3] = {0,0,0};
3438    if(event->IsA()==AliESDEvent::Class()){
3439       AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(event);
3440       if(!esdEvent) return -999;
3441       AliESDv0 *v0 = esdEvent->GetV0(photon->GetV0Index());