From b5d32347c4632e4acb32dc59b70c3d4ba5bae8d2 Mon Sep 17 00:00:00 2001
From: "james.david.brown@cern.ch" <james.david.brown@cern.ch>
Date: Wed, 28 Jun 2023 15:21:23 +0200
Subject: [PATCH 1/2] Initial commit for BdK1MuMu Line

---
 .../StrippingRD/StrippingB2K1MuMu.py          | 162 ++++++++++++++++++
 1 file changed, 162 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..ef08bfc66
--- /dev/null
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
@@ -0,0 +1,162 @@
+"""
+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
+
+### TEST DATA
+echo -n 2016 BD2K1MUMU | ./run gaudirun.py -T Phys/StrippingSelections/tests/users/TestMyStrippingLine.py >& ./k1.log &
+
+### SIGNAL
+echo -n 2016 Bd2K1MuMu | ./run gaudirun.py -T TestMyStrippingLineSignal.py >& ./signalK1.log &
+"""
+
+########################################################################
+__author__ = ['James Brown']
+__date__ = '23/06/2023'
+__version__ = '$ 1.0 $'
+
+# Add all functions in here - must have default_config
+__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
+
+# Need to add this
+# moni = MonFilter( 'VoidFilter_SpdHits' , Code = "( recSummary(LHCb.RecSummary.nSPDhits,'Raw/Spd/Digits') < 600 )", Preambulo=[ "from LoKiNumbers.decorators import *", "from LoKiCore.basic import LHCb" ])
+
+default_config = {
+    'NAME'        : 'Bd2K1MuMu',
+    'WGs'         : ['RD'],
+    # Should be the name of the class where stripping line is registered
+    '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
+
+        # 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,
+                                                 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")
+
+    # Create a new selection using the combined selection and the filter
+    return Selection( name,
+                      Algorithm = CombineKst,
+                      RequiredSelections = [ StdAllLooseKaons, StdAllLoosePions ] )
\ No newline at end of file
-- 
GitLab


From 2e0a1b82a0e6a83c42b97f0e73e3d0b7ddc60d4a Mon Sep 17 00:00:00 2001
From: "james.david.brown@cern.ch" <james.david.brown@cern.ch>
Date: Wed, 28 Jun 2023 17:18:45 +0200
Subject: [PATCH 2/2] Initial commit for B2K1MuMu

---
 .../StrippingRD/StrippingB2K1MuMu.py          | 34 ++++++++++---------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
index ef08bfc66..81ac957cb 100644
--- a/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
+++ b/Phys/StrippingSelections/python/StrippingSelections/StrippingRD/StrippingB2K1MuMu.py
@@ -1,13 +1,18 @@
+###############################################################################
+# (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
-
-### TEST DATA
-echo -n 2016 BD2K1MUMU | ./run gaudirun.py -T Phys/StrippingSelections/tests/users/TestMyStrippingLine.py >& ./k1.log &
-
-### SIGNAL
-echo -n 2016 Bd2K1MuMu | ./run gaudirun.py -T TestMyStrippingLineSignal.py >& ./signalK1.log &
 """
 
 ########################################################################
@@ -15,7 +20,6 @@ __author__ = ['James Brown']
 __date__ = '23/06/2023'
 __version__ = '$ 1.0 $'
 
-# Add all functions in here - must have default_config
 __all__ = ('Bd2K1MuMuLine',
            'makeBdK1Jpsi',
            'makeJpsis',
@@ -31,13 +35,9 @@ from PhysSelPython.Wrappers      import Selection
 from StrippingConf.StrippingLine import StrippingLine
 from StrippingUtils.Utils        import LineBuilder, checkConfig
 
-# Need to add this
-# moni = MonFilter( 'VoidFilter_SpdHits' , Code = "( recSummary(LHCb.RecSummary.nSPDhits,'Raw/Spd/Digits') < 600 )", Preambulo=[ "from LoKiNumbers.decorators import *", "from LoKiCore.basic import LHCb" ])
-
 default_config = {
     'NAME'        : 'Bd2K1MuMu',
     'WGs'         : ['RD'],
-    # Should be the name of the class where stripping line is registered
     'BUILDERTYPE' : 'Bd2K1MuMuLine',
     'CONFIG'      : {'PrescaleBd2K1MuMuLine'  : 1,
                     ### B0
@@ -76,6 +76,12 @@ class Bd2K1MuMuLine( LineBuilder ) :
 
         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'],
@@ -91,6 +97,7 @@ class Bd2K1MuMuLine( LineBuilder ) :
         self.lineBd2K1MuMu = StrippingLine( Bd2K1MuMuName+"Line",
                                                  prescale  = config['PrescaleBd2K1MuMuLine'],
                                                  selection = self.BdK1Jpsi,
+                                                 FILTER = SPDFilter,
                                                  EnableFlavourTagging = False,
                                                  RequiredRawEvents = ["Trigger","Muon","Calo","Rich","Velo","Tracker"])
                                                  #RequiredRawEvents = ["Velo"])
@@ -114,8 +121,6 @@ def makeBdK1Jpsi( name, Jpsi, K1,
                       Algorithm = CombineBdK1Jpsi,
                       RequiredSelections = [ Jpsi, K1 ] )
 
-##############################################################
-
 def makeJpsis(  name,
                 InterMIPCHI2DV, InterVertexCHI2, JpsiLowerM, JpsiUpperM,
                 fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, muPROBpi, fsM) :
@@ -137,8 +142,6 @@ def makeJpsis(  name,
                       Algorithm = CombineDiMuons,
                       RequiredSelections = [ StdLooseMuons ] )
 
-##############################################################
-
 def makeKstars( name,
                 InterMIPCHI2DV, InterVertexCHI2, KstLowerM, KstUpperM, Kst_PT,
                 fsPT, fsMIPCHI2DV, fsTRCHI2, fsTRGHOSTPROB, fsPROBNN, fsM) :
@@ -156,7 +159,6 @@ def makeKstars( name,
 
     KstConf = CombineKst.configurable("CombineKst")
 
-    # Create a new selection using the combined selection and the filter
     return Selection( name,
                       Algorithm = CombineKst,
                       RequiredSelections = [ StdAllLooseKaons, StdAllLoosePions ] )
\ No newline at end of file
-- 
GitLab