Belle II Software  release-08-01-10
evtgenB2Kpi.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ----------------------------------------------------------------------------------
13 # Example of generating signal MC (B0 -> K- pi+, one of the benchmarks for TOP)
14 # Beam BG is added if variable BELLE2_BACKGROUND_DIR is set with the path to BG files
15 # At KEKCC the path to BG files is /sw/belle2/bkg
16 # Two outputs are provided:
17 # - mdst format, suitable for physics studies (analysis package)
18 # - flat ntuple, suitable for TOP efficiency studies
19 # ----------------------------------------------------------------------------------
20 
21 import basf2 as b2
22 import os
23 from simulation import add_simulation
24 from reconstruction import add_reconstruction
25 from mdst import add_mdst_output
26 import glob
27 
28 # Suppress messages and warnings during processing:
29 b2.set_log_level(b2.LogLevel.ERROR)
30 
31 # Create path
32 main = b2.create_path()
33 
34 # Number of events to be generated
35 eventinfosetter = b2.register_module('EventInfoSetter')
36 eventinfosetter.param('evtNumList', [100])
37 main.add_module(eventinfosetter)
38 
39 # Event generator (B0 -> K+pi- + cc, other B0 generic)
40 evtgeninput = b2.register_module('EvtGenInput')
41 evtgeninput.param('userDECFile',
42  b2.find_file('top/examples/B2Kpi.dec'))
43 main.add_module(evtgeninput)
44 
45 # Detector simulation
46 bg = None
47 if 'BELLE2_BACKGROUND_DIR' in os.environ:
48  bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
49 add_simulation(main, bkgfiles=bg)
50 
51 # Reconstruction
52 add_reconstruction(main)
53 
54 # Output to mdst
55 add_mdst_output(main, filename='evtgenB2Kpi.mdst.root')
56 
57 # Output to a flat ntuple with TOP likelihoods, track info and MC truth
58 ntuple = b2.register_module('TOPNtuple')
59 ntuple.param('outputFileName', 'ntupleB2Kpi.root')
60 main.add_module(ntuple)
61 
62 # Show progress of processing
63 progress = b2.register_module('Progress')
64 main.add_module(progress)
65 
66 # Process events
67 b2.process(main)
68 
69 # Print call statistics
70 print(b2.statistics)