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