added new conversion task (gamma, gamma & dalitz task) + corresponding dependencies
[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 "AliLog.h"
43
44 class iostream;
45
46 using namespace std;
47
48 ClassImp(AliConversionCuts)
49
50
51 const char* AliConversionCuts::fgkCutNames[AliConversionCuts::kNCuts] = {
52 "GoodId",
53 "V0FinderType",
54 "eProbCut",
55 "ededxSigmaCut",
56 "pidedxSigmaCut",
57 "piMomdedxSigmaCut",
58 "Chi2GammaCut",
59 "SinglePtCut",
60 "ClsTPCCut",
61 "EtaCut",
62 "Chi2MesonCut",
63 "LowPRejectionSigmaCut",
64 "QtMaxCut",
65 "piMaxMomdedxSigmaCut",
66 "AlphaMesonCut",
67 "MinRCut",
68 "RapidityMesonCut",
69 "BackgroundScheme",
70 "DegreesForRotationMethod",
71 "NumberOfRotations",
72 "RemovePileUp",
73 "SelectV0AND",
74 "MultiplicityMethod",
75 "HeavyIon",
76 "CentralityMin",
77 "CentralityMax",
78 "TOFelectronPID",
79 "UseMCPSmearing",
80 "DoPhotonAsymmetryCut",
81 "PsiPair",
82 "CosinePointingAngle",
83 "SharedElectronCuts",
84 "RejectToCloseV0s",
85 };
86
87
88 //________________________________________________________________________
89 AliConversionCuts::AliConversionCuts(const char *name,const char *title) : AliAnalysisCuts(name,title),
90     fHistograms(NULL),
91     fPIDResponse(NULL),
92     fEventQuality(-1),
93     fMaxR(200),
94     fMinR(0),
95     fEtaCut(0.9),
96     fEtaCutMin(-0.1),
97     fPtCut(0.02),
98     fSinglePtCut(0),
99     fMaxZ(1000),
100     fMinClsTPC(0.),
101     fMinClsTPCToF(0.),
102     fLineCutZRSlope(0.),
103     fLineCutZValue(0),
104     fLineCutZRSlopeMin(0.),
105     fLineCutZValueMin(0),
106     fChi2CutConversion(1000),
107     fChi2CutMeson(1000),
108     fPIDProbabilityCutNegativeParticle(0),
109     fPIDProbabilityCutPositiveParticle(0),
110     fDodEdxSigmaCut(kTRUE),
111     fDoTOFsigmaCut(kFALSE), // RRnewTOF
112     fPIDTRDEfficiency(1),
113     fDoTRDPID(kFALSE),
114     fPIDnSigmaAboveElectronLine(100),
115     fPIDnSigmaBelowElectronLine(-100),
116     fTofPIDnSigmaAboveElectronLine(100), // RRnewTOF
117     fTofPIDnSigmaBelowElectronLine(-100), // RRnewTOF
118     fPIDnSigmaAbovePionLine(0),
119     fPIDnSigmaAbovePionLineHighPt(-100),
120     fPIDMinPnSigmaAbovePionLine(0),
121     fPIDMaxPnSigmaAbovePionLine(0),
122     fDoKaonRejectionLowP(kFALSE),
123     fDoProtonRejectionLowP(kFALSE),
124     fDoPionRejectionLowP(kFALSE),
125     fPIDnSigmaAtLowPAroundKaonLine(0),
126     fPIDnSigmaAtLowPAroundProtonLine(0),
127     fPIDnSigmaAtLowPAroundPionLine(0),
128     fPIDMinPKaonRejectionLowP(0),
129     fPIDMinPProtonRejectionLowP(0),
130     fPIDMinPPionRejectionLowP(0),
131     fDoQtGammaSelection(kTRUE),
132     fDoHighPtQtGammaSelection(kFALSE), // RRnew
133     fQtMax(100),
134     fHighPtQtMax(0.), // RRnew
135     fPtBorderForQt(0), // RRnew
136     fXVertexCut(0.),
137     fYVertexCut(0.),
138     fZVertexCut(0.),
139     fNSigmaMass(0.),
140     fUseEtaMinCut(kFALSE),
141     fUseOnFlyV0Finder(kTRUE),
142     fDoPhotonAsymmetryCut(kTRUE),
143     fMinPPhotonAsymmetryCut(100.),
144     fMinPhotonAsymmetry(0.),
145     fIsHeavyIon(kFALSE),
146     fDetectorCentrality(0),
147     fModCentralityClass(0),
148     fMaxVertexZ(10),
149     fCentralityMin(0),
150     fCentralityMax(0),
151     fUseCorrectedTPCClsInfo(kFALSE),
152     fUseTOFpid(kFALSE),
153     fAlphaMinCutMeson(0),
154     fAlphaCutMeson(1),
155     fRapidityCutMeson(1),
156     fUseRotationMethodInBG(kFALSE),
157     fdoBGProbability(kFALSE),
158     fUseTrackMultiplicityForBG(kFALSE),
159     fnDegreeRotationPMForBG(0),
160     fnumberOfRotationEventsForBG(0),
161     fUseMCPSmearing(kFALSE),
162     fPBremSmearing(0),
163     fPSigSmearing(0),
164     fPSigSmearingCte(0),
165     fBrem(NULL),
166     fMultiplicityMethod(0),
167     fSelectV0AND(kFALSE),
168     fRemovePileUp(kFALSE),
169     fOpeningAngle(0.005),
170     fPsiPairCut(10000),
171     fCosPAngleCut(10000),
172     fDoToCloseV0sCut(kFALSE),
173     fminV0Dist(200.),
174     fDoSharedElecCut(kFALSE),
175     fOfflineTriggerMask(0),
176     fRandom(0),
177     fElectronLabelArray(NULL),
178     fCutString(NULL),
179     hdEdxCuts(NULL),
180     hTPCdEdxbefore(NULL),
181     hTPCdEdxafter(NULL),
182     hTOFbefore(NULL),
183     hTOFafter(NULL),
184     hTrackCuts(NULL),
185     hPhotonCuts(NULL),
186     hInvMassbefore(NULL),
187     hArmenterosbefore(NULL),
188     hInvMassafter(NULL),
189     hArmenterosafter(NULL),
190     hAcceptanceCuts(NULL),
191     hCutIndex(NULL),
192     hV0EventCuts(NULL),
193     hCentrality(NULL),
194     hVertexZ(NULL),
195     hTriggerClass(NULL),
196     hMesonCuts(NULL),
197     hMesonBGCuts(NULL)
198 {
199     InitPIDResponse();
200     for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
201     fCutString=new TObjString((GetCutNumber()).Data());
202
203     if (fBrem == NULL){
204        fBrem = new TF1("fBrem","pow(-log(x),[0]/log(2.0)-1.0)/TMath::Gamma([0]/log(2.0))",0.00001,0.999999999);
205        // tests done with 1.0e-14
206        fBrem->SetParameter(0,fPBremSmearing);
207        fBrem->SetNpx(100000);
208     }
209
210     fElectronLabelArray = new Int_t[500];
211 }
212
213 //________________________________________________________________________
214 AliConversionCuts::~AliConversionCuts() {
215     // Destructor
216   //Deleting fHistograms leads to seg fault it it's added to output collection of a task
217   // if(fHistograms)
218   //    delete fHistograms;
219   // fHistograms = NULL;
220    if(fCutString != NULL){
221       delete fCutString;
222       fCutString = NULL;
223    }
224    if(fBrem){
225       delete fBrem;
226       fBrem = NULL;
227    }
228    if(fElectronLabelArray){
229       delete fElectronLabelArray;
230       fElectronLabelArray = NULL;
231    }
232
233 }
234
235 //________________________________________________________________________
236 void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
237
238     // Initialize Cut Histograms for QA (only initialized and filled if function is called)
239
240     if(fHistograms != NULL){
241         delete fHistograms;
242         fHistograms=NULL;
243     }
244     if(fHistograms==NULL){
245         fHistograms=new TList();
246         if(name=="")fHistograms->SetName(Form("ConvCuts_%s",GetCutNumber().Data()));
247         else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
248     }
249
250     // IsPhotonSelected
251     hCutIndex=new TH1F(Form("IsPhotonSelected %s",GetCutNumber().Data()),"IsPhotonSelected",10,-0.5,9.5);
252     hCutIndex->GetXaxis()->SetBinLabel(kPhotonIn+1,"in");
253     hCutIndex->GetXaxis()->SetBinLabel(kOnFly+1,"onfly");
254     hCutIndex->GetXaxis()->SetBinLabel(kNoTracks+1,"no tracks");
255     hCutIndex->GetXaxis()->SetBinLabel(kdEdxCuts+1,"dEdx");
256     hCutIndex->GetXaxis()->SetBinLabel(kTrackCuts+1,"Track cuts");
257     hCutIndex->GetXaxis()->SetBinLabel(kConvPointFail+1,"ConvPoint fail");
258     hCutIndex->GetXaxis()->SetBinLabel(kPhotonCuts+1,"PhotonCuts");
259     hCutIndex->GetXaxis()->SetBinLabel(kPhotonOut+1,"out");
260     fHistograms->Add(hCutIndex);
261
262     // Track Cuts
263     hTrackCuts=new TH1F(Form("TrackCuts %s",GetCutNumber().Data()),"TrackCuts",10,-0.5,9.5);
264     hTrackCuts->GetXaxis()->SetBinLabel(1,"in");
265     hTrackCuts->GetXaxis()->SetBinLabel(2,"likesign");
266     hTrackCuts->GetXaxis()->SetBinLabel(3,"ntpccl");
267     hTrackCuts->GetXaxis()->SetBinLabel(4,"acceptance");
268     hTrackCuts->GetXaxis()->SetBinLabel(5,"singlept");
269     hTrackCuts->GetXaxis()->SetBinLabel(6,"TPCrefit");
270     hTrackCuts->GetXaxis()->SetBinLabel(7,"kink");
271     hTrackCuts->GetXaxis()->SetBinLabel(8,"out");
272     fHistograms->Add(hTrackCuts);
273
274     // Photon Cuts
275     hPhotonCuts=new TH1F(Form("PhotonCuts %s",GetCutNumber().Data()),"PhotonCuts",12,-0.5,11.5);
276     hPhotonCuts->GetXaxis()->SetBinLabel(1,"in");
277     hPhotonCuts->GetXaxis()->SetBinLabel(2,"qtcut");
278     hPhotonCuts->GetXaxis()->SetBinLabel(3,"chi2");
279     hPhotonCuts->GetXaxis()->SetBinLabel(4,"acceptance");
280     hPhotonCuts->GetXaxis()->SetBinLabel(5,"asymmetry");
281     hPhotonCuts->GetXaxis()->SetBinLabel(6,"pidprob");
282     hPhotonCuts->GetXaxis()->SetBinLabel(7,"cortpcclinfo");
283     hPhotonCuts->GetXaxis()->SetBinLabel(8,"PsiPair");
284     hPhotonCuts->GetXaxis()->SetBinLabel(9,"CosPAngle");
285     hPhotonCuts->GetXaxis()->SetBinLabel(10,"out");
286     fHistograms->Add(hPhotonCuts);
287
288     if(preCut){
289        hInvMassbefore=new TH1F(Form("InvMass_before %s",GetCutNumber().Data()),"InvMass_before",100,0,0.3);
290        fHistograms->Add(hInvMassbefore);
291        hArmenterosbefore=new TH2F(Form("Armenteros_before %s",GetCutNumber().Data()),"Armenteros_before",200,-1,1,250,0,0.25);
292        fHistograms->Add(hArmenterosbefore);
293     }
294     hInvMassafter=new TH1F(Form("InvMass_after %s",GetCutNumber().Data()),"InvMass_after",100,0,0.3);
295     fHistograms->Add(hInvMassafter);
296     hArmenterosafter=new TH2F(Form("Armenteros_after %s",GetCutNumber().Data()),"Armenteros_after",200,-1,1,250,0,0.25);
297     fHistograms->Add(hArmenterosafter);
298
299     hAcceptanceCuts=new TH1F(Form("PhotonAcceptanceCuts %s",GetCutNumber().Data()),"PhotonAcceptanceCuts",10,-0.5,9.5);
300     hAcceptanceCuts->GetXaxis()->SetBinLabel(1,"in");
301     hAcceptanceCuts->GetXaxis()->SetBinLabel(2,"maxR");
302     hAcceptanceCuts->GetXaxis()->SetBinLabel(3,"minR");
303     hAcceptanceCuts->GetXaxis()->SetBinLabel(4,"line");
304     hAcceptanceCuts->GetXaxis()->SetBinLabel(5,"maxZ");
305     hAcceptanceCuts->GetXaxis()->SetBinLabel(6,"eta");
306     hAcceptanceCuts->GetXaxis()->SetBinLabel(7,"minpt");
307     hAcceptanceCuts->GetXaxis()->SetBinLabel(8,"out");
308     fHistograms->Add(hAcceptanceCuts);
309
310     // dEdx Cuts
311     hdEdxCuts=new TH1F(Form("dEdxCuts %s",GetCutNumber().Data()),"dEdxCuts",10,-0.5,9.5);
312     hdEdxCuts->GetXaxis()->SetBinLabel(1,"in");
313     hdEdxCuts->GetXaxis()->SetBinLabel(2,"TPCelectron");
314     hdEdxCuts->GetXaxis()->SetBinLabel(3,"TPCpion");
315     hdEdxCuts->GetXaxis()->SetBinLabel(4,"TPCpionhighp");
316     hdEdxCuts->GetXaxis()->SetBinLabel(5,"TPCkaonlowprej");
317     hdEdxCuts->GetXaxis()->SetBinLabel(6,"TPCprotonlowprej");
318     hdEdxCuts->GetXaxis()->SetBinLabel(7,"TPCpionlowprej");
319     hdEdxCuts->GetXaxis()->SetBinLabel(8,"TOFelectron");
320     hdEdxCuts->GetXaxis()->SetBinLabel(9,"TRDelectron");
321     hdEdxCuts->GetXaxis()->SetBinLabel(10,"out");
322     fHistograms->Add(hdEdxCuts);
323     
324     TAxis *AxisBeforedEdx = NULL;
325     TAxis *AxisBeforeTOF = NULL;
326     if(preCut){
327        hTPCdEdxbefore=new TH2F(Form("Gamma_dEdx_before %s",GetCutNumber().Data()),"dEdx Gamma before" ,150,0.05,20,400,-10,10);
328        fHistograms->Add(hTPCdEdxbefore);
329        AxisBeforedEdx = hTPCdEdxbefore->GetXaxis(); 
330
331        hTOFbefore=new TH2F(Form("Gamma_TOF_before %s",GetCutNumber().Data()),"TOF Gamma before" ,150,0.05,20,400,-6,10);
332        fHistograms->Add(hTOFbefore);
333        AxisBeforeTOF = hTOFbefore->GetXaxis(); 
334     }
335     hTPCdEdxafter=new TH2F(Form("Gamma_dEdx_after %s",GetCutNumber().Data()),"dEdx Gamma after" ,150,0.05,20,400, -10,10);
336     fHistograms->Add(hTPCdEdxafter);
337
338     hTOFafter=new TH2F(Form("Gamma_TOF_after %s",GetCutNumber().Data()),"TOF Gamma after" ,150,0.05,20,400,-6,10);
339     fHistograms->Add(hTOFafter);
340
341     TAxis *AxisAfter = hTPCdEdxafter->GetXaxis(); 
342     Int_t bins = AxisAfter->GetNbins();
343     Double_t from = AxisAfter->GetXmin();
344     Double_t to = AxisAfter->GetXmax();
345     Double_t *newBins = new Double_t[bins+1];
346     newBins[0] = from;
347     Double_t factor = TMath::Power(to/from, 1./bins);
348     for(Int_t i=1; i<=bins; ++i) newBins[i] = factor * newBins[i-1];
349     AxisAfter->Set(bins, newBins);
350     AxisAfter = hTOFafter->GetXaxis(); 
351     AxisAfter->Set(bins, newBins);
352     if(preCut){
353        AxisBeforedEdx->Set(bins, newBins);
354        AxisBeforeTOF->Set(bins, newBins);
355     }
356     delete [] newBins;
357         
358     // Event Cuts and Info
359     if(preCut){
360        hV0EventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",10,-0.5,9.5);
361        hV0EventCuts->GetXaxis()->SetBinLabel(1,"in");
362        hV0EventCuts->GetXaxis()->SetBinLabel(2,"OfflineTrigger");
363        hV0EventCuts->GetXaxis()->SetBinLabel(3,"VertexZ");
364        hV0EventCuts->GetXaxis()->SetBinLabel(4,"nvtxcontr");
365        hV0EventCuts->GetXaxis()->SetBinLabel(5,"pileup");
366        hV0EventCuts->GetXaxis()->SetBinLabel(6,"centrsel");
367        hV0EventCuts->GetXaxis()->SetBinLabel(7,"out");
368        fHistograms->Add(hV0EventCuts);
369        
370        hCentrality=new TH1F(Form("Centrality %s",GetCutNumber().Data()),"Centrality",100,0,100);
371        fHistograms->Add(hCentrality);
372        hVertexZ=new TH1F(Form("VertexZ %s",GetCutNumber().Data()),"VertexZ",1000,-50,50);
373        fHistograms->Add(hVertexZ);
374        
375        hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",4,-0.5,3.5);
376        hTriggerClass->GetXaxis()->SetBinLabel(1,"kAny");
377        hTriggerClass->GetXaxis()->SetBinLabel(2,"kMB");
378        hTriggerClass->GetXaxis()->SetBinLabel(3,"kCentral");
379        hTriggerClass->GetXaxis()->SetBinLabel(4,"kSemiCentral");
380        fHistograms->Add(hTriggerClass);
381     }
382     
383     // Meson Cuts
384     hMesonCuts=new TH1F(Form("MesonCuts %s",GetCutNumber().Data()),"MesonCuts",10,-0.5,9.5);
385     hMesonCuts->GetXaxis()->SetBinLabel(1,"in");
386     hMesonCuts->GetXaxis()->SetBinLabel(2,"undef rapidity");
387     hMesonCuts->GetXaxis()->SetBinLabel(3,"rapidity cut");
388     hMesonCuts->GetXaxis()->SetBinLabel(4,"opening angle");
389     hMesonCuts->GetXaxis()->SetBinLabel(5,"alpha max");
390     hMesonCuts->GetXaxis()->SetBinLabel(6,"alpha min");
391     hMesonCuts->GetXaxis()->SetBinLabel(7,"out");
392     fHistograms->Add(hMesonCuts);
393
394     hMesonBGCuts=new TH1F(Form("MesonBGCuts %s",GetCutNumber().Data()),"MesonBGCuts",10,-0.5,9.5);
395     hMesonBGCuts->GetXaxis()->SetBinLabel(1,"in");
396     hMesonBGCuts->GetXaxis()->SetBinLabel(2,"undef rapidity");
397     hMesonBGCuts->GetXaxis()->SetBinLabel(3,"rapidity cut");
398     hMesonBGCuts->GetXaxis()->SetBinLabel(4,"opening angle");
399     hMesonBGCuts->GetXaxis()->SetBinLabel(5,"alpha max");
400     hMesonBGCuts->GetXaxis()->SetBinLabel(6,"alpha min");
401     hMesonBGCuts->GetXaxis()->SetBinLabel(7,"out");
402     fHistograms->Add(hMesonBGCuts);
403 }
404
405 //________________________________________________________________________
406 Bool_t AliConversionCuts::InitPIDResponse(){
407     // Set Pointer to AliPIDResponse
408
409   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
410   if(man) { 
411         AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
412     fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
413     if(fPIDResponse)return kTRUE;
414     
415   }
416   
417   return kFALSE;
418 }
419 ///________________________________________________________________________
420 Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent){
421     // Process Event Selection
422
423     Int_t cutindex=0;
424     if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
425     cutindex++;
426     
427     // Check for MC event
428     if(fMCEvent){
429        // Check if MC event is correctly loaded
430        AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
431        if (!mcHandler){
432           fEventQuality = 2;
433           return kFALSE;
434        }
435        if (!mcHandler->InitOk() ){
436           fEventQuality = 2;
437           return kFALSE;
438        }
439        if (!mcHandler->TreeK() ){
440           fEventQuality = 2;
441           return kFALSE;
442        }
443        if (!mcHandler->TreeTR() ) {
444           fEventQuality = 2;
445           return kFALSE;
446        }
447     }
448     
449     // Event Trigger
450
451     if(!IsTriggerSelected()){
452         if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
453         fEventQuality = 3;
454         return kFALSE;
455     }
456     cutindex++;
457
458     // Z Vertex Position Cut
459     if(!VertexZCut(fInputEvent)){
460         if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
461         fEventQuality = 4;
462         return kFALSE;
463     }
464     cutindex++;
465
466     // Number of Contributors Cut
467     if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
468         if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
469         fEventQuality = 5;
470         return kFALSE;
471     }
472     cutindex++;
473
474     // Pile Up Rejection
475
476     if(fRemovePileUp){
477         if(fInputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
478             if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
479             fEventQuality = 6;
480             return kFALSE;
481         }
482     }
483     cutindex++;
484
485     // Centrality Selection
486     if(!IsCentralitySelected(fInputEvent)){
487         if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
488         fEventQuality = 1;
489         return kFALSE;
490     }
491     cutindex++;
492
493     // Fill Event Histograms
494     if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
495     if(hVertexZ)hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
496     if(hCentrality)hCentrality->Fill(GetCentrality(fInputEvent));
497
498     fEventQuality = 0;
499     return kTRUE;
500 }
501
502 ///________________________________________________________________________
503 Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCStack,Bool_t checkForConvertedGamma){
504     // MonteCarlo Photon Selection
505
506     if(!fMCStack)return kFALSE;
507
508     if (particle->GetPdgCode() == 22){
509               
510         if(particle->R() > fMaxR)       return kFALSE;
511         if(TMath::Abs(particle->Eta())> fEtaCut || TMath::Abs(particle->Eta())< fEtaCutMin)     return kFALSE;
512
513         if(particle->GetMother(0) >-1 && fMCStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
514             return kFALSE; // no photon as mothers!
515         }
516
517         if(particle->GetMother(0) >= fMCStack->GetNprimary()){
518             return kFALSE; // the gamma has a mother, and it is not a primary particle
519         }
520
521         if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
522
523         // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
524         TParticle* ePos = NULL;
525         TParticle* eNeg = NULL;
526
527         if(particle->GetNDaughters() >= 2){
528             for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
529                 TParticle *tmpDaughter = fMCStack->Particle(daughterIndex);
530                 if(tmpDaughter->GetUniqueID() == 5){
531                     if(tmpDaughter->GetPdgCode() == 11){
532                         eNeg = tmpDaughter;
533                     } else if(tmpDaughter->GetPdgCode() == -11){
534                         ePos = tmpDaughter;
535                     }
536                 }
537             }
538         }
539
540         if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
541             return kFALSE;
542         }
543         
544         if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
545            return kFALSE; // no reconstruction below the Pt cut
546         }
547         
548         if( TMath::Abs(ePos->Eta())> fEtaCut || TMath::Abs(ePos->Eta())< fEtaCutMin || 
549             TMath::Abs(eNeg->Eta())> fEtaCut || TMath::Abs(eNeg->Eta())< fEtaCutMin ) {
550            return kFALSE;
551         }
552         
553         if(ePos->R()>fMaxR){
554            return kFALSE; // cuts on distance from collision point
555         }
556
557         if(TMath::Abs(ePos->Vz()) > fMaxZ){
558            return kFALSE;        // outside material
559         }
560         if(TMath::Abs(eNeg->Vz()) > fMaxZ){
561            return kFALSE;        // outside material
562         }
563
564         if( ePos->R() <= ((TMath::Abs(ePos->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
565            return kFALSE;  // line cut to exclude regions where we do not reconstruct
566         } else if ( fEtaCutMin != -0.1 &&   ePos->R() >= ((TMath::Abs(ePos->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
567            return kFALSE;
568         }
569         
570         if( eNeg->R() <= ((TMath::Abs(eNeg->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
571            return kFALSE; // line cut to exclude regions where we do not reconstruct
572         } else if ( fEtaCutMin != -0.1 &&   eNeg->R() >= ((TMath::Abs(eNeg->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
573            return kFALSE;
574         }
575         
576         return kTRUE;
577         //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
578     }
579     return kFALSE;
580 }
581
582
583 //________________________________________________________________________
584 Bool_t AliConversionCuts::MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack,Bool_t bMCDaughtersInAcceptance){
585     // Returns true for all pions within acceptance cuts for decay into 2 photons
586     // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
587
588     if(!fMCStack)return kFALSE;
589     
590     if(fMCMother->GetPdgCode()==111 || fMCMother->GetPdgCode()==221){
591        
592        if(fMCMother->R()>fMaxR) return kFALSE; // cuts on distance from collision point
593
594        Double_t rapidity = 10.;
595        if(fMCMother->Energy() - fMCMother->Pz() == 0 || fMCMother->Energy() + fMCMother->Pz() == 0){
596           rapidity=8.;
597        }
598        else{
599           rapidity = 0.5*(TMath::Log((fMCMother->Energy()+fMCMother->Pz()) / (fMCMother->Energy()-fMCMother->Pz())));
600        }        
601        
602        // Rapidity Cut
603        if(TMath::Abs(rapidity)>fRapidityCutMeson)return kFALSE;
604
605         // Select only -> 2y decay channel
606         if(fMCMother->GetNDaughters()!=2)return kFALSE;
607
608         for(Int_t i=0;i<2;i++){
609             TParticle *MDaughter=fMCStack->Particle(fMCMother->GetDaughter(i));
610
611             // Is Daughter a Photon?
612             if(MDaughter->GetPdgCode()!=22)return kFALSE;
613             // Is Photon in Acceptance?
614             if(bMCDaughtersInAcceptance){
615                 if(!PhotonIsSelectedMC(MDaughter,fMCStack)){return kFALSE;}
616             }
617         }
618         return kTRUE;
619     }
620     return kFALSE;
621 }
622
623 ///________________________________________________________________________
624 Bool_t AliConversionCuts::PhotonCuts(AliConversionPhotonBase *photon,AliVEvent *event)
625 {   // Specific Photon Cuts
626
627     Int_t cutIndex = 0;
628     if(hPhotonCuts)hPhotonCuts->Fill(cutIndex);
629     cutIndex++;
630
631     // Fill Histos before Cuts
632     if(hInvMassbefore)hInvMassbefore->Fill(photon->GetMass());
633     if(hArmenterosbefore)hArmenterosbefore->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
634
635     // Gamma selection based on QT from Armenteros
636     if(fDoQtGammaSelection == kTRUE){
637         if(!ArmenterosQtCut(photon)){
638             if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //1
639             return kFALSE;
640         }
641     }
642     cutIndex++; //2
643
644     // Chi Cut
645     if(photon->GetChi2perNDF() > fChi2CutConversion || photon->GetChi2perNDF() <=0){
646         {
647             if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //2
648             return kFALSE;
649         }
650     }
651     cutIndex++;//3
652
653     // Reconstruction Acceptance Cuts
654     if(!AcceptanceCuts(photon)){
655         if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //3
656         return kFALSE;
657     }
658
659     cutIndex++; //4
660     // Asymmetry Cut
661     if(fDoPhotonAsymmetryCut == kTRUE){
662         if(!AsymmetryCut(photon,event)){
663             if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //4
664             return kFALSE;
665         }
666     }
667
668     //Check the pid probability
669     cutIndex++; //5
670     if(!PIDProbabilityCut(photon, event)) {
671         if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //5
672         return kFALSE;
673     }
674
675     cutIndex++; //6
676     if(!CorrectedTPCClusterCut(photon, event)) {
677         if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //6
678         return kFALSE;
679     }
680
681
682     cutIndex++; //7
683     if(!PsiPairCut(photon)) {
684           if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //7
685           return kFALSE;
686     }
687
688     cutIndex++; //8
689     if(!CosinePAngleCut(photon, event)) {
690           if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //8
691           return kFALSE;
692     }
693
694     cutIndex++; //9
695     if(hPhotonCuts)hPhotonCuts->Fill(cutIndex); //9
696
697     // Histos after Cuts
698     if(hInvMassafter)hInvMassafter->Fill(photon->GetMass());
699     if(hArmenterosafter)hArmenterosafter->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
700
701
702     return kTRUE;
703
704 }
705
706 ///________________________________________________________________________
707 Bool_t AliConversionCuts::CorrectedTPCClusterCut(AliConversionPhotonBase *photon, AliVEvent * event)
708 {   //Cut on corrected TPC Cluster Info
709
710     AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
711     AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
712
713     if(!negTrack||!posTrack)return kFALSE;
714
715     Double_t negclsToF=0;
716
717     if (!fUseCorrectedTPCClsInfo ){
718         if(negTrack->GetTPCNclsF()!=0){
719             negclsToF = (Double_t)negTrack->GetNcls(1)/(Double_t)negTrack->GetTPCNclsF();}// Ncluster/Nfindablecluster
720     }
721     else {
722         negclsToF = negTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
723     }
724
725     Double_t posclsToF = 0.;
726     if (!fUseCorrectedTPCClsInfo ){
727         if(posTrack->GetTPCNclsF()!=0   ){
728             posclsToF = (Double_t)posTrack->GetNcls(1)/(Double_t)posTrack->GetTPCNclsF();
729         }
730     }else{
731         posclsToF = posTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
732     }
733
734     if( negclsToF < fMinClsTPCToF ||    posclsToF < fMinClsTPCToF ){
735     return kFALSE;
736     }
737
738     return kTRUE;
739 }
740
741 ///________________________________________________________________________
742 Bool_t AliConversionCuts::PhotonIsSelected(AliConversionPhotonBase *photon, AliVEvent * event)
743 {
744     //Selection of Reconstructed Photons
745
746     FillPhotonCutIndex(kPhotonIn);
747
748     // Get Tracks
749     AliVTrack * negTrack = GetTrack(event, photon->GetTrackLabelNegative());
750     AliVTrack * posTrack = GetTrack(event, photon->GetTrackLabelPositive());
751
752     if(!negTrack || !posTrack) {
753         FillPhotonCutIndex(kNoTracks);
754         return kFALSE;
755     }
756
757     // dEdx Cuts
758     if(!dEdxCuts(negTrack) || !dEdxCuts(posTrack)) {
759         FillPhotonCutIndex(kdEdxCuts);
760         return kFALSE;
761     }
762
763     // Track Cuts
764     if(!TracksAreSelected(negTrack, posTrack)){
765         FillPhotonCutIndex(kTrackCuts);
766         return kFALSE;
767     }
768
769     // Photon Cuts
770     if(!PhotonCuts(photon,event)){
771         FillPhotonCutIndex(kPhotonCuts);
772         return kFALSE;
773     }
774
775     // Photon passed cuts
776     FillPhotonCutIndex(kPhotonOut);
777     return kTRUE;
778 }
779
780 ///________________________________________________________________________
781 Bool_t AliConversionCuts::MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal)
782 {
783     // Selection of reconstructed Meson candidates
784     // Use flag IsSignal in order to fill Fill different
785     // histograms for Signal and Background
786     TH1 *hist=0x0;
787
788     if(IsSignal){hist=hMesonCuts;
789     }
790     else{hist=hMesonBGCuts;}
791
792     Int_t cutIndex=0;
793     if(hist)hist->Fill(cutIndex);
794     cutIndex++;
795
796     // Undefined Rapidity -> Floating Point exception
797     if((pi0->E()+pi0->Pz())/(pi0->E()-pi0->Pz())<=0){
798         if(hist)hist->Fill(cutIndex);
799         cutIndex++;
800         return kFALSE;
801     }
802     else{
803         // PseudoRapidity Cut --> But we cut on Rapidity !!!
804         cutIndex++;
805         if(TMath::Abs(pi0->Rapidity())>fRapidityCutMeson){
806         //if(TMath::Abs(pi0->PseudoRapidity())>fRapidityCutMeson){
807             if(hist)hist->Fill(cutIndex);
808             return kFALSE;
809         }
810     }
811     cutIndex++;
812
813     // Opening Angle Cut
814     //fOpeningAngle=2*TMath::ATan(0.134/pi0->P());// physical minimum opening angle
815     if(pi0->GetOpeningAngle()<fOpeningAngle){
816         if(hist)hist->Fill(cutIndex);
817         return kFALSE;
818     }
819     cutIndex++;
820
821     // Alpha Max Cut
822     if(pi0->GetAlpha()>fAlphaCutMeson){
823         if(hist)hist->Fill(cutIndex);
824         return kFALSE;
825     }
826     cutIndex++;
827
828     // Alpha Min Cut
829     if(pi0->GetAlpha()<fAlphaMinCutMeson){
830         if(hist)hist->Fill(cutIndex);
831         return kFALSE;
832     }
833     cutIndex++;
834
835     if(hist)hist->Fill(cutIndex);
836     return kTRUE;
837 }
838
839
840 ///________________________________________________________________________
841 Bool_t AliConversionCuts::ArmenterosQtCut(AliConversionPhotonBase *photon)
842 {   // Armenteros Qt Cut
843
844   if(fDoHighPtQtGammaSelection){
845         if(photon->GetPhotonPt() < fPtBorderForQt){
846           if(photon->GetArmenterosQt()>fQtMax){
847                 return kFALSE;
848           }
849         } else {
850           if(photon->GetArmenterosQt()>fHighPtQtMax){
851                 return kFALSE;
852           }
853         }
854   } else {
855
856         if(photon->GetArmenterosQt()>fQtMax){
857           return kFALSE;
858         }
859   }
860   return kTRUE;
861 }
862
863
864 ///________________________________________________________________________
865 Bool_t AliConversionCuts::AcceptanceCuts(AliConversionPhotonBase *photon) {
866     // Exclude certain areas for photon reconstruction
867
868     Int_t cutIndex=0;
869     if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
870     cutIndex++;
871
872     if(photon->GetConversionRadius()>fMaxR){ // cuts on distance from collision point
873         if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
874         return kFALSE;
875     }
876     cutIndex++;
877
878     if(photon->GetConversionRadius()<fMinR){ // cuts on distance from collision point
879         if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
880         return kFALSE;
881     }
882     cutIndex++;
883
884     if(photon->GetConversionRadius() <= ((TMath::Abs(photon->GetConversionZ())*fLineCutZRSlope)-fLineCutZValue)){
885       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
886       return kFALSE;
887     }
888     else if (fUseEtaMinCut &&  photon->GetConversionRadius() >= ((TMath::Abs(photon->GetConversionZ())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
889         if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
890         return kFALSE;
891     }
892     cutIndex++;
893
894   if(TMath::Abs(photon->GetConversionZ()) > fMaxZ ){ // cuts out regions where we do not reconstruct
895       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
896       return kFALSE;
897   }
898     cutIndex++;
899
900
901   if(TMath::Abs(photon->GetPhotonEta())> fEtaCut || TMath::Abs(photon->GetPhotonEta())< fEtaCutMin){
902       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
903       return kFALSE;
904   }
905     cutIndex++;
906
907
908   if(photon->GetPhotonPt()<fPtCut){
909       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
910       return kFALSE;
911   }
912     cutIndex++;
913
914   if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
915  
916   return kTRUE;
917 }
918
919
920 ///________________________________________________________________________
921 Bool_t AliConversionCuts::SpecificTrackCuts(AliAODTrack * negTrack, AliAODTrack * posTrack,Int_t &cutIndex) {
922     // Track Cuts which require AOD/ESD specific implementation
923
924   if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
925       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
926       return kFALSE;
927   }
928   cutIndex++;
929
930   AliAODVertex * NegVtxType=negTrack->GetProdVertex();
931   AliAODVertex * PosVtxType=posTrack->GetProdVertex();
932   if((NegVtxType->GetType())==AliAODVertex::kKink  || (PosVtxType->GetType())==AliAODVertex::kKink) {
933       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
934       return kFALSE;
935   }
936   return kTRUE;
937
938 }
939
940
941 ///________________________________________________________________________
942 Bool_t AliConversionCuts::SpecificTrackCuts(AliESDtrack * negTrack, AliESDtrack * posTrack,Int_t &cutIndex) {
943     // Track Cuts which require AOD/ESD specific implementation
944
945    if( !negTrack->IsOn(AliESDtrack::kTPCrefit)  || !posTrack->IsOn(AliESDtrack::kTPCrefit)   )  {
946       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
947       return kFALSE;
948   }
949   cutIndex++;
950
951   if(negTrack->GetKinkIndex(0) > 0  || posTrack->GetKinkIndex(0) > 0 ) {
952       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
953       return kFALSE;
954   }
955   return kTRUE;
956 }
957
958
959
960 ///________________________________________________________________________
961 Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * posTrack) {
962     // Track Selection for Photon Reconstruction
963
964     Int_t cutIndex=0;
965     if(hTrackCuts)hTrackCuts->Fill(cutIndex);
966     cutIndex++;
967
968   // avoid like sign
969   if(negTrack->Charge() == posTrack->Charge()) {
970        if(hTrackCuts)hTrackCuts->Fill(cutIndex);
971         return kFALSE;
972   }
973   cutIndex++;
974
975   // Number of TPC Clusters
976   if( negTrack->GetNcls(1) < fMinClsTPC || posTrack->GetNcls(1) < fMinClsTPC ) {
977       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
978         return kFALSE;
979   }
980   cutIndex++;
981
982   // Acceptance
983
984   if(TMath::Abs(negTrack->Eta()) > fEtaCut || TMath::Abs(negTrack->Eta()) < fEtaCutMin ||
985      TMath::Abs(posTrack->Eta())> fEtaCut || TMath::Abs(posTrack->Eta())< fEtaCutMin) {
986        if(hTrackCuts)hTrackCuts->Fill(cutIndex);
987       return kFALSE;
988   }
989   cutIndex++;
990
991   // Single Pt Cut
992   if( negTrack->Pt()< fSinglePtCut ||   posTrack->Pt()< fSinglePtCut){
993       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
994       return kFALSE;
995   }
996   cutIndex++;
997
998   // AOD ESD specific cuts
999   Bool_t passCuts = kTRUE;
1000
1001   if(negTrack->IsA()==AliAODTrack::Class()) {
1002         passCuts = passCuts * SpecificTrackCuts(static_cast<AliAODTrack*>(negTrack), static_cast<AliAODTrack*>(posTrack),cutIndex);
1003   } else { 
1004         passCuts = passCuts * SpecificTrackCuts(static_cast<AliESDtrack*>(negTrack), static_cast<AliESDtrack*>(posTrack),cutIndex);
1005   }     
1006
1007   if(!passCuts){
1008       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1009       return kFALSE;
1010   }
1011   cutIndex++;
1012
1013   if(hTrackCuts)hTrackCuts->Fill(cutIndex);
1014
1015   return kTRUE;
1016                     
1017 }
1018
1019 ///________________________________________________________________________
1020 Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
1021     // Electron Identification Cuts for Photon reconstruction
1022
1023     if(!fPIDResponse){InitPIDResponse();}// Try to reinitialize PID Response
1024     if(!fPIDResponse){AliError("No PID Response"); return kTRUE;}// if still missing fatal error
1025
1026     Int_t cutIndex=0;
1027     if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1028     if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1029     cutIndex++;
1030     
1031
1032   if(fDodEdxSigmaCut == kTRUE){
1033       // TPC Electron Line
1034       if( fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaBelowElectronLine ||
1035                 fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaAboveElectronLine){
1036
1037           if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1038           return kFALSE;
1039       }
1040       cutIndex++;
1041
1042       // TPC Pion Line
1043         if( fCurrentTrack->P()>fPIDMinPnSigmaAbovePionLine && fCurrentTrack->P()<fPIDMaxPnSigmaAbovePionLine ){
1044           if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1045                  fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine&&
1046                  fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLine){
1047
1048               if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1049               return kFALSE;
1050           }
1051         }
1052         cutIndex++;
1053    
1054         // High Pt Pion rej
1055         if( fCurrentTrack->P()>fPIDMaxPnSigmaAbovePionLine ){
1056           if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
1057                  fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine&&
1058                  fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineHighPt){
1059
1060                 if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1061                 return kFALSE;
1062           }
1063         }
1064         cutIndex++;
1065   }
1066   else{cutIndex+=3;}
1067
1068   if(fDoKaonRejectionLowP == kTRUE){
1069         if(fCurrentTrack->P()<fPIDMinPKaonRejectionLowP ){
1070           if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
1071
1072               if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1073               return kFALSE;
1074           }
1075         }
1076   }
1077   cutIndex++;
1078    
1079   if(fDoProtonRejectionLowP == kTRUE){
1080         if( fCurrentTrack->P()<fPIDMinPProtonRejectionLowP ){
1081           if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
1082
1083               if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1084               return kFALSE;
1085           }
1086         }
1087   }
1088    cutIndex++;
1089    
1090   if(fDoPionRejectionLowP == kTRUE){
1091         if( fCurrentTrack->P()<fPIDMinPPionRejectionLowP ){
1092           if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion))<fPIDnSigmaAtLowPAroundPionLine){
1093
1094               if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1095                 return kFALSE;
1096           }
1097         }
1098   }
1099   cutIndex++;
1100    
1101   if((fCurrentTrack->GetStatus() & AliESDtrack::kTOFpid) && !(fCurrentTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
1102      if(hTOFbefore) hTOFbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1103      if(fUseTOFpid){
1104         if(fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)>fTofPIDnSigmaAboveElectronLine ||
1105            fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)<fTofPIDnSigmaBelowElectronLine ){
1106            if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1107            return kFALSE;
1108         }
1109      }
1110      if(hTOFafter)hTOFafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
1111   }
1112      cutIndex++;
1113    
1114     // Apply TRD PID
1115   if(fDoTRDPID){
1116         if(!fPIDResponse->IdentifiedAsElectronTRD(fCurrentTrack,fPIDTRDEfficiency)){
1117
1118             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1119             return kFALSE;
1120         }
1121   }
1122   cutIndex++;
1123
1124   if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
1125   if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
1126
1127   return kTRUE;
1128 }
1129
1130 ///________________________________________________________________________
1131 Bool_t AliConversionCuts::AsymmetryCut(AliConversionPhotonBase * photon,AliVEvent *event) {
1132     // Cut on Energy Assymetry
1133
1134     for(Int_t ii=0;ii<2;ii++){
1135
1136         AliVTrack *track=GetTrack(event,photon->GetTrackLabel(ii));
1137
1138         if( track->P() > fMinPPhotonAsymmetryCut ){
1139             Double_t trackNegAsy=0;
1140             if (photon->GetPhotonP()!=0.){
1141                 trackNegAsy= track->P()/photon->GetPhotonP();
1142             }
1143
1144             if( trackNegAsy<fMinPhotonAsymmetry ||trackNegAsy>(1.- fMinPhotonAsymmetry)){
1145                 return kFALSE;
1146             }
1147         }
1148
1149     }
1150     return kTRUE;
1151 }
1152
1153 ///________________________________________________________________________
1154 AliVTrack *AliConversionCuts::GetTrack(AliVEvent * event, Int_t label){
1155     //Returns pointer to the track with given ESD label
1156     //(Important for AOD implementation, since Track array in AOD data is different
1157     //from ESD array, but ESD tracklabels are stored in AOD Tracks)
1158
1159   AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1160   if(esdEvent) {
1161         if(label > event->GetNumberOfTracks() ) return NULL;
1162         AliESDtrack * track = esdEvent->GetTrack(label);
1163         return track;
1164         
1165   } else { 
1166         for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
1167           AliVTrack * track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
1168           
1169           if(track) { 
1170                 if(track->GetID() == label) {
1171                   return track;
1172                 }
1173           }
1174         }
1175   }
1176   
1177   //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
1178   return NULL;
1179 }
1180
1181
1182 ///________________________________________________________________________
1183 Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, AliVEvent * event){
1184     // Cut on Electron Probability for Photon Reconstruction
1185
1186   AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
1187
1188   if(esdEvent){
1189         
1190         Bool_t iResult=kFALSE;
1191         
1192         Double_t *posProbArray = new Double_t[AliPID::kSPECIES];
1193         Double_t *negProbArray = new Double_t[AliPID::kSPECIES];
1194         
1195         AliESDtrack* negTrack   = esdEvent->GetTrack(photon->GetTrackLabelNegative());
1196         AliESDtrack* posTrack   = esdEvent->GetTrack(photon->GetTrackLabelPositive());
1197         
1198         if(negProbArray && posProbArray){
1199           
1200           negTrack->GetTPCpid(negProbArray);
1201           posTrack->GetTPCpid(posProbArray);
1202
1203           if(negProbArray[AliPID::kElectron]>=fPIDProbabilityCutNegativeParticle && posProbArray[AliPID::kElectron]>=fPIDProbabilityCutPositiveParticle){
1204                 iResult=kTRUE;
1205           }
1206         }
1207         
1208         delete [] posProbArray;
1209         delete [] negProbArray;
1210         return iResult;
1211
1212   } else {
1213       ///Not possible for AODs
1214       return kTRUE;
1215   }
1216
1217
1218
1219   
1220 }
1221
1222
1223 ///________________________________________________________________________
1224 Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TParticle* eNeg){
1225     // MC Acceptance Cuts
1226     //(Certain areas were excluded for photon reconstruction)
1227
1228   if(particle->R()>fMaxR){
1229         return kFALSE;}
1230
1231   if(ePos->R()>fMaxR){
1232         return kFALSE;
1233   }
1234
1235   if(ePos->R()<fMinR){
1236         return kFALSE;
1237   }
1238
1239   if( ePos->R() <= ((TMath::Abs(ePos->Vz())*fLineCutZRSlope)-fLineCutZValue)){
1240         return kFALSE;
1241   }
1242   else if (fUseEtaMinCut &&  ePos->R() >= ((TMath::Abs(ePos->Vz())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
1243       return kFALSE;
1244   }
1245
1246   if(TMath::Abs(eNeg->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1247         return kFALSE;
1248   }
1249
1250   if(eNeg->Vz()!=ePos->Vz()||eNeg->R()!=ePos->R()){
1251         return kFALSE;
1252   }
1253
1254   if(TMath::Abs(ePos->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
1255         return kFALSE;
1256   }
1257
1258   if(TMath::Abs(particle->Eta())> fEtaCut || TMath::Abs(particle->Eta())< fEtaCutMin){
1259         return kFALSE;
1260   }
1261
1262   if(TMath::Abs(ePos->Eta())> fEtaCut || TMath::Abs(ePos->Eta())< fEtaCutMin){
1263         return kFALSE;
1264   }
1265
1266   if(TMath::Abs(eNeg->Eta())> fEtaCut || TMath::Abs(eNeg->Eta())< fEtaCutMin){
1267         return kFALSE;
1268   }
1269
1270   if( ePos->Pt()< fSinglePtCut ||  eNeg->Pt()< fSinglePtCut){
1271         return kFALSE;
1272   }
1273
1274   if(particle->Pt()<fPtCut){
1275         return kFALSE;
1276   }
1277
1278   return kTRUE;
1279 }
1280 ///________________________________________________________________________
1281 Bool_t AliConversionCuts::UpdateCutString(cutIds cutID, Int_t value) {
1282 ///Update the cut string (if it has been created yet)
1283
1284   if(fCutString && fCutString->GetString().Length() == kNCuts) {
1285         fCutString->SetString(GetCutNumber());
1286   } else {
1287         return kFALSE;
1288   }
1289   return kTRUE;
1290 }
1291
1292 ///________________________________________________________________________
1293 Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
1294    // Initialize Cuts from a given Cut string
1295
1296     AliInfo(Form("Set Cut Number: %s",analysisCutSelection.Data()));
1297   if(analysisCutSelection.Length()!=kNCuts) {
1298         AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
1299         return kFALSE;
1300   }
1301   if(!analysisCutSelection.IsDigit()){
1302         AliError("Cut selection contains characters");
1303         return kFALSE;
1304   }
1305   
1306   const char *cutSelection = analysisCutSelection.Data();
1307   #define ASSIGNARRAY(i)        fCuts[i] = cutSelection[i] - '0'
1308   for(Int_t ii=0;ii<kNCuts;ii++){
1309       ASSIGNARRAY(ii);
1310   }
1311
1312   // TestFlag
1313   if(fCuts[0] !=9){
1314     AliError("Analysis Cut Selection does not start with 9");
1315         PrintCuts();
1316     return kFALSE;
1317   }
1318
1319   // Set Individual Cuts
1320   for(Int_t ii=0;ii<kNCuts;ii++){
1321       if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
1322   }
1323
1324   //PrintCuts();
1325
1326   // Set StandardTriggers
1327
1328   if(fIsHeavyIon)SelectCollisionCandidates(AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral);
1329   else SelectCollisionCandidates(AliVEvent::kMB);
1330
1331   return kTRUE;
1332 }
1333 ///________________________________________________________________________
1334 Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
1335   ///Set individual cut ID
1336
1337
1338   switch (cutID) {
1339   case kgoodId:
1340         fCuts[kgoodId] = value;
1341         if(value != 9) {
1342           AliError("First value of cut string is wrong, aborting!!");
1343           return kFALSE;
1344         } else {
1345           return kTRUE;
1346         }
1347
1348   case kv0FinderType:
1349         if( SetV0Finder(value)) {
1350           fCuts[kv0FinderType] = value;
1351           UpdateCutString(cutID, value);
1352           return kTRUE;
1353         } else return kFALSE;
1354
1355   case keProbCut:
1356         if( SetElectronProbCut(value)) {
1357           fCuts[keProbCut] = value;
1358           UpdateCutString(cutID, value);
1359           return kTRUE;
1360         } else return kFALSE;
1361
1362   case kededxSigmaCut:
1363         if( SetTPCdEdxCutElectronLine(value)) {
1364           fCuts[kededxSigmaCut] = value;
1365           UpdateCutString(cutID, value);
1366           return kTRUE;
1367         } else return kFALSE;
1368
1369   case kpidedxSigmaCut:
1370         if( SetTPCdEdxCutPionLine(value)) {
1371           fCuts[kpidedxSigmaCut] = value;
1372           UpdateCutString(cutID, value);
1373           return kTRUE;
1374         } else return kFALSE;
1375
1376   case kpiMomdedxSigmaCut:
1377         if( SetMinMomPiondEdxCut(value)) {
1378           fCuts[kpiMomdedxSigmaCut] = value;
1379           UpdateCutString(cutID, value);
1380           return kTRUE;
1381         } else return kFALSE;
1382
1383   case kchi2GammaCut:
1384         if( SetChi2GammaCut(value)) {
1385           fCuts[kchi2GammaCut] = value;
1386           UpdateCutString(cutID, value);
1387           return kTRUE;
1388         } else return kFALSE;
1389
1390   case ksinglePtCut:
1391         if( SetSinglePtCut(value)) {
1392           fCuts[ksinglePtCut] = value;
1393           UpdateCutString(cutID, value);
1394           return kTRUE;
1395         } else return kFALSE;
1396
1397   case kclsTPCCut:
1398         if( SetTPCClusterCut(value)) {
1399           fCuts[kclsTPCCut] = value;
1400           UpdateCutString(cutID, value);
1401           return kTRUE;
1402         } else return kFALSE;
1403
1404   case ketaCut:
1405         if( SetEtaCut(value)) {
1406           fCuts[ketaCut] = value;
1407           UpdateCutString(cutID, value);
1408           return kTRUE;
1409         } else return kFALSE;
1410
1411   case kchi2MesonCut:
1412         if( SetChi2MesonCut(value)) {
1413           fCuts[kchi2MesonCut] = value;
1414           UpdateCutString(cutID, value);
1415           return kTRUE;
1416         } else return kFALSE;
1417
1418   case kLowPRejectionSigmaCut:
1419         if( SetLowPRejectionCuts(value)) {
1420           fCuts[kLowPRejectionSigmaCut] = value;
1421           UpdateCutString(cutID, value);
1422           return kTRUE;
1423         } else return kFALSE;
1424
1425   case kQtMaxCut:
1426         if( SetQtMaxCut(value)) {
1427           fCuts[kQtMaxCut] = value;
1428           UpdateCutString(cutID, value);
1429           return kTRUE;
1430         } else return kFALSE;
1431
1432   case kpiMaxMomdedxSigmaCut:
1433         if( SetMaxMomPiondEdxCut(value)) {
1434           fCuts[kpiMaxMomdedxSigmaCut] = value;
1435           UpdateCutString(cutID, value);
1436           return kTRUE;
1437         } else return kFALSE;
1438
1439   case kalphaMesonCut:
1440         if( SetAlphaMesonCut(value)) {
1441           fCuts[kalphaMesonCut] = value;
1442           UpdateCutString(cutID, value);
1443           return kTRUE;
1444         } else return kFALSE;
1445
1446   case kminRCut:
1447         if( SetRCut(value)) {
1448           fCuts[kminRCut] = value;
1449           UpdateCutString(cutID, value);
1450           return kTRUE;
1451         } else return kFALSE;
1452
1453   case kRapidityMesonCut:
1454         if( SetRapidityMesonCut(value)) {
1455           fCuts[kRapidityMesonCut] = value;
1456           UpdateCutString(cutID, value);
1457           return kTRUE;
1458         } else return kFALSE;
1459
1460   case kBackgroundScheme:
1461         if( SetBackgroundScheme(value)) {
1462           fCuts[kBackgroundScheme] = value;
1463           UpdateCutString(cutID, value);
1464           return kTRUE;
1465         } else return kFALSE;
1466
1467   case kDegreesForRotationMethod:
1468         if( SetNDegreesForRotationMethod(value)) {
1469           fCuts[kDegreesForRotationMethod] = value;
1470           UpdateCutString(cutID, value);
1471           return kTRUE;
1472         } else return kFALSE;
1473
1474   case kNumberOfRotations:
1475         if( SetNumberOfRotations(value)) {
1476           fCuts[kNumberOfRotations] = value;
1477           UpdateCutString(cutID, value);
1478           return kTRUE;
1479         } else return kFALSE;
1480
1481   case kremovePileUp:
1482         if( SetRemovePileUp(value)) {
1483           fCuts[kremovePileUp] = value;
1484           UpdateCutString(cutID, value);
1485           return kTRUE;
1486         } else return kFALSE;
1487
1488   case kselectV0AND:
1489         if( SetSelectV0AND(value)) {
1490           fCuts[kselectV0AND] = value;
1491           UpdateCutString(cutID, value);
1492           return kTRUE;
1493         } else return kFALSE;
1494
1495   case kmultiplicityMethod:
1496         if( SetMultiplicityMethod(value)) {
1497           fCuts[kmultiplicityMethod] = value;
1498           UpdateCutString(cutID, value);
1499           return kTRUE;
1500         } else return kFALSE;
1501
1502   case kisHeavyIon:
1503         if( SetIsHeavyIon(value)) {
1504           fCuts[kisHeavyIon] = value;
1505           UpdateCutString(cutID, value);
1506           return kTRUE;
1507         } else return kFALSE;
1508
1509   case kCentralityMin:
1510         if( SetCentralityMin(value)) {
1511           fCuts[kCentralityMin] = value;
1512           UpdateCutString(cutID, value);
1513           return kTRUE;
1514         } else return kFALSE;
1515
1516   case kCentralityMax:
1517         if( SetCentralityMax(value)) {
1518           fCuts[kCentralityMax] = value;
1519           UpdateCutString(cutID, value);
1520           return kTRUE;
1521         } else return kFALSE;
1522
1523   case kTOFelectronPID:
1524         if( SetTOFElectronPIDCut(value)) {
1525           fCuts[kTOFelectronPID] = value;
1526           UpdateCutString(cutID, value);
1527           return kTRUE;
1528         } else return kFALSE;
1529
1530   case kuseMCPSmearing:
1531         if( SetMCPSmearing(value)) {
1532           fCuts[kuseMCPSmearing] = value;
1533           UpdateCutString(cutID, value);
1534           return kTRUE;
1535         } else return kFALSE;
1536
1537   case kdoPhotonAsymmetryCut:
1538         if( SetPhotonAsymmetryCut(value)) {
1539           fCuts[kdoPhotonAsymmetryCut] = value;
1540           UpdateCutString(cutID, value);
1541           return kTRUE;
1542         } else return kFALSE;
1543
1544   case kPsiPair:
1545         if( SetPsiPairCut(value)) {
1546           fCuts[kPsiPair] = value;
1547           UpdateCutString(cutID, value);
1548           return kTRUE;
1549         } else return kFALSE;
1550
1551   case kCosPAngle:
1552         if( SetCosPAngleCut(value)) {
1553           fCuts[kCosPAngle] = value;
1554           UpdateCutString(cutID, value);
1555           return kTRUE;
1556         } else return kFALSE;
1557
1558
1559   case kElecShare:
1560         if( SetSharedElectronCut(value)) {
1561           fCuts[kElecShare] = value;
1562           UpdateCutString(cutID, value);
1563           return kTRUE;
1564         } else return kFALSE;
1565
1566
1567   case kToCloseV0s:
1568         if( SetToCloseV0sCut(value)) {
1569           fCuts[kToCloseV0s] = value;
1570           UpdateCutString(cutID, value);
1571           return kTRUE;
1572         } else return kFALSE;
1573
1574   case kNCuts:
1575       AliError("Cut id out of range");
1576         return kFALSE;
1577   }
1578
1579   AliError("Cut id %d not recognized");
1580   return kFALSE;
1581
1582 }
1583 ///________________________________________________________________________
1584 Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
1585 {// Set Cut
1586     switch(removePileUp){
1587     case 0:
1588         fRemovePileUp=kFALSE;
1589         break;
1590     case 1:
1591         fRemovePileUp=kTRUE;
1592         break;
1593     default:
1594         AliError("RemovePileUpCut not defined");
1595         return kFALSE;
1596     }
1597     return kTRUE;
1598 }
1599
1600 ///________________________________________________________________________
1601 Bool_t AliConversionCuts::SetSelectV0AND(Int_t selectV0AND)
1602 {// Set Cut
1603   switch(selectV0AND){
1604   case 0:
1605       fSelectV0AND=kFALSE;
1606       break;
1607   case 1:
1608       fSelectV0AND=kTRUE;
1609       break;
1610   default:
1611       AliError("Warning: V0ANDCut not defined");
1612       return kFALSE;
1613   }
1614   return kTRUE;
1615 }
1616
1617 ///________________________________________________________________________
1618 Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
1619 {
1620     // Set Cut
1621     fMultiplicityMethod=multiplicityMethod;
1622
1623     // 0 Photon Multiplicity
1624     // 1 TPC Track multiplicity
1625     // 2 V0 Mult
1626     // 3 SPD Mult
1627
1628     return kTRUE;
1629 }
1630
1631 ///________________________________________________________________________
1632 Bool_t AliConversionCuts::SetMCPSmearing(Int_t useMCPSmearing)
1633 {// Set Cut
1634     switch(useMCPSmearing){
1635     case 0:
1636         fUseMCPSmearing=0;
1637         fPBremSmearing=1.;
1638         fPSigSmearing=0.;
1639         fPSigSmearingCte=0.;
1640         break;
1641     case 1:
1642         fUseMCPSmearing=1;
1643         fPBremSmearing=1.0e-14;
1644         fPSigSmearing=0.;
1645         fPSigSmearingCte=0.;
1646         break;
1647     case 2:
1648         fUseMCPSmearing=1;
1649         fPBremSmearing=1.0e-15;
1650         fPSigSmearing=0.0;
1651         fPSigSmearingCte=0.;
1652         break;
1653     case 3:
1654         fUseMCPSmearing=1;
1655         fPBremSmearing=1.;
1656         fPSigSmearing=0.003;
1657         fPSigSmearingCte=0.002;
1658         break;
1659     case 4:
1660         fUseMCPSmearing=1;
1661         fPBremSmearing=1.;
1662         fPSigSmearing=0.003;
1663         fPSigSmearingCte=0.007;
1664         break;
1665     case 5:
1666         fUseMCPSmearing=1;
1667         fPBremSmearing=1.;
1668         fPSigSmearing=0.003;
1669         fPSigSmearingCte=0.016;
1670         break;
1671     case 6:
1672         fUseMCPSmearing=1;
1673         fPBremSmearing=1.;
1674         fPSigSmearing=0.007;
1675         fPSigSmearingCte=0.016;
1676         break;
1677     case 7:
1678         fUseMCPSmearing=1;
1679         fPBremSmearing=1.0e-16;
1680         fPSigSmearing=0.0;
1681         fPSigSmearingCte=0.;
1682         break;
1683     case 8:
1684         fUseMCPSmearing=1;
1685         fPBremSmearing=1.;
1686         fPSigSmearing=0.007;
1687         fPSigSmearingCte=0.014;
1688         break;
1689     case 9:
1690         fUseMCPSmearing=1;
1691         fPBremSmearing=1.;
1692         fPSigSmearing=0.007;
1693         fPSigSmearingCte=0.011;
1694         break;
1695
1696     default:
1697         AliError("Warning: UseMCPSmearing not defined");
1698         return kFALSE;
1699     }
1700     return kTRUE;
1701 }
1702
1703 ///________________________________________________________________________
1704 void AliConversionCuts::PrintCuts() {
1705     // Print out current Cut Selection
1706   for(Int_t ic = 0; ic < kNCuts; ic++) {
1707         printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
1708   }
1709
1710 }
1711
1712 ///________________________________________________________________________
1713 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
1714     // Set Cut
1715     switch(RCut){
1716     case 0:
1717         fMinR=0;
1718         fMaxR = 180.;
1719         break;
1720     case 1:
1721         fMinR=2.8;
1722         fMaxR = 180.;
1723         break;
1724     case 2:
1725         fMinR=5.;
1726         fMaxR = 180.;
1727         break;
1728     case 3:
1729         fMaxR = 70.;
1730         fMinR = 10.;
1731         break;
1732     case 4:
1733         fMaxR = 70.;
1734         fMinR = 5.;
1735         break;
1736         // High purity cuts for PbPb (remove first layers of material)
1737     case 5:
1738         fMaxR = 180.;
1739         fMinR = 10.;  
1740         break;
1741      case 6:
1742         fMaxR = 180.;
1743         fMinR = 20.;
1744          break;
1745     case 7:
1746         fMaxR = 180.;
1747         fMinR = 26.;
1748         break;
1749     case 8:
1750         fMaxR = 180.;
1751         fMinR = 35.;
1752         break;
1753     case 9:
1754         fMaxR = 180.;
1755         fMinR = 60.;
1756         break;
1757
1758     default:
1759         AliError("RCut not defined");
1760         return kFALSE;
1761     }
1762     return kTRUE;
1763 }
1764
1765 ///________________________________________________________________________
1766 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
1767 {   // Set Cut
1768     switch(ededxSigmaCut){
1769     case 0: // -10,10
1770         fPIDnSigmaBelowElectronLine=-10;
1771         fPIDnSigmaAboveElectronLine=10;
1772         break;
1773     case 1: // -5,5
1774         fPIDnSigmaBelowElectronLine=-5;
1775         fPIDnSigmaAboveElectronLine=5;
1776         break;
1777     case 2: // -3,5
1778         fPIDnSigmaBelowElectronLine=-3;
1779         fPIDnSigmaAboveElectronLine=5;
1780         break;
1781     case 3: // -4,5
1782         fPIDnSigmaBelowElectronLine=-4;
1783         fPIDnSigmaAboveElectronLine=5;
1784         break;
1785     case 4: // -6,7
1786        fPIDnSigmaBelowElectronLine=-6;
1787        fPIDnSigmaAboveElectronLine=7;
1788        break;
1789     case 5: // -4,4
1790        fPIDnSigmaBelowElectronLine=-4;
1791        fPIDnSigmaAboveElectronLine=4;
1792        break;
1793     case 6: // -2.5,4
1794        fPIDnSigmaBelowElectronLine=-2.5;
1795        fPIDnSigmaAboveElectronLine=4;
1796        break;
1797     case 7: // -2,3.5
1798        fPIDnSigmaBelowElectronLine=-2;
1799        fPIDnSigmaAboveElectronLine=3.5;
1800        break;
1801     default:
1802         AliError("TPCdEdxCutElectronLine not defined");
1803         return kFALSE;
1804         
1805     }
1806     return kTRUE;
1807 }
1808
1809 ///________________________________________________________________________
1810 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
1811 {   // Set Cut
1812
1813     switch(pidedxSigmaCut){
1814     case 0:  // -10
1815         fPIDnSigmaAbovePionLine=-10;
1816         fPIDnSigmaAbovePionLineHighPt=-10;
1817         break;
1818     case 1:   // 0
1819         fPIDnSigmaAbovePionLine=0;
1820         fPIDnSigmaAbovePionLineHighPt=-10;
1821         break;
1822     case 2:  // 1
1823         fPIDnSigmaAbovePionLine=1;
1824         fPIDnSigmaAbovePionLineHighPt=-10;
1825         break;
1826     case 3:  // 1
1827         fPIDnSigmaAbovePionLine=-1;
1828         fPIDnSigmaAbovePionLineHighPt=-10;
1829         break;
1830     case 4:  // 1
1831         fPIDnSigmaAbovePionLine=2.5;
1832         fPIDnSigmaAbovePionLineHighPt=-10;
1833         break;
1834     case 5:  // 1
1835         fPIDnSigmaAbovePionLine=2.;
1836         fPIDnSigmaAbovePionLineHighPt=-10;
1837         break;
1838     case 6:  // 1
1839         fPIDnSigmaAbovePionLine=2.;
1840         fPIDnSigmaAbovePionLineHighPt=0.5;
1841         break;
1842     case 7:  // 1
1843         fPIDnSigmaAbovePionLine=3.5;
1844         fPIDnSigmaAbovePionLineHighPt=-10;
1845         break;
1846     case 8:  // 1
1847         fPIDnSigmaAbovePionLine=2.;
1848         fPIDnSigmaAbovePionLineHighPt=1.;
1849         break;
1850     case 9:
1851         fPIDnSigmaAbovePionLine=3.0; // We need a bit less tight cut on dE/dx
1852         fPIDnSigmaAbovePionLineHighPt=-10;
1853         break;
1854     default:
1855         AliError(Form("Warning: pidedxSigmaCut not defined %d",pidedxSigmaCut));
1856         return kFALSE;
1857     }
1858     return kTRUE;
1859 }
1860
1861 ///________________________________________________________________________
1862 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
1863 {   // Set Cut
1864     switch(piMomdedxSigmaCut){
1865     case 0:  // 0.5 GeV
1866         fPIDMinPnSigmaAbovePionLine=0.5;
1867         break;
1868     case 1:  // 1. GeV
1869         fPIDMinPnSigmaAbovePionLine=1.;
1870         break;
1871     case 2:  // 1.5 GeV
1872         fPIDMinPnSigmaAbovePionLine=1.5;
1873         break;
1874     case 3:  // 20.0 GeV
1875         fPIDMinPnSigmaAbovePionLine=20.;
1876         break;
1877     case 4:  // 50.0 GeV
1878         fPIDMinPnSigmaAbovePionLine=50.;
1879         break;
1880     case 5:  // 0.3 GeV
1881         fPIDMinPnSigmaAbovePionLine=0.3;
1882         break;
1883     case 6:  // 0.25 GeV
1884         fPIDMinPnSigmaAbovePionLine=0.25;
1885         break;
1886     case 7:  // 0.4 GeV
1887         fPIDMinPnSigmaAbovePionLine=0.4;
1888         break;
1889     default:
1890         AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
1891         return kFALSE;
1892     }
1893     return kTRUE;
1894 }
1895
1896 ///________________________________________________________________________
1897 Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
1898 {   // Set Cut
1899
1900     switch(chi2GammaCut){
1901     case 0: // 100
1902         fChi2CutConversion = 100.;
1903         break;
1904     case 1:  // 50
1905         fChi2CutConversion = 50.;
1906         break;
1907     case 2:  // 30
1908         fChi2CutConversion = 30.;
1909         break;
1910     case 3:
1911         fChi2CutConversion = 200.;
1912         break;
1913     case 4:
1914         fChi2CutConversion = 500.;
1915         break;
1916     case 5:
1917         fChi2CutConversion = 100000.;
1918         break;
1919     case 6:
1920         fChi2CutConversion = 5.;
1921         break;
1922     case 7:
1923         fChi2CutConversion = 10.;
1924         break;
1925     case 8:
1926         fChi2CutConversion = 20.;
1927         break;
1928     case 9:
1929         fChi2CutConversion = 15.;
1930         break;
1931     default:
1932         AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
1933         return kFALSE;
1934     }
1935     return kTRUE;
1936 }
1937
1938 ///________________________________________________________________________
1939 Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
1940 {   // Set Cut
1941     switch (v0FinderType){
1942     case 0:  // on fly V0 finder
1943         fUseOnFlyV0Finder=kTRUE;
1944         break;
1945     case 1:  // offline V0 finder
1946         fUseOnFlyV0Finder=kFALSE;
1947         break;
1948     default:
1949         AliError(Form(" v0FinderType not defined %d",v0FinderType));
1950         return kFALSE;
1951     }
1952     return kTRUE;
1953 }
1954
1955 ///________________________________________________________________________
1956 Bool_t AliConversionCuts::SetElectronProbCut(Int_t eProbCut)
1957 {   // Set Cut
1958
1959     switch(eProbCut){
1960     case 0:
1961         fPIDProbabilityCutNegativeParticle=0;
1962         fPIDProbabilityCutPositiveParticle=0;
1963         break;
1964     case 1:
1965         fPIDProbabilityCutNegativeParticle=0.1;
1966         fPIDProbabilityCutPositiveParticle=0.1;
1967         break;
1968     case 2:
1969         fPIDProbabilityCutNegativeParticle=0.5;
1970         fPIDProbabilityCutPositiveParticle=0.5;
1971         break;
1972     case 3:
1973         fPIDProbabilityCutNegativeParticle=0.7;
1974         fPIDProbabilityCutPositiveParticle=0.7;
1975         break;
1976     default:
1977         AliError(Form("Warning: eProbCut not defined %d",eProbCut));
1978         return kFALSE;
1979     }
1980     return kTRUE;
1981 }
1982
1983 ///________________________________________________________________________
1984 Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
1985 {   // Set Cut
1986     switch(singlePtCut){
1987     case 0: // 0.050 GeV
1988         fSinglePtCut = 0.050;
1989         break;
1990     case 1:  // 0.100 GeV
1991         fSinglePtCut = 0.100;
1992         break;
1993     case 2:  // 0.150 GeV
1994         fSinglePtCut = 0.150;
1995         break;
1996     case 3:  // 0.200 GeV
1997         fSinglePtCut = 0.200;
1998         break;
1999     case 4:  // 0.075 GeV
2000         fSinglePtCut = 0.075;
2001         break;
2002     case 5:  // 0.125 GeV
2003         fSinglePtCut = 0.125;
2004         break;
2005     default:
2006         AliError(Form("singlePtCut not defined %d",singlePtCut));
2007         return kFALSE;
2008     }
2009     return kTRUE;
2010 }
2011 ///________________________________________________________________________
2012 Bool_t AliConversionCuts::SetTPCClusterCut(Int_t clsTPCCut)
2013 {   // Set Cut
2014     switch(clsTPCCut){
2015     case 0: // 0
2016         fMinClsTPC= 0.;
2017         break;
2018     case 1:  // 70
2019         fMinClsTPC= 70.;
2020         break;
2021     case 2:  // 80
2022         fMinClsTPC= 80.;
2023         break;
2024     case 3:  // 100
2025         fMinClsTPC= 100.;
2026         break;
2027     case 4:  // 60% of findable clusters
2028         fMinClsTPCToF= 0.6;
2029         fUseCorrectedTPCClsInfo=0;
2030         break;
2031     case 5:  // 0% of findable clusters
2032         fMinClsTPCToF= 0.0;
2033         fUseCorrectedTPCClsInfo=1;
2034         break;
2035     case 6:  // 0% of findable clusters
2036         fMinClsTPCToF= 0.7;
2037         fUseCorrectedTPCClsInfo=1;
2038         break;
2039     case 7:  // 0% of findable clusters
2040         fMinClsTPCToF= 0.35;
2041         fUseCorrectedTPCClsInfo=0;
2042         break;
2043     case 8:
2044         fMinClsTPCToF= 0.35;
2045         fUseCorrectedTPCClsInfo=1;
2046         break;
2047     case 9:
2048         fMinClsTPCToF= 0.6;
2049         fUseCorrectedTPCClsInfo=1;
2050         break;
2051     default:
2052         AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
2053         return kFALSE;
2054     }
2055     return kTRUE;
2056 }
2057
2058 ///________________________________________________________________________
2059 Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
2060 {   // Set Cut
2061
2062    //Set Standard LineCutZValues
2063    fLineCutZValueMin = -2;
2064    fLineCutZValue = 7.;
2065    
2066     switch(etaCut){
2067     case 0: // 0.9
2068         fEtaCut         = 0.9;
2069         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2070         fEtaCutMin              = -0.1;
2071         fLineCutZRSlopeMin = 0.;
2072         break;
2073     case 1:     // 1.2
2074         fEtaCut         = 1.2;
2075         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2076         fEtaCutMin              = -0.1;
2077         fLineCutZRSlopeMin = 0.;
2078         break;
2079     case 2:     // 1.4
2080         fEtaCut         = 1.4;
2081         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2082         fEtaCutMin              = -0.1;
2083         fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCut)));
2084         break;
2085     case 3: // 0.8
2086         fEtaCut         = 0.8;
2087         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2088         fEtaCutMin              = -0.1;
2089         fLineCutZRSlopeMin = 0.;
2090         break;
2091     case 4: // 0.75
2092         fEtaCut         = 0.75;
2093         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2094         fEtaCutMin              = -0.1;
2095         fLineCutZRSlopeMin = 0.;
2096         break;
2097     case 5: // 0.9 - 1.4
2098         fEtaCut         = 1.4;
2099         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2100         fEtaCutMin              = 0.9;
2101         fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2102         break;
2103     case 6: // 0.9 - 1.2
2104         fEtaCut         = 1.2;
2105         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2106         fEtaCutMin              = 0.9;
2107         fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2108         break;
2109     case 7: // 0.1 - 0.8
2110         fEtaCut         = 0.8;
2111         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2112         fEtaCutMin              = 0.1;
2113         fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2114         break;
2115     case 8: // 0.1 - 0.8
2116         fEtaCut         = 0.9;
2117         fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
2118         fEtaCutMin              = 0.1;
2119         fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
2120         break;
2121     default:
2122         AliError(Form(" EtaCut not defined %d",etaCut));
2123         return kFALSE;
2124     }
2125     return kTRUE;
2126 }
2127
2128 ///________________________________________________________________________
2129 Bool_t AliConversionCuts::SetChi2MesonCut(Int_t chi2MesonCut)
2130 {   // Set Cut
2131     switch(chi2MesonCut){
2132     case 0:  // 100.
2133         fChi2CutMeson = 100.;
2134         break;
2135     case 1:  // 50.
2136         fChi2CutMeson = 50.;
2137         break;
2138     case 2:  // 30.
2139         fChi2CutMeson = 30.;
2140         break;
2141     case 3:
2142         fChi2CutMeson = 200.;
2143         break;
2144     case 4:
2145         fChi2CutMeson = 500.;
2146         break;
2147     case 5:
2148         fChi2CutMeson = 1000.;
2149         break;
2150     default:
2151         AliError(Form("Chi2MesonCut not defined %d",chi2MesonCut));
2152         return kFALSE;
2153     }
2154     return kTRUE;
2155 }
2156
2157 ///________________________________________________________________________
2158 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
2159 {   // Set Cut
2160     switch(piMaxMomdedxSigmaCut){
2161     case 0:  // 100. GeV
2162         fPIDMaxPnSigmaAbovePionLine=100.;
2163         break;
2164     case 1:  // 5. GeV
2165         fPIDMaxPnSigmaAbovePionLine=5.;
2166         break;
2167     case 2:  // 4. GeV
2168         fPIDMaxPnSigmaAbovePionLine=4.;
2169         break;
2170     case 3:  // 3.5 GeV
2171         fPIDMaxPnSigmaAbovePionLine=3.5;
2172         break;
2173     case 4:  // 3. GeV
2174         fPIDMaxPnSigmaAbovePionLine=3.;
2175         break;
2176     default:
2177         AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
2178         return kFALSE;
2179     }
2180     return kTRUE;
2181 }
2182
2183 ///________________________________________________________________________
2184 Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
2185 {   // Set Cut
2186    switch(isHeavyIon){
2187                 case 0:
2188                         fIsHeavyIon=0;
2189                         break;
2190                 case 1:
2191                         fIsHeavyIon=1;
2192                         fDetectorCentrality=0;
2193                         break;
2194                 case 2:
2195                         fIsHeavyIon=1;
2196                         fDetectorCentrality=1;
2197                         break;
2198                 case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
2199                         fIsHeavyIon=1;
2200                         fDetectorCentrality=0;    
2201                         fModCentralityClass=1;
2202                         break;
2203                 case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
2204                         fIsHeavyIon=1;
2205                         fDetectorCentrality=0;
2206                         fModCentralityClass=2;
2207                         break;
2208                 default:
2209                         AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
2210                         return kFALSE;
2211    }
2212    return kTRUE;
2213 }
2214
2215 ///________________________________________________________________________
2216 Bool_t AliConversionCuts::SetAlphaMesonCut(Int_t alphaMesonCut)
2217 {   // Set Cut
2218     switch(alphaMesonCut){
2219     case 0:     // 0- 0.7
2220         fAlphaMinCutMeson        = 0.0;
2221         fAlphaCutMeson   = 0.7;
2222         break;
2223     case 1:     // 0-0.5
2224         fAlphaMinCutMeson        = 0.0;
2225         fAlphaCutMeson   = 0.5;
2226         break;
2227     case 2:     // 0.5-1
2228         fAlphaMinCutMeson        = 0.5;
2229         fAlphaCutMeson   = 1.;
2230         break;
2231     case 3:     // 0.0-1
2232         fAlphaMinCutMeson        = 0.0;
2233         fAlphaCutMeson   = 1.;
2234         break;
2235     case 4:     // 0-0.65
2236         fAlphaMinCutMeson        = 0.0;
2237         fAlphaCutMeson   = 0.65;
2238         break;
2239     case 5:     // 0-0.75
2240         fAlphaMinCutMeson        = 0.0;
2241         fAlphaCutMeson   = 0.75;
2242         break;
2243     case 6:     // 0-0.8
2244         fAlphaMinCutMeson        = 0.0;
2245         fAlphaCutMeson   = 0.8;
2246         break;
2247     case 7:     // 0.0-0.85
2248         fAlphaMinCutMeson        = 0.0;
2249         fAlphaCutMeson   = 0.85;
2250         break;
2251     case 8:     // 0.0-0.6
2252         fAlphaMinCutMeson        = 0.0;
2253         fAlphaCutMeson   = 0.6;
2254         break;
2255     default:
2256         AliError(Form("AlphaMesonCut not defined %d",alphaMesonCut));
2257         return kFALSE;
2258     }
2259     return kTRUE;
2260 }
2261
2262 ///________________________________________________________________________
2263 Bool_t AliConversionCuts::SetRapidityMesonCut(Int_t RapidityMesonCut)
2264 {   // Set Cut
2265     switch(RapidityMesonCut){
2266     case 0:  //
2267         fRapidityCutMeson   = 0.9;
2268         break;
2269     case 1:  //
2270         fRapidityCutMeson   = 0.8;
2271         break;
2272     case 2:  //
2273         fRapidityCutMeson   = 0.7;
2274         break;
2275
2276     default:
2277         AliError(Form("RapidityMesonCut not defined %d",RapidityMesonCut));
2278         return kFALSE;
2279     }
2280     return kTRUE;
2281 }
2282
2283 ///________________________________________________________________________
2284 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
2285 {   // Set Cut
2286     switch(LowPRejectionSigmaCut){
2287         case 0:  //
2288         fPIDnSigmaAtLowPAroundKaonLine=0;
2289         fPIDnSigmaAtLowPAroundProtonLine=0;
2290         fPIDnSigmaAtLowPAroundPionLine=0;
2291         break;
2292     case 1:  //
2293         fPIDnSigmaAtLowPAroundKaonLine=0.5;
2294         fPIDnSigmaAtLowPAroundProtonLine=0.5;
2295         fPIDnSigmaAtLowPAroundPionLine=0.5;
2296         break;
2297     case 2:  //
2298         fPIDnSigmaAtLowPAroundKaonLine=1;
2299         fPIDnSigmaAtLowPAroundProtonLine=1;
2300         fPIDnSigmaAtLowPAroundPionLine=1;
2301         break;
2302     case 3:  //
2303         fPIDnSigmaAtLowPAroundKaonLine=2.;
2304         fPIDnSigmaAtLowPAroundProtonLine=2.;
2305         fPIDnSigmaAtLowPAroundPionLine=2.;
2306         break;
2307     case 4:  //
2308         fPIDnSigmaAtLowPAroundKaonLine=0.;
2309         fPIDnSigmaAtLowPAroundProtonLine=0.;
2310         fPIDnSigmaAtLowPAroundPionLine=1;
2311         break;
2312     case 5:  //
2313         fPIDnSigmaAtLowPAroundKaonLine=0.;
2314         fPIDnSigmaAtLowPAroundProtonLine=0.;
2315         fPIDnSigmaAtLowPAroundPionLine=1.5;
2316         break;
2317     case 6:  //
2318         fPIDnSigmaAtLowPAroundKaonLine=0.;
2319         fPIDnSigmaAtLowPAroundProtonLine=0.;
2320         fPIDnSigmaAtLowPAroundPionLine=2.;
2321         break;
2322     default:
2323         AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
2324         return kFALSE;
2325     }
2326     return kTRUE;
2327 }
2328
2329 ///________________________________________________________________________
2330 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
2331     // Set Cut
2332     switch(TOFelectronPID){ // RRnewTOF start //////////////////////////////////////////////////////////////////////////
2333     case 0: // no cut
2334         fUseTOFpid = kFALSE;
2335         fTofPIDnSigmaBelowElectronLine=-100;
2336         fTofPIDnSigmaAboveElectronLine=100;
2337         break;
2338     case 1: // -7,7
2339         fUseTOFpid = kTRUE;
2340         fTofPIDnSigmaBelowElectronLine=-7;
2341         fTofPIDnSigmaAboveElectronLine=7;
2342         break;
2343     case 2: // -5,5
2344         fUseTOFpid = kTRUE;
2345         fTofPIDnSigmaBelowElectronLine=-5;
2346         fTofPIDnSigmaAboveElectronLine=5;
2347         break;
2348     case 3: // -3,5
2349         fUseTOFpid = kTRUE;
2350         fTofPIDnSigmaBelowElectronLine=-3;
2351         fTofPIDnSigmaAboveElectronLine=5;
2352         break;
2353     case 4: // -2,3
2354         fUseTOFpid = kTRUE;
2355         fTofPIDnSigmaBelowElectronLine=-2;
2356         fTofPIDnSigmaAboveElectronLine=3;
2357         break;
2358     default:
2359         AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
2360         return kFALSE;
2361     } //////////////////////// RRnewTOF end //////////////////////////////////////////////////////////////////////////
2362     return kTRUE;
2363 }
2364
2365 ///________________________________________________________________________
2366 Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
2367 {   // Set Cut
2368     switch(TRDElectronCut){
2369     case 0:
2370         fDoTRDPID=kFALSE;
2371         break;
2372     case 1:
2373         fDoTRDPID=kTRUE;
2374         fPIDTRDEfficiency=0.1;
2375         break;
2376     case 8:
2377         fDoTRDPID=kTRUE;
2378         fPIDTRDEfficiency=0.8;
2379         break;
2380     case 9:
2381         fDoTRDPID=kTRUE;
2382         fPIDTRDEfficiency=0.9;
2383         break;
2384     default:
2385         AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
2386         return kFALSE;
2387     }
2388
2389     return kTRUE;
2390 }
2391 ///________________________________________________________________________
2392 Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
2393 {   // Set Cut
2394     switch(QtMaxCut){
2395     case 0: //
2396         fQtMax=1.;
2397         fDoQtGammaSelection=kFALSE;      //No Qt selection (true by default)
2398         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2399         fHighPtQtMax=100.;              // RRnew
2400         fPtBorderForQt=100.;            // RRnew
2401         break;
2402     case 1:
2403         fQtMax=0.1;
2404         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2405         fHighPtQtMax=100.;              // RRnew
2406         fPtBorderForQt=100.;            // RRnew
2407         break;
2408     case 2:
2409         fQtMax=0.07;
2410         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2411         fHighPtQtMax=100.;              // RRnew
2412         fPtBorderForQt=100.;            // RRnew
2413         break;
2414     case 3:
2415         fQtMax=0.05;
2416         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2417         fHighPtQtMax=100.;              // RRnew
2418         fPtBorderForQt=100.;            // RRnew
2419         break;
2420     case 4:
2421         fQtMax=0.03;
2422         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2423         fHighPtQtMax=100.;              // RRnew
2424         fPtBorderForQt=100.;            // RRnew
2425         break;
2426     case 5: // RR try to improve (get rid of) low InvMass peak in PbPb
2427         fQtMax=0.02;
2428         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2429         fHighPtQtMax=100.;              // RRnew
2430         fPtBorderForQt=100.;            // RRnew
2431         break; // end RR ///////////////////////////////////////////////
2432     case 6:  // RRnew start: pT dependent qT cut
2433         fQtMax=0.02;
2434         fDoHighPtQtGammaSelection=kTRUE;
2435         fHighPtQtMax=0.06;
2436         fPtBorderForQt=2.5;
2437         break; // RRnew end ////////////////////////////////////////////
2438     case 7:
2439         fQtMax=0.15;
2440         fDoHighPtQtGammaSelection=kFALSE; // RRnew
2441         fHighPtQtMax=100.;              // RRnew
2442         fPtBorderForQt=100.;            // RRnew
2443         break;
2444     default:
2445         AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
2446         return kFALSE;
2447     }
2448     return kTRUE;
2449 }
2450
2451 //-------------------------------------------------------------
2452 Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
2453 {   // Get Event Centrality
2454
2455     AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
2456     if(esdEvent){
2457         AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
2458
2459         if(fDetectorCentrality==0){
2460             return fESDCentrality->GetCentralityPercentile("V0M"); // default
2461         }
2462         if(fDetectorCentrality==1){
2463             return fESDCentrality->GetCentralityPercentile("CL1");
2464         }
2465     }
2466
2467     AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
2468     if(aodEvent){
2469         if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
2470     }
2471
2472     return -1;
2473 }
2474
2475 //-------------------------------------------------------------
2476 Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event)
2477 {   // Centrality Selection
2478    if(!fIsHeavyIon)return kTRUE;
2479     
2480         if(fCentralityMin == 0 && fCentralityMax == 0) return kTRUE;//0-100%
2481         if(fCentralityMin >= fCentralityMax) return kTRUE;//0-100%
2482    
2483         Double_t centrality=GetCentrality(event);
2484         if(centrality<0)return kFALSE;
2485         
2486         Int_t centralityC=0;
2487         if (fModCentralityClass == 0){
2488                 centralityC= Int_t(centrality/10);
2489                 if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
2490                         return kTRUE;
2491                 else 
2492                         return kFALSE;
2493         }       else if (fModCentralityClass ==1){
2494                 centralityC= Int_t(centrality);
2495                 if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
2496                         return kTRUE;
2497                 } else { 
2498                         return kFALSE;
2499                 }
2500         } else if (fModCentralityClass ==2){
2501                 centralityC= Int_t(centrality+1);
2502                 if(centralityC >= (fCentralityMin*5+45) && centralityC < (fCentralityMax*5+45))
2503                         return kTRUE;
2504                 else 
2505                         return kFALSE;
2506         }
2507         return kFALSE;
2508 }
2509
2510 //-------------------------------------------------------------
2511 Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
2512 {
2513     // Set Cut
2514     if(minCentrality<0||minCentrality>9){
2515         AliError(Form("minCentrality not defined %d",minCentrality));
2516         return kFALSE;
2517     }
2518
2519     fCentralityMin=minCentrality;
2520     return kTRUE;
2521 }
2522 //-------------------------------------------------------------
2523 Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
2524 {
2525     // Set Cut
2526     if(maxCentrality<0||maxCentrality>9){
2527         AliError(Form("maxCentrality not defined %d",maxCentrality));
2528         return kFALSE;
2529     }
2530
2531     fCentralityMax=maxCentrality;
2532     return kTRUE;
2533 }
2534
2535 ///________________________________________________________________________
2536 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
2537     // Set Cut
2538     switch(doPhotonAsymmetryCut){
2539     case 0:
2540         fDoPhotonAsymmetryCut=0;
2541         fMinPPhotonAsymmetryCut=100.;
2542         fMinPhotonAsymmetry=0.;
2543         break;
2544     case 1:
2545         fDoPhotonAsymmetryCut=1;
2546         fMinPPhotonAsymmetryCut=3.5;
2547         fMinPhotonAsymmetry=0.04;
2548         break;
2549     case 2:
2550         fDoPhotonAsymmetryCut=1;
2551         fMinPPhotonAsymmetryCut=3.5;
2552         fMinPhotonAsymmetry=0.06;
2553         break;
2554     default:
2555         AliError(Form("PhotonAsymmetryCut not defined %d",doPhotonAsymmetryCut));
2556         return kFALSE;
2557     }
2558     fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
2559     return kTRUE;
2560 }
2561
2562 ///________________________________________________________________________
2563 Bool_t AliConversionCuts::SetBackgroundScheme(Int_t BackgroundScheme){
2564     // Set Cut
2565     switch(BackgroundScheme){
2566     case 0: //Rotation
2567         fUseRotationMethodInBG=kTRUE;
2568         fdoBGProbability=kFALSE;
2569         break;
2570     case 1: // mixed event with V0 multiplicity
2571         fUseRotationMethodInBG=kFALSE;
2572         fUseTrackMultiplicityForBG=kFALSE;
2573         fdoBGProbability=kFALSE;
2574         break;
2575     case 2: // mixed event with track multiplicity
2576         fUseRotationMethodInBG=kFALSE;
2577         fUseTrackMultiplicityForBG=kTRUE;
2578         fdoBGProbability=kFALSE;
2579         break;
2580     case 3: //Rotation
2581         fUseRotationMethodInBG=kTRUE;
2582         fdoBGProbability=kTRUE;
2583         break;
2584     default:
2585         AliError(Form("BackgroundScheme not defined %d",BackgroundScheme));
2586         return kFALSE;
2587     }
2588     return kTRUE;
2589 }
2590
2591 ///________________________________________________________________________
2592 Bool_t AliConversionCuts::SetNDegreesForRotationMethod(Int_t DegreesForRotationMethod){
2593     // Set Cut
2594     switch(DegreesForRotationMethod){
2595     case 0:
2596         fnDegreeRotationPMForBG = 5;
2597         break;
2598     case 1:
2599         fnDegreeRotationPMForBG = 10;
2600         break;
2601     case 2:
2602         fnDegreeRotationPMForBG = 15;
2603         break;
2604     case 3:
2605         fnDegreeRotationPMForBG = 20;
2606         break;
2607     default:
2608         AliError(Form("DegreesForRotationMethod not defined %d",DegreesForRotationMethod));
2609         return kFALSE;
2610     }
2611     fCuts[kDegreesForRotationMethod]=DegreesForRotationMethod;
2612     return kTRUE;
2613 }
2614
2615 ///________________________________________________________________________
2616 Bool_t AliConversionCuts::SetNumberOfRotations(Int_t NumberOfRotations)
2617 {   // Set Cut
2618     switch(NumberOfRotations){
2619     case 0:
2620         fnumberOfRotationEventsForBG = 5;
2621         break;
2622     case 1:
2623         fnumberOfRotationEventsForBG = 10;
2624         break;
2625     case 2:
2626         fnumberOfRotationEventsForBG = 15;
2627         break;
2628     case 3:
2629         fnumberOfRotationEventsForBG = 20;
2630         break;
2631     case 4:
2632         fnumberOfRotationEventsForBG = 2;
2633         break;
2634     case 5:
2635         fnumberOfRotationEventsForBG = 50;
2636         break;
2637     case 6:
2638         fnumberOfRotationEventsForBG = 80;
2639         break;
2640     case 7:
2641         fnumberOfRotationEventsForBG = 100;
2642         break;
2643     default:
2644         AliError(Form("NumberOfRotations not defined %d",NumberOfRotations));
2645         return kFALSE;
2646     }
2647     return kTRUE;
2648 }
2649
2650 ///________________________________________________________________________
2651 Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
2652   
2653
2654   switch(psiCut) {
2655   case 0:
2656         fPsiPairCut = 10000; // 
2657         break;
2658   case 1:
2659         fPsiPairCut = 0.1; // 
2660         break;
2661   case 2:
2662         fPsiPairCut = 0.05; // Standard
2663         break;
2664   case 3:
2665         fPsiPairCut = 0.035; // 
2666         break;
2667   case 4:
2668         fPsiPairCut = 0.15; // 
2669         break;
2670   case 5:
2671         fPsiPairCut = 0.2; // 
2672         break;
2673   case 6:
2674         fPsiPairCut = 0.03; // 
2675         break;
2676   case 7:
2677         fPsiPairCut = 0.025; // 
2678         break;
2679   case 8:
2680         fPsiPairCut = 0.01; // 
2681         break;
2682   default:
2683       AliError(Form("PsiPairCut not defined %d",psiCut));
2684       return kFALSE;
2685   }
2686
2687   return kTRUE;
2688 }
2689
2690 ///________________________________________________________________________
2691 Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
2692
2693     switch(cosCut){
2694     case 0:
2695         fCosPAngleCut = TMath::Pi(); //
2696         break;
2697     case 1:
2698         fCosPAngleCut = 0.1; //
2699         break;
2700     case 2:
2701         fCosPAngleCut = 0.05; //
2702         break;
2703     case 3:
2704         fCosPAngleCut = 0.025; // Standard
2705         break;
2706     case 4:
2707         fCosPAngleCut = 0.01; //
2708         break;
2709     default:
2710         AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
2711         return kFALSE;
2712     }
2713         
2714     return kTRUE;
2715 }
2716
2717
2718 ///________________________________________________________________________
2719 Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
2720     // Cut on z position of primary vertex
2721      Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
2722
2723      if(TMath::Abs(fVertexZ)>fMaxVertexZ)return kFALSE;
2724      return kTRUE;
2725 }
2726
2727 ///________________________________________________________________________
2728 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
2729
2730    switch(sharedElec){
2731     case 0:
2732        fDoSharedElecCut = kFALSE;
2733         break;
2734     case 1:
2735        fDoSharedElecCut = kTRUE;
2736         break;
2737     default:
2738         AliError(Form("Shared Electron Cut not defined %d",sharedElec));
2739         return kFALSE;
2740     }
2741         
2742     return kTRUE;
2743 }
2744
2745 ///________________________________________________________________________
2746 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
2747
2748    switch(toClose){
2749    case 0:
2750       fDoToCloseV0sCut = kFALSE;
2751       fminV0Dist = 250;
2752       break;
2753    case 1:
2754       fDoToCloseV0sCut = kTRUE;
2755       fminV0Dist = 1;
2756       break;
2757    case 2:
2758       fDoToCloseV0sCut = kTRUE;
2759       fminV0Dist = 2;
2760       break;
2761    case 3:
2762       fDoToCloseV0sCut = kTRUE;
2763       fminV0Dist = 3;
2764       break;
2765    default:
2766        AliError(Form("Shared Electron Cut not defined %d",toClose));
2767         return kFALSE;
2768    }
2769    return kTRUE;
2770 }
2771
2772
2773
2774 ///________________________________________________________________________
2775
2776 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
2777     // returns number of contributors to the vertex
2778     
2779     AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
2780     if(fESDEvent){
2781         if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors()>0) {
2782             return fESDEvent->GetPrimaryVertexTracks()->GetNContributors();
2783         }
2784      
2785         if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors()<1) {
2786             //          return 0;
2787             //-AM test pi0s without SPD only vertex
2788             if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
2789                 return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
2790
2791             }
2792             if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()<1) {
2793                 return 0;
2794             }
2795         }
2796     }
2797
2798     AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
2799     if(fAODEvent){
2800         if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
2801             return fAODEvent->GetPrimaryVertex()->GetNContributors();
2802         }
2803         if(fAODEvent->GetPrimaryVertex()->GetNContributors()<1) {
2804             if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
2805                 return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
2806             }
2807             if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()<1) {
2808                 AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
2809                 return 0;
2810             }
2811         }
2812     }
2813
2814
2815   return 0;
2816 }
2817
2818 ///________________________________________________________________________
2819
2820 Bool_t AliConversionCuts::IsTriggerSelected()
2821 {
2822     AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
2823
2824     UInt_t isSelected = AliVEvent::kAny;
2825     if( fInputHandler && fInputHandler->GetEventSelection()) {
2826         // Get the actual offline trigger mask for the event and AND it with the
2827         // requested mask. If no mask requested select by default the event.
2828         if (fOfflineTriggerMask)
2829             isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
2830     }
2831    
2832     if(!isSelected)return kFALSE;
2833
2834     // Fill Histogram
2835     if(hTriggerClass){
2836         if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(0);
2837         if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(1);
2838         if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(2);
2839         if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(3);
2840     }
2841
2842     
2843     return kTRUE;
2844
2845 }
2846
2847 ///________________________________________________________________________
2848 Int_t AliConversionCuts::GetFirstTPCRow(Double_t radius){
2849     // Get first TPC row
2850         Int_t firstTPCRow=0;
2851         Double_t radiusI        =       84.8;
2852         Double_t radiusO        = 134.6;
2853         Double_t radiusOB = 198.;
2854         Double_t rSizeI  = 0.75;
2855         Double_t rSizeO  = 1.;
2856         Double_t rSizeOB        = 1.5;
2857         Int_t nClsI=63;
2858         Int_t nClsIO=127;
2859
2860         if(radius <= radiusI){
2861                 return firstTPCRow;
2862         }
2863         if(radius>radiusI && radius<=radiusO){
2864                 firstTPCRow = (Int_t)((radius-radiusI)/rSizeI);
2865         }
2866         if(radius>radiusO && radius<=radiusOB){
2867                 firstTPCRow = (Int_t)(nClsI+(radius-radiusO)/rSizeO);
2868         }
2869
2870         if(radius>radiusOB){
2871                 firstTPCRow =(Int_t)(nClsIO+(radius-radiusOB)/rSizeOB);
2872         }
2873
2874         return firstTPCRow;
2875 }
2876
2877 Bool_t AliConversionCuts::CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const {
2878   ///Check if passes cosine of pointing angle cut
2879    if(GetCosineOfPointingAngle(photon, event) < (TMath::Cos(fCosPAngleCut))){
2880       return kFALSE;
2881    }
2882    return kTRUE;
2883 }
2884
2885 Double_t AliConversionCuts::GetCosineOfPointingAngle( const AliConversionPhotonBase * photon, AliVEvent * event) const{
2886    // calculates the pointing angle of the recalculated V0 
2887
2888    Double_t momV0[3] = {0,0,0};
2889    if(event->IsA()==AliESDEvent::Class()){
2890       AliESDEvent *esdEvent = dynamic_cast<AliESDEvent*>(event);
2891       AliESDv0 *v0 = esdEvent->GetV0(photon->GetV0Index());
2892       v0->GetPxPyPz(momV0[0],momV0[1],momV0[2]);
2893    }
2894    if(event->IsA()==AliAODEvent::Class()){
2895       momV0[0] = photon->GetPx();
2896       momV0[1] = photon->GetPy();
2897       momV0[2] = photon->GetPz();
2898    }
2899    
2900    //Double_t momV0[3] = { photon->GetPx(), photon->GetPy(), photon->GetPz() }; //momentum of the V0
2901    Double_t PosV0[3] = { photon->GetConversionX() - event->GetPrimaryVertex()->GetX(), 
2902                          photon->GetConversionY() - event->GetPrimaryVertex()->GetY(), 
2903                          photon->GetConversionZ() - event->GetPrimaryVertex()->GetZ() }; //Recalculated V0 Position vector
2904    
2905    Double_t momV02 = momV0[0]*momV0[0] + momV0[1]*momV0[1] + momV0[2]*momV0[2];
2906    Double_t PosV02 = PosV0[0]*PosV0[0] + PosV0[1]*PosV0[1] + PosV0[2]*PosV0[2];
2907
2908    Double_t cosinePointingAngle = (PosV0[0]*momV0[0] +  PosV0[1]*momV0[1] + PosV0[2]*momV0[2] ) / TMath::Sqrt(momV02 * PosV02);
2909   
2910    return cosinePointingAngle;
2911 }
2912
2913
2914 Bool_t AliConversionCuts::PsiPairCut(const AliConversionPhotonBase * photon) const {
2915
2916     if(photon->GetPsiPair() > fPsiPairCut){
2917         return kFALSE;}
2918     else{return kTRUE;}
2919
2920 }
2921
2922 ///________________________________________________________________________
2923 TString AliConversionCuts::GetCutNumber(){
2924     // returns TString with current cut number
2925   TString a(kNCuts);
2926   for(Int_t ii=0;ii<kNCuts;ii++){
2927       a.Append(Form("%d",fCuts[ii]));
2928   }
2929   return a;
2930 }
2931
2932 ///________________________________________________________________________
2933 void AliConversionCuts::SmearParticle(AliAODConversionPhoton* photon)
2934 {
2935    Double_t facPBrem = 1.;
2936    Double_t facPSig = 0.;
2937
2938    Double_t phi=0.;
2939    Double_t theta=0.;
2940    Double_t P=0.;
2941
2942    
2943    P=photon->P();
2944    phi=photon->Phi();
2945    if( photon->P()!=0){
2946       theta=acos( photon->Pz()/ photon->P());
2947    }
2948
2949    if( fPSigSmearing != 0. || fPSigSmearingCte!=0. ){ 
2950       facPSig = TMath::Sqrt(fPSigSmearingCte*fPSigSmearingCte+fPSigSmearing*fPSigSmearing*P*P)*fRandom.Gaus(0.,1.);
2951    }
2952         
2953    if( fPBremSmearing != 1.){
2954       if(fBrem!=NULL){
2955          facPBrem = fBrem->GetRandom();
2956       }
2957    }
2958
2959    photon->SetPx(facPBrem* (1+facPSig)* P*sin(theta)*cos(phi)) ;
2960    photon->SetPy(facPBrem* (1+facPSig)* P*sin(theta)*sin(phi)) ;
2961    photon->SetPz(facPBrem* (1+facPSig)* P*cos(theta)) ;
2962    photon->SetE(photon->P());
2963 }
2964 ///________________________________________________________________________
2965 void AliConversionCuts::FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0){
2966    
2967    Int_t posLabel = photon->GetTrackLabelPositive();
2968    Int_t negLabel = photon->GetTrackLabelNegative();
2969    
2970    fElectronLabelArray[nV0*2] = posLabel;
2971    fElectronLabelArray[(nV0*2)+1] = negLabel;
2972 }
2973 ///________________________________________________________________________
2974 Bool_t AliConversionCuts::RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s){
2975
2976    Int_t posLabel = photon->GetTrackLabelPositive();
2977    Int_t negLabel = photon->GetTrackLabelNegative();
2978    
2979    for(Int_t i = 0; i<nV0s*2;i++){
2980       if(i==nV0*2)     continue;
2981       if(i==(nV0*2)+1) continue;
2982       if(fElectronLabelArray[i] == posLabel){
2983          return kFALSE;}
2984       if(fElectronLabelArray[i] == negLabel){
2985          return kFALSE;}
2986    }
2987
2988    return kTRUE;
2989 }
2990 ///________________________________________________________________________
2991 Bool_t AliConversionCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0){
2992
2993
2994    Double_t posX = photon->GetConversionX();
2995    Double_t posY = photon->GetConversionY();
2996    Double_t posZ = photon->GetConversionZ();
2997
2998    for(Int_t i = 0;i<photons->GetEntries();i++){
2999       if(nV0 == i) continue;
3000       AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
3001       Double_t posCompX = photonComp->GetConversionX();
3002       Double_t posCompY = photonComp->GetConversionY();
3003       Double_t posCompZ = photonComp->GetConversionZ();
3004       
3005       Double_t dist = pow((posX - posCompX),2)+pow((posY - posCompY),2)+pow((posZ - posCompZ),2);
3006
3007       if(dist < fminV0Dist*fminV0Dist){
3008          if(photon->GetChi2perNDF() < photonComp->GetChi2perNDF()) return kTRUE;
3009          else {
3010             return kFALSE;}
3011       }
3012       
3013    }
3014    return kTRUE;
3015 }