14from basf2
import Module, Path, B2ERROR, B2INFO
19 '''Select events according to given trigger types.'''
23 from ROOT
import Belle2
31 '''Initialize the module.'''
35 '''Event processing.'''
40 B2ERROR(
'TRGSummary is not available: the event is discarded.')
49def get_trigger_types_for_bgo():
50 '''Get the default trigger types to be used for the Beam Background Overlay (BGO) production.'''
51 from ROOT
import Belle2
54 Belle2.TRGSummary.TTYP_DPHY,
55 Belle2.TRGSummary.TTYP_RAND,
60def get_background_files(folder=None, output_file_info=True):
61 """ Loads the location of the background files from the environmant variable
62 BELLE2_BACKGROUND_DIR which is set on the validation server and ensures that background
63 files exist and returns the list of background files which
64 can be directly used with add_simulation() :
66 >>> add_simulation(main, bkgfiles=background.get_background_files())
68 Will fail with an assert if no background folder set or if no background file was
69 found in the set folder.
72 folder (str): A specific folder to search for background files can be given as an optional parameter
73 output_file_info (str): If true, a list of the found background files and there size will be printed
74 This is useful to understand later which background campaign has been used
78 env_name =
'BELLE2_BACKGROUND_DIR'
82 if env_name
not in os.environ:
83 raise RuntimeError(
"Environment variable {} for background files not set. Terminanting this script.".format(env_name))
84 folder = os.environ[env_name]
86 bg = glob.glob(folder +
'/*.root')
89 raise RuntimeError(
"No background files found in folder {} . Terminating this script.".format(folder))
91 B2INFO(
"Background files loaded from folder {}".format(folder))
97 bg_sizes = [os.path.getsize(f)
for f
in bg]
99 table_rows = [list(entry)
for entry
in zip(bg, bg_sizes)]
100 table_rows.insert(0, [
"- Background file name -",
"- file size -"])
102 pretty_print_table(table_rows, [0, 0])
107def add_output(path, bgType, realTime, sampleType, phase=3, fileName='output.root', excludeBranches=None):
109 A function to be used for output of BG simulation.
110 @param path path name
111 @param bgType background type, to get available types: basf2 -m BeamBkgTagSetter
112 @param realTime equivalent time of superKEKB running in [ns]
113 @param sampleType 'study' (for BG studies) or 'usual', 'PXD', 'ECL' (for BG mixer)
114 @param specify the Phase, 1 for Phase 1, 2 for Phase 2, and 3 for Physics Run or Phase 3
115 @param fileName optional file name, can be overridden by basf2 -o
117 if excludeBranches
is None:
120 if sampleType ==
'study':
123 elif sampleType ==
'usual' and phase == 3:
134 elif sampleType ==
'usual' and phase == 2:
153 elif sampleType ==
'usual' and phase == 1:
165 elif sampleType ==
'ECL':
167 branches = [
'ECLHits']
168 elif sampleType ==
'PXD':
170 branches = [
'PXDSimHits']
174 B2ERROR(
'add_output - invalid value of argument sampleType: %s'
178 tagSetter = path.add_module(
'BeamBkgTagSetter', backgroundType=bgType, realTime=realTime,
179 specialFor=madeFor, Phase=phase)
182 if sampleType !=
'study':
184 tagSetter.if_false(emptyPath)
189 path.add_module(
'RootOutput', outputFileName=fileName, branchNames=branches, excludeBranchNames=excludeBranches,
190 buildIndex=
False, autoFlushSize=-500000)
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)