Belle II Software  release-05-01-25
test_std_photons.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import unittest
5 from basf2 import create_path
6 import stdPhotons
7 
8 
9 class TestStdPhotons(unittest.TestCase):
10  """Test case for standard photon lists"""
11 
12  def _check_list(self, listtype=None, std_function=stdPhotons.stdPhotons, expected_lists=["all"]):
13  """check that a given listtype function works"""
14  testpath = create_path()
15  if (std_function is stdPhotons.stdPhotons) and (listtype is not None):
16  std_function(listtype, path=testpath)
17  else:
18  std_function(path=testpath)
19 
20  # verify that we load only the list-creating modules
21  self.assertEqual(
22  len(testpath.modules()), len(expected_lists),
23  "List %s doesn't work with function %s" % (listtype, std_function.__name__))
24  self.assertTrue(all((module.type() == "ParticleLoader") or (module.type() == "ParticleListManipulator")
25  for module in testpath.modules()))
26 
27  #
28  built_list = []
29  for module in testpath.modules():
30  for param in module.available_params():
31  if param.name == 'decayStringsWithCuts':
32  name = param.values[0][0].split(':')[1]
33  built_list.append(name)
34  if param.name == 'outputListName':
35  name = str(param.values).split(':')[1]
36  built_list.append(name)
37 
38  # we have the particle lists we expect
39  for a, b in zip(built_list, expected_lists):
40  self.assertEqual(a, b, "Loaded list \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
41 
42  def test_nonsense_list(self):
43  """check that the builder function works with the all list"""
44  self._check_list("flibble", expected_lists=[])
45 
46  def test_all_list(self):
47  """check that the builder function works with the all list"""
48  self._check_list("all", expected_lists=["all"])
49 
50  def test_cdc_list(self):
51  """check that the builder function works with the cdc list"""
52  self._check_list("cdc", expected_lists=["cdc"])
53 
54  def test_loose_list(self):
55  """check that the builder function works with the loose list"""
56  self._check_list("loose", expected_lists=["cdc", "loose"])
57 
58  def test_default_list(self):
59  """check that the builder function works with the default (loose) list"""
60  self._check_list(expected_lists=["cdc", "loose"])
61 
62  def test_tight_list(self):
63  """check that the builder function works with the tight list"""
64  self._check_list("tight", expected_lists=["cdc", "loose", "tight"])
65 
67  """check that the builder function works with the pi0eff60_Jan2020 list"""
68  self._check_list("pi0eff60_Jan2020", expected_lists=["pi0eff60_Jan2020"])
69 
71  """check that the builder function works with the pi0eff50_Jan2020 list"""
72  self._check_list("pi0eff50_Jan2020", expected_lists=["pi0eff50_Jan2020"])
73 
75  """check that the builder function works with the pi0eff40_Jan2020 list"""
76  self._check_list("pi0eff40_Jan2020", expected_lists=["pi0eff40_Jan2020"])
77 
79  """check that the builder function works with the pi0eff30_Jan2020 list"""
80  self._check_list("pi0eff30_Jan2020", expected_lists=["pi0eff30_Jan2020"])
81 
83  """check that the builder function works with the pi0eff20_Jan2020 list"""
84  self._check_list("pi0eff20_Jan2020", expected_lists=["pi0eff20_Jan2020"])
85 
87  """check that the builder function works with the pi0eff10_Jan2020 list"""
88  self._check_list("pi0eff10_Jan2020", expected_lists=["pi0eff10_Jan2020"])
89 
90  def test_skim(self):
91  """check that the builder function works with the skim list"""
92  self._check_list("skim", std_function=stdPhotons.loadStdSkimPhoton, expected_lists=["cdc", "loose", "skim"])
93 
94  def test_belle(self):
95  """check that the builder function works with the belle list"""
96  self._check_list("goodBelle", std_function=stdPhotons.loadStdGoodBellePhoton, expected_lists=["goodBelle"])
97 
98 
99 if __name__ == '__main__':
100  unittest.main()
test_std_photons.TestStdPhotons.test_loose_list
def test_loose_list(self)
Definition: test_std_photons.py:54
test_std_photons.TestStdPhotons.test_pi0eff20_Jan2020_list
def test_pi0eff20_Jan2020_list(self)
Definition: test_std_photons.py:82
test_std_photons.TestStdPhotons.test_pi0eff10_Jan2020_list
def test_pi0eff10_Jan2020_list(self)
Definition: test_std_photons.py:86
test_std_photons.TestStdPhotons.test_nonsense_list
def test_nonsense_list(self)
Definition: test_std_photons.py:42
test_std_photons.TestStdPhotons.test_pi0eff30_Jan2020_list
def test_pi0eff30_Jan2020_list(self)
Definition: test_std_photons.py:78
test_std_photons.TestStdPhotons.test_skim
def test_skim(self)
Definition: test_std_photons.py:90
test_std_photons.TestStdPhotons.test_all_list
def test_all_list(self)
Definition: test_std_photons.py:46
test_std_photons.TestStdPhotons.test_belle
def test_belle(self)
Definition: test_std_photons.py:94
test_std_photons.TestStdPhotons.test_default_list
def test_default_list(self)
Definition: test_std_photons.py:58
test_std_photons.TestStdPhotons.test_cdc_list
def test_cdc_list(self)
Definition: test_std_photons.py:50
test_std_photons.TestStdPhotons.test_tight_list
def test_tight_list(self)
Definition: test_std_photons.py:62
test_std_photons.TestStdPhotons
Definition: test_std_photons.py:9
test_std_photons.TestStdPhotons._check_list
def _check_list(self, listtype=None, std_function=stdPhotons.stdPhotons, expected_lists=["all"])
Definition: test_std_photons.py:12
test_std_photons.TestStdPhotons.test_pi0eff60_Jan2020_list
def test_pi0eff60_Jan2020_list(self)
Definition: test_std_photons.py:66
test_std_photons.TestStdPhotons.test_pi0eff40_Jan2020_list
def test_pi0eff40_Jan2020_list(self)
Definition: test_std_photons.py:74
test_std_photons.TestStdPhotons.test_pi0eff50_Jan2020_list
def test_pi0eff50_Jan2020_list(self)
Definition: test_std_photons.py:70