Belle II Software development
genericBBbarWithBGOverlay.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 generic BBbar events with BG overlay.
21#
22# This example generates BBbar events using EvtGenInput module,
23# runs full simulation and digitization,
24# then adds measured BG to simulated data using BGOverlayExecutor module,
25# runs full reconstruction and finaly writes the results to mdst file.
26# ----------------------------------------------------------------------------------
27
28b2.set_log_level(b2.LogLevel.ERROR)
29
30if 'BELLE2_BACKGROUND_DIR' not in os.environ:
31 b2.B2ERROR('BELLE2_BACKGROUND_DIR variable is not set - it must contain the path to BG overlay samples')
32 sys.exit()
33
34# background overlay files
35bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
36if len(bg) == 0:
37 b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
38 sys.exit()
39
40# Create path
41main = b2.create_path()
42
43# Set number of events to generate
44eventinfosetter = b2.register_module('EventInfoSetter')
45eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
46main.add_module(eventinfosetter)
47
48# generate BBbar events
49evtgeninput = b2.register_module('EvtGenInput')
50main.add_module(evtgeninput)
51
52# Simulation
53add_simulation(main, bkgfiles=bg, bkgOverlay=True)
54
55# Set debug level for overlay executor module (all instances)
56paths = [main]
57for p in paths:
58 for m in p.modules():
59 paths += m.get_all_condition_paths()
60 if m.type() == "BGOverlayExecutor":
61 m.logging.log_level = b2.LogLevel.DEBUG # comment or remove to turn off
62 m.logging.debug_level = 20
63
64# Reconstruction
65add_reconstruction(main)
66
67# Mdst output
68add_mdst_output(main)
69
70# Show progress of processing
71progress = b2.register_module('Progress')
72main.add_module(progress)
73
74# Process events
75b2.process(main)
76
77# Print call statistics
78print(b2.statistics)