From 3faf9678cf0fee2469c992b7939de3aa0c1e445c Mon Sep 17 00:00:00 2001
From: "vitalii.lisovskyi@cern.ch" <vitalii.lisovskyi@cern.ch>
Date: Fri, 18 Jun 2021 16:53:22 +0200
Subject: [PATCH 1/2] some extra multilepton magic

---
 .../StrippingRD/StrippingMultiLepton.py       | 311 +++++++++++++++++-
 1 file changed, 308 insertions(+), 3 deletions(-)

diff --git a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
index b24064e55..f51de64b9 100644
--- a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
@@ -61,8 +61,13 @@ default_config = {
         , 'Bu2mmLinePrescale'    : 1
         },
     'WGs'     : [ 'RD' ],
-    'STREAMS'     : { 'Leptonic' : ['StrippingMultiLepton_B24muXLine','StrippingMultiLepton_B24muXUpLine','StrippingMultiLepton_Jpsi22Mu2EPromptLine','StrippingMultiLepton_Jpsi23MuEDetachedLine','StrippingMultiLepton_Jpsi23MuEPromptLine','StrippingMultiLepton_Jpsi2Mu3EDetachedLine','StrippingMultiLepton_Jpsi2Mu3EPromptLine','StrippingMultiLepton_InclDet4muLowMassLine','StrippingMultiLepton_InclDet4muLowMassUpLine','StrippingMultiLepton_Jpsi24MuPromptLine'],
-                      'Dimuon' : ['StrippingMultiLepton_B24muXTightLine','StrippingMultiLepton_B22mu2eXTightLine','StrippingMultiLepton_InclDet4muLine','StrippingMultiLepton_InclDet2mu2muLine','StrippingMultiLepton_InclDet6muLine','StrippingMultiLepton_InclDet5muLine','StrippingMultiLepton_InclPrompt6muLine','StrippingMultiLepton_Incl8muLine','StrippingMultiLepton_Incl8mu4bodyLine','StrippingMultiLepton_InclDet6mu3bodyLine','StrippingMultiLepton_Jpsi24MuPromptTightLine','StrippingMultiLepton_Jpsi22Mu2EDetachedLine','StrippingMultiLepton_Jpsi22E2EDetachedLine','StrippingMultiLepton_Jpsi22Mu2ESSDetachedLine']}
+    'STREAMS'     : { 'Leptonic' :
+                       [
+                      'StrippingMultiLepton_B24muXLine','StrippingMultiLepton_B24muXUpLine','StrippingMultiLepton_Jpsi22Mu2EPromptLine','StrippingMultiLepton_Jpsi23MuEDetachedLine','StrippingMultiLepton_Jpsi23MuEPromptLine','StrippingMultiLepton_Jpsi2Mu3EDetachedLine','StrippingMultiLepton_Jpsi2Mu3EPromptLine','StrippingMultiLepton_InclDet4muLowMassLine','StrippingMultiLepton_InclDet4muLowMassUpLine','StrippingMultiLepton_Jpsi24MuPromptLine',
+                      'StrippingMultiLepton_B24muXLongLivedLine','StrippingMultiLepton_B26muXLongLivedLine'],
+                       'Dimuon' : ['StrippingMultiLepton_B24muXTightLine','StrippingMultiLepton_B22mu2eXTightLine','StrippingMultiLepton_InclDet4muLine','StrippingMultiLepton_InclDet2mu2muLine','StrippingMultiLepton_InclDet6muLine','StrippingMultiLepton_InclDet5muLine','StrippingMultiLepton_InclPrompt6muLine','StrippingMultiLepton_Incl8muLine','StrippingMultiLepton_Incl8mu4bodyLine','StrippingMultiLepton_InclDet6mu3bodyLine','StrippingMultiLepton_Jpsi24MuPromptTightLine','StrippingMultiLepton_Jpsi22Mu2EDetachedLine','StrippingMultiLepton_Jpsi22E2EDetachedLine','StrippingMultiLepton_Jpsi22Mu2ESSDetachedLine',
+                       'StrippingMultiLepton_Incl8mu4bodyLongLivedLine','StrippingMultiLepton_InclDet6mu3bodyLongLivedLine']
+                      }
     }
 
 
@@ -114,6 +119,8 @@ class MultiLeptonConf(LineBuilder) :
 
         self._name = name
         fourmXLine_name   = name+'_B24muX'
+        fourmX_longlived_Line_name   = name+'_B24muXLongLived'
+        sixmX_longlived_Line_name   = name+'_B26muXLongLived'
         fourmXUpLine_name   = name+'_B24muXUp'
         fourmXLineTight_name   = name+'_B24muXTight'
         twomutwoeXLineTight_name  = name+'_B22mu2eXTight'
@@ -123,9 +130,11 @@ class MultiLeptonConf(LineBuilder) :
         Incl2m2mLine_name = name+'_InclDet2mu2mu'
         Incl6mLine_name = name+'_InclDet6mu'
         Incl6m3xLine_name = name+'_InclDet6mu3body'
+        Incl6m_longlived_Line_name = name+'_InclDet6mu3bodyLongLived'
         InclPrompt6mLine_name = name+'_InclPrompt6mu'
         Incl8mLine_name = name+'_Incl8mu'
         Incl8m4xLine_name = name+'_Incl8mu4body'
+        Incl8m4x_longlived_Line_name = name+'_Incl8mu4bodyLongLived'
         Incl5mLine_name = name+'_InclDet5mu'
         Jpsi24MuPromptLine_name   = name+'_Jpsi24MuPrompt'
         Jpsi24MuPromptTightLine_name   = name+'_Jpsi24MuPromptTight'
@@ -198,6 +207,9 @@ class MultiLeptonConf(LineBuilder) :
         SelDiMuonPrompt = self._makeDiMuonPrompt( name   = "2muPromptFor" + self._name,
                                params = config )
 
+        SelDiMuonLongLived = self._makeDiMuonLongLived( name   = "2muLongLivedFor" + self._name,
+                               params = config )
+
         SelFourMuonDetached = self._makeFourMuonDetached( name   = "4muDetFor" + self._name,
                                #dimuons=SelDiMuonDetached,
                                params = config )
@@ -227,6 +239,18 @@ class MultiLeptonConf(LineBuilder) :
                                    params   = config,
                                    masscut  = "ADAMASS('B+') <  %(BMassWindow)s *MeV"% config)
 
+        SelB24mX_LongLived = self._makeB24muX_LongLived(fourmX_longlived_Line_name,
+                                   dilepton = SelDiMuonLongLived,
+                                   hadrons  = [ SelKaons, SelPhis, SelKstars, SelLstars, SelLambdasDD, SelLambdasLL ],
+                                   params   = config,
+                                   masscut  = "ADAMASS('B+') <  %(BMassWindow)s *MeV"% config)
+
+        SelB26mX_LongLived = self._makeB26muX_LongLived(sixmX_longlived_Line_name,
+                                   dilepton = SelDiMuonLongLived,
+                                   hadrons  = [ SelKaons, SelPhis, SelKstars, SelLstars, SelLambdasDD, SelLambdasLL ],
+                                   params   = config,
+                                   masscut  = "ADAMASS('B+') <  %(BMassWindow)s *MeV"% config)
+
         SelB24mXUp = self._makeB24muX(fourmXUpLine_name,
                                    fourlepton = SelFourMuonDetachedUp,
                                    hadrons  = [ SelKaons, SelPhis, SelKstars, SelLstars, SelKshortsLL, SelKshortsDD, SelLambdasDD, SelLambdasLL ],
@@ -264,6 +288,10 @@ class MultiLeptonConf(LineBuilder) :
 #                                   dilepton = SelDiMuonDetached,
                                    params   = config)
 
+        SelSixMuonLongLivedIncl = self._make6mu3bodyInclLongLived(Incl6m_longlived_Line_name,
+                                   dilepton = SelDiMuonLongLived,
+                                   params   = config)
+
         SelSixMuon3xDetachedIncl = self._make6mu3bodyInclDet(Incl6m3xLine_name,
                                    dilepton = SelDiMuonDetached,
                                    params   = config)
@@ -276,10 +304,14 @@ class MultiLeptonConf(LineBuilder) :
 #                                   dilepton = SelDiMuonDetached,
                                    params   = config)
 
-        SelOttoMuon4xPromptIncl = self. _make8mu4bodyIncl(Incl8m4xLine_name,
+        SelOttoMuon4xPromptIncl = self._make8mu4bodyIncl(Incl8m4xLine_name,
 #                                   dilepton = SelDiMuonPrompt,
                                    params   = config)
 
+        SelOttoMuon4xLongLivedIncl = self._make8mu4bodyLongLived(Incl8m4x_longlived_Line_name,
+                                   dilepton = SelDiMuonLongLived,
+                                   params   = config)
+
         SelFiveMuonDetachedIncl = self._make5Mu(Incl5mLine_name,
                                    params   = config)
 
@@ -353,6 +385,46 @@ class MultiLeptonConf(LineBuilder) :
                                        ],
                                        MDSTFlag          = False )
 
+        self.B24mXLine_LongLived = StrippingLine(fourmX_longlived_Line_name + "Line",
+                                       prescale          = config['Bu2mmLinePrescale'],
+                                       postscale         = 1,
+                                       selection         = SelB24mX_LongLived,
+                                       FILTER            = SPDFilter,
+                                       RequiredRawEvents=["Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker"],
+                                       RelatedInfoTools = [
+                                         { "Type" : "RelInfoMuonIDPlus",
+                                         "Variables" : ["MU_BDT"],
+                                         "DaughterLocations"  : {
+                                         "[ Beauty -> (X -> ^mu+ mu-) (X -> mu+ mu-) X ]CC" : "Muon1BDT",
+                                         "[ Beauty -> (X -> mu+ ^mu-) (X -> mu+ mu-) X ]CC" : "Muon2BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> ^mu+ mu-) X ]CC" : "Muon3BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> mu+ ^mu-) X ]CC" : "Muon4BDT",
+                                         }
+                                         },
+                                       ],
+                                       MDSTFlag          = False )
+
+        self.B26mXLine_LongLived = StrippingLine(sixmX_longlived_Line_name + "Line",
+                                       prescale          = config['Bu2mmLinePrescale'],
+                                       postscale         = 1,
+                                       selection         = SelB26mX_LongLived,
+                                       FILTER            = SPDFilter,
+                                       RequiredRawEvents=["Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker"],
+                                       RelatedInfoTools = [
+                                         { "Type" : "RelInfoMuonIDPlus",
+                                         "Variables" : ["MU_BDT"],
+                                         "DaughterLocations"  : {
+                                         "[ Beauty -> (X -> ^mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-) X ]CC" : "Muon1BDT",
+                                         "[ Beauty -> (X -> mu+ ^mu-) (X -> mu+ mu-) (X -> mu+ mu-) X ]CC" : "Muon2BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> ^mu+ mu-) (X -> mu+ mu-) X ]CC" : "Muon3BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> mu+ ^mu-) (X -> mu+ mu-) X ]CC" : "Muon4BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> ^mu+ mu-) X ]CC" : "Muon5BDT",
+                                         "[ Beauty -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ ^mu-) X ]CC" : "Muon6BDT",
+                                         }
+                                         },
+                                       ],
+                                       MDSTFlag          = False )
+
         self.B24mXUpLine = StrippingLine(fourmXUpLine_name + "Line",
                                        prescale          = config['Bu2mmLinePrescale'],
                                        postscale         = 1,
@@ -526,6 +598,50 @@ class MultiLeptonConf(LineBuilder) :
                                        #RequiredRawEvents=["Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker"],
                                        MDSTFlag          = False )
 
+        self.B26m3xInclLongLivedLine = StrippingLine(Incl6m_longlived_Line_name + "Line",
+                                       prescale          = config['Bu2mmLinePrescale'],
+                                       postscale         = 1,
+                                       selection         = SelSixMuonLongLivedIncl,
+                                       FILTER            = SPDFilter,
+                                       RelatedInfoTools = [
+                                         { "Type" : "RelInfoMuonIDPlus",
+                                         "Variables" : ["MU_BDT"],
+                                         "DaughterLocations"  : {
+                                         " X -> (X -> ^mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon1BDT",
+                                         " X -> (X -> mu+ ^mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon2BDT",
+                                         " X -> (X -> mu+ mu-) (X -> ^mu+ mu-) (X -> mu+ mu-)" : "Muon3BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ ^mu-) (X -> mu+ mu-)" : "Muon4BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> ^mu+ mu-)" : "Muon5BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ ^mu-)" : "Muon6BDT",
+                                         }
+                                         },
+                                       ],
+                                       #RequiredRawEvents=["Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker"],
+                                       MDSTFlag          = False )
+
+        self.B28m4xInclLongLivedLine = StrippingLine(Incl8m4x_longlived_Line_name + "Line",
+                                       prescale          = config['Bu2mmLinePrescale'],
+                                       postscale         = 1,
+                                       selection         = SelOttoMuon4xLongLivedIncl,
+                                       FILTER            = SPDFilter,
+                                       RelatedInfoTools = [
+                                         { "Type" : "RelInfoMuonIDPlus",
+                                         "Variables" : ["MU_BDT"],
+                                         "DaughterLocations"  : {
+                                         " X -> (X -> ^mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon1BDT",
+                                         " X -> (X -> mu+ ^mu-) (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon2BDT",
+                                         " X -> (X -> mu+ mu-) (X -> ^mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon3BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ ^mu-) (X -> mu+ mu-) (X -> mu+ mu-)" : "Muon4BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> ^mu+ mu-) (X -> mu+ mu-)" : "Muon5BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ ^mu-) (X -> mu+ mu-)" : "Muon6BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-) (X -> ^mu+ mu-)" : "Muon7BDT",
+                                         " X -> (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ mu-) (X -> mu+ ^mu-)" : "Muon8BDT",
+                                         }
+                                         },
+                                       ],
+                                       #RequiredRawEvents=["Trigger", "Muon", "Calo", "Rich", "Velo", "Tracker"],
+                                       MDSTFlag          = False )
+
         self.B25mInclLine = StrippingLine(Incl5mLine_name + "Line",
                                        prescale          = config['Bu2mmLinePrescale'],
                                        postscale         = 1,
@@ -806,6 +922,14 @@ class MultiLeptonConf(LineBuilder) :
         self.registerLine( self.Jpsi23MuEPromptLine )
         self.registerLine( self.Jpsi2Mu3EDetachedLine )
         self.registerLine( self.Jpsi2Mu3EPromptLine )
+
+#added for the 2018 restripping
+
+        self.registerLine( self.B24mXLine_LongLived )
+        self.registerLine( self.B26mXLine_LongLived )
+        self.registerLine( self.B26m3xInclLongLivedLine )
+        self.registerLine( self.B28m4xInclLongLivedLine )
+
 #####################################################
     def _filterKaon( self, name, sel, params ):
         """
@@ -1008,6 +1132,58 @@ class MultiLeptonConf(LineBuilder) :
         _stdLooseMuons = DataOnDemand(Location = "Phys/StdAllLooseMuons/Particles")
 
         return Selection( name, Algorithm = _Combine, RequiredSelections = [ _stdLooseMuons ] )
+# added for the 2018 restripping: dileptons from the KS intermediate particle, to allow for lifetime in the vertex fit
+#####################################################
+    # def _makeDiElectronLongLived( self, name, params ) :
+    #     """
+    #     Make a dielectron
+    #     KS0 is just a proxy to get the two-body combination
+    #     """
+    #
+    #     from Configurables import DiElectronMaker, ProtoParticleCALOFilter
+    #
+    #     dieLL = DiElectronMaker('MyDiElectronFromTracks')
+    #     dieLL.Particle = "KS0"
+    #     selector = trackSelector ( dieLL , trackTypes = ["Long"] )
+    #     dieLL.addTool( ProtoParticleCALOFilter, name='Electron' )
+    #     dieLL.Electron.Selection = ["RequiresDet='CALO' CombDLL(e-pi)>'-1.0'"]
+    #     dieLL.DiElectronMassMax = 500000.*MeV
+    #     dieLL.DiElectronMassMin = 0.*MeV
+    #     dieLL.DiElectronPtMin = 200.*MeV
+    #
+    #
+    #     return Selection( name, Algorithm = dieLL )
+
+#####################################################
+    def _makeDiMuonLongLived( self, name, params ) :
+        """
+        Make a dimuon
+        KS0 is just a proxy to get the two-body combination
+        """
+
+        _Decays = "KS0 -> mu+ mu-"
+
+         # define all the cuts
+        _CombCuts    = "(AM > 0*MeV) & (ADOCA(1,2)<%(DiHadronADOCA)s*mm)" % params
+
+        _MotherCuts  = "(VFASPF(VCHI2PDOF) < 9) & (BPVVDCHI2>16)"
+
+        _daughtersCutsmu = "(TRCHI2DOF < %(Trk_Chi2)s) & (TRGHOSTPROB < %(Trk_GhostProb)s)" % params# & (ISMUON) & (PROBNNmu>0.1) " % params
+
+        _Combine = CombineParticles()
+
+        _Combine.DecayDescriptor = _Decays
+
+        _Combine.DaughtersCuts = {
+            "mu+"  : _daughtersCutsmu }
+
+        _Combine.CombinationCut   = _CombCuts
+        _Combine.MotherCut        = _MotherCuts
+
+        _stdLooseMuons = DataOnDemand(Location = "Phys/StdAllLooseMuons/Particles")
+
+        return Selection( name, Algorithm = _Combine, RequiredSelections = [ _stdLooseMuons ] )
+
 #####################################################
     def _makeFourMuonDetached( self, name, params ) :
         """
@@ -1257,6 +1433,69 @@ class MultiLeptonConf(LineBuilder) :
         _Merge = MergedSelection( "Merge" + name, RequiredSelections = hadrons )
 
         return Selection(name, Algorithm = _Combine, RequiredSelections = [ fourlepton, _Merge ] )
+
+#####################################################
+    def _makeB24muX_LongLived( self, name, dilepton, hadrons, params, masscut ):
+        """
+        CombineParticles / Selection for the B
+        """
+
+        _Decays = [
+                    "[ B+ -> KS0 KS0 K+ ]cc",
+                    "B_s0 -> KS0 KS0 phi(1020)",
+                    #" B0 -> J/psi(1S) KS0 ",
+                    "[ B0 -> KS0 KS0 K*(892)0 ]cc",
+                    "[Lambda_b0 -> KS0 KS0 Lambda(1520)0]cc ",
+                    "[Lambda_b0 -> KS0 KS0 Lambda0]cc ",
+                  ]
+
+        _Cut = "((VFASPF(VCHI2/VDOF) < %(BVertexCHI2)s) "\
+               "& (BPVIPCHI2() < %(BIPCHI2)s) "\
+               "& (BPVDIRA > %(BDIRA)s) "\
+               "& (BPVVDCHI2 > %(BFlightCHI2)s))" % params
+
+        _Combine = CombineParticles( DecayDescriptors = _Decays,
+                                     CombinationCut   = masscut,
+                                     MotherCut        = _Cut )
+
+        _Combine.DaughtersCuts = {
+            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.2)) )>0.5)" }
+
+        _Merge = MergedSelection( "Merge" + name, RequiredSelections = hadrons )
+
+        return Selection(name, Algorithm = _Combine, RequiredSelections = [ dilepton, _Merge ] )
+
+#####################################################
+    def _makeB26muX_LongLived( self, name, dilepton, hadrons, params, masscut ):
+        """
+        CombineParticles / Selection for the B
+        """
+
+        _Decays = [
+                    "[ B+ -> KS0 KS0 KS0 K+ ]cc",
+                    "B_s0 -> KS0 KS0 KS0 phi(1020)",
+                    #" B0 -> J/psi(1S) KS0 ",
+                    "[ B0 -> KS0 KS0 KS0 K*(892)0 ]cc",
+                    "[Lambda_b0 -> KS0 KS0 KS0 Lambda(1520)0]cc ",
+                    "[Lambda_b0 -> KS0 KS0 KS0 Lambda0]cc ",
+                  ]
+
+        _Cut = "((VFASPF(VCHI2/VDOF) < %(BVertexCHI2)s) "\
+               "& (BPVIPCHI2() < %(BIPCHI2)s) "\
+               "& (BPVDIRA > %(BDIRA)s) "\
+               "& (BPVVDCHI2 > %(BFlightCHI2)s))" % params
+
+        _Combine = CombineParticles( DecayDescriptors = _Decays,
+                                     CombinationCut   = masscut,
+                                     MotherCut        = _Cut )
+
+        _Combine.DaughtersCuts = {
+            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.05)) )>0.5)" }
+
+        _Merge = MergedSelection( "Merge" + name, RequiredSelections = hadrons )
+
+        return Selection(name, Algorithm = _Combine, RequiredSelections = [ dilepton, _Merge ] )
+
 #####################################################
     def _makeB22mu2EXTight( self, name, fourlepton, hadrons, params, masscut ):
         """
@@ -1585,6 +1824,37 @@ class MultiLeptonConf(LineBuilder) :
 
         return Selection( name, Algorithm = _Combine, RequiredSelections = [ dilepton ] )
 
+#####################################################
+    def _make6mu3bodyInclLongLived( self, name, dilepton, params ) :
+        """
+        Make a 6-muon
+        Jpsi is just a proxy to get the 6-body combination
+        """
+        _Decays = "J/psi(1S) -> KS0 KS0 KS0"
+
+         # define all the cuts
+        _CombCuts12  = "(ADOCA(1,2)<0.7*mm) & (APT>500)"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> -0.5)" #2.5
+        _CombCuts    = "ACUTDOCACHI2(16,'')"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)" #4.5
+        _MotherCuts  = "(BPVDLS>3) & (VFASPF(VCHI2PDOF) < 16) & ( NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.15) )> 2.5) & ( NINTREE ( ( 'mu-' == ABSID ) & (PT>400) )> 2.5  ) & (BPVDIRA > 0.995)" % params
+
+        _daughtersCuts = "(PT>400*MeV)  & ( NINTREE ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)"
+
+        _Combine = DaVinci__N3BodyDecays()
+
+        _Combine.DecayDescriptor = _Decays
+
+        _Combine.DaughtersCuts = {
+            "KS0"  : _daughtersCuts }
+
+        _Combine.Combination12Cut   = _CombCuts12
+        # _Combine.Combination123Cut   = _CombCuts123
+        # _Combine.Combination1234Cut   = _CombCuts1234
+        # _Combine.Combination12345Cut   = _CombCuts1234
+        _Combine.CombinationCut   = _CombCuts
+        _Combine.MotherCut        = _MotherCuts
+        #_stdNoPIDLooseMuons = DataOnDemand(Location = "Phys/StdAllNoPIDsMuons/Particles")
+
+        return Selection( name, Algorithm = _Combine, RequiredSelections = [ dilepton ] )
 
 #####################################################
     def _make8muIncl( self, name, params ) :
@@ -1707,6 +1977,41 @@ class MultiLeptonConf(LineBuilder) :
 
         return Selection( name, Algorithm = _Combine, RequiredSelections = [ seldimu ] )
 
+#####################################################
+    def  _make8mu4bodyLongLived( self, name, dilepton, params ) :
+        """
+        Make a 8-muon
+        Jpsi is just a proxy to get the 8-body combination
+        Start with a dimuon
+        """
+
+        #now, build the Jpsi
+        _Decays = "J/psi(1S) -> KS0 KS0 KS0 KS0"
+
+         # define all the cuts
+        _CombCuts12  = "(ADOCA(1,2)<0.7*mm) & (APT>500)"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)" #2.5
+        _CombCuts123  = "ACUTDOCACHI2(16,'')"#" & (ANUM (( 'mu-' == ABSID ) & ISMUON )>0.5)" #  & (ANUM (( 'mu-' == ABSID ) & (PROBNNmu>0.05) )>0.5)" #4.5
+        # _CombCuts1234  = "ACUTDOCACHI2(20,'')"
+        _CombCuts    = "ACUTDOCACHI2(16,'')"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)" #6.5
+        _MotherCuts  = "(VFASPF(VCHI2PDOF) < 16) & ( NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.05) )> 4.5) & ( NINTREE ( ( 'mu-' == ABSID ) & (PT>400) )> 4.5  ) & ( NINTREE ( ( 'mu-' == ABSID ) & (ISMUON) )> 4.5)" % params #5.5 , 6.5
+
+        _daughtersCuts = "(PT>400*MeV)  & ( NINTREE ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)"
+
+        _Combine = DaVinci__N4BodyDecays()
+
+        _Combine.DecayDescriptor = _Decays
+
+        _Combine.DaughtersCuts = {
+            "KS0"  : _daughtersCuts }
+
+        _Combine.Combination12Cut   = _CombCuts12
+        _Combine.Combination123Cut   = _CombCuts123
+
+        _Combine.CombinationCut   = _CombCuts
+        _Combine.MotherCut        = _MotherCuts
+
+        return Selection( name, Algorithm = _Combine, RequiredSelections = [ dilepton ] )
+
 #####################################################
     def _make2Mu2EInclDetLoose( self, name, dimuon, dielectron, params ) :
         """
-- 
GitLab


From fbeb016fb133ad1e7f5a1d183265de7171626ec2 Mon Sep 17 00:00:00 2001
From: Vitalii Lisovskyi <vitalii.lisovskyi@cern.ch>
Date: Tue, 22 Jun 2021 09:08:53 +0000
Subject: [PATCH 2/2] fix multiplicity of 6mu builders + wrong parent cut

---
 .../StrippingRD/StrippingMultiLepton.py                   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
index f51de64b9..44a9e6a7b 100644
--- a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingMultiLepton.py
@@ -1452,6 +1452,7 @@ class MultiLeptonConf(LineBuilder) :
         _Cut = "((VFASPF(VCHI2/VDOF) < %(BVertexCHI2)s) "\
                "& (BPVIPCHI2() < %(BIPCHI2)s) "\
                "& (BPVDIRA > %(BDIRA)s) "\
+               "& (NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.1) )> 2.5)"\
                "& (BPVVDCHI2 > %(BFlightCHI2)s))" % params
 
         _Combine = CombineParticles( DecayDescriptors = _Decays,
@@ -1459,7 +1460,7 @@ class MultiLeptonConf(LineBuilder) :
                                      MotherCut        = _Cut )
 
         _Combine.DaughtersCuts = {
-            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.2)) )>0.5)" }
+            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.1)) )>0.5)" }
 
         _Merge = MergedSelection( "Merge" + name, RequiredSelections = hadrons )
 
@@ -1483,6 +1484,7 @@ class MultiLeptonConf(LineBuilder) :
         _Cut = "((VFASPF(VCHI2/VDOF) < %(BVertexCHI2)s) "\
                "& (BPVIPCHI2() < %(BIPCHI2)s) "\
                "& (BPVDIRA > %(BDIRA)s) "\
+               "& (NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.1) )> 4.5)"\
                "& (BPVVDCHI2 > %(BFlightCHI2)s))" % params
 
         _Combine = CombineParticles( DecayDescriptors = _Decays,
@@ -1490,7 +1492,7 @@ class MultiLeptonConf(LineBuilder) :
                                      MotherCut        = _Cut )
 
         _Combine.DaughtersCuts = {
-            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.05)) )>0.5)" }
+            "KS0"  : "(M < 6100)  & (NINTREE ( ( 'mu-' == ABSID ) & (ISLONG) & ((PROBNNmu>0.1)) )>0.5)" }
 
         _Merge = MergedSelection( "Merge" + name, RequiredSelections = hadrons )
 
@@ -1835,7 +1837,7 @@ class MultiLeptonConf(LineBuilder) :
          # define all the cuts
         _CombCuts12  = "(ADOCA(1,2)<0.7*mm) & (APT>500)"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> -0.5)" #2.5
         _CombCuts    = "ACUTDOCACHI2(16,'')"#"  & ( ANUM ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)" #4.5
-        _MotherCuts  = "(BPVDLS>3) & (VFASPF(VCHI2PDOF) < 16) & ( NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.15) )> 2.5) & ( NINTREE ( ( 'mu-' == ABSID ) & (PT>400) )> 2.5  ) & (BPVDIRA > 0.995)" % params
+        _MotherCuts  = "(VFASPF(VCHI2PDOF) < 16) & ( NINTREE ( ( 'mu-' == ABSID ) & (PROBNNmu>0.1) )> 4.5) & ( NINTREE ( ( 'mu-' == ABSID ) & (PT>400) )> 3.5  )" % params
 
         _daughtersCuts = "(PT>400*MeV)  & ( NINTREE ( ( 'mu-' == ABSID ) & (ISMUON) )> 0.5)"
 
-- 
GitLab