151):
152 """
153 Fragment for configuring a LHE generation step.
154
155 This starts from MadGraphBaseCfg and creates a MGC instance
156 that is later used to call the MadGraphUtils functions that steer
157 the event generation.
158
159 All arguments after * are keyword-only to avoid confusion
160 between MadGraphControl settings and CA configuration options.
161 Set prepare_lhe_for_shower=True when the same job should feed the
162 produced LHE file into a shower generator.
163
164 process_definition is required, the rest is optional.
165
166 run_card_settings maps run_card.dat settings to their requested values.
167 param_card_settings maps param_card.dat settings to dictionaries of
168 parameter indices and values.
169
170 If prepare_lhe_for_shower is True, the produced LHE file will be
171 symlinked to lhe_file (default: events.lhe)
172 for later use in the showering step.
173 """
174
175 from MadGraphControl.MGC import MGControl
177
178 if isinstance(pdf_setting, MadGraphPDFSets):
179 pdf_setting = get_pdf_set(pdf_setting)
180
181
182 ca, cfg = MadGraphBaseCfg(
183 flags,
184 safety=safety,
185 pdf_setting=pdf_setting,
186 devices=devices,
187 catch_errors=catch_errors,
188 lhe_version=lhe_version,
189 saveProcDir=saveProcDir,
190 keepJpegs=keepJpegs,
191 usePMGSettings=usePMGSettings,
192 )
193
194 run_card_settings = {} if run_card_settings is None else dict(run_card_settings)
195 param_card_settings = {} if param_card_settings is None else dict(param_card_settings)
196
197
198
199 run_card_settings["nevents"] = _get_nevents(flags, cfg["safety"])
200
201
202 mgc = MGControl(
203 process=process_definition,
204 plugin=plugin,
205 keepJpegs=cfg["keepJpegs"],
206 usePMGSettings=cfg["usePMGSettings"],
207 pdf_setting=cfg["pdf_setting"],
208 devices=cfg["devices"],
209 catch_errors=cfg["catch_errors"],
210 )
211
212
213
214
215
216 MadGraphUtils.my_MGC_instance = mgc
217
218
219 process_dir = mgc.process_dir
220
221
222 mgc.runCardDict.update(run_card_settings)
223
224
225 mgc.paramCard.modify_paramCardDict(
226 params=param_card_settings
227 )
228
229
230 MadGraphUtils.generate(process_dir=process_dir, flags=flags, pdf_setting=cfg["pdf_setting"])
231 produced_output = MadGraphUtils.arrange_output(
232 process_dir=process_dir,
233 flags=flags,
234 lhe_version=cfg["lhe_version"],
235 saveProcDir=cfg["saveProcDir"],
236 pdf_setting=cfg["pdf_setting"],
237 )
238
239
240
241
242 if prepare_lhe_for_shower:
243 _prepare_lhe_for_shower(produced_output, lhe_file)
244
245
246
247
248 requested_output = flags.Output.TXTFileName
249 if requested_output and not os.path.exists(requested_output):
250 root, _ = os.path.splitext(requested_output)
251 candidates = [candidate for candidate in (produced_output, f"{root}.events", "events.events") if candidate]
252 _symlink_first_existing(requested_output, candidates, overwrite=True)
253
254 return ca