Belle II Software  release-08-01-10
treeFit_referenced_ignore_klong.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import unittest
12 import tempfile
13 import basf2
14 import b2test_utils
15 import modularAnalysis as ma
16 from stdKlongs import stdKlongs
17 from ROOT import TFile
18 
19 
20 class TestTreeFits(unittest.TestCase):
21  """The unit test case for TreeFitter"""
22 
23  def testFit(self):
24  """Run the test fit"""
25 
26  testFile = tempfile.NamedTemporaryFile()
27 
28  main = basf2.create_path()
29 
30  ma.inputMdstList([basf2.find_file('B02JpsiKL_Jpsi2mumu.root', 'examples', False)], path=main)
31 
32  ma.fillParticleList('mu+:sig', 'muonID > 0.5', path=main)
33  stdKlongs('allklm', path=main)
34 
35  ma.reconstructDecay('J/psi:mumu -> mu-:sig mu+:sig', '3.08 < M < 3.12', path=main)
36  ma.reconstructMissingKlongDecayExpert('B0:sig -> J/psi:mumu K_L0:allklm', '',
37  path=main,
38  recoList="_reco")
39  ma.matchMCTruth('B0:sig', path=main)
40 
41  conf = -1
42  main.add_module('TreeFitter',
43  particleList='B0:sig',
44  confidenceLevel=conf,
45  massConstraintList=[],
46  massConstraintListParticlename=[],
47  expertUseReferencing=True,
48  ipConstraint=True,
49  updateAllDaughters=True,
50  ignoreFromVertexFit='B0 -> J/psi ^K_L0')
51 
52  ntupler = basf2.register_module('VariablesToNtuple')
53  ntupler.param('fileName', testFile.name)
54  ntupler.param('variables', ['chiProb', 'isSignal', 'Mbc', 'deltaE', 'dz'])
55  ntupler.param('particleList', 'B0:sig')
56  main.add_module(ntupler)
57 
58  basf2.process(main)
59 
60  ntuplefile = TFile(testFile.name)
61  ntuple = ntuplefile.Get('ntuple')
62 
63  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
64 
65  allSig = ntuple.GetEntries("isSignal == 1")
66  allBkg = ntuple.GetEntries("isSignal == 0")
67 
68  truePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 1)")
69  falsePositives = ntuple.GetEntries("(chiProb > 0) && (isSignal == 0)")
70 
71  SigDeltaEReasonable = ntuple.GetEntries("isSignal==1 && deltaE<0.1")
72 
73  print(f"True fit survivors: {truePositives} out of {allSig} true candidates")
74  print(f"False fit survivors: {falsePositives} out of {allBkg} false candidates")
75 
76  self.assertTrue(falsePositives < 2041, "Background rejection too small.")
77  self.assertTrue(truePositives > 522, "Signal rejection too high")
78 
79  print(f"Signal events with good deltaE values {SigDeltaEReasonable}")
80  self.assertTrue(SigDeltaEReasonable > 463, "Signal kinematics is wrongly reconstructed too much")
81 
82  print("Test passed, cleaning up.")
83 
84 
85 if __name__ == '__main__':
87  unittest.main()
def clean_working_directory()
Definition: __init__.py:189