Belle II Software development
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 self.assertRaises(ValueError, self._check_list, "flibble")
53
55 """
56 Check that the default list type is one of the lists in the cases that are checked for in :func:`stdPi0s.stdPi0s`.
57
58 This test relies on ``ValueError`` being raised for nonsense list types, which is tested by
59 :func:`test_nonsense_list`. However, :func:`test_nonsense_list` doesn't ensure that the default list works, so
60 for that this test is needed.
61 """
62 test_path = create_path()
63 try:
64 stdPi0s.stdPi0s(path=test_path)
65 except ValueError:
66 stdPi0s_signature = inspect.signature(stdPi0s.stdPi0s)
67 default_listtype = stdPi0s_signature.parameters["listtype"].default
68 self.fail(f"stdPi0s default listtype {default_listtype} is not in set of allowed list names.")
69
71 """Check that the default list type works."""
72 stdPi0s_signature = inspect.signature(stdPi0s.stdPi0s)
73 default_listtype = stdPi0s_signature.parameters["listtype"].default
74 self._check_list(
75 expected_lists=[
76 "pi0" +
77 default_listtype,
78 "pi0" +
79 default_listtype,
80 default_listtype +
81 "_nomcmatch",
82 default_listtype])
83
84 def test_all_list(self):
85 """check that the builder function works with the all list"""
86 self._check_list("all", expected_lists=["all", "all"])
87
89 """check that the builder function works with the eff10_May2020 list"""
90 self._check_list("eff10_May2020", expected_lists=["pi0eff10_May2020", "pi0eff10_May2020", "eff10_May2020"])
91
93 """check that the builder function works with the eff20_May2020 list"""
94 self._check_list("eff20_May2020", expected_lists=["pi0eff20_May2020", "pi0eff20_May2020", "eff20_May2020"])
95
97 """check that the builder function works with the eff30_May2020 list"""
98 self._check_list("eff30_May2020", expected_lists=["pi0eff30_May2020", "pi0eff30_May2020", "eff30_May2020"])
99
101 """check that the builder function works with the eff40_May2020 list"""
102 self._check_list("eff40_May2020", expected_lists=["pi0eff40_May2020", "pi0eff40_May2020", "eff40_May2020"])
103
105 """check that the builder function works with the eff50_May2020_nomcmatch list"""
106 self._check_list("eff50_May2020_nomcmatch",
107 expected_lists=["pi0eff50_May2020",
108 "pi0eff50_May2020",
109 "eff50_May2020_nomcmatch"])
110
112 """check that the builder function works with the eff50_May2020 list"""
113 self._check_list(
114 "eff50_May2020",
115 expected_lists=[
116 "pi0eff50_May2020",
117 "pi0eff50_May2020",
118 "eff50_May2020_nomcmatch",
119 "eff50_May2020"])
120
122 """check that the builder function works with the eff50_May2020_nomcmatch list"""
123 self._check_list("eff60_May2020_nomcmatch",
124 expected_lists=["pi0eff60_May2020",
125 "pi0eff60_May2020",
126 "eff60_May2020_nomcmatch"])
127
129 """check that the builder function works with the eff60_May2020 list"""
130 self._check_list(
131 "eff60_May2020",
132 expected_lists=[
133 "pi0eff60_May2020",
134 "pi0eff60_May2020",
135 "eff60_May2020_nomcmatch",
136 "eff60_May2020"])
137
139 """check that the builder function works with the allFit list"""
140 self._check_list("allFit", expected_lists=["all", "all", "allFit"])
141
143 """check that the builder function works with the eff10_May2020Fit list"""
144 self._check_list(
145 "eff10_May2020Fit",
146 expected_lists=[
147 "pi0eff10_May2020",
148 "pi0eff10_May2020",
149 "eff10_May2020",
150 "eff10_May2020Fit"])
151
153 """check that the builder function works with the eff20_May2020Fit list"""
154 self._check_list(
155 "eff20_May2020Fit",
156 expected_lists=[
157 "pi0eff20_May2020",
158 "pi0eff20_May2020",
159 "eff20_May2020",
160 "eff20_May2020Fit"])
161
163 """check that the builder function works with the eff30_May2020Fit list"""
164 self._check_list(
165 "eff30_May2020Fit",
166 expected_lists=[
167 "pi0eff30_May2020",
168 "pi0eff30_May2020",
169 "eff30_May2020",
170 "eff30_May2020Fit"])
171
173 """check that the builder function works with the eff40_May2020Fit list"""
174 self._check_list(
175 "eff40_May2020Fit",
176 expected_lists=[
177 "pi0eff40_May2020",
178 "pi0eff40_May2020",
179 "eff40_May2020",
180 "eff40_May2020Fit"])
181
183 """check that the builder function works with the eff50_May2020Fit list"""
184 self._check_list(
185 "eff50_May2020Fit",
186 expected_lists=[
187 "pi0eff50_May2020",
188 "pi0eff50_May2020",
189 'eff50_May2020_nomcmatch',
190 "eff50_May2020",
191 "eff50_May2020Fit"])
192
194 """check that the builder function works with the eff60_May2020Fit list"""
195 self._check_list(
196 "eff60_May2020Fit",
197 expected_lists=[
198 "pi0eff60_May2020",
199 "pi0eff60_May2020",
200 'eff60_May2020_nomcmatch',
201 "eff60_May2020",
202 "eff60_May2020Fit"])
203
204 def test_skim(self):
205 """check that the builder function works with the skim list"""
206 self._check_list(
207 std_function=stdPi0s.loadStdSkimPi0,
208 expected_lists=[
209 "pi0eff50_May2020",
210 "pi0eff50_May2020",
211 "eff50_May2020_nomcmatch",
212 "skim"])
213
215 """check that the builder function works with the skim list"""
216 self._check_list(
217 std_function=stdPi0s.loadStdSkimHighEffPi0,
218 expected_lists=[
219 "pi0eff60_May2020",
220 "pi0eff60_May2020",
221 "eff60_May2020_nomcmatch",
222 "SkimHighEff"])
223
224
225if __name__ == '__main__':
226 unittest.main()
def test_eff60_May2020fit_list(self)
def _check_list(self, listtype=None, std_function=stdPi0s.stdPi0s, expected_lists=["all"])
def test_eff50_May2020fit_list(self)
def test_eff20_May2020fit_list(self)
def test_eff50_May2020_nomcmatch_list(self)
def test_eff40_May2020fit_list(self)
def test_eff10_May2020fit_list(self)
def test_eff30_May2020fit_list(self)
def test_default_list_exists(self)
def test_eff60_May2020_nomcmatch_list(self)
def stdPi0s(listtype="eff60_May2020", path=None, beamBackgroundMVAWeight="", fakePhotonMVAWeight="", biasCorrectionTable="")
Definition: stdPi0s.py:22