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