4from GeneratorConfig.Sequences
import EvgenSequence, EvgenSequenceFactory
10from MadGraphControl.MadGraphPDFSettings
import MadGraphPDFSets, get_pdf_set
17 if (produced_output
and produced_output.endswith(
".gz")
18 and not produced_output.endswith((
".tar.gz",
".tgz"))):
19 compressed_lhe_file = (
20 lhe_file
if lhe_file.endswith(
".gz")
else f
"{lhe_file}.gz"
23 compressed_lhe_file, [produced_output], overwrite=
True):
26 "Could not prepare compressed LHE file for showering. "
27 f
"Expected: {produced_output}"
32 if produced_output.endswith(
".tar.gz"):
33 root = produced_output[:-7]
34 elif produced_output.endswith(
".tgz"):
35 root = produced_output[:-4]
37 root, _ = os.path.splitext(produced_output)
38 primary_output = f
"{root}.events"
42 candidates = [candidate
43 for candidate
in (primary_output,
44 "tmp_LHE_events.events",
51 "Could not prepare LHE file for showering. "
52 f
"Expected one of: {', '.join(candidates)}"
58 Helper function to symlink the first existing file in candidates to link_name.
60 if os.path.exists(link_name)
and not overwrite:
63 for candidate
in candidates:
64 if not candidate
or not os.path.exists(candidate):
66 if os.path.abspath(candidate) == os.path.abspath(link_name):
68 if os.path.lexists(link_name):
70 os.symlink(os.path.abspath(candidate), link_name)
77 """Base MadGraph CA fragment. It returns a CA object
78 that contains the generator metadata and registers
79 default values for steering the MGC object
80 (to be created by the top-level config)."""
81 from MadGraphControl.MGC
import (
82 MADGRAPH_CATCH_ERRORS,
91 "pdf_setting": MADGRAPH_PDFSETTING,
92 "devices": MADGRAPH_DEVICES,
93 "catch_errors": MADGRAPH_CATCH_ERRORS,
97 "usePMGSettings":
False,
102 cfg = {**defaults, **{k: v
for k, v
in kwargs.items()
if v
is not None}}
105 ca = ComponentAccumulator(EvgenSequenceFactory(EvgenSequence.Generator))
107 GeneratorInfoSvcCfg(flags, Generators=[
"MadGraph"]),
108 sequenceName=EvgenSequence.Generator.value,
119 run_card_settings=None,
120 param_card_settings=None,
129 prepare_lhe_for_shower=False,
130 lhe_file="events.lhe",
133 Fragment for configuring a LHE generation step.
135 This starts from MadGraphBaseCfg and creates a MGC instance
136 that is later used to call the MadGraphUtils functions that steer
137 the event generation.
139 All arguments after * are keyword-only to avoid confusion
140 between MadGraphControl settings and CA configuration options.
141 Set prepare_lhe_for_shower=True when the same job should feed the
142 produced LHE file into a shower generator.
144 process_definition is required, the rest is optional.
146 run_card_settings maps run_card.dat settings to their requested values.
147 param_card_settings maps param_card.dat settings to dictionaries of
148 parameter indices and values.
150 If prepare_lhe_for_shower is True, the produced LHE file will be
151 symlinked to lhe_file (default: events.lhe)
152 for later use in the showering step.
155 from MadGraphControl.MGC
import MGControl
158 if isinstance(pdf_setting, MadGraphPDFSets):
159 pdf_setting = get_pdf_set(pdf_setting)
165 pdf_setting=pdf_setting,
167 catch_errors=catch_errors,
168 lhe_version=lhe_version,
169 saveProcDir=saveProcDir,
171 usePMGSettings=usePMGSettings,
174 run_card_settings = {}
if run_card_settings
is None else dict(run_card_settings)
175 param_card_settings = {}
if param_card_settings
is None else dict(param_card_settings)
179 run_card_settings[
"nevents"] = _get_nevents(flags, cfg[
"safety"])
183 process=process_definition,
185 keepJpegs=cfg[
"keepJpegs"],
186 usePMGSettings=cfg[
"usePMGSettings"],
187 pdf_setting=cfg[
"pdf_setting"],
188 devices=cfg[
"devices"],
189 catch_errors=cfg[
"catch_errors"],
196 MadGraphUtils.my_MGC_instance = mgc
199 process_dir = mgc.process_dir
202 mgc.runCardDict.update(run_card_settings)
205 mgc.paramCard.modify_paramCardDict(
206 params=param_card_settings
210 MadGraphUtils.generate(process_dir=process_dir, flags=flags, pdf_setting=cfg[
"pdf_setting"])
211 produced_output = MadGraphUtils.arrange_output(
212 process_dir=process_dir,
214 lhe_version=cfg[
"lhe_version"],
215 saveProcDir=cfg[
"saveProcDir"],
216 pdf_setting=cfg[
"pdf_setting"],
222 if prepare_lhe_for_shower:
228 requested_output = flags.Output.TXTFileName
229 if requested_output
and not os.path.exists(requested_output):
230 root, _ = os.path.splitext(requested_output)
231 candidates = [candidate
for candidate
in (produced_output, f
"{root}.events",
"events.events")
if candidate]
MadGraphCfg(flags, process_definition, *, safety=None, run_card_settings=None, param_card_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")