Isolation variables from persisted extra particles using the FunctorsToRelTable algorithm
This examples shows how to retrieve and store in an ntuple isolation variables for HLT2/Spruce lines which persisted extra particles for isolation. The variables are calculated using the using the FunctorsToRelTable algorithm.
from PyConf.reading import get_particles
import Functors as F
from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple
import FunTuple.functorcollections as FC
from DaVinci.algorithms import create_lines_filter
from DaVinci import Options, make_config
from PyConf.Algorithms import (
LHCb__Phys__RelationTables__FunctorsToRelTable as FunctorsToRelTable,
)
def main(options: Options):
# Customise line & decay descriptor
#####################################################################
line = "Hlt2BnoC_BdsToPhiPhi"
branches = {
"B": "[B_s0 -> (phi(1020) -> K+ K- ) (phi(1020) -> K+ K-)]CC",
}
#####################################################################
# Copy reltables_kwargs information from your HLT2 line persistency settings
#####################################################################
reltables_kwargs = {
"name": "B0",
"coneangles": [1.0],
"vertexIsoVariables": ["SMALLEST_REF_ENDVERTEX_IPCHI2"],
"LongTrackIso": True,
"NeutralIso": True,
"coneVariables": [
"CONE_MULT",
"CONE_PX",
"CONE_PY",
"CONE_PZ",
"CONE_ASYM_PT",
"CONE_DELTA_PHI",
],
}
#####################################################################
line_data = get_particles(f"/Event/HLT2/{line}/Particles")
def getIsolationVariablesFromParts(
line_data,
name,
coneangles,
vertexIsoVariables=[],
LongTrackIso=False,
NeutralIso=False,
PiZerosIso=False,
UpstreamTrackIso=False,
DownstreamTrackIso=False,
TTrackIso=False,
coneVariables=[],
):
isolation_types = []
if LongTrackIso:
isolation_types += ["LongTrackIsolation"]
if NeutralIso:
isolation_types += ["NeutralIsolation"]
if PiZerosIso:
isolation_types += ["PiZerosIsolation"]
if UpstreamTrackIso:
isolation_types += ["UpstreamTrackIsolation"]
if DownstreamTrackIso:
isolation_types += ["DownstreamTrackIsolation"]
if TTrackIso:
isolation_types += ["TTrackIsolation"]
isolation = FunctorCollection()
if coneVariables:
for isolation_type in isolation_types:
extra_parts = get_particles(
f"/Event/HLT2/{line}/{name}_{isolation_type}/Particles"
)
for angle in coneangles:
table = FunctorsToRelTable(
InputCandidates=line_data,
InputOtherTracks=extra_parts,
Cut=(~F.FIND_IN_TREE & (F.SQRT @ F.DR2 < angle)),
Variables=coneVariables,
).OutputLocation
isolation += FC.RelTablesIsolation(
table,
isolation_type,
str(angle),
variables=coneVariables,
)
if vertexIsoVariables:
extra_parts = get_particles(
f"/Event/HLT2/{line}/{name}_LongTrackIsolation/Particles"
)
table = FunctorsToRelTable(
InputCandidates=line_data,
InputOtherTracks=extra_parts,
Cut=(~F.FIND_IN_TREE),
Variables=vertexIsoVariables,
).OutputLocation
isolation += FC.RelTablesIsolation(
table, "", "", variables=vertexIsoVariables
)
return isolation
isolation_variables = getIsolationVariablesFromParts(line_data, **reltables_kwargs)
variables = {"B": isolation_variables}
my_filter = create_lines_filter(name="HDRFilter_hlt2line", lines=[f"{line}"])
my_tuple = Funtuple(
name="Tuple",
tuple_name="DecayTree",
fields=branches,
variables=variables,
inputs=line_data,
)
return make_config(options, [my_filter, my_tuple])
To run the example:
lbexec DaVinciExamples.tupling.option_davinci_tupling_reltablesfromparticles_isolation_variables:main $DAVINCIEXAMPLESROOT/example_data/bdstophiphi_isolation.yaml
For reference, these are the options of this example
testfiledb_key: hlt2_bds2phiphi_isolation_opt
input_manifest_file: "root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/bds2phiphi_example.tck.json"
evt_max: -1
ntuple_file: "DV_example_isolation_reltables.root"
print_freq: 20
input_process: Hlt2
input_raw_format : 0.5
lumi: False
write_fsr: False
persistreco_version: 0.0