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