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