15import modularAnalysis
as ma
16from stdKlongs
import stdKlongs
19from b2test_utils
import skip_test
23 """The unit test case for TreeFitter"""
26 """Run the test fit"""
28 basf2.set_random_seed(
'klong')
29 testFile = tempfile.NamedTemporaryFile()
31 main = basf2.create_path()
33 ma.inputMdstList([basf2.find_file(
'B02JpsiKL_Jpsi2mumu.root',
'examples',
False)], path=main)
35 ma.fillParticleList(
'mu+:sig',
'muonID > 0.5', path=main)
38 ma.reconstructDecay(
'J/psi:mumu -> mu-:sig mu+:sig',
'3.08 < M < 3.12', path=main)
39 ma.reconstructDecay(
'B0:sig -> J/psi:mumu K_L0:allklm',
'', path=main)
40 ma.matchMCTruth(
'B0:sig', path=main)
43 main.add_module(
'TreeFitter',
44 particleList=
'B0:sig',
46 massConstraintList=[],
47 massConstraintListParticlename=[
'B0'],
48 expertUseReferencing=
True,
50 updateAllDaughters=
True)
52 ntupler = basf2.register_module(
'VariablesToNtuple')
53 ntupler.param(
'fileName', testFile.name)
54 ntupler.param(
'variables', [
'chiProb',
'isSignal',
'Mbc',
'deltaE',
'dz'])
55 ntupler.param(
'particleList',
'B0:sig')
56 main.add_module(ntupler)
60 ntuplefile = TFile(testFile.name)
61 ntuple = ntuplefile.Get(
'ntuple')
63 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
65 allSig = ntuple.GetEntries(
"isSignal == 1")
66 allBkg = ntuple.GetEntries(
"isSignal == 0")
68 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 1)")
69 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
71 SigDeltaEReasonable = ntuple.GetEntries(
"isSignal==1 && deltaE<0.1 && chiProb>0")
73 print(f
"True fit survivors: {truePositives} out of {allSig} true candidates")
74 print(f
"False fit survivors: {falsePositives} out of {allBkg} false candidates")
75 print(f
"True fit survivors with reasonable deltaE: {SigDeltaEReasonable}")
77 self.assertTrue(falsePositives == 1247,
"Background rejection too small.")
78 self.assertTrue(truePositives == 319,
"Signal rejection too high")
80 self.assertTrue(SigDeltaEReasonable == 273,
"Signal kinematics is wrongly reconstructed too much")
82 print(
"Test passed, cleaning up.")
85if __name__ ==
'__main__':
86 skip_test(
"TreeFit with Klong is not robust enough to get the identical results with different processors.")
def clean_working_directory()