]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG3/vertexingHF/AliRDHFCutsDstoKKpi.cxx
memory usage optimised
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliRDHFCutsDstoKKpi.cxx
index e83793e01d0365f9533a99456e2c599e00f39628..f81f052634687dd829bad43ef212aef06e8848e5 100644 (file)
@@ -13,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 /////////////////////////////////////////////////////////////
 //
 // Class for cuts on AOD reconstructed Ds->KKpi
@@ -32,14 +34,15 @@ ClassImp(AliRDHFCutsDstoKKpi)
 
 //--------------------------------------------------------------------------
 AliRDHFCutsDstoKKpi::AliRDHFCutsDstoKKpi(const char* name) : 
-AliRDHFCuts(name)
+AliRDHFCuts(name),
+fPidOption(0)
 {
   //
   // Default Constructor
   //
-  Int_t nvars=14;
+  Int_t nvars=16;
   SetNVars(nvars);
-  TString varNames[14]={"inv. mass [GeV]",   
+  TString varNames[16]={"inv. mass [GeV]",   
                        "pTK [GeV/c]",
                        "pTPi [GeV/c]",
                        "d0K [cm]",
@@ -52,8 +55,11 @@ AliRDHFCuts(name)
                        "Sum d0^2 (cm^2)",
                        "dca [cm]",
                        "inv. mass (Mphi-MKK) [GeV]",
-                       "inv. mass (MKo*-MKpi) [GeV]"};
-  Bool_t isUpperCut[14]={kTRUE,
+                       "inv. mass (MKo*-MKpi) [GeV]",
+                       "Abs(CosineKpiPhiRFrame)^3",
+                       "CosPiDsLabFrame"};
+                       
+  Bool_t isUpperCut[16]={kTRUE,
                         kFALSE,
                         kFALSE,
                         kFALSE,
@@ -66,9 +72,11 @@ AliRDHFCuts(name)
                         kFALSE,
                         kTRUE,
                         kTRUE,
+                        kTRUE,
+                        kFALSE,
                         kTRUE};
-  SetVarNames(14,varNames,isUpperCut);
-  Bool_t forOpt[14]={kFALSE,
+  SetVarNames(16,varNames,isUpperCut);
+  Bool_t forOpt[16]={kFALSE,
                    kFALSE,
                    kFALSE,
                    kFALSE,
@@ -81,7 +89,9 @@ AliRDHFCuts(name)
                    kTRUE,
                    kFALSE,
                    kTRUE,
-                   kTRUE};
+                   kTRUE,
+                   kFALSE,
+                   kFALSE};
   SetVarsForOpt(7,forOpt);
   Float_t limits[2]={0,999999999.};
   SetPtBins(2,limits);
@@ -103,7 +113,8 @@ AliRDHFCuts(name)
 }
 //--------------------------------------------------------------------------
 AliRDHFCutsDstoKKpi::AliRDHFCutsDstoKKpi(const AliRDHFCutsDstoKKpi &source) :
-  AliRDHFCuts(source)
+  AliRDHFCuts(source),
+  fPidOption(source.fPidOption)
 {
   //
   // Copy constructor
@@ -125,7 +136,7 @@ AliRDHFCutsDstoKKpi &AliRDHFCutsDstoKKpi::operator=(const AliRDHFCutsDstoKKpi &s
 
 
 //---------------------------------------------------------------------------
-void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,Int_t nvars,Int_t *pdgdaughters) {
+void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,Int_t nvars,Int_t *pdgdaughters,AliAODEvent *aod) {
   // 
   // Fills in vars the values of the variables 
   //
@@ -136,11 +147,23 @@ void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,In
   }
 
   AliAODRecoDecayHF3Prong *dd = (AliAODRecoDecayHF3Prong*)d;
+  
+  //recalculate vertex w/o daughters
+  Bool_t cleanvtx=kFALSE;
+  AliAODVertex *origownvtx=0x0;
+  if(fRemoveDaughtersFromPrimary) {
+    if(dd->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*dd->GetOwnPrimaryVtx());
+    cleanvtx=kTRUE;
+    if(!RecalcOwnPrimaryVtx(dd,aod)) {
+      CleanOwnPrimaryVtx(dd,aod,origownvtx);
+      cleanvtx=kFALSE;
+    }
+  }
+
   Int_t iter=-1;
   if(fVarsForOpt[0]){
     iter++;
-    if(TMath::Abs(pdgdaughters[0]==321)){
+    if(TMath::Abs(pdgdaughters[0])==321){
       vars[iter]=dd->InvMassDsKKpi();
     }else{
       vars[iter]=dd->InvMassDspiKK();
@@ -220,7 +243,7 @@ void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,In
   if(fVarsForOpt[12]){
     iter++;
     Double_t mPDGPhi = TDatabasePDG::Instance()->GetParticle(333)->Mass();
-    if(TMath::Abs(pdgdaughters[0]==321)){
+    if(TMath::Abs(pdgdaughters[0])==321){
       
       Double_t phimass01=d->InvMass2Prongs(0,1,321,321);
        vars[iter]=TMath::Abs(phimass01-mPDGPhi);
@@ -234,7 +257,7 @@ void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,In
   if(fVarsForOpt[13]){
     iter++;
     Double_t mPDGK0star = TDatabasePDG::Instance()->GetParticle(313)->Mass();
-    if(TMath::Abs(pdgdaughters[0]==321)){
+    if(TMath::Abs(pdgdaughters[0])==321){
       
       Double_t mass12kpi=d->InvMass2Prongs(1,2,321,211);
       vars[iter]=TMath::Abs(mass12kpi-mPDGK0star);
@@ -245,8 +268,24 @@ void AliRDHFCutsDstoKKpi::GetCutVarsForOpt(AliAODRecoDecayHF *d,Float_t *vars,In
       //       vars[iter]=dd->InvMass2Prongs(0,1,211,321);      
     }
   }
+  if(fVarsForOpt[14]){
+    iter++;
+    if(TMath::Abs(pdgdaughters[0])==321){
+      vars[iter]=dd->CosPiKPhiRFrameKKpi();
+    }else{
+      vars[iter]=dd->CosPiKPhiRFramepiKK();
+    }
+  }
+  if(fVarsForOpt[15]){
+    iter++;
+    if(TMath::Abs(pdgdaughters[0])==321){
+      vars[iter]=dd->CosPiDsLabFrameKKpi();
+    }else{
+      vars[iter]=dd->CosPiDsLabFramepiKK();
+    }
+  }
 
-  
+  if(cleanvtx)CleanOwnPrimaryVtx(dd,aod,origownvtx); 
   return;
 }
 //---------------------------------------------------------------------------
@@ -284,6 +323,15 @@ Int_t AliRDHFCutsDstoKKpi::IsSelectedPID(AliAODRecoDecayHF *rd) {
     AliWarning("AliAODPidHF not created!");
     return retCode;
   }
+
+  Double_t origCompatTOF=fPidHF->GetPCompatTOF();
+  Double_t origThreshTPC=fPidHF->GetPtThresholdTPC();
+  if(fPidOption==kStrong){
+    fPidHF->SetPCompatTOF(999999.);
+    fPidHF->SetPtThresholdTPC(999999.);
+  }
+
+
   Int_t nKaons=0;
   Int_t nNotKaons=0;
   Int_t sign= rd->GetCharge(); 
@@ -293,21 +341,45 @@ Int_t AliRDHFCutsDstoKKpi::IsSelectedPID(AliAODRecoDecayHF *rd) {
     Int_t isKaon=fPidHF->MakeRawPid(track,AliPID::kKaon);
     Int_t isProton=fPidHF->MakeRawPid(track,AliPID::kProton);
     
-    if(isProton>0 &&  isKaon<0  && isPion<0) return 0;
+    if(isProton>0 &&  isKaon<0  && isPion<0){
+      fPidHF->SetPCompatTOF(origCompatTOF);
+      fPidHF->SetPtThresholdTPC(origThreshTPC);
+      return 0;
+    }
     if(sign!=track->Charge()){// must be kaon
-      if(isKaon<0) return 0;
+      if(isKaon<0){
+       fPidHF->SetPCompatTOF(origCompatTOF);
+       fPidHF->SetPtThresholdTPC(origThreshTPC);
+       return 0;
+      }
+      if(fPidOption==kStrong && isKaon<=0){
+       fPidHF->SetPCompatTOF(origCompatTOF);
+       fPidHF->SetPtThresholdTPC(origThreshTPC);
+       return 0;
+      }
     }
     if(isKaon>0 && isPion<0) nKaons++;
     if(isKaon<0) nNotKaons++;
     if(iDaught==0){
       if(isKaon<0) okKKpi=kFALSE;
-      if(isPion<0) okpiKK=kFALSE;
+      if(isPion<0) okpiKK=kFALSE;      
+      if(fPidOption==kStrong){
+       if(isKaon<=0) okKKpi=kFALSE;
+       if(isPion<=0) okpiKK=kFALSE;
+      }
     }
     else if(iDaught==2){
       if(isKaon<0) okpiKK=kFALSE;
       if(isPion<0) okKKpi=kFALSE;
+       if(fPidOption==kStrong){
+       if(isKaon<=0) okpiKK=kFALSE;
+       if(isPion<=0) okKKpi=kFALSE;
+      }
     }
   }
+
+  fPidHF->SetPCompatTOF(origCompatTOF);
+  fPidHF->SetPtThresholdTPC(origThreshTPC);
   
   if(nKaons>2)return 0;
   if(nNotKaons>1) return 0;
@@ -325,7 +397,7 @@ Int_t AliRDHFCutsDstoKKpi::IsSelected(TObject* obj,Int_t selectionLevel, AliAODE
   //
 
   if(!fCutsRD){
-    cout<<"Cut matrice not inizialized. Exit..."<<endl;
+    cout<<"Cut matrix not inizialized. Exit..."<<endl;
     return 0;
   }
   //PrintAll();
@@ -335,10 +407,12 @@ Int_t AliRDHFCutsDstoKKpi::IsSelected(TObject* obj,Int_t selectionLevel, AliAODE
     cout<<"AliAODRecoDecayHF3Prong null"<<endl;
     return 0;
   }
+  
+  if(fKeepSignalMC) if(IsSignalMC(d,aod,431)) return 3;
  
-  Double_t pt=d->Pt();
-  if(pt<fMinPtCand) return 0;
-  if(pt>fMaxPtCand) return 0;
+  Double_t ptD=d->Pt();
+  if(ptD<fMinPtCand) return 0;
+  if(ptD>fMaxPtCand) return 0;
 
   // selection on daughter tracks 
   if(selectionLevel==AliRDHFCuts::kAll || 
@@ -348,78 +422,49 @@ Int_t AliRDHFCutsDstoKKpi::IsSelected(TObject* obj,Int_t selectionLevel, AliAODE
 
 
 
-  // PID selection
-  Int_t returnvaluePID=3;  
-  if(selectionLevel==AliRDHFCuts::kAll || 
-     selectionLevel==AliRDHFCuts::kCandidate ||     
-     selectionLevel==AliRDHFCuts::kPID) {
-    returnvaluePID = IsSelectedPID(d);
-  }
-  if(returnvaluePID==0)return 0;
-  Bool_t okPidDsKKpi=returnvaluePID&1;
-  Bool_t okPidDspiKK=returnvaluePID&2;
  
-  Int_t returnvalueCuts=15;
   // selection on candidate
   if(selectionLevel==AliRDHFCuts::kAll || 
      selectionLevel==AliRDHFCuts::kCandidate) {
     //recalculate vertex w/o daughters
     AliAODVertex *origownvtx=0x0;
-    AliAODVertex *recvtx=0x0;
     if(fRemoveDaughtersFromPrimary) {
-      if(!aod) {
-       AliError("Can not remove daughters from vertex without AOD event");
-       return 0;
-      }
       if(d->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*d->GetOwnPrimaryVtx());
-      recvtx=d->RemoveDaughtersFromPrimaryVtx(aod);
-      if(!recvtx){
-       AliDebug(2,"Removal of daughter tracks failed");
-       //recvtx=d->GetPrimaryVtx();
-       if(origownvtx){
-         delete origownvtx;
-         origownvtx=NULL;
-       }
+      if(!RecalcOwnPrimaryVtx(d,aod)) {
+       CleanOwnPrimaryVtx(d,aod,origownvtx);
        return 0;
       }
-      //set recalculed primary vertex
-      d->SetOwnPrimaryVtx(recvtx);
-      delete recvtx; recvtx=NULL;
     }
 
     Int_t okDsKKpi=1;
     Int_t okDspiKK=1;
-    Int_t okMassPhi=0;
-    Int_t okMassK0star=0;
+    Int_t okMassPhiKKpi=0;
+    Int_t okMassPhipiKK=0;
+    Int_t okMassK0starKKpi=0;
+    Int_t okMassK0starpiKK=0;
+    Int_t okDsPhiKKpi=0;
+    Int_t okDsPhipiKK=0;
+    Int_t okDsK0starKKpi=0;
+    Int_t okDsK0starpiKK=0;
 
     Double_t pt=d->Pt();
     Int_t ptbin=PtBin(pt);
-
+    if (ptbin==-1) {
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
     Double_t mDsPDG = TDatabasePDG::Instance()->GetParticle(431)->Mass();
     Double_t mDsKKpi=d->InvMassDsKKpi();
     Double_t mDspiKK=d->InvMassDspiKK();
     if(TMath::Abs(mDsKKpi-mDsPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okDsKKpi = 0;
     if(TMath::Abs(mDspiKK-mDsPDG)>fCutsRD[GetGlobalIndex(0,ptbin)]) okDspiKK = 0;
-    if(!okDsKKpi && !okDspiKK) returnvalueCuts=0;
-    if(okPidDsKKpi && !okDsKKpi)  returnvalueCuts=0;
-    if(okPidDspiKK && !okDspiKK) returnvalueCuts=0;
-
-    //single track
-    if(TMath::Abs(d->PtProng(1)) < fCutsRD[GetGlobalIndex(1,ptbin)] || 
-       TMath::Abs(d->Getd0Prong(1))<fCutsRD[GetGlobalIndex(3,ptbin)]) returnvalueCuts=0;
-    if(okDsKKpi){
-      if(TMath::Abs(d->PtProng(0)) < fCutsRD[GetGlobalIndex(1,ptbin)] || 
-        TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDsKKpi=0;
-      if(TMath::Abs(d->PtProng(2)) < fCutsRD[GetGlobalIndex(2,ptbin)] || 
-        TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDsKKpi=0;
-    }
-    if(okDspiKK){
-      if(TMath::Abs(d->PtProng(0)) < fCutsRD[GetGlobalIndex(2,ptbin)] || 
-        TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDspiKK=0;
-      if(TMath::Abs(d->PtProng(2)) < fCutsRD[GetGlobalIndex(1,ptbin)] || 
-        TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDspiKK=0;
+    if(!okDsKKpi && !okDspiKK){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
     }
-    if(!okDsKKpi && !okDspiKK) returnvalueCuts=0;
+
+
 
     // cuts on resonant decays (via Phi or K0*)
     Double_t mPhiPDG = TDatabasePDG::Instance()->GetParticle(333)->Mass();
@@ -427,55 +472,176 @@ Int_t AliRDHFCutsDstoKKpi::IsSelected(TObject* obj,Int_t selectionLevel, AliAODE
     if(okDsKKpi){
       Double_t mass01phi=d->InvMass2Prongs(0,1,321,321);
       Double_t mass12K0s=d->InvMass2Prongs(1,2,321,211);
-      if(TMath::Abs(mass01phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhi=1;
-      if(TMath::Abs(mass12K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0star = 1;
-      if(!okMassPhi && !okMassK0star) okDsKKpi=0;
+      if(TMath::Abs(mass01phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhiKKpi=1;
+      if(TMath::Abs(mass12K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0starKKpi = 1;
+      if(!okMassPhiKKpi && !okMassK0starKKpi) okDsKKpi=0;
+      if(okMassPhiKKpi) okDsPhiKKpi=1;
+      if(okMassK0starKKpi) okDsK0starKKpi=1;
     }
     if(okDspiKK){
       Double_t mass01K0s=d->InvMass2Prongs(0,1,211,321);
       Double_t mass12phi=d->InvMass2Prongs(1,2,321,321);
-      if(TMath::Abs(mass01K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0star = 1;
-      if(TMath::Abs(mass12phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhi=1;
-      if(!okMassPhi && !okMassK0star) okDspiKK=0;
+      if(TMath::Abs(mass01K0s-mK0starPDG)<fCutsRD[GetGlobalIndex(13,ptbin)]) okMassK0starpiKK = 1;
+      if(TMath::Abs(mass12phi-mPhiPDG)<fCutsRD[GetGlobalIndex(12,ptbin)]) okMassPhipiKK=1;
+      if(!okMassPhipiKK && !okMassK0starpiKK) okDspiKK=0;
+      if(okMassPhipiKK) okDsPhipiKK=1;
+      if(okMassK0starpiKK) okDsK0starpiKK=1;
+    }
+    if(!okDsKKpi && !okDspiKK){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
     }
-    if(!okDsKKpi && !okDspiKK) returnvalueCuts=0;
 
     // Cuts on track pairs
-    for(Int_t i=0;i<3;i++) if(d->GetDCA(i)>fCutsRD[GetGlobalIndex(11,ptbin)])  returnvalueCuts=0;
+    for(Int_t i=0;i<3;i++){
+      if(d->GetDCA(i)>fCutsRD[GetGlobalIndex(11,ptbin)]){
+       CleanOwnPrimaryVtx(d,aod,origownvtx);
+       return 0;
+      }
+    }
     if(d->GetDist12toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)] || 
-       d->GetDist23toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)]) returnvalueCuts=0;
+       d->GetDist23toPrim()<fCutsRD[GetGlobalIndex(5,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
 
 
+
+    //single track
+    if(TMath::Abs(d->Pt2Prong(1)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
+       TMath::Abs(d->Getd0Prong(1))<fCutsRD[GetGlobalIndex(3,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+
+    if(okDsKKpi){
+      if(TMath::Abs(d->Pt2Prong(0)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
+        TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDsKKpi=0;
+      if(TMath::Abs(d->Pt2Prong(2)) < fCutsRD[GetGlobalIndex(2,ptbin)]*fCutsRD[GetGlobalIndex(2,ptbin)] || 
+        TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDsKKpi=0;
+    }
+    if(okDspiKK){
+      if(TMath::Abs(d->Pt2Prong(0)) < fCutsRD[GetGlobalIndex(2,ptbin)]*fCutsRD[GetGlobalIndex(2,ptbin)] || 
+        TMath::Abs(d->Getd0Prong(0))<fCutsRD[GetGlobalIndex(4,ptbin)]) okDspiKK=0;
+      if(TMath::Abs(d->Pt2Prong(2)) < fCutsRD[GetGlobalIndex(1,ptbin)]*fCutsRD[GetGlobalIndex(1,ptbin)] || 
+        TMath::Abs(d->Getd0Prong(2))<fCutsRD[GetGlobalIndex(3,ptbin)]) okDspiKK=0;
+    }
+    if(!okDsKKpi && !okDspiKK){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+
     // Cuts on candidate triplet
-    if(d->GetSigmaVert()>fCutsRD[GetGlobalIndex(6,ptbin)]) returnvalueCuts=0;
-    if(d->DecayLength()<fCutsRD[GetGlobalIndex(7,ptbin)]) returnvalueCuts=0;
-    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)]) returnvalueCuts=0;
-    if(d->CosPointingAngle()< fCutsRD[GetGlobalIndex(9,ptbin)])returnvalueCuts=0;
+
+    if(d->GetSigmaVert()>fCutsRD[GetGlobalIndex(6,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+
+    if(d->CosPointingAngle()< fCutsRD[GetGlobalIndex(9,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx); 
+      return 0;
+    }
+     
+    if(d->Pt2Prong(0)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)] && 
+       d->Pt2Prong(1)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)] && 
+       d->Pt2Prong(2)<fCutsRD[GetGlobalIndex(8,ptbin)]*fCutsRD[GetGlobalIndex(8,ptbin)]) {
+      CleanOwnPrimaryVtx(d,aod,origownvtx); 
+      return 0;
+    }
+
+    if(d->DecayLength2()<fCutsRD[GetGlobalIndex(7,ptbin)]*fCutsRD[GetGlobalIndex(7,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+
+
     Double_t sum2=d->Getd0Prong(0)*d->Getd0Prong(0)+d->Getd0Prong(1)*d->Getd0Prong(1)+d->Getd0Prong(2)*d->Getd0Prong(2);
-    if(sum2<fCutsRD[GetGlobalIndex(10,ptbin)])returnvalueCuts=0;
+    if(sum2<fCutsRD[GetGlobalIndex(10,ptbin)]){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
 
+   
+    if(okDsKKpi){
+      Double_t cosPiKPhiRFKKpi=d->CosPiKPhiRFrameKKpi();
+      Double_t kincutPiKPhiKKpi=TMath::Abs(cosPiKPhiRFKKpi*cosPiKPhiRFKKpi*cosPiKPhiRFKKpi);
+      if(kincutPiKPhiKKpi<fCutsRD[GetGlobalIndex(14,ptbin)]) okDsKKpi=0;
+    }
+    if(okDspiKK){
+      Double_t cosPiKPhiRFpiKK=d->CosPiKPhiRFramepiKK();
+      Double_t kincutPiKPhipiKK=TMath::Abs(cosPiKPhiRFpiKK*cosPiKPhiRFpiKK*cosPiKPhiRFpiKK);
+      if(kincutPiKPhipiKK<fCutsRD[GetGlobalIndex(14,ptbin)]) okDspiKK=0;
+    }
+    if(!okDsKKpi && !okDspiKK){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+    
+    
+    
+    if(okDsKKpi){
+      Double_t cosPiDsLabFrameKKpi=d->CosPiDsLabFrameKKpi();
+      if(TMath::Abs(cosPiDsLabFrameKKpi)>fCutsRD[GetGlobalIndex(15,ptbin)]) okDsKKpi=0;
+    }
+    if(okDspiKK){
+      Double_t cosPiDsLabFramepiKK=d->CosPiDsLabFramepiKK();
+      if(TMath::Abs(cosPiDsLabFramepiKK)>fCutsRD[GetGlobalIndex(15,ptbin)]) okDspiKK=0;
+    }
+    if(!okDsKKpi && !okDspiKK){
+      CleanOwnPrimaryVtx(d,aod,origownvtx);
+      return 0;
+    }
+    
      // unset recalculated primary vertex when not needed any more
-    if(origownvtx) {
-      d->SetOwnPrimaryVtx(origownvtx);
-      delete origownvtx;
-      origownvtx=NULL;
-    } else if(fRemoveDaughtersFromPrimary) {
-      d->UnsetOwnPrimaryVtx();
-      AliDebug(3,"delete new vertex\n");
+    CleanOwnPrimaryVtx(d,aod,origownvtx);
+      
+    
+
+    if(!okDsKKpi){
+      okDsPhiKKpi=0;
+      okDsK0starKKpi=0;
+    }
+    if(!okDspiKK){
+      okDsPhipiKK=0;
+      okDsK0starpiKK=0;
+    }
+
+    // PID selection
+    Int_t returnvaluePID=3;  
+    if(selectionLevel==AliRDHFCuts::kAll || 
+       selectionLevel==AliRDHFCuts::kCandidate ||     
+       selectionLevel==AliRDHFCuts::kPID) {
+      returnvaluePID = IsSelectedPID(d);
+      fIsSelectedPID=returnvaluePID;
+    }
+    if(returnvaluePID==0)return 0;
+
+    Bool_t okPidDsKKpi=returnvaluePID&1;
+    Bool_t okPidDspiKK=returnvaluePID&2;
+    if(!okPidDsKKpi){
+      okDsPhiKKpi=0;
+      okDsK0starKKpi=0;
+    }
+    if(!okPidDspiKK){
+      okDsPhipiKK=0;
+      okDsK0starpiKK=0;
+    }
+
+    if((okPidDsKKpi && okDsKKpi)||(okPidDspiKK && okDspiKK)){
+      Int_t returnvalue=0;
+      if(okDsKKpi) returnvalue+=1;
+      if(okDspiKK) returnvalue+=2;
+      if(okDsPhiKKpi) returnvalue+=4;
+      if(okDsPhipiKK) returnvalue+=8;
+      if(okDsK0starKKpi) returnvalue+=16;
+      if(okDsK0starpiKK) returnvalue+=32;
+      return returnvalue;
+    }else{
+      return 0;
     }
-   
-    if(returnvalueCuts == 0) return 0;
-    Int_t returnvalue=0;
-    if(okDsKKpi) returnvalue+=1;
-    if(okDspiKK) returnvalue+=2;
-    if(okMassPhi) returnvalue+=4;
-    if(okMassK0star) returnvalue+=8;
-
-    return returnvalue;
   }
-  return returnvalueCuts;
+  return 15;
 
 }
 //---------------------------------------------------------------------------