b40ee39e2608f2aeceb3a5dcf7a9bc0e4b16d150
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliRDHFCutsDstoKKpi.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 Ds->KKpi
21 //
22 // Author: A.Dainese, andrea.dainese@pd.infn.it
23 /////////////////////////////////////////////////////////////
24
25 #include <TDatabasePDG.h>
26 #include <Riostream.h>
27
28 #include "AliRDHFCutsDstoKKpi.h"
29 #include "AliAODRecoDecayHF3Prong.h"
30 #include "AliAODTrack.h"
31 #include "AliESDtrack.h"
32
33 ClassImp(AliRDHFCutsDstoKKpi)
34
35 //--------------------------------------------------------------------------
36 AliRDHFCutsDstoKKpi::AliRDHFCutsDstoKKpi(const char* name) : 
37 AliRDHFCuts(name),
38 fPidOption(0)
39 {
40   //
41   // Default Constructor
42   //
43   Int_t nvars=16;
44   SetNVars(nvars);
45   TString varNames[16]={"inv. mass [GeV]",   
46                         "pTK [GeV/c]",
47                         "pTPi [GeV/c]",
48                         "d0K [cm]",
49                         "d0Pi [cm]",
50                         "dist12 [cm]",
51                         "sigmavert [cm]",
52                         "decLen [cm]",
53                         "ptMax [GeV/c]",
54                         "cosThetaPoint",
55                         "Sum d0^2 (cm^2)",
56                         "dca [cm]",
57                         "inv. mass (Mphi-MKK) [GeV]",
58                         "inv. mass (MKo*-MKpi) [GeV]",
59                         "Abs(CosineKpiPhiRFrame)^3",
60                         "CosPiDsLabFrame"};
61                         
62   Bool_t isUpperCut[16]={kTRUE,
63                          kFALSE,
64                          kFALSE,
65                          kFALSE,
66                          kFALSE,
67                          kFALSE,
68                          kTRUE,
69                          kFALSE,
70                          kFALSE,
71                          kFALSE,
72                          kFALSE,
73                          kTRUE,
74                          kTRUE,
75                          kTRUE,
76                          kFALSE,
77                          kTRUE};
78   SetVarNames(16,varNames,isUpperCut);
79   Bool_t forOpt[16]={kFALSE,
80                     kFALSE,
81                     kFALSE,
82                     kFALSE,
83                     kFALSE,
84                     kFALSE,
85                     kTRUE,
86                     kTRUE,
87                     kTRUE,
88                     kTRUE,
89                     kTRUE,
90                     kFALSE,
91                     kTRUE,
92                     kTRUE,
93                     kFALSE,
94                     kFALSE};
95   SetVarsForOpt(7,forOpt);
96   Float_t limits[2]={0,999999999.};
97   SetPtBins(2,limits);
98   if(fPidHF)delete fPidHF;
99   fPidHF=new AliAODPidHF();
100   Double_t plim[2]={0.6,0.8};
101   Double_t nsigma[5]={2.,1.,2.,3.,0.};
102   
103   fPidHF->SetPLimit(plim);
104   fPidHF->SetAsym(kTRUE);
105   fPidHF->SetSigma(nsigma);
106   fPidHF->SetMatch(1);
107   fPidHF->SetTPC(1);
108   fPidHF->SetTOF(1);
109   fPidHF->SetITS(0);
110   fPidHF->SetTRD(0);
111   fPidHF->SetCompat(kTRUE);
112
113 }
114 //--------------------------------------------------------------------------
115 AliRDHFCutsDstoKKpi::AliRDHFCutsDstoKKpi(const AliRDHFCutsDstoKKpi &source) :
116   AliRDHFCuts(source),
117   fPidOption(source.fPidOption)
118 {
119   //
120   // Copy constructor
121   //
122
123 }
124 //--------------------------------------------------------------------------
125 AliRDHFCutsDstoKKpi &AliRDHFCutsDstoKKpi::operator=(const AliRDHFCutsDstoKKpi &source)
126 {
127   //
128   // assignment operator
129   //
130   if(&source == this) return *this;
131
132   AliRDHFCuts::operator=(source);
133
134   return *this;
135 }
136
137
138 //---------------------------------------------------------------------------
139 void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,Int_t nvars,Int_t *pdgdaughters,AliAODEvent *aod) {
140   // 
141   // Fills in vars the values of the variables 
142   //
143
144   if(nvars!=fnVarsForOpt) {
145     printf("AliRDHFCutsDstoKKpi::GetCutsVarsForOpt: wrong number of variables\n");
146     return;
147   }
148
149   AliAODRecoDecayHF3Prong *dd = (AliAODRecoDecayHF3Prong*)d;
150   
151   //recalculate vertex w/o daughters
152   Bool_t cleanvtx=kFALSE;
153   AliAODVertex *origownvtx=0x0;
154   if(fRemoveDaughtersFromPrimary) {
155     if(dd->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*dd->GetOwnPrimaryVtx());
156     cleanvtx=kTRUE;
157     if(!RecalcOwnPrimaryVtx(dd,aod)) {
158       CleanOwnPrimaryVtx(dd,aod,origownvtx);
159       cleanvtx=kFALSE;
160     }
161   }
162
163   Int_t iter=-1;
164   if(fVarsForOpt[0]){
165     iter++;
166     if(TMath::Abs(pdgdaughters[0])==321){
167       vars[iter]=dd->InvMassDsKKpi();
168     }else{
169       vars[iter]=dd->InvMassDspiKK();
170     }
171   }
172   if(fVarsForOpt[1]){
173     iter++;
174     Float_t minPtDau=99999.;
175     for(Int_t iprong=0;iprong<3;iprong++){
176       if(TMath::Abs(pdgdaughters[iprong])==321 && 
177          dd->PtProng(iprong)<minPtDau) minPtDau=dd->PtProng(iprong);
178     }
179     vars[iter]=minPtDau;
180   }
181   if(fVarsForOpt[2]){
182     iter++;
183     for(Int_t iprong=0;iprong<3;iprong++){
184       if(TMath::Abs(pdgdaughters[iprong])==211) {
185         vars[iter]=dd->PtProng(iprong);
186       }
187     }
188   }
189   if(fVarsForOpt[3]){
190     iter++;
191     Float_t minImpParDau=99999.;
192     for(Int_t iprong=0;iprong<3;iprong++){
193       if(TMath::Abs(pdgdaughters[iprong])==321 &&
194          dd->Getd0Prong(iprong)<minImpParDau) minImpParDau=dd->Getd0Prong(iprong);
195     }
196     vars[iter]=minImpParDau;
197   }
198   if(fVarsForOpt[4]){
199     iter++;
200     for(Int_t iprong=0;iprong<3;iprong++){
201       if(TMath::Abs(pdgdaughters[iprong])==211) {
202         vars[iter]=dd->Getd0Prong(iprong);
203       }
204     }
205   }
206   if(fVarsForOpt[5]){
207     iter++;
208     Float_t minDistPair=TMath::Min(dd->GetDist12toPrim(),dd->GetDist23toPrim());
209     vars[iter]=minDistPair;
210   }
211   if(fVarsForOpt[6]){
212     iter++;
213     vars[iter]=dd->GetSigmaVert();
214   }
215   if(fVarsForOpt[7]){
216     iter++;
217     vars[iter] = dd->DecayLength();
218   }
219   if(fVarsForOpt[8]){
220     iter++;
221     Float_t ptmax=0;
222     for(Int_t i=0;i<3;i++){
223       if(dd->PtProng(i)>ptmax)ptmax=dd->PtProng(i);
224     }
225     vars[iter]=ptmax;
226   }
227   if(fVarsForOpt[9]){
228     iter++;
229     vars[iter]=dd->CosPointingAngle();
230   }
231   if(fVarsForOpt[10]){
232     iter++;
233     vars[iter]=dd->Getd0Prong(0)*dd->Getd0Prong(0)+dd->Getd0Prong(1)*dd->Getd0Prong(1)+dd->Getd0Prong(2)*dd->Getd0Prong(2);
234   }
235   if(fVarsForOpt[11]){
236     iter++;
237     Float_t maxDCA=0.;
238     for(Int_t i=0;i<3;i++){ 
239       if(d->GetDCA(i)>maxDCA) maxDCA=d->GetDCA(i);
240     }
241     vars[iter]=maxDCA;
242   }
243   if(fVarsForOpt[12]){
244     iter++;
245     Double_t mPDGPhi = TDatabasePDG::Instance()->GetParticle(333)->Mass();
246     if(TMath::Abs(pdgdaughters[0])==321){
247       
248       Double_t phimass01=d->InvMass2Prongs(0,1,321,321);
249        vars[iter]=TMath::Abs(phimass01-mPDGPhi);
250        // vars[iter]=dd->InvMass2Prongs(0,1,321,321);
251     }else{
252       Double_t phimass12=d->InvMass2Prongs(1,2,321,321);
253        vars[iter]=TMath::Abs(phimass12-mPDGPhi);
254        // vars[iter]=dd->InvMass2Prongs(1,2,321,321);      
255     }
256   }
257   if(fVarsForOpt[13]){
258     iter++;
259     Double_t mPDGK0star = TDatabasePDG::Instance()->GetParticle(313)->Mass();
260     if(TMath::Abs(pdgdaughters[0])==321){
261       
262       Double_t mass12kpi=d->InvMass2Prongs(1,2,321,211);
263       vars[iter]=TMath::Abs(mass12kpi-mPDGK0star);
264       //              vars[iter]=dd->InvMass2Prongs(1,2,321,211);
265     }else{
266       Double_t mass01pik=d->InvMass2Prongs(0,1,211,321);
267       vars[iter]=TMath::Abs(mass01pik-mPDGK0star);
268       //        vars[iter]=dd->InvMass2Prongs(0,1,211,321);      
269     }
270   }
271   if(fVarsForOpt[14]){
272     iter++;
273     if(TMath::Abs(pdgdaughters[0])==321){
274       vars[iter]=dd->CosPiKPhiRFrameKKpi();
275     }else{
276       vars[iter]=dd->CosPiKPhiRFramepiKK();
277     }
278   }
279   if(fVarsForOpt[15]){
280     iter++;
281     if(TMath::Abs(pdgdaughters[0])==321){
282       vars[iter]=dd->CosPiDsLabFrameKKpi();
283     }else{
284       vars[iter]=dd->CosPiDsLabFramepiKK();
285     }
286   }
287
288   if(cleanvtx)CleanOwnPrimaryVtx(dd,aod,origownvtx); 
289   return;
290 }
291 //---------------------------------------------------------------------------
292 Bool_t AliRDHFCutsDstoKKpi::IsInFiducialAcceptance(Double_t pt, Double_t y) const
293 {
294   //
295   // Checking if Ds is in fiducial acceptance region 
296   //
297
298   if(pt > 5.) {
299     // applying cut for pt > 5 GeV
300     AliDebug(2,Form("pt of Ds = %f (> 5), cutting at |y| < 0.8",pt)); 
301     if (TMath::Abs(y) > 0.8) return kFALSE;
302     
303   } else {
304     // appliying smooth cut for pt < 5 GeV
305     Double_t maxFiducialY = -0.2/15*pt*pt+1.9/15*pt+0.5; 
306     Double_t minFiducialY = 0.2/15*pt*pt-1.9/15*pt-0.5;         
307     AliDebug(2,Form("pt of Ds = %f (< 5), cutting  according to the fiducial zone [%f, %f]\n",pt,minFiducialY,maxFiducialY)); 
308     if (y < minFiducialY || y > maxFiducialY) return kFALSE;    
309   }
310
311   return kTRUE;
312 }
313
314 //---------------------------------------------------------------------------
315 Int_t AliRDHFCutsDstoKKpi::IsSelectedPID(AliAODRecoDecayHF *rd) {
316   // PID selection
317   // return values: 0->NOT OK, 1->OK as KKpi, 2->OK as piKK, 3->OK as both 
318   Int_t retCode=3;
319   Bool_t okKKpi=kTRUE;
320   Bool_t okpiKK=kTRUE;
321   if(!fUsePID || !rd) return retCode;
322   if(!fPidHF){
323     AliWarning("AliAODPidHF not created!");
324     return retCode;
325   }
326
327   Double_t origCompatTOF=fPidHF->GetPCompatTOF();
328   Double_t origThreshTPC=fPidHF->GetPtThresholdTPC();
329   if(fPidOption==kStrong){
330     fPidHF->SetPCompatTOF(999999.);
331     fPidHF->SetPtThresholdTPC(999999.);
332   }
333
334
335   Int_t nKaons=0;
336   Int_t nNotKaons=0;
337   Int_t sign= rd->GetCharge(); 
338   for(Int_t iDaught=0; iDaught<3; iDaught++){
339     AliAODTrack *track=(AliAODTrack*)rd->GetDaughter(iDaught);
340     Int_t isPion=fPidHF->MakeRawPid(track,AliPID::kPion);
341     Int_t isKaon=fPidHF->MakeRawPid(track,AliPID::kKaon);
342     Int_t isProton=fPidHF->MakeRawPid(track,AliPID::kProton);
343     
344     if(isProton>0 &&  isKaon<0  && isPion<0){
345       fPidHF->SetPCompatTOF(origCompatTOF);
346       fPidHF->SetPtThresholdTPC(origThreshTPC);
347       return 0;
348     }
349     if(sign!=track->Charge()){// must be kaon
350       if(isKaon<0){
351         fPidHF->SetPCompatTOF(origCompatTOF);
352         fPidHF->SetPtThresholdTPC(origThreshTPC);
353         return 0;
354       }
355       if(fPidOption==kStrong && isKaon<=0){
356         fPidHF->SetPCompatTOF(origCompatTOF);
357         fPidHF->SetPtThresholdTPC(origThreshTPC);
358         return 0;
359       }
360     }
361     if(isKaon>0 && isPion<0) nKaons++;
362     if(isKaon<0) nNotKaons++;
363     if(iDaught==0){
364       if(isKaon<0) okKKpi=kFALSE;
365       if(isPion<0) okpiKK=kFALSE;      
366       if(fPidOption==kStrong){
367         if(isKaon<=0) okKKpi=kFALSE;
368         if(isPion<=0) okpiKK=kFALSE;
369       }
370     }
371     else if(iDaught==2){
372       if(isKaon<0) okpiKK=kFALSE;
373       if(isPion<0) okKKpi=kFALSE;
374        if(fPidOption==kStrong){
375         if(isKaon<=0) okpiKK=kFALSE;
376         if(isPion<=0) okKKpi=kFALSE;
377       }
378     }
379   }
380
381   fPidHF->SetPCompatTOF(origCompatTOF);
382   fPidHF->SetPtThresholdTPC(origThreshTPC);
383   
384   if(nKaons>2)return 0;
385   if(nNotKaons>1) return 0;
386   
387   if(!okKKpi) retCode-=1;
388   if(!okpiKK) retCode-=2;
389
390   return retCode;
391 }
392
393 //---------------------------------------------------------------------------
394 Int_t AliRDHFCutsDstoKKpi::IsSelected(TObject* obj,Int_t selectionLevel, AliAODEvent* aod) {
395   //
396   // Apply selection
397   //
398
399   if(!fCutsRD){
400     cout<<"Cut matrix not inizialized. Exit..."<<endl;
401     return 0;
402   }
403   //PrintAll();
404   AliAODRecoDecayHF3Prong* d=(AliAODRecoDecayHF3Prong*)obj;
405
406   if(!d){
407     cout<<"AliAODRecoDecayHF3Prong null"<<endl;
408     return 0;
409   }
410   
411   if(fKeepSignalMC) if(IsSignalMC(d,aod,431)) return 3;
412  
413   Double_t ptD=d->Pt();
414   if(ptD<fMinPtCand) return 0;
415   if(ptD>fMaxPtCand) return 0;
416
417   // selection on daughter tracks 
418   if(selectionLevel==AliRDHFCuts::kAll || 
419      selectionLevel==AliRDHFCuts::kTracks) {
420     if(!AreDaughtersSelected(d)) return 0;
421   }
422
423
424
425  
426   // selection on candidate
427   if(selectionLevel==AliRDHFCuts::kAll || 
428      selectionLevel==AliRDHFCuts::kCandidate) {
429     //recalculate vertex w/o daughters
430     AliAODVertex *origownvtx=0x0;
431     if(fRemoveDaughtersFromPrimary) {
432       if(d->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*d->GetOwnPrimaryVtx());
433       if(!RecalcOwnPrimaryVtx(d,aod)) {
434         CleanOwnPrimaryVtx(d,aod,origownvtx);
435         return 0;
436       }
437     }
438
439     Int_t okDsKKpi=1;
440     Int_t okDspiKK=1;
441     Int_t okMassPhiKKpi=0;
442     Int_t okMassPhipiKK=0;
443     Int_t okMassK0starKKpi=0;
444     Int_t okMassK0starpiKK=0;
445     Int_t okDsPhiKKpi=0;
446     Int_t okDsPhipiKK=0;
447     Int_t okDsK0starKKpi=0;
448     Int_t okDsK0starpiKK=0;
449
450     Double_t pt=d->Pt();
451     Int_t ptbin=PtBin(pt);
452     if (ptbin==-1) {
453       CleanOwnPrimaryVtx(d,aod,origownvtx);
454       return 0;
455     }
456  
457     Double_t mDsPDG = TDatabasePDG::Instance()->GetParticle(431)->Mass();
458     Double_t mDsKKpi=d->InvMassDsKKpi();
459     Double_t mDspiKK=d->InvMassDspiKK();
460     if(TMath::Abs(mDsKKpi-mDsPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okDsKKpi = 0;
461     if(TMath::Abs(mDspiKK-mDsPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okDspiKK = 0;
462     if(!okDsKKpi && !okDspiKK){
463       CleanOwnPrimaryVtx(d,aod,origownvtx);
464       return 0;
465     }
466
467
468
469     // cuts on resonant decays (via Phi or K0*)
470     Double_t mPhiPDG = TDatabasePDG::Instance()->GetParticle(333)->Mass();
471     Double_t mK0starPDG = TDatabasePDG::Instance()->GetParticle(313)->Mass();
472     if(okDsKKpi){
473       Double_t mass01phi=d->InvMass2Prongs(0,1,321,321);
474       Double_t mass12K0s=d->InvMass2Prongs(1,2,321,211);
475       if(TMath::Abs(mass01phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhiKKpi=1;
476       if(TMath::Abs(mass12K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0starKKpi = 1;
477       if(!okMassPhiKKpi && !okMassK0starKKpi) okDsKKpi=0;
478       if(okMassPhiKKpi) okDsPhiKKpi=1;
479       if(okMassK0starKKpi) okDsK0starKKpi=1;
480     }
481     if(okDspiKK){
482       Double_t mass01K0s=d->InvMass2Prongs(0,1,211,321);
483       Double_t mass12phi=d->InvMass2Prongs(1,2,321,321);
484       if(TMath::Abs(mass01K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0starpiKK = 1;
485       if(TMath::Abs(mass12phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhipiKK=1;
486       if(!okMassPhipiKK && !okMassK0starpiKK) okDspiKK=0;
487       if(okMassPhipiKK) okDsPhipiKK=1;
488       if(okMassK0starpiKK) okDsK0starpiKK=1;
489     }
490     if(!okDsKKpi && !okDspiKK){
491       CleanOwnPrimaryVtx(d,aod,origownvtx);
492       return 0;
493     }
494
495     // Cuts on track pairs
496     for(Int_t i=0;i<3;i++){
497       if(d->GetDCA(i)>fCutsRD[GetGlobalIndex(11,ptbin)]){
498         CleanOwnPrimaryVtx(d,aod,origownvtx);
499         return 0;
500       }
501     }
502     if(d->GetDist12toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)] || 
503        d->GetDist23toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)]){
504       CleanOwnPrimaryVtx(d,aod,origownvtx);
505       return 0;
506     }
507
508
509
510     //single track
511     if(TMath::Abs(d->Pt2Prong(1)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
512        TMath::Abs(d->Getd0Prong(1))<fCutsRD[GetGlobalIndex(3,ptbin)]){
513       CleanOwnPrimaryVtx(d,aod,origownvtx);
514       return 0;
515     }
516
517     if(okDsKKpi){
518       if(TMath::Abs(d->Pt2Prong(0)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
519          TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDsKKpi=0;
520       if(TMath::Abs(d->Pt2Prong(2)) < fCutsRD[GetGlobalIndex(2,ptbin)]*fCutsRD[GetGlobalIndex(2,ptbin)] || 
521          TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDsKKpi=0;
522     }
523     if(okDspiKK){
524       if(TMath::Abs(d->Pt2Prong(0)) < fCutsRD[GetGlobalIndex(2,ptbin)]*fCutsRD[GetGlobalIndex(2,ptbin)] || 
525          TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDspiKK=0;
526       if(TMath::Abs(d->Pt2Prong(2)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
527          TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDspiKK=0;
528     }
529     if(!okDsKKpi && !okDspiKK){
530       CleanOwnPrimaryVtx(d,aod,origownvtx);
531       return 0;
532     }
533
534     // Cuts on candidate triplet
535
536     if(d->GetSigmaVert()>fCutsRD[GetGlobalIndex(6,ptbin)]){
537       CleanOwnPrimaryVtx(d,aod,origownvtx);
538       return 0;
539     }
540
541     if(d->CosPointingAngle()< fCutsRD[GetGlobalIndex(9,ptbin)]){
542       CleanOwnPrimaryVtx(d,aod,origownvtx); 
543       return 0;
544     }
545      
546     if(d->Pt2Prong(0)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)] && 
547        d->Pt2Prong(1)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)] && 
548        d->Pt2Prong(2)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)]) {
549       CleanOwnPrimaryVtx(d,aod,origownvtx); 
550       return 0;
551     }
552
553     if(d->DecayLength2()<fCutsRD[GetGlobalIndex(7,ptbin)]*fCutsRD[GetGlobalIndex(7,ptbin)]){
554       CleanOwnPrimaryVtx(d,aod,origownvtx);
555       return 0;
556     }
557
558
559     Double_t sum2=d->Getd0Prong(0)*d->Getd0Prong(0)+d->Getd0Prong(1)*d->Getd0Prong(1)+d->Getd0Prong(2)*d->Getd0Prong(2);
560     if(sum2<fCutsRD[GetGlobalIndex(10,ptbin)]){
561       CleanOwnPrimaryVtx(d,aod,origownvtx);
562       return 0;
563     }
564
565      // unset recalculated primary vertex when not needed any more
566     CleanOwnPrimaryVtx(d,aod,origownvtx);
567     
568     if(okDsKKpi){
569       Double_t cosPiKPhiRFKKpi=d->CosPiKPhiRFrameKKpi();
570       Double_t kincutPiKPhiKKpi=TMath::Abs(cosPiKPhiRFKKpi*cosPiKPhiRFKKpi*cosPiKPhiRFKKpi);
571       if(kincutPiKPhiKKpi<fCutsRD[GetGlobalIndex(14,ptbin)]) okDsKKpi=0;
572     }
573     if(okDspiKK){
574       Double_t cosPiKPhiRFpiKK=d->CosPiKPhiRFramepiKK();
575       Double_t kincutPiKPhipiKK=TMath::Abs(cosPiKPhiRFpiKK*cosPiKPhiRFpiKK*cosPiKPhiRFpiKK);
576       if(kincutPiKPhipiKK<fCutsRD[GetGlobalIndex(14,ptbin)]) okDspiKK=0;
577     }
578     if(!okDsKKpi && !okDspiKK){
579       CleanOwnPrimaryVtx(d,aod,origownvtx);
580       return 0;
581     }
582     
583     
584     
585     if(okDsKKpi){
586       Double_t cosPiDsLabFrameKKpi=d->CosPiDsLabFrameKKpi();
587       if(TMath::Abs(cosPiDsLabFrameKKpi)>fCutsRD[GetGlobalIndex(15,ptbin)]) okDsKKpi=0;
588     }
589     if(okDspiKK){
590       Double_t cosPiDsLabFramepiKK=d->CosPiDsLabFramepiKK();
591       if(TMath::Abs(cosPiDsLabFramepiKK)>fCutsRD[GetGlobalIndex(15,ptbin)]) okDspiKK=0;
592     }
593     if(!okDsKKpi && !okDspiKK){
594       CleanOwnPrimaryVtx(d,aod,origownvtx);
595       return 0;
596     }
597     
598     
599     
600
601     if(!okDsKKpi){
602       okDsPhiKKpi=0;
603       okDsK0starKKpi=0;
604     }
605     if(!okDspiKK){
606       okDsPhipiKK=0;
607       okDsK0starpiKK=0;
608     }
609
610     // PID selection
611     Int_t returnvaluePID=3;  
612     if(selectionLevel==AliRDHFCuts::kAll || 
613        selectionLevel==AliRDHFCuts::kCandidate ||     
614        selectionLevel==AliRDHFCuts::kPID) {
615       returnvaluePID = IsSelectedPID(d);
616       fIsSelectedPID=returnvaluePID;
617     }
618     if(returnvaluePID==0)return 0;
619
620     Bool_t okPidDsKKpi=returnvaluePID&1;
621     Bool_t okPidDspiKK=returnvaluePID&2;
622     if(!okPidDsKKpi){
623       okDsPhiKKpi=0;
624       okDsK0starKKpi=0;
625     }
626     if(!okPidDspiKK){
627       okDsPhipiKK=0;
628       okDsK0starpiKK=0;
629     }
630
631     if((okPidDsKKpi && okDsKKpi)||(okPidDspiKK && okDspiKK)){
632       Int_t returnvalue=0;
633       if(okDsKKpi) returnvalue+=1;
634       if(okDspiKK) returnvalue+=2;
635       if(okDsPhiKKpi) returnvalue+=4;
636       if(okDsPhipiKK) returnvalue+=8;
637       if(okDsK0starKKpi) returnvalue+=16;
638       if(okDsK0starpiKK) returnvalue+=32;
639       return returnvalue;
640     }else{
641       return 0;
642     }
643   }
644   return 15;
645
646 }
647 //---------------------------------------------------------------------------