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