From 13ab0464a0f289104724e04aedde1898e281c7eb Mon Sep 17 00:00:00 2001
From: Izaac Sanderswood <izaac.sanderswood@cern.ch>
Date: Fri, 7 Jan 2022 17:54:15 +0100
Subject: [PATCH] skeleton of bs2phigamma line

---
 .../Hlt2Conf/lines/rd/bs2phigamma_line.py     | 165 ++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 Hlt/Hlt2Conf/python/Hlt2Conf/lines/rd/bs2phigamma_line.py

diff --git a/Hlt/Hlt2Conf/python/Hlt2Conf/lines/rd/bs2phigamma_line.py b/Hlt/Hlt2Conf/python/Hlt2Conf/lines/rd/bs2phigamma_line.py
new file mode 100644
index 00000000000..f5b80579f8d
--- /dev/null
+++ b/Hlt/Hlt2Conf/python/Hlt2Conf/lines/rd/bs2phigamma_line.py
@@ -0,0 +1,165 @@
+###############################################################################
+# (c) Copyright 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.									   #
+###############################################################################
+""" Bs2PhiGamma Hlt2 Line
+
+"""
+from Moore.config import register_line_builder
+from Moore.lines import Hlt2Line
+from RecoConf.reconstruction_objects import upfront_reconstruction
+
+from GaudiKernel.SystemOfUnits import GeV, MeV, mm
+import Functors as F
+from Functors.math import in_range
+
+from RecoConf.reconstruction_objects import (
+	make_pvs_v2 as make_pvs,
+	make_pvs as make_pvs_v1
+	)
+
+from PyConf import configurable
+
+# from Hlt2Conf.standard_particles import (
+# 	make_photons,
+# 	make_long_kaons,
+# 	make_phi2kk,
+# 	make_has_rich_long_kaons
+# )
+
+from Hlt2Conf.lines.rd.builders.rdbuilder_thor import (
+	make_rd_photons as make_photons,
+	make_rd_detached_phis,
+)
+
+from Hlt2Conf.lines.rd.builders import b_tmva_builder
+
+all_lines = {}
+
+from Hlt2Conf.algorithms_thor import ParticleCombiner, ParticleFilter, require_all
+
+## The cuts are put here for clarity
+## If adding new cuts, please add here, then refer to them in the parts below
+photon_cuts = {
+	"pt_min" : 2 * GeV,
+	"p_min" : 5*GeV,
+}
+
+track_cuts = {
+	"chi2pdof_max" : 5,
+	"ipchi2_min" : 20,
+	"pt_min": 500 * MeV,
+}
+	
+phi_cuts = {
+	"vchi2pdof_max" : 25 ,
+	"comb_m_min": 1010 * MeV,
+	"comb_m_max" : 1030 * MeV ,
+}
+	
+b_cuts = {
+	"vchi2pdof_max" : 25 ,
+	"dira_max": 0.063,
+	"pt_min" : 2000 * MeV,
+	"comb_m_min" : 750 * MeV,
+	"comb_m_max" : 2250 * MeV,
+	"ipchi2_max": 12,
+}
+	
+cuts = {
+	"photon": photon_cuts,
+	"track": track_cuts,
+	"phi": phi_cuts,
+	"b": b_cuts
+}
+
+
+# make sure we passed GEC and have PV in event
+def prefilters():
+	return [require_pvs(make_pvs())]
+
+
+# Define photon filter
+# TO DO -- what are the filter requirements?
+# @configurable
+# def filter_photons(photons,pvs,pt_min=photon_cuts["pt_min"]):
+# 	filter_code = require_all(
+# 		F.PT > pt_min
+# 	)
+# 	return ParticleFilter(photons,F.FILTER(filter_code))
+# 	# return photons
+
+# # Define the kaon filter
+# @configurable
+# def filter_kaons(kaons,pvs,pt_min=track_cuts["pt_min"],chi2pdof_max=track_cuts["chi2pdof_max"],ipchi2_min=track_cuts["ipchi2_min"]):
+# 	filter_code = require_all(
+# 		F.PT > pt_min,
+# 		F.CHI2DOF < chi2pdof_max,
+# 		F.BPVIPCHI2(pvs) > ipchi2_min
+# 	)
+# 	return ParticleFilter(kaons,F.FILTER(filter_code))
+
+# # define the maker for the phi
+# @configurable
+# def make_phis(kaons,pvs,comb_m_min=phi_cuts["comb_m_min"],comb_m_max=phi_cuts["comb_m_max"],vchi2pdof_max=phi_cuts["vchi2pdof_max"]):
+# 	descriptor = "[phi(1020) -> K+ K-]cc"
+# 	combination_code = in_range(comb_m_min,F.MASS,comb_m_max)
+# 	vertex_code = require_all(
+# 		F.CHI2DOF < vchi2pdof_max
+# 	)
+# 	return ParticleCombiner(
+# 		name="Phi2KKCombiner4Bs2PhiGamma",
+# 		Inputs=kaons,
+# 		DecayDescriptor=descriptor,
+# 		CombinationCut=combination_code,
+# 		CompositeCut=vertex_code
+# 		)
+
+
+
+# Make the Bs
+@configurable
+def make_bs2phigamma(phis, photons, pvs,comb_m_min=b_cuts["comb_m_min"],comb_m_max=b_cuts["comb_m_max"],pt_min=b_cuts["pt_min"],vchi2pdof_max=b_cuts["vchi2pdof_max"],ipchi2_max=b_cuts["ipchi2_max"]):
+	descriptor = "[B_s0 -> phi(1020) gamma]cc"
+	combination_code = require_all(
+		in_range(comb_m_min,F.MASS,comb_m_max),
+		F.SUM(F.PT) > pt_min,
+	)
+	vertex_code = require_all(
+		F.CHI2DOF < vchi2pdof_max,
+		F.BPVIPCHI2(pvs) < ipchi2_max
+	)
+	# return particle combiner
+	return ParticleCombiner(name="Bs2PhiGammaCombiner",
+							Inputs=[phis,photons],
+							DecayDescriptor=descriptor,
+							CombinationCut=combination_code,
+							CompositeCut=vertex_code
+							)
+
+@register_line_builder(all_lines)
+def bs2phigamma_line(name="Hlt2Bs2PhiGammaLine",prescale=1):
+	pvs = make_pvs()
+	pvs_v1 = make_pvs_v1()
+	# to do: double check which type of kaon to use
+	# kaons = filter_kaons(kaons=make_long_kaons(),pvs=pvs)
+	# phis = make_phis([kaons,kaons],pvs) # is this ok or broken?
+	phis = make_rd_detached_phis()
+
+	# photons = filter_photons(photons=make_photons(),pvs=pvs)
+	photons = make_photons() ;
+	b_s0_presel = make_bs2phigamma(phis=phis,photons=photons,pvs=pvs)
+	b_s0 = b_tmva_builder.make_b(b_s0_presel, pvs_v1, "HHgamma", 0.18)
+
+
+	return Hlt2Line(
+		name=name,
+		algs=upfront_reconstruction()+[b_s0],
+		prescale=prescale,
+		)
\ No newline at end of file
-- 
GitLab