Belle II Software  release-05-01-25
onlyBGOverlay.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 from reconstruction import add_reconstruction
8 from reconstruction import add_mdst_output
9 import glob
10 import sys
11 
12 # ---------------------------------------------------------------------------------
13 # Example of simulation/reconstruction of events with beam background only.
14 #
15 # This example runs full simulation of beam BG only events using BGOverlayExecutor,
16 # then runs full reconstruction and finaly writes the results to mdst file.
17 # ---------------------------------------------------------------------------------
18 
19 set_log_level(LogLevel.ERROR)
20 
21 if 'BELLE2_BACKGROUND_DIR' not in os.environ:
22  B2ERROR('BELLE2_BACKGROUND_DIR variable is not set - it must contain the path to BG overlay samples')
23  sys.exit()
24 
25 # background overlay files
26 bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
27 if len(bg) == 0:
28  B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
29  sys.exit()
30 
31 # Create path
32 main = create_path()
33 
34 # Set number of events to generate
35 eventinfosetter = register_module('EventInfoSetter')
36 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
37 main.add_module(eventinfosetter)
38 
39 # Simulation
40 add_simulation(main, bkgfiles=bg, bkgOverlay=True)
41 
42 # set debug level for overlay executor module
43 for m in main.modules():
44  if m.type() == "BGOverlayExecutor":
45  m.logging.log_level = LogLevel.DEBUG # comment or remove to turn off
46  m.logging.debug_level = 100
47  break
48 
49 # Reconstruction
50 add_reconstruction(main)
51 
52 # Mdst output
53 add_mdst_output(main)
54 
55 # Show progress of processing
56 progress = register_module('Progress')
57 main.add_module(progress)
58 
59 # Process events
60 process(main)
61 
62 # Print call statistics
63 print(statistics)