Belle II Software light-2406-ragdoll
usingCollections.py
1#!/usr/bin/env python3
2
3
10
11# The VariablesToNtuple (and VariablesToTree) module support collections of variables.
12# You specify a collection instead of a variable name, and the collection will be automatically
13# resolved to a set of variable names
14# the Python module variables.collections defines some default collections, just import it
15#
16# For full documentation please refer to https://software.belle2.org
17# Anything unclear? Ask questions at https://questions.belle2.org
18
19import basf2
20import variables
21import variables.collections as vc # collections of variables
22import modularAnalysis as ma # a shorthand for the analysis tools namespace
23from variables import variables as vm # shorthand name for the VariableManager instance
24
25# You can also define collections yourself
26vm.addCollection('MyCollection', variables.std_vector('daughter(0, kaonID)', 'daughter(1, pionID)'))
27
28mypath = basf2.Path() # create a new path
29
30# add input data and ParticleLoader modules to the path
31ma.inputMdstList([basf2.find_file('analysis/tests/mdst.root')], path=mypath)
32ma.fillParticleLists([('K-', 'kaonID > 0.2'), ('pi+', 'pionID > 0.2')], path=mypath)
33ma.reconstructDecay('D0 -> K- pi+', '1.750 < M < 1.95', path=mypath)
34ma.matchMCTruth('D0', path=mypath)
35
36# Add the VariablesToNtuple module explicitly
37# this will write out one row per candidate in the D0 list
38mypath.add_module('VariablesToNtuple',
39 particleList='D0',
40 variables=vc.kinematics + vc.mc_truth + ['MyCollection'],
41 fileName='CollectionVariables.root')
42
43# you might also like to uncomment the following, and read the help for the
44# convenient wrapper function:
45# print(help(ma.variablesToNtuple))
46
47# process the data
48basf2.process(mypath)
49print(basf2.statistics)
def std_vector(*args)
Definition: __init__.py:135