14from basf2
import Module, Path, B2ERROR, B2INFO
16from rawdata
import add_unpackers
17from gdltrigger
import filter_trigger_abort_gaps
21 'EventLevelTriggerTimeInfo',
36 '''Select events according to given trigger types.'''
45 '''Initialize the module.'''
46 from ROOT
import Belle2
52 '''Event processing.'''
57 B2ERROR(
'TRGSummary is not available: the event is discarded.')
66def get_trigger_types_for_bgo():
67 '''Get the default trigger types to be used for the Beam Background Overlay (BGO) production.'''
68 from ROOT
import Belle2
71 Belle2.TRGSummary.TTYP_DPHY,
72 Belle2.TRGSummary.TTYP_RAND,
77def get_background_files(folder=None, output_file_info=True):
78 """ Loads the location of the background files from the environmant variable
79 BELLE2_BACKGROUND_DIR which is set on the validation server and ensures that background
80 files exist and returns the list of background files which
81 can be directly used with add_simulation() :
83 >>> add_simulation(main, bkgfiles=background.get_background_files())
85 Will fail with an assert if no background folder set or if no background file was
86 found in the set folder.
89 folder (str): A specific folder to search for background files can be given as an optional parameter
90 output_file_info (str): If true, a list of the found background files and there size will be printed
91 This is useful to understand later which background campaign has been used
95 env_name =
'BELLE2_BACKGROUND_DIR'
99 if env_name
not in os.environ:
100 raise RuntimeError(
"Environment variable {} for background files not set. Terminanting this script.".format(env_name))
101 folder = os.environ[env_name]
103 bg = glob.glob(folder +
'/*.root')
106 raise RuntimeError(
"No background files found in folder {} . Terminating this script.".format(folder))
108 B2INFO(
"Background files loaded from folder {}".format(folder))
114 bg_sizes = [os.path.getsize(f)
for f
in bg]
116 table_rows = [list(entry)
for entry
in zip(bg, bg_sizes)]
117 table_rows.insert(0, [
"- Background file name -",
"- file size -"])
119 pretty_print_table(table_rows, [0, 0])
124def add_output(path, bgType, realTime, sampleType, phase=3, fileName='output.root', excludeBranches=None):
126 A function to be used for output of BG simulation.
127 @param path path name
128 @param bgType background type, to get available types: basf2 -m BeamBkgTagSetter
129 @param realTime equivalent time of superKEKB running in [ns]
130 @param sampleType 'study' (for BG studies) or 'usual', 'PXD', 'ECL' (for BG mixer)
131 @param specify the Phase, 1 for Phase 1, 2 for Phase 2, and 3 for Physics Run or Phase 3
132 @param fileName optional file name, can be overridden by basf2 -o
134 if excludeBranches
is None:
137 if sampleType ==
'study':
140 elif sampleType ==
'usual' and phase == 3:
151 elif sampleType ==
'usual' and phase == 2:
170 elif sampleType ==
'usual' and phase == 1:
182 elif sampleType ==
'ECL':
184 branches = [
'ECLHits']
185 elif sampleType ==
'PXD':
187 branches = [
'PXDSimHits']
191 B2ERROR(
'add_output - invalid value of argument sampleType: %s'
195 tagSetter = path.add_module(
'BeamBkgTagSetter', backgroundType=bgType, realTime=realTime,
196 specialFor=madeFor, Phase=phase)
199 if sampleType !=
'study':
201 tagSetter.if_false(emptyPath)
206 path.add_module(
'RootOutput', outputFileName=fileName, branchNames=branches, excludeBranchNames=excludeBranches,
207 buildIndex=
False, autoFlushSize=-500000)
210def add_bgo_modules(path, additionalBranches=None):
212 This function adds to the path all the necessary modules to produce Beam Background Overlay (BGO) files
213 starting from raw data.
214 This function already adds the ``RootOutput`` module with all the branch names correctly set.
217 path (Path): Path to add module to
218 additionalBranches (list): Additional objects/arrays of event durability to save
224 path.add_module(
'Gearbox')
227 path.add_module(
'Geometry')
230 path.add_module(
'TRGGDLUnpacker')
231 path.add_module(
'TRGGDLSummary')
234 path.add_module(
'Progress')
237 selector = path.add_module(
SelectTRGTypes(trg_types=get_trigger_types_for_bgo()))
238 selector.if_false(empty)
241 filter_trigger_abort_gaps(path)
244 add_unpackers(path, components=[
'PXD',
'SVD',
'CDC',
'ECL',
'TOP',
'ARICH',
'KLM'])
247 compress = path.add_module(
'ECLCompressBGOverlay', CompressionAlgorithm=3)
248 compress.if_false(empty)
251 path.add_module(
'KLMDigitTimeShifter')
254 path.add_module(
'TRGECLUnpacker')
255 path.add_module(
'TRGECLBGTCHit')
258 branches = list(BGO_OBJECTS)
259 if additionalBranches:
260 branches += additionalBranches
261 path.add_module(
'RootOutput', branchNames=branches)
a (simplified) python wrapper for StoreObjPtr.
trg_summary
The trigger summary object.
trg_types
The trigger types.
__init__(self, trg_types=None)
initialize(self, trg_types=None)