Belle II Software development
genericBBbarWithBGMixing.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import os
13import sys
14from simulation import add_simulation
15from reconstruction import add_reconstruction
16from mdst import add_mdst_output
17import glob
18
19# ----------------------------------------------------------------------------------
20# Example of simulation/reconstruction of generic BBbar events with beam background.
21#
22# This example generates BBbar events using EvtGenInput module, runs full simulation
23# with BG mixing using BeamBkgMixer module, then runs full reconstruction and finaly
24# writes the results to mdst file.
25# ----------------------------------------------------------------------------------
26
27b2.set_log_level(b2.LogLevel.ERROR)
28
29if 'BELLE2_BACKGROUND_MIXING_DIR' not in os.environ:
30 b2.B2ERROR('BELLE2_BACKGROUND_MIXING_DIR variable is not set - it must contain the path to BG mixing samples')
31 sys.exit()
32
33# background (collision) files
34bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
35if len(bg) == 0:
36 b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
37 sys.exit()
38
39# Create path
40main = b2.create_path()
41
42# Set number of events to generate
43eventinfosetter = b2.register_module('EventInfoSetter')
44eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
45main.add_module(eventinfosetter)
46
47# generate BBbar events
48evtgeninput = b2.register_module('EvtGenInput')
49main.add_module(evtgeninput)
50
51# Simulation
52add_simulation(main, bkgfiles=bg, bkgOverlay=False)
53
54# Reconstruction
55add_reconstruction(main)
56
57# Mdst output
58add_mdst_output(main)
59
60# Show progress of processing
61progress = b2.register_module('Progress')
62main.add_module(progress)
63
64# Process events
65b2.process(main)
66
67# Print call statistics
68print(b2.statistics)