Belle II Software development
beamBkgMixer.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import os
13import sys
14import glob
15
16# ----------------------------------------------------------------------------------
17# This example shows some of the possibilities to steer BG mixing with BeamBkgMixer.
18#
19# For simplicity no particle generator and/or geant simulation is included,
20# digitization and event reconstruction is also not done. The output root file
21# will contain SimHits from BG.
22#
23# Note: in multiprocessing mode put BG mixer in the path first then FullSim
24# ----------------------------------------------------------------------------------
25
26b2.set_log_level(b2.LogLevel.INFO)
27
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# define background (collision) files
34# glob.glob is the prefered way to get the list of files:
35# (the directory must include only BG files!)
36
37bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
38if len(bg) == 0:
39 b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
40 sys.exit()
41
42# alternative: you can specify files explicitely
43#
44# dir = '/sw/belle2/bkg/' # change the directory name if you don't run on KEKCC
45# bg = [
46# dir + 'Coulomb_HER_100us.root',
47# dir + 'Coulomb_LER_100us.root',
48# dir + 'RBB_HER_100us.root',
49# dir + 'RBB_LER_100us.root',
50# dir + 'Touschek_HER_100us.root',
51# dir + 'Touschek_LER_100us.root',
52# ]
53# change the file names if differ, remove some or add some more files
54
55# Create path
56main = b2.create_path()
57
58# Set number of events to generate
59eventinfosetter = b2.register_module('EventInfoSetter')
60eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
61main.add_module(eventinfosetter)
62
63# Gearbox: access to database (xml files)
64gearbox = b2.register_module('Gearbox')
65main.add_module(gearbox)
66
67# Geometry
68geometry = b2.register_module('Geometry')
69main.add_module(geometry)
70
71# Simulate the EventLevelTriggerTimeInfo (empty object for now)
72simulateEventLevelTriggerTimeInfo = b2.register_module('SimulateEventLevelTriggerTimeInfo')
73main.add_module(simulateEventLevelTriggerTimeInfo)
74
75# particle generator can be put here
76
77# Mix beam background
78bkgmixer = b2.register_module('BeamBkgMixer')
79bkgmixer.param('backgroundFiles', bg) # specify BG files
80bkgmixer.param('components', ['CDC', 'TOP', 'ECL']) # mix BG only for those components
81bkgmixer.param('minTime', -5000) # set time window start time [ns]
82bkgmixer.param('maxTime', 10000) # set time window stop time [ns]
83bkgmixer.param('scaleFactors', [('Coulomb_LER', 1.05), ('Coulomb_HER', 1.08), ('RBB_LER', 0.8)]) # scale rates of some backgrounds
84main.add_module(bkgmixer)
85
86# FullSim, digitizers, clusterizers and reconstruction modules can be put here
87
88# Output
89output = b2.register_module('RootOutput')
90output.param('outputFileName', 'testMixer.root')
91main.add_module(output)
92
93# Show progress of processing
94progress = b2.register_module('Progress')
95main.add_module(progress)
96
97# Process events
98b2.process(main)
99
100# Print call statistics
101print(b2.statistics)