5f770e70da08d4374c4ec1b8812eabbc7c6ff982
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliRDHFCutsLctopKpi.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2010, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
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 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////
19 //
20 // Class for cuts on AOD reconstructed Lc->pKpi
21 //
22 // Author: A.Dainese, andrea.dainese@pd.infn.it
23 /////////////////////////////////////////////////////////////
24
25 #include <TDatabasePDG.h>
26 #include <Riostream.h>
27 #include <AliAnalysisManager.h>
28 #include <AliInputEventHandler.h>
29 #include <AliPIDResponse.h>
30
31 #include "AliRDHFCutsLctopKpi.h"
32 #include "AliAODRecoDecayHF3Prong.h"
33 #include "AliRDHFCuts.h"
34 #include "AliAODTrack.h"
35 #include "AliESDtrack.h"
36 #include "AliKFParticle.h"
37 #include "AliESDVertex.h"
38
39 using std::cout;
40 using std::endl;
41
42 ClassImp(AliRDHFCutsLctopKpi)
43
44 //--------------------------------------------------------------------------
45 AliRDHFCutsLctopKpi::AliRDHFCutsLctopKpi(const char* name) : 
46 AliRDHFCuts(name),
47 fPidObjprot(0),
48 fPidObjpion(0),
49 fUseImpParProdCorrCut(kFALSE),
50 fPIDStrategy(kNSigma),
51 fCutsStrategy(kStandard),
52 fUseSpecialCut(kFALSE)
53 {
54   //
55   // Default Constructor
56   //
57   Int_t nvars=13;
58   SetNVars(nvars);
59   TString varNames[13]={"inv. mass [GeV]",
60                         "pTK [GeV/c]",
61                         "pTP [GeV/c]",
62                         "d0K [cm]   lower limit!",
63                         "d0Pi [cm]  lower limit!",
64                         "dist12 (cm)",
65                         "sigmavert (cm)",
66                         "dist prim-sec (cm)",
67                         "pM=Max{pT1,pT2,pT3} (GeV/c)",
68                         "cosThetaPoint",
69                         "Sum d0^2 (cm^2)",
70                         "dca cut (cm)",
71                         "cut on pTpion [GeV/c]"};
72   Bool_t isUpperCut[13]={kTRUE,
73                          kFALSE,
74                          kFALSE,
75                          kFALSE,
76                          kFALSE,
77                          kFALSE,
78                          kTRUE,
79                          kFALSE,
80                          kFALSE,
81                          kFALSE,
82                          kFALSE,
83                          kTRUE,
84                          kFALSE
85                          };
86   SetVarNames(nvars,varNames,isUpperCut);
87   Bool_t forOpt[13]={kFALSE,
88                      kTRUE,
89                      kTRUE,
90                      kFALSE,
91                      kFALSE,
92                      kFALSE,
93                      kFALSE,
94                      kTRUE,
95                      kFALSE,
96                      kFALSE,
97                      kFALSE,
98                      kFALSE,
99                      kTRUE};
100   SetVarsForOpt(4,forOpt);
101   Float_t limits[2]={0,999999999.};
102   SetPtBins(2,limits);
103   for (Int_t ispecies=0;ispecies<AliPID::kSPECIES;++ispecies)
104       fPIDThreshold[ispecies]=0.;
105 }
106 //--------------------------------------------------------------------------
107 AliRDHFCutsLctopKpi::AliRDHFCutsLctopKpi(const AliRDHFCutsLctopKpi &source) :
108   AliRDHFCuts(source),
109   fPidObjprot(0x0),
110   fPidObjpion(0x0),
111   fUseImpParProdCorrCut(source.fUseImpParProdCorrCut),
112   fPIDStrategy(source.fPIDStrategy),
113   fCutsStrategy(source.fCutsStrategy),
114   fUseSpecialCut(source.fUseSpecialCut)
115 {
116   //
117   // Copy constructor
118   //
119   if (source.fPidObjprot) fPidObjprot = new AliAODPidHF(*(source.fPidObjprot));
120   else fPidObjprot = new AliAODPidHF();
121   if (source.fPidObjpion) fPidObjpion = new AliAODPidHF(*(source.fPidObjpion));
122   else fPidObjpion = new AliAODPidHF();
123   memcpy(fPIDThreshold,source.fPIDThreshold,AliPID::kSPECIES*sizeof(Double_t));
124 }
125 //--------------------------------------------------------------------------
126 AliRDHFCutsLctopKpi &AliRDHFCutsLctopKpi::operator=(const AliRDHFCutsLctopKpi &source)
127 {
128   //
129   // assignment operator
130   //
131   if(this != &source) {
132     
133     AliRDHFCuts::operator=(source);
134     delete fPidObjprot;
135     fPidObjprot = new AliAODPidHF(*(source.fPidObjprot));
136     delete fPidObjpion;
137     fPidObjpion = new AliAODPidHF(*(source.fPidObjpion));
138     fPIDStrategy=source.fPIDStrategy;
139     fCutsStrategy=source.fCutsStrategy;
140     memcpy(fPIDThreshold,source.fPIDThreshold,AliPID::kSPECIES*sizeof(Double_t));
141   }
142     
143   return *this;
144 }
145 //---------------------------------------------------------------------------
146 AliRDHFCutsLctopKpi::~AliRDHFCutsLctopKpi() {
147  //
148  //  // Default Destructor
149  //   
150  if(fPidObjpion){
151   delete fPidObjpion;
152   fPidObjpion=0;
153  }
154  if(fPidObjprot){
155   delete fPidObjprot;
156   fPidObjprot=0;
157  }
158
159 }
160
161 //---------------------------------------------------------------------------
162 void AliRDHFCutsLctopKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,Int_t nvars,Int_t *pdgdaughters, AliAODEvent *aod) {
163   // 
164   // Fills in vars the values of the variables 
165   //
166
167   if(nvars!=fnVarsForOpt) {
168     printf("AliRDHFCutsLctopKpi::GetCutsVarsForOpt: wrong number of variables\n");
169     return;
170   }
171
172   AliAODRecoDecayHF3Prong *dd = (AliAODRecoDecayHF3Prong*)d;
173
174   Int_t iter=-1;
175   if(fVarsForOpt[0]){
176     iter++;
177     vars[iter]=dd->InvMassLcpKpi();
178   }
179   if(fVarsForOpt[1]){
180     iter++;
181     for(Int_t iprong=0;iprong<3;iprong++){
182       if(TMath::Abs(pdgdaughters[iprong])==321) {
183         vars[iter]=dd->PtProng(iprong);
184       }
185     }
186   }
187   if(fVarsForOpt[2]){
188     iter++;
189     for(Int_t iprong=0;iprong<3;iprong++){
190       if(TMath::Abs(pdgdaughters[iprong])==2212) {
191         vars[iter]=dd->PtProng(iprong);
192       }
193     }
194   }
195   if(fVarsForOpt[3]){
196     iter++;
197     for(Int_t iprong=0;iprong<3;iprong++){
198       if(TMath::Abs(pdgdaughters[iprong])==2212) {
199         vars[iter]=dd->Getd0Prong(iprong);
200       }
201     }
202   }
203   if(fVarsForOpt[4]){
204     iter++;
205     for(Int_t iprong=0;iprong<3;iprong++){
206       if(TMath::Abs(pdgdaughters[iprong])==211) {
207         vars[iter]=dd->Getd0Prong(iprong);
208       }
209     }
210   }
211   if(fVarsForOpt[5]){
212     iter++;
213     vars[iter]=dd->GetDist12toPrim();
214   }
215   if(fVarsForOpt[6]){
216     iter++;
217     vars[iter]=dd->GetSigmaVert(aod);
218   }
219   if(fVarsForOpt[7]){
220     iter++;
221     vars[iter] = dd->DecayLength();
222   }
223   if(fVarsForOpt[8]){
224     iter++;
225     Float_t ptmax=0;
226     for(Int_t i=0;i<3;i++){
227       if(dd->PtProng(i)>ptmax)ptmax=dd->PtProng(i);
228     }
229     vars[iter]=ptmax;
230   }
231   if(fVarsForOpt[9]){
232     iter++;
233     vars[iter]=dd->CosPointingAngle();
234   }
235   if(fVarsForOpt[10]){
236     iter++;
237     vars[iter]=dd->Getd0Prong(0)*dd->Getd0Prong(0)+dd->Getd0Prong(1)*dd->Getd0Prong(1)+dd->Getd0Prong(2)*dd->Getd0Prong(2);
238   }
239   if(fVarsForOpt[11]){
240     iter++;
241     vars[iter]=dd->GetDCA();
242   }
243   if(fVarsForOpt[12]){
244     iter++;
245     for(Int_t iprong=0;iprong<3;iprong++){
246       if(TMath::Abs(pdgdaughters[iprong])==211) {
247         vars[iter]=dd->PtProng(iprong);
248       }
249     }
250   }
251
252   return;
253 }
254 //---------------------------------------------------------------------------
255 Int_t AliRDHFCutsLctopKpi::IsSelected(TObject* obj,Int_t selectionLevel,AliAODEvent *aod) {
256   //
257   // Apply selection
258   //
259
260   if(!fCutsRD){
261     AliError("Cut matrice not inizialized. Exit...\n");
262     return 0;
263   }
264   //PrintAll();
265   AliAODRecoDecayHF3Prong* d=(AliAODRecoDecayHF3Prong*)obj;
266
267   if(!d){
268     AliError("AliAODRecoDecayHF3Prong null \n");
269     return 0;
270   }
271
272
273   if(fKeepSignalMC) if(IsSignalMC(d,aod,4122)) return 3;
274
275   Int_t returnvalue=3;
276   Int_t returnvaluePID=3;
277
278   if(d->Pt()<fMinPtCand) return 0;
279   if(d->Pt()>fMaxPtCand) return 0;
280
281   if(fUseTrackSelectionWithFilterBits && d->HasBadDaughters()) return 0;
282
283
284   // selection on daughter tracks 
285   if(selectionLevel==AliRDHFCuts::kAll || 
286      selectionLevel==AliRDHFCuts::kTracks) {
287     if(!AreDaughtersSelected(d)) return 0;
288   }
289
290
291   // PID selection
292   if(selectionLevel==AliRDHFCuts::kAll ||
293      selectionLevel==AliRDHFCuts::kCandidate|| 
294      selectionLevel==AliRDHFCuts::kPID) {
295     switch (fPIDStrategy) {
296     case kNSigma:
297       returnvaluePID = IsSelectedPID(d);
298       break;
299     case kCombined:
300       returnvaluePID = IsSelectedCombinedPID(d);
301       break;
302     case kCombinedSoft:
303       returnvaluePID = IsSelectedCombinedPIDSoft(d);
304       break;
305     case kNSigmaStrong:
306       returnvaluePID = IsSelectedPIDStrong(d);
307       break;
308     case kCombinedpPb:
309       returnvaluePID = IsSelectedCombinedPIDpPb(d);
310       break;
311     case kCombinedpPb2:
312       returnvaluePID = IsSelectedCombinedPIDpPb2(d);
313       break;
314     }
315     fIsSelectedPID=returnvaluePID;
316   }
317   //  if(fUsePID || selectionLevel==AliRDHFCuts::kPID) returnvaluePID = IsSelectedCombinedPID(d);   // to test!!
318   if(returnvaluePID==0) return 0;
319
320
321
322
323   // selection on candidate
324   if(selectionLevel==AliRDHFCuts::kAll || 
325      selectionLevel==AliRDHFCuts::kCandidate) {
326
327     Double_t pt=d->Pt();
328     
329     Int_t ptbin=PtBin(pt);
330     
331     Double_t mLcpKpi=0.,mLcpiKp=0.;
332     Int_t okLcpKpi=1,okLcpiKp=1;
333
334     Double_t mLcPDG = TDatabasePDG::Instance()->GetParticle(4122)->Mass();
335
336     mLcpKpi=d->InvMassLcpKpi();
337     mLcpiKp=d->InvMassLcpiKp();
338
339     if(TMath::Abs(mLcpKpi-mLcPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okLcpKpi = 0;
340     if(TMath::Abs(mLcpiKp-mLcPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okLcpiKp = 0;
341     if(!okLcpKpi && !okLcpiKp) return 0;
342
343   switch (fCutsStrategy) {
344
345     case kStandard:
346     if(TMath::Abs(d->PtProng(1)) < fCutsRD[GetGlobalIndex(1,ptbin)] || TMath::Abs(d->Getd0Prong(1))<fCutsRD[GetGlobalIndex(3,ptbin)]) return 0;//Kaon
347     if(d->Pt()>=3. && d->PProng(1)<0.55) return 0;
348     if(fUseSpecialCut) {
349       if(TMath::Abs(d->PtProng(0)) < TMath::Abs(d->PtProng(2)) )okLcpKpi=0;
350       if(TMath::Abs(d->PtProng(2)) < TMath::Abs(d->PtProng(0)) )okLcpiKp=0;
351     }
352     if((TMath::Abs(d->PtProng(0)) < fCutsRD[GetGlobalIndex(2,ptbin)]) || (TMath::Abs(d->PtProng(2)) < fCutsRD[GetGlobalIndex(12,ptbin)])) okLcpKpi=0;
353     if((TMath::Abs(d->PtProng(2)) < fCutsRD[GetGlobalIndex(2,ptbin)]) || (TMath::Abs(d->PtProng(0)) < fCutsRD[GetGlobalIndex(12,ptbin)]))okLcpiKp=0;
354     if(!okLcpKpi && !okLcpiKp) return 0;
355     //2track cuts
356     if(d->GetDist12toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)]|| d->GetDist23toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)]) return 0;
357     if(d->GetDist12toPrim()>0.5) return 0;
358     if(d->GetDist23toPrim()>0.5) return 0;
359     if(fUseImpParProdCorrCut){
360       if(d->Getd0Prong(0)*d->Getd0Prong(1)<0. && d->Getd0Prong(2)*d->Getd0Prong(1)<0.) return 0;
361     }
362     //sec vert
363     if(d->DecayLength()<fCutsRD[GetGlobalIndex(7,ptbin)]) return 0;
364     if(d->DecayLength()>0.5) return 0;
365
366   //  Double_t sumd0s=d->Getd0Prong(0)*d->Getd0Prong(0)+d->Getd0Prong(1)*d->Getd0Prong(1)+d->Getd0Prong(2)*d->Getd0Prong(2);
367   //  if(sumd0s<fCutsRD[GetGlobalIndex(10,ptbin)]) return 0;
368     if((d->Getd0Prong(0)*d->Getd0Prong(0)+d->Getd0Prong(1)*d->Getd0Prong(1)+d->Getd0Prong(2)*d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(10,ptbin)]) return 0;
369     
370     if(TMath::Abs(d->PtProng(0))<fCutsRD[GetGlobalIndex(8,ptbin)] && TMath::Abs(d->PtProng(1))<fCutsRD[GetGlobalIndex(8,ptbin)] && TMath::Abs(d->PtProng(2))<fCutsRD[GetGlobalIndex(8,ptbin)]) return 0;
371     if(d->CosPointingAngle()< fCutsRD[GetGlobalIndex(9,ptbin)]) return 0;
372     if(d->GetSigmaVert(aod)>fCutsRD[GetGlobalIndex(6,ptbin)]) return 0;
373     
374     //DCA
375     for(Int_t i=0;i<3;i++) if(d->GetDCA(i)>fCutsRD[GetGlobalIndex(11,ptbin)]) return 0;
376
377     break;
378
379    case kKF:
380     Int_t pdgs[3]={0,321,0};
381     Bool_t constraint=kFALSE;
382     if(fCutsRD[GetGlobalIndex(1,ptbin)]>0.) constraint=kTRUE;
383     Double_t field=aod->GetMagneticField();
384     if (returnvaluePID==1 || returnvaluePID==3){
385
386       pdgs[0]=2122;pdgs[2]=211;
387       AliKFParticle *lc1=ReconstructKF(d,pdgs,field,constraint);
388       if(!lc1){
389         okLcpKpi=0;
390       }else{
391         if(lc1->GetChi2()/lc1->GetNDF()>fCutsRD[GetGlobalIndex(2,ptbin)]) okLcpKpi=0;
392       }
393     } else if(returnvaluePID>=2){
394
395       pdgs[0]=211;pdgs[2]=2212;
396       AliKFParticle *lc2=ReconstructKF(d,pdgs,field,constraint);
397       if(!lc2){ 
398         okLcpiKp=0;
399       }else{
400         if(lc2->GetChi2()/lc2->GetNDF()>fCutsRD[GetGlobalIndex(2,ptbin)])okLcpiKp=0; 
401       }
402     }
403     break;
404
405    }
406
407     if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
408     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
409     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
410    
411   }
412
413
414   Int_t returnvalueTot=CombinePIDCuts(returnvalue,returnvaluePID);
415   return returnvalueTot;
416 }
417 //---------------------------------------------------------------------------
418 Int_t AliRDHFCutsLctopKpi::IsSelectedPID(AliAODRecoDecayHF* obj) {
419
420
421     if(!fUsePID || !obj) return 3;
422     Int_t okLcpKpi=0,okLcpiKp=0;
423     Int_t returnvalue=0;
424     Bool_t isPeriodd=fPidHF->GetOnePad();
425     Bool_t isMC=fPidHF->GetMC();
426     Bool_t ispion0=kTRUE,ispion2=kTRUE;
427     Bool_t isproton0=kFALSE,isproton2=kFALSE;
428     Bool_t iskaon1=kFALSE;
429     if(isPeriodd) {
430      fPidObjprot->SetOnePad(kTRUE);
431      fPidObjpion->SetOnePad(kTRUE);
432     }
433     if(isMC) {
434      fPidObjprot->SetMC(kTRUE);
435      fPidObjpion->SetMC(kTRUE);
436     }
437
438    if(fPidObjprot->GetPidResponse()==0x0){
439       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
440       AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
441       AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
442       fPidObjprot->SetPidResponse(pidResp);
443     }
444     if(fPidObjpion->GetPidResponse()==0x0){
445       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
446       AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
447       AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
448       fPidObjpion->SetPidResponse(pidResp);
449     }
450     if(fPidHF->GetPidResponse()==0x0){
451       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
452       AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
453       AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
454       fPidHF->SetPidResponse(pidResp);
455     }
456
457     for(Int_t i=0;i<3;i++){
458      AliAODTrack *track=(AliAODTrack*)obj->GetDaughter(i);
459      if(!track) return 0;
460      // identify kaon
461      if(track->P()<0.55){
462       fPidHF->SetTOF(kFALSE);
463       fPidHF->SetTOFdecide(kFALSE);
464      }
465      if(i==1) {
466       Int_t isKaon=fPidHF->MakeRawPid(track,3); 
467       if(isKaon>=1) iskaon1=kTRUE;
468       if(track->P()<0.55){
469        fPidHF->SetTOF(kTRUE);
470        fPidHF->SetTOFdecide(kTRUE);
471       }
472       
473       if(!iskaon1) return 0;
474      
475      }else{
476      //pion or proton
477     if(track->P()<1.){
478       fPidObjprot->SetTOF(kFALSE);
479       fPidObjprot->SetTOFdecide(kFALSE);
480      }
481       
482      Int_t isProton=fPidObjprot->MakeRawPid(track,4);
483      
484
485      Int_t isPion=fPidObjpion->MakeRawPid(track,2);
486      
487      if(track->P()<1.){
488       fPidObjprot->SetTOF(kTRUE);
489       fPidObjprot->SetTOFdecide(kTRUE);
490      }
491      
492
493      if(i==0) {
494       if(isPion<0) ispion0=kFALSE;
495       if(isProton>=1) isproton0=kTRUE;
496
497      }
498       if(!ispion0 && !isproton0) return 0;
499      if(i==2) {
500       if(isPion<0) ispion2=kFALSE;
501       if(isProton>=1) isproton2=kTRUE;
502      }
503
504     }
505    }
506
507     if(ispion2 && isproton0 && iskaon1) okLcpKpi=1;
508     if(ispion0 && isproton2 && iskaon1) okLcpiKp=1;
509     if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
510     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
511     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
512
513  return returnvalue;
514 }
515 //---------------------------------------------------------------------------
516 Int_t AliRDHFCutsLctopKpi::IsSelectedCombinedPID(AliAODRecoDecayHF* obj) {
517     
518     if(!fUsePID || !obj) {return 3;}
519     Int_t okLcpKpi=0,okLcpiKp=0;
520     Int_t returnvalue=0;
521     Bool_t isPeriodd=fPidHF->GetOnePad();
522     Bool_t isMC=fPidHF->GetMC();
523
524     if(isPeriodd) {
525             fPidObjprot->SetOnePad(kTRUE);
526             fPidObjpion->SetOnePad(kTRUE);
527     }
528     if(isMC) {
529             fPidObjprot->SetMC(kTRUE);
530             fPidObjpion->SetMC(kTRUE);
531     }
532
533     AliVTrack *track0=dynamic_cast<AliVTrack*>(obj->GetDaughter(0));
534     AliVTrack *track1=dynamic_cast<AliVTrack*>(obj->GetDaughter(1));
535     AliVTrack *track2=dynamic_cast<AliVTrack*>(obj->GetDaughter(2));
536     if (!track0 || !track1 || !track2) return 0;
537     Double_t prob0[AliPID::kSPECIES];
538     Double_t prob1[AliPID::kSPECIES];
539     Double_t prob2[AliPID::kSPECIES];
540     if(obj->Pt()<3. && track0->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
541     fPidHF->GetPidCombined()->ComputeProbabilities(track0,fPidHF->GetPidResponse(),prob0);
542     if(obj->Pt()<3. && track0->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
543
544    if(obj->Pt()<3. && track1->P()<0.55) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
545     fPidHF->GetPidCombined()->ComputeProbabilities(track1,fPidHF->GetPidResponse(),prob1);
546    if(obj->Pt()<3. && track1->P()<0.55) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
547
548     if(obj->Pt()<3. && track2->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
549     fPidHF->GetPidCombined()->ComputeProbabilities(track2,fPidHF->GetPidResponse(),prob2);
550    if(obj->Pt()<3. && track2->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
551
552     if(fPIDThreshold[AliPID::kPion]>0. && fPIDThreshold[AliPID::kKaon]>0. && fPIDThreshold[AliPID::kProton]>0.){
553     okLcpiKp=  (prob0[AliPID::kPion  ]>fPIDThreshold[AliPID::kPion  ])
554              &&(prob1[AliPID::kKaon  ]>fPIDThreshold[AliPID::kKaon  ])
555              &&(prob2[AliPID::kProton]>fPIDThreshold[AliPID::kProton]);
556     okLcpKpi=  (prob0[AliPID::kProton]>fPIDThreshold[AliPID::kProton])
557              &&(prob1[AliPID::kKaon  ]>fPIDThreshold[AliPID::kKaon  ])
558              &&(prob2[AliPID::kPion  ]>fPIDThreshold[AliPID::kPion  ]);
559    }else{ 
560                     //pion or proton
561                     
562                     
563     if(TMath::MaxElement(AliPID::kSPECIES,prob1) == prob1[AliPID::kKaon]){
564     if(TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kPion]) okLcpKpi = 1;  
565     if(TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kPion]) okLcpiKp = 1; 
566             }
567            }
568     
569     if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
570     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
571     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
572     
573     return returnvalue;
574 }
575 //-----------------------
576 Int_t AliRDHFCutsLctopKpi::CombinePIDCuts(Int_t returnvalue, Int_t returnvaluePID) const {
577
578  Int_t returnvalueTot=0;
579  Int_t okLcpKpi=0,okLcpiKp=0;
580  if(returnvaluePID==1){
581    if(returnvalue==1 || returnvalue==3) okLcpKpi=1;
582  }
583  if(returnvaluePID==2){
584    if(returnvalue>=2) okLcpiKp=1;
585  }
586  if(returnvaluePID==3 && returnvalue>0){
587   if(returnvalue==1 || returnvalue==3) okLcpKpi=1;
588   if(returnvalue>=2) okLcpiKp=1;
589  } 
590
591  if(okLcpKpi) returnvalueTot=1; //cuts passed as Lc->pKpi
592  if(okLcpiKp) returnvalueTot=2; //cuts passed as Lc->piKp
593  if(okLcpKpi && okLcpiKp) returnvalueTot=3; //cuts passed as both pKpi and piKp
594  return returnvalueTot;
595 }
596 //----------------------------------
597 void AliRDHFCutsLctopKpi::SetStandardCutsPP2010() {
598
599  SetName("LctopKpiProdCuts");
600  SetTitle("Production cuts for Lc analysis");
601
602  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
603  esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
604  esdTrackCuts->SetRequireTPCRefit(kTRUE);
605  esdTrackCuts->SetMinNClustersTPC(70);
606  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,
607                                           AliESDtrackCuts::kAny);
608  esdTrackCuts->SetRequireITSRefit(kTRUE);
609  esdTrackCuts->SetMinNClustersITS(4);
610  esdTrackCuts->SetMinDCAToVertexXY(0.);
611  esdTrackCuts->SetEtaRange(-0.8,0.8);
612  esdTrackCuts->SetPtRange(0.3,1.e10);
613  AddTrackCuts(esdTrackCuts);
614
615  const Int_t nptbins=4;
616  const Int_t nvars=13;
617  Float_t* ptbins;
618  ptbins=new Float_t[nptbins+1];
619  
620  ptbins[0]=0.;
621  ptbins[1]=2.;
622  ptbins[2]=3.;
623  ptbins[3]=4.;
624  ptbins[4]=9999.;
625
626  SetGlobalIndex(nvars,nptbins);
627  SetPtBins(nptbins+1,ptbins);
628
629  Float_t** prodcutsval;
630  prodcutsval=new Float_t*[nvars];
631  for(Int_t iv=0;iv<nvars;iv++){
632   prodcutsval[iv]=new Float_t[nptbins];
633  }
634
635  for(Int_t ipt=0;ipt<nptbins;ipt++){
636   prodcutsval[0][ipt]=0.18;
637   prodcutsval[1][ipt]=0.4;
638   prodcutsval[2][ipt]=0.5;
639   prodcutsval[3][ipt]=0.;
640   prodcutsval[4][ipt]=0.;
641   prodcutsval[5][ipt]=0.01;
642   prodcutsval[6][ipt]=0.06;
643   prodcutsval[7][ipt]=0.005;
644   prodcutsval[8][ipt]=0.;
645   prodcutsval[9][ipt]=0.;
646   prodcutsval[10][ipt]=0.;
647   prodcutsval[11][ipt]=0.05;
648   prodcutsval[12][ipt]=0.4;
649  }
650  SetCuts(nvars,nptbins,prodcutsval);
651
652  AliAODPidHF* pidObjK=new AliAODPidHF();
653  Double_t sigmasK[5]={3.,1.,1.,3.,2.};
654  pidObjK->SetSigma(sigmasK);
655  pidObjK->SetAsym(kTRUE);
656  pidObjK->SetMatch(1);
657  pidObjK->SetTPC(kTRUE);
658  pidObjK->SetTOF(kTRUE);
659  pidObjK->SetITS(kTRUE);
660  Double_t plimK[2]={0.5,0.8};
661  pidObjK->SetPLimit(plimK,2);
662  pidObjK->SetTOFdecide(kTRUE);
663
664  SetPidHF(pidObjK);
665
666  AliAODPidHF* pidObjpi=new AliAODPidHF();
667  pidObjpi->SetTPC(kTRUE);
668  Double_t sigmaspi[5]={3.,0.,0.,0.,0.};
669  pidObjpi->SetSigma(sigmaspi);
670  pidObjpi->SetTOFdecide(kTRUE);
671  SetPidpion(pidObjpi);
672
673  AliAODPidHF* pidObjp=new AliAODPidHF();
674  Double_t sigmasp[5]={3.,1.,1.,3.,2.};
675  pidObjp->SetSigma(sigmasp);
676  pidObjp->SetAsym(kTRUE);
677  pidObjp->SetMatch(1);
678  pidObjp->SetTPC(kTRUE);
679  pidObjp->SetTOF(kTRUE);
680  pidObjp->SetITS(kTRUE);
681  Double_t plimp[2]={1.,2.};
682  pidObjp->SetPLimit(plimp,2);
683  pidObjp->SetTOFdecide(kTRUE);
684
685  SetPidprot(pidObjp);
686
687  SetUsePID(kTRUE);
688
689  PrintAll();
690
691  for(Int_t iiv=0;iiv<nvars;iiv++){
692   delete [] prodcutsval[iiv];
693  }
694  delete [] prodcutsval;
695  prodcutsval=NULL;
696  delete [] ptbins;
697  ptbins=NULL;
698
699  delete pidObjK;
700  pidObjK=NULL;
701  delete pidObjpi;
702  pidObjpi=NULL;
703  delete pidObjp;
704  pidObjp=NULL;
705
706  return;
707 }
708 //------------------
709 void AliRDHFCutsLctopKpi::SetStandardCutsPbPb2010() {
710
711  SetName("LctopKpiProdCuts");
712  SetTitle("Production cuts for Lc analysis");
713
714  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
715
716  esdTrackCuts->SetRequireTPCRefit(kTRUE);
717  esdTrackCuts->SetMinNClustersTPC(70);
718  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,
719                                           AliESDtrackCuts::kAny);
720  esdTrackCuts->SetRequireITSRefit(kTRUE);
721  esdTrackCuts->SetMinNClustersITS(4);
722  esdTrackCuts->SetMinDCAToVertexXYPtDep("0.0100*TMath::Max(0.,(1-TMath::Floor(TMath::Abs(pt)/2.)))");
723  esdTrackCuts->SetEtaRange(-0.8,0.8);
724  esdTrackCuts->SetMaxDCAToVertexXY(1.);
725  esdTrackCuts->SetMaxDCAToVertexZ(1.);
726  esdTrackCuts->SetPtRange(0.49,1.e10);
727  AddTrackCuts(esdTrackCuts);
728
729  const Int_t nptbins=4;
730  const Int_t nvars=13;
731  Float_t* ptbins;
732  ptbins=new Float_t[nptbins+1];
733  
734  ptbins[0]=0.;
735  ptbins[1]=2.;
736  ptbins[2]=3.;
737  ptbins[3]=4.;
738  ptbins[4]=9999.;
739
740  SetGlobalIndex(nvars,nptbins);
741  SetPtBins(nptbins+1,ptbins);
742
743  Float_t** prodcutsval;
744  prodcutsval=new Float_t*[nvars];
745  for(Int_t iv=0;iv<nvars;iv++){
746   prodcutsval[iv]=new Float_t[nptbins];
747  }
748
749  for(Int_t ipt=0;ipt<nptbins;ipt++){
750   prodcutsval[0][ipt]=0.13;
751   prodcutsval[1][ipt]=0.5;
752   prodcutsval[2][ipt]=0.6;
753   prodcutsval[3][ipt]=0.;
754   prodcutsval[4][ipt]=0.;
755   prodcutsval[5][ipt]=0.01;
756   prodcutsval[6][ipt]=0.04;
757   prodcutsval[7][ipt]=0.006;
758   prodcutsval[8][ipt]=0.8;
759   prodcutsval[9][ipt]=0.3;
760   prodcutsval[10][ipt]=0.;
761   prodcutsval[11][ipt]=0.05;
762   prodcutsval[12][ipt]=0.4;
763  }
764  SetCuts(nvars,nptbins,prodcutsval);
765
766  AliAODPidHF* pidObjK=new AliAODPidHF();
767  Double_t sigmasK[5]={3.,1.,1.,3.,2.};
768  pidObjK->SetSigma(sigmasK);
769  pidObjK->SetAsym(kTRUE);
770  pidObjK->SetMatch(1);
771  pidObjK->SetTPC(kTRUE);
772  pidObjK->SetTOF(kTRUE);
773  pidObjK->SetITS(kTRUE);
774  Double_t plimK[2]={0.5,0.8};
775  pidObjK->SetPLimit(plimK,2);
776
777  SetPidHF(pidObjK);
778
779  AliAODPidHF* pidObjpi=new AliAODPidHF();
780  pidObjpi->SetTPC(kTRUE);
781  Double_t sigmaspi[5]={3.,0.,0.,0.,0.};
782  pidObjpi->SetSigma(sigmaspi);
783  SetPidpion(pidObjpi);
784
785  AliAODPidHF* pidObjp=new AliAODPidHF();
786  Double_t sigmasp[5]={3.,1.,1.,3.,2.};
787  pidObjp->SetSigma(sigmasp);
788  pidObjp->SetAsym(kTRUE);
789  pidObjp->SetMatch(1);
790  pidObjp->SetTPC(kTRUE);
791  pidObjp->SetTOF(kTRUE);
792  pidObjp->SetITS(kTRUE);
793  Double_t plimp[2]={1.,2.};
794  pidObjp->SetPLimit(plimp,2);
795
796  SetPidprot(pidObjp);
797
798  SetUsePID(kTRUE);
799
800  PrintAll();
801
802  for(Int_t iiv=0;iiv<nvars;iiv++){
803   delete [] prodcutsval[iiv];
804  }
805  delete [] prodcutsval;
806  prodcutsval=NULL;
807  delete [] ptbins;
808  ptbins=NULL;
809
810  delete pidObjK;
811  pidObjK=NULL;
812  delete pidObjpi;
813  pidObjpi=NULL;
814  delete pidObjp;
815  pidObjp=NULL;
816
817  return;
818 }
819 //------------------
820 AliKFParticle* AliRDHFCutsLctopKpi::ReconstructKF(AliAODRecoDecayHF3Prong *d,Int_t *pdgs,Double_t field,Bool_t constraint) const{
821   // Method to construct the KF particle from the candidate
822
823  const Int_t nprongs=d->GetNProngs();
824  if(nprongs<=0) return 0x0;
825
826  Int_t iprongs[nprongs];
827  for(Int_t i=0;i<nprongs;i++) iprongs[i]=i;
828
829  Double_t mass[2]={0.,0.};
830
831  AliKFParticle *decay=d->ApplyVertexingKF(iprongs,nprongs,pdgs,constraint,field,mass);
832  if(!decay) return 0x0;
833  AliESDVertex *vertexESD = new AliESDVertex(decay->Parameters(),
834                                             decay->CovarianceMatrix(),
835                                             decay->GetChi2(),
836                                             nprongs);
837  Double_t pos[3],cov[6],chi2perNDF;
838  vertexESD->GetXYZ(pos);
839  vertexESD->GetCovMatrix(cov);
840  chi2perNDF = vertexESD->GetChi2toNDF();
841  delete vertexESD; vertexESD=NULL;
842  AliAODVertex *vertexAOD = new AliAODVertex(pos,cov,chi2perNDF,0x0,-1,AliAODVertex::kUndef,nprongs);
843  d->SetSecondaryVtx(vertexAOD);
844  return decay;
845 }
846
847 //------------------
848 void AliRDHFCutsLctopKpi::SetStandardCutsPbPb2011() {
849
850   // Default 2010 PbPb cut object
851   SetStandardCutsPbPb2010();
852
853   //
854   // Enable all 2011 PbPb run triggers
855   //  
856   SetTriggerClass("");
857   ResetMaskAndEnableMBTrigger();
858   EnableCentralTrigger();
859   EnableSemiCentralTrigger();
860 }
861 //-----------------
862
863 Bool_t AliRDHFCutsLctopKpi::IsInFiducialAcceptance(Double_t pt, Double_t y) const
864 {
865   //
866   //  // Checking if Lc is in fiducial acceptance region 
867   //    //
868   //
869   if(fMaxRapidityCand>-998.){
870     if(TMath::Abs(y) > fMaxRapidityCand) return kFALSE;
871     else return kTRUE;
872   }
873
874   if(pt > 5.) {
875     // applying cut for pt > 5 GeV
876    AliDebug(2,Form("pt of Lc = %f (> 5), cutting at |y| < 0.8",pt));
877    if (TMath::Abs(y) > 0.8) return kFALSE;
878   
879   } else {
880    // appliying smooth cut for pt < 5 GeV
881    Double_t maxFiducialY = -0.2/15*pt*pt+1.9/15*pt+0.5;
882    Double_t minFiducialY = 0.2/15*pt*pt-1.9/15*pt-0.5;
883   AliDebug(2,Form("pt of Lc = %f (< 5), cutting  according to the fiducial zone [%f, %f]\n",pt,minFiducialY,maxFiducialY));
884   if (y < minFiducialY || y > maxFiducialY) return kFALSE;
885  }
886   //
887   return kTRUE;
888 }
889 //--------------------------------------------------------
890 Int_t AliRDHFCutsLctopKpi::IsSelectedCombinedPIDSoft(AliAODRecoDecayHF* obj) {
891  if(!fUsePID || !obj) {return 3;}
892  Int_t okLcpKpi=0,okLcpiKp=0;
893  Int_t returnvalue=0;
894  
895  AliVTrack *track0=dynamic_cast<AliVTrack*>(obj->GetDaughter(0));
896  AliVTrack *track1=dynamic_cast<AliVTrack*>(obj->GetDaughter(1));
897  AliVTrack *track2=dynamic_cast<AliVTrack*>(obj->GetDaughter(2));
898  if (!track0 || !track1 || !track2) return 0;
899  Double_t prob0[AliPID::kSPECIES];
900  Double_t prob1[AliPID::kSPECIES];
901  Double_t prob2[AliPID::kSPECIES];
902
903  Bool_t isTOF0=fPidHF->CheckTOFPIDStatus((AliAODTrack*)obj->GetDaughter(0));
904  Bool_t isTOF1=fPidHF->CheckTOFPIDStatus((AliAODTrack*)obj->GetDaughter(1));
905  Bool_t isTOF2=fPidHF->CheckTOFPIDStatus((AliAODTrack*)obj->GetDaughter(2));
906
907 Bool_t isK1=kFALSE;
908  if(isTOF1){ //kaon
909   if(track1->P()<1.8) {
910     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
911     if(obj->Pt()<3. && track1->P()<0.55) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
912     fPidHF->GetPidCombined()->ComputeProbabilities(track1,fPidHF->GetPidResponse(),prob1);
913    
914   }else{
915     AliAODTrack *trackaod1=(AliAODTrack*)(obj->GetDaughter(1));
916     if(trackaod1->P()<0.55){
917       fPidHF->SetTOF(kFALSE);
918       fPidHF->SetTOFdecide(kFALSE);
919      }
920     Int_t isKaon=fPidHF->MakeRawPid(trackaod1,3);
921     if(isKaon>=1) isK1=kTRUE;
922     if(trackaod1->P()<0.55){
923       fPidHF->SetTOF(kTRUE);
924       fPidHF->SetTOFdecide(kTRUE);
925      }
926   }
927  }else{
928   if(track1->P()<0.8){
929     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
930     fPidHF->GetPidCombined()->ComputeProbabilities(track1,fPidHF->GetPidResponse(),prob0);
931   }else{
932     AliAODTrack *trackaod1=(AliAODTrack*)(obj->GetDaughter(1));
933      if(trackaod1->P()<0.55){
934       fPidHF->SetTOF(kFALSE);
935       fPidHF->SetTOFdecide(kFALSE);
936      }
937     Int_t isKaon=fPidHF->MakeRawPid(trackaod1,3);
938     if(isKaon>=1) isK1=kTRUE;
939      if(trackaod1->P()<0.55){
940       fPidHF->SetTOF(kTRUE);
941       fPidHF->SetTOFdecide(kTRUE);
942      }
943   }
944  }
945
946  Bool_t ispi0=kFALSE;
947  Bool_t isp0=kFALSE;
948  Bool_t ispi2=kFALSE;
949  Bool_t isp2=kFALSE;
950
951  if(isTOF0){ //proton
952   if(track0->P()<2.2) {
953     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
954     if(obj->Pt()<3. && track0->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
955     fPidHF->GetPidCombined()->ComputeProbabilities(track0,fPidHF->GetPidResponse(),prob0);
956   }else{
957    AliAODTrack *trackaod0=(AliAODTrack*)(obj->GetDaughter(0));
958    if(trackaod0->P()<1.){
959       fPidObjprot->SetTOF(kFALSE);
960       fPidObjprot->SetTOFdecide(kFALSE);
961    }
962    Int_t isProton=fPidObjprot->MakeRawPid(trackaod0,4);
963    if(isProton>=1) isp0=kTRUE;
964    if(trackaod0->P()<1.){
965       fPidObjprot->SetTOF(kTRUE);
966       fPidObjprot->SetTOFdecide(kTRUE);
967    }
968   }
969  }else{
970    if(track0->P()<1.2){
971     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
972     fPidHF->GetPidCombined()->ComputeProbabilities(track0,fPidHF->GetPidResponse(),prob0);
973    }else{
974     AliAODTrack *trackaod0=(AliAODTrack*)(obj->GetDaughter(0));
975     if(trackaod0->P()<1.){
976       fPidObjprot->SetTOF(kFALSE);
977       fPidObjprot->SetTOFdecide(kFALSE);
978     }
979     Int_t isProton=fPidObjprot->MakeRawPid(trackaod0,4);
980     if(isProton>=1) isp0=kTRUE;
981     if(trackaod0->P()<1.){
982       fPidObjprot->SetTOF(kTRUE);
983       fPidObjprot->SetTOFdecide(kTRUE);
984     }
985    }
986  }
987
988  if(isTOF2){ //proton
989   if(track2->P()<2.2) {
990     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC|AliPIDResponse::kDetTOF);
991     if(obj->Pt()<3. && track2->P()<1.) fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
992     fPidHF->GetPidCombined()->ComputeProbabilities(track2,fPidHF->GetPidResponse(),prob2);
993   }else{
994     AliAODTrack *trackaod2=(AliAODTrack*)(obj->GetDaughter(2));
995     if(trackaod2->P()<1.){
996       fPidObjprot->SetTOF(kFALSE);
997       fPidObjprot->SetTOFdecide(kFALSE);
998     }
999    Int_t isProton=fPidObjprot->MakeRawPid(trackaod2,4);
1000    if(isProton>=1) isp2=kTRUE;
1001    if(trackaod2->P()<1.){
1002       fPidObjprot->SetTOF(kTRUE);
1003       fPidObjprot->SetTOFdecide(kTRUE);
1004     }
1005   }
1006  }else{
1007    if(track2->P()<1.2){
1008     fPidHF->GetPidCombined()->SetDetectorMask(AliPIDResponse::kDetTPC);
1009     fPidHF->GetPidCombined()->ComputeProbabilities(track2,fPidHF->GetPidResponse(),prob2);
1010    }else{
1011     AliAODTrack *trackaod2=(AliAODTrack*)(obj->GetDaughter(2));
1012      if(trackaod2->P()<1.){
1013       fPidObjprot->SetTOF(kFALSE);
1014       fPidObjprot->SetTOFdecide(kFALSE);
1015     }
1016     Int_t isProton=fPidObjprot->MakeRawPid(trackaod2,4);
1017     if(isProton>=1) isp2=kTRUE;
1018     if(trackaod2->P()<1.){
1019       fPidObjprot->SetTOF(kTRUE);
1020       fPidObjprot->SetTOFdecide(kTRUE);
1021     }
1022    }
1023  }
1024   AliAODTrack *trackaod2=(AliAODTrack*)(obj->GetDaughter(2));
1025   if(fPidObjpion->MakeRawPid(trackaod2,2)>=1)ispi2=kTRUE;
1026   AliAODTrack *trackaod0=(AliAODTrack*)(obj->GetDaughter(2));
1027   if(fPidObjpion->MakeRawPid(trackaod0,2)>=1)ispi0=kTRUE;
1028
1029   if(TMath::MaxElement(AliPID::kSPECIES,prob1) == prob1[AliPID::kKaon]){
1030
1031     if(TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kPion]) okLcpKpi = 1;
1032     if(TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kPion]) okLcpiKp = 1;
1033     }
1034
1035    if(!isK1 && TMath::MaxElement(AliPID::kSPECIES,prob1) == prob1[AliPID::kKaon]) isK1=kTRUE;
1036     if(!ispi0 && TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kPion]) ispi0=kTRUE;
1037     if(!ispi2 && TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kPion]) ispi2=kTRUE;
1038     if(!isp0 && TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kProton]) isp0=kTRUE;
1039     if(!isp2 && TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kProton]) isp2=kTRUE;
1040     if(isK1 && ispi0 && isp2) okLcpiKp = 1;
1041     if(isK1 && isp0 && ispi2) okLcpKpi = 1;
1042
1043    if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
1044     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
1045     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
1046
1047     return returnvalue;
1048  
1049
1050 }
1051 //----------------------------------------------------------
1052 Int_t AliRDHFCutsLctopKpi::IsSelectedPIDStrong(AliAODRecoDecayHF* obj) {
1053
1054
1055     if(!fUsePID || !obj) return 3;
1056     Int_t okLcpKpi=0,okLcpiKp=0;
1057     Int_t returnvalue=0;
1058     Bool_t isPeriodd=fPidHF->GetOnePad();
1059     Bool_t isMC=fPidHF->GetMC();
1060     Bool_t ispion0=kTRUE,ispion2=kTRUE;
1061     Bool_t isproton0=kFALSE,isproton2=kFALSE;
1062     Bool_t iskaon1=kFALSE;
1063     if(isPeriodd) {
1064      fPidObjprot->SetOnePad(kTRUE);
1065      fPidObjpion->SetOnePad(kTRUE);
1066     }
1067     if(isMC) {
1068      fPidObjprot->SetMC(kTRUE);
1069      fPidObjpion->SetMC(kTRUE);
1070     }
1071
1072     for(Int_t i=0;i<3;i++){
1073      AliAODTrack *track=(AliAODTrack*)obj->GetDaughter(i);
1074      if(!track) return 0;
1075      // identify kaon
1076      if(i==1) {
1077       Int_t isKaon=fPidHF->MakeRawPid(track,3);
1078       if(isKaon>=1) {
1079        iskaon1=kTRUE;
1080       if(fPidHF->MakeRawPid(track,2)>=1) iskaon1=kFALSE;
1081       }
1082       if(!iskaon1) return 0;
1083      
1084      }else{
1085      //pion or proton
1086      
1087      Int_t isProton=fPidObjprot->MakeRawPid(track,4);
1088      if(isProton>=1){
1089       if(fPidHF->MakeRawPid(track,2)>=1) isProton=-1;
1090       if(fPidHF->MakeRawPid(track,3)>=1) isProton=-1;
1091      }
1092
1093      Int_t isPion=fPidObjpion->MakeRawPid(track,2);
1094      if(fPidHF->MakeRawPid(track,3)>=1) isPion=-1;
1095      if(fPidObjprot->MakeRawPid(track,4)>=1) isPion=-1;
1096
1097
1098      if(i==0) {
1099       if(isPion<0) ispion0=kFALSE;
1100       if(isProton>=1) isproton0=kTRUE;
1101
1102      }
1103       if(!ispion0 && !isproton0) return 0;
1104      if(i==2) {
1105       if(isPion<0) ispion2=kFALSE;
1106       if(isProton>=1) isproton2=kTRUE;
1107      }
1108
1109     }
1110    }
1111
1112     if(ispion2 && isproton0 && iskaon1) okLcpKpi=1;
1113     if(ispion0 && isproton2 && iskaon1) okLcpiKp=1;
1114     if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
1115     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
1116     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
1117
1118  return returnvalue;
1119 }
1120 //--------------------
1121 Int_t AliRDHFCutsLctopKpi::IsSelectedCombinedPIDpPb(AliAODRecoDecayHF* obj) {
1122     
1123     if(!fUsePID || !obj) {return 3;}
1124     Int_t okLcpKpi=0,okLcpiKp=0;
1125     Int_t returnvalue=0;
1126    
1127     Bool_t isMC=fPidHF->GetMC();
1128
1129     
1130     if(isMC) {
1131             fPidObjprot->SetMC(kTRUE);
1132             fPidObjpion->SetMC(kTRUE);
1133     }
1134
1135     AliVTrack *track0=dynamic_cast<AliVTrack*>(obj->GetDaughter(0));
1136     AliVTrack *track1=dynamic_cast<AliVTrack*>(obj->GetDaughter(1));
1137     AliVTrack *track2=dynamic_cast<AliVTrack*>(obj->GetDaughter(2));
1138     if (!track0 || !track1 || !track2) return 0;
1139     Double_t prob0[AliPID::kSPECIES];
1140     Double_t prob1[AliPID::kSPECIES];
1141     Double_t prob2[AliPID::kSPECIES];
1142     
1143     fPidHF->GetPidCombined()->ComputeProbabilities(track0,fPidHF->GetPidResponse(),prob0);
1144     fPidHF->GetPidCombined()->ComputeProbabilities(track1,fPidHF->GetPidResponse(),prob1);
1145     fPidHF->GetPidCombined()->ComputeProbabilities(track2,fPidHF->GetPidResponse(),prob2);
1146   
1147
1148     if(fPIDThreshold[AliPID::kPion]>0. && fPIDThreshold[AliPID::kKaon]>0. && fPIDThreshold[AliPID::kProton]>0.){
1149     okLcpiKp=  (prob0[AliPID::kPion  ]>fPIDThreshold[AliPID::kPion  ])
1150              &&(prob1[AliPID::kKaon  ]>fPIDThreshold[AliPID::kKaon  ])
1151              &&(prob2[AliPID::kProton]>fPIDThreshold[AliPID::kProton]);
1152     okLcpKpi=  (prob0[AliPID::kProton]>fPIDThreshold[AliPID::kProton])
1153              &&(prob1[AliPID::kKaon  ]>fPIDThreshold[AliPID::kKaon  ])
1154              &&(prob2[AliPID::kPion  ]>fPIDThreshold[AliPID::kPion  ]);
1155    }else{ 
1156                     //pion or proton
1157                     
1158                     
1159     if(TMath::MaxElement(AliPID::kSPECIES,prob1) == prob1[AliPID::kKaon]){
1160     if(TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kPion]) okLcpKpi = 1;  
1161     if(TMath::MaxElement(AliPID::kSPECIES,prob2) == prob2[AliPID::kProton] && TMath::MaxElement(AliPID::kSPECIES,prob0) == prob0[AliPID::kPion]) okLcpiKp = 1; 
1162             }
1163            }
1164     
1165     if(okLcpKpi) returnvalue=1; //cuts passed as Lc->pKpi
1166     if(okLcpiKp) returnvalue=2; //cuts passed as Lc->piKp
1167     if(okLcpKpi && okLcpiKp) returnvalue=3; //cuts passed as both pKpi and piKp
1168     
1169     return returnvalue;
1170 }
1171 //-----------------------
1172 Int_t AliRDHFCutsLctopKpi::IsSelectedCombinedPIDpPb2(AliAODRecoDecayHF* obj) {
1173
1174   Int_t returnvalue =0;
1175   Double_t thresholdK =0.7;
1176   Double_t thresholdPi =0.3; //!
1177   Double_t thresholdPr =0.7;
1178
1179   AliVTrack *track0=dynamic_cast<AliVTrack*>(obj->GetDaughter(0));
1180   AliVTrack *track1=dynamic_cast<AliVTrack*>(obj->GetDaughter(1));
1181   AliVTrack *track2=dynamic_cast<AliVTrack*>(obj->GetDaughter(2));
1182
1183   if (!track0 || !track1 || !track2) return 0;
1184   Double_t prob0[AliPID::kSPECIES];
1185   Double_t prob1[AliPID::kSPECIES];
1186   Double_t prob2[AliPID::kSPECIES];
1187
1188   fPidHF->GetPidCombined()->ComputeProbabilities(track0,fPidHF->GetPidResponse(),prob0);
1189   fPidHF->GetPidCombined()->ComputeProbabilities(track1,fPidHF->GetPidResponse(),prob1);
1190   fPidHF->GetPidCombined()->ComputeProbabilities(track2,fPidHF->GetPidResponse(),prob2);
1191
1192   if(prob1[AliPID::kKaon]>thresholdK){
1193     if(TMath::MaxElement(AliPID::kSPECIES,prob0)>TMath::MaxElement(AliPID::kSPECIES,prob2)){
1194       if(((prob0[AliPID::kPion  ]>prob0[AliPID::kProton  ])&& prob0[AliPID::kPion]>thresholdPi) && prob2[AliPID::kProton]>thresholdPr) returnvalue=2;//piKp     
1195       else if(((prob0[AliPID::kProton  ]>prob0[AliPID::kPion  ])&& prob0[AliPID::kProton]>thresholdPr) && prob2[AliPID::kPion]>thresholdPi)returnvalue =1;//pKpi
1196     }
1197
1198     else if(TMath::MaxElement(AliPID::kSPECIES,prob0)<TMath::MaxElement(AliPID::kSPECIES,prob2)){
1199       if(((prob2[AliPID::kPion  ]>prob2[AliPID::kProton  ])&& prob2[AliPID::kPion]>thresholdPi) && prob0[AliPID::kProton]>thresholdPr) returnvalue=1; //pKpi    
1200       else if(((prob2[AliPID::kProton  ]>prob2[AliPID::kPion  ])&& prob2[AliPID::kProton]>thresholdPr) && prob0[AliPID::kPion]>thresholdPi)returnvalue =2;      //piKp
1201     }
1202
1203   }
1204   return returnvalue;
1205
1206 }
1207