Belle II Software  release-06-02-00
test_std_v0.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import unittest
13 from basf2 import create_path
14 import stdV0s
15 
16 
17 class TestStdV0(unittest.TestCase):
18  """Test case for standard V0 lists"""
19 
21  self,
22  std_function=stdV0s.stdKshorts,
23  expected_modules=[
24  "ParticleLoader",
25  "ParticleListManipulator",
26  "TreeFitter",
27  "ParticleSelector",
28  "ParticleLoader",
29  "ParticleCombiner",
30  "TreeFitter",
31  "ParticleSelector",
32  "ParticleListManipulator"],
33  expected_lists=['V0', 'V0_MassWindow', 'all', 'RD', 'merged']):
34  """check that a given function works"""
35  testpath = create_path()
36  std_function(path=testpath)
37 
38  # verify that we load the correct amount of modules
39  self.assertEqual(
40  len(testpath.modules()), len(expected_modules),
41  "Function %s does not load the expected number of modules" % (std_function.__name__))
42 
43  #
44  loaded_modules = []
45  built_lists = []
46  for module in testpath.modules():
47  loaded_modules.append(module.type())
48  for param in module.available_params():
49  if module.type() == 'ParticleLoader' and param.name == 'decayStrings':
50  name = param.values[0].split(':')[1].split(' -> ')[0]
51  built_lists.append(name)
52  if module.type() == 'ParticleListManipulator' and param.name == 'outputListName':
53  name = str(param.values).split(':')[1].split(' -> ')[0]
54  built_lists.append(name)
55  if module.type() == 'ParticleCombiner' and param.name == 'decayString':
56  name = param.values.split(':')[1].split(' -> ')[0]
57  built_lists.append(name)
58 
59  # we have the modules we expect
60  for a, b in zip(loaded_modules, expected_modules):
61  self.assertEqual(a, b, "Loaded module \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
62 
63  # we have the particle lists we expect
64  for a, b in zip(built_lists, expected_lists):
65  self.assertEqual(a, b, "Loaded list \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
66 
68  """check that the builder function works with the stdKshorts list"""
69  self._check_list_check_list()
70 
71  def test_belle_list(self):
72  """check that the builder function works with the legacy Belle Kshorts list"""
73  expected_modules = ["ParticleLoader",
74  "ParticleListManipulator",
75  "ParticleSelector",
76  "ParticleVertexFitter",
77  "ParticleSelector"]
78  self._check_list_check_list(std_function=stdV0s.goodBelleKshort, expected_modules=expected_modules, expected_lists=["legacyGoodKS"])
79 
81  """check that the builder function works with the stdLambdas list"""
82  expected_modules = ["ParticleLoader",
83  "ParticleListManipulator",
84  "TreeFitter",
85  "ParticleSelector",
86  "DuplicateVertexMarker",
87  "ParticleSelector",
88  "ParticleLoader",
89  "ParticleLoader",
90  "ParticleCombiner",
91  "TreeFitter",
92  "ParticleSelector",
93  "DuplicateVertexMarker",
94  "ParticleSelector",
95  "ParticleListManipulator"]
96  expected_lists = ['V0', 'V0_MassWindow', 'all', 'all', 'RD', 'merged']
97  self._check_list_check_list(std_function=stdV0s.stdLambdas, expected_modules=expected_modules, expected_lists=expected_lists)
98 
99 
100 if __name__ == '__main__':
101  unittest.main()
def _check_list(self, std_function=stdV0s.stdKshorts, expected_modules=["ParticleLoader", "ParticleListManipulator", "TreeFitter", "ParticleSelector", "ParticleLoader", "ParticleCombiner", "TreeFitter", "ParticleSelector", "ParticleListManipulator"], expected_lists=['V0', 'V0_MassWindow', 'all', 'RD', 'merged'])
Definition: test_std_v0.py:33
def test_stdlambdas_list(self)
Definition: test_std_v0.py:80
def test_stdkshorts_list(self)
Definition: test_std_v0.py:67
def test_belle_list(self)
Definition: test_std_v0.py:71