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