8 import modularAnalysis
as ma
9 from ROOT
import Belle2
10 from ROOT
import TFile
11 from ROOT
import TNtuple
15 """The unit test case for TreeFitter"""
18 """Run the test fit"""
20 testFile = tempfile.NamedTemporaryFile()
22 main = basf2.create_path()
25 ma.inputMdst(
'default', inputfile, path=main)
27 ma.fillParticleList(
'pi+:a',
'pionID > 0.5', path=main)
29 ma.fillParticleList(
'gamma:a',
'', path=main)
30 ma.reconstructDecay(
'pi0:a -> gamma:a gamma:a',
'0.125 < InvM < 0.145', 0, path=main)
32 ma.reconstructDecay(
'B0:rec -> pi-:a pi+:a pi0:a',
'', 0, path=main)
33 ma.matchMCTruth(
'B0:rec', path=main)
36 main.add_module(
'TreeFitter',
37 particleList=
'B0:rec',
39 massConstraintList=[],
40 massConstraintListParticlename=[],
41 expertUseReferencing=
True,
43 updateAllDaughters=
True)
45 ntupler = basf2.register_module(
'VariablesToNtuple')
46 ntupler.param(
'fileName', testFile.name)
47 ntupler.param(
'variables', [
'chiProb',
'M',
'isSignal'])
48 ntupler.param(
'particleList',
'B0:rec')
49 main.add_module(ntupler)
53 ntuplefile = TFile(testFile.name)
54 ntuple = ntuplefile.Get(
'ntuple')
56 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
58 allBkg = ntuple.GetEntries(
"isSignal == 0")
59 allSig = ntuple.GetEntries(
"isSignal > 0")
61 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
62 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
64 mustBeZero = ntuple.GetEntries(
"(chiProb < {})".format(conf))
66 print(
"True fit survivors: {0} out of {1} true candidates".format(truePositives, allSig))
67 print(
"False fit survivors: {0} out of {1} false candidates".format(falsePositives, allBkg))
69 self.assertFalse(truePositives == 0,
"No signal survived the fit.")
71 self.assertTrue(falsePositives < 2596,
"Background rejection increased.")
73 self.assertTrue(truePositives > 34,
"Signal rejection too high")
74 self.assertFalse(mustBeZero,
"We should have dropped all candidates with confidence level less than {}.".format(conf))
76 print(
"Test passed, cleaning up.")
79 if __name__ ==
'__main__':