Belle II Software  release-08-01-10
TestTreeFits Class Reference
Inheritance diagram for TestTreeFits:
Collaboration 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_charged_tree.py.

Member Function Documentation

◆ testFit()

def testFit (   self)
Run the test fit

Definition at line 21 of file treeFit_referenced_charged_tree.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_DstD0Kpi_skimmed.root', 'validation', py_case=self)
30  ma.inputMdst(inputfile, path=main)
31 
32  ma.fillParticleList('pi+:a', 'pionID > 0.5', path=main)
33  ma.fillParticleList('K+:a', 'kaonID > 0.5', path=main)
34 
35  ma.reconstructDecay('D0:rec -> K-:a pi+:a', '', 0, path=main)
36  ma.reconstructDecay('D*+:rec -> D0:rec pi+:a', '', 0, path=main)
37  ma.reconstructDecay('B0:rec -> D*+:rec pi-:a', ' InvM > 5', 0, path=main)
38  ma.matchMCTruth('B0:rec', path=main)
39 
40  conf = 0
41  main.add_module('TreeFitter',
42  particleList='B0:rec',
43  confidenceLevel=conf,
44  massConstraintList=[],
45  massConstraintListParticlename=[],
46  expertUseReferencing=True,
47  ipConstraint=False,
48  updateAllDaughters=False)
49 
50  ntupler = basf2.register_module('VariablesToNtuple')
51  ntupler.param('fileName', testFile.name)
52  ntupler.param('variables', ['chiProb', 'M', 'isSignal'])
53  ntupler.param('particleList', 'B0:rec')
54  main.add_module(ntupler)
55 
56  basf2.process(main)
57 
58  ntuplefile = TFile(testFile.name)
59  ntuple = ntuplefile.Get('ntuple')
60 
61  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
62 
63  allBkg = ntuple.GetEntries("isSignal == 0")
64  allSig = ntuple.GetEntries("isSignal > 0")
65 
66  truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal > 0)")
67  falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
68 
69  mustBeZero = ntuple.GetEntries(f"(chiProb < {conf})")
70 
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 
74  self.assertFalse(truePositives == 0, "No signal survived the fit.")
75 
76  self.assertTrue(falsePositives == 1598, f"Background rejection {falsePositives} out of {allBkg}")
77 
78  self.assertTrue(truePositives == 156, f"Signal rejection too high {truePositives} out of {allSig}")
79  self.assertFalse(mustBeZero, f"We should have dropped all candidates with confidence level less than {conf}.")
80 
81  print("Test passed, cleaning up.")
82 
83 
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54

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