From e81e1bbcbce7609a9205086807a4fb42d20192d5 Mon Sep 17 00:00:00 2001
From: James David Brown <James David Brown james.david.brown@cern.ch>
Date: Thu, 29 Jun 2023 10:04:48 +0200
Subject: [PATCH 1/2] Initial commit

---
 .../StrippingRD/StrippingB2K1MuMu.py          | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py

diff --git a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
new file mode 100644
index 000000000..81ac957cb
--- /dev/null
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
@@ -0,0 +1,164 @@
+###############################################################################
+# (c) Copyright 2000-2021 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+"""
+Stripping options for "B0 -> ( Jpsi -> mu+ mu- ) ( K1(1270) -> ( K*(892) -> K+ pi- ) pi0 )"CC - reconstructed as Bd -> Jpsi K* for efficiency reasons'
+
+Author: James Brown
+"""
+
+########################################################################
+__author__ = ['James Brown']
+__date__ = '23/06/2023'
+__version__ = '$ 1.0 $'
+
+__all__ = ('Bd2K1MuMuLine',
+           'makeBdK1Jpsi',
+           'makeJpsis',
+           'makeKstars',
+           'default_config')
+
+from Gaudi.Configuration import *
+
+from GaudiConfUtils.ConfigurableGenerators import CombineParticles
+from StandardParticles                     import StdLooseMuons, StdAllLooseKaons, StdAllLoosePions
+
+from PhysSelPython.Wrappers      import Selection
+from StrippingConf.StrippingLine import StrippingLine
+from StrippingUtils.Utils        import LineBuilder, checkConfig
+
+default_config = {
+    'NAME'        : 'Bd2K1MuMu',
+    'WGs'         : ['RD'],
+    'BUILDERTYPE' : 'Bd2K1MuMuLine',
+    'CONFIG'      : {'PrescaleBd2K1MuMuLine'  : 1,
+                    ### B0
+                     'BMassWindow'      : 2500,
+                     'BDIRA'            : 0.9995, 
+                     'BIPCHI2'          : 100,
+                     'BVertexCHI2'      : 9,
+                     'BVDCHI2'          : 100,
+                    ### Intermediates - Jpsi/Kst
+                     "InterMIPCHI2DV"   : 0,
+                     "InterVertexCHI2"  : 9,
+                     "JpsiUpperM"       : 3300,
+                     "JpsiLowerM"       : 3000,
+                     "KstUpperM"        : 1100,
+                     "KstLowerM"        : 700,
+                     "Kst_PT"           : 800,
+                    ### Final states
+                     "fsPT"             : 300,
+                     "fsMIPCHI2DV"      : 4,
+                     "fsTRCHI2"         : 4,
+                     "fsTRGHOSTPROB"    : 0.4,
+                     "fsPROBNN"         : 0.4,
+                     "muPROBpi"         : 0.95,
+                     "fsM"              : 2600,
+                    },
+    'STREAMS'     : ['Leptonic']
+}
+
+class Bd2K1MuMuLine( LineBuilder ) :
+
+    __configuration_keys__ = default_config['CONFIG'].keys()
+
+    def __init__( self,name,config ) :
+
+        LineBuilder.__init__(self, name, config)
+
+        Bd2K1MuMuName = name
+
+        # Default SPD hits filter
+        SPDFilter = {
+            'Code'      : " ( recSummary(LHCb.RecSummary.nSPDhits,'Raw/Spd/Digits') < 600 )" ,
+            'Preambulo' : [ "from LoKiNumbers.decorators import *", "from LoKiCore.basic import LHCb" ]
+            }
+
+        # Make parents
+        self.Jpsi = makeJpsis(  "JpsisForBd2K1MuMu",
+                                config['InterMIPCHI2DV'], config['InterVertexCHI2'], config['JpsiLowerM'], config['JpsiUpperM'],
+                                config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['muPROBpi'], config['fsM'])
+        self.Kst = makeKstars(  "KstForBd2K1MuMu",
+                                config['InterMIPCHI2DV'], config['InterVertexCHI2'], config['KstLowerM'], config['KstUpperM'], config['Kst_PT'],
+                                config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['fsM'])
+
+        # Make B0
+        self.BdK1Jpsi = makeBdK1Jpsi( name, self.Jpsi, self.Kst, 
+                                            config['BMassWindow'], config['BVertexCHI2'], config['BIPCHI2'], config['BDIRA'], config['BVDCHI2'])
+
+        self.lineBd2K1MuMu = StrippingLine( Bd2K1MuMuName+"Line",
+                                                 prescale  = config['PrescaleBd2K1MuMuLine'],
+                                                 selection = self.BdK1Jpsi,
+                                                 FILTER = SPDFilter,
+                                                 EnableFlavourTagging = False,
+                                                 RequiredRawEvents = ["Trigger","Muon","Calo","Rich","Velo","Tracker"])
+                                                 #RequiredRawEvents = ["Velo"])
+
+        self.registerLine(self.lineBd2K1MuMu)
+
+##############################################################
+
+def makeBdK1Jpsi( name, Jpsi, K1, 
+                        BMassWindow, BVertexCHI2, BIPCHI2, BDIRA, BVDCHI2) :
+
+    _combination_cuts = "( ADAMASS('B0') < %(BMassWindow)s * MeV )" %locals()
+
+    _mother_cuts = "( (VFASPF(VCHI2/VDOF) < %(BVertexCHI2)s ) & (BPVIPCHI2() < %(BIPCHI2)s ) & (BPVDIRA > %(BDIRA)s ) & (BPVVDCHI2 > %(BVDCHI2)s ) )" %locals()
+
+    CombineBdK1Jpsi = CombineParticles( DecayDescriptor = "[B0 -> J/psi(1S) K*(892)0]cc",
+                                               CombinationCut = _combination_cuts,
+                                               MotherCut = _mother_cuts )
+
+    return Selection( name,
+                      Algorithm = CombineBdK1Jpsi,
+                      RequiredSelections = [ Jpsi, K1 ] )
+
+def makeJpsis(  name,
+                InterMIPCHI2DV, InterVertexCHI2, JpsiLowerM, JpsiUpperM,
+                fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, muPROBpi, fsM) :
+
+    _daughters_cuts = '(HASMUON) & (ISMUON) & ( PT > %(fsPT)s ) & ( MIPCHI2DV(PRIMARY) > %(fsMIPCHI2DV)s ) & ( TRGHOSTPROB < %(fsTRGHOSTPROB)s ) & ( TRCHI2DOF < %(fsTRCHI2)s ) & ( PROBNNpi < %(muPROBpi)s ) & ( PROBNNmu > %(fsPROBNN)s )' %locals()
+
+    _combination_cuts = "(AM > 100*MeV)"
+
+    _mother_cuts = "(MM > %(JpsiLowerM)s *MeV) & (MM < %(JpsiUpperM)s *MeV) & (VFASPF(VCHI2/VDOF)<%(InterVertexCHI2)s) & (MIPCHI2DV(PRIMARY) > %(InterMIPCHI2DV)s )" %locals()
+
+    CombineDiMuons = CombineParticles( DecayDescriptor = "J/psi(1S) -> mu+ mu-",
+                                               DaughtersCuts = { "mu+" : _daughters_cuts, "mu-" : _daughters_cuts},
+                                               CombinationCut = _combination_cuts,
+                                               MotherCut = _mother_cuts )
+
+    DiMuonConf = CombineDiMuons.configurable("CombineDiMuons")
+
+    return Selection( name,
+                      Algorithm = CombineDiMuons,
+                      RequiredSelections = [ StdLooseMuons ] )
+
+def makeKstars( name,
+                InterMIPCHI2DV, InterVertexCHI2, KstLowerM, KstUpperM, Kst_PT,
+                fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, fsM) :
+
+    _daughters_cuts = "(PT > %(fsPT)s) & (MIPCHI2DV(PRIMARY)>%(fsMIPCHI2DV)s) & (TRGHOSTPROB<%(fsTRGHOSTPROB)s) & (TRCHI2DOF<%(fsTRCHI2)s) & (M<%(fsM)s)" %locals()
+
+    _combination_cuts = "(APT > 500 *MeV) & (ADAMASS('K*(892)0') < 300 *MeV) & (ADOCACHI2CUT(30, ''))"
+
+    _mother_cuts = "(MM > %(KstLowerM)s *MeV) & (MM < %(KstUpperM)s *MeV) & (VFASPF(VCHI2/VDOF)<%(InterVertexCHI2)s) & (MIPCHI2DV(PRIMARY) > %(InterMIPCHI2DV)s ) & (PT>%(Kst_PT)s *MeV)" %locals()
+
+    CombineKst = CombineParticles( DecayDescriptor = "[K*(892)0 -> K+ pi-]cc",
+                                               DaughtersCuts = {"K+" : _daughters_cuts + " & (PROBNNk>%(fsPROBNN)s)" %locals(), "pi-" : _daughters_cuts + " & (PROBNNpi>%(fsPROBNN)s)" %locals()},
+                                               CombinationCut = _combination_cuts,
+                                               MotherCut = _mother_cuts)
+
+    KstConf = CombineKst.configurable("CombineKst")
+
+    return Selection( name,
+                      Algorithm = CombineKst,
+                      RequiredSelections = [ StdAllLooseKaons, StdAllLoosePions ] )
\ No newline at end of file
-- 
GitLab


From 9387f2c1d58c00b9973be4bd330db5b4488117e9 Mon Sep 17 00:00:00 2001
From: James David Brown <James David Brown james.david.brown@cern.ch>
Date: Thu, 13 Jul 2023 16:24:14 +0200
Subject: [PATCH 2/2] Added SS muons line and widened Jpsi mass window

---
 .../StrippingRD/StrippingB2K1MuMu.py          | 47 +++++++++++++++----
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
index 81ac957cb..bdbde4d03 100644
--- a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
@@ -10,7 +10,8 @@
 ###############################################################################
 
 """
-Stripping options for "B0 -> ( Jpsi -> mu+ mu- ) ( K1(1270) -> ( K*(892) -> K+ pi- ) pi0 )"CC - reconstructed as Bd -> Jpsi K* for efficiency reasons'
+Stripping options for "B0 -> ( Jpsi -> mu+ mu- ) ( K1(1270) -> ( K*(892) -> K+ pi- ) pi0 )CC" - reconstructed as Bd -> Jpsi K* for efficiency reasons
+Also contains the SS muons line: "B0 -> ( Jpsi -> mu+ mu+ ) ( K1(1270) -> ( K*(892) -> K+ pi- ) pi0 )CC"
 
 Author: James Brown
 """
@@ -18,7 +19,7 @@ Author: James Brown
 ########################################################################
 __author__ = ['James Brown']
 __date__ = '23/06/2023'
-__version__ = '$ 1.0 $'
+__version__ = '$ 1.1 $'
 
 __all__ = ('Bd2K1MuMuLine',
            'makeBdK1Jpsi',
@@ -40,6 +41,7 @@ default_config = {
     'WGs'         : ['RD'],
     'BUILDERTYPE' : 'Bd2K1MuMuLine',
     'CONFIG'      : {'PrescaleBd2K1MuMuLine'  : 1,
+                    'PrescaleBd2K1MuMuSSLine' : 1,
                     ### B0
                      'BMassWindow'      : 2500,
                      'BDIRA'            : 0.9995, 
@@ -49,8 +51,8 @@ default_config = {
                     ### Intermediates - Jpsi/Kst
                      "InterMIPCHI2DV"   : 0,
                      "InterVertexCHI2"  : 9,
-                     "JpsiUpperM"       : 3300,
-                     "JpsiLowerM"       : 3000,
+                     "JpsiUpperM"       : 9000,
+                     "JpsiLowerM"       : 1000,
                      "KstUpperM"        : 1100,
                      "KstLowerM"        : 700,
                      "Kst_PT"           : 800,
@@ -83,9 +85,18 @@ class Bd2K1MuMuLine( LineBuilder ) :
             }
 
         # Make parents
+        # Mu+Mu-/Mu-Mu+
         self.Jpsi = makeJpsis(  "JpsisForBd2K1MuMu",
                                 config['InterMIPCHI2DV'], config['InterVertexCHI2'], config['JpsiLowerM'], config['JpsiUpperM'],
-                                config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['muPROBpi'], config['fsM'])
+                                config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['muPROBpi'], config['fsM'], 
+                                sameSign = False)
+        
+        # Mu+Mu+/Mu-Mu- (SS)
+        self.JpsiSS = makeJpsis(  "SSJpsisForBd2K1MuMu",
+                                config['InterMIPCHI2DV'], config['InterVertexCHI2'], config['JpsiLowerM'], config['JpsiUpperM'],
+                                config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['muPROBpi'], config['fsM'], 
+                                sameSign = True)
+        # Kstar candidates
         self.Kst = makeKstars(  "KstForBd2K1MuMu",
                                 config['InterMIPCHI2DV'], config['InterVertexCHI2'], config['KstLowerM'], config['KstUpperM'], config['Kst_PT'],
                                 config['fsPT'], config['fsMIPCHI2DV'], config['fsTRCHI2'], config['fsTRGHOSTPROB'], config['fsPROBNN'], config['fsM'])
@@ -93,6 +104,10 @@ class Bd2K1MuMuLine( LineBuilder ) :
         # Make B0
         self.BdK1Jpsi = makeBdK1Jpsi( name, self.Jpsi, self.Kst, 
                                             config['BMassWindow'], config['BVertexCHI2'], config['BIPCHI2'], config['BDIRA'], config['BVDCHI2'])
+        
+        # Make B0 with SS
+        self.BdK1JpsiSS = makeBdK1Jpsi( name+'SS', self.JpsiSS, self.Kst, 
+                                            config['BMassWindow'], config['BVertexCHI2'], config['BIPCHI2'], config['BDIRA'], config['BVDCHI2'])
 
         self.lineBd2K1MuMu = StrippingLine( Bd2K1MuMuName+"Line",
                                                  prescale  = config['PrescaleBd2K1MuMuLine'],
@@ -100,11 +115,18 @@ class Bd2K1MuMuLine( LineBuilder ) :
                                                  FILTER = SPDFilter,
                                                  EnableFlavourTagging = False,
                                                  RequiredRawEvents = ["Trigger","Muon","Calo","Rich","Velo","Tracker"])
-                                                 #RequiredRawEvents = ["Velo"])
+        
+        self.lineBd2K1MuMuSS = StrippingLine( Bd2K1MuMuName+"SSLine",
+                                                 prescale  = config['PrescaleBd2K1MuMuSSLine'],
+                                                 selection = self.BdK1JpsiSS,
+                                                 FILTER = SPDFilter,
+                                                 EnableFlavourTagging = False,
+                                                 RequiredRawEvents = ["Trigger","Muon","Calo","Rich","Velo","Tracker"])
 
         self.registerLine(self.lineBd2K1MuMu)
+        self.registerLine(self.lineBd2K1MuMuSS)
 
-##############################################################
+############################################################## FUNCTIONS
 
 def makeBdK1Jpsi( name, Jpsi, K1, 
                         BMassWindow, BVertexCHI2, BIPCHI2, BDIRA, BVDCHI2) :
@@ -123,7 +145,8 @@ def makeBdK1Jpsi( name, Jpsi, K1,
 
 def makeJpsis(  name,
                 InterMIPCHI2DV, InterVertexCHI2, JpsiLowerM, JpsiUpperM,
-                fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, muPROBpi, fsM) :
+                fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, muPROBpi, fsM,
+                sameSign) :
 
     _daughters_cuts = '(HASMUON) & (ISMUON) & ( PT > %(fsPT)s ) & ( MIPCHI2DV(PRIMARY) > %(fsMIPCHI2DV)s ) & ( TRGHOSTPROB < %(fsTRGHOSTPROB)s ) & ( TRCHI2DOF < %(fsTRCHI2)s ) & ( PROBNNpi < %(muPROBpi)s ) & ( PROBNNmu > %(fsPROBNN)s )' %locals()
 
@@ -131,7 +154,13 @@ def makeJpsis(  name,
 
     _mother_cuts = "(MM > %(JpsiLowerM)s *MeV) & (MM < %(JpsiUpperM)s *MeV) & (VFASPF(VCHI2/VDOF)<%(InterVertexCHI2)s) & (MIPCHI2DV(PRIMARY) > %(InterMIPCHI2DV)s )" %locals()
 
-    CombineDiMuons = CombineParticles( DecayDescriptor = "J/psi(1S) -> mu+ mu-",
+    # identical cuts, just with the muon sign either the same or opposite
+    if sameSign :
+        decDesc = "[J/psi(1S) -> mu+ mu+]cc"
+    else:
+        decDesc = "J/psi(1S) -> mu+ mu-"
+
+    CombineDiMuons = CombineParticles( DecayDescriptor = decDesc,
                                                DaughtersCuts = { "mu+" : _daughters_cuts, "mu-" : _daughters_cuts},
                                                CombinationCut = _combination_cuts,
                                                MotherCut = _mother_cuts )
-- 
GitLab