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