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