Belle II Software development
kinfit.py
1#!/usr/bin/env python3
2
3
10
11from basf2 import register_module
12
13import pdg
14
15
16def fitKinematic4C(
17 list_name,
18 fitterEngine='NewFitterGSL',
19 constraint='HardBeam',
20 daughtersUpdate=True,
21 addUnmeasuredPhoton=False,
22 variablePrefix="",
23 decayStringForDirectionOnlyParticles="",
24 decayStringForAlternateMassParticles="",
25 alternateMassHypos=[],
26 decayStringForNeutronVsAntiNeutron="",
27 path=None,
28):
29 """
30 Perform a 4C momentum constraint kinematic fit for particles in the given ParticleList.
31
32 @param list_name name of the input ParticleList
33 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
34 @param constraint HardBeam or RecoilMass
35 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
36 @param addUnmeasuredPhoton add one unmeasured photon (uses up three constraints)
37 @param variablePrefix prepended to fit variables stored in extra info. Required if
38 ParticleKinematicFitter is run multiple times
39 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
40 to use only direction information in the fit
41 @param decayStringForAlternateMassParticles DecayString specifying the particles
42 where an alternate mass hypothesis is used
43 @param alternateMassHypos list of pdg values (or particle names) for particles where
44 different mass hypothesis is used in the fit
45 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
46 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
47 is flipped from default given in alternateMassHypos
48 @param path modules are added to this path
49 """
50
51 orca = register_module('ParticleKinematicFitter')
52 orca.set_name('ParticleKinematicFitter_' + list_name)
53 orca.param('debugFitter', False)
54 orca.param('orcaTracer', 'None')
55 orca.param('orcaFitterEngine', fitterEngine)
56 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
57 orca.param('listName', list_name)
58 orca.param('updateDaughters', daughtersUpdate)
59 orca.param('addUnmeasuredPhoton', addUnmeasuredPhoton)
60 orca.param('variablePrefix', variablePrefix)
61 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
62 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
63 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
64 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
65 path.add_module(orca)
66
67
68def UnmeasuredfitKinematic1C(
69 list_name,
70 fitterEngine='NewFitterGSL',
71 constraint='HardBeam',
72 daughtersUpdate=True,
73 variablePrefix="",
74 decayStringForDirectionOnlyParticles="",
75 decayStringForAlternateMassParticles="",
76 alternateMassHypos=[],
77 decayStringForNeutronVsAntiNeutron="",
78 path=None,
79):
80 """
81 Perform 1C momentum constraint kinematic fit with one unmeasured photon for particles in the given ParticleList.
82
83 @param list_name name of the input ParticleList
84 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
85 @param constraint HardBeam or RecoilMass
86 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
87 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
88 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
89 to use only direction information in the fit
90 @param decayStringForAlternateMassParticles DecayString specifying the particles
91 where an alternate mass hypothesis is used
92 @param alternateMassHypos list of pdg values (or particle names) for particles where
93 different mass hypothesis is used in the fit
94 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
95 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
96 is flipped from default given in alternateMassHypos
97 @param path modules are added to this path
98 """
99
100 orca = register_module('ParticleKinematicFitter')
101 orca.set_name('ParticleKinematicFitter_' + list_name)
102 orca.param('debugFitter', False)
103 orca.param('orcaTracer', 'None')
104 orca.param('orcaFitterEngine', fitterEngine)
105 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
106 orca.param('listName', list_name)
107 orca.param('updateDaughters', daughtersUpdate)
108 orca.param('addUnmeasuredPhoton', True)
109 orca.param('variablePrefix', variablePrefix)
110 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
111 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
112 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
113 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
114 path.add_module(orca)
115
116
117def fitKinematic3C(
118 list_name,
119 fitterEngine='NewFitterGSL',
120 constraint='HardBeam',
121 daughtersUpdate=True,
122 addUnmeasuredPhoton=False,
123 add3CPhoton=True,
124 variablePrefix="",
125 decayStringForDirectionOnlyParticles="",
126 decayStringForAlternateMassParticles="",
127 alternateMassHypos=[],
128 decayStringForNeutronVsAntiNeutron="",
129 path=None,
130):
131 """
132 Perform 3C momentum constraint kinematic fit with one photon with unmeasured energy for particles
133 in the given ParticleList, the first daughter should be the energy unmeasured Photon.
134
135 @param list_name name of the input ParticleList
136 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
137 @param constraint HardBeam or RecoilMass
138 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
139 @param addUnmeasuredPhoton add one unmeasured photon (uses up three constraints)
140 @param add3CPhoton add one photon with unmeasured energy (uses up a constraint)
141 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
142 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
143 to use only direction information in the fit
144 @param decayStringForAlternateMassParticles DecayString specifying the particles
145 where an alternate mass hypothesis is used
146 @param alternateMassHypos list of pdg values (or particle names) for particles where
147 different mass hypothesis is used in the fit
148 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
149 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
150 is flipped from default given in alternateMassHypos
151 @param path modules are added to this path
152 """
153
154 orca = register_module('ParticleKinematicFitter')
155 orca.set_name('ParticleKinematicFitter_' + list_name)
156 orca.param('debugFitter', False)
157 orca.param('orcaTracer', 'None')
158 orca.param('orcaFitterEngine', fitterEngine)
159 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
160 orca.param('listName', list_name)
161 orca.param('updateDaughters', daughtersUpdate)
162 orca.param('addUnmeasuredPhoton', addUnmeasuredPhoton)
163 orca.param('add3CPhoton', add3CPhoton)
164 orca.param('variablePrefix', variablePrefix)
165 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
166 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
167 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
168 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
169 path.add_module(orca)
170
171
172def fitKinematic2C(
173 list_name,
174 fitterEngine='NewFitterGSL',
175 constraint='HardBeam',
176 daughtersUpdate=True,
177 addUnmeasuredPhotonAlongBeam="",
178 variablePrefix="",
179 decayStringForDirectionOnlyParticles="",
180 decayStringForAlternateMassParticles="",
181 alternateMassHypos=[],
182 decayStringForNeutronVsAntiNeutron="",
183 path=None,
184):
185 """
186 Perform 2C momentum constraint kinematic fit. The photon with unmeasured energy and theta
187 has to be the first particle in the decay string. If 'addUnmeasuredPhotonAlongBeam' is set to
188 'HER' or 'LER', both phi and theta (treated as measured) of this photon are then used. Concurrently,
189 an additional unmeasured photon along HER/LER will be taken into account in the fit, which means
190 the momentum is only constrained in the plane perpendicular to one of the beams.
191
192 @param list_name name of the input ParticleList
193 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
194 @param constraint HardBeam or RecoilMass
195 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
196 @param addUnmeasuredPhotonAlongBeam add an unmeasured photon along beam if 'HER' or 'LER' is set
197 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
198 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
199 to use only direction information in the fit
200 @param decayStringForAlternateMassParticles DecayString specifying the particles
201 where an alternate mass hypothesis is used
202 @param alternateMassHypos list of pdg values (or particle names) for particles where
203 different mass hypothesis is used in the fit
204 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
205 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
206 is flipped from default given in alternateMassHypos
207 @param path modules are added to this path
208 """
209
210 # Parameter check
211 assert addUnmeasuredPhotonAlongBeam in ["", "LER", "HER"]
212
213 orca = register_module('ParticleKinematicFitter')
214 orca.set_name('ParticleKinematicFitter_' + list_name)
215 orca.param('debugFitter', False)
216 orca.param('orcaTracer', 'None')
217 orca.param('orcaFitterEngine', fitterEngine)
218 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
219 orca.param('listName', list_name)
220 orca.param('updateDaughters', daughtersUpdate)
221 orca.param('add3CPhoton', True)
222 if addUnmeasuredPhotonAlongBeam == "":
223 orca.param('liftPhotonTheta', True)
224 else:
225 orca.param('addUnmeasuredPhoton', True)
226 if addUnmeasuredPhotonAlongBeam == "HER":
227 orca.param('fixUnmeasuredToHER', True)
228 else: # should be LER
229 orca.param('fixUnmeasuredToLER', True)
230 orca.param('variablePrefix', variablePrefix)
231 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
232 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
233 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
234 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
235 path.add_module(orca)
236
237
238def MassfitKinematic1CRecoil(
239 list_name,
240 recoilMass,
241 fitterEngine='NewFitterGSL',
242 constraint='RecoilMass',
243 daughtersUpdate=True,
244 variablePrefix="",
245 decayStringForDirectionOnlyParticles="",
246 decayStringForAlternateMassParticles="",
247 alternateMassHypos=[],
248 decayStringForNeutronVsAntiNeutron="",
249 path=None,
250):
251 """
252 Perform recoil mass kinematic fit for particles in the given ParticleList.
253
254 @param list_name name of the input ParticleList
255 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
256 @param constraint HardBeam or RecoilMass
257 @param recoilMass RecoilMass (GeV)
258 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
259 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
260 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
261 to use only direction information in the fit
262 @param decayStringForAlternateMassParticles DecayString specifying the particles
263 where an alternate mass hypothesis is used
264 @param alternateMassHypos list of pdg values (or particle names) for particles where
265 different mass hypothesis is used in the fit
266 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
267 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
268 is flipped from default given in alternateMassHypos
269 @param path modules are added to this path
270 """
271
272 orca = register_module('ParticleKinematicFitter')
273 orca.set_name('ParticleKinematicFitter_' + list_name)
274 orca.param('debugFitter', False)
275 orca.param('orcaTracer', 'None')
276 orca.param('orcaFitterEngine', fitterEngine)
277 orca.param('orcaConstraint', constraint)
278 orca.param('recoilMass', recoilMass)
279 orca.param('listName', list_name)
280 orca.param('updateDaughters', daughtersUpdate)
281 orca.param('addUnmeasuredPhoton', False)
282 orca.param('variablePrefix', variablePrefix)
283 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
284 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
285 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
286 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
287 path.add_module(orca)
288
289
290def MassfitKinematic1C(
291 list_name,
292 invMass,
293 fitterEngine='NewFitterGSL',
294 constraint='Mass',
295 daughtersUpdate=True,
296 variablePrefix="",
297 decayStringForDirectionOnlyParticles="",
298 decayStringForAlternateMassParticles="",
299 alternateMassHypos=[],
300 decayStringForNeutronVsAntiNeutron="",
301 path=None,
302):
303 """
304 Perform recoil mass kinematic fit for particles in the given ParticleList.
305
306 @param list_name name of the input ParticleList
307 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
308 @param constraint HardBeam or RecoilMass or Mass
309 @param invMass Invariant Mass (GeV)
310 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
311 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
312 @param decayStringForDirectionOnlyParticles DecayString specifying the particles
313 to use only direction information in the fit
314 @param decayStringForAlternateMassParticles DecayString specifying the particles
315 where an alternate mass hypothesis is used
316 @param alternateMassHypos list of pdg values (or particle names) for particles where
317 different mass hypothesis is used in the fit
318 @param decayStringForNeutronVsAntiNeutron DecayString specifying the charged particle
319 used to tag whether n or nbar. When tag particle has negative charge, PDG sign of n/nbar
320 is flipped from default given in alternateMassHypos
321 @param path modules are added to this path
322 """
323
324 orca = register_module('ParticleKinematicFitter')
325 orca.set_name('ParticleKinematicFitter_' + list_name)
326 orca.param('debugFitter', False)
327 orca.param('orcaTracer', 'None')
328 orca.param('orcaFitterEngine', fitterEngine)
329 orca.param('orcaConstraint', constraint)
330 orca.param('invMass', invMass)
331 orca.param('listName', list_name)
332 orca.param('updateDaughters', daughtersUpdate)
333 orca.param('addUnmeasuredPhoton', False)
334 orca.param('variablePrefix', variablePrefix)
335 orca.param('decayStringForDirectionOnlyParticles', decayStringForDirectionOnlyParticles)
336 orca.param('decayStringForAlternateMassParticles', decayStringForAlternateMassParticles)
337 orca.param('decayStringForNeutronVsAntiNeutron', decayStringForNeutronVsAntiNeutron)
338 orca.param('alternateMassHypos', pdg.from_names(alternateMassHypos))
339 path.add_module(orca)
340
341
342if __name__ == '__main__':
343 from basf2.utils import pretty_print_module
344 pretty_print_module(__name__, "kinfit")
def from_names(names)
Definition: pdg.py:74