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