Belle II Software  release-08-01-10
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 
17 import basf2
18 import sys
19 import glob
20 from rawdata import add_unpackers
21 from svd import add_svd_reconstruction
22 from ROOT import Belle2
23 
24 # Argument parsing
25 argvs = sys.argv
26 if len(argvs) < 4:
27  print("usage: basf2", argvs[0], "expNo runNo globalTag [outputFolder]")
28  sys.exit()
29 
30 expNo = 'e' + '{:0=4d}'.format(int(argvs[1]))
31 runNo = 'r' + '{:0=5d}'.format(int(argvs[2]))
32 global_tag = argvs[3]
33 trigTypes = [5, 7] # trigger types for event selection (see TRGSummary.h)
34 
35 indir = '/hsm/belle2/bdata/Data/Raw/' + expNo + '/' + runNo + '/sub00'
36 files = sorted(glob.glob(indir + '/*.root'))
37 if len(files) == 0:
38  basf2.B2ERROR('No files found in ' + indir)
39  sys.exit()
40 
41 outdir = '.'
42 if len(argvs) > 4:
43  outdir = argvs[4]
44 outputFile = outdir + '/beamBkgHitRates-' + expNo + '-' + runNo + '.root'
45 
46 
47 class 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
66 basf2.conditions.prepend_globaltag(global_tag)
67 
68 # Create paths
69 main = basf2.create_path()
70 emptypath = basf2.create_path()
71 
72 # Input (raw data)
73 main.add_module('RootInput', inputFileNames=files)
74 
75 # Gearbox
76 main.add_module('Gearbox')
77 
78 # Geometry
79 main.add_module('Geometry')
80 
81 # Unpack TRGSummary
82 main.add_module('TRGGDLUnpacker')
83 main.add_module('TRGGDLSummary')
84 
85 # Show progress of processing
86 main.add_module('Progress')
87 
88 # Skip events not matching given trigger types, if the list is not empty
89 if len(trigTypes) > 0:
90  selector = SelectTRGTypes()
91  main.add_module(selector)
92  selector.if_false(emptypath)
93 
94 # Unpack detector data
95 add_unpackers(path=main,
96  components=['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM'])
97 
98 # additional modules if needed for hit processing
99 main.add_module('ARICHFillHits')
100 main.add_module('TOPChannelMasker')
101 main.add_module('ActivatePXDGainCalibrator')
102 main.add_module('PXDClusterizer')
103 add_svd_reconstruction(main, applyMasking=True)
104 main.add_module(
105  'SVDZeroSuppressionEmulator',
106  SNthreshold=5,
107  ShaperDigits='SVDShaperDigitsUnmasked',
108  ShaperDigitsIN='SVDShaperDigitsZS5')
109 main.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
115 main.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
126 basf2.process(main)
127 
128 # Print call statistics
129 print(basf2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67