Advanced DaVinci Job on MC

This example shows how to:

  1. reconstruct and select two detached opposite-charge muons

  2. add a tuple of the selected \(J/\psi\) candidates.

  3. reconstruct and select two detached opposite-charge pions

  4. add a tuple of the selected \(K^0_S\) candidates.

import Functors as F
from Hlt2Conf.standard_particles import make_detached_mumu, make_KsDD
from PyConf.control_flow import CompositeNode, NodeLogic
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
import FunTuple.functorcollections as FC
from DaVinci import Options, make_config


def main(options: Options):
    # Prepare the node with the selection
    dimuons = make_detached_mumu()
    kshorts = make_KsDD()
    """
    Tuple observables related to Jpsi -> mu+ mu-
    """
    # FunTuple: make fields (branches) to tuple (NB: adding a special keyword 'ALL' with throw an error)
    fields = {}
    fields["Jpsi"] = "J/psi(1S) -> mu+ mu-"
    fields["MuPlus"] = "J/psi(1S) -> ^mu+ mu-"

    # FunTuple: make collection of functors for Jpsi
    variables_jpsi = FunctorCollection(
        {
            "PT": F.PT,
            "PX": F.PX,
            "PY": F.PY,
            "PZ": F.PZ,
            "ENERGY": F.ENERGY,
            "FourMom_P": F.FOURMOMENTUM,
            "MAXPT": "TRACK_MAX_PT",
        }
    )
    # FunTuple: extend the collection given a dictionary
    # In case of common entries (i.e. common key irrespective of functor code) the program warns user and overwrites the previous entry
    variables_jpsi.update(
        {"PT": F.PT}
    )  # OR like dictionaries can do variables_jpsi['LOKI_PT'] = 'PT'
    # FunTuple: Remove from collection given the list of variable names
    variables_jpsi.pop(["PT", "ENERGY"])
    # FunTuple: Join two functor
    # If entries already exist user is warned about picking entries from the base instance.
    variables_extra = FunctorCollection({"ENERGY": F.ENERGY, "P": F.P})
    variables_jpsi += variables_extra
    # FunTuple: Can also subtract two FunctorCollection to get unique entries like below
    # variables_unique = variables_jpsi - variables_extra
    print("Variables in Jpsi field", variables_jpsi)

    # FunTuple: make functor collection from the imported functor library Kinematics
    variables_all = FC.Kinematics()
    print("Variables in ALL field", variables_all)
    print("Variables in MuPlus field", variables_extra)

    # FunTuple: associate functor collections to field (branch) name
    variables = {}
    variables["ALL"] = variables_all  # adds variables to all fields
    variables["Jpsi"] = variables_jpsi
    variables["MuPlus"] = variables_extra

    # FunTuple: define list of preambles for loki
    loki_preamble = ["TRACK_MAX_PT = MAXTREE(ISBASIC & HASTRACK, PT, -1)"]

    # FunTuple: Configure Funtuple algorithm
    tuple_dimuons = Funtuple(
        name="DimuonsTuple",
        tuple_name="DecayTree",
        fields=fields,
        variables=variables,
        loki_preamble=loki_preamble,
        inputs=dimuons,
    )
    """
    Tuple observables related to KS0 -> 2pi
    """
    # FunTuple: As above make fields (branches)
    fields_KS = {}
    fields_KS["KS"] = "KS0 -> pi+ pi-"
    # FunTuple: Associate the functor collections to field names
    variables_KS = {}
    variables_KS["ALL"] = variables_all
    variables_KS["KS"] = variables_jpsi
    # FunTuple: Configure Funtuple algorithm
    tuple_kshorts = Funtuple(
        name="KsTuple",
        tuple_name="DecayTree",
        fields=fields_KS,
        variables=variables_KS,
        loki_preamble=loki_preamble,
        inputs=kshorts,
    )

    return make_config(
        options,
        [
            CompositeNode(
                "Tupling",
                children=[tuple_dimuons, tuple_kshorts],
                combine_logic=NodeLogic.NONLAZY_AND,
            )
        ],
    )

To run the example:

lbexec DaVinciExamples.tupling.advanced_run_mc:main $DAVINCIEXAMPLESROOT/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml+$DAVINCIEXAMPLESROOT/example_options/example_tupling_advanced_run_mc.yaml

For reference, these are the options of this example

input_files: root://eoslhcb.cern.ch//eos/lhcb/grid/prod/lhcb/MC/Upgrade/LDST/00076720/0000/00076720_000000{01,02,04,27,36,37,38,39,43,51,57,68}_1.ldst
input_type: ROOT
simulation: true
conddb_tag: sim-20171127-vc-md100
dddb_tag: dddb-20171126
conditions_version: master
geometry_version: run3/trunk
input_process: Brunel
persistreco_version: 0.0
lumi: False
write_fsr: False
evt_max: 10
ntuple_file: DV-example-tupling-advanced-ntp.root
histo_file: DV-example-tupling-advanced-his.root
input_raw_format: 4.3