10Helper functions for producing events with the WHIZARD generator.
24_default_iterations =
'25:10000:"gw", 10:10000:""'
27_refined_iterations =
'25:10000:"gw", 20:10000:""'
32 'final_state':
'"e-", "e+", "e-", "e+"',
33 'cuts':
'cuts = all M > 500 MeV ["e-" + "e+"]',
34 'iterations': _refined_iterations,
37 'final_state':
'"e-", "e+", "mu-", "mu+"',
38 'cuts':
'cuts = all M > 500 MeV ["mu+" + "mu-"]',
39 'iterations': _default_iterations
42 'final_state':
'"e-", "e+", "tau-", "tau+"',
44 'iterations': _default_iterations
47 'final_state':
'"mu-", "mu+", "mu-", "mu+"',
49 'iterations': _default_iterations
52 'final_state':
'"mu-", "mu+", "tau-", "tau+"',
54 'iterations': _default_iterations
57 'final_state':
'"tau-", "tau+", "tau-", "tau+"',
59 'iterations': _default_iterations
64_sindarin_template =
'''
65process {process} = "e-", "e+" => {final_state}
68beams = "e-",
"e+" => isr
70$isr_handler_mode =
"recoil"
76sqrts = {cm_energy} GeV
80integrate ({process}) {{
81 iterations = {iterations}
82 relative_error_goal = 0.05
88def get_sindarin(process, events, cm_energy, random_seed=114):
90 Return a properly formatted SINDARIN file as a string.
92 if process
not in _processes_dict.keys():
93 basf2.B2FATAL(f
'The process {process} is currently not supported, you need to write a SINDARIN file yourself.')
94 sindarin = _sindarin_template.format(
96 final_state=_processes_dict[process][
'final_state'],
97 cuts=_processes_dict[process][
'cuts'],
98 iterations=_processes_dict[process][
'iterations'],
101 random_seed=random_seed
106def run_whizard(process, experiment, run, events, print_sindarin=False):
108 This function takes care of running WHIZARD.
110 if process
not in _processes_dict.keys():
111 basf2.B2FATAL(f
'The process {process} is currently not supported, you need to write a SINDARIN file yourself.')
115 basf2_seed = basf2.get_random_seed().encode(
'utf-8')
116 whizard_seed = int(hashlib.sha256(basf2_seed).hexdigest(), 16) % 10**8
118 sindarin = get_sindarin(process, events, cm_energy, whizard_seed)
120 basf2.B2INFO(f
'The SINDARIN file is:\n\n{sindarin}')
123 path = os.path.join(cwd, f
'{process}_{whizard_seed}')
125 sin = f
'{process}.sin'
126 lhe = f
'{process}.lhe'
127 log = f
'{process}.log'
129 if not os.path.exists(path):
132 shutil.rmtree(path, ignore_errors=
True)
142 with open(sin,
'w')
as sindarin_file:
143 sindarin_file.write(sindarin)
148 subprocess.check_call([whizard,
'-L', log, sin])
149 moved_lhe, moved_log = os.path.join(path, lhe), os.path.join(path, log)
150 shutil.move(os.path.join(tmp, lhe), moved_lhe)
151 shutil.move(os.path.join(tmp, log), moved_log)
152 except subprocess.CalledProcessError:
156 basf2.B2FATAL(f
'WHIZARD failed while generating the {process} process')
158 return path, moved_lhe, moved_log
161if __name__ ==
"__main__":
def get_collisions_invariant_mass(experiment, run, verbose=False)
def clean_working_directory()