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