Skip to content
Snippets Groups Projects
Commit 1fb42f24 authored by Alessandro Bertolin's avatar Alessandro Bertolin Committed by Alexander Leon Gilman
Browse files

B2OC: run on centrally produced MC samples removing the hlt2 PID cuts

parent d91a4300
No related branches found
No related tags found
2 merge requests!2320B2OC: run on centrally produced MC samples removing the hlt2 PID cuts,!2313Draft: Rquaglia rd ap 2024 for b->v ee very low q2 fixes on DTF and vertex errors
# Based on:
# https://gitlab.cern.ch/lhcb/DaVinci/-/blob/v63r2/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_from_hlt2.py
import Functors as F
import FunTuple.functorcollections as FC
from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple
from PyConf.reading import get_particles, get_pvs, get_rec_summary, get_odin
from GaudiKernel.SystemOfUnits import GeV
from Hlt2Conf.algorithms_thor import ParticleFilter
from DaVinci.algorithms import create_lines_filter
from DaVinci import Options, make_config
from DaVinciMCTools import MCTruthAndBkgCat
from DecayTreeFitter import DecayTreeFitter
from Hlt2Conf.flavourTagging import run2_all_taggers
# specific for the B2OC SigmaNet
import Functors.math as fmath
import os
def alg_config(options: Options):
line = "SpruceB2OC_BdToDmPi_DmToPimPimKp"
line_data = get_particles(f"/Event/Spruce/{line}/Particles")
my_filter = create_lines_filter("Hlt2Line_Filter",
lines=[f"{line}"])
Hlt1_decisions = [
"Hlt1TrackMVADecision",
"Hlt1TwoTrackMVADecision",
]
Hlt2_decisions = ['Hlt2B2OC_BdToDmPi_DmToPimPimKpDecision',
'Hlt2Topo2BodyDecision',
'Hlt2Topo3BodyDecision']
fields = {
"lab0": "[[B0]CC -> (D- -> K+ pi- pi-) pi+]CC",
"lab1": "[[B0]CC -> (D- -> K+ pi- pi-) ^pi+]CC",
"lab2": "[[B0]CC -> ^(D- -> K+ pi- pi-) pi+]CC",
"lab3": "[[B0]CC -> (D- -> ^K+ pi- pi-) pi+]CC",
"lab4": "[[B0]CC -> (D- -> K+ ^pi- pi-) pi+]CC",
"lab5": "[[B0]CC -> (D- -> K+ pi- ^pi-) pi+]CC",
}
pvs = get_pvs()
DTF_MassFitConsD = DecayTreeFitter(name="DTF_MassFitConsD",
input_particles=line_data,
mass_constraints=["D-"])
DTF_LifetimeFit = DecayTreeFitter(name="DTF_LifetimeFit",
input_particles=line_data,
input_pvs=pvs)
all_tagging = run2_all_taggers(line_data)
# define helper functors
get_child = F.CHILD(1, F.FORWARDARG0) # change here the index of the child
get_SV = F.ENDVERTEX @ F.FORWARDARG0
get_SV_pos = F.TOLINALG @ F.POSITION @ get_SV # only if composite (i.e. has vertex)
get_child_endvtx_pos = F.ENDVERTEX_POS @ get_child
get_fdvec_child = get_child_endvtx_pos - get_SV_pos
# define observables
IP_wrt_SV = F.IP.bind(get_SV_pos , get_child)
IPCHI2_wrt_SV = F.IPCHI2.bind(get_SV , get_child) # only if child is composite (i.e. has vertex)
FD_wrt_SV = F.MAGNITUDE @ get_fdvec_child
FDCHI2_wrt_SV = F.VTX_FDCHI2.bind(get_SV, get_child)
B_variables = FunctorCollection(
{
"ID": F.PARTICLE_ID,
"PT": F.PT,
"ETA": F.ETA,
"P": F.P,
"SUMPT": F.SUM(F.PT),
"MASS": F.MASS,
"BPVDIRA": F.BPVDIRA(pvs),
"CHI2DOF": F.CHI2DOF,
"BPVIPCHI2": F.BPVIPCHI2(pvs),
"BPVIP": F.BPVIP(pvs),
"BPVFDCHI2": F.BPVFDCHI2(pvs),
"BPVLTIME": F.BPVLTIME(pvs),
"BPVFD": F.BPVFD(pvs),
"CHILD1_IPwrtSV": IP_wrt_SV,
"CHILD1_IPCHI2wrtSV": IPCHI2_wrt_SV,
"CHILD1_FDwrtSV": FD_wrt_SV,
"CHILD1_FDCHI2wrtSV": FDCHI2_wrt_SV,
"DTF_MassFitConsD_MASS": DTF_MassFitConsD(F.MASS),
"DTF_MassFitConsD_CHI2DOF": DTF_MassFitConsD(F.CHI2DOF), # track or vertex chi2/ndf
"DTF_MassFitConsD_P": DTF_MassFitConsD(F.P),
"DTF_LifetimeFit_MASS": DTF_LifetimeFit(F.MASS),
"DTF_LifetimeFit_CHI2DOF": DTF_LifetimeFit(F.CHI2DOF), # track or vertex chi2/ndf
"DTF_LifetimeFit_CTAU": DTF_LifetimeFit.CTAU,
"DTF_LifetimeFit_CTAUERR": DTF_LifetimeFit.CTAUERR,
"PX": F.PX,
"PY": F.PY,
"PZ": F.PZ,
"BPVX": F.BPVX(pvs),
"BPVY": F.BPVY(pvs),
"BPVZ": F.BPVZ(pvs),
"END_VX": F.END_VX,
"END_VY": F.END_VY,
"END_VZ": F.END_VZ,
"END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
"BPVCHI2DOF": F.CHI2DOF @ F.BPV(pvs),
# B2OC generic B hadron NN Hlt2 algorithm,
# not planning to use it directly for B2OC EM
"MVA": F.MVA(
MVAType="SigmaNet",
Config={
"File":
"paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json",
"Name":
"B2OC_SigmaNet_Generic",
"Lambda":
"2.0",
"NLayers":
"3",
"InputSize":
"6",
"Monotone_Constraints":
"[1,-1,-1,-1,-1,-1]",
"Variables":
"log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
},
Inputs={
"log_B_PT": fmath.log(F.PT),
"B_ETA": F.ETA,
"log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)),
"log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
"log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
"log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
}),
"MVAold": F.MVA(
MVAType="SigmaNet",
Config={
"File":
"paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v1.json",
"Name":
"B2OC_SigmaNet_Generic",
"Lambda":
"2.0",
"NLayers":
"3",
"InputSize":
"6",
"Monotone_Constraints":
"[1,-1,-1,-1,-1,-1]",
"Variables":
"log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
},
Inputs={
"log_B_PT": fmath.log(F.PT),
"B_ETA": F.ETA,
"log_B_DIRA": fmath.log(1. - F.BPVDIRA(pvs)),
"log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
"log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
"log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
}),
}
)
B_variables+=FC.HltTisTos(selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=line_data)
B_variables+=FC.FlavourTaggingResults(all_tagging)
C_variables = FunctorCollection(
{
"ID": F.PARTICLE_ID,
"PT": F.PT,
"ETA": F.ETA,
"P": F.P,
"SUMPT": F.SUM(F.PT),
"MASS": F.MASS,
"DOCA12": F.DOCA(1, 2),
"DOCA13": F.DOCA(1, 3),
"DOCA23": F.DOCA(2, 3),
"BPVDIRA": F.BPVDIRA(pvs),
"CHI2DOF": F.CHI2DOF,
"BPVIP": F.BPVIP(pvs),
"BPVIPCHI2": F.BPVIPCHI2(pvs),
"BPVFD": F.BPVFD(pvs),
"BPVFDCHI2": F.BPVFDCHI2(pvs),
"MINIPCHI2": F.MINIPCHI2(pvs),
"PX": F.PX,
"PY": F.PY,
"PZ": F.PZ,
"BPVX": F.BPVX(pvs),
"BPVY": F.BPVY(pvs),
"BPVZ": F.BPVZ(pvs),
"END_VX": F.END_VX,
"END_VY": F.END_VY,
"END_VZ": F.END_VZ,
"END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
}
)
fs_variables = FunctorCollection(
{
"ID": F.PARTICLE_ID,
"PT": F.PT,
"ETA": F.ETA,
"PHI": F.PHI,
"P": F.P,
"MASS": F.MASS,
"CHI2DOF": F.CHI2DOF,
"MINIPCHI2": F.MINIPCHI2(pvs),
"BPVIPCHI2": F.BPVIPCHI2(pvs),
"PX": F.PX,
"PY": F.PY,
"PZ": F.PZ,
"hasRICH": F.PPHASRICH() @ F.PROTOPARTICLE(),
"PIDK": F.PID_K,
"PIDp": F.PID_P,
"PIDe": F.PID_E,
"PIDmu": F.PID_MU,
"isMuon": F.ISMUON,
"TRACK_GhostProb": F.GHOSTPROB,
"ProbNNp": F.PROBNN_P,
"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, # VeloPixel hits
"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, # UpstreamTracker hits
"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, # ForwardTracker hits
"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
}
)
variables = {
"lab0": B_variables,
"lab1": fs_variables,
"lab2": C_variables,
"lab3": fs_variables,
"lab4": fs_variables,
"lab5": fs_variables,
}
if options.simulation:
# get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output
mctruth = MCTruthAndBkgCat(line_data)
# add helper lambda that configures a functor to get truth information
MCTRUTH = lambda func: F.MAP_INPUT(Functor=func, Relations=mctruth.MCAssocTable)
trueid_bkgcat_info = {
# Important note: specify an invalid value for integer functors if there exists no truth info.
# The invalid value for floating point functors is set to nan.
"TRUEID": F.VALUE_OR(0) @ MCTRUTH(F.PARTICLE_ID),
"TRUEKEY": F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
#
"TRUEPT": MCTRUTH(F.PT),
"TRUEPX": MCTRUTH(F.PX),
"TRUEPY": MCTRUTH(F.PY),
"TRUEPZ": MCTRUTH(F.PZ),
"TRUEENERGY": MCTRUTH(F.ENERGY),
"TRUEP": MCTRUTH(F.P),
"TRUEFOURMOMENTUM": MCTRUTH(F.FOURMOMENTUM),
"BKGCAT": F.BKGCAT(Relations=mctruth.BkgCatTable),
}
for field in variables.keys():
variables[field] += FunctorCollection(trueid_bkgcat_info)
odin = get_odin()
rec_summary = get_rec_summary()
# define event level variables
evt_variables = FunctorCollection({
"RUNNUMBER": F.RUNNUMBER(odin),
"EVENTNUMBER": F.EVENTNUMBER(odin),
"nVPClusters" : F.VALUE_OR(-1) @ F.RECSUMMARY_INFO( rec_summary, "nVPClusters"),
"nFTClusters" : F.VALUE_OR(-1) @ F.RECSUMMARY_INFO( rec_summary, "nFTClusters"),
"nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"),
"nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
"nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_summary,"nVeloTracks"),
})
evt_variables+=FC.SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_decisions)
evt_variables+=FC.SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_decisions)
# define FunTuple instance
my_tuple = Funtuple(
name="Tuple",
tuple_name="DecayTree",
fields=fields,
variables=variables,
event_variables=evt_variables,
inputs=line_data,
store_multiple_cand_info=True,
)
return make_config(options, [my_filter, my_tuple])
defaults:
wg: B2OC
automatically_configure: no
inform:
- alessandro.bertolin@pd.infn.it
{%- set datasets = [
('11264001', 'MagUp', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-mu100'),
('11264011', 'MagUp', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-mu100'),
('11164404', 'MagUp', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-mu100'),
('11164406', 'MagUp', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-mu100'),
('11264001', 'MagDown', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-md100'),
('11264011', 'MagDown', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-md100'),
('11164404', 'MagDown', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-md100'),
('11164406', 'MagDown', '40', '42', '7', '6', '40', '42', 'dddb-20240427', 'sim10-2024.W40.42-v00.00-md100'),
('11264001', 'MagDown', '37', '39', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W37.39-v00.00-md100'),
('11264011', 'MagDown', '37', '39', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W37.39-v00.00-md100'),
('11164404', 'MagDown', '37', '39', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W37.39-v00.00-md100'),
('11164406', 'MagDown', '37', '39', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W37.39-v00.00-md100'),
('11264001', 'MagUp', '35', '37', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W35.37-v00.00-mu100'),
('11264011', 'MagUp', '35', '37', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W35.37-v00.00-mu100'),
('11164404', 'MagUp', '35', '37', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W35.37-v00.00-mu100'),
('11164406', 'MagUp', '35', '37', '6', '3', '35', '39', 'dddb-20240427', 'sim10-2024.W35.37-v00.00-mu100'),
]%}
{%- for evttype, pol, n1, n2, n3, n4, n5, n6, dddb, conddb in datasets %}
Bd2Dpi_{{ evttype }}_{{ pol }}_{{ n1 }}_{{ n2}}_{{ n3 }}_{{ n4 }}_{{ n5 }}_{{ n6 }}_spruce:
application: Moore/v55r12p3@x86_64_v2-el9-gcc13+detdesc-opt
input:
bk_query: "/MC/2024/Beam6800GeV-2024.W{{ n1 }}.{{ n2 }}-{{ pol }}-Nu{{ n3 }}.{{ n4 }}-25ns-Pythia8/Sim10d/HLT2-2024.W{{ n5 }}.{{ n6 }}/{{ evttype }}/HLT2.DST"
dq_flags:
- OK
n_test_lfns: 1
options:
entrypoint: bd2dpi_run3_spruce.spruce:alg_config
extra_options:
input_raw_format: 0.5
conddb_tag: {{ conddb }}
dddb_tag: {{ dddb }}
input_process: "Hlt2"
process: "Spruce"
input_type: "ROOT"
output_type: "ROOT"
simulation: True
data_type: "Upgrade"
output_manifest_file: spruce.tck.json
scheduler_legacy_mode: False
compression:
algorithm: ZSTD
level: 1
max_buffer_size: 1048576
output: spruce.dst
Bd2Dpi_{{ evttype }}_{{ pol }}_{{ n1 }}_{{ n2}}_{{ n3 }}_{{ n4 }}_{{ n5 }}_{{ n6 }}_DV:
application: DaVinci/v64r10@x86_64_v2-el9-gcc13+detdesc-opt
input:
job_name: Bd2Dpi_{{ evttype }}_{{ pol }}_{{ n1 }}_{{ n2}}_{{ n3 }}_{{ n4 }}_{{ n5 }}_{{ n6 }}_spruce
output: dv.root
options:
entrypoint: bd2dpi_run3_spruce.dv_simple:alg_config
extra_options:
input_raw_format: 0.5
input_type: "ROOT"
simulation: True
data_type: "Upgrade"
conddb_tag: {{ conddb }}
dddb_tag: {{ dddb }}
input_process: "Spruce"
{%- endfor %}
###############################################################################
# (c) Copyright 2023 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. #
###############################################################################
"""
Configures running Spruce via Moore.
"""
from Moore import options, Options, run_moore
from Hlt2Conf.lines.b_to_open_charm import sprucing_lines
#
from RecoConf.global_tools import stateProvider_with_simplified_geom
from RecoConf.reconstruction_objects import reconstruction
import sys
sprucing_lines = {}
from Moore.config import SpruceLine, register_line_builder
from GaudiKernel.SystemOfUnits import MeV
from Hlt2Conf.lines.b_to_open_charm import prefilters
from Hlt2Conf.lines.b_to_open_charm.builders import basic_builder
from Hlt2Conf.lines.b_to_open_charm.builders import d_builder
from Hlt2Conf.lines.b_to_open_charm.builders import b_builder
@register_line_builder(sprucing_lines)
def BdToDmPi_DmToPimPimKp_line(name='SpruceB2OC_BdToDmPi_DmToPimPimKp', prescale=1):
pion = basic_builder.make_tight_pions(pi_pidk_max=None)
d = d_builder.make_dplus_to_kmpippip(pi_pidk_max=None, k_pidk_min=None)
line_alg = b_builder.make_b2x(
particles=[d, pion],
descriptors=['[B0 -> D- pi+]cc'],
am_min=4950 * MeV,
am_max=6000 * MeV,
am_min_vtx=4950 * MeV,
am_max_vtx=6000 * MeV)
return SpruceLine(
name=name,
prescale=prescale,
algs=prefilters.b2oc_prefilters() + [line_alg],
tagging_particles=True)
def make_lines():
lines = [builder() for builder in sprucing_lines.values()]
return lines
def alg_config(options: Options):
public_tools = [stateProvider_with_simplified_geom()]
config = run_moore(options, make_lines, public_tools)
return config
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment