Belle II Software development
stdV0s.py
1#!/usr/bin/env python3
2
3
10
11import b2bii
12from basf2 import B2ERROR
13import modularAnalysis as ma
14from stdCharged import stdPi, stdPr
15import vertex
16
17
18def stdKshorts(
19 prioritiseV0=True,
20 fitter="TreeFit",
21 path=None,
22 updateAllDaughters=False,
23 writeOut=False,
24 addSuffix=False,
25):
26 """
27 Load a combined list of the Kshorts list from V0 objects merged with
28 a list of particles combined using the analysis ParticleCombiner module.
29
30 The ParticleList is named ``K_S0:merged`` by default. If ``addSuffix`` is set to True,
31 then a suffix of form ``_<fitter>`` is added depending on the chosen fitter.
32 A vertex fit is performed and only candidates with an invariant mass in the
33 range :math:`0.450 < M < 0.550~GeV` after the vertex fit,
34 and for which the vertex fit did not fail, are kept.
35
36 The vertex fitter can be selected among ``TreeFit``, ``KFit``, and ``Rave``.
37
38 Parameters:
39 prioritiseV0 (bool): should the V0 mdst objects be prioritised when merging?
40 fitter (str): vertex fitter name, valid options are ``TreeFit``, ``KFit``, and ``Rave``.
41 path (basf2.Path): the path to load the modules
42 updateAllDaughters (bool): see the ``updateAllDaughters`` parameter of `vertex.treeFit`
43 or the ``daughtersUpdate`` parameter of `vertex.kFit` / `vertex.raveFit`.
44
45 .. warning:: The momenta of the daughters are updated only if ``updateAllDaughters`` is set
46 to ``True`` (i.e. **not** by default). Some variables, e.g. `daughterAngle`, will only
47 return meaningful results if the daughters momenta are updated.
48
49 This happens because variables like `daughterAngle` assume the direction of the
50 daughers momenta *at the Ks vertex* to be provided, while non-updated daughters will
51 provide their momenta direction at the point-of-closest-approach (POCA) to the beam axis.
52
53 writeOut (bool): whether RootOutput module should save the created ParticleList
54 addSuffix (bool): whether to add a suffix of form ``_<fitter>`` to the ParticleList name
55 depending on the chosen fitter
56 """
57 suffix = ""
58 if addSuffix:
59 suffix = f"_{fitter}"
60 # Fill one list from V0
61 ma.fillParticleList(
62 f"K_S0:V0_ToFit{suffix} -> pi+ pi-", "", writeOut=writeOut, path=path
63 )
64 # Perform vertex fit and apply tighter mass window
65 if fitter == "TreeFit":
67 f"K_S0:V0_ToFit{suffix}",
68 conf_level=0.0,
69 path=path,
70 updateAllDaughters=updateAllDaughters,
71 )
72 elif fitter == "KFit":
74 f"K_S0:V0_ToFit{suffix}",
75 conf_level=0.0,
76 path=path,
77 daughtersUpdate=updateAllDaughters,
78 )
79 elif fitter == "Rave":
81 f"K_S0:V0_ToFit{suffix}",
82 conf_level=0.0,
83 path=path,
84 silence_warning=True,
85 daughtersUpdate=updateAllDaughters,
86 )
87 else:
88 B2ERROR(
89 "Valid fitter options for Kshorts are 'TreeFit', 'KFit', and 'Rave'. However, the latter is not recommended."
90 )
91 ma.applyCuts(f"K_S0:V0_ToFit{suffix}", "0.450 < M < 0.550", path=path)
92 # Reconstruct a second list
93 stdPi("all", path=path, writeOut=writeOut) # no quality cuts
94 ma.reconstructDecay(
95 f"K_S0:RD{suffix} -> pi+:all pi-:all",
96 "0.3 < M < 0.7",
97 1,
98 writeOut=writeOut,
99 path=path,
100 )
101 # Again perform vertex fit and apply tighter mass window
102 if fitter == "TreeFit":
104 f"K_S0:RD{suffix}",
105 conf_level=0.0,
106 path=path,
107 updateAllDaughters=updateAllDaughters,
108 )
109 elif fitter == "KFit":
111 f"K_S0:RD{suffix}",
112 conf_level=0.0,
113 path=path,
114 daughtersUpdate=updateAllDaughters,
115 )
116 elif fitter == "Rave":
118 f"K_S0:RD{suffix}",
119 conf_level=0.0,
120 path=path,
121 silence_warning=True,
122 daughtersUpdate=updateAllDaughters,
123 )
124 ma.applyCuts(f"K_S0:RD{suffix}", "0.450 < M < 0.550", path=path)
125 # Create merged list based on provided priority
126 ma.mergeListsWithBestDuplicate(
127 f"K_S0:merged{suffix}",
128 [f"K_S0:V0_ToFit{suffix}", f"K_S0:RD{suffix}"],
129 variable="particleSource",
130 preferLowest=prioritiseV0,
131 path=path,
132 )
133
134
135def goodBelleKshort(path):
136 """
137 Load the Belle goodKshort list. Creates a ParticleList named
138 ``K_S0:legacyGoodKS``. A vertex fit is performed and only candidates that
139 satisfy the :b2:var:`goodBelleKshort` criteria, with an invariant mass in the range
140 :math:`0.468 < M < 0.528~GeV` after the vertex fit, and for which the vertex fit did not fail, are kept.
141
142 Parameters:
143 path (basf2.Path): the path to load the modules
144 """
145 if b2bii.isB2BII():
146 ma.cutAndCopyList(
147 "K_S0:legacyGoodKS", "K_S0:mdst", "0.3 < M < 0.7", writeOut=True, path=path
148 )
149 else:
150 ma.fillParticleList(
151 "K_S0:legacyGoodKS -> pi+ pi-", "0.3 < M < 0.7", writeOut=True, path=path
152 )
153 vertex.kFit("K_S0:legacyGoodKS", conf_level=0.0, path=path)
154 ma.applyCuts(
155 "K_S0:legacyGoodKS", "0.468 < M < 0.528 and goodBelleKshort==1", path=path
156 )
157
158
159def scaleErrorKshorts(
160 prioritiseV0=True,
161 fitter="TreeFit",
162 scaleFactors_V0=[1.125927, 1.058803, 1.205928, 1.066734, 1.047513],
163 scaleFactorsNoPXD_V0=[1.125927, 1.058803, 1.205928, 1.066734, 1.047513],
164 d0Resolution_V0=[0.001174, 0.000779],
165 z0Resolution_V0=[0.001350, 0.000583],
166 d0MomThr_V0=0.500000,
167 z0MomThr_V0=0.00000,
168 scaleFactors_RD=[1.149631, 1.085547, 1.151704, 1.096434, 1.086659],
169 scaleFactorsNoPXD_RD=[1.149631, 1.085547, 1.151704, 1.096434, 1.086659],
170 d0Resolution_RD=[0.00115328, 0.00134704],
171 z0Resolution_RD=[0.00124327, 0.0013272],
172 d0MomThr_RD=0.500000,
173 z0MomThr_RD=0.500000,
174 addSuffix=False,
175 path=None,
176):
177 """
178 Reconstruct K_S0 applying helix error correction to K_S0 daughters given by ``modularAnalysis.scaleError``.
179 The ParticleList is named ``K_S0:scaled`` by default. If ``addSuffix`` is set to True,
180 then a suffix of form ``_<fitter>`` is added.
181
182 Considering the difference of multiple scattering through the beam pipe,
183 different parameter sets are used for K_S0 decaying outside/inside the beam pipe (``K_S0:V0/RD``).
184
185 Only for TDCPV analysis.
186
187 @param prioritiseV0 If True K_S0 from V0 object is prioritised over RD when merged.
188 @param fitter Vertex fitter option. Choose from ``TreeFit``, ``KFit`` and ``Rave``.
189 @param scaleFactors_V0 List of five constants to be multiplied to each of helix errors (for tracks with a PXD hit)
190 @param scaleFactorsNoPXD_V0 List of five constants to be multiplied to each of helix errors (for tracks without a PXD hit)
191 @param d0Resolution_V0 List of two parameters, (a [cm], b [cm/(GeV/c)]),
192 defining d0 best resolution as sqrt{ a**2 + (b / (p*beta*sinTheta**1.5))**2 }
193 @param z0Resolution_V0 List of two parameters, (a [cm], b [cm/(GeV/c)]),
194 defining z0 best resolution as sqrt{ a**2 + (b / (p*beta*sinTheta**2.5))**2 }
195 @param d0MomThr_V0 d0 best resolution is kept constant below this momentum
196 @param z0MomThr_V0 z0 best resolution is kept constant below this momentum
197 @param scaleFactors_RD List of five constants to be multiplied to each of helix errors (for tracks with a PXD hit)
198 @param scaleFactorsNoPXD_RD List of five constants to be multiplied to each of helix errors (for tracks without a PXD hit)
199 @param d0Resolution_RD List of two parameters, (a [cm], b [cm/(GeV/c)]),
200 defining d0 best resolution as sqrt{ a**2 + (b / (p*beta*sinTheta**1.5))**2 }
201 @param z0Resolution_RD List of two parameters, (a [cm], b [cm/(GeV/c)]),
202 defining z0 best resolution as sqrt{ a**2 + (b / (p*beta*sinTheta**2.5))**2 }
203 @param d0MomThr_RD d0 best resolution is kept constant below this momentum
204 @param z0MomThr_RD z0 best resolution is kept constant below this momentum
205 @param addSuffix Whether to add a suffix of form ``_<fitter>`` to the ParticleList name
206 depending on the chosen fitter
207
208 """
209 from basf2 import register_module
210
211 suffix = ""
212 if addSuffix:
213 suffix = f"_{fitter}"
214
215 # Load K_S0 from V0 and apply helix error correction to V0 daughters
216 ma.fillParticleList(f"K_S0:V0{suffix} -> pi+ pi-", "", True, path=path)
217 scaler_V0 = register_module("HelixErrorScaler")
218 scaler_V0.set_name("ScaleError_" + f"K_S0:V0{suffix}")
219 scaler_V0.param("inputListName", f"K_S0:V0{suffix}")
220 scaler_V0.param("outputListName", f"K_S0:V0_scaled{suffix}")
221 scaler_V0.param("scaleFactors_PXD", scaleFactors_V0)
222 scaler_V0.param("scaleFactors_noPXD", scaleFactorsNoPXD_V0)
223 scaler_V0.param("d0ResolutionParameters", d0Resolution_V0)
224 scaler_V0.param("z0ResolutionParameters", z0Resolution_V0)
225 scaler_V0.param("d0MomentumThreshold", d0MomThr_V0)
226 scaler_V0.param("z0MomentumThreshold", z0MomThr_V0)
227 path.add_module(scaler_V0)
228
229 # Perform vertex fit and apply tighter mass window
230 if fitter == "TreeFit":
231 vertex.treeFit(f"K_S0:V0_scaled{suffix}", conf_level=0.0, path=path)
232 elif fitter == "KFit":
233 vertex.kFit(f"K_S0:V0_scaled{suffix}", conf_level=0.0, path=path)
234 elif fitter == "Rave":
236 f"K_S0:V0_scaled{suffix}", conf_level=0.0, path=path, silence_warning=True
237 )
238 else:
239 B2ERROR(
240 "Valid fitter options for Kshorts are 'TreeFit', 'KFit', and 'Rave'. However, the latter is not recommended."
241 )
242 ma.applyCuts(f"K_S0:V0_scaled{suffix}", "0.450 < M < 0.550", path=path)
243
244 # Reconstruct a second list
245 stdPi("all", path=path)
246 ma.scaleError(
247 "pi+:scaled",
248 "pi+:all",
249 scaleFactors=scaleFactors_RD,
250 scaleFactorsNoPXD=scaleFactorsNoPXD_RD,
251 d0Resolution=d0Resolution_RD,
252 z0Resolution=z0Resolution_RD,
253 d0MomThr=d0MomThr_RD,
254 z0MomThr=z0MomThr_RD,
255 path=path,
256 )
257
258 ma.reconstructDecay(
259 f"K_S0:RD_scaled{suffix} -> pi+:scaled pi-:scaled", "0.3 < M < 0.7", 1, True, path=path
260 )
261 # Again perform vertex fit and apply tighter mass window
262 if fitter == "TreeFit":
263 vertex.treeFit(f"K_S0:RD_scaled{suffix}", conf_level=0.0, path=path)
264 elif fitter == "KFit":
265 vertex.kFit(f"K_S0:RD_scaled{suffix}", conf_level=0.0, path=path)
266 elif fitter == "Rave":
268 f"K_S0:RD_scaled{suffix}", conf_level=0.0, path=path, silence_warning=True
269 )
270 ma.applyCuts(f"K_S0:RD_scaled{suffix}", "0.450 < M < 0.550", path=path)
271 # Create merged list based on provided priority
272 ma.mergeListsWithBestDuplicate(
273 f"K_S0:scaled{suffix}",
274 [f"K_S0:V0_scaled{suffix}", f"K_S0:RD_scaled{suffix}"],
275 variable="particleSource",
276 preferLowest=prioritiseV0,
277 path=path,
278 )
279
280
281def stdLambdas(
282 prioritiseV0=True,
283 fitter="TreeFit",
284 path=None,
285 updateAllDaughters=False,
286 writeOut=False,
287 addSuffix=False,
288):
289 """
290 Load a combined list of the Lambda list from V0 objects merged with
291 a list of particles combined using the analysis ParticleCombiner module.
292
293 The ParticleList is named ``Lambda0:merged`` by default. If ``addSuffix`` is set to True,
294 then a suffix of form ``_<fitter>`` is added depending on the chosen fitter.
295 A vertex fit is performed and only candidates with an invariant mass in the
296 range :math:`1.10 < M < 1.13~GeV` after the vertex fit,
297 and for which the vertex fit did not fail, are kept.
298
299 The vertex fitter can be selected among ``TreeFit``, ``KFit``, and ``Rave``.
300
301 Parameters:
302 prioritiseV0 (bool): should the V0 mdst objects be prioritised when merging?
303 fitter (str): vertex fitter name, valid options are ``TreeFit``, ``KFit``, and ``Rave``.
304 path (basf2.Path): the path to load the modules
305 updateAllDaughters (bool): see the ``updateAllDaughters`` parameter of `vertex.treeFit`
306 or the ``daughtersUpdate`` parameter of `vertex.kFit` / `vertex.raveFit`.
307
308 .. warning:: The momenta of the daughters are updated only if ``updateAllDaughters`` is set
309 to ``True`` (i.e. **not** by default). Some variables, e.g. `daughterAngle`, will only
310 return meaningful results if the daughters momenta are updated.
311
312 This happens because variables like `daughterAngle` assume the direction of the
313 daughers momenta *at the Lambda vertex* to be provided, while non-updated daughters
314 will provide their momenta direction at the point-of-closest-approach (POCA) to the
315 beam axis.
316
317 writeOut (bool): whether RootOutput module should save the created ParticleList
318 addSuffix (bool): whether to add a suffix of form ``_<fitter>`` to the ParticleList name
319 depending on the chosen fitter
320 """
321 suffix = ""
322 if addSuffix:
323 suffix = f"_{fitter}"
324 # Fill one list from V0
325 ma.fillParticleList(
326 f"Lambda0:V0_ToFit{suffix} -> p+ pi-", "", writeOut=writeOut, path=path
327 )
328 # Perform vertex fit and apply tighter mass window
329 if fitter == "TreeFit":
331 f"Lambda0:V0_ToFit{suffix}",
332 conf_level=0.0,
333 path=path,
334 updateAllDaughters=updateAllDaughters,
335 )
336 elif fitter == "KFit":
338 f"Lambda0:V0_ToFit{suffix}",
339 conf_level=0.0,
340 path=path,
341 daughtersUpdate=updateAllDaughters,
342 )
343 elif fitter == "Rave":
345 f"Lambda0:V0_ToFit{suffix}",
346 conf_level=0.0,
347 path=path,
348 silence_warning=True,
349 daughtersUpdate=updateAllDaughters,
350 )
351 else:
352 B2ERROR(
353 "Valid fitter options for Lambdas are 'TreeFit', 'KFit', and 'Rave'. However, the latter is not recommended."
354 )
355 ma.applyCuts(f"Lambda0:V0_ToFit{suffix}", "1.10 < M < 1.13", path=path)
356 # Find V0 duplicate with better vertex fit quality
357 ma.markDuplicate(f"Lambda0:V0_ToFit{suffix}", False, path=path)
358 ma.applyCuts(f"Lambda0:V0_ToFit{suffix}", "extraInfo(highQualityVertex)", path=path)
359 # Reconstruct a second list
360 stdPi("all", path=path, writeOut=writeOut) # no quality cuts
361 stdPr("all", path=path, writeOut=writeOut) # no quality cuts
362 ma.reconstructDecay(
363 f"Lambda0:RD{suffix} -> p+:all pi-:all",
364 "0.9 < M < 1.3",
365 1,
366 writeOut=writeOut,
367 path=path,
368 )
369 # Again perform vertex fit and apply tighter mass window
370 if fitter == "TreeFit":
372 f"Lambda0:RD{suffix}",
373 conf_level=0.0,
374 path=path,
375 updateAllDaughters=updateAllDaughters,
376 )
377 elif fitter == "KFit":
379 f"Lambda0:RD{suffix}",
380 conf_level=0.0,
381 path=path,
382 daughtersUpdate=updateAllDaughters,
383 )
384 elif fitter == "Rave":
386 f"Lambda0:RD{suffix}",
387 conf_level=0.0,
388 path=path,
389 silence_warning=True,
390 daughtersUpdate=updateAllDaughters,
391 )
392 ma.applyCuts(f"Lambda0:RD{suffix}", "1.10 < M < 1.13", path=path)
393 # Find RD duplicate with better vertex fit quality
394 ma.markDuplicate(f"Lambda0:RD{suffix}", False, path=path)
395 ma.applyCuts(f"Lambda0:RD{suffix}", "extraInfo(highQualityVertex)", path=path)
396 ma.mergeListsWithBestDuplicate(
397 f"Lambda0:merged{suffix}",
398 [f"Lambda0:V0_ToFit{suffix}", f"Lambda0:RD{suffix}"],
399 variable="particleSource",
400 preferLowest=prioritiseV0,
401 path=path,
402 )
isB2BII()
Definition b2bii.py:14
treeFit(list_name, conf_level=0.001, massConstraint=[], ipConstraint=False, updateAllDaughters=False, massConstraintDecayString='', massConstraintMassValues=[], customOriginConstraint=False, customOriginVertex=[0.001, 0, 0.0116], customOriginCovariance=[0.0048, 0, 0, 0, 0.003567, 0, 0, 0, 0.0400], originDimension=3, treatAsInvisible='', ignoreFromVertexFit='', path=None)
Definition vertex.py:237
raveFit(list_name, conf_level, fit_type='vertex', decay_string='', constraint='', daughtersUpdate=False, path=None, silence_warning=False)
Definition vertex.py:168
kFit(list_name, conf_level, fit_type='vertex', constraint='', daughtersUpdate=False, decay_string='', massConstraint=[], recoilMass=0, smearing=0, path=None)
Definition vertex.py:126