Belle II Software  release-05-02-19
TestParticleCombiner Class Reference
Inheritance diagram for TestParticleCombiner:
Collaboration diagram for TestParticleCombiner:

Public Member Functions

def testChargeConjugation (self)
 

Detailed Description

The unit test case for the ParticleCombinerModule

Definition at line 14 of file chargeConjugation.py.

Member Function Documentation

◆ testChargeConjugation()

def testChargeConjugation (   self)
Reconstruct decays with and without charge conjugation

Definition at line 17 of file chargeConjugation.py.

17  def testChargeConjugation(self):
18  """Reconstruct decays with and without charge conjugation"""
19 
20  testFile = tempfile.NamedTemporaryFile()
21  # make logging more reproducible by replacing some strings.
22  # Also make sure the testfile name is replaced if necessary
23  b2test_utils.configure_logging_for_tests({testFile.name: "${testfile}"})
24 
25  main = basf2.create_path()
26  ma.inputMdst('default', b2test_utils.require_file('analysis/tests/mdst.root'), path=main)
27 
28  ma.fillParticleList('pi+:pionlike', 'pionID > 0.5', path=main)
29  ma.fillParticleList('K+:kaonlike', 'kaonID > 0.5', path=main)
30 
31  # combine all kaons with all pions for both charge configurations (K- pi+ and K+ pi-)
32  ma.reconstructDecay('D0:all -> K-:kaonlike pi+:pionlike', '', chargeConjugation=True, path=main)
33 
34  # only reconstruct D0
35  ma.reconstructDecay('D0:particle -> K-:kaonlike pi+:pionlike', '', chargeConjugation=False, path=main)
36 
37  # only reconstruct anti-D0
38  ma.reconstructDecay('anti-D0:anti-particle -> K+:kaonlike pi-:pionlike', '', chargeConjugation=False, path=main)
39 
40  # use particle's charge to separate D0 flavors,
41  ma.reconstructDecay(
42  'D0:positiveFlavour -> K-:kaonlike pi+:pionlike',
43  'daughter(0, charge) < 0',
44  chargeConjugation=True,
45  path=main)
46  ma.reconstructDecay(
47  'D0:negativeFlavour -> K-:kaonlike pi+:pionlike',
48  'daughter(0, charge) > 0',
49  chargeConjugation=True,
50  path=main)
51 
52  variables.addAlias('nDs', 'nParticlesInList(D0:all)')
53  variables.addAlias('nD0s', 'nParticlesInList(D0:particle)')
54  variables.addAlias('nAntiD0s', 'nParticlesInList(anti-D0:anti-particle)')
55  variables.addAlias('nPositiveFlavourDs', 'nParticlesInList(D0:positiveFlavour)')
56  variables.addAlias('nNegativeFlavourDs', 'nParticlesInList(D0:negativeFlavour)')
57 
58  allvariables = ['nDs', 'nD0s', 'nAntiD0s', 'nPositiveFlavourDs', 'nNegativeFlavourDs']
59  ma.variablesToNtuple('', variables=allvariables, filename=testFile.name, path=main)
60 
61  basf2.process(main)
62 
63  ntuplefile = TFile(testFile.name)
64  ntuple = ntuplefile.Get('variables')
65 
66  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
67 
68  # sum of D0s and D0bars should be equal to all D0s
69  if (ntuple.GetEntries() != ntuple.GetEntries("nDs == nD0s + nAntiD0s")):
70  ntuple.Scan("nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs", "", "", 10)
71  self.assertFalse(True, "Number of D0s does not agree with sum of both flavors!")
72 
73  # D0s should be combinations of K- and pi+ only
74  if (ntuple.GetEntries() != ntuple.GetEntries("nD0s == nPositiveFlavourDs")):
75  ntuple.Scan("nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs", "", "", 10)
76  self.assertFalse(True, "Number of D0s does not agree with number of K- pi+ combinations!")
77 
78  # D0bars should be combinations of K+ and pi- only
79  if (ntuple.GetEntries() != ntuple.GetEntries("nAntiD0s == nNegativeFlavourDs")):
80  ntuple.Scan("nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs", "", "", 10)
81  self.assertFalse(True, "Number of anti D0s does not agree with number of K+ pi- combinations!")
82 
83  print("Test passed, cleaning up.")
84 
85 

The documentation for this class was generated from the following file:
b2test_utils.configure_logging_for_tests
def configure_logging_for_tests(user_replacements=None)
Definition: __init__.py:99
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
b2test_utils.require_file
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:47