Tupling from Spruce data

Test for checking the correct processing of Spruce data.

from PyConf.reading import get_particles
from FunTuple import FunctorCollection
from FunTuple import 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):
    line_B0DsK = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST"
    line_B0Dspi = "SpruceB2OC_BdToDsmPi_DsmToKpKmPim"
    bd2dsk_line = get_particles(f"/Event/Spruce/{line_B0DsK}/Particles")
    bd2dspi_line = get_particles(f"/Event/Spruce/{line_B0Dspi}/Particles")

    fields_dsk = {
        "B0": "[B0 -> D_s- K+]CC",
        "Ds": "[B0 -> ^D_s- K+]CC",
        "Kp": "[B0 -> D_s- ^K+]CC",
    }

    fields_dspi = {
        "B0": "[B0 -> D_s- pi+]CC",
        "Ds": "[B0 -> ^D_s- pi+]CC",
        "pip": "[B0 -> D_s- ^pi+]CC",
    }

    variables = FunctorCollection(
        {
            "LOKI_MAXPT": "TRACK_MAX_PT",
            "LOKI_Muonp_PT": "CHILD(PT, 1)",
            "LOKI_Muonm_PT": "CHILD(PT, 2)",
        }
    )

    variables_extra = FunctorCollection(
        {"LOKI_NTRCKS_ABV_THRSHLD": "NINTREE(ISBASIC & (PT > 15*MeV))"}
    )
    variables += variables_extra

    # FunTuple: make functor collection from the imported functor library Kinematics
    variables_all = FC.Kinematics()

    # FunTuple: associate functor collections to field (branch) name
    variables_dsk = {
        "ALL": variables_all,  # adds variables to all fields
        "B0": variables,
        "Ds": variables_extra,
        "Kp": variables_extra,
    }

    variables_dspi = {
        "ALL": variables_all,  # adds variables to all fields
        "B0": variables,
        "Ds": variables_extra,
        "pip": variables_extra,
    }

    loki_preamble = ["TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)"]

    tuple_B0DsK = Funtuple(
        name="B0DsK_Tuple",
        tuple_name="DecayTree",
        fields=fields_dsk,
        variables=variables_dsk,
        loki_preamble=loki_preamble,
        inputs=bd2dsk_line,
    )

    tuple_B0Dspi = Funtuple(
        name="B0Dspi_Tuple",
        tuple_name="DecayTree",
        fields=fields_dspi,
        variables=variables_dspi,
        loki_preamble=loki_preamble,
        inputs=bd2dspi_line,
    )

    evt_prefilter = create_lines_filter(
        name="Hlt2TopoLineFilter", lines=["Hlt2Topo2BodyLineDecision"]
    )
    filter_B0DsK = create_lines_filter(name="HDRFilter_B0DsK", lines=[f"{line_B0DsK}"])
    filter_B0Dspi = create_lines_filter(
        name="HDRFilter_B0Dspi", lines=[f"{line_B0Dspi}"]
    )

    algs = {
        "B0DsK": [evt_prefilter, filter_B0DsK, tuple_B0DsK],
        "B0Dspi": [evt_prefilter, filter_B0Dspi, tuple_B0Dspi],
    }

    return make_config(options, algs)

To run the example:

lbexec DaVinciExamples.tupling.option_davinci_tupling_from_spruce:main $DAVINCIEXAMPLESROOT/example_data/Spruce_all_lines_dst.yaml+$DAVINCIEXAMPLESROOT/example_options/example_tupling_from_spruce.yaml

For reference, these are the options of this example

input_files:
- root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/spruce_all_lines_realtimereco_newPacking_newDst.dst
input_manifest_file: root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/spruce_all_lines_realtime_newPacking_newDst.tck.json
input_type: ROOT
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
conditions_version: master
geometry_version: run3/trunk
lumi: False
write_fsr: False
histo_file: sprucing_histos.root
ntuple_file: sprucing_tuple.root
input_raw_format: 0.5
input_process: Spruce
persistreco_version: 0.0
Hlt2TopoLineFilter: "HLT_PASS('Hlt2Topo2BodyLineDecision')"
ntuple_file: "DV_example_sprucing_ntp.root"
histo_file: "DV_example_sprucing_his.root"
print_freq: 1