Belle II Software  release-05-01-25
test_mbc_cut_eff.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 import unittest
4 import os
5 import tempfile
6 import basf2
7 import b2test_utils
8 import modularAnalysis as ma
9 from ROOT import Belle2
10 from ROOT import TFile
11 from ROOT import TNtuple
12 
13 
14 class TestMbcEff(unittest.TestCase):
15  """The unit test"""
16 
17  def testMbcEff(self):
18  """Reconstruct stuff with tight Mbc cut."""
19 
20  testFile = tempfile.NamedTemporaryFile()
21 
22  main = basf2.create_path()
23 
24  inputfile = b2test_utils.require_file(
25  'analysis/1000_B_DstD0Kpi_skimmed.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  ma.fillParticleList('K+:a', 'pidProbabilityExpert(321, ALL) > 0.5', path=main)
30 
31  ma.reconstructDecay('D0:rec -> K-:a pi+:a', '', 0, path=main)
32  ma.reconstructDecay('D*+:rec -> D0:rec pi+:a', '', 0, path=main)
33  ma.reconstructDecay('B0:rec -> D*+:rec pi-:a', ' InvM > 5.27', 0, path=main)
34  ma.matchMCTruth('B0:rec', path=main)
35 
36  ntupler = basf2.register_module('VariablesToNtuple')
37  ntupler.param('fileName', testFile.name)
38  ntupler.param('variables', ['isSignal'])
39  ntupler.param('particleList', 'B0:rec')
40  main.add_module(ntupler)
41 
42  basf2.process(main)
43 
44  ntuplefile = TFile(testFile.name)
45  ntuple = ntuplefile.Get('ntuple')
46 
47  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
48 
49  allBkg = ntuple.GetEntries("isSignal == 0")
50  allSig = ntuple.GetEntries("isSignal > 0")
51 
52  print("True candidates {0}".format(allSig))
53  print("False candidates {0}".format(allBkg))
54 
55  sig_expected = 136
56  bkg_expected = 1630
57 
58  self.assertTrue(
59  allSig == sig_expected,
60  f"Mbc cut efficency has changed! n_sig expected: {sig_expected} found: {allSig}.")
61  self.assertTrue(allBkg == bkg_expected, f"Mbc cut background has changed! n_bkg expected: {bkg_expected} found: {allBkg}.")
62 
63  print("Test passed, cleaning up.")
64 
65 
66 if __name__ == '__main__':
67  unittest.main()
test_mbc_cut_eff.TestMbcEff.testMbcEff
def testMbcEff(self)
Definition: test_mbc_cut_eff.py:17
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
test_mbc_cut_eff.TestMbcEff
Definition: test_mbc_cut_eff.py:14
b2test_utils.require_file
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:47