Belle II Software light-2509-fornax
test_std_pi0s.py
1#!/usr/bin/env python3
2
3
10
11import inspect
12import unittest
13
14from basf2 import create_path
15import stdPi0s
16
17
18class TestStdPi0s(unittest.TestCase):
19 """Test case for standard pi0 lists"""
20
21 def _check_list(self, listtype=None, std_function=stdPi0s.stdPi0s, expected_lists=["all"]):
22 """check that a given listtype function works"""
23 testpath = create_path()
24 if (std_function is stdPi0s.stdPi0s) and (listtype is not None):
25 std_function(listtype, path=testpath)
26 else:
27 std_function(path=testpath)
28
29 built_lists = []
30 for module in testpath.modules():
31 for param in module.available_params():
32 if module.type() == 'ParticleLoader' and param.name == 'decayStrings':
33 name = param.values[0].split(':')[1]
34 built_lists.append(name)
35 if module.type() == 'ParticleListManipulator' and param.name == 'outputListName':
36 name = str(param.values).split(':')[1]
37 built_lists.append(name)
38 if module.type() == 'ParticleCombiner' and param.name == 'decayString':
39 name = param.values.split(':')[1].split(' -> ')[0]
40 built_lists.append(name)
41
42 # we have the particle lists we expect
43 for a, b in zip(built_lists, expected_lists):
44 self.assertEqual(a, b, f"Loaded list \'{a}\' instead of \'{b}\' with function {std_function.__name__}")
45
46 print(list(built_lists))
47 result = map(lambda w1, w2: w1 == w2, built_lists, expected_lists)
48 print(list(result))
49
51 """check that the builder function raises a ValueError for a non-existing list name"""
52 # \cond false positive doxygen warning
53 self.assertRaises(ValueError, self._check_list, "flibble")
54 # \endcond
55
57 """
58 Check that the default list type is one of the lists in the cases that are checked for in :func:`stdPi0s.stdPi0s`.
59
60 This test relies on ``ValueError`` being raised for nonsense list types, which is tested by
61 :func:`test_nonsense_list`. However, :func:`test_nonsense_list` doesn't ensure that the default list works, so
62 for that this test is needed.
63 """
64 test_path = create_path()
65 try:
66 stdPi0s.stdPi0s(path=test_path)
67 except ValueError:
68 stdPi0s_signature = inspect.signature(stdPi0s.stdPi0s)
69 default_listtype = stdPi0s_signature.parameters["listtype"].default
70 self.fail(f"stdPi0s default listtype {default_listtype} is not in set of allowed list names.")
71
73 """Check that the default list type works."""
74 stdPi0s_signature = inspect.signature(stdPi0s.stdPi0s)
75 default_listtype = stdPi0s_signature.parameters["listtype"].default
76 self._check_list(
77 expected_lists=[
78 "pi0" +
79 default_listtype,
80 "pi0" +
81 default_listtype,
82 default_listtype +
83 "_nomcmatch",
84 default_listtype])
85
86 def test_all_list(self):
87 """check that the builder function works with the all list"""
88 self._check_list("all", expected_lists=["all", "all"])
89
91 """check that the builder function works with the eff10_May2020 list"""
92 self._check_list("eff10_May2020", expected_lists=["pi0eff10_May2020", "pi0eff10_May2020", "eff10_May2020"])
93
95 """check that the builder function works with the eff20_May2020 list"""
96 self._check_list("eff20_May2020", expected_lists=["pi0eff20_May2020", "pi0eff20_May2020", "eff20_May2020"])
97
99 """check that the builder function works with the eff30_May2020 list"""
100 self._check_list("eff30_May2020", expected_lists=["pi0eff30_May2020", "pi0eff30_May2020", "eff30_May2020"])
101
103 """check that the builder function works with the eff40_May2020 list"""
104 self._check_list("eff40_May2020", expected_lists=["pi0eff40_May2020", "pi0eff40_May2020", "eff40_May2020"])
105
107 """check that the builder function works with the eff50_May2020_nomcmatch list"""
108 self._check_list("eff50_May2020_nomcmatch",
109 expected_lists=["pi0eff50_May2020",
110 "pi0eff50_May2020",
111 "eff50_May2020_nomcmatch"])
112
114 """check that the builder function works with the eff50_May2020 list"""
115 self._check_list(
116 "eff50_May2020",
117 expected_lists=[
118 "pi0eff50_May2020",
119 "pi0eff50_May2020",
120 "eff50_May2020_nomcmatch",
121 "eff50_May2020"])
122
124 """check that the builder function works with the eff50_May2020_nomcmatch list"""
125 self._check_list("eff60_May2020_nomcmatch",
126 expected_lists=["pi0eff60_May2020",
127 "pi0eff60_May2020",
128 "eff60_May2020_nomcmatch"])
129
131 """check that the builder function works with the eff60_May2020 list"""
132 self._check_list(
133 "eff60_May2020",
134 expected_lists=[
135 "pi0eff60_May2020",
136 "pi0eff60_May2020",
137 "eff60_May2020_nomcmatch",
138 "eff60_May2020"])
139
141 """check that the builder function works with the allFit list"""
142 self._check_list("allFit", expected_lists=["all", "all", "allFit"])
143
145 """check that the builder function works with the eff10_May2020Fit list"""
146 self._check_list(
147 "eff10_May2020Fit",
148 expected_lists=[
149 "pi0eff10_May2020",
150 "pi0eff10_May2020",
151 "eff10_May2020",
152 "eff10_May2020Fit"])
153
155 """check that the builder function works with the eff20_May2020Fit list"""
156 self._check_list(
157 "eff20_May2020Fit",
158 expected_lists=[
159 "pi0eff20_May2020",
160 "pi0eff20_May2020",
161 "eff20_May2020",
162 "eff20_May2020Fit"])
163
165 """check that the builder function works with the eff30_May2020Fit list"""
166 self._check_list(
167 "eff30_May2020Fit",
168 expected_lists=[
169 "pi0eff30_May2020",
170 "pi0eff30_May2020",
171 "eff30_May2020",
172 "eff30_May2020Fit"])
173
175 """check that the builder function works with the eff40_May2020Fit list"""
176 self._check_list(
177 "eff40_May2020Fit",
178 expected_lists=[
179 "pi0eff40_May2020",
180 "pi0eff40_May2020",
181 "eff40_May2020",
182 "eff40_May2020Fit"])
183
185 """check that the builder function works with the eff50_May2020Fit list"""
186 self._check_list(
187 "eff50_May2020Fit",
188 expected_lists=[
189 "pi0eff50_May2020",
190 "pi0eff50_May2020",
191 'eff50_May2020_nomcmatch',
192 "eff50_May2020",
193 "eff50_May2020Fit"])
194
196 """check that the builder function works with the eff60_May2020Fit list"""
197 self._check_list(
198 "eff60_May2020Fit",
199 expected_lists=[
200 "pi0eff60_May2020",
201 "pi0eff60_May2020",
202 'eff60_May2020_nomcmatch',
203 "eff60_May2020",
204 "eff60_May2020Fit"])
205
206 def test_skim(self):
207 """check that the builder function works with the skim list"""
208 self._check_list(
209 std_function=stdPi0s.loadStdSkimPi0,
210 expected_lists=[
211 "pi0eff50_May2020",
212 "pi0eff50_May2020",
213 "eff50_May2020_nomcmatch",
214 "skim"])
215
217 """check that the builder function works with the skim list"""
218 self._check_list(
219 std_function=stdPi0s.loadStdSkimHighEffPi0,
220 expected_lists=[
221 "pi0eff60_May2020",
222 "pi0eff60_May2020",
223 "eff60_May2020_nomcmatch",
224 "SkimHighEff"])
225
226
227if __name__ == '__main__':
228 unittest.main()
_check_list(self, listtype=None, std_function=stdPi0s.stdPi0s, expected_lists=["all"])
stdPi0s(listtype="eff60_May2020", path=None, beamBackgroundMVAWeight="", fakePhotonMVAWeight="", biasCorrectionTable="")
Definition stdPi0s.py:22