15import modularAnalysis
as ma
16from stdKlongs
import stdKlongs
21 """The unit test case for TreeFitter"""
24 """Run the test fit"""
26 basf2.set_random_seed(
'klong')
27 testFile = tempfile.NamedTemporaryFile()
29 main = basf2.create_path()
31 ma.inputMdstList([basf2.find_file(
'B02JpsiKL_Jpsi2mumu.root',
'examples',
False)], path=main)
33 ma.fillParticleList(
'mu+:sig',
'muonID > 0.5', path=main)
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)
41 main.add_module(
'TreeFitter',
42 particleList=
'B0:sig',
44 massConstraintList=[],
45 massConstraintListParticlename=[
'B0'],
46 expertUseReferencing=
True,
48 updateAllDaughters=
True)
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)
58 ntuplefile = TFile(testFile.name)
59 ntuple = ntuplefile.Get(
'ntuple')
61 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
63 allSig = ntuple.GetEntries(
"isSignal == 1")
64 allBkg = ntuple.GetEntries(
"isSignal == 0")
66 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 1)")
67 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
69 SigDeltaEReasonable = ntuple.GetEntries(
"isSignal==1 && deltaE<0.1 && chiProb>0")
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}")
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")
79 self.assertTrue(SigDeltaEReasonable >= 427,
80 f
"Signal kinematics is correctly reconstructed in {SigDeltaEReasonable} candidates.")
82 print(
"Test passed, cleaning up.")
85if __name__ ==
'__main__':
def clean_working_directory()