13import modularAnalysis
as ma
14from vertex
import treeFit
20 """The unit test case for TreeFitter"""
23 """Run the test fit"""
25 testFile = tempfile.NamedTemporaryFile()
27 main = basf2.create_path()
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)
39 treeFit(
'B0:rec', conf_level=-1, ipConstraint=
False, updateAllDaughters=
True, path=main)
41 ntupler = basf2.register_module(
'VariablesToNtuple')
42 ntupler.param(
'fileName', testFile.name)
43 ntupler.param(
'variables', [
'chiProb',
'M',
'isSignal'])
44 ntupler.param(
'particleList',
'B0:rec')
45 main.add_module(ntupler)
49 ntuplefile = TFile(testFile.name)
50 ntuple = ntuplefile.Get(
'ntuple')
52 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
54 allBkg = ntuple.GetEntries(
"isSignal == 0")
55 allSig = ntuple.GetEntries(
"isSignal > 0")
57 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
58 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
60 print(f
"True fit survivors: {truePositives} out of {allSig} true candidates")
61 print(f
"False fit survivors: {falsePositives} out of {allBkg} false candidates")
63 self.assertTrue(truePositives > 212, f
"Signal rejection too high. True positives: {truePositives}")
65 self.assertTrue(falsePositives < 8299, f
"Background rejection got worse. False positives: {falsePositives}")
67 print(
"Test passed, cleaning up.")
70if __name__ ==
'__main__':
def require_file(filename, data_type="", py_case=None)
def clean_working_directory()