Belle II Software development
beamBkgHitRates.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------
12# Steering file for producing summary ntuple of beam background hit rates
13#
14# usage: basf2 beamBkgHitRates.py expNo runNo globalTag [outputFolder]
15# ---------------------------------------------------------------------------------------
16
17import basf2
18import sys
19import glob
20from rawdata import add_unpackers
21from svd import add_svd_reconstruction
22from ROOT import Belle2
23
24# Argument parsing
25argvs = sys.argv
26if len(argvs) < 4:
27 print("usage: basf2", argvs[0], "expNo runNo globalTag [outputFolder]")
28 sys.exit()
29
30expNo = 'e' + '{:0=4d}'.format(int(argvs[1]))
31runNo = 'r' + '{:0=5d}'.format(int(argvs[2]))
32global_tag = argvs[3]
33trigTypes = [5, 7] # trigger types for event selection (see TRGSummary.h)
34
35indir = '/hsm/belle2/bdata/Data/Raw/' + expNo + '/' + runNo + '/sub00'
36files = sorted(glob.glob(indir + '/*.root'))
37if len(files) == 0:
38 basf2.B2ERROR('No files found in ' + indir)
39 sys.exit()
40
41outdir = '.'
42if len(argvs) > 4:
43 outdir = argvs[4]
44outputFile = outdir + '/beamBkgHitRates-' + expNo + '-' + runNo + '.root'
45
46
47class SelectTRGTypes(basf2.Module):
48 ''' select events according to given trigger types '''
49
50 def event(self):
51 ''' event processing '''
52
53 self.return_value(0)
54 trg_summary = Belle2.PyStoreObj('TRGSummary')
55 if not trg_summary.isValid():
56 basf2.B2ERROR('No TRGSummary available - event ignored')
57 return
58
59 for trgType in trigTypes:
60 if trg_summary.getTimType() == trgType:
61 self.return_value(1)
62 return
63
64
65# Define global tag
66basf2.conditions.prepend_globaltag(global_tag)
67
68# Create paths
69main = basf2.create_path()
70emptypath = basf2.create_path()
71
72# Input (raw data)
73main.add_module('RootInput', inputFileNames=files)
74
75# Gearbox
76main.add_module('Gearbox')
77
78# Geometry
79main.add_module('Geometry')
80
81# Unpack TRGSummary
82main.add_module('TRGGDLUnpacker')
83main.add_module('TRGGDLSummary')
84
85# Show progress of processing
86main.add_module('Progress')
87
88# Skip events not matching given trigger types, if the list is not empty
89if len(trigTypes) > 0:
90 selector = SelectTRGTypes()
91 main.add_module(selector)
92 selector.if_false(emptypath)
93
94# Unpack detector data
95add_unpackers(path=main,
96 components=['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM'])
97
98# additional modules if needed for hit processing
99main.add_module('ARICHFillHits')
100main.add_module('TOPChannelMasker')
101main.add_module('ActivatePXDGainCalibrator')
102main.add_module('PXDClusterizer')
103add_svd_reconstruction(main, applyMasking=True)
104main.add_module(
105 'SVDZeroSuppressionEmulator',
106 SNthreshold=5,
107 ShaperDigits='SVDShaperDigitsUnmasked',
108 ShaperDigitsIN='SVDShaperDigitsZS5')
109main.add_module('TFCDC_WireHitPreparer',
110 wirePosition='aligned',
111 flightTimeEstimation='outwards',
112 filter='cuts_from_DB')
113
114# Beam background rate monitor: output to flat ntuple
115main.add_module(
116 'BeamBkgHitRateMonitor',
117 outputFileName=outputFile,
118 trgTypes=trigTypes,
119 svdShaperDigitsName='SVDShaperDigitsZS5',
120 cdcTimeWindowLowerEdgeSmallCell=4720,
121 cdcTimeWindowUpperEdgeSmallCell=5020,
122 cdcTimeWindowLowerEdgeNormalCell=4720,
123 cdcTimeWindowUpperEdgeNormalCell=5020)
124
125# Process events
126basf2.process(main)
127
128# Print call statistics
129print(basf2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67