23 def testFit(self):
24 """Run the test fit"""
25
26 basf2.set_random_seed('klong')
27 testFile = tempfile.NamedTemporaryFile()
28
29 main = basf2.create_path()
30
31 ma.inputMdstList([basf2.find_file('B02JpsiKL_Jpsi2mumu.root', 'examples', False)], path=main)
32
33 ma.fillParticleList('mu+:sig', 'muonID > 0.5', path=main)
35
36 ma.reconstructDecay('J/psi:mumu -> mu-:sig mu+:sig', '3.08 < M < 3.12', path=main)
37 ma.reconstructDecay('B0:sig -> J/psi:mumu K_L0:allklm', '', path=main)
38 ma.matchMCTruth('B0:sig', path=main)
39
40 conf = -1
41 main.add_module('TreeFitter',
42 particleList='B0:sig',
43 confidenceLevel=conf,
44 massConstraintList=[],
45 massConstraintListParticlename=['B0'],
46 expertUseReferencing=True,
47 ipConstraint=True,
48 updateAllDaughters=True)
49
50 ntupler = basf2.register_module('VariablesToNtuple')
51 ntupler.param('fileName', testFile.name)
52 ntupler.param('variables', ['chiProb', 'isSignal', 'Mbc', 'deltaE', 'dz'])
53 ntupler.param('particleList', 'B0:sig')
54 main.add_module(ntupler)
55
56 basf2.process(main)
57
58 ntuplefile = TFile(testFile.name)
59 ntuple = ntuplefile.Get('ntuple')
60
61 self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
62
63 allSig = ntuple.GetEntries("isSignal == 1")
64 allBkg = ntuple.GetEntries("isSignal == 0")
65
66 truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 1)")
67 falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
68
69 SigDeltaEReasonable = ntuple.GetEntries("isSignal==1 && deltaE<0.1 && chiProb>0")
70
71 print(f"True fit survivors: {truePositives} out of {allSig} true candidates")
72 print(f"False fit survivors: {falsePositives} out of {allBkg} false candidates")
73 print(f"True fit survivors with reasonable deltaE: {SigDeltaEReasonable}")
74
75 self.assertTrue(allBkg - falsePositives >= 43,
76 f"Background rejection: {allBkg-falsePositives} out of {allBkg} false candidates rejected")
77 self.assertTrue(truePositives >= 501, f"Signal efficiency: {truePositives} out of {allSig} true candidates retained")
78
79 self.assertTrue(SigDeltaEReasonable >= 427,
80 f"Signal kinematics is correctly reconstructed in {SigDeltaEReasonable} candidates.")
81
82 print("Test passed, cleaning up.")
83
84