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