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