Belle II Software light-2411-aldebaran
kinfit.py
1#!/usr/bin/env python3
2
3
10
11from basf2 import register_module
12
13
14def fitKinematic4C(
15 list_name,
16 fitterEngine='NewFitterGSL',
17 constraint='HardBeam',
18 daughtersUpdate=True,
19 addUnmeasuredPhoton=False,
20 variablePrefix="",
21 path=None,
22):
23 """
24 Perform a 4C momentum constraint kinematic fit for particles in the given ParticleList.
25
26 @param list_name name of the input ParticleList
27 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
28 @param constraint HardBeam or RecoilMass
29 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
30 @param addUnmeasuredPhoton add one unmeasured photon (uses up three constraints)
31 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
32 @param path modules are added to this path
33 """
34
35 orca = register_module('ParticleKinematicFitter')
36 orca.set_name('ParticleKinematicFitter_' + list_name)
37 orca.param('debugFitter', False)
38 orca.param('orcaTracer', 'None')
39 orca.param('orcaFitterEngine', fitterEngine)
40 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
41 orca.param('listName', list_name)
42 orca.param('updateDaughters', daughtersUpdate)
43 orca.param('addUnmeasuredPhoton', addUnmeasuredPhoton)
44 orca.param('variablePrefix', variablePrefix)
45 path.add_module(orca)
46
47
48def UnmeasuredfitKinematic1C(
49 list_name,
50 fitterEngine='NewFitterGSL',
51 constraint='HardBeam',
52 daughtersUpdate=True,
53 variablePrefix="",
54 path=None,
55):
56 """
57 Perform 1C momentum constraint kinematic fit with one unmeasured photon for particles in the given ParticleList.
58
59 @param list_name name of the input ParticleList
60 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
61 @param constraint HardBeam or RecoilMass
62 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
63 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
64 @param path modules are added to this path
65 """
66
67 orca = register_module('ParticleKinematicFitter')
68 orca.set_name('ParticleKinematicFitter_' + list_name)
69 orca.param('debugFitter', False)
70 orca.param('orcaTracer', 'None')
71 orca.param('orcaFitterEngine', fitterEngine)
72 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
73 orca.param('listName', list_name)
74 orca.param('updateDaughters', daughtersUpdate)
75 orca.param('addUnmeasuredPhoton', True)
76 orca.param('variablePrefix', variablePrefix)
77 path.add_module(orca)
78
79
80def fitKinematic3C(
81 list_name,
82 fitterEngine='NewFitterGSL',
83 constraint='HardBeam',
84 daughtersUpdate=True,
85 addUnmeasuredPhoton=False,
86 add3CPhoton=True,
87 variablePrefix="",
88 path=None,
89):
90 """
91 Perform 3C momentum constraint kinematic fit with one photon with unmeasured energy for particles
92 in the given ParticleList, the first daughter should be the energy unmeasured Photon.
93
94 @param list_name name of the input ParticleList
95 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
96 @param constraint HardBeam or RecoilMass
97 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
98 @param addUnmeasuredPhoton add one unmeasured photon (uses up three constraints)
99 @param add3CPhoton add one photon with unmeasured energy (uses up a constraint)
100 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
101 @param path modules are added to this path
102 """
103
104 orca = register_module('ParticleKinematicFitter')
105 orca.set_name('ParticleKinematicFitter_' + list_name)
106 orca.param('debugFitter', False)
107 orca.param('orcaTracer', 'None')
108 orca.param('orcaFitterEngine', fitterEngine)
109 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
110 orca.param('listName', list_name)
111 orca.param('updateDaughters', daughtersUpdate)
112 orca.param('addUnmeasuredPhoton', addUnmeasuredPhoton)
113 orca.param('add3CPhoton', add3CPhoton)
114 orca.param('variablePrefix', variablePrefix)
115 path.add_module(orca)
116
117
118def fitKinematic2C(
119 list_name,
120 fitterEngine='NewFitterGSL',
121 constraint='HardBeam',
122 daughtersUpdate=True,
123 addUnmeasuredPhotonAlongBeam="",
124 variablePrefix="",
125 path=None,
126):
127 """
128 Perform 2C momentum constraint kinematic fit. The photon with unmeasured energy and theta
129 has to be the first particle in the decay string. If 'addUnmeasuredPhotonAlongBeam' is set to
130 'HER' or 'LER', both phi and theta (treated as measured) of this photon are then used. Concurrently,
131 an additional unmeasured photon along HER/LER will be taken into account in the fit, which means
132 the momentum is only constrained in the plane perpendicular to one of the beams.
133
134 @param list_name name of the input ParticleList
135 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
136 @param constraint HardBeam or RecoilMass
137 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
138 @param addUnmeasuredPhotonAlongBeam add an unmeasured photon along beam if 'HER' or 'LER' is set
139 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
140 @param path modules are added to this path
141 """
142
143 # Parameter check
144 assert addUnmeasuredPhotonAlongBeam in ["", "LER", "HER"]
145
146 orca = register_module('ParticleKinematicFitter')
147 orca.set_name('ParticleKinematicFitter_' + list_name)
148 orca.param('debugFitter', False)
149 orca.param('orcaTracer', 'None')
150 orca.param('orcaFitterEngine', fitterEngine)
151 orca.param('orcaConstraint', constraint) # beam parameters automatically taken from database
152 orca.param('listName', list_name)
153 orca.param('updateDaughters', daughtersUpdate)
154 orca.param('add3CPhoton', True)
155 if addUnmeasuredPhotonAlongBeam == "":
156 orca.param('liftPhotonTheta', True)
157 else:
158 orca.param('addUnmeasuredPhoton', True)
159 if addUnmeasuredPhotonAlongBeam == "HER":
160 orca.param('fixUnmeasuredToHER', True)
161 else: # should be LER
162 orca.param('fixUnmeasuredToLER', True)
163 orca.param('variablePrefix', variablePrefix)
164 path.add_module(orca)
165
166
167def MassfitKinematic1CRecoil(
168 list_name,
169 recoilMass,
170 fitterEngine='NewFitterGSL',
171 constraint='RecoilMass',
172 daughtersUpdate=True,
173 variablePrefix="",
174 path=None,
175):
176 """
177 Perform recoil mass kinematic fit for particles in the given ParticleList.
178
179 @param list_name name of the input ParticleList
180 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
181 @param constraint HardBeam or RecoilMass
182 @param recoilMass RecoilMass (GeV)
183 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
184 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
185 @param path modules are added to this path
186 """
187
188 orca = register_module('ParticleKinematicFitter')
189 orca.set_name('ParticleKinematicFitter_' + list_name)
190 orca.param('debugFitter', False)
191 orca.param('orcaTracer', 'None')
192 orca.param('orcaFitterEngine', fitterEngine)
193 orca.param('orcaConstraint', constraint)
194 orca.param('recoilMass', recoilMass)
195 orca.param('listName', list_name)
196 orca.param('updateDaughters', daughtersUpdate)
197 orca.param('addUnmeasuredPhoton', False)
198 orca.param('variablePrefix', variablePrefix)
199 path.add_module(orca)
200
201
202def MassfitKinematic1C(
203 list_name,
204 invMass,
205 fitterEngine='NewFitterGSL',
206 constraint='Mass',
207 daughtersUpdate=True,
208 variablePrefix="",
209 path=None,
210):
211 """
212 Perform recoil mass kinematic fit for particles in the given ParticleList.
213
214 @param list_name name of the input ParticleList
215 @param fitterEngine which fitter engine to use? 'NewFitterGSL' or 'OPALFitterGSL'
216 @param constraint HardBeam or RecoilMass or Mass
217 @param invMass Invariant Mass (GeV)
218 @param daughtersUpdate make copy of the daughters and update them after the vertex fit
219 @param variablePrefix prepended to fit variables stored in extra info. Required if ParticleKinematicFitter is run multiple times
220 @param path modules are added to this path
221 """
222
223 orca = register_module('ParticleKinematicFitter')
224 orca.set_name('ParticleKinematicFitter_' + list_name)
225 orca.param('debugFitter', False)
226 orca.param('orcaTracer', 'None')
227 orca.param('orcaFitterEngine', fitterEngine)
228 orca.param('orcaConstraint', constraint)
229 orca.param('invMass', invMass)
230 orca.param('listName', list_name)
231 orca.param('updateDaughters', daughtersUpdate)
232 orca.param('addUnmeasuredPhoton', False)
233 orca.param('variablePrefix', variablePrefix)
234 path.add_module(orca)
235
236
237if __name__ == '__main__':
238 from basf2.utils import pretty_print_module
239 pretty_print_module(__name__, "kinfit")