15import modularAnalysis
as ma
16from stdKlongs
import stdKlongs
21 """The unit test case for TreeFitter"""
24 """Run the test fit"""
26 testFile = tempfile.NamedTemporaryFile()
28 main = basf2.create_path()
30 ma.inputMdstList([basf2.find_file(
'B02JpsiKL_Jpsi2mumu.root',
'examples',
False)], path=main)
32 ma.fillParticleList(
'mu+:sig',
'muonID > 0.5', path=main)
35 ma.reconstructDecay(
'J/psi:mumu -> mu-:sig mu+:sig',
'3.08 < M < 3.12', path=main)
36 ma.reconstructMissingKlongDecayExpert(
'B0:sig -> J/psi:mumu K_L0:allklm',
'',
39 ma.matchMCTruth(
'B0:sig', path=main)
42 main.add_module(
'TreeFitter',
43 particleList=
'B0:sig',
45 massConstraintList=[],
46 massConstraintListParticlename=[],
47 expertUseReferencing=
True,
49 updateAllDaughters=
True,
50 ignoreFromVertexFit=
'B0 -> J/psi ^K_L0')
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")
73 print(f
"True fit survivors: {truePositives} out of {allSig} true candidates")
74 print(f
"False fit survivors: {falsePositives} out of {allBkg} false candidates")
76 self.assertTrue(falsePositives < 2041,
"Background rejection too small.")
77 self.assertTrue(truePositives > 522,
"Signal rejection too high")
79 print(f
"Signal events with good deltaE values {SigDeltaEReasonable}")
80 self.assertTrue(SigDeltaEReasonable > 463,
"Signal kinematics is wrongly reconstructed too much")
82 print(
"Test passed, cleaning up.")
85if __name__ ==
'__main__':
def clean_working_directory()