Belle II Software  release-05-01-25
test_reconstructmcdecay.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 import unittest
4 import os
5 import tempfile
6 from basf2 import create_path, register_module
7 import b2test_utils
8 from modularAnalysis import fillParticleListFromMC, reconstructMCDecay, inputMdst
9 from ROOT import Belle2
10 from ROOT import TFile
11 from ROOT import TNtuple
12 
13 
14 class TestNewMCDecayFinder(unittest.TestCase):
15  """The unit test"""
16 
18  """Reconstruct/search for an MC decay chain using the reconstructMCDecay tool."""
19 
20  testFile = tempfile.NamedTemporaryFile()
21 
22  main = create_path()
23 
24  inputfile = b2test_utils.require_file(
25  'analysis/1000_B_DstD0Kpi_skimmed.root', 'validation', py_case=self)
26  inputMdst('default', inputfile, path=main)
27 
28  fillParticleListFromMC('gamma:MC', 'mcPrimary', path=main)
29  fillParticleListFromMC('K+:MC', 'mcPrimary', path=main)
30  fillParticleListFromMC('pi+:MC', 'mcPrimary', path=main)
31 
33  'B0:DstD0Kpi =direct=> [D*+:MC =direct=> [D0:MC =direct=> K-:MC pi+:MC ] pi+:MC] pi-:MC',
34  '',
35  path=main)
36 
37  ntupler = register_module('VariablesToNtuple')
38  ntupler.param('fileName', testFile.name)
39  ntupler.param('variables', ['isSignal'])
40  ntupler.param('particleList', 'B0:DstD0Kpi')
41  main.add_module(ntupler)
42 
44 
45  ntuplefile = TFile(testFile.name)
46  ntuple = ntuplefile.Get('ntuple')
47 
48  self.assertFalse(ntuple.GetEntries() == 0, "Ntuple is empty.")
49 
50  allBkg = ntuple.GetEntries("isSignal == 0")
51  allSig = ntuple.GetEntries("isSignal > 0")
52 
53  print("True candidates {0}".format(allSig))
54  print("False candidates {0}".format(allBkg))
55 
56  sig_expected = 406
57 
58  self.assertTrue(
59  allSig == sig_expected,
60  f"n_sig expected: {sig_expected} found: {sig_expected}.")
61  self.assertTrue(allBkg == 0, f"n_bkg expected 0, found: {allBkg}.")
62 
63  print("Test passed, cleaning up.")
64 
65 
66 if __name__ == '__main__':
67  unittest.main()
reconstructMCDecay
Definition: reconstructMCDecay.py:1
test_reconstructmcdecay.TestNewMCDecayFinder.testNewMCDecayFinder
def testNewMCDecayFinder(self)
Definition: test_reconstructmcdecay.py:17
test_reconstructmcdecay.TestNewMCDecayFinder
Definition: test_reconstructmcdecay.py:14
b2test_utils.safe_process
def safe_process(*args, **kwargs)
Definition: __init__.py:224
b2test_utils.require_file
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:47