Belle II Software  release-05-01-25
genericBBbarWithBGMixing.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from basf2 import *
5 import os
6 from simulation import add_simulation
7 from reconstruction import add_reconstruction
8 from reconstruction import add_mdst_output
9 import glob
10 
11 # ----------------------------------------------------------------------------------
12 # Example of simulation/reconstruction of generic BBbar events with beam background.
13 #
14 # This example generates BBbar events using EvtGenInput module, runs full simulation
15 # with BG mixing using BeamBkgMixer module, then runs full reconstruction and finaly
16 # writes the results to mdst file.
17 # ----------------------------------------------------------------------------------
18 
19 set_log_level(LogLevel.ERROR)
20 
21 if 'BELLE2_BACKGROUND_MIXING_DIR' not in os.environ:
22  B2ERROR('BELLE2_BACKGROUND_MIXING_DIR variable is not set - it must contain the path to BG mixing samples')
23  sys.exit()
24 
25 # background (collision) files
26 bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
27 if len(bg) == 0:
28  B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
29  sys.exit()
30 
31 # Create path
32 main = create_path()
33 
34 # Set number of events to generate
35 eventinfosetter = register_module('EventInfoSetter')
36 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
37 main.add_module(eventinfosetter)
38 
39 # generate BBbar events
40 evtgeninput = register_module('EvtGenInput')
41 main.add_module(evtgeninput)
42 
43 # Simulation
44 add_simulation(main, bkgfiles=bg, bkgOverlay=False)
45 
46 # Reconstruction
47 add_reconstruction(main)
48 
49 # Mdst output
50 add_mdst_output(main)
51 
52 # Show progress of processing
53 progress = register_module('Progress')
54 main.add_module(progress)
55 
56 # Process events
57 process(main)
58 
59 # Print call statistics
60 print(statistics)