Belle II Software  release-08-01-10
makeBGOverlayFromData.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 import sys
13 from rawdata import add_unpackers
14 from ROOT import Belle2
15 
16 # --------------------------------------------------------------------------------------
17 # Make data sample for BG overlay from experimental raw data
18 #
19 # Usage: basf2 makeBGOverlayFromData.py -i <inputFileName> -o <outputFileName> globalTag
20 #
21 # --------------------------------------------------------------------------------------
22 
23 # Argument parsing
24 argvs = sys.argv
25 if len(argvs) < 2:
26  print("usage: basf2", argvs[0], "globalTag -i <inputFileName> -o <outputFileName>")
27  sys.exit()
28 
29 globalTag = argvs[1]
30 trigTypes = [5, 7] # trigger types for event selection (see TRGSummary.h)
31 
32 
33 class SelectTRGTypes(basf2.Module):
34  ''' select events according to given trigger types '''
35 
36  def event(self):
37  ''' event processing '''
38 
39  self.return_value(0)
40  trg_summary = Belle2.PyStoreObj('TRGSummary')
41  if not trg_summary.isValid():
42  basf2.B2ERROR('No TRGSummary available - event ignored')
43  return
44 
45  for trgType in trigTypes:
46  if trg_summary.getTimType() == trgType:
47  self.return_value(1)
48  return
49 
50 
51 # Define global tag
52 basf2.conditions.prepend_globaltag(globalTag)
53 
54 # Create paths
55 main = basf2.create_path()
56 emptypath = basf2.create_path()
57 
58 # Input: raw data
59 main.add_module('RootInput')
60 
61 # Gearbox
62 main.add_module('Gearbox')
63 
64 # Geometry
65 main.add_module('Geometry')
66 
67 # Unpack TRGSummary
68 main.add_module('TRGGDLUnpacker')
69 main.add_module('TRGGDLSummary')
70 
71 # Show progress of processing
72 main.add_module('Progress')
73 
74 # Select random trigger events
75 selector = SelectTRGTypes()
76 main.add_module(selector)
77 selector.if_false(emptypath)
78 
79 # Unpack detector data
80 add_unpackers(main,
81  components=['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM'])
82 
83 # Shift the time of KLMDigits
84 main.add_module('KLMDigitTimeShifter')
85 
86 # ECL trigger unpacker and BGOverlay dataobject
87 main.add_module('TRGECLUnpacker')
88 main.add_module('TRGECLBGTCHit')
89 
90 # Convert ECLDsps to ECLWaveforms
91 compress = basf2.register_module('ECLCompressBGOverlay')
92 main.add_module(compress, CompressionAlgorithm=3)
93 compress.if_false(emptypath)
94 
95 # Output: digitized hits only
96 output = basf2.register_module('RootOutput')
97 output.param('branchNames', ['EventLevelTriggerTimeInfo', 'PXDDigits', 'SVDShaperDigits', 'CDCHits', 'TOPDigits',
98  'ARICHDigits', 'ECLWaveforms', 'KLMDigits', 'TRGECLBGTCHits'])
99 main.add_module(output)
100 
101 # Process events
102 basf2.process(main)
103 
104 # Print call statistics
105 print(basf2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67