Belle II Software  release-08-01-10
beamBkgMixerSteering.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 import os
13 import sys
14 from simulation import add_simulation
15 import glob
16 
17 # ----------------------------------------------------------------------------------
18 # Example of BeamBkgMixer steering after add_simulation
19 # ----------------------------------------------------------------------------------
20 
21 b2.set_log_level(b2.LogLevel.INFO)
22 
23 if '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
28 bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
29 if len(bg) == 0:
30  b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
31  sys.exit()
32 
33 # Create path
34 main = b2.create_path()
35 
36 # Set number of events to generate
37 eventinfosetter = b2.register_module('EventInfoSetter')
38 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
39 main.add_module(eventinfosetter)
40 
41 # generate BBbar events
42 evtgeninput = b2.register_module('EvtGenInput')
43 main.add_module(evtgeninput)
44 
45 # Simulation
46 add_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
50 for m in main.modules():
51  if m.type() == "BeamBkgMixer":
52  m.param('overallScaleFactor', 2.5)
53  m.param('maxEdepECL', 0)
54  break
55 else:
56  b2.B2ERROR("Could not find module of type 'BeamBkgMixer'")
57 
58 # Show progress of processing
59 progress = b2.register_module('Progress')
60 main.add_module(progress)
61 
62 # Process events
63 b2.process(main)
64 
65 # Print call statistics
66 print(b2.statistics)