Belle II Software  release-08-01-10
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 
14 import basf2
15 from modularAnalysis import inputMdst
16 from modularAnalysis import fillParticleList
17 from modularAnalysis import variablesToNtuple
18 from variables.utils import add_collection
19 # This import statement is put here for the use of lists of mc_gen_topo variables
20 from variables.MCGenTopo import mc_gen_topo
21 
22 # create path
23 my_path = basf2.create_path()
24 
25 # load input ROOT file
26 inputMdst(basf2.find_file('JPsi2ee_e2egamma.root', 'examples', False), path=my_path)
27 
28 # create and fill ParticleList
29 fillParticleList('e+', 'nTracks>=2 and abs(d0)<2 and abs(z0)<4 and clusterE>2', path=my_path)
30 
31 # define variables
32 var_e = ['M', 'px', 'py', 'pz', 'E']
33 add_collection(var_e, 'var_e')
34 var_evt = ['nTracks']
35 add_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.
39 add_collection(mc_gen_topo(), 'mc_gen_topo')
40 add_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
45 variablesToNtuple('e+', var_e, 'var_e_1', 'MCGenTopoVariables.root', path=my_path)
46 # with a particle list, regular variables, using collection of variables
47 variablesToNtuple('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
49 variablesToNtuple('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
51 variablesToNtuple('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
53 variablesToNtuple('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
55 variablesToNtuple('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
57 variablesToNtuple('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
59 variablesToNtuple('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
61 variablesToNtuple('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
63 variablesToNtuple('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
66 variablesToNtuple('', var_evt, 'var_evt_1', 'MCGenTopoVariables.root', path=my_path)
67 # with no particle list, regular variables, using collection of variables
68 variablesToNtuple('', ['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
70 variablesToNtuple('', 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
72 variablesToNtuple('', ['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
74 variablesToNtuple('', 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
76 variablesToNtuple('', ['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
78 variablesToNtuple('', 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
80 variablesToNtuple('', ['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
82 variablesToNtuple('', 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
84 variablesToNtuple('', ['var_evt', 'mc_gen_topo_120'], 'evt_120_2', 'MCGenTopoVariables.root', path=my_path)
85 
86 # Process the events
87 basf2.process(my_path)
88 
89 # print out the summary
90 print(basf2.statistics)