4from GeneratorConfig.Sequences
import EvgenSequence, EvgenSequenceFactory
9from MadGraphControl.MadGraphPDFSettings
import MadGraphPDFSets, get_pdf_set
36 if produced_output.endswith(
".tar.gz"):
37 root = produced_output[:-7]
38 elif produced_output.endswith(
".tgz"):
39 root = produced_output[:-4]
40 elif produced_output.endswith(
".gz"):
41 root = produced_output[:-3]
43 root, _ = os.path.splitext(produced_output)
44 primary_output = f
"{root}.events"
48 candidates = [candidate
49 for candidate
in (primary_output,
50 "tmp_LHE_events.events",
57 "Could not prepare LHE file for showering. "
58 f
"Expected one of: {', '.join(candidates)}"
64 Helper function to symlink the first existing file in candidates to link_name.
66 if os.path.exists(link_name)
and not overwrite:
69 for candidate
in candidates:
70 if not candidate
or not os.path.exists(candidate):
72 if os.path.abspath(candidate) == os.path.abspath(link_name):
74 if os.path.lexists(link_name):
76 os.symlink(os.path.abspath(candidate), link_name)
83 """Base MadGraph CA fragment. It returns a CA object
84 that contains the generator metadata and registers
85 default values for steering the MGC object
86 (to be created by the top-level config)."""
87 from MadGraphControl.MGC
import (
88 MADGRAPH_CATCH_ERRORS,
97 "pdf_setting": MADGRAPH_PDFSETTING,
98 "devices": MADGRAPH_DEVICES,
99 "catch_errors": MADGRAPH_CATCH_ERRORS,
101 "saveProcDir":
False,
103 "usePMGSettings":
False,
108 cfg = {**defaults, **{k: v
for k, v
in kwargs.items()
if v
is not None}}
111 ca = ComponentAccumulator(EvgenSequenceFactory(EvgenSequence.Generator))
113 GeneratorInfoSvcCfg(flags, Generators=[
"MadGraph"]),
114 sequenceName=EvgenSequence.Generator.value,
134 prepare_lhe_for_shower=False,
135 lhe_file="events.lhe",
138 Fragment for configuring a LHE generation step.
140 This starts from MadGraphBaseCfg and creates a MGC instance
141 that is later used to call the MadGraphUtils functions that steer
142 the event generation.
144 All arguments after * are keyword-only to avoid confusion
145 between MadGraphControl settings and CA configuration options.
146 Set prepare_lhe_for_shower=True when the same job should feed the
147 produced LHE file into a shower generator.
149 process_definition is required, the rest is optional.
151 If prepare_lhe_for_shower is True, the produced LHE file will be
152 symlinked to lhe_file (default: events.lhe)
153 for later use in the showering step.
156 from MadGraphControl.MGC
import MGControl
159 if isinstance(pdf_setting, MadGraphPDFSets):
160 pdf_setting = get_pdf_set(pdf_setting)
166 pdf_setting=pdf_setting,
168 catch_errors=catch_errors,
169 lhe_version=lhe_version,
170 saveProcDir=saveProcDir,
172 usePMGSettings=usePMGSettings,
175 run_card_settings = {}
if settings
is None else dict(settings)
178 run_card_settings[
"nevents"] =
_get_nevents(flags, cfg[
"safety"])
182 process=process_definition,
184 keepJpegs=cfg[
"keepJpegs"],
185 usePMGSettings=cfg[
"usePMGSettings"],
186 pdf_setting=cfg[
"pdf_setting"],
187 devices=cfg[
"devices"],
188 catch_errors=cfg[
"catch_errors"],
195 MadGraphUtils.my_MGC_instance = mgc
198 process_dir = mgc.process_dir
199 MadGraphUtils.modify_run_card(
200 process_dir=process_dir,
202 settings=run_card_settings,
203 pdf_setting=cfg[
"pdf_setting"],
207 MadGraphUtils.generate(process_dir=process_dir, flags=flags, pdf_setting=cfg[
"pdf_setting"])
208 produced_output = MadGraphUtils.arrange_output(
209 process_dir=process_dir,
211 lhe_version=cfg[
"lhe_version"],
212 saveProcDir=cfg[
"saveProcDir"],
213 pdf_setting=cfg[
"pdf_setting"],
219 if prepare_lhe_for_shower:
225 requested_output = flags.Output.TXTFileName
226 if requested_output
and not os.path.exists(requested_output):
227 root, _ = os.path.splitext(requested_output)
228 candidates = [candidate
for candidate
in (produced_output, f
"{root}.events",
"events.events")
if candidate]
MadGraphCfg(flags, process_definition, *, safety=None, settings=None, pdf_setting=None, devices=None, catch_errors=None, lhe_version=None, saveProcDir=None, plugin=None, keepJpegs=None, usePMGSettings=None, prepare_lhe_for_shower=False, lhe_file="events.lhe")