131):
132 """
133 Fragment for configuring a LHE generation step.
134
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.
138
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.
143
144 process_definition is required, the rest is optional.
145
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.
149
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.
153 """
154
155 from MadGraphControl.MGC import MGControl
157
158 if isinstance(pdf_setting, MadGraphPDFSets):
159 pdf_setting = get_pdf_set(pdf_setting)
160
161
162 ca, cfg = MadGraphBaseCfg(
163 flags,
164 safety=safety,
165 pdf_setting=pdf_setting,
166 devices=devices,
167 catch_errors=catch_errors,
168 lhe_version=lhe_version,
169 saveProcDir=saveProcDir,
170 keepJpegs=keepJpegs,
171 usePMGSettings=usePMGSettings,
172 )
173
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)
176
177
178
179 run_card_settings["nevents"] = _get_nevents(flags, cfg["safety"])
180
181
182 mgc = MGControl(
183 process=process_definition,
184 plugin=plugin,
185 keepJpegs=cfg["keepJpegs"],
186 usePMGSettings=cfg["usePMGSettings"],
187 pdf_setting=cfg["pdf_setting"],
188 devices=cfg["devices"],
189 catch_errors=cfg["catch_errors"],
190 )
191
192
193
194
195
196 MadGraphUtils.my_MGC_instance = mgc
197
198
199 process_dir = mgc.process_dir
200
201
202 mgc.runCardDict.update(run_card_settings)
203
204
205 mgc.paramCard.modify_paramCardDict(
206 params=param_card_settings
207 )
208
209
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,
213 flags=flags,
214 lhe_version=cfg["lhe_version"],
215 saveProcDir=cfg["saveProcDir"],
216 pdf_setting=cfg["pdf_setting"],
217 )
218
219
220
221
222 if prepare_lhe_for_shower:
223 _prepare_lhe_for_shower(produced_output, lhe_file)
224
225
226
227
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]
232 _symlink_first_existing(requested_output, candidates, overwrite=True)
233
234 return ca