11from basf2
import create_path, B2ERROR, B2INFO
17def get_background_files(folder=None, output_file_info=True):
18 """ Loads the location of the background files from the environmant variable
19 BELLE2_BACKGROUND_DIR which is set on the validation server
and ensures that background
20 files exist
and returns the list of background files which
21 can be directly used
with add_simulation() :
25 Will fail
with an
assert if no background folder set
or if no background file was
26 found
in the set folder.
29 folder (str): A specific folder to search
for background files can be given
as an optional parameter
30 output_file_info (str): If true, a list of the found background files
and there size will be printed
31 This
is useful to understand later which background campaign has been used
35 env_name = 'BELLE2_BACKGROUND_DIR'
39 if env_name
not in os.environ:
40 raise RuntimeError(
"Environment variable {} for backgound files not set. Terminanting this script.".format(env_name))
41 folder = os.environ[env_name]
43 bg = glob.glob(folder +
'/*.root')
46 raise RuntimeError(
"No background files found in folder {} . Terminating this script.".format(folder))
48 B2INFO(
"Background files loaded from folder {}".format(folder))
54 bg_sizes = [os.path.getsize(f)
for f
in bg]
56 table_rows = [list(entry)
for entry
in zip(bg, bg_sizes)]
57 table_rows.insert(0, [
"- Background file name -",
"- file size -"])
59 pretty_print_table(table_rows, [0, 0])
64def add_output(path, bgType, realTime, sampleType, phase=3, fileName='output.root', excludeBranches=None):
66 A function to be used for output of BG simulation.
68 @param bgType background type, to get available types: basf2 -m BeamBkgTagSetter
69 @param realTime equivalent time of superKEKB running
in [ns]
70 @param sampleType
'study' (
for BG studies)
or 'usual',
'PXD',
'ECL' (
for BG mixer)
71 @param specify the Phase, 1
for Phase 1, 2
for Phase 2,
and 3
for Physics Run
or Phase 3
72 @param fileName optional file name, can be overridden by basf2 -o
74 if excludeBranches
is None:
77 if sampleType ==
'study':
80 elif sampleType ==
'usual' and phase == 3:
91 elif sampleType ==
'usual' and phase == 2:
110 elif sampleType ==
'usual' and phase == 1:
122 elif sampleType ==
'ECL':
124 branches = [
'ECLHits']
125 elif sampleType ==
'PXD':
127 branches = [
'PXDSimHits']
131 B2ERROR(
'add_output - invalid value of argument sampleType: %s'
135 tagSetter = path.add_module(
'BeamBkgTagSetter', backgroundType=bgType, realTime=realTime,
136 specialFor=madeFor, Phase=phase)
139 if sampleType !=
'study':
140 emptyPath = create_path()
141 tagSetter.if_false(emptyPath)
146 path.add_module(
'RootOutput', outputFileName=fileName, branchNames=branches, excludeBranchNames=excludeBranches,
147 buildIndex=
False, autoFlushSize=-500000)
def get_background_files(folder=None, output_file_info=True)