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