Belle II Software  release-05-02-19
test_std_pi0s.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import unittest
5 from basf2 import create_path
6 import stdPi0s
7 
8 
9 class TestStdPi0s(unittest.TestCase):
10  """Test case for standard pi0 lists"""
11 
12  def _check_list(self, listtype=None, std_function=stdPi0s.stdPi0s, expected_lists=["all"]):
13  """check that a given listtype function works"""
14  testpath = create_path()
15  if (std_function is stdPi0s.stdPi0s) and (listtype is not None):
16  std_function(listtype, path=testpath)
17  else:
18  std_function(path=testpath)
19 
20  built_lists = []
21  for module in testpath.modules():
22  for param in module.available_params():
23  if module.type() == 'ParticleLoader' and param.name == 'decayStringsWithCuts':
24  name = param.values[0][0].split(':')[1]
25  built_lists.append(name)
26  if module.type() == 'ParticleListManipulator' and param.name == 'outputListName':
27  name = str(param.values).split(':')[1]
28  built_lists.append(name)
29  if module.type() == 'ParticleCombiner' and param.name == 'decayString':
30  name = param.values.split(':')[1].split(' -> ')[0]
31  built_lists.append(name)
32 
33  # we have the particle lists we expect
34  for a, b in zip(built_lists, expected_lists):
35  self.assertEqual(a, b, "Loaded list \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
36 
37  print(list(built_lists))
38  result = map(lambda w1, w2: w1 == w2, built_lists, expected_lists)
39  print(list(result))
40 
41  def test_nonsense_list(self):
42  """check that the builder function raises a ValueError for a non-existing list name"""
43  self.assertRaises(ValueError, self._check_list, "flibble")
44 
45  def test_all_list(self):
46  """check that the builder function works with the all list"""
47  self._check_list("all", expected_lists=["all", "all"])
48 
50  """check that the builder function works with the eff10_Jan2020 list"""
51  self._check_list("eff10_Jan2020", expected_lists=["pi0eff10_Jan2020", "eff10_Jan2020"])
52 
54  """check that the builder function works with the eff20_Jan2020 list"""
55  self._check_list("eff20_Jan2020", expected_lists=["pi0eff20_Jan2020", "eff20_Jan2020"])
56 
58  """check that the builder function works with the eff30_Jan2020 list"""
59  self._check_list("eff30_Jan2020", expected_lists=["pi0eff30_Jan2020", "eff30_Jan2020"])
60 
62  """check that the builder function works with the eff40_Jan2020 list"""
63  self._check_list("eff40_Jan2020", expected_lists=["pi0eff40_Jan2020", "eff40_Jan2020"])
64 
66  """check that the builder function works with the eff50_Jan2020_nomcmatch list"""
67  self._check_list("eff50_Jan2020_nomcmatch", expected_lists=["pi0eff50_Jan2020", "eff50_Jan2020_nomcmatch"])
68 
70  """check that the builder function works with the eff50_Jan2020 list"""
71  self._check_list("eff50_Jan2020", expected_lists=["pi0eff50_Jan2020", "eff50_Jan2020_nomcmatch", "eff50_Jan2020"])
72 
74  """check that the builder function works with the eff60_Jan2020 list"""
75  self._check_list("eff60_Jan2020", expected_lists=["pi0eff60_Jan2020", "eff60_Jan2020"])
76 
77  def test_allfit_list(self):
78  """check that the builder function works with the allFit list"""
79  self._check_list("allFit", expected_lists=["all", "all", "allFit"])
80 
82  """check that the builder function works with the eff10_Jan2020Fit list"""
83  self._check_list("eff10_Jan2020Fit", expected_lists=["pi0eff10_Jan2020", "eff10_Jan2020", "eff10_Jan2020Fit"])
84 
86  """check that the builder function works with the eff20_Jan2020Fit list"""
87  self._check_list("eff20_Jan2020Fit", expected_lists=["pi0eff20_Jan2020", "eff20_Jan2020", "eff20_Jan2020Fit"])
88 
90  """check that the builder function works with the eff30_Jan2020Fit list"""
91  self._check_list("eff30_Jan2020Fit", expected_lists=["pi0eff30_Jan2020", "eff30_Jan2020", "eff30_Jan2020Fit"])
92 
94  """check that the builder function works with the eff40_Jan2020Fit list"""
95  self._check_list("eff40_Jan2020Fit", expected_lists=["pi0eff40_Jan2020", "eff40_Jan2020", "eff40_Jan2020Fit"])
96 
98  """check that the builder function works with the eff50_Jan2020Fit list"""
99  self._check_list(
100  "eff50_Jan2020Fit",
101  expected_lists=[
102  "pi0eff50_Jan2020",
103  'eff50_Jan2020_nomcmatch',
104  "eff50_Jan2020",
105  "eff50_Jan2020Fit"])
106 
108  """check that the builder function works with the eff60_Jan2020Fit list"""
109  self._check_list("eff60_Jan2020Fit", expected_lists=["pi0eff60_Jan2020", "eff60_Jan2020", "eff60_Jan2020Fit"])
110 
111  def test_skim(self):
112  """check that the builder function works with the skim list"""
113  self._check_list(
114  std_function=stdPi0s.loadStdSkimPi0,
115  expected_lists=[
116  "pi0eff50_Jan2020",
117  "eff50_Jan2020_nomcmatch",
118  "skim"])
119 
120 if __name__ == '__main__':
121  unittest.main()
test_std_pi0s.TestStdPi0s.test_eff30_Jan2020_list
def test_eff30_Jan2020_list(self)
Definition: test_std_pi0s.py:57
test_std_pi0s.TestStdPi0s.test_eff50_Jan2020_nomcmatch_list
def test_eff50_Jan2020_nomcmatch_list(self)
Definition: test_std_pi0s.py:65
test_std_pi0s.TestStdPi0s._check_list
def _check_list(self, listtype=None, std_function=stdPi0s.stdPi0s, expected_lists=["all"])
Definition: test_std_pi0s.py:12
test_std_pi0s.TestStdPi0s.test_eff10_Jan2020_list
def test_eff10_Jan2020_list(self)
Definition: test_std_pi0s.py:49
test_std_pi0s.TestStdPi0s.test_skim
def test_skim(self)
Definition: test_std_pi0s.py:111
test_std_pi0s.TestStdPi0s.test_allfit_list
def test_allfit_list(self)
Definition: test_std_pi0s.py:77
test_std_pi0s.TestStdPi0s
Definition: test_std_pi0s.py:9
test_std_pi0s.TestStdPi0s.test_nonsense_list
def test_nonsense_list(self)
Definition: test_std_pi0s.py:41
test_std_pi0s.TestStdPi0s.test_all_list
def test_all_list(self)
Definition: test_std_pi0s.py:45
test_std_pi0s.TestStdPi0s.test_eff50_Jan2020fit_list
def test_eff50_Jan2020fit_list(self)
Definition: test_std_pi0s.py:97
test_std_pi0s.TestStdPi0s.test_eff20_Jan2020_list
def test_eff20_Jan2020_list(self)
Definition: test_std_pi0s.py:53
test_std_pi0s.TestStdPi0s.test_eff10_Jan2020fit_list
def test_eff10_Jan2020fit_list(self)
Definition: test_std_pi0s.py:81
test_std_pi0s.TestStdPi0s.test_eff50_Jan2020_list
def test_eff50_Jan2020_list(self)
Definition: test_std_pi0s.py:69
test_std_pi0s.TestStdPi0s.test_eff30_Jan2020fit_list
def test_eff30_Jan2020fit_list(self)
Definition: test_std_pi0s.py:89
test_std_pi0s.TestStdPi0s.test_eff60_Jan2020fit_list
def test_eff60_Jan2020fit_list(self)
Definition: test_std_pi0s.py:107
test_std_pi0s.TestStdPi0s.test_eff60_Jan2020_list
def test_eff60_Jan2020_list(self)
Definition: test_std_pi0s.py:73
test_std_pi0s.TestStdPi0s.test_eff20_Jan2020fit_list
def test_eff20_Jan2020fit_list(self)
Definition: test_std_pi0s.py:85
test_std_pi0s.TestStdPi0s.test_eff40_Jan2020fit_list
def test_eff40_Jan2020fit_list(self)
Definition: test_std_pi0s.py:93
test_std_pi0s.TestStdPi0s.test_eff40_Jan2020_list
def test_eff40_Jan2020_list(self)
Definition: test_std_pi0s.py:61