Update for Kink tasks:
[u/mrichter/AliRoot.git] / PWG2 / KINK / AliResonanceKinkLikeSign.cxx
index c6060bc960e2a1c21fb4cdd70dcabc34f0b3c8a4..8d91539357d60b8b0977eac20ab29d8a093dcc21 100644 (file)
 //        Background is calculated from a positive kaon kink and a negative track.
 //-----------------------------------------------------------------------------------------------------------------
 
-#include "TChain.h"
-#include "TTree.h"
-#include "TVector3.h"
-#include "TF1.h"
+#include "AliESDEvent.h"
 #include "TH1D.h"
 #include "TH2D.h"
-#include <TDatabasePDG.h>
-#include <TParticlePDG.h>
+#include "TF1.h"
+#include "TDatabasePDG.h"
 #include "TLorentzVector.h"
-#include "AliAnalysisTaskSE.h"
-#include "AliAnalysisManager.h"
-
-#include "AliESDInputHandler.h"
+#include "AliESDkink.h"
 
 #include "AliResonanceKinkLikeSign.h"
-#include "AliESDkink.h"
 
 ClassImp(AliResonanceKinkLikeSign)
 
-//________________________________________________________________________
-AliResonanceKinkLikeSign::AliResonanceKinkLikeSign() 
-  : AliAnalysisTaskSE(), fESD(0), fListOfHistos(0), f1(0), f2(0), fPosKaonLikeSign(0), fLikeSignInvmassPt(0)
-{
-  // Constructor
-}
-
 //________________________________________________________________________
 AliResonanceKinkLikeSign::AliResonanceKinkLikeSign(const char *name) 
-  : AliAnalysisTaskSE(name), fESD(0), fListOfHistos(0), f1(0), f2(0), fPosKaonLikeSign(0), fLikeSignInvmassPt(0)
+  : AliAnalysisTaskSE(name), fDebug(0), fListOfHistos(0), f1(0), f2(0), fPosKaonLikeSign(0), fLikeSignInvmassPt(0), fMaxNSigmaToVertex(0), fMinPtTrackCut(0), fMaxDCAxy(0), fMaxDCAzaxis(0), 
+fMinTPCclusters(0),fMaxChi2PerTPCcluster(0), fMaxCov0(0), fMaxCov2(0), fMaxCov5(0) , fMaxCov9(0), fMaxCov14(0), fdaughter1pdg(0), fdaughter2pdg(0), fnbins(0), fnlowx(0), fnhighx(0)
 
 {
   // Constructor
 
   // Define input and output slots here
   // Input slot #0 works with a TChain
-  DefineInput(0, TChain::Class());
   DefineOutput(1, TList::Class());
 }
 
 //________________________________________________________________________
-void AliResonanceKinkLikeSign::ConnectInputData(Option_t *option) 
-{
-  // Connect ESD or AOD here
-  // Called once
-  AliAnalysisTaskSE::ConnectInputData(option);
-  TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
-  if (!tree) {
-    Printf("ERROR: Could not read chain from input slot 0");
-  } else {
-  
-    AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
-
-    if (!esdH) {
-      Printf("ERROR: Could not get ESDInputHandler");
-    } else
-      fESD = esdH->GetEvent();
-  }
-}
-
-//________________________________________________________________________
-void AliResonanceKinkLikeSign::CreateOutputObjects() 
+void AliResonanceKinkLikeSign::UserCreateOutputObjects() 
 {
   // Create histograms
   // Called once
@@ -93,16 +59,9 @@ void AliResonanceKinkLikeSign::CreateOutputObjects()
    f2->SetParameter(1,0.2731374);
    f2->SetParameter(2,TMath::Pi());
   
-   //OpenFile(1);  //uncomment for proof analysis 
-   
-    // for K*0(892)
-   fPosKaonLikeSign=new TH1D("fPosKaonLikeSign"," ", 60,0.6,1.2);
-   fLikeSignInvmassPt=new TH2D("fLikeSignInvmassPt"," ", 60,0.6,1.2, 100,0.0,10.0);
-   
-   // for phi(1020)
- //  fPosKaonLikeSign=new TH1D("fPosKaonLikeSign"," ", 70,0.99,1.088);
-    
-
+   fPosKaonLikeSign=new TH1D("fPosKaonLikeSign"," ", fnbins, fnlowx, fnhighx);
+   fLikeSignInvmassPt=new TH2D("fLikeSignInvmassPt"," ", fnbins, fnlowx, fnhighx, 100,0.0,10.0);
    fListOfHistos=new TList();
    fListOfHistos->Add(fPosKaonLikeSign);
    fListOfHistos->Add(fLikeSignInvmassPt);     
@@ -110,22 +69,47 @@ void AliResonanceKinkLikeSign::CreateOutputObjects()
 }
 
 //________________________________________________________________________
-void AliResonanceKinkLikeSign::Exec(Option_t *option
+void AliResonanceKinkLikeSign::UserExec(Option_t *
 {
   // Main loop
   // Called for each event
  
-   Double_t daughter1Mass=TDatabasePDG::Instance()->GetParticle(kKPlus)->Mass();
-   Double_t daughter2Mass=TDatabasePDG::Instance()->GetParticle(kPiPlus)->Mass();
+  AliVEvent *event = InputEvent();
+  if (!event) {
+     Printf("ERROR: Could not retrieve event");
+     return;
+  }
 
-   if (option) Printf("WARNING: an option was initially required");
+  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event);
+  if (!esd) {
+     Printf("ERROR: Could not retrieve esd");
+     return;
+  }
 
-  if (!fESD) {
-    Printf("ERROR: fESD not available");
+  AliMCEvent* mcEvent = MCEvent();
+  if (!mcEvent) {
+     Printf("ERROR: Could not retrieve MC event");
+     return;
+  }
+  
+   Double_t daughter1Mass, daughter2Mass;
+  
+   if (fdaughter1pdg==kKPlus)  {
+     daughter1Mass=TDatabasePDG::Instance()->GetParticle(fdaughter1pdg)->Mass();
+     daughter2Mass=TDatabasePDG::Instance()->GetParticle(fdaughter2pdg)->Mass(); 
+   }
+  
+   if (fdaughter1pdg!=kKPlus)  {
+     daughter1Mass=TDatabasePDG::Instance()->GetParticle(fdaughter2pdg)->Mass();
+     daughter2Mass=TDatabasePDG::Instance()->GetParticle(fdaughter1pdg)->Mass();   
+   }  // to ensure that daughter1Mass has always the kaon mass
+
+  if (!esd) {
+    Printf("ERROR: esd not available");
     return;
   }  
 
-  const AliESDVertex* vertex = GetEventVertex(fESD);
+  const AliESDVertex* vertex = GetEventVertex(esd);
   if(!vertex) return;
   
   Double_t ptrackpos[3], ptrackneg[3];
@@ -134,142 +118,68 @@ void AliResonanceKinkLikeSign::Exec(Option_t *option)
   TLorentzVector p4neg;
   TLorentzVector p4comb; 
 
-  for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
-    AliESDtrack* trackpos = fESD->GetTrack(iTracks);
+  for (Int_t iTracks = 0; iTracks < esd->GetNumberOfTracks(); iTracks++) {
+    
+    AliESDtrack* trackpos = esd->GetTrack(iTracks);
     if (!trackpos) {
       if (fDebug > 0) Printf("ERROR: Could not receive track %d", iTracks);
       continue;
     }
-    
     if (trackpos->GetSign() < 0) continue;
     
-    trackpos->GetPxPyPz(ptrackpos);
+    AliExternalTrackParam *tpcTrackpos = (AliExternalTrackParam *)trackpos->GetTPCInnerParam();
+    if(!tpcTrackpos) continue;
+    ptrackpos[0]=tpcTrackpos->Px();
+    ptrackpos[1]=tpcTrackpos->Py();   
+    ptrackpos[2]=tpcTrackpos->Pz();  
     
-    Float_t nSigmaToVertex = GetSigmaToVertex(trackpos);      
-    
-    Float_t bpos[2];
-    Float_t bCovpos[3];
-    trackpos->GetImpactParameters(bpos,bCovpos);
-    
-    if (bCovpos[0]<=0 || bCovpos[2]<=0) {
-     if (fDebug > 0) Printf("Estimated b resolution lower or equal zero!");
-     bCovpos[0]=0; bCovpos[2]=0;
-    }
-
-    Float_t dcaToVertexXYpos = bpos[0];
-    Float_t dcaToVertexZpos = bpos[1];
-
-    if(nSigmaToVertex>=4) continue;
-    if((dcaToVertexXYpos>3.0)||(dcaToVertexZpos>3.0)) continue;
+    Bool_t firstLevelAcceptPosTrack=IsAcceptedForKink(esd, vertex, trackpos);
+    if(firstLevelAcceptPosTrack==kFALSE) continue;
     
     TVector3 posTrackMom(ptrackpos[0],ptrackpos[1],ptrackpos[2]);
-  
-    if(posTrackMom.Perp()<=0.25) continue; 
-       
-    //Uncomment the following block if the Like Sign is made of K+ kink + positive track
     
-    Int_t indexKink=trackpos->GetKinkIndex(0);
-    Int_t kaonKinkFlag=0;
-    if(indexKink<0){
-               
-        AliESDkink *kink=fESD->GetKink(TMath::Abs(indexKink)-1);
-       const TVector3 motherMfromKink(kink->GetMotherP());
-       const TVector3 daughterMKink(kink->GetDaughterP());
-       Float_t qt=kink->GetQt();
-
-        Double_t maxDecAngKmu=f1->Eval(motherMfromKink.Mag(),0.,0.,0.);
-        Double_t maxDecAngpimu=f2->Eval(motherMfromKink.Mag(),0.,0.,0.);
-
-        Float_t kinkAngle=TMath::RadToDeg()*kink->GetAngle(2);
-        
-       Float_t energyDaughterMu=TMath::Sqrt(daughterMKink.Mag()*daughterMKink.Mag()+0.105658*0.105658);
-        Float_t p1XM= motherMfromKink.Px();
-        Float_t p1YM= motherMfromKink.Py();
-        Float_t p1ZM= motherMfromKink.Pz();
-        Float_t p2XM= daughterMKink.Px();
-        Float_t p2YM= daughterMKink.Py();
-        Float_t p2ZM= daughterMKink.Pz();
-        Float_t p3Daughter=TMath::Sqrt(((p1XM-p2XM)*(p1XM-p2XM))+((p1YM-p2YM)*(p1YM-p2YM))+((p1ZM-p2ZM)*(p1ZM-p2ZM)));
-        Double_t invariantMassKmu= TMath::Sqrt((energyDaughterMu+p3Daughter)*(energyDaughterMu+p3Daughter)-motherMfromKink.Mag()*motherMfromKink.Mag());
-
-        if((kinkAngle>maxDecAngpimu)&&(qt>0.05)&&(qt<0.25)&&((kink->GetR()>110.)&&(kink->GetR()<230.))&&(TMath::Abs(posTrackMom.Eta())<1.1)&&(invariantMassKmu<0.6)) {
-
-          if(posTrackMom.Mag()<=1.1) {
-          kaonKinkFlag=1;
-         }
-         else 
-         if (kinkAngle<maxDecAngKmu) {
-          kaonKinkFlag=1;      
-         }
-       }
+    Int_t indexKinkPos=trackpos->GetKinkIndex(0);
+    Bool_t posKaonKinkFlag=0;
+    if(indexKinkPos<0) posKaonKinkFlag=IsKink(esd, indexKinkPos, posTrackMom);
+    if(posKaonKinkFlag==0) continue; 
+    if(posKaonKinkFlag==1) p4pos.SetVectM(posTrackMom, daughter1Mass);
 
-    }  //End Kink Information   
-    
-    if(kaonKinkFlag==0) continue; 
-    if(kaonKinkFlag==1) p4pos.SetVectM(posTrackMom,daughter1Mass);
-
-      // Comment the following statements till the "for" if the Like Sign of K+ kink + positive track is needed
-
-//       UInt_t status=trackpos->GetStatus();
-//       if((status&AliESDtrack::kTPCrefit)==0) continue;
-//       if(trackpos->GetTPCclusters(0)<50) continue;
-//       if((trackpos->GetTPCchi2()/trackpos->GetTPCclusters(0))>3.5) continue;
-//       Double_t extCovPos[15];
-//       trackpos->GetExternalCovariance(extCovPos);    
-//       if(extCovPos[0]>2) continue;
-//       if(extCovPos[2]>2) continue;    
-//       if(extCovPos[5]>0.5) continue;  
-//       if(extCovPos[9]>0.5) continue;
-//       if(extCovPos[14]>2) continue; 
-// 
-//        p4pos.SetVectM(posTrackMom,daughter1Mass);
-
-      for (Int_t j=0; j<fESD->GetNumberOfTracks(); j++) {
+    for (Int_t j=0; j<esd->GetNumberOfTracks(); j++) {
         if(iTracks==j) continue;
-        AliESDtrack* trackneg=fESD->GetTrack(j);
+        AliESDtrack* trackneg=esd->GetTrack(j);
+        if (!trackneg) {
+          if (fDebug > 0) Printf("ERROR: Could not receive track %d", j);
+          continue;
+        } 
         if (trackneg->GetSign() < 0) continue;
-       
-       trackneg->GetPxPyPz(ptrackneg);
-        Float_t negSigmaToVertex = GetSigmaToVertex(trackneg);
-      
-        Float_t bneg[2];
-        Float_t bCovneg[3];
-        trackneg->GetImpactParameters(bneg,bCovneg);
-        if (bCovneg[0]<=0 || bCovneg[2]<=0) {
-          if (fDebug > 0) Printf("Estimated b resolution lower or equal zero!");
-          bCovneg[0]=0; bCovneg[2]=0;
-        }
-
-        Float_t dcaToVertexXYneg = bneg[0];
-        Float_t dcaToVertexZneg = bneg[1];
-    
-        if(negSigmaToVertex>=4) continue;
-        if((dcaToVertexXYneg>3.0)||(dcaToVertexZneg>3.0)) continue;
 
-        TVector3 negTrackMom(ptrackneg[0],ptrackneg[1],ptrackneg[2]);
-
-        if(negTrackMom.Perp()<=0.25) continue; 
+       AliExternalTrackParam *tpcTrackneg = (AliExternalTrackParam *)trackneg->GetTPCInnerParam();
+        if(!tpcTrackneg) continue;
+        ptrackneg[0]=tpcTrackneg->Px();
+        ptrackneg[1]=tpcTrackneg->Py();   
+        ptrackneg[2]=tpcTrackneg->Pz();  
+    
+        Bool_t firstLevelAcceptNegTrack=IsAcceptedForKink(esd, vertex, trackneg);
+        if(firstLevelAcceptNegTrack==kFALSE) continue; 
        
-       UInt_t statusneg=trackneg->GetStatus();
-
-        if((statusneg&AliESDtrack::kTPCrefit)==0) continue;
-
-        if(trackneg->GetTPCclusters(0)<50) continue;
-        if((trackneg->GetTPCchi2()/trackneg->GetTPCclusters(0))>3.5) continue;
-               Double_t extCovneg[15];
-        trackneg->GetExternalCovariance(extCovneg);
-        if(extCovneg[0]>2) continue;
-        if(extCovneg[2]>2) continue;    
-        if(extCovneg[5]>0.5) continue;  
-        if(extCovneg[9]>0.5) continue;
-        if(extCovneg[14]>2) continue;
+        TVector3 negTrackMom(ptrackneg[0],ptrackneg[1],ptrackneg[2]);
 
-       p4neg.SetVectM(negTrackMom, daughter2Mass);
+       Bool_t secondLevelAcceptNegTrack=IsAcceptedForTrack(esd, vertex, trackneg);
+        if(secondLevelAcceptNegTrack==kFALSE) continue;  
+               
+       p4neg.SetVectM(negTrackMom, daughter2Mass);  
        
        p4comb=p4pos;
        p4comb+=p4neg;
-       fPosKaonLikeSign->Fill(p4comb.M());
-       fLikeSignInvmassPt->Fill(p4comb.M(), p4comb.Vect().Pt());
+       
+       if(p4comb.Vect().Pt()<=0.25) continue;  
+       
+        if((TMath::Abs(p4pos.Vect().Eta())<0.9)&&(TMath::Abs(p4neg.Vect().Eta())<0.9)&&(p4comb.Vect().Eta()<0.9)) {
+       
+         fPosKaonLikeSign->Fill(p4comb.M());
+         fLikeSignInvmassPt->Fill(p4comb.M(), p4comb.Vect().Pt());
+       
+       }
        
       } //inner track loop 
 
@@ -278,6 +188,12 @@ void AliResonanceKinkLikeSign::Exec(Option_t *option)
     PostData(1, fListOfHistos);
 }      
 
+//________________________________________________________________________
+void AliResonanceKinkLikeSign::Terminate(Option_t *) 
+{
+}
+
 //____________________________________________________________________//
 
 Float_t AliResonanceKinkLikeSign::GetSigmaToVertex(AliESDtrack* esdTrack) const {
@@ -326,3 +242,163 @@ const AliESDVertex* AliResonanceKinkLikeSign::GetEventVertex(const AliESDEvent*
   }
 }
 
+//________________________________________________________________________
+
+ Bool_t AliResonanceKinkLikeSign::IsAcceptedForKink(AliESDEvent *localesd,
+            const AliESDVertex *localvertex, AliESDtrack* localtrack) {
+   // Apply the selections for each kink
+
+  Double_t gPt = 0.0, gPx = 0.0, gPy = 0.0, gPz = 0.0;
+  Double_t dca[2] = {0.0,0.0}, cov[3] = {0.0,0.0,0.0};  //The impact parameters and their covariance.
+  Double_t dca3D = 0.0;
+  
+  AliExternalTrackParam *tpcTrack = (AliExternalTrackParam *)localtrack->GetTPCInnerParam();
+  if(!tpcTrack) {
+    gPt = 0.0; gPx = 0.0; gPy = 0.0; gPz = 0.0;
+    dca[0] = -100.; dca[1] = -100.; dca3D = -100.;
+    cov[0] = -100.; cov[1] = -100.; cov[2] = -100.;
+  }
+  else {
+    gPt = tpcTrack->Pt();
+    gPx = tpcTrack->Px();
+    gPy = tpcTrack->Py();
+    gPz = tpcTrack->Pz();
+    tpcTrack->PropagateToDCA(localvertex,
+              localesd->GetMagneticField(),100.,dca,cov);
+  }
+  
+  if(GetSigmaToVertex(localtrack) > fMaxNSigmaToVertex) {
+      if (fDebug > 1) Printf("IsAcceptedKink: Track rejected because it has a %lf sigmas to vertex TPC (max. requested: %lf)",   GetSigmaToVertex(localtrack),fMaxNSigmaToVertex);
+      return kFALSE;
+  }
+  
+  if(TMath::Abs(dca[0]) > fMaxDCAxy) {
+      if (fDebug > 1) Printf("IsAcceptedKink: Track rejected because it has a value of dca(xy) (TPC) of %lf (max. requested: %lf)", TMath::Abs(dca[0]), fMaxDCAxy);
+      return kFALSE;
+  }
+    
+  if(TMath::Abs(dca[1]) > fMaxDCAzaxis) {
+      if (fDebug > 1) Printf("IsAcceptedKink: Track rejected because it has a value of dca(z) of %lf (max. requested: %lf)", TMath::Abs(dca[1]), fMaxDCAzaxis);
+      return kFALSE;
+  }
+  
+  if(gPt <= fMinPtTrackCut) {
+      if (fDebug > 1) Printf("IsAcceptedKink: Track rejected because it has a min value of pt of %lf (min. requested: %lf)", gPt, fMinPtTrackCut);
+      return kFALSE;
+  } 
+  
+  return kTRUE;
+}
+
+//________________________________________________________________________
+Bool_t AliResonanceKinkLikeSign::IsAcceptedForTrack(AliESDEvent *localesd,                                                                                                                                          const AliESDVertex *localvertex, AliESDtrack *localtrack) {
+   // Apply the selections for each track
+
+  Double_t gPt = 0.0, gPx = 0.0, gPy = 0.0, gPz = 0.0;
+  Double_t dca[2] = {0.0,0.0}, cov[3] = {0.0,0.0,0.0};  //The impact parameters and their covariance.
+  Double_t dca3D = 0.0;
+  
+  AliExternalTrackParam *tpcTrack = (AliExternalTrackParam *)localtrack->GetTPCInnerParam();
+  if(!tpcTrack) {
+    gPt = 0.0; gPx = 0.0; gPy = 0.0; gPz = 0.0;
+    dca[0] = -100.; dca[1] = -100.; dca3D = -100.;
+    cov[0] = -100.; cov[1] = -100.; cov[2] = -100.;
+  }
+  else {
+    gPt = tpcTrack->Pt();
+    gPx = tpcTrack->Px();
+    gPy = tpcTrack->Py();
+    gPz = tpcTrack->Pz();
+    tpcTrack->PropagateToDCA(localvertex,
+              localesd->GetMagneticField(),100.,dca,cov);
+  }
+  
+  Int_t fcls[200];
+  Int_t nClustersTPC=localtrack->GetTPCclusters(fcls);
+  Float_t chi2perTPCcluster=-1.0;
+  if(nClustersTPC!=0) chi2perTPCcluster=(localtrack->GetTPCchi2())/Float_t(nClustersTPC);
+  
+  Double_t extCov[15];
+  localtrack->GetExternalCovariance(extCov);
+  
+  if((localtrack->GetStatus() & AliESDtrack::kTPCrefit) == 0) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because of no refited in TPC");
+      return kFALSE;
+  } 
+
+  if(nClustersTPC < fMinTPCclusters) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of nclusters (TPC) of %ld (min. requested: %ld)", nClustersTPC, fMinTPCclusters);
+      return kFALSE;
+  } 
+  
+  if(chi2perTPCcluster > fMaxChi2PerTPCcluster) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of chi2perTPCcluster of %lf (max. requested: %lf)", chi2perTPCcluster, fMaxChi2PerTPCcluster);
+      return kFALSE;
+  } 
+
+  if(extCov[0] > fMaxCov0) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of cov[0] of %lf (max. requested: %lf)", cov[0], fMaxCov0);
+      return kFALSE;
+  }
+  
+  if(extCov[2] > fMaxCov2) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of cov[2] of %lf (max. requested: %lf)", cov[2], fMaxCov2);
+      return kFALSE;
+  }
+    
+  if(extCov[5] > fMaxCov5) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of cov[5] of %lf (max. requested: %lf)", cov[5], fMaxCov5);
+      return kFALSE;
+  }  
+  
+  if(extCov[9] > fMaxCov9) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of cov[9] of %lf (max. requested: %lf)", cov[9], fMaxCov9);
+      return kFALSE;
+  }  
+  
+  if(extCov[14] > fMaxCov14) {
+      if (fDebug > 1) Printf("IsAccepted: Track rejected because it has a value of cov[14] of %lf (max. requested: %lf)", cov[14], fMaxCov14);
+      return kFALSE;
+  } 
+  return kTRUE;
+
+}
+
+//________________________________________________________________________
+Bool_t AliResonanceKinkLikeSign::IsKink(AliESDEvent *localesd, Int_t kinkIndex, TVector3 trackMom) 
+{
+   // Test some kinematical criteria for each kink
+
+        AliESDkink *kink=localesd->GetKink(TMath::Abs(kinkIndex)-1);
+        const TVector3 motherMfromKink(kink->GetMotherP());
+        const TVector3 daughterMKink(kink->GetDaughterP());
+        Float_t qt=kink->GetQt();
+
+        Double_t maxDecAngKmu=f1->Eval(motherMfromKink.Mag(),0.,0.,0.);
+        Double_t maxDecAngpimu=f2->Eval(motherMfromKink.Mag(),0.,0.,0.);
+
+         Float_t kinkAngle=TMath::RadToDeg()*kink->GetAngle(2);
+        
+        Float_t energyDaughterMu=TMath::Sqrt(daughterMKink.Mag()*daughterMKink.Mag()+0.105658*0.105658);
+        Float_t p1XM= motherMfromKink.Px();
+         Float_t p1YM= motherMfromKink.Py();
+         Float_t p1ZM= motherMfromKink.Pz();
+         Float_t p2XM= daughterMKink.Px();
+         Float_t p2YM= daughterMKink.Py();
+         Float_t p2ZM= daughterMKink.Pz();
+         Float_t p3Daughter=TMath::Sqrt(((p1XM-p2XM)*(p1XM-p2XM))+((p1YM-p2YM)*(p1YM-p2YM))+((p1ZM-p2ZM)*(p1ZM-p2ZM)));
+         Double_t invariantMassKmu= TMath::Sqrt((energyDaughterMu+p3Daughter)*(energyDaughterMu+p3Daughter)-motherMfromKink.Mag()*motherMfromKink.Mag());
+
+         if((kinkAngle>maxDecAngpimu)&&(qt>0.05)&&(qt<0.25)&&((kink->GetR()>120.)&&(kink->GetR()<220.))&&(TMath::Abs(trackMom.Eta())<0.9)&&(invariantMassKmu<0.6)) {
+
+           if(trackMom.Mag()<=1.1) {
+               return kTRUE;
+           }
+          else 
+          if (kinkAngle<maxDecAngKmu) {
+               return kTRUE;
+          }
+        }
+        return kFALSE;
+}