Belle II Software  release-08-01-10
genericBBbarWithBGMixing.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 import os
13 import sys
14 from simulation import add_simulation
15 from reconstruction import add_reconstruction
16 from mdst import add_mdst_output
17 import glob
18 
19 # ----------------------------------------------------------------------------------
20 # Example of simulation/reconstruction of generic BBbar events with beam background.
21 #
22 # This example generates BBbar events using EvtGenInput module, runs full simulation
23 # with BG mixing using BeamBkgMixer module, then runs full reconstruction and finaly
24 # writes the results to mdst file.
25 # ----------------------------------------------------------------------------------
26 
27 b2.set_log_level(b2.LogLevel.ERROR)
28 
29 if 'BELLE2_BACKGROUND_MIXING_DIR' not in os.environ:
30  b2.B2ERROR('BELLE2_BACKGROUND_MIXING_DIR variable is not set - it must contain the path to BG mixing samples')
31  sys.exit()
32 
33 # background (collision) files
34 bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
35 if len(bg) == 0:
36  b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_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 # generate BBbar events
48 evtgeninput = b2.register_module('EvtGenInput')
49 main.add_module(evtgeninput)
50 
51 # Simulation
52 add_simulation(main, bkgfiles=bg, bkgOverlay=False)
53 
54 # Reconstruction
55 add_reconstruction(main)
56 
57 # Mdst output
58 add_mdst_output(main)
59 
60 # Show progress of processing
61 progress = b2.register_module('Progress')
62 main.add_module(progress)
63 
64 # Process events
65 b2.process(main)
66 
67 # Print call statistics
68 print(b2.statistics)