Belle II Software development
test_mbc_cut_eff.py
1#!/usr/bin/env python3
2
3
10import unittest
11import tempfile
12import basf2
13import b2test_utils
14import modularAnalysis as ma
15from ROOT import TFile
16
17
18class TestMbcEff(unittest.TestCase):
19 """The unit test"""
20
21 def testMbcEff(self):
22 """Reconstruct stuff with tight Mbc cut."""
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.27', 0, path=main)
38 ma.matchMCTruth('B0:rec', path=main)
39
40 ntupler = basf2.register_module('VariablesToNtuple')
41 ntupler.param('fileName', testFile.name)
42 ntupler.param('variables', ['isSignal'])
43 ntupler.param('particleList', 'B0:rec')
44 main.add_module(ntupler)
45
46 basf2.process(main)
47
48 ntuplefile = TFile(testFile.name)
49 ntuple = ntuplefile.Get('ntuple')
50
51 self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
52
53 allBkg = ntuple.GetEntries("isSignal == 0")
54 allSig = ntuple.GetEntries("isSignal > 0")
55
56 print(f"True candidates {allSig}")
57 print(f"False candidates {allBkg}")
58
59 sig_expected = 136
60 bkg_expected = 1630
61
62 self.assertTrue(
63 allSig == sig_expected,
64 f"Mbc cut efficiency has changed! n_sig expected: {sig_expected} found: {allSig}.")
65 self.assertTrue(allBkg == bkg_expected, f"Mbc cut background has changed! n_bkg expected: {bkg_expected} found: {allBkg}.")
66
67 print("Test passed, cleaning up.")
68
69
70if __name__ == '__main__':
72 unittest.main()
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:189