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