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