Belle II Software development
TestTreeFits Class Reference
Inheritance diagram for TestTreeFits:

Public Member Functions

def testFit (self)
 

Detailed Description

The unit test case for TreeFitter

Definition at line 18 of file treeFit_referenced_single_vertex.py.

Member Function Documentation

◆ testFit()

def testFit (   self)
Run the test fit

Definition at line 21 of file treeFit_referenced_single_vertex.py.

21 def testFit(self):
22 """Run the test fit"""
23
24 testFile = tempfile.NamedTemporaryFile()
25
26 main = basf2.create_path()
27
28 inputfile = b2test_utils.require_file(
29 'analysis/1000_B_Jpsi_ks_pipi.root', 'validation', py_case=self)
30 ma.inputMdst(inputfile, path=main)
31
32 ma.fillParticleList('mu+', 'muonID > 0.5', path=main)
33
34 ma.reconstructDecay('J/psi:all -> mu+ mu-', '', 0, path=main)
35 ma.matchMCTruth('J/psi:all', path=main)
36
37 conf = 0
38 main.add_module('TreeFitter',
39 particleList='J/psi:all',
40 confidenceLevel=conf,
41 massConstraintList=[],
42 massConstraintListParticlename=[],
43 expertUseReferencing=True,
44 ipConstraint=False,
45 updateAllDaughters=False)
46
47 ntupler = basf2.register_module('VariablesToNtuple')
48 ntupler.param('fileName', testFile.name)
49 ntupler.param('variables', ['chiProb', 'M', 'isSignal'])
50 ntupler.param('particleList', 'J/psi:all')
51 main.add_module(ntupler)
52
53 basf2.process(main)
54
55 ntuplefile = TFile(testFile.name)
56 ntuple = ntuplefile.Get('ntuple')
57
58 self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
59
60 allBkg = ntuple.GetEntries("isSignal == 0")
61 allSig = ntuple.GetEntries("isSignal > 0")
62
63 truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal > 0)")
64 falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
65
66 mustBeZero = ntuple.GetEntries(f"(chiProb < {conf})")
67
68 print(f"True fit survivors: {truePositives} out of {allSig} true candidates")
69 print(f"False fit survivors: {falsePositives} out of {allBkg} false candidates")
70
71 self.assertFalse(truePositives == 0, "No signal survived the fit.")
72
73 self.assertTrue(falsePositives <= 1828, f"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
74
75 self.assertTrue(truePositives == 745, "Signal rejection too high")
76
77 self.assertFalse(mustBeZero, f"We should have dropped all candidates with confidence level less than {conf}.")
78
79 print("Test passed, cleaning up.")
80
81
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54

The documentation for this class was generated from the following file: