12 from basf2
import create_path, B2ERROR, B2INFO
18 def get_background_files(folder=None, output_file_info=True):
19 """ Loads the location of the background files from the environmant variable
20 BELLE2_BACKGROUND_DIR which is set on the validation server and ensures that background
21 files exist and returns the list of background files which
22 can be directly used with add_simulation() :
24 >>> add_simulation(main, bkgfiles=background.get_background_files())
26 Will fail with an assert if no background folder set or if no background file was
27 found in the set folder.
30 folder (str): A specific folder to search for background files can be given as an optional parameter
31 output_file_info (str): If true, a list of the found background files and there size will be printed
32 This is useful to understand later which background campaign has been used
36 env_name =
'BELLE2_BACKGROUND_DIR'
40 if env_name
not in os.environ:
41 raise RuntimeError(
"Environment variable {} for backgound files not set. Terminanting this script.".format(env_name))
42 folder = os.environ[env_name]
44 bg = glob.glob(folder +
'/*.root')
47 raise RuntimeError(
"No background files found in folder {} . Terminating this script.".format(folder))
49 B2INFO(
"Background files loaded from folder {}".format(folder))
55 bg_sizes = [os.path.getsize(f)
for f
in bg]
57 table_rows = [list(entry)
for entry
in zip(bg, bg_sizes)]
58 table_rows.insert(0, [
"- Background file name -",
"- file size -"])
60 pretty_print_table(table_rows, [0, 0])
65 def add_output(path, bgType, realTime, sampleType, phase=3, fileName='output.root', excludeBranches=None):
67 A function to be used for output of BG simulation.
69 @param bgType background type, to get available types: basf2 -m BeamBkgTagSetter
70 @param realTime equivalent time of superKEKB running in [ns]
71 @param sampleType 'study' (for BG studies) or 'usual', 'PXD', 'ECL' (for BG mixer)
72 @param specify the Phase, 1 for Phase 1, 2 for Phase 2, and 3 for Physics Run or Phase 3
73 @param fileName optional file name, can be overridden by basf2 -o
75 if excludeBranches
is None:
78 if sampleType ==
'study':
81 elif sampleType ==
'usual' and phase == 3:
93 elif sampleType ==
'usual' and phase == 2:
113 elif sampleType ==
'usual' and phase == 1:
125 elif sampleType ==
'ECL':
127 branches = [
'ECLHits']
128 elif sampleType ==
'PXD':
130 branches = [
'PXDSimHits']
134 B2ERROR(
'add_output - invalid value of argument sampleType: %s'
138 tagSetter = path.add_module(
'BeamBkgTagSetter', backgroundType=bgType, realTime=realTime,
139 specialFor=madeFor, Phase=phase)
142 if sampleType !=
'study':
143 emptyPath = create_path()
144 tagSetter.if_false(emptyPath)
149 path.add_module(
'RootOutput', outputFileName=fileName, branchNames=branches, excludeBranchNames=excludeBranches,
150 buildIndex=
False, autoFlushSize=-500000)