7 import modularAnalysis
as ma
8 from variables
import variables
9 from ROOT
import Belle2
10 from ROOT
import TFile
11 from ROOT
import TNtuple
15 """The unit test case for the ParticleCombinerModule"""
18 """Reconstruct decays with and without charge conjugation"""
20 testFile = tempfile.NamedTemporaryFile()
25 main = basf2.create_path()
28 ma.fillParticleList(
'pi+:pionlike',
'pionID > 0.5', path=main)
29 ma.fillParticleList(
'K+:kaonlike',
'kaonID > 0.5', path=main)
32 ma.reconstructDecay(
'D0:all -> K-:kaonlike pi+:pionlike',
'', chargeConjugation=
True, path=main)
35 ma.reconstructDecay(
'D0:particle -> K-:kaonlike pi+:pionlike',
'', chargeConjugation=
False, path=main)
38 ma.reconstructDecay(
'anti-D0:anti-particle -> K+:kaonlike pi-:pionlike',
'', chargeConjugation=
False, path=main)
42 'D0:positiveFlavour -> K-:kaonlike pi+:pionlike',
43 'daughter(0, charge) < 0',
44 chargeConjugation=
True,
47 'D0:negativeFlavour -> K-:kaonlike pi+:pionlike',
48 'daughter(0, charge) > 0',
49 chargeConjugation=
True,
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)')
58 allvariables = [
'nDs',
'nD0s',
'nAntiD0s',
'nPositiveFlavourDs',
'nNegativeFlavourDs']
59 ma.variablesToNtuple(
'', variables=allvariables, filename=testFile.name, path=main)
63 ntuplefile = TFile(testFile.name)
64 ntuple = ntuplefile.Get(
'variables')
66 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
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!")
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!")
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!")
83 print(
"Test passed, cleaning up.")
86 if __name__ ==
'__main__':