Belle II Software light-2406-ragdoll
usingMCGenTopo.py
1#!/usr/bin/env python3
2
3
10
11# This example demonstrates the detailed usage of the parameter lists of variables returned by mc_gen_topo(n).
12# For details on mc_gen_topo(n), please refer to its definition in analysis/scripts/variables/MCGenTopo.py.
13
14import basf2
15from modularAnalysis import inputMdst
16from modularAnalysis import fillParticleList
17from modularAnalysis import variablesToNtuple
18from variables.utils import add_collection
19# This import statement is put here for the use of lists of mc_gen_topo variables
20from variables.MCGenTopo import mc_gen_topo
21
22# create path
23my_path = basf2.create_path()
24
25# load input ROOT file
26inputMdst(basf2.find_file('JPsi2ee_e2egamma.root', 'examples', False), path=my_path)
27
28# create and fill ParticleList
29fillParticleList('e+', 'nTracks>=2 and abs(d0)<2 and abs(z0)<4 and clusterE>2', path=my_path)
30
31# define variables
32var_e = ['M', 'px', 'py', 'pz', 'E']
33add_collection(var_e, 'var_e')
34var_evt = ['nTracks']
35add_collection(var_evt, 'var_evt')
36# Collections associated with mc_gen_topo(n) are not defined by default.
37# If you want to use them, just define them with add_collection as the two instances above.
38# Here are the two instances that will be used in the following part of the script.
39add_collection(mc_gen_topo(), 'mc_gen_topo')
40add_collection(mc_gen_topo(120), 'mc_gen_topo_120')
41
42# output variables to ntuples with variablesToNtuple
43
44# with a particle list, regular variables, using list of variables
45variablesToNtuple('e+', var_e, 'var_e_1', 'MCGenTopoVariables.root', path=my_path)
46# with a particle list, regular variables, using collection of variables
47variablesToNtuple('e+', ['var_e'], 'var_e_2', 'MCGenTopoVariables.root', path=my_path)
48# with a particle list, mc_gen_topo variables with default parameter value 200, using list of variables
49variablesToNtuple('e+', mc_gen_topo(), 'mc_gen_topo_e_1', 'MCGenTopoVariables.root', path=my_path)
50# with a particle list, mc_gen_topo variables with default parameter value 200, using collection of variables
51variablesToNtuple('e+', ['mc_gen_topo'], 'mc_gen_topo_e_2', 'MCGenTopoVariables.root', path=my_path)
52# with a particle list, mc_gen_topo variables with specified parameter value 120, using list of variables
53variablesToNtuple('e+', mc_gen_topo(120), 'mc_gen_topo_e_120_1', 'MCGenTopoVariables.root', path=my_path)
54# with a particle list, mc_gen_topo variables with specified parameter value 120, using collection of variables
55variablesToNtuple('e+', ['mc_gen_topo_120'], 'mc_gen_topo_e_120_2', 'MCGenTopoVariables.root', path=my_path)
56# with a particle list, regular variables + mc_gen_topo variables with default parameter value 200, using list of variables
57variablesToNtuple('e+', var_e + mc_gen_topo(), 'e_1', 'MCGenTopoVariables.root', path=my_path)
58# with a particle list, regular variables + mc_gen_topo variables with default parameter value 200, using collection of variables
59variablesToNtuple('e+', ['var_e', 'mc_gen_topo'], 'e_2', 'MCGenTopoVariables.root', path=my_path)
60# with a particle list, regular variables + mc_gen_topo variables with specified parameter value 120, using list of variables
61variablesToNtuple('e+', var_e + mc_gen_topo(120), 'e_120_1', 'MCGenTopoVariables.root', path=my_path)
62# with a particle list, regular variables + mc_gen_topo variables with specified parameter value 120, using collection of variables
63variablesToNtuple('e+', ['var_e', 'mc_gen_topo_120'], 'e_120_2', 'MCGenTopoVariables.root', path=my_path)
64
65# with no particle list, regular variables, using list of variables
66variablesToNtuple('', var_evt, 'var_evt_1', 'MCGenTopoVariables.root', path=my_path)
67# with no particle list, regular variables, using collection of variables
68variablesToNtuple('', ['var_evt'], 'var_evt_2', 'MCGenTopoVariables.root', path=my_path)
69# with no particle list, mc_gen_topo variables with default parameter value 200, using list of variables
70variablesToNtuple('', mc_gen_topo(), 'mc_gen_topo_evt_1', 'MCGenTopoVariables.root', path=my_path)
71# with no particle list, mc_gen_topo variables with default parameter value 200, using collection of variables
72variablesToNtuple('', ['mc_gen_topo'], 'mc_gen_topo_evt_2', 'MCGenTopoVariables.root', path=my_path)
73# with no particle list, mc_gen_topo variables with specified parameter value 120, using list of variables
74variablesToNtuple('', mc_gen_topo(120), 'mc_gen_topo_evt_120_1', 'MCGenTopoVariables.root', path=my_path)
75# with no particle list, mc_gen_topo variables with specified parameter value 120, using collection of variables
76variablesToNtuple('', ['mc_gen_topo_120'], 'mc_gen_topo_evt_120_2', 'MCGenTopoVariables.root', path=my_path)
77# with no particle list, regular variables + mc_gen_topo variables with default parameter value 200, using list of variables
78variablesToNtuple('', var_evt + mc_gen_topo(), 'evt_1', 'MCGenTopoVariables.root', path=my_path)
79# with no particle list, regular variables + mc_gen_topo variables with default parameter value 200, using collection of variables
80variablesToNtuple('', ['var_evt', 'mc_gen_topo'], 'evt_2', 'MCGenTopoVariables.root', path=my_path)
81# with no particle list, regular variables + mc_gen_topo variables with specified parameter value 120, using list of variables
82variablesToNtuple('', var_evt + mc_gen_topo(120), 'evt_120_1', 'MCGenTopoVariables.root', path=my_path)
83# with no particle list, regular variables + mc_gen_topo variables with specified parameter value 120, using collection of variables
84variablesToNtuple('', ['var_evt', 'mc_gen_topo_120'], 'evt_120_2', 'MCGenTopoVariables.root', path=my_path)
85
86# Process the events
87basf2.process(my_path)
88
89# print out the summary
90print(basf2.statistics)