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