Belle II Software development
stdPi0s.py
1#!/usr/bin/env python3
2
3
10
11import modularAnalysis as ma
12from stdPhotons import stdPhotons
13from vertex import kFit
14from basf2 import B2WARNING
15
16
17def stdPi0s(
18 listtype="eff60_May2020",
19 path=None,
20 beamBackgroundMVAWeight="",
21 fakePhotonMVAWeight="",
22 biasCorrectionTable="",
23 writeOut=True
24 ):
25 """
26 Function to prepare one of several standardized types of pi0 lists.
27
28 The following lists are **deprecated** and will be removed at the end of 2026:
29
30 - 'all' using gamma:all, no cuts
31 - 'eff10_May2020' gamma:pi0eff10_May2020, mass range selection, 10% pi0 efficiency list, optimized in May 2020
32 - 'eff20_May2020' gamma:pi0eff20_May2020, mass range selection, 20% pi0 efficiency list, optimized in May 2020
33 - 'eff30_May2020' gamma:pi0eff30_May2020, mass range selection, 30% pi0 efficiency list, optimized in May 2020
34 - 'eff40_May2020' gamma:pi0eff40_May2020, mass range selection, 40% pi0 efficiency list, optimized in May 2020
35 - 'eff50_May2020' gamma:pi0eff50_May2020, mass range selection, 50% pi0 efficiency list, optimized in May 2020
36 - 'eff60_May2020' gamma:pi0eff60_May2020, mass range selection, 60% pi0 efficiency list, optimized in May 2020
37
38 You can also append "Fit" to the effXX listtype which will run a mass fit and
39 require that the fit did not fail. For example: "pi0:eff50_May2020Fit" is the 50%
40 efficiency list plus a not-failing mass fit.
41 These Fit variants are also deprecated, fits with mass constraint can be performed manually when necessary.
42
43 .. deprecated:: light-2604-jellyfish
44 All list types in this function are deprecated and will be removed at the end of 2026.
45 Please use ``reconstructDecay`` directly with an appropriate selection optimised for your analysis.
46 Refer to the :ref:`b2help-recommendation` tool
47 (web version: `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_)
48 for guidance. To provide feedback on the removal, see
49 `work item #11641 <https://gitlab.desy.de/belle2/software/basf2/-/work_items/11641>`_.
50
51 Parameters:
52 listtype (str): name of standard list
53 path (basf2.Path): modules are added to this path
54 beamBackgroundMVAWeight (str): type of weight file for beam background MVA; if empty, beam background MVA will not be used
55
56 .. tip::
57 Please refer to the
58 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
59 for information on the beam background MVA.
60
61 fakePhotonMVAWeight (str): type of weight file for fake photon MVA; if empty, fake photon MVA will not be used
62
63 .. tip::
64 Please refer to the
65 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
66 for information on the fake photon MVA.
67
68 biasCorrectionTable (str): correction table for the photon energy bias correction (should only be applied to data)
69
70 .. tip::
71 Please refer to the
72 `Performance Recommendations <https://belle2.pages.desy.de/performance/recommendations/>`_
73 for information on the names of available correction tables.
74
75 writeOut (bool): whether RootOutput module should save the created ParticleList
76
77 """
78
79 _deprecated_pi0_lists = {
80 'all', 'allFit',
81 'eff10_May2020', 'eff20_May2020', 'eff30_May2020',
82 'eff40_May2020', 'eff50_May2020', 'eff60_May2020',
83 'eff50_May2020_nomcmatch', 'eff60_May2020_nomcmatch',
84 'eff10_May2020Fit', 'eff20_May2020Fit', 'eff30_May2020Fit',
85 'eff40_May2020Fit', 'eff50_May2020Fit', 'eff60_May2020Fit',
86 }
87 if listtype in _deprecated_pi0_lists:
88 B2WARNING(
89 f"The standard pi0 list 'pi0:{listtype}' is deprecated "
90 "and will be removed at the end of 2026. "
91 "Please use reconstructDecay directly with an appropriate selection optimised for your analysis. "
92 "To provide feedback on the removal, see "
93 "https://gitlab.desy.de/belle2/software/basf2/-/work_items/11641"
94 )
95
96 if listtype == 'all':
97 stdPhotons('all', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
98 ma.reconstructDecay('pi0:all -> gamma:all gamma:all', '', 1, writeOut=writeOut, path=path)
99 ma.matchMCTruth('pi0:all', path)
100 elif 'eff10_May2020' == listtype:
101 stdPhotons('pi0eff10_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
102 ma.reconstructDecay('pi0:eff10_May2020 -> gamma:pi0eff10_May2020 gamma:pi0eff10_May2020',
103 '0.127<InvM<0.139 and -0.9<daughterDiffOf(0,1,phi)<0.9 and daughterAngle(0,1)<0.8',
104 1,
105 writeOut=writeOut,
106 path=path)
107 ma.matchMCTruth('pi0:eff10_May2020', path)
108 elif 'eff20_May2020' == listtype:
109 stdPhotons('pi0eff20_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
110 ma.reconstructDecay('pi0:eff20_May2020 -> gamma:pi0eff20_May2020 gamma:pi0eff20_May2020',
111 '0.121<InvM<0.142 and -1.0<daughterDiffOf(0,1,phi)<1.0 and daughterAngle(0,1)<0.9',
112 1,
113 writeOut=writeOut,
114 path=path)
115 ma.matchMCTruth('pi0:eff20_May2020', path)
116 elif 'eff30_May2020' == listtype:
117 stdPhotons('pi0eff30_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
118 ma.reconstructDecay('pi0:eff30_May2020 -> gamma:pi0eff30_May2020 gamma:pi0eff30_May2020',
119 '0.120<InvM<0.145 and -1.5<daughterDiffOf(0,1,phi)<1.5 and daughterAngle(0,1)<1.4',
120 1,
121 writeOut=writeOut,
122 path=path)
123 ma.matchMCTruth('pi0:eff30_May2020', path)
124 elif 'eff40_May2020' == listtype:
125 stdPhotons('pi0eff40_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
126 ma.reconstructDecay('pi0:eff40_May2020 -> gamma:pi0eff40_May2020 gamma:pi0eff40_May2020',
127 '0.120<InvM<0.145', 1, writeOut=writeOut, path=path)
128 ma.matchMCTruth('pi0:eff40_May2020', path)
129 elif 'eff50_May2020_nomcmatch' == listtype:
130 stdPhotons('pi0eff50_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
131 ma.reconstructDecay(
132 'pi0:eff50_May2020_nomcmatch -> gamma:pi0eff50_May2020 gamma:pi0eff50_May2020',
133 '0.105<InvM<0.150',
134 1,
135 writeOut=writeOut,
136 path=path)
137 elif 'eff50_May2020' == listtype:
138 stdPi0s('eff50_May2020_nomcmatch', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
139 ma.cutAndCopyList('pi0:eff50_May2020', 'pi0:eff50_May2020_nomcmatch', '', writeOut=writeOut, path=path)
140 ma.matchMCTruth('pi0:eff50_May2020', path)
141 elif 'eff60_May2020_nomcmatch' == listtype:
142 stdPhotons('pi0eff60_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight, biasCorrectionTable)
143 ma.reconstructDecay(
144 'pi0:eff60_May2020_nomcmatch -> gamma:pi0eff60_May2020 gamma:pi0eff60_May2020',
145 '0.03<InvM',
146 1,
147 writeOut=writeOut,
148 path=path)
149 elif 'eff60_May2020' == listtype:
150 stdPi0s('eff60_May2020_nomcmatch', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
151 ma.cutAndCopyList('pi0:eff60_May2020', 'pi0:eff60_May2020_nomcmatch', '', writeOut=writeOut, path=path)
152 ma.matchMCTruth('pi0:eff60_May2020', path)
153
154 # skim list(s)
155 elif listtype == 'skim':
156 stdPi0s('eff50_May2020_nomcmatch', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
157 ma.cutAndCopyList('pi0:skim', 'pi0:eff50_May2020_nomcmatch', '', writeOut=writeOut, path=path)
158 kFit('pi0:skim', 0.0, 'mass', path=path)
159 elif listtype == 'SkimHighEff':
160 stdPi0s('eff60_May2020_nomcmatch', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
161 ma.cutAndCopyList('pi0:SkimHighEff', 'pi0:eff60_May2020_nomcmatch', '', writeOut=writeOut, path=path)
162 kFit('pi0:SkimHighEff', 0.0, 'mass', path=path)
163
164 # same lists with, but with mass constraints fits
165 elif listtype == 'allFit':
166 stdPi0s('all', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
167 ma.cutAndCopyList('pi0:allFit', 'pi0:all', '', writeOut=writeOut, path=path)
168 kFit('pi0:allFit', 0.0, 'mass', path=path)
169 elif listtype == 'eff10_May2020Fit':
170 stdPi0s('eff10_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
171 ma.cutAndCopyList('pi0:eff10_May2020Fit', 'pi0:eff10_May2020', '', writeOut=writeOut, path=path)
172 kFit('pi0:eff10_May2020Fit', 0.0, 'mass', path=path)
173 elif listtype == 'eff20_May2020Fit':
174 stdPi0s('eff20_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
175 ma.cutAndCopyList('pi0:eff20_May2020Fit', 'pi0:eff20_May2020', '', writeOut=writeOut, path=path)
176 kFit('pi0:eff20_May2020Fit', 0.0, 'mass', path=path)
177 elif listtype == 'eff30_May2020Fit':
178 stdPi0s('eff30_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
179 ma.cutAndCopyList('pi0:eff30_May2020Fit', 'pi0:eff30_May2020', '', writeOut=writeOut, path=path)
180 kFit('pi0:eff30_May2020Fit', 0.0, 'mass', path=path)
181 elif listtype == 'eff40_May2020Fit':
182 stdPi0s('eff40_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
183 ma.cutAndCopyList('pi0:eff40_May2020Fit', 'pi0:eff40_May2020', '', writeOut=writeOut, path=path)
184 kFit('pi0:eff40_May2020Fit', 0.0, 'mass', path=path)
185 elif listtype == 'eff50_May2020Fit':
186 stdPi0s('eff50_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
187 ma.cutAndCopyList('pi0:eff50_May2020Fit', 'pi0:eff50_May2020', '', writeOut=writeOut, path=path)
188 kFit('pi0:eff50_May2020Fit', 0.0, 'mass', path=path)
189 elif listtype == 'eff60_May2020Fit':
190 stdPi0s('eff60_May2020', path, beamBackgroundMVAWeight, fakePhotonMVAWeight)
191 ma.cutAndCopyList('pi0:eff60_May2020Fit', 'pi0:eff60_May2020', '', writeOut=writeOut, path=path)
192 kFit('pi0:eff60_May2020Fit', 0.0, 'mass', path=path)
193 else:
194 raise ValueError(f"\"{listtype}\" is none of the allowed standardized types of pi0 lists!")
195
196# pi0 list(s) for skims (and ONLY for skims)
197
198
199def loadStdSkimPi0(path):
200 """
201 Function to prepare the skim pi0 lists.
202
203 Warning:
204 Should only be used by skims.
205
206 Parameters:
207 path (basf2.Path) modules are added to this path
208
209 """
210 stdPi0s('skim', path)
211
212
213def loadStdSkimHighEffPi0(path):
214 """
215 Function to prepare the high-efficiency skim pi0 lists based on eff60_May2020 list.
216
217 Warning:
218 Should only be used by skims.
219
220 Parameters:
221 path (basf2.Path) modules are added to this path
222
223 """
224 stdPi0s('SkimHighEff', path)