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