Belle II Software development
beamBkgMixerSteering.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import os
13import sys
14from simulation import add_simulation
15import glob
16
17# ----------------------------------------------------------------------------------
18# Example of BeamBkgMixer steering after add_simulation
19# ----------------------------------------------------------------------------------
20
21b2.set_log_level(b2.LogLevel.INFO)
22
23if 'BELLE2_BACKGROUND_MIXING_DIR' not in os.environ:
24 b2.B2ERROR('BELLE2_BACKGROUND_MIXING_DIR variable is not set - it must contain the path to BG mixing samples')
25 sys.exit()
26
27# background (collision) files
28bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
29if len(bg) == 0:
30 b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
31 sys.exit()
32
33# Create path
34main = b2.create_path()
35
36# Set number of events to generate
37eventinfosetter = b2.register_module('EventInfoSetter')
38eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
39main.add_module(eventinfosetter)
40
41# generate BBbar events
42evtgeninput = b2.register_module('EvtGenInput')
43main.add_module(evtgeninput)
44
45# Simulation
46add_simulation(main, bkgfiles=bg, bkgOverlay=False)
47
48# Search for BeamBkgMixer in the path,
49# then set overall scale factor to 2.5 and remove cut on ECL deposited energy
50for m in main.modules():
51 if m.type() == "BeamBkgMixer":
52 m.param('overallScaleFactor', 2.5)
53 m.param('maxEdepECL', 0)
54 break
55else:
56 b2.B2ERROR("Could not find module of type 'BeamBkgMixer'")
57
58# Show progress of processing
59progress = b2.register_module('Progress')
60main.add_module(progress)
61
62# Process events
63b2.process(main)
64
65# Print call statistics
66print(b2.statistics)