Belle II Software  release-05-01-25
beamBkgMixer.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from basf2 import *
5 import os
6 import glob
7 
8 # ----------------------------------------------------------------------------------
9 # This example shows some of the possibilities to steer BG mixing with BeamBkgMixer.
10 #
11 # For simplicity no particle generator and/or geant simulation is included,
12 # digitization and event reconstruction is also not done. The output root file
13 # will contain SimHits from BG.
14 #
15 # Note: in multiprocessing mode put BG mixer in the path first then FullSim
16 # ----------------------------------------------------------------------------------
17 
18 set_log_level(LogLevel.INFO)
19 
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 # define background (collision) files
26 # glob.glob is the prefered way to get the list of files:
27 # (the directory must include only BG files!)
28 
29 bg = glob.glob(os.environ['BELLE2_BACKGROUND_MIXING_DIR'] + '/*.root')
30 if len(bg) == 0:
31  B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_MIXING_DIR'])
32  sys.exit()
33 
34 # alternative: you can specify files explicitely
35 #
36 # dir = '/sw/belle2/bkg/' # change the directory name if you don't run on KEKCC
37 # bg = [
38 # dir + 'Coulomb_HER_100us.root',
39 # dir + 'Coulomb_LER_100us.root',
40 # dir + 'RBB_HER_100us.root',
41 # dir + 'RBB_LER_100us.root',
42 # dir + 'Touschek_HER_100us.root',
43 # dir + 'Touschek_LER_100us.root',
44 # ]
45 # change the file names if differ, remove some or add some more files
46 
47 # Create path
48 main = create_path()
49 
50 # Set number of events to generate
51 eventinfosetter = register_module('EventInfoSetter')
52 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
53 main.add_module(eventinfosetter)
54 
55 # Gearbox: access to database (xml files)
56 gearbox = register_module('Gearbox')
57 main.add_module(gearbox)
58 
59 # Geometry
60 geometry = register_module('Geometry')
61 main.add_module(geometry)
62 
63 # particle generator can be put here
64 
65 # Mix beam background
66 bkgmixer = register_module('BeamBkgMixer')
67 bkgmixer.param('backgroundFiles', bg) # specify BG files
68 bkgmixer.param('components', ['CDC', 'TOP', 'ECL']) # mix BG only for those components
69 bkgmixer.param('minTime', -5000) # set time window start time [ns]
70 bkgmixer.param('maxTime', 10000) # set time window stop time [ns]
71 bkgmixer.param('scaleFactors', [('Coulomb_LER', 1.05), ('Coulomb_HER', 1.08), ('RBB_LER', 0.8)]) # scale rates of some backgrounds
72 main.add_module(bkgmixer)
73 
74 # FullSim, digitizers, clusterizers and reconstruction modules can be put here
75 
76 # Output
77 output = register_module('RootOutput')
78 output.param('outputFileName', 'testMixer.root')
79 main.add_module(output)
80 
81 # Show progress of processing
82 progress = register_module('Progress')
83 main.add_module(progress)
84 
85 # Process events
86 process(main)
87 
88 # Print call statistics
89 print(statistics)