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