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