Belle II Software development
makeBGOverlayFromData.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12import sys
13from rawdata import add_unpackers
14from 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
24argvs = sys.argv
25if len(argvs) < 2:
26 print("usage: basf2", argvs[0], "globalTag -i <inputFileName> -o <outputFileName>")
27 sys.exit()
28
29globalTag = argvs[1]
30trigTypes = [5, 7] # trigger types for event selection (see TRGSummary.h)
31
32
33class 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
52basf2.conditions.prepend_globaltag(globalTag)
53
54# Create paths
55main = basf2.create_path()
56emptypath = basf2.create_path()
57
58# Input: raw data
59main.add_module('RootInput')
60
61# Gearbox
62main.add_module('Gearbox')
63
64# Geometry
65main.add_module('Geometry')
66
67# Unpack TRGSummary
68main.add_module('TRGGDLUnpacker')
69main.add_module('TRGGDLSummary')
70
71# Show progress of processing
72main.add_module('Progress')
73
74# Select random trigger events
75selector = SelectTRGTypes()
76main.add_module(selector)
77selector.if_false(emptypath)
78
79# Unpack detector data
80add_unpackers(main,
81 components=['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM'])
82
83# Shift the time of KLMDigits
84main.add_module('KLMDigitTimeShifter')
85
86# ECL trigger unpacker and BGOverlay dataobject
87main.add_module('TRGECLUnpacker')
88main.add_module('TRGECLBGTCHit')
89
90# Convert ECLDsps to ECLWaveforms
91compress = basf2.register_module('ECLCompressBGOverlay')
92main.add_module(compress, CompressionAlgorithm=3)
93compress.if_false(emptypath)
94
95# Output: digitized hits only
96output = basf2.register_module('RootOutput')
97output.param('branchNames', ['EventLevelTriggerTimeInfo', 'PXDDigits', 'SVDShaperDigits', 'CDCHits', 'TOPDigits',
98 'ARICHDigits', 'ECLWaveforms', 'KLMDigits', 'TRGECLBGTCHits', 'TRGSummary'])
99main.add_module(output)
100
101# Process events
102basf2.process(main)
103
104# Print call statistics
105print(basf2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67