22 """Run the test fit"""
24 testFile = tempfile.NamedTemporaryFile()
26 main = basf2.create_path()
28 inputfile = b2test_utils.require_file(
29 'analysis/1000_B_Jpsi_ks_pipi.root', 'validation', py_case=self)
30 ma.inputMdst(inputfile, path=main)
32 ma.fillParticleList('mu+', 'muonID > 0.5', path=main)
34 ma.reconstructDecay('J/psi:all -> mu+ mu-', '', 0, path=main)
35 ma.matchMCTruth('J/psi:all', path=main)
38 main.add_module('TreeFitter',
39 particleList='J/psi:all',
41 massConstraintList=[],
43 updateAllDaughters=False)
45 ntupler = basf2.register_module('VariablesToNtuple')
46 ntupler.param('fileName', testFile.name)
47 ntupler.param('variables', ['chiProb', 'M', 'isSignal'])
48 ntupler.param('particleList', 'J/psi:all')
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(f"(chiProb < {conf})")
66 print(f"True fit survivors: {truePositives} out of {allSig} true candidates")
67 print(f"False fit survivors: {falsePositives} out of {allBkg} false candidates")
69 self.assertFalse(truePositives == 0, "No signal survived the fit.")
71 self.assertTrue(falsePositives <= 1828, f"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
73 self.assertTrue(truePositives == 745, "Signal rejection too high")
75 self.assertFalse(mustBeZero, f"We should have dropped all candidates with confidence level less than {conf}.")
77 print("Test passed, cleaning up.")