14 import modularAnalysis
as ma
15 from variables
import variables
16 from ROOT
import TFile
20 """The unit test case for the ParticleCombinerModule"""
23 """Reconstruct decays with and without charge conjugation"""
25 testFile = tempfile.NamedTemporaryFile()
30 main = basf2.create_path()
33 ma.fillParticleList(
'pi+:pionlike',
'pionID > 0.5', path=main)
34 ma.fillParticleList(
'K+:kaonlike',
'kaonID > 0.5', path=main)
37 ma.reconstructDecay(
'D0:all -> K-:kaonlike pi+:pionlike',
'', chargeConjugation=
True, path=main)
40 ma.reconstructDecay(
'D0:particle -> K-:kaonlike pi+:pionlike',
'', chargeConjugation=
False, path=main)
43 ma.reconstructDecay(
'anti-D0:anti-particle -> K+:kaonlike pi-:pionlike',
'', chargeConjugation=
False, path=main)
47 'D0:positiveFlavour -> K-:kaonlike pi+:pionlike',
48 'daughter(0, charge) < 0',
49 chargeConjugation=
True,
52 'D0:negativeFlavour -> K-:kaonlike pi+:pionlike',
53 'daughter(0, charge) > 0',
54 chargeConjugation=
True,
57 variables.addAlias(
'nDs',
'nParticlesInList(D0:all)')
58 variables.addAlias(
'nD0s',
'nParticlesInList(D0:particle)')
59 variables.addAlias(
'nAntiD0s',
'nParticlesInList(anti-D0:anti-particle)')
60 variables.addAlias(
'nPositiveFlavourDs',
'nParticlesInList(D0:positiveFlavour)')
61 variables.addAlias(
'nNegativeFlavourDs',
'nParticlesInList(D0:negativeFlavour)')
63 allvariables = [
'nDs',
'nD0s',
'nAntiD0s',
'nPositiveFlavourDs',
'nNegativeFlavourDs']
64 ma.variablesToNtuple(
'', variables=allvariables, filename=testFile.name, path=main)
68 ntuplefile = TFile(testFile.name)
69 ntuple = ntuplefile.Get(
'variables')
71 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
74 if (ntuple.GetEntries() != ntuple.GetEntries(
"nDs == nD0s + nAntiD0s")):
75 ntuple.Scan(
"nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs",
"",
"", 10)
76 self.assertFalse(
True,
"Number of D0s does not agree with sum of both flavors!")
79 if (ntuple.GetEntries() != ntuple.GetEntries(
"nD0s == nPositiveFlavourDs")):
80 ntuple.Scan(
"nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs",
"",
"", 10)
81 self.assertFalse(
True,
"Number of D0s does not agree with number of K- pi+ combinations!")
84 if (ntuple.GetEntries() != ntuple.GetEntries(
"nAntiD0s == nNegativeFlavourDs")):
85 ntuple.Scan(
"nDs:nD0s:nAntiD0s:nPositiveFlavourDs:nNegativeFlavourDs",
"",
"", 10)
86 self.assertFalse(
True,
"Number of anti D0s does not agree with number of K+ pi- combinations!")
88 print(
"Test passed, cleaning up.")
91 if __name__ ==
'__main__':
def testChargeConjugation(self)
def configure_logging_for_tests(user_replacements=None)
def require_file(filename, data_type="", py_case=None)