Belle II Software  release-08-01-10
beamBkgHitRates_MC.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 from simulation import add_simulation
13 from pxd import add_pxd_reconstruction
14 from svd import add_svd_reconstruction
15 import os
16 import glob
17 import sys
18 
19 # ---------------------------------------------------------------------------------------
20 # Example of producing summary ntuple of beam background hit rates on MC using BG overlay
21 #
22 # This example is for nominal phase-3.
23 # For phase-2 or early phase-3 one should replace 'expList' with 1002 or 1003, resp.,
24 # and use the corresponding BG overlay samples (e.g. redefine BELLE2_BACKGROUND_DIR)
25 #
26 # usage: basf2 beamBkgHitRates_MC.py
27 # ---------------------------------------------------------------------------------------
28 
29 
30 if 'BELLE2_BACKGROUND_DIR' not in os.environ:
31  basf2.B2ERROR('BELLE2_BACKGROUND_DIR variable is not set - it must contain the path to BG overlay samples')
32  sys.exit()
33 
34 # background overlay files
35 bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
36 if len(bg) == 0:
37  basf2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
38  sys.exit()
39 
40 # Create path
41 main = basf2.create_path()
42 
43 # Set number of events to generate
44 eventinfosetter = basf2.register_module('EventInfoSetter')
45 eventinfosetter.param({'evtNumList': [1000], 'runList': [0], 'expList': [0]})
46 main.add_module(eventinfosetter)
47 
48 # Simulation
49 add_simulation(main, bkgfiles=bg, bkgOverlay=True)
50 
51 # additional modules, if needed for hit processing
52 main.add_module("ARICHFillHits")
53 main.add_module('TOPChannelMasker')
54 add_pxd_reconstruction(main)
55 add_svd_reconstruction(main)
56 main.add_module('SVDZeroSuppressionEmulator', SNthreshold=5, ShaperDigitsIN='SVDShaperDigitsZS5')
57 
58 # Bkg rate monitor: output to flat ntuple
59 # - all trigger types must be selected since no TRGSummary is given by the simulation
60 main.add_module('BeamBkgHitRateMonitor',
61  trgTypes=[],
62  svdShaperDigitsName='SVDShaperDigitsZS5',
63  outputFileName='beamBkgHitRates_MC.root')
64 
65 # Show progress of processing
66 main.add_module('Progress')
67 
68 # Process events
69 basf2.process(main)
70 
71 # Print call statistics
72 print(basf2.statistics)