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