Belle II Software  release-08-01-10
onlyBGMixing.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 events with beam background only.
21 #
22 # This example runs full simulation of beam BG only events using BeamBkgMixer module,
23 # then runs full reconstruction and finaly writes the results to mdst file.
24 # ----------------------------------------------------------------------------------
25 
26 b2.set_log_level(b2.LogLevel.ERROR)
27 
28 if 'BELLE2_BACKGROUND_MIXING_DIR' not in os.environ:
29  b2.B2ERROR('BELLE2_BACKGROUND_MIXING_DIR variable is not set - it must contain the path to BG mixing samples')
30  sys.exit()
31 
32 # background (collision) files
33 bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
34 if len(bg) == 0:
35  b2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
36  sys.exit()
37 
38 # Create path
39 main = b2.create_path()
40 
41 # Set number of events to generate
42 eventinfosetter = b2.register_module('EventInfoSetter')
43 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
44 main.add_module(eventinfosetter)
45 
46 # Simulation
47 add_simulation(main, bkgfiles=bg, bkgOverlay=False)
48 
49 # Reconstruction
50 add_reconstruction(main)
51 
52 # Mdst output
53 add_mdst_output(main)
54 
55 # Show progress of processing
56 progress = b2.register_module('Progress')
57 main.add_module(progress)
58 
59 # Process events
60 b2.process(main)
61 
62 # Print call statistics
63 print(b2.statistics)