Belle II Software  release-05-01-25
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 14 of file treeFit_referenced_single_displaced_vertex.py.

Member Function Documentation

◆ testFit()

def testFit (   self)
Run the test fit

Definition at line 17 of file treeFit_referenced_single_displaced_vertex.py.

17  def testFit(self):
18  """Run the test fit"""
19 
20  testFile = tempfile.NamedTemporaryFile()
21 
22  main = basf2.create_path()
23 
24  inputfile = b2test_utils.require_file(
25  'analysis/1000_B_Jpsi_ks_pipi.root', 'validation', py_case=self)
26  ma.inputMdst('default', inputfile, path=main)
27 
28  ma.fillParticleList('pi+:a', 'pidProbabilityExpert(211, ALL) > 0.5', path=main)
29 
30  ma.reconstructDecay('K_S0:all -> pi+:a pi-:a', '', 0, path=main)
31  ma.matchMCTruth('K_S0:all', path=main)
32 
33  conf = 0
34  main.add_module('TreeFitter',
35  particleList='K_S0:all',
36  confidenceLevel=conf,
37  massConstraintList=[],
38  massConstraintListParticlename=[],
39  expertUseReferencing=True,
40  ipConstraint=False,
41  updateAllDaughters=False)
42 
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)
48 
49  basf2.process(main)
50 
51  ntuplefile = TFile(testFile.name)
52  ntuple = ntuplefile.Get('ntuple')
53 
54  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
55 
56  allBkg = ntuple.GetEntries("isSignal == 0")
57  allSig = ntuple.GetEntries("isSignal > 0")
58 
59  truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal > 0)")
60  falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
61 
62  mustBeZero = ntuple.GetEntries("(chiProb < {})".format(conf))
63 
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))
66 
67  self.assertFalse(truePositives == 0, "No signal survived the fit.")
68 
69  self.assertTrue(falsePositives < 2586, f"Too many false positives: {falsePositives} out of {allBkg} total bkg events.")
70 
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))
73 
74  print("Test passed, cleaning up.")
75 

The documentation for this class was generated from the following file:
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
b2test_utils.require_file
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:47