Isolation variables from persisted Relation Tables using the FunctorsToRelTable algorithm
This examples shows how to retrieve and store in an ntuple isolation variables for HLT2/Spruce lines which persisted relation tables using the FunctorsToRelTable algorithm.
from PyConf.reading import get_particles, _get_unpacked
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
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, 1.8],
"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 getIsolationVariables(
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:
for angle in coneangles:
table = _get_unpacked(
"P2InfoRelations",
f"/Event/HLT2/{line}/{name}_DeltaR_{str(angle).replace('.', '')}_{isolation_type}/P2InfoRelations",
)
isolation += FC.RelTablesIsolation(
table,
isolation_type,
str(angle),
variables=coneVariables,
)
if vertexIsoVariables:
table = _get_unpacked(
"P2InfoRelations",
f"/Event/HLT2/{line}/{name}_VertexIsolation/P2InfoRelations",
)
isolation += FC.RelTablesIsolation(
table, "", "", variables=vertexIsoVariables
)
return isolation
isolation_variables = getIsolationVariables(**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_reltablesfromHLT2_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