22 """Run the test fit"""
24 testFile = tempfile.NamedTemporaryFile()
26 main = basf2.create_path()
28 inputfile = b2test_utils.require_file('analysis/B0ToPiPiPi0.root', 'validation', py_case=self)
29 ma.inputMdst(inputfile, path=main)
31 ma.fillParticleList('pi+:a', 'pionID > 0.5', path=main)
33 ma.fillParticleList('gamma:a', '', path=main)
34 ma.reconstructDecay('pi0:a -> gamma:a gamma:a', '0.125 < InvM < 0.145', 0, path=main)
36 ma.reconstructDecay('B0:rec -> pi-:a pi+:a pi0:a', '', 0, path=main)
37 ma.matchMCTruth('B0:rec', path=main)
40 main.add_module('TreeFitter',
41 particleList='B0:rec',
43 massConstraintList=[],
45 updateAllDaughters=True)
47 ntupler = basf2.register_module('VariablesToNtuple')
48 ntupler.param('fileName', testFile.name)
49 ntupler.param('variables', ['chiProb', 'M', 'isSignal'])
50 ntupler.param('particleList', 'B0:rec')
51 main.add_module(ntupler)
55 ntuplefile = TFile(testFile.name)
56 ntuple = ntuplefile.Get('ntuple')
58 self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
60 allBkg = ntuple.GetEntries("isSignal == 0")
61 allSig = ntuple.GetEntries("isSignal > 0")
63 truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal > 0)")
64 falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
66 mustBeZero = ntuple.GetEntries(f"(chiProb < {conf})")
68 print(f"True fit survivors: {truePositives} out of {allSig} true candidates")
69 print(f"False fit survivors: {falsePositives} out of {allBkg} false candidates")
71 self.assertFalse(truePositives == 0, "No signal survived the fit.")
73 self.assertTrue(falsePositives < 8299, "Background rejection too small.")
75 self.assertTrue(truePositives > 211, "Signal rejection too high")
76 self.assertFalse(mustBeZero, f"We should have dropped all candidates with confidence level less than {conf}.")
78 print("Test passed, cleaning up.")