Belle II Software development
beamBkgHitRates_MC.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from simulation import add_simulation
13from pxd import add_pxd_reconstruction
14from svd import add_svd_reconstruction
15import os
16import glob
17import 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
30if '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
35bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
36if len(bg) == 0:
37 basf2.B2ERROR('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
38 sys.exit()
39
40# Create path
41main = basf2.create_path()
42
43# Set number of events to generate
44eventinfosetter = basf2.register_module('EventInfoSetter')
45eventinfosetter.param({'evtNumList': [1000], 'runList': [0], 'expList': [0]})
46main.add_module(eventinfosetter)
47
48# Simulation
49add_simulation(main, bkgfiles=bg, bkgOverlay=True)
50
51# additional modules, if needed for hit processing
52main.add_module("ARICHFillHits")
53main.add_module('TOPChannelMasker')
54add_pxd_reconstruction(main)
55add_svd_reconstruction(main)
56main.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
60main.add_module('BeamBkgHitRateMonitor',
61 trgTypes=[],
62 svdShaperDigitsName='SVDShaperDigitsZS5',
63 outputFileName='beamBkgHitRates_MC.root')
64
65# Show progress of processing
66main.add_module('Progress')
67
68# Process events
69basf2.process(main)
70
71# Print call statistics
72print(basf2.statistics)