7 import modularAnalysis
as ma
9 from ROOT
import Belle2
10 from ROOT
import TFile
11 from ROOT
import TNtuple
15 """The unit test case for TreeFitter"""
18 """Run the test fit"""
20 testFile = tempfile.NamedTemporaryFile()
22 main = basf2.create_path()
25 'analysis/1000_B_Jpsi_ks_pipi.root',
'validation', py_case=self)
26 ma.inputMdst(
'default', inputfile, path=main)
28 ma.fillParticleList(
'pi+:a',
'pidProbabilityExpert(211, ALL) > 0.5', path=main)
30 ma.reconstructDecay(
'K_S0:all -> pi+:a pi-:a',
'', 0, path=main)
31 ma.matchMCTruth(
'K_S0:all', path=main)
34 main.add_module(
'TreeFitter',
35 particleList=
'K_S0:all',
37 massConstraintList=[],
38 massConstraintListParticlename=[],
39 expertUseReferencing=
True,
41 updateAllDaughters=
False)
43 ntupler = basf2.register_module(
'VariablesToNtuple')
44 ntupler.param(
'fileName', testFile.name)
45 ntupler.param(
'variables', [
'chiProb',
'M',
'isSignal'])
46 ntupler.param(
'particleList',
'K_S0:all')
47 main.add_module(ntupler)
51 ntuplefile = TFile(testFile.name)
52 ntuple = ntuplefile.Get(
'ntuple')
54 self.assertFalse(ntuple.GetEntries() == 0,
"Ntuple is empty.")
56 allBkg = ntuple.GetEntries(
"isSignal == 0")
57 allSig = ntuple.GetEntries(
"isSignal > 0")
59 truePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal > 0)")
60 falsePositives = ntuple.GetEntries(
"(chiProb > 0) && (isSignal == 0)")
62 mustBeZero = ntuple.GetEntries(
"(chiProb < {})".format(conf))
64 print(
"True fit survivors: {0} out of {1} true candidates".format(truePositives, allSig))
65 print(
"False fit survivors: {0} out of {1} false candidates".format(falsePositives, allBkg))
67 self.assertFalse(truePositives == 0,
"No signal survived the fit.")
69 self.assertTrue(falsePositives < 2586, f
"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
71 self.assertTrue(truePositives > 540,
"Signal rejection too high")
72 self.assertFalse(mustBeZero,
"We should have dropped all candidates with confidence level less than {}.".format(conf))
74 print(
"Test passed, cleaning up.")
76 if __name__ ==
'__main__':