- changes in ConversionCuts in order to make cut on photon quality possible on AODs...
[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            UChar_t photonQuality = 0;
1113             AliAODEvent * aodEvent = dynamic_cast<AliAODEvent*>(event);
1114                 if(aodEvent) {
1115                         photonQuality = DeterminePhotonQualityAOD(photonAOD, event);
1116                 } else {
1117                         photonQuality = photonAOD->GetPhotonQuality();
1118                 }       
1119                 if (fDoPhotonQualitySelectionCut && photonQuality != fPhotonQualityCut){
1120                         if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //11
1121                         return kFALSE;
1122                 }       
1123    } 
1124    cutIndex++; //12
1125    if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //11
1126
1127    // Histos after Cuts
1128    if(hInvMassafter)hInvMassafter->Fill(photon->GetMass());
1129    if(hArmenterosafter)hArmenterosafter->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
1130    if(hPsiPairDeltaPhiafter)hPsiPairDeltaPhiafter->Fill(deltaPhi,photon->GetPsiPair());
1131    return kTRUE;
1132
1133 }
1134
1135 ///________________________________________________________________________
1136 Bool_t AliConversionCuts::CorrectedTPCClusterCut(AliConversionPhotonBase *photon, AliVEvent * event)
1137 {   //Cut on corrected TPC Cluster Info
1138
1139    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1140    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1141
1142    if(!negTrack||!posTrack)return kFALSE;
1143
1144    Double_t negclsToF=0;
1145
1146    if (!fUseCorrectedTPCClsInfo ){
1147       if(negTrack->GetTPCNclsF()!=0){
1148          negclsToF = (Double_t)negTrack->GetNcls(1)/(Double_t)negTrack->GetTPCNclsF();}// Ncluster/Nfindablecluster
1149    }
1150    else {
1151       negclsToF = negTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1152    }
1153
1154    Double_t posclsToF = 0.;
1155    if (!fUseCorrectedTPCClsInfo ){
1156       if(posTrack->GetTPCNclsF()!=0){
1157          posclsToF = (Double_t)posTrack->GetNcls(1)/(Double_t)posTrack->GetTPCNclsF();
1158       }
1159    }else{
1160       posclsToF = posTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
1161    }
1162
1163    if( negclsToF < fMinClsTPCToF || posclsToF < fMinClsTPCToF ){
1164       return kFALSE;
1165    }
1166
1167    return kTRUE;
1168 }
1169
1170 ///________________________________________________________________________
1171 Bool_t AliConversionCuts::PhotonIsSelected(AliConversionPhotonBase *photon, AliVEvent * event)
1172 {
1173    //Selection of Reconstructed Photons
1174
1175    FillPhotonCutIndex(kPhotonIn);
1176
1177    if(event->IsA()==AliESDEvent::Class()) {
1178      if(!SelectV0Finder( ( ((AliESDEvent*)event)->GetV0(photon->GetV0Index()))->GetOnFlyStatus() ) ){
1179          FillPhotonCutIndex(kOnFly);
1180          return kFALSE;
1181       }
1182    }
1183    // else if(event->IsA()==AliAODEvent::Class()) {
1184    //    if(!SelectV0Finder( ( ((AliAODEvent*)event)->GetV0(photon->GetV0Index())) ) ){
1185    //       FillPhotonCutIndex(kOnFly);
1186    //       return kFALSE;
1187    //    }
1188    // }
1189
1190    // Get Tracks
1191    AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
1192    AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
1193
1194    if(!negTrack || !posTrack) {
1195       FillPhotonCutIndex(kNoTracks);
1196       return kFALSE;
1197    }
1198    photon->DeterminePhotonQuality(negTrack,posTrack);
1199    // Track Cuts
1200    if(!TracksAreSelected(negTrack, posTrack)){
1201       FillPhotonCutIndex(kTrackCuts);
1202       return kFALSE;
1203    }
1204    if (hEtaDistV0s)hEtaDistV0s->Fill(photon->GetPhotonEta());
1205    // dEdx Cuts
1206    if(!dEdxCuts(negTrack) || !dEdxCuts(posTrack)) {
1207       FillPhotonCutIndex(kdEdxCuts);
1208       return kFALSE;
1209    }
1210    if (hEtaDistV0sAfterdEdxCuts)hEtaDistV0sAfterdEdxCuts->Fill(photon->GetPhotonEta());
1211    // Photon Cuts
1212    if(!PhotonCuts(photon,event)){
1213       FillPhotonCutIndex(kPhotonCuts);
1214       return kFALSE;
1215    }
1216
1217    // Photon passed cuts
1218    FillPhotonCutIndex(kPhotonOut);
1219    return kTRUE;
1220 }
1221
1222 ///________________________________________________________________________
1223 Bool_t AliConversionCuts::ArmenterosQtCut(AliConversionPhotonBase *photon)
1224 {   // Armenteros Qt Cut
1225    if(fDo2DQt){
1226       if ( !(TMath::Power(photon->GetArmenterosAlpha()/0.95,2)+TMath::Power(photon->GetArmenterosQt()/fQtMax,2) < 1) ){
1227          return kFALSE;
1228       }
1229    } else {
1230       if(photon->GetArmenterosQt()>fQtMax){
1231          return kFALSE;
1232       }
1233    }
1234    return kTRUE;
1235 }
1236
1237
1238 ///________________________________________________________________________
1239 Bool_t AliConversionCuts::AcceptanceCuts(AliConversionPhotonBase *photon) {
1240    // Exclude certain areas for photon reconstruction
1241
1242    Int_t cutIndex=0;
1243    if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1244    cutIndex++;
1245
1246    if(photon->GetConversionRadius()>fMaxR){ // cuts on distance from collision point
1247       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1248       return kFALSE;
1249    }
1250    cutIndex++;
1251
1252    if(photon->GetConversionRadius()<fMinR){ // cuts on distance from collision point
1253       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1254       return kFALSE;
1255    }
1256    cutIndex++;
1257
1258    if(photon->GetConversionRadius() <= ((abs(photon->GetConversionZ())*fLineCutZRSlope)-fLineCutZValue)){
1259       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1260       return kFALSE;
1261    }
1262    else if (fUseEtaMinCut &&  photon->GetConversionRadius() >= ((abs(photon->GetConversionZ())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
1263       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1264       return kFALSE;
1265    }
1266    cutIndex++;
1267
1268    if(abs(photon->GetConversionZ()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1269       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1270       return kFALSE;
1271    }
1272    cutIndex++;
1273
1274
1275    if( photon->GetPhotonEta() > (fEtaCut + fEtaShift)    || photon->GetPhotonEta() < (-fEtaCut + fEtaShift) ){
1276       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1277       return kFALSE;
1278    }
1279    if(fEtaCutMin>-0.1){
1280       if( photon->GetPhotonEta() < (fEtaCutMin + fEtaShift) && photon->GetPhotonEta() > (-fEtaCutMin + fEtaShift) ){
1281          if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1282          return kFALSE;
1283       }
1284    }
1285    cutIndex++;
1286
1287    if(photon->GetPhotonPt()<fPtCut){
1288       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1289       return kFALSE;
1290    }
1291    cutIndex++;
1292
1293    if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
1294
1295    return kTRUE;
1296 }
1297
1298
1299 ///________________________________________________________________________
1300 Bool_t AliConversionCuts::SpecificTrackCuts(AliAODTrack * negTrack, AliAODTrack * posTrack,Int_t &cutIndex) {
1301    // Track Cuts which require AOD/ESD specific implementation
1302
1303    if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
1304       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1305       return kFALSE;
1306    }
1307    cutIndex++;
1308
1309    AliAODVertex * NegVtxType=negTrack->GetProdVertex();
1310    AliAODVertex * PosVtxType=posTrack->GetProdVertex();
1311    if( (NegVtxType->GetType())==AliAODVertex::kKink || (PosVtxType->GetType())==AliAODVertex::kKink) {
1312       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1313       return kFALSE;
1314    }
1315    return kTRUE;
1316
1317 }
1318
1319
1320 ///________________________________________________________________________
1321 Bool_t AliConversionCuts::SpecificTrackCuts(AliESDtrack * negTrack, AliESDtrack * posTrack,Int_t &cutIndex) {
1322    // Track Cuts which require AOD/ESD specific implementation
1323
1324    if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
1325       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1326       return kFALSE;
1327    }
1328    cutIndex++;
1329
1330    if(negTrack->GetKinkIndex(0) > 0  || posTrack->GetKinkIndex(0) > 0 ) {
1331       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1332       return kFALSE;
1333    }
1334    return kTRUE;
1335 }
1336
1337
1338
1339 ///________________________________________________________________________
1340 Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * posTrack) {
1341    // Track Selection for Photon Reconstruction
1342
1343    Int_t cutIndex=0;
1344    if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1345    cutIndex++;
1346
1347    // avoid like sign
1348    if(negTrack->Charge() == posTrack->Charge()) {
1349       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1350       return kFALSE;
1351    }
1352    cutIndex++;
1353
1354    // Number of TPC Clusters
1355
1356
1357    if( negTrack->GetNcls(1) < fMinClsTPC || posTrack->GetNcls(1) < fMinClsTPC ) {
1358       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1359       return kFALSE;
1360    }
1361    cutIndex++;
1362
1363    // Acceptance
1364    if( posTrack->Eta() > (fEtaCut + fEtaShift) || posTrack->Eta() < (-fEtaCut + fEtaShift) ||
1365        negTrack->Eta() > (fEtaCut + fEtaShift) || negTrack->Eta() < (-fEtaCut + fEtaShift) ){
1366       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1367       return kFALSE;
1368    }
1369    if(fEtaCutMin>-0.1){
1370       if( (posTrack->Eta() < (fEtaCutMin + fEtaShift) && posTrack->Eta() > (-fEtaCutMin + fEtaShift)) ||
1371           (negTrack->Eta() < (fEtaCutMin + fEtaShift) && negTrack->Eta() > (-fEtaCutMin + fEtaShift)) ){
1372          if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1373          return kFALSE;
1374       }
1375    }
1376    cutIndex++;
1377
1378    // Single Pt Cut
1379    if( negTrack->Pt()< fSinglePtCut || posTrack->Pt()< fSinglePtCut){
1380       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1381       return kFALSE;
1382    }
1383    cutIndex++;
1384
1385    // AOD ESD specific cuts
1386    Bool_t passCuts = kTRUE;
1387
1388    if(negTrack->IsA()==AliAODTrack::Class()) {
1389       passCuts = passCuts * SpecificTrackCuts(static_cast<AliAODTrack*>(negTrack), static_cast<AliAODTrack*>(posTrack),cutIndex);
1390    } else {
1391       passCuts = passCuts * SpecificTrackCuts(static_cast<AliESDtrack*>(negTrack), static_cast<AliESDtrack*>(posTrack),cutIndex);
1392    }
1393
1394    if(!passCuts){
1395       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1396       return kFALSE;
1397    }
1398    cutIndex++;
1399
1400    if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1401
1402    return kTRUE;
1403
1404 }
1405
1406 ///________________________________________________________________________
1407 Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
1408    // Electron Identification Cuts for Photon reconstruction
1409    if(!fPIDResponse){InitPIDResponse();}// Try to reinitialize PID Response
1410    if(!fPIDResponse){AliError("No PID Response"); return kTRUE;}// if still missing fatal error
1411
1412    Int_t cutIndex=0;
1413    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1414    if(hTPCdEdxSigbefore)hTPCdEdxSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1415    if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
1416    cutIndex++;
1417
1418    if(fDodEdxSigmaCut == kTRUE){
1419       // TPC Electron Line
1420       if( fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaBelowElectronLine ||
1421           fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaAboveElectronLine){
1422
1423          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1424          return kFALSE;
1425       }
1426       cutIndex++;
1427
1428       // TPC Pion Line
1429       if( fCurrentTrack->P()>fPIDMinPnSigmaAbovePionLine && fCurrentTrack->P()<fPIDMaxPnSigmaAbovePionLine ){
1430          if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1431             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine&&
1432             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLine){
1433
1434             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1435             return kFALSE;
1436          }
1437       }
1438       cutIndex++;
1439
1440       // High Pt Pion rej
1441       if( fCurrentTrack->P()>fPIDMaxPnSigmaAbovePionLine ){
1442          if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1443             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine &&
1444             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineHighPt){
1445
1446             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1447             return kFALSE;
1448          }
1449       }
1450       cutIndex++;
1451    }
1452    else{cutIndex+=3;}
1453
1454    if(fDoKaonRejectionLowP == kTRUE){
1455       if(fCurrentTrack->P()<fPIDMinPKaonRejectionLowP ){
1456          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
1457
1458             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1459             return kFALSE;
1460          }
1461       }
1462    }
1463    cutIndex++;
1464    if(fDoProtonRejectionLowP == kTRUE){
1465       if( fCurrentTrack->P()<fPIDMinPProtonRejectionLowP ){
1466          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
1467
1468             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1469             return kFALSE;
1470          }
1471       }
1472    }
1473    cutIndex++;
1474
1475    if(fDoPionRejectionLowP == kTRUE){
1476       if( fCurrentTrack->P()<fPIDMinPPionRejectionLowP ){
1477          if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion))<fPIDnSigmaAtLowPAroundPionLine){
1478
1479             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1480             return kFALSE;
1481          }
1482       }
1483    }
1484    cutIndex++;
1485
1486
1487    // cout<<"Start"<<endl;
1488    // AliPIDResponse::EDetPidStatus status=fPIDResponse->CheckPIDStatus(AliPIDResponse::kTOF,fCurrentTrack);
1489
1490    // if( ( (status & AliVTrack::kTOFout) == AliVTrack::kTOFout ) && ( (status & AliVTrack::kTIME) == AliVTrack::kTIME ))
1491    //    {cout<<"TOF DA"<<endl;}
1492    // if(status == AliPIDResponse::kDetPidOk){
1493    //    Float_t probMis = fPIDResponse->GetTOFMismatchProbability(fCurrentTrack);
1494    //    cout<<"--> "<<probMis<<endl;
1495    //    if(probMis > 0.01){
1496
1497    //    }
1498    // }
1499
1500    if((fCurrentTrack->GetStatus() & AliESDtrack::kTOFpid) && !(fCurrentTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
1501       if(hTOFbefore){
1502          Double_t t0 = fPIDResponse->GetTOFResponse().GetStartTime(fCurrentTrack->P());
1503          Double_t  times[AliPID::kSPECIESC];
1504          fCurrentTrack->GetIntegratedTimes(times);
1505          Double_t TOFsignal = fCurrentTrack->GetTOFsignal();
1506          Double_t dT = TOFsignal - t0 - times[0];
1507          hTOFbefore->Fill(fCurrentTrack->P(),dT);
1508       }
1509       if(hTOFSigbefore) hTOFSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1510       if(fUseTOFpid){
1511          if(fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)>fTofPIDnSigmaAboveElectronLine ||
1512             fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)<fTofPIDnSigmaBelowElectronLine ){
1513             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1514             return kFALSE;
1515          }
1516       }
1517       if(hTOFSigafter)hTOFSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1518    }
1519    cutIndex++;
1520    // Apply TRD PID
1521    if(fDoTRDPID){
1522       if(!fPIDResponse->IdentifiedAsElectronTRD(fCurrentTrack,fPIDTRDEfficiency)){
1523          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1524          return kFALSE;
1525       }
1526    }
1527    cutIndex++;
1528
1529    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1530    if(hTPCdEdxSigafter)hTPCdEdxSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1531    if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
1532    
1533    return kTRUE;
1534 }
1535
1536 ///________________________________________________________________________
1537 Bool_t AliConversionCuts::AsymmetryCut(AliConversionPhotonBase * photon,AliVEvent *event) {
1538    // Cut on Energy Assymetry
1539
1540    for(Int_t ii=0;ii<2;ii++){
1541
1542       AliVTrack *track=GetTrack(event,photon->GetTrackLabel(ii));
1543
1544       if( track->P() > fMinPPhotonAsymmetryCut ){
1545          Double_t trackNegAsy=0;
1546          if (photon->GetPhotonP()!=0.){
1547             trackNegAsy= track->P()/photon->GetPhotonP();
1548          }
1549
1550          if( trackNegAsy<fMinPhotonAsymmetry ||trackNegAsy>(1.- fMinPhotonAsymmetry)){
1551             return kFALSE;
1552          }
1553       }
1554
1555    }
1556    return kTRUE;
1557 }
1558
1559 ///________________________________________________________________________
1560 AliVTrack *AliConversionCuts::GetTrack(AliVEvent * event, Int_t label){
1561    //Returns pointer to the track with given ESD label
1562    //(Important for AOD implementation, since Track array in AOD data is different
1563    //from ESD array, but ESD tracklabels are stored in AOD Tracks)
1564
1565    AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1566    if(esdEvent) {
1567       if(label > event->GetNumberOfTracks() ) return NULL;
1568       AliESDtrack * track = esdEvent->GetTrack(label);
1569       return track;
1570
1571    } else {
1572       AliVTrack * track = 0x0;
1573       if(((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->AreAODsRelabeled()){
1574          track = dynamic_cast<AliVTrack*>(event->GetTrack(label));
1575          return track;
1576       }
1577       else{
1578          for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
1579             track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
1580             if(track){
1581                if(track->GetID() == label) {
1582                   return track;
1583                }
1584             }
1585          }
1586       }
1587    }
1588    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
1589    return NULL;
1590 }
1591
1592 ///________________________________________________________________________
1593 AliESDtrack *AliConversionCuts::GetESDTrack(AliESDEvent * event, Int_t label){
1594    //Returns pointer to the track with given ESD label
1595    //(Important for AOD implementation, since Track array in AOD data is different
1596    //from ESD array, but ESD tracklabels are stored in AOD Tracks)
1597
1598    if(event) {
1599       if(label > event->GetNumberOfTracks() ) return NULL;
1600       AliESDtrack * track = event->GetTrack(label);
1601       return track;
1602    }
1603    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
1604    return NULL;
1605 }
1606
1607
1608
1609 ///________________________________________________________________________
1610 Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, AliVEvent * event){
1611    // Cut on Electron Probability for Photon Reconstruction
1612
1613    AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1614
1615    if(esdEvent){
1616
1617       Bool_t iResult=kFALSE;
1618
1619       Double_t *posProbArray = new Double_t[AliPID::kSPECIES];
1620       Double_t *negProbArray = new Double_t[AliPID::kSPECIES];
1621
1622       AliESDtrack* negTrack   = esdEvent->GetTrack(photon->GetTrackLabelNegative());
1623       AliESDtrack* posTrack   = esdEvent->GetTrack(photon->GetTrackLabelPositive());
1624
1625       if(negProbArray && posProbArray){
1626
1627          negTrack->GetTPCpid(negProbArray);
1628          posTrack->GetTPCpid(posProbArray);
1629
1630          if(negProbArray[AliPID::kElectron]>=fPIDProbabilityCutNegativeParticle && posProbArray[AliPID::kElectron]>=fPIDProbabilityCutPositiveParticle){
1631             iResult=kTRUE;
1632          }
1633       }
1634
1635       delete [] posProbArray;
1636       delete [] negProbArray;
1637       return iResult;
1638
1639    } else {
1640       ///Not possible for AODs
1641       return kTRUE;
1642    }
1643
1644
1645
1646
1647 }
1648
1649
1650 ///________________________________________________________________________
1651 Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TParticle* eNeg){
1652    // MC Acceptance Cuts
1653    //(Certain areas were excluded for photon reconstruction)
1654
1655    if(particle->R()>fMaxR){
1656       return kFALSE;}
1657
1658    if(ePos->R()>fMaxR){
1659       return kFALSE;
1660    }
1661
1662    if(ePos->R()<fMinR){
1663       return kFALSE;
1664    }
1665
1666    if( ePos->R() <= ((abs(ePos->Vz())*fLineCutZRSlope)-fLineCutZValue)){
1667       return kFALSE;
1668    }
1669    else if (fUseEtaMinCut &&  ePos->R() >= ((abs(ePos->Vz())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
1670       return kFALSE;
1671    }
1672
1673    if(abs(eNeg->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1674       return kFALSE;
1675    }
1676
1677    if(eNeg->Vz()!=ePos->Vz()||eNeg->R()!=ePos->R()){
1678       return kFALSE;
1679    }
1680
1681    if(abs(ePos->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1682       return kFALSE;
1683    }
1684
1685
1686    if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) ){
1687       return kFALSE;
1688    }
1689    if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ){
1690       return kFALSE;
1691    }
1692    if( eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) ){
1693       return kFALSE;
1694    }
1695    if(fEtaCutMin>-0.1){
1696       if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) ){
1697          return kFALSE;
1698       }
1699       if( ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift) ){
1700          return kFALSE;
1701       }
1702       if( eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift) ){
1703          return kFALSE;
1704       }
1705    }
1706
1707    if( ePos->Pt()< fSinglePtCut ||  eNeg->Pt()< fSinglePtCut){
1708       return kFALSE;
1709    }
1710
1711    if(particle->Pt()<fPtCut){
1712       return kFALSE;
1713    }
1714
1715    return kTRUE;
1716 }
1717 ///________________________________________________________________________
1718 Bool_t AliConversionCuts::UpdateCutString() {
1719    ///Update the cut string (if it has been created yet)
1720
1721    if(fCutString && fCutString->GetString().Length() == kNCuts) {
1722       fCutString->SetString(GetCutNumber());
1723    } else {
1724       return kFALSE;
1725    }
1726    return kTRUE;
1727 }
1728 ///________________________________________________________________________
1729 void AliConversionCuts::LoadReweightingHistosMCFromFile() {
1730
1731   AliInfo("Entering loading of histograms for weighting");
1732   TFile *f = TFile::Open(fPathTrFReweighting.Data());
1733   if(!f){
1734      AliError(Form("file for weighting %s not found",fPathTrFReweighting.Data()));
1735      return;
1736   }
1737   if (fNameHistoReweightingPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
1738          cout << "I have to find: " <<  fNameHistoReweightingPi0.Data() << endl;
1739      TH1D *hReweightMCHistPi0temp = (TH1D*)f->Get(fNameHistoReweightingPi0.Data());
1740      hReweightMCHistPi0 = new TH1D(*hReweightMCHistPi0temp);
1741      hReweightMCHistPi0->SetDirectory(0);
1742      if (hReweightMCHistPi0) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingPi0.Data(),fPathTrFReweighting.Data() ));
1743      else AliWarning(Form("%s not found in %s", fNameHistoReweightingPi0.Data() ,fPathTrFReweighting.Data()));
1744   }
1745   if (fNameFitDataPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
1746           cout << "I have to find: " <<  fNameFitDataPi0.Data() << endl;
1747      TF1 *fFitDataPi0temp = (TF1*)f->Get(fNameFitDataPi0.Data());
1748      fFitDataPi0 = new TF1(*fFitDataPi0temp);
1749      if (fFitDataPi0) AliInfo(Form("%s has been loaded from %s", fNameFitDataPi0.Data(),fPathTrFReweighting.Data() ));
1750      else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameFitDataPi0.Data() ));
1751   }
1752
1753   if (fNameHistoReweightingEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
1754          cout << "I have to find: " <<  fNameHistoReweightingEta.Data() << endl;
1755      TH1D *hReweightMCHistEtatemp = (TH1D*)f->Get(fNameHistoReweightingEta.Data());
1756      hReweightMCHistEta = new TH1D(*hReweightMCHistEtatemp);
1757      hReweightMCHistEta->SetDirectory(0);
1758      if (hReweightMCHistEta) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
1759      else AliWarning(Form("%s not found in %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
1760   }
1761
1762   if (fNameFitDataEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
1763          cout << "I have to find: " <<  fNameFitDataEta.Data() << endl;
1764      TF1 *fFitDataEtatemp = (TF1*)f->Get(fNameFitDataEta.Data());
1765      fFitDataEta = new TF1(*fFitDataEtatemp);
1766      if (fFitDataEta) AliInfo(Form("%s has been loaded from %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
1767      else AliWarning(Form("%s not found in %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
1768
1769   }
1770   if (fNameHistoReweightingK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
1771          cout << "I have to find: " <<  fNameHistoReweightingK0s.Data() << endl;
1772      TH1D *hReweightMCHistK0stemp = (TH1D*)f->Get(fNameHistoReweightingK0s.Data());
1773      hReweightMCHistK0s = new TH1D(*hReweightMCHistK0stemp);
1774      hReweightMCHistK0s->SetDirectory(0);
1775      if (hReweightMCHistK0s) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
1776      else AliWarning(Form("%s not found in %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
1777   }
1778
1779   if (fNameFitDataK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
1780          cout << "I have to find: " <<  fNameFitDataK0s.Data() << endl; 
1781      TF1 *fFitDataK0stemp = (TF1*)f->Get(fNameFitDataK0s.Data());
1782      fFitDataK0s = new TF1(*fFitDataK0stemp);
1783      if (fFitDataK0s) AliInfo(Form("%s has been loaded from %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
1784      else AliWarning(Form("%s not found in %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
1785   }
1786   f->Close();
1787   delete f;
1788   
1789 }
1790
1791
1792 ///________________________________________________________________________
1793 Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
1794    // Initialize Cuts from a given Cut string
1795    if(fDoReweightHistoMCPi0 || fDoReweightHistoMCEta || fDoReweightHistoMCK0s) {
1796       AliInfo("Weighting was enabled");
1797       LoadReweightingHistosMCFromFile();
1798    }
1799
1800    AliInfo(Form("Set Photoncut Number: %s",analysisCutSelection.Data()));
1801    if(analysisCutSelection.Length()!=kNCuts) {
1802       AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
1803       return kFALSE;
1804    }
1805    if(!analysisCutSelection.IsDigit()){
1806       AliError("Cut selection contains characters");
1807       return kFALSE;
1808    }
1809
1810    const char *cutSelection = analysisCutSelection.Data();
1811 #define ASSIGNARRAY(i)  fCuts[i] = cutSelection[i] - '0'
1812    for(Int_t ii=0;ii<kNCuts;ii++){
1813       ASSIGNARRAY(ii);
1814    }
1815
1816    // Set Individual Cuts
1817    for(Int_t ii=0;ii<kNCuts;ii++){
1818       if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
1819    }
1820
1821    PrintCutsWithValues();
1822
1823    return kTRUE;
1824 }
1825 ///________________________________________________________________________
1826 Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
1827    ///Set individual cut ID
1828
1829    switch (cutID) {
1830
1831    case kv0FinderType:
1832       if( SetV0Finder(value)) {
1833          fCuts[kv0FinderType] = value;
1834          UpdateCutString();
1835          return kTRUE;
1836       } else return kFALSE;
1837
1838    case kededxSigmaCut:
1839       if( SetTPCdEdxCutElectronLine(value)) {
1840          fCuts[kededxSigmaCut] = value;
1841          UpdateCutString();
1842          return kTRUE;
1843       } else return kFALSE;
1844
1845    case kpidedxSigmaCut:
1846       if( SetTPCdEdxCutPionLine(value)) {
1847          fCuts[kpidedxSigmaCut] = value;
1848          UpdateCutString();
1849          return kTRUE;
1850       } else return kFALSE;
1851
1852    case kpiMomdedxSigmaCut:
1853       if( SetMinMomPiondEdxCut(value)) {
1854          fCuts[kpiMomdedxSigmaCut] = value;
1855          UpdateCutString();
1856          return kTRUE;
1857       } else return kFALSE;
1858
1859    case kchi2GammaCut:
1860       if( SetChi2GammaCut(value)) {
1861          fCuts[kchi2GammaCut] = value;
1862          UpdateCutString();
1863          return kTRUE;
1864       } else return kFALSE;
1865
1866    case ksinglePtCut:
1867       if( SetSinglePtCut(value)) {
1868          fCuts[ksinglePtCut] = value;
1869          UpdateCutString();
1870          return kTRUE;
1871       } else return kFALSE;
1872
1873    case kclsTPCCut:
1874       if( SetTPCClusterCut(value)) {
1875          fCuts[kclsTPCCut] = value;
1876          UpdateCutString();
1877          return kTRUE;
1878       } else return kFALSE;
1879
1880    case ketaCut:
1881       if( SetEtaCut(value)) {
1882          fCuts[ketaCut] = value;
1883          UpdateCutString();
1884          return kTRUE;
1885       } else return kFALSE;
1886
1887    case kLowPRejectionSigmaCut:
1888       if( SetLowPRejectionCuts(value)) {
1889          fCuts[kLowPRejectionSigmaCut] = value;
1890          UpdateCutString();
1891          return kTRUE;
1892       } else return kFALSE;
1893
1894    case kQtMaxCut:
1895       if( SetQtMaxCut(value)) {
1896          fCuts[kQtMaxCut] = value;
1897          UpdateCutString();
1898          return kTRUE;
1899       } else return kFALSE;
1900
1901    case kpiMaxMomdedxSigmaCut:
1902       if( SetMaxMomPiondEdxCut(value)) {
1903          fCuts[kpiMaxMomdedxSigmaCut] = value;
1904          UpdateCutString();
1905          return kTRUE;
1906       } else return kFALSE;
1907
1908    case kRCut:
1909       if( SetRCut(value)) {
1910          fCuts[kRCut] = value;
1911          UpdateCutString();
1912          return kTRUE;
1913       } else return kFALSE;
1914
1915    case kremovePileUp:
1916       if( SetRemovePileUp(value)) {
1917          fCuts[kremovePileUp] = value;
1918          UpdateCutString();
1919          return kTRUE;
1920       } else return kFALSE;
1921
1922    case kselectV0AND:
1923       if( SetSelectSpecialTrigger(value)) {
1924          fCuts[kselectV0AND] = value;
1925          UpdateCutString();
1926          return kTRUE;
1927       } else return kFALSE;
1928
1929    case kmultiplicityMethod:
1930       if( SetMultiplicityMethod(value)) {
1931          fCuts[kmultiplicityMethod] = value;
1932          UpdateCutString();
1933          return kTRUE;
1934       } else return kFALSE;
1935
1936    case kisHeavyIon:
1937       if( SetIsHeavyIon(value)) {
1938          fCuts[kisHeavyIon] = value;
1939          UpdateCutString();
1940          return kTRUE;
1941       } else return kFALSE;
1942
1943    case kCentralityMin:
1944       if( SetCentralityMin(value)) {
1945          fCuts[kCentralityMin] = value;
1946          UpdateCutString();
1947          return kTRUE;
1948       } else return kFALSE;
1949
1950    case kCentralityMax:
1951       if( SetCentralityMax(value)) {
1952          fCuts[kCentralityMax] = value;
1953          UpdateCutString();
1954          return kTRUE;
1955       } else return kFALSE;
1956
1957    case kTOFelectronPID:
1958       if( SetTOFElectronPIDCut(value)) {
1959          fCuts[kTOFelectronPID] = value;
1960          UpdateCutString();
1961          return kTRUE;
1962       } else return kFALSE;
1963
1964    case kdoPhotonAsymmetryCut:
1965       if( SetPhotonAsymmetryCut(value)) {
1966          fCuts[kdoPhotonAsymmetryCut] = value;
1967          UpdateCutString();
1968          return kTRUE;
1969       } else return kFALSE;
1970
1971    case kPsiPair:
1972       if( SetPsiPairCut(value)) {
1973          fCuts[kPsiPair] = value;
1974          UpdateCutString();
1975          return kTRUE;
1976       } else return kFALSE;
1977
1978    case kCosPAngle:
1979       if( SetCosPAngleCut(value)) {
1980          fCuts[kCosPAngle] = value;
1981          UpdateCutString();
1982          return kTRUE;
1983       } else return kFALSE;
1984
1985
1986    case kElecShare:
1987       if( SetSharedElectronCut(value)) {
1988          fCuts[kElecShare] = value;
1989          UpdateCutString();
1990          return kTRUE;
1991       } else return kFALSE;
1992
1993    case kToCloseV0s:
1994       if( SetToCloseV0sCut(value)) {
1995          fCuts[kToCloseV0s] = value;
1996          UpdateCutString();
1997          return kTRUE;
1998       } else return kFALSE;
1999
2000    case kExtraSignals:
2001       if( SetRejectExtraSignalsCut(value)) {
2002          fCuts[kExtraSignals] = value;
2003          UpdateCutString();
2004          return kTRUE;
2005       } else return kFALSE;
2006
2007    case kDcaRPrimVtx:
2008       if( SetDCARPhotonPrimVtxCut(value)) {
2009          fCuts[kDcaRPrimVtx] = value;
2010          UpdateCutString();
2011          return kTRUE;
2012       } else return kFALSE;
2013
2014    case kDcaZPrimVtx:
2015       if( SetDCAZPhotonPrimVtxCut(value)) {
2016          fCuts[kDcaZPrimVtx] = value;
2017          UpdateCutString();
2018          return kTRUE;
2019       } else return kFALSE;
2020
2021    case kInPlaneOutOfPlane:
2022    if( SetInPlaneOutOfPlane(value)) {
2023       fCuts[kInPlaneOutOfPlane] = value;
2024       UpdateCutString();
2025       return kTRUE;
2026    } else return kFALSE;
2027
2028
2029       
2030
2031    case kNCuts:
2032       AliError("Cut id out of range");
2033       return kFALSE;
2034    }
2035
2036    AliError("Cut id %d not recognized");
2037    return kFALSE;
2038
2039
2040 }
2041 ///________________________________________________________________________
2042 void AliConversionCuts::PrintCuts() {
2043    // Print out current Cut Selection
2044    for(Int_t ic = 0; ic < kNCuts; ic++) {
2045       printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
2046    }
2047 }
2048
2049 void AliConversionCuts::PrintCutsWithValues() {
2050    // Print out current Cut Selection with value
2051    if (fIsHeavyIon == 0) {
2052       printf("Running in pp mode \n");
2053       if (fSpecialTrigger == 0){
2054         printf("\t only events triggered by V0OR will be analysed \n");
2055       } else if (fSpecialTrigger == 1){
2056         printf("\t only events triggered by V0AND will be analysed \n");
2057       } else if (fSpecialTrigger == 2){
2058          printf("\t only events where SDD was present will be analysed \n");
2059       } else if (fSpecialTrigger == 3){
2060          printf("\t only events where SDD was present will be analysed and triggered by VOAND\n");
2061       } else if (fSpecialTrigger > 3){   
2062          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2063       }
2064    } else if (fIsHeavyIon == 1){ 
2065       printf("Running in PbPb mode \n");
2066       if (fDetectorCentrality == 0){
2067          printf("\t centrality selection based on V0M \n");
2068       } else if (fDetectorCentrality == 1){
2069          printf("\t centrality selection based on Cl1 \n");
2070       }   
2071       if (fModCentralityClass == 0){
2072         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
2073       } else if ( fModCentralityClass == 1){ 
2074         printf("\t %d - %d \n", fCentralityMin*5, fCentralityMax*5);
2075       } else if ( fModCentralityClass == 2){ 
2076         printf("\t %d - %d \n", fCentralityMin*5+45, fCentralityMax*5+45);
2077       } else if (fModCentralityClass == 3){
2078         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*10, fCentralityMax*10);
2079       } else if ( fModCentralityClass == 4){ 
2080         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5, fCentralityMax*5);
2081       } else if ( fModCentralityClass == 5){ 
2082         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5+45, fCentralityMax*5+45);
2083       }
2084       if (fSpecialTrigger == 0){
2085         printf("\t only events triggered by kMB, kCentral, kSemiCentral will be analysed \n");
2086       } else if (fSpecialTrigger > 4){   
2087          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2088       }
2089    } else if (fIsHeavyIon == 2){
2090       printf("Running in pPb mode \n");
2091       if (fDetectorCentrality == 0){
2092          printf("\t centrality selection based on V0A \n");
2093       } else if (fDetectorCentrality == 1){
2094          printf("\t centrality selection based on Cl1 \n");
2095       }   
2096       if (fModCentralityClass == 0){
2097         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
2098       }
2099       if (fSpecialTrigger == 0){
2100         printf("\t only events triggered by kINT7 will be analysed \n");
2101       } else if (fSpecialTrigger > 4){   
2102          printf("\t only events triggered by %s \n", fSpecialTriggerName.Data());
2103       }
2104    }
2105    printf("Electron cuts: \n");
2106    if (fEtaCutMin > -0.1) printf("\t %3.2f < eta_{e} < %3.2f\n", fEtaCutMin, fEtaCut );
2107      else printf("\t eta_{e} < %3.2f\n", fEtaCut );
2108    printf("\t p_{T,e} > %3.2f\n", fSinglePtCut );
2109    printf("\t %3.2f < n sigma e < %3.2f\n", fPIDnSigmaBelowElectronLine, fPIDnSigmaAboveElectronLine );
2110    
2111    printf("Photon cuts: \n");
2112    printf("\t %3.2f < R_{conv} < %3.2f\n", fMinR, fMaxR );
2113    printf("\t Z_{conv} < %3.2f\n", fMaxZ );
2114    if (fEtaCutMin > -0.1) printf("\t %3.2f < eta_{conv} < %3.2f\n", fEtaCutMin, fEtaCut );
2115      else printf("\t eta_{conv} < %3.2f\n", fEtaCut );
2116    printf("\t p_{T,gamma} > %3.2f\n", fPtCut );  
2117    if (fDo2DQt){
2118           printf("\t 2 dimensional q_{T} cut applied with maximum of %3.2f \n", fQtMax );
2119    } else {
2120           printf("\t 1 dimensional q_{T} cut applied with maximum of %3.2f \n", fQtMax );
2121    }
2122    if (fDo2DPsiPairChi2){
2123           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 ); 
2124    } else {
2125       printf("\t chi^{2} max cut chi^{2} < %3.2f \n", fChi2CutConversion ); 
2126           printf("\t psi_{pair} max cut |psi_{pair}| < %3.2f \n", fPsiPairCut ); 
2127    }       
2128    printf("\t cos(Theta_{point}) > %3.2f \n", fCosPAngleCut );
2129    printf("\t dca_{R} < %3.2f \n", fDCARPrimVtxCut );
2130    printf("\t dca_{Z} < %3.2f \n", fDCAZPrimVtxCut );
2131    if (fDoPhotonQualitySelectionCut) printf("\t selection based on photon quality with quality %d \n", fPhotonQualityCut );
2132 }
2133
2134 ///________________________________________________________________________
2135 Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
2136 {   // Set Cut
2137    switch(isHeavyIon){
2138    case 0:
2139       fIsHeavyIon=0;
2140       break;
2141    case 1:
2142       fIsHeavyIon=1;
2143       fDetectorCentrality=0;
2144       break;
2145    case 2:
2146       fIsHeavyIon=1;
2147       fDetectorCentrality=1;
2148       break;
2149    case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
2150       fIsHeavyIon=1;
2151       fDetectorCentrality=0;
2152       fModCentralityClass=1;
2153       break;
2154    case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2155       fIsHeavyIon=1;
2156       fDetectorCentrality=0;
2157       fModCentralityClass=2;
2158       break;
2159    case 5: //strict cut on v0 tracks for MC
2160       fIsHeavyIon=1;
2161       fDetectorCentrality=0;
2162       fModCentralityClass=3;
2163       break;
2164    case 6: //allows to select centrality 0-45% in steps of 5% for track mult
2165       //strict cut on v0 tracks for MC
2166       fIsHeavyIon=1;
2167       fDetectorCentrality=0;
2168       fModCentralityClass=4;
2169       break;
2170    case 7: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2171       //strict cut on v0 tracks for MC
2172       fIsHeavyIon=1;
2173       fDetectorCentrality=0;
2174       fModCentralityClass=5;
2175       break;
2176    case 8:
2177       fIsHeavyIon=2;
2178       fDetectorCentrality=0;
2179       break;
2180    case 9:
2181       fIsHeavyIon=2;
2182       fDetectorCentrality=1;
2183       break;
2184    default:
2185       AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
2186       return kFALSE;
2187    }
2188    return kTRUE;
2189 }
2190
2191 //___________________________________________________________________
2192 Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
2193 {
2194    // Set Cut
2195    if(minCentrality<0||minCentrality>9){
2196       AliError(Form("minCentrality not defined %d",minCentrality));
2197       return kFALSE;
2198    }
2199
2200    fCentralityMin=minCentrality;
2201    return kTRUE;
2202 }
2203 //___________________________________________________________________
2204 Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
2205 {
2206    // Set Cut
2207    if(maxCentrality<0||maxCentrality>9){
2208       AliError(Form("maxCentrality not defined %d",maxCentrality));
2209       return kFALSE;
2210    }
2211    fCentralityMax=maxCentrality;
2212    return kTRUE;
2213 }
2214 ///________________________________________________________________________
2215 Int_t AliConversionCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
2216 {// Set Cut
2217
2218    switch(selectSpecialTrigger){
2219    case 0:
2220       fSpecialTrigger=0; // dont care
2221       break;
2222    case 1:
2223       fSpecialTrigger=1; // V0AND
2224       break;
2225    case 2:
2226       fSpecialTrigger=2; // with SDD requested
2227       break;
2228    case 3:
2229       fSpecialTrigger=3; // V0AND plus with SDD requested
2230       break;
2231    // allows to run MB & 6 other different trigger classes in parallel with the same photon cut
2232    case 4:
2233       fSpecialTrigger=4; // different trigger class as MB
2234       fTriggerSelectedManually = kTRUE;
2235       break;
2236    case 5:
2237       fSpecialTrigger=4; // different trigger class as MB
2238       fTriggerSelectedManually = kTRUE;
2239       break;
2240    case 6:
2241       fSpecialTrigger=4; // different trigger class as MB
2242       fTriggerSelectedManually = kTRUE;
2243       break;
2244    case 7:
2245       fSpecialTrigger=4; // different trigger class as MB
2246       fTriggerSelectedManually = kTRUE;
2247       break;
2248     case 8:
2249       fSpecialTrigger=4; // different trigger class as MB
2250       fTriggerSelectedManually = kTRUE;
2251       break;
2252     case 9:
2253       fSpecialTrigger=4; // different trigger class as MB
2254       fTriggerSelectedManually = kTRUE;
2255       break;
2256    default:
2257       AliError("Warning: Special Trigger Not known");
2258       return kFALSE;
2259    }
2260    return kTRUE;
2261 }
2262 ///________________________________________________________________________
2263 Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
2264 {
2265    // Set Cut
2266    fMultiplicityMethod=multiplicityMethod;
2267
2268    // 0 Photon Multiplicity
2269    // 1 TPC Track multiplicity
2270    // 2 V0 Mult
2271    // 3 SPD Mult
2272
2273    return kTRUE;
2274 }
2275 ///________________________________________________________________________
2276 Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
2277 {// Set Cut
2278    switch(removePileUp){
2279    case 0:
2280       fRemovePileUp=kFALSE;
2281       break;
2282    case 1:
2283       fRemovePileUp=kTRUE;
2284       break;
2285    default:
2286       AliError("RemovePileUpCut not defined");
2287       return kFALSE;
2288    }
2289    return kTRUE;
2290 }
2291 ///________________________________________________________________________
2292 Bool_t AliConversionCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
2293
2294    switch(extraSignal){
2295    case 0:
2296       fRejectExtraSignals = 0;
2297       break; // No Rejection
2298    case 1:
2299       fRejectExtraSignals = 1;
2300       break; // MinBias Header
2301    case 2:
2302       fRejectExtraSignals = 2;
2303       break; // User String Array
2304    case 3:
2305       fRejectExtraSignals = 3;
2306       break; // Rejection for Gamma Correction only
2307    default:
2308       AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
2309       return kFALSE;
2310    }
2311    return kTRUE;
2312 }
2313 ///________________________________________________________________________
2314 Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
2315 {   // Set Cut
2316    switch (v0FinderType){
2317    case 0:  // on fly V0 finder
2318       cout << "have chosen onfly V0" << endl;
2319       fUseOnFlyV0Finder=kTRUE;
2320       break;
2321    case 1:  // offline V0 finder
2322       cout << "have chosen offline V0" << endl;
2323       fUseOnFlyV0Finder=kFALSE;
2324       break;
2325    default:
2326       AliError(Form(" v0FinderType not defined %d",v0FinderType));
2327       return kFALSE;
2328    }
2329    return kTRUE;
2330 }
2331 ///________________________________________________________________________
2332 Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
2333 {   // Set Cut
2334
2335    //Set Standard LineCutZValues
2336    fLineCutZValueMin = -2;
2337    fLineCutZValue = 7.;
2338
2339    switch(etaCut){
2340    case 0: // 0.9
2341       fEtaCut     = 0.9;
2342       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2343       fEtaCutMin     = -0.1;
2344       fLineCutZRSlopeMin = 0.;
2345       break;
2346    case 1:  // 0.6  // changed from 1.2 to 0.6 on 2013.06.10
2347       fEtaCut     = 0.6;
2348       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2349       fEtaCutMin     = -0.1;
2350       fLineCutZRSlopeMin = 0.;
2351       break;
2352    case 2:  // 1.4
2353       fEtaCut     = 1.4;
2354       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2355       fEtaCutMin     = -0.1;
2356       fLineCutZRSlopeMin = 0.;
2357       break;
2358    case 3: // 0.65
2359       fEtaCut     = 0.65;
2360       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2361       fEtaCutMin     = -0.1;
2362       fLineCutZRSlopeMin = 0.;
2363       break;
2364    case 4: // 0.75
2365       fEtaCut     = 0.75;
2366       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2367       fEtaCutMin     = -0.1;
2368       fLineCutZRSlopeMin = 0.;
2369       break;
2370    case 5: // 0.5
2371       fEtaCut     = 0.5;
2372       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2373       fEtaCutMin     = -0.1;
2374       fLineCutZRSlopeMin = 0.;
2375       break;
2376    case 6: // 5.
2377       fEtaCut     = 5.;
2378       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2379       fEtaCutMin     = -0.1;
2380       fLineCutZRSlopeMin = 0.;
2381       break;
2382    case 7:
2383       if (fIsHeavyIon==1){
2384          fEtaCut     = 0.7;
2385          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2386          fEtaCutMin     = -0.1;
2387          fLineCutZRSlopeMin = 0.;
2388          break;
2389       } else {   
2390          fEtaCut     = 0.3;
2391          fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2392          fEtaCutMin     = -0.1;
2393          fLineCutZRSlopeMin = 0.;
2394          break;
2395       }
2396    // case 8: // 0.1 - 0.8
2397    //    fEtaCut     = 0.9;
2398    //    fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2399    //    fEtaCutMin     = 0.1;
2400    //    fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2401    //    break;
2402    case 8: // 0.4
2403       fEtaCut     = 0.4;
2404       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2405       fEtaCutMin     = -0.1;
2406       fLineCutZRSlopeMin = 0.;
2407       break;
2408    case 9: // 10
2409       fEtaCut     = 10;
2410       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2411       fEtaCutMin     = -0.1;
2412       fLineCutZRSlopeMin = 0.;
2413       break;
2414    default:
2415       AliError(Form(" EtaCut not defined %d",etaCut));
2416       return kFALSE;
2417    }
2418    return kTRUE;
2419 }
2420 ///________________________________________________________________________
2421 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
2422    // Set Cut
2423    switch(RCut){
2424    case 0:
2425       fMinR=0;
2426       fMaxR = 180.;
2427       break;
2428    case 1:
2429       fMinR=2.8;
2430       fMaxR = 180.;
2431       break;
2432    case 2:
2433       fMinR=5.;
2434       fMaxR = 180.;
2435       break;
2436    case 3:
2437       fMaxR = 70.;
2438       fMinR = 10.;
2439       break;
2440    case 4:
2441       fMaxR = 70.;
2442       fMinR = 5.;
2443       break;
2444    case 5:
2445       fMaxR = 180.;
2446       fMinR = 10.;
2447       break;
2448    case 6:
2449       fMaxR = 180.;
2450       fMinR = 20.;
2451       break;
2452    case 7:
2453       fMaxR = 180.;
2454       fMinR = 35.; //old 26.
2455       break;
2456    case 8:
2457       fMaxR = 180.;
2458       fMinR = 12.5;
2459       break;
2460    case 9:
2461       fMaxR = 180.;
2462       fMinR = 7.5;
2463       break;
2464
2465    default:
2466       AliError("RCut not defined");
2467       return kFALSE;
2468    }
2469    return kTRUE;
2470 }
2471 ///________________________________________________________________________
2472 Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
2473 {   // Set Cut
2474    switch(singlePtCut){
2475    case 0: // 0.050 GeV
2476       fSinglePtCut = 0.050;
2477       break;
2478    case 1:  // 0.100 GeV
2479       fSinglePtCut = 0.100;
2480       break;
2481    case 2:  // 0.150 GeV
2482       fSinglePtCut = 0.150;
2483       break;
2484    case 3:  // 0.200 GeV
2485       fSinglePtCut = 0.200;
2486       break;
2487    case 4:  // 0.075 GeV
2488       fSinglePtCut = 0.075;
2489       break;
2490    case 5:  // 0.125 GeV
2491       fSinglePtCut = 0.125;
2492       break;
2493    case 6:  // 0.04 GeV
2494       fSinglePtCut = 0.040;
2495       break;
2496    case 7:  // 0.0 GeV
2497       fSinglePtCut = 0.0;
2498       break;
2499    default:
2500       AliError(Form("singlePtCut not defined %d",singlePtCut));
2501       return kFALSE;
2502    }
2503    return kTRUE;
2504 }
2505 ///________________________________________________________________________
2506 Bool_t AliConversionCuts::SetTPCClusterCut(Int_t clsTPCCut)
2507 {   // Set Cut
2508    switch(clsTPCCut){
2509    case 0: // 0
2510       fMinClsTPC= 0.;
2511       break;
2512    case 1:  // 60
2513       fMinClsTPC= 60.;
2514       break;
2515    case 2:  // 80
2516       fMinClsTPC= 80.;
2517       break;
2518    case 3:  // 100
2519       fMinClsTPC= 100.;
2520       break;
2521    case 4:  // 95% of findable clusters
2522       fMinClsTPCToF= 0.95;
2523       fUseCorrectedTPCClsInfo=1;
2524       break;
2525    case 5:  // 0% of findable clusters
2526       fMinClsTPCToF= 0.0;
2527       fUseCorrectedTPCClsInfo=1;
2528       break;
2529    case 6:  // 70% of findable clusters
2530       fMinClsTPCToF= 0.7;
2531       fUseCorrectedTPCClsInfo=1;
2532       break;
2533    case 7:  // 0% of findable clusters
2534       fMinClsTPCToF= 0.35;
2535       fUseCorrectedTPCClsInfo=0;
2536       break;
2537    case 8:
2538       fMinClsTPCToF= 0.35;
2539       fUseCorrectedTPCClsInfo=1;
2540       break;
2541    case 9:
2542       fMinClsTPCToF= 0.6;
2543       fUseCorrectedTPCClsInfo=1;
2544       break;
2545    default:
2546       AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
2547       return kFALSE;
2548    }
2549    return kTRUE;
2550 }
2551 ///________________________________________________________________________
2552 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
2553 {   // Set Cut
2554    switch(ededxSigmaCut){
2555    case 0: // -10,10
2556       fPIDnSigmaBelowElectronLine=-10;
2557       fPIDnSigmaAboveElectronLine=10;
2558       break;
2559    case 1: // -5,5
2560       fPIDnSigmaBelowElectronLine=-5;
2561       fPIDnSigmaAboveElectronLine=5;
2562       break;
2563    case 2: // -3,5
2564       fPIDnSigmaBelowElectronLine=-3;
2565       fPIDnSigmaAboveElectronLine=5;
2566       break;
2567    case 3: // -4,5
2568       fPIDnSigmaBelowElectronLine=-4;
2569       fPIDnSigmaAboveElectronLine=5;
2570       break;
2571    case 4: // -6,7
2572       fPIDnSigmaBelowElectronLine=-6;
2573       fPIDnSigmaAboveElectronLine=7;
2574       break;
2575    case 5: // -4,4
2576       fPIDnSigmaBelowElectronLine=-4;
2577       fPIDnSigmaAboveElectronLine=4;
2578       break;
2579    case 6: // -2.5,4
2580       fPIDnSigmaBelowElectronLine=-2.5;
2581       fPIDnSigmaAboveElectronLine=4;
2582       break;
2583    case 7: // -2,3.5
2584       fPIDnSigmaBelowElectronLine=-2;
2585       fPIDnSigmaAboveElectronLine=3.5;
2586       break;
2587    default:
2588       AliError("TPCdEdxCutElectronLine not defined");
2589       return kFALSE;
2590
2591    }
2592    return kTRUE;
2593 }
2594 ///________________________________________________________________________
2595 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
2596 {   // Set Cut
2597
2598    switch(pidedxSigmaCut){
2599    case 0:  // -10
2600       fPIDnSigmaAbovePionLine=-10;
2601       fPIDnSigmaAbovePionLineHighPt=-10;
2602       break;
2603    case 1:   // 0
2604       fPIDnSigmaAbovePionLine=0;
2605       fPIDnSigmaAbovePionLineHighPt=-10;
2606       break;
2607    case 2:  // 1
2608       fPIDnSigmaAbovePionLine=1;
2609       fPIDnSigmaAbovePionLineHighPt=-10;
2610       break;
2611    case 3:  // 1
2612       fPIDnSigmaAbovePionLine=2.5;
2613       fPIDnSigmaAbovePionLineHighPt=-10;
2614       break;
2615    case 4:  // 1
2616       fPIDnSigmaAbovePionLine=0.5;
2617       fPIDnSigmaAbovePionLineHighPt=-10;
2618       break;
2619    case 5:  // 1
2620       fPIDnSigmaAbovePionLine=2.;
2621       fPIDnSigmaAbovePionLineHighPt=-10;
2622       break;
2623    case 6:  // 1
2624       fPIDnSigmaAbovePionLine=2.;
2625       fPIDnSigmaAbovePionLineHighPt=0.5;
2626       break;
2627    case 7:  // 1
2628       fPIDnSigmaAbovePionLine=3.5;
2629       fPIDnSigmaAbovePionLineHighPt=-10;
2630       break;
2631    case 8:  // 1
2632       fPIDnSigmaAbovePionLine=2.;
2633       fPIDnSigmaAbovePionLineHighPt=1.;
2634       break;
2635    case 9:
2636       fPIDnSigmaAbovePionLine=3.0; // We need a bit less tight cut on dE/dx
2637       fPIDnSigmaAbovePionLineHighPt=-10;
2638       break;
2639    default:
2640       AliError(Form("Warning: pidedxSigmaCut not defined %d",pidedxSigmaCut));
2641       return kFALSE;
2642    }
2643    return kTRUE;
2644 }
2645 ///________________________________________________________________________
2646 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
2647 {   // Set Cut
2648    switch(piMomdedxSigmaCut){
2649    case 0:  // 0.5 GeV
2650       fPIDMinPnSigmaAbovePionLine=0.5;
2651       break;
2652    case 1:  // 1. GeV
2653       fPIDMinPnSigmaAbovePionLine=1.;
2654       break;
2655    case 2:  // 1.5 GeV
2656       fPIDMinPnSigmaAbovePionLine=1.5;
2657       break;
2658    case 3:  // 20.0 GeV
2659       fPIDMinPnSigmaAbovePionLine=20.;
2660       break;
2661    case 4:  // 50.0 GeV
2662       fPIDMinPnSigmaAbovePionLine=50.;
2663       break;
2664    case 5:  // 0.3 GeV
2665       fPIDMinPnSigmaAbovePionLine=0.3;
2666       break;
2667    case 6:  // 0.25 GeV
2668       fPIDMinPnSigmaAbovePionLine=0.25;
2669       break;
2670    case 7:  // 0.4 GeV
2671       fPIDMinPnSigmaAbovePionLine=0.4;
2672       break;
2673    case 8:  // 0.2 GeV
2674       fPIDMinPnSigmaAbovePionLine=0.2;
2675       break;
2676    default:
2677       AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
2678       return kFALSE;
2679    }
2680    return kTRUE;
2681 }
2682 ///________________________________________________________________________
2683 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
2684 {   // Set Cut
2685    switch(piMaxMomdedxSigmaCut){
2686    case 0:  // 100. GeV
2687       fPIDMaxPnSigmaAbovePionLine=100.;
2688       break;
2689    case 1:  // 5. GeV
2690       fPIDMaxPnSigmaAbovePionLine=5.;
2691       break;
2692    case 2:  // 4. GeV
2693       fPIDMaxPnSigmaAbovePionLine=4.;
2694       break;
2695    case 3:  // 3.5 GeV
2696       fPIDMaxPnSigmaAbovePionLine=3.5;
2697       break;
2698    case 4:  // 3. GeV
2699       fPIDMaxPnSigmaAbovePionLine=3.;
2700       break;
2701    case 5:  // 7. GeV
2702       fPIDMaxPnSigmaAbovePionLine=7.;
2703       break;
2704    default:
2705       AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
2706       return kFALSE;
2707    }
2708    return kTRUE;
2709 }
2710 ///________________________________________________________________________
2711 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
2712 {   // Set Cut
2713    switch(LowPRejectionSigmaCut){
2714    case 0:  //
2715       fPIDnSigmaAtLowPAroundKaonLine=0;
2716       fPIDnSigmaAtLowPAroundProtonLine=0;
2717       fPIDnSigmaAtLowPAroundPionLine=0;
2718       fDoKaonRejectionLowP = kFALSE;
2719       fDoProtonRejectionLowP = kFALSE;
2720       fDoPionRejectionLowP = kFALSE;
2721       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2722       break;
2723    case 1:  //
2724       fPIDnSigmaAtLowPAroundKaonLine=0.5;
2725       fPIDnSigmaAtLowPAroundProtonLine=0.5;
2726       fPIDnSigmaAtLowPAroundPionLine=0.5;
2727       fDoKaonRejectionLowP = kTRUE;
2728       fDoProtonRejectionLowP = kTRUE;
2729       fDoPionRejectionLowP = kTRUE;
2730       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2731       break;
2732    case 2:  //
2733       fPIDnSigmaAtLowPAroundKaonLine=1;
2734       fPIDnSigmaAtLowPAroundProtonLine=1;
2735       fPIDnSigmaAtLowPAroundPionLine=1;
2736       fDoKaonRejectionLowP = kTRUE;
2737       fDoProtonRejectionLowP = kTRUE;
2738       fDoPionRejectionLowP = kTRUE;
2739       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2740       break;
2741    case 3:  //
2742       fPIDnSigmaAtLowPAroundKaonLine=2.;
2743       fPIDnSigmaAtLowPAroundProtonLine=2.;
2744       fPIDnSigmaAtLowPAroundPionLine=2.;
2745       fDoKaonRejectionLowP = kTRUE;
2746       fDoProtonRejectionLowP = kTRUE;
2747       fDoPionRejectionLowP = kTRUE;
2748       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2749       break;
2750    case 4:  //
2751       fPIDnSigmaAtLowPAroundKaonLine=0.;
2752       fPIDnSigmaAtLowPAroundProtonLine=0.;
2753       fPIDnSigmaAtLowPAroundPionLine=1;
2754       fDoKaonRejectionLowP = kFALSE;
2755       fDoProtonRejectionLowP = kFALSE;
2756       fDoPionRejectionLowP = kTRUE;
2757       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2758       break;
2759    case 5:  //
2760       fPIDnSigmaAtLowPAroundKaonLine=0.;
2761       fPIDnSigmaAtLowPAroundProtonLine=0.;
2762       fPIDnSigmaAtLowPAroundPionLine=1.5;
2763       fDoKaonRejectionLowP = kFALSE;
2764       fDoProtonRejectionLowP = kFALSE;
2765       fDoPionRejectionLowP = kTRUE;
2766       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2767       break;
2768    case 6:  //
2769       fPIDnSigmaAtLowPAroundKaonLine=0.;
2770       fPIDnSigmaAtLowPAroundProtonLine=0.;
2771       fPIDnSigmaAtLowPAroundPionLine=2.;
2772       fDoKaonRejectionLowP = kFALSE;
2773       fDoProtonRejectionLowP = kFALSE;
2774       fDoPionRejectionLowP = kTRUE;
2775       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2776       break;
2777    case 7:  //
2778       fPIDnSigmaAtLowPAroundKaonLine=0.;
2779       fPIDnSigmaAtLowPAroundProtonLine=0.;
2780       fPIDnSigmaAtLowPAroundPionLine=0.5;
2781       fDoKaonRejectionLowP = kFALSE;
2782       fDoProtonRejectionLowP = kFALSE;
2783       fDoPionRejectionLowP = kTRUE;
2784       fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
2785       break;
2786    default:
2787       AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
2788       return kFALSE;
2789    }
2790    return kTRUE;
2791 }
2792 ///________________________________________________________________________
2793 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
2794    // Set Cut
2795    switch(TOFelectronPID){
2796    case 0: // no cut
2797       fUseTOFpid = kFALSE;
2798       fTofPIDnSigmaBelowElectronLine=-100;
2799       fTofPIDnSigmaAboveElectronLine=100;
2800       break;
2801    case 1: // -7,7
2802       fUseTOFpid = kTRUE;
2803       fTofPIDnSigmaBelowElectronLine=-7;
2804       fTofPIDnSigmaAboveElectronLine=7;
2805       break;
2806    case 2: // -5,5
2807       fUseTOFpid = kTRUE;
2808       fTofPIDnSigmaBelowElectronLine=-5;
2809       fTofPIDnSigmaAboveElectronLine=5;
2810       break;
2811    case 3: // -3,5
2812       fUseTOFpid = kTRUE;
2813       fTofPIDnSigmaBelowElectronLine=-3;
2814       fTofPIDnSigmaAboveElectronLine=5;
2815       break;
2816    case 4: // -2,3
2817       fUseTOFpid = kTRUE;
2818       fTofPIDnSigmaBelowElectronLine=-2;
2819       fTofPIDnSigmaAboveElectronLine=3;
2820       break;
2821    case 5: // -3,3
2822       fUseTOFpid = kTRUE;
2823       fTofPIDnSigmaBelowElectronLine=-3;
2824       fTofPIDnSigmaAboveElectronLine=3;
2825       break;
2826    default:
2827       AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
2828       return kFALSE;
2829    }
2830    return kTRUE;
2831 }
2832 ///________________________________________________________________________
2833 Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
2834 {   // Set Cut
2835    switch(QtMaxCut){
2836    case 0: //
2837       fQtMax=1.;
2838       fDoQtGammaSelection=kFALSE;
2839       fDo2DQt=kFALSE;
2840       break;
2841    case 1:
2842       fQtMax=0.1;
2843       fDo2DQt=kFALSE;
2844       break;
2845    case 2:
2846       fQtMax=0.07;
2847       fDo2DQt=kFALSE;
2848       break;
2849    case 3:
2850       fQtMax=0.05;
2851       fDo2DQt=kFALSE;
2852       break;
2853    case 4:
2854       fQtMax=0.03;
2855       fDo2DQt=kFALSE;
2856       break;
2857    case 5:
2858       fQtMax=0.02;
2859       fDo2DQt=kFALSE;
2860       break;
2861    case 6:
2862       fQtMax=0.02;
2863       fDo2DQt=kTRUE;
2864       break;
2865    case 7:
2866       fQtMax=0.15;
2867       fDo2DQt=kFALSE;
2868       break;
2869    case 8:
2870       fQtMax=0.05;
2871       fDo2DQt=kTRUE;
2872       break;   
2873    case 9:
2874       fQtMax=0.03;
2875       fDo2DQt=kTRUE;
2876       break;      
2877    default:
2878       AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
2879       return kFALSE;
2880    }
2881    return kTRUE;
2882 }
2883 ///________________________________________________________________________
2884 Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
2885 {   // Set Cut
2886
2887    switch(chi2GammaCut){
2888    case 0: // 100
2889       fChi2CutConversion = 100.;
2890       break;
2891    case 1:  // 50
2892       fChi2CutConversion = 50.;
2893       break;
2894    case 2:  // 30
2895       fChi2CutConversion = 30.;
2896       break;
2897    case 3:
2898       fChi2CutConversion = 200.;
2899       break;
2900    case 4:
2901       fChi2CutConversion = 500.;
2902       break;
2903    case 5:
2904       fChi2CutConversion = 100000.;
2905       break;
2906    case 6:
2907       fChi2CutConversion = 5.;
2908       break;
2909    case 7:
2910       fChi2CutConversion = 10.;
2911       break;
2912    case 8:
2913       fChi2CutConversion = 20.;
2914       break;
2915    case 9:
2916       fChi2CutConversion = 15.;
2917       break;
2918    default:
2919       AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
2920       return kFALSE;
2921    }
2922    return kTRUE;
2923 }
2924 ///________________________________________________________________________
2925 Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
2926
2927    switch(psiCut) {
2928    case 0:
2929       fPsiPairCut = 10000; //
2930       break;
2931    case 1:
2932       fPsiPairCut = 0.1; //
2933       break;
2934    case 2:
2935       fPsiPairCut = 0.05; // Standard
2936       break;
2937    case 3:
2938       fPsiPairCut = 0.035; //
2939       break;
2940    case 4:
2941       fPsiPairCut = 0.2; //
2942       break;   
2943    case 5:
2944       fPsiPairCut = 0.1; //
2945       fDo2DPsiPairChi2 = kTRUE;
2946       break;
2947    case 6:
2948       fPsiPairCut = 0.05; //
2949       fDo2DPsiPairChi2 = kTRUE;
2950       break;
2951    case 7:
2952       fPsiPairCut = 0.035; //
2953       fDo2DPsiPairChi2 = kTRUE;
2954       break;
2955    case 8:
2956       fPsiPairCut = 0.2; //
2957       fDo2DPsiPairChi2 = kTRUE; //
2958       break;
2959    case 9:
2960       fPsiPairCut = 0.5; //
2961       break;
2962    default:
2963       AliError(Form("PsiPairCut not defined %d",psiCut));
2964       return kFALSE;
2965    }
2966
2967    return kTRUE;
2968 }
2969 ///________________________________________________________________________
2970 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
2971    // Set Cut
2972    switch(doPhotonAsymmetryCut){
2973    case 0:
2974       fDoPhotonAsymmetryCut=0;
2975       fMinPPhotonAsymmetryCut=100.;
2976       fMinPhotonAsymmetry=0.;
2977       break;
2978    case 1:
2979       fDoPhotonAsymmetryCut=1;
2980       fMinPPhotonAsymmetryCut=3.5;
2981       fMinPhotonAsymmetry=0.04;
2982       break;
2983    case 2:
2984       fDoPhotonAsymmetryCut=1;
2985       fMinPPhotonAsymmetryCut=3.5;
2986       fMinPhotonAsymmetry=0.06;
2987       break;
2988    case 3:
2989       fDoPhotonAsymmetryCut=1;
2990       fMinPPhotonAsymmetryCut=0.0;
2991       fMinPhotonAsymmetry=0.05;
2992       break; 
2993    default:
2994       AliError(Form("PhotonAsymmetryCut not defined %d",doPhotonAsymmetryCut));
2995       return kFALSE;
2996    }
2997    fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
2998    return kTRUE;
2999 }
3000 ///________________________________________________________________________
3001 Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
3002
3003    switch(cosCut){
3004    case 0:
3005       fCosPAngleCut = -1; 
3006       break;
3007    case 1:
3008       fCosPAngleCut = 0; 
3009       break;
3010    case 2:
3011       fCosPAngleCut = 0.5; 
3012       break;
3013    case 3:
3014       fCosPAngleCut = 0.75; 
3015       break;
3016    case 4:
3017       fCosPAngleCut = 0.85; 
3018       break;
3019    case 5:
3020       fCosPAngleCut = 0.88; 
3021       break;
3022    case 6:
3023       fCosPAngleCut = 0.9;
3024       break;
3025    case 7:
3026       fCosPAngleCut = 0.95;
3027       break;
3028    default:
3029       AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
3030       return kFALSE;
3031    }
3032
3033    return kTRUE;
3034 }
3035 ///________________________________________________________________________
3036 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
3037
3038         switch(sharedElec){
3039         case 0:
3040                 fDoSharedElecCut = kFALSE;
3041                 fDoPhotonQualitySelectionCut = kFALSE;
3042                 fPhotonQualityCut = 0;
3043                 break;
3044         case 1:
3045                 fDoSharedElecCut = kTRUE;
3046                 fDoPhotonQualitySelectionCut = kFALSE;
3047                 fPhotonQualityCut = 0;
3048                 break;
3049         case 2:
3050                 fDoSharedElecCut = kFALSE;
3051                 fDoPhotonQualitySelectionCut = kTRUE;
3052                 fPhotonQualityCut = 1;
3053                 break;
3054         case 3:
3055                 fDoSharedElecCut = kFALSE;
3056                 fDoPhotonQualitySelectionCut = kTRUE;     
3057                 fPhotonQualityCut = 2;
3058                 break;
3059         case 4:
3060                 fDoSharedElecCut = kFALSE;
3061                 fDoPhotonQualitySelectionCut = kTRUE;     
3062                 fPhotonQualityCut = 3;
3063                 break;
3064         default:
3065                 AliError(Form("Shared Electron Cut not defined %d",sharedElec));        
3066                 return kFALSE;
3067    }
3068
3069    return kTRUE;
3070 }
3071 ///________________________________________________________________________
3072 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
3073
3074    switch(toClose){
3075    case 0:
3076       fDoToCloseV0sCut = kFALSE;
3077       fminV0Dist = 250;
3078       break;
3079    case 1:
3080       fDoToCloseV0sCut = kTRUE;
3081       fminV0Dist = 1;
3082       break;
3083    case 2:
3084       fDoToCloseV0sCut = kTRUE;
3085       fminV0Dist = 2;
3086       break;
3087    case 3:
3088       fDoToCloseV0sCut = kTRUE;
3089       fminV0Dist = 3;
3090       break;
3091    default:
3092       AliError(Form("Shared Electron Cut not defined %d",toClose));
3093       return kFALSE;
3094    }
3095    return kTRUE;
3096 }
3097 ///________________________________________________________________________
3098 Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
3099 {   // Set Cut
3100    switch(TRDElectronCut){
3101    case 0:
3102       fDoTRDPID=kFALSE;
3103       break;
3104    case 1:
3105       fDoTRDPID=kTRUE;
3106       fPIDTRDEfficiency=0.1;
3107       break;
3108    case 8:
3109       fDoTRDPID=kTRUE;
3110       fPIDTRDEfficiency=0.8;
3111       break;
3112    case 9:
3113       fDoTRDPID=kTRUE;
3114       fPIDTRDEfficiency=0.9;
3115       break;
3116    default:
3117       AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
3118       return kFALSE;
3119    }
3120
3121    return kTRUE;
3122 }
3123
3124 ///________________________________________________________________________
3125 Bool_t AliConversionCuts::SetDCAZPhotonPrimVtxCut(Int_t DCAZPhotonPrimVtx){
3126    // Set Cut
3127    switch(DCAZPhotonPrimVtx){
3128    case 0:  //
3129       fDCAZPrimVtxCut   = 1000;
3130       break;
3131    case 1:  //
3132       fDCAZPrimVtxCut   = 10;
3133       break;
3134    case 2:  //
3135       fDCAZPrimVtxCut   = 5;
3136       break;
3137    case 3:  //
3138       fDCAZPrimVtxCut   = 4;
3139       break;
3140    case 4:  //
3141       fDCAZPrimVtxCut   = 3;
3142       break;
3143    case 5:  //
3144       fDCAZPrimVtxCut   = 2.5;
3145       break;
3146    case 6:  //
3147       fDCAZPrimVtxCut   = 2;
3148       break;
3149    case 7:  //
3150       fDCAZPrimVtxCut   = 1.5;
3151       break;
3152    case 8:  //
3153       fDCAZPrimVtxCut   = 1;
3154       break;
3155    case 9:  //
3156       fDCAZPrimVtxCut   = 0.5;
3157       break;
3158    default:
3159       cout<<"Warning: DCAZPhotonPrimVtx not defined "<<DCAZPhotonPrimVtx<<endl;
3160       return kFALSE;
3161    }
3162    return kTRUE;
3163 }
3164
3165 ///________________________________________________________________________
3166 Bool_t AliConversionCuts::SetDCARPhotonPrimVtxCut(Int_t DCARPhotonPrimVtx){
3167    // Set Cut
3168    switch(DCARPhotonPrimVtx){
3169    case 0:  //
3170       fDCARPrimVtxCut   = 1000;
3171       break;
3172    case 1:  //
3173       fDCARPrimVtxCut   = 10;
3174       break;
3175    case 2:  //
3176       fDCARPrimVtxCut   = 5;
3177       break;
3178    case 3:  //
3179       fDCARPrimVtxCut   = 4;
3180       break;
3181    case 4:  //
3182       fDCARPrimVtxCut   = 3;
3183       break;
3184    case 5:  //
3185       fDCARPrimVtxCut   = 2.5;
3186       break;
3187    case 6:  //
3188       fDCARPrimVtxCut   = 2;
3189       break;
3190    case 7:  //
3191       fDCARPrimVtxCut   = 1.5;
3192       break;
3193    case 8:  //
3194       fDCARPrimVtxCut   = 1;
3195       break;
3196    case 9:  //
3197       fDCARPrimVtxCut   = 0.5;
3198       break;
3199    default:
3200       cout<<"Warning: DCARPhotonPrimVtx not defined "<<DCARPhotonPrimVtx<<endl;
3201       return kFALSE;
3202    }
3203    return kTRUE;
3204 }
3205
3206 ///________________________________________________________________________
3207 Bool_t AliConversionCuts::SetInPlaneOutOfPlane(Int_t inOutPlane){
3208    // Set Cut
3209    switch(inOutPlane){
3210    case 0:  //
3211       fInPlaneOutOfPlane = 0; // No Event Plane
3212       break;
3213    case 1:  //
3214       fInPlaneOutOfPlane = 1; // In-Plane
3215       break;
3216    case 2:  //
3217       fInPlaneOutOfPlane = 2; // Out-Of-Plane
3218       break;
3219    default:
3220       cout<<"Warning: In-Plane or Out-Of-Plane not defined "<<inOutPlane<<endl;
3221       return kFALSE;
3222    }
3223    return kTRUE;
3224 }
3225
3226
3227 //-------------------------------------------------------------
3228 Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
3229 {   // Get Event Centrality
3230
3231    AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
3232    if(esdEvent){
3233       AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
3234
3235       if(fDetectorCentrality==0){
3236          if (fIsHeavyIon==2){
3237             return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
3238          } else{
3239             return fESDCentrality->GetCentralityPercentile("V0M"); // default
3240          }
3241       }
3242       if(fDetectorCentrality==1){
3243          return fESDCentrality->GetCentralityPercentile("CL1");
3244       }
3245    }
3246
3247    AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
3248    if(aodEvent){
3249       if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
3250    }
3251
3252    return -1;
3253 }
3254 //-------------------------------------------------------------
3255 Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
3256 {   // Centrality Selection
3257    if(!fIsHeavyIon)return kTRUE;
3258
3259    if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
3260    else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
3261
3262    Double_t centrality=GetCentrality(event);
3263    if(centrality<0)return kFALSE;
3264
3265    Int_t centralityC=0;
3266    if (fModCentralityClass == 0){
3267       centralityC= Int_t(centrality/10);
3268       if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3269          return kTRUE;
3270       else return kFALSE;
3271    }
3272    else if (fModCentralityClass ==1){
3273       centralityC= Int_t(centrality);
3274       if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3275          return kTRUE;
3276       } else return kFALSE;
3277    }
3278    else if (fModCentralityClass ==2){
3279       centralityC= Int_t(centrality);
3280       if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3281          return kTRUE;
3282       else return kFALSE;
3283    }
3284
3285    Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetNumberOfPrimaryTracks();
3286    Int_t PrimaryTracks10[10][2] =
3287       {
3288          {9999,9999}, //  0
3289          {1210, 928}, // 10
3290          { 817, 658}, // 20
3291          { 536, 435}, // 30
3292          { 337, 276}, // 40
3293          { 197, 162}, // 50
3294          { 106, 100}, // 60
3295          {  51,  44}, // 70
3296          {  21,  18}, // 80
3297          {   0,   0}  // 90
3298       };
3299    Int_t PrimaryTracks5a[10][2] =
3300       {
3301          {9999,9999}, // 0
3302          {1485,1168}, // 5
3303          {1210, 928}, // 10
3304          { 995, 795}, // 15
3305          { 817, 658}, // 20
3306          { 666, 538}, // 25
3307          { 536, 435}, // 30
3308          { 428, 350}, // 35
3309          { 337, 276}, // 40
3310          { 260, 214}  // 45
3311       };
3312    Int_t PrimaryTracks5b[10][2] =
3313       {
3314          { 260, 214}, // 45
3315          { 197, 162}, // 50
3316          { 147, 125}, // 55
3317          { 106, 100}, // 60
3318          {  75,  63}, // 65
3319          {  51,  44}, // 70
3320          {  34,  29}, // 75
3321          {  21,  18}, // 80
3322          {  13,  11}, // 85
3323          {   0,   0}  // 90
3324       };
3325
3326    Int_t column = -1;
3327    if(event->IsA()==AliESDEvent::Class()) column = 0;
3328    if(event->IsA()==AliAODEvent::Class()) column = 1;
3329
3330    if (fModCentralityClass == 3){
3331       if(fMCEvent){
3332          if(nprimaryTracks > PrimaryTracks10[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks10[fCentralityMin][column])
3333             return kTRUE;
3334          else return kFALSE;
3335       }
3336       else{
3337          centralityC= Int_t(centrality/10);
3338          if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
3339             return kTRUE;
3340          else return kFALSE;
3341       }
3342    }
3343    else if (fModCentralityClass ==4){
3344       if(fMCEvent){
3345          if(nprimaryTracks > PrimaryTracks5a[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5a[fCentralityMin][column])
3346             return kTRUE;
3347          else return kFALSE;
3348       }
3349       else{
3350          centralityC= Int_t(centrality);
3351          if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
3352             return kTRUE;
3353          } else return kFALSE;
3354       }
3355    }
3356    else if (fModCentralityClass ==5){
3357       if(fMCEvent){
3358          if(nprimaryTracks > PrimaryTracks5b[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5b[fCentralityMin][column])
3359             return kTRUE;
3360          else return kFALSE;
3361       }
3362       else{
3363          centralityC= Int_t(centrality);
3364          if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
3365             return kTRUE;
3366          else return kFALSE;
3367       }
3368    }
3369
3370    return kFALSE;
3371 }
3372 ///________________________________________________________________________
3373 Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
3374    // Cut on z position of primary vertex
3375    Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
3376    Double_t fVertexZSPD = 0;
3377    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
3378    if(fESDEvent){
3379       fVertexZSPD = fESDEvent->GetPrimaryVertexSPD()->GetZ();
3380    } 
3381    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
3382    if(fAODEvent){
3383       fVertexZSPD = fAODEvent->GetPrimaryVertexSPD()->GetZ();
3384    }
3385   
3386    if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
3387
3388    TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
3389                                                 ->GetTask("V0ReaderV1"))->GetPeriodName();
3390    if (periodName.CompareTo("LHC11h")==0){
3391      if (abs(fVertexZ-fVertexZSPD) > 0.1) return kFALSE;
3392    }                                            
3393    if (fIsHeavyIon == 2){
3394      if(fUtils->IsFirstEventInChunk(event)) return kFALSE;
3395      if(!fUtils->IsVertexSelected2013pA(event)) return kFALSE;
3396      if(fUtils->IsPileUpEvent(event)) return kFALSE;
3397    }
3398
3399    return kTRUE;
3400 }
3401 ///________________________________________________________________________
3402
3403 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
3404    // returns number of contributors to the vertex
3405
3406    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
3407    if(fESDEvent){
3408       if (fESDEvent->GetPrimaryVertex() != NULL){
3409          if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
3410 //     cout << "accepted global" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertex()->GetNContributors() << endl;
3411             return fESDEvent->GetPrimaryVertex()->GetNContributors();
3412          }
3413       }
3414
3415       if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
3416          if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3417 //     cout << "accepted SPD" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertexSPD()->GetNContributors() << endl;
3418             return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
3419          }  else {
3420             AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
3421 //            cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3422             return 0;
3423          }
3424       }
3425    }
3426
3427    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
3428    if(fAODEvent){
3429       if (fAODEvent->GetPrimaryVertex() != NULL){
3430          if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
3431             return fAODEvent->GetPrimaryVertex()->GetNContributors();
3432          }
3433       }
3434       if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
3435          if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
3436             return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
3437          } else {
3438             AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
3439             return 0;
3440          }
3441       }
3442    }
3443   // cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
3444    return 0;
3445 }
3446
3447 ///________________________________________________________________________
3448
3449 Bool_t AliConversionCuts::IsTriggerSelected(AliVEvent *fInputEvent)
3450 {
3451
3452    AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
3453
3454    UInt_t isSelected = AliVEvent::kAny;
3455    TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetPeriodName();
3456 //    cout <<   periodName.Data() << endl;
3457    
3458    if (fInputHandler==NULL) return kFALSE;
3459    if( fInputHandler->GetEventSelection() || fInputEvent->IsA()==AliAODEvent::Class()) {
3460       if (!fTriggerSelectedManually){
3461          if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
3462          else {
3463             if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
3464             else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
3465             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 ) {
3466                                 fOfflineTriggerMask = AliVEvent::kINT7;      
3467 //                              cout << "will take kINT7 as trigger mask" << endl; 
3468                         }       
3469             else fOfflineTriggerMask = AliVEvent::kMB;
3470          }
3471       }
3472       // Get the actual offline trigger mask for the event and AND it with the
3473       // requested mask. If no mask requested select by default the event.
3474 //       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
3475 //       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
3476
3477       if (fOfflineTriggerMask)
3478          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
3479    }
3480    fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
3481
3482    // Fill Histogram
3483    if(hTriggerClass){
3484       if (fIsSDDFired) hTriggerClass->Fill(33);
3485       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
3486       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
3487       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
3488       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
3489       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
3490       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
3491       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
3492       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
3493       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
3494       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
3495       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
3496       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
3497       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
3498       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
3499       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
3500       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
3501       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
3502       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
3503       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
3504       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
3505       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
3506       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
3507       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
3508       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
3509       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
3510       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
3511       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
3512       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
3513       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
3514       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
3515       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
3516       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
3517       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
3518       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
3519       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
3520       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
3521       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClass->Fill(28);
3522       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(29);
3523       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(30);
3524       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(31);
3525       if (!fInputHandler->IsEventSelected()) hTriggerClass->Fill(34);
3526    }
3527
3528    if(hTriggerClassSelected && isSelected){
3529       if (!fIsSDDFired) hTriggerClassSelected->Fill(33);
3530       if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClassSelected->Fill(0);
3531       if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClassSelected->Fill(1);
3532       if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClassSelected->Fill(2);
3533       if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClassSelected->Fill(3);
3534       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClassSelected->Fill(4);
3535       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClassSelected->Fill(5);
3536       if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClassSelected->Fill(6);
3537       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClassSelected->Fill(6);
3538       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClassSelected->Fill(7);
3539       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClassSelected->Fill(7);
3540       if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClassSelected->Fill(8);
3541       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClassSelected->Fill(8);
3542       if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClassSelected->Fill(9);
3543       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClassSelected->Fill(9);
3544       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClassSelected->Fill(10);
3545       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClassSelected->Fill(10);
3546       if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClassSelected->Fill(11);
3547       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClassSelected->Fill(12);
3548       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClassSelected->Fill(13);
3549       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClassSelected->Fill(13);
3550       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClassSelected->Fill(13);
3551       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClassSelected->Fill(14);
3552       if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClassSelected->Fill(15);
3553       if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClassSelected->Fill(16);
3554       if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClassSelected->Fill(17);
3555       if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClassSelected->Fill(18);
3556       if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClassSelected->Fill(19);
3557       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClassSelected->Fill(20);
3558       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClassSelected->Fill(20);
3559       if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClassSelected->Fill(21);
3560       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClassSelected->Fill(22);
3561       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClassSelected->Fill(23);
3562       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClassSelected->Fill(24);
3563       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClassSelected->Fill(25);
3564       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClassSelected->Fill(26);
3565       if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClassSelected->Fill(27);
3566       if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClassSelected->Fill(28);
3567       if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClassSelected->Fill(29);
3568       if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClassSelected->Fill(30);
3569       if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClassSelected->Fill(31);
3570    }
3571
3572    if(!isSelected)return kFALSE;
3573
3574    return kTRUE;
3575
3576 }
3577
3578 ///________________________________________________________________________
3579 Int_t AliConversionCuts::GetFirstTPCRow(Double_t radius){
3580    // Get first TPC row
3581    Int_t firstTPCRow = 0;
3582    Double_t radiusI = 84.8;
3583    Double_t radiusO = 134.6;
3584    Double_t radiusOB = 198.;
3585    Double_t rSizeI = 0.75;
3586    Double_t rSizeO = 1.;
3587    Double_t rSizeOB = 1.5;
3588    Int_t nClsI = 63;
3589    Int_t nClsIO = 127;
3590
3591    if(radius <= radiusI){
3592       return firstTPCRow;
3593    }
3594    if(radius>radiusI && radius<=radiusO){
3595       firstTPCRow = (Int_t)((radius-radiusI)/rSizeI);
3596    }
3597    if(radius>radiusO && radius<=radiusOB){
3598       firstTPCRow = (Int_t)(nClsI+(radius-radiusO)/rSizeO);
3599    }
3600
3601    if(radius>radiusOB){
3602       firstTPCRow =(Int_t)(nClsIO+(radius-radiusOB)/rSizeOB);
3603    }
3604
3605    return firstTPCRow;
3606 }
3607
3608 Bool_t AliConversionCuts::CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const {
3609    ///Check if passes cosine of pointing angle cut
3610    if(GetCosineOfPointingAngle(photon, event) < fCosPAngleCut){
3611       return kFALSE;
3612    }
3613    return kTRUE;
3614 }
3615
3616 Double_t AliConversionCuts::GetCosineOfPointingAngle( const AliConversionPhotonBase * photon, AliVEvent * event) const{
3617    // calculates the pointing angle of the recalculated V0
3618
3619    Double_t momV0[3] = {0,0,0};
3620    if(event->IsA()==AliESDEvent::Class()){
3621       AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(event);
3622       if(!esdEvent) return -999;
3623       AliESDv0 *v0 = esdEvent->GetV0(photon->GetV0Index());
3624       if(!v0) return -999;
3625       v0->GetPxPyPz(momV0[0],momV0[1],momV0[2]);
3626    }
3627    if(event->IsA()==AliAODEvent::Class()){
3628       momV0[0] = photon->GetPx();
3629       momV0[1] = photon->GetPy();
3630       momV0[2] = photon->GetPz();
3631    }
3632
3633    //Double_t momV0[3] = { photon->GetPx(), photon->GetPy(), photon->GetPz() }; //momentum of the V0
3634    Double_t PosV0[3] = { photon->GetConversionX() - event->GetPrimaryVertex()->GetX(),
3635                          photon->GetConversionY() - event->GetPrimaryVertex()->GetY(),
3636                          photon->GetConversionZ() - event->GetPrimaryVertex()->GetZ() }; //Recalculated V0 Position vector
3637
3638    Double_t momV02 = momV0[0]*momV0[0] + momV0[1]*momV0[1] + momV0[2]*momV0[2];
3639    Double_t PosV02 = PosV0[0]*PosV0[0] + PosV0[1]*PosV0[1] + PosV0[2]*PosV0[2];
3640
3641
3642    Double_t cosinePointingAngle = -999;
3643    if(momV02*PosV02 > 0.0)
3644       cosinePointingAngle = (PosV0[0]*momV0[0] +  PosV0[1]*momV0[1] + PosV0[2]*momV0[2] ) / TMath::Sqrt(momV02 * PosV02);
3645
3646    return cosinePointingAngle;
3647 }
3648
3649 ///________________________________________________________________________
3650 Bool_t AliConversionCuts::PsiPairCut(const AliConversionPhotonBase * photon) const {
3651
3652    if (fDo2DPsiPairChi2){
3653       if (abs(photon->GetPsiPair()) < -fPsiPairCut/fChi2CutConversion*photon->GetChi2perNDF() + fPsiPairCut ){  
3654          return kTRUE;
3655       } else {
3656          return kFALSE;
3657       }    
3658    } else {
3659       if(abs(photon->GetPsiPair()) > fPsiPairCut){
3660          return kFALSE;}
3661       else{return kTRUE;}
3662    } 
3663 }
3664
3665 ///________________________________________________________________________
3666 TString AliConversionCuts::GetCutNumber(){
3667    // returns TString with current cut number
3668    TString a(kNCuts);
3669    for(Int_t ii=0;ii<kNCuts;ii++){
3670       a.Append(Form("%d",fCuts[ii]));
3671    }
3672    return a;
3673 }
3674
3675 ///________________________________________________________________________
3676 void AliConversionCuts::FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0){
3677
3678    Int_t posLabel = photon->GetTrackLabelPositive();
3679    Int_t negLabel = photon->GetTrackLabelNegative();
3680
3681    fElectronLabelArray[nV0*2] = posLabel;
3682    fElectronLabelArray[(nV0*2)+1] = negLabel;
3683 }
3684 ///________________________________________________________________________
3685 Bool_t AliConversionCuts::RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s){
3686
3687    Int_t posLabel = photon->GetTrackLabelPositive();
3688    Int_t negLabel = photon->GetTrackLabelNegative();
3689
3690    for(Int_t i = 0; i<nV0s*2;i++){
3691       if(i==nV0*2)     continue;
3692       if(i==(nV0*2)+1) continue;
3693       if(fElectronLabelArray[i] == posLabel){
3694          return kFALSE;}
3695       if(fElectronLabelArray[i] == negLabel){
3696          return kFALSE;}
3697    }
3698
3699    return kTRUE;
3700 }
3701 ///________________________________________________________________________
3702 Bool_t AliConversionCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0){
3703
3704
3705    Double_t posX = photon->GetConversionX();
3706    Double_t posY = photon->GetConversionY();
3707    Double_t posZ = photon->GetConversionZ();
3708
3709    for(Int_t i = 0;i<photons->GetEntries();i++){
3710       if(nV0 == i) continue;
3711       AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
3712       Double_t posCompX = photonComp->GetConversionX();
3713       Double_t posCompY = photonComp->GetConversionY();
3714       Double_t posCompZ = photonComp->GetConversionZ();
3715
3716       Double_t dist = pow((posX - posCompX),2)+pow((posY - posCompY),2)+pow((posZ - posCompZ),2);
3717
3718       if(dist < fminV0Dist*fminV0Dist){
3719          if(photon->GetChi2perNDF() < photonComp->GetChi2perNDF()) return kTRUE;
3720          else {
3721             return kFALSE;}
3722       }
3723
3724    }
3725    return kTRUE;
3726 }
3727 ///________________________________________________________________________
3728 void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent){
3729
3730         TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->GetPeriodName();
3731
3732
3733         if(fNotRejectedStart){
3734                 delete[] fNotRejectedStart;
3735                 fNotRejectedStart = NULL;
3736         }
3737         if(fNotRejectedEnd){
3738                 delete[] fNotRejectedEnd;
3739                 fNotRejectedEnd = NULL;
3740         }
3741         if(fGeneratorNames){
3742                 delete[] fGeneratorNames;
3743                 fGeneratorNames = NULL;
3744         }
3745
3746         if(rejection == 0) return; // No Rejection
3747
3748         AliGenCocktailEventHeader *cHeader = 0x0;
3749         AliAODMCHeader *cHeaderAOD = 0x0;
3750         Bool_t headerFound = kFALSE;
3751         AliStack *fMCStack = 0x0;
3752         TClonesArray *fMCStackAOD = 0x0;
3753         if(MCEvent->IsA()==AliMCEvent::Class()){
3754                 cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
3755                 if(cHeader) headerFound = kTRUE;
3756                 fMCStack = dynamic_cast<AliStack*>(dynamic_cast<AliMCEvent*>(MCEvent)->Stack());
3757         }
3758         if(MCEvent->IsA()==AliAODEvent::Class()){ // MCEvent is a AODEvent in case of AOD
3759                 cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
3760                 fMCStackAOD = dynamic_cast<TClonesArray*>(MCEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3761                 
3762                 
3763                 if(cHeaderAOD) headerFound = kTRUE;
3764         }
3765
3766         if(headerFound){
3767                 TList *genHeaders = 0x0;
3768                 if(cHeader) genHeaders = cHeader->GetHeaders();
3769                 if(cHeaderAOD){
3770                         genHeaders = cHeaderAOD->GetCocktailHeaders();
3771                         if(genHeaders->GetEntries()==1){
3772                                 SetRejectExtraSignalsCut(0);
3773                                 return;
3774                         }
3775                 }
3776                 AliGenEventHeader* gh = 0;
3777                 fnHeaders = 0;
3778                 Int_t firstindexA = 0;
3779                 Int_t lastindexA =  -1;
3780                 if(rejection == 1 || rejection == 3) fnHeaders = 1; // MinBiasHeader
3781                 if(rejection == 2){ // TList of Headers Names
3782                         for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3783                                 gh = (AliGenEventHeader*)genHeaders->At(i);
3784                                 TString GeneratorName = gh->GetName();
3785                                 lastindexA = lastindexA + gh->NProduced();
3786 //                              cout << i << "\t" << GeneratorName.Data() << endl;
3787                                 for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3788                                         TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3789                                         if(GeneratorName.CompareTo(GeneratorInList) == 0){
3790                                                 if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
3791                                                         if(fMCStack){
3792                                                                 if (fMCStack->Particle(firstindexA)->GetPdgCode() == fAddedSignalPDGCode ) {
3793                                                                         if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
3794                                                                                 if (gh->NProduced() > 10 && fMCStack->Particle(firstindexA+10)->GetPdgCode() == fAddedSignalPDGCode ){
3795 //                                                                                      cout << "cond 1: "<< fnHeaders << endl;
3796                                                                                         fnHeaders++;
3797                                                                                         continue;
3798                                                                                 }       
3799                                                                                 continue;
3800                                                                         } else {
3801 //                                                                              cout << "cond 2: " << fnHeaders << endl;
3802                                                                                 fnHeaders++;
3803                                                                                 continue;
3804                                                                         }       
3805                                                                 }
3806                                                         }   
3807                                                         if ( fMCStackAOD){
3808                                                                 AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA));
3809                                                                 if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
3810                                                                         if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
3811                                                                                 if (gh->NProduced() > 10){
3812                                                                                         AliAODMCParticle *aodMCParticle2 = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA+10));
3813                                                                                         if (  aodMCParticle2->GetPdgCode() == fAddedSignalPDGCode ){
3814 //                                                                                              cout << "cond 1: " << fnHeaders << endl;
3815                                                                                                 fnHeaders++;
3816                                                                                                 continue;
3817                                                                                         } 
3818                                                                                 }       
3819                                                                                 continue;
3820                                                                         } else {
3821 //                                                                              cout << "cond 2: " << fnHeaders << endl;
3822                                                                                 fnHeaders++;
3823                                                                                 continue;
3824                                                                         }       
3825                                                                 }   
3826                                                         }
3827                                                         continue;
3828                                                 }
3829 //                                              cout << "cond 3: "<< fnHeaders << endl;
3830                                                 fnHeaders++;
3831                                                 continue;
3832                                         }
3833                                 }
3834                                 firstindexA = firstindexA + gh->NProduced();
3835                         }
3836                 }
3837 //              cout << "number of headers: " <<fnHeaders << endl;
3838                 
3839                 fNotRejectedStart = new Int_t[fnHeaders];
3840                 fNotRejectedEnd = new Int_t[fnHeaders];
3841                 fGeneratorNames = new TString[fnHeaders];
3842
3843                 if(rejection == 1 || rejection == 3){
3844                         fNotRejectedStart[0] = 0;
3845                         fNotRejectedEnd[0] = ((AliGenEventHeader*)genHeaders->At(0))->NProduced()-1;
3846                         fGeneratorNames[0] = ((AliGenEventHeader*)genHeaders->At(0))->GetName();
3847                         return;
3848                 }
3849
3850                 Int_t firstindex = 0;
3851                 Int_t lastindex =  -1;
3852                 Int_t number = 0;
3853                 
3854                 for(Int_t i = 0; i<genHeaders->GetEntries();i++){
3855                         gh = (AliGenEventHeader*)genHeaders->At(i);
3856                         TString GeneratorName = gh->GetName();
3857                         lastindex = lastindex + gh->NProduced();
3858                         for(Int_t j = 0; j<HeaderList->GetEntries();j++){
3859                                 TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
3860 //                              cout << i << "\t" << GeneratorName.Data() << endl;
3861                                 if(GeneratorName.CompareTo(GeneratorInList) == 0){
3862                                         if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
3863                                                 if(fMCStack){
3864                                                         if (fMCStack->Particle(firstindex)->GetPdgCode() == fAddedSignalPDGCode ) {
3865                                                                 if (periodName.CompareTo(