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