Belle II Software light-2406-ragdoll
B2A202-LoadReconstructedParticles.py
1#!/usr/bin/env python3
2
3
10
11
25
26import basf2 as b2
27import modularAnalysis as ma
28import variables.collections as vc
29import variables.utils as vu
30from stdV0s import stdKshorts
31from stdPi0s import stdPi0s
32from stdKlongs import stdKlongs
33
34# create path
35my_path = b2.create_path()
36
37# load input ROOT file
38ma.inputMdst(filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples', False),
39 path=my_path)
40
41# print contents of the DataStore before loading Particles
42ma.printDataStore(path=my_path)
43
44# create and fill gamma/e/mu/pi/K/p/n ParticleLists
45# second argument are the selection criteria: '' means no cut, take all
46#
47# note that you can give any name to your lists e.g. 'gamma:mycandidates',
48# except for the name 'all' which is the only name that is reserved for lists
49# with no cuts
50ma.fillParticleList(decayString='gamma:all', cut='', path=my_path)
51ma.fillParticleList(decayString='e-:all', cut='', path=my_path)
52ma.fillParticleList(decayString='mu-:all', cut='', path=my_path)
53ma.fillParticleList(decayString='pi-:all', cut='', path=my_path)
54ma.fillParticleList(decayString='K-:all', cut='', path=my_path)
55ma.fillParticleList(decayString='anti-p-:all', cut='', path=my_path)
56ma.fillParticleList(decayString='anti-n0:all', cut='', path=my_path)
57
58# alternatively, we can create and fill final state Particle lists only
59# with candidates that pass certain PID requirements
60ma.fillParticleList(decayString='gamma:highE', cut='E > 1.0', path=my_path)
61ma.fillParticleList(decayString='e+:good', cut='electronID > 0.1', path=my_path)
62ma.fillParticleList(decayString='mu+:good', cut='muonID > 0.1', path=my_path)
63ma.fillParticleList(decayString='pi+:good', cut='protonID > 0.1', path=my_path)
64ma.fillParticleList(decayString='K+:good', cut='kaonID > 0.1', path=my_path)
65ma.fillParticleList(decayString='p+:good', cut='protonID > 0.1', path=my_path)
66
67# another possibility is to use default functions
68# for example stdKshorts() from stdV0s.py that:
69# - takes all V0 candidates, performs vertex fit, and fills 'K_S0:merged' ParticleList
70# (-> for more details about V0s have a look at B2A203-LoadV0s.py)
71# or for example stdPi0s() from stdPi0s.py:
72stdKshorts(prioritiseV0=True, path=my_path)
73stdPi0s(listtype='eff10_May2020Fit', path=my_path)
74stdPi0s(listtype='eff20_May2020Fit', path=my_path)
75stdPi0s(listtype='eff30_May2020Fit', path=my_path)
76stdPi0s(listtype='eff40_May2020Fit', path=my_path)
77stdPi0s(listtype='eff50_May2020Fit', path=my_path)
78stdPi0s(listtype='eff60_May2020Fit', path=my_path)
79stdKlongs(listtype='allklm', path=my_path) # only 'allklm' is recommended at the moment
80
81# print contents of the DataStore after loading Particles
82ma.printDataStore(path=my_path)
83
84# print out the contents of each ParticleList
85ma.printList('gamma:all', False, path=my_path)
86ma.printList('gamma:highE', False, path=my_path)
87ma.printList('e-:all', False, path=my_path)
88ma.printList('e-:good', False, path=my_path)
89ma.printList('mu-:all', False, path=my_path)
90ma.printList('mu-:good', False, path=my_path)
91ma.printList('pi-:all', False, path=my_path)
92ma.printList('pi-:good', False, path=my_path)
93ma.printList('K-:all', False, path=my_path)
94ma.printList('K-:good', False, path=my_path)
95ma.printList('anti-p-:all', False, path=my_path)
96ma.printList('anti-p-:good', False, path=my_path)
97ma.printList('K_S0:merged', False, path=my_path)
98ma.printList('pi0:eff40_May2020Fit', False, path=my_path)
99ma.printList('K_L0:allklm', False, path=my_path)
100ma.printList('n0:all', False, path=my_path)
101
102
103# Select variables that we want to store to ntuple
104# You can either use preselected variable groups from variableCollections
105# or use your own lists. Both options are shown here.
106# For more information on the VariableManager, VariableCollections, etc.,
107# please refer to the dedicated VariableManager examples.
108
109# Note: vc.<collection> is a list (of variables); multiple lists are
110# concatenated with the + operator.
111
112charged_particle_variables = vc.reco_stats + \
113 vc.kinematics + \
114 vc.track + \
115 vc.track_hits + \
116 vc.pid + \
117 vc.mc_truth + \
118 vc.mc_kinematics
119
120gamma_variables = vc.kinematics + \
121 vc.mc_kinematics + \
122 vc.cluster
123
124K0s_variables = vc.kinematics + \
125 vc.inv_mass + \
126 vc.vertex + \
127 vc.mc_vertex + \
128 vc.pid + \
129 vc.mc_truth + \
130 ['dr', 'dz', 'isSignal', 'chiProb']
131
132pi0_variables = vc.mc_truth + \
133 vc.kinematics + \
134 ['extraInfo(BDT)', 'decayAngle(0)']
135
136K0l_variables = vc.kinematics + \
137 vc.mc_kinematics + \
138 vc.klm_cluster
139
140n0_variables = K0l_variables + \
141 ['isFromECL', 'isFromKLM']
142
143# Saving variables to ntuple
144output_file = 'B2A202-LoadReconstructedParticles.root'
145ma.variablesToNtuple(decayString='pi+:all',
146 variables=charged_particle_variables,
147 treename='pion',
148 filename=output_file,
149 path=my_path)
150ma.variablesToNtuple(decayString='K+:all',
151 variables=charged_particle_variables,
152 treename='kaon',
153 filename=output_file,
154 path=my_path)
155ma.variablesToNtuple(decayString='e+:all',
156 variables=charged_particle_variables,
157 treename='elec',
158 filename=output_file,
159 path=my_path)
160ma.variablesToNtuple(decayString='mu+:all',
161 variables=charged_particle_variables,
162 treename='muon',
163 filename=output_file,
164 path=my_path)
165ma.variablesToNtuple(decayString='gamma:all',
166 variables=gamma_variables,
167 treename='phot',
168 filename=output_file,
169 path=my_path)
170ma.variablesToNtuple(decayString='K_L0:allklm',
171 variables=K0l_variables,
172 treename='klong',
173 filename=output_file,
174 path=my_path)
175ma.variablesToNtuple(decayString='n0:all',
176 variables=n0_variables,
177 treename='neutron',
178 filename=output_file,
179 path=my_path)
180
181# Note here, that since we want to get info about gammas from pi0,
182# we convert names of the variables from the gamma list in the way that they will
183# correspond to given gammas.
184ma.variablesToNtuple(decayString='pi0:eff40_May2020Fit',
185 variables=pi0_variables + vu.create_aliases_for_selected(gamma_variables, 'pi0 -> ^gamma ^gamma'),
186 filename=output_file,
187 treename='pi0',
188 path=my_path)
189
190# Here for pions from K0s we do the same thing, but here we add custom aliases
191# (see ntuples to see the difference)
192ma.variablesToNtuple(decayString='K_S0:merged',
193 variables=K0s_variables +
194 vu.create_aliases_for_selected(charged_particle_variables, 'K_S0 -> ^pi+ pi-', 'pip') +
195 vu.create_aliases_for_selected(charged_particle_variables, 'K_S0 -> pi+ ^pi-', 'pim'),
196 filename=output_file,
197 treename='kshort',
198 path=my_path)
199
200# Process the events
201b2.process(my_path)
202
203# print out the summary
204print(b2.statistics)