ATLAS Offline Software
Loading...
Searching...
No Matches
python.MadGraphConfig Namespace Reference

Functions

 _get_nevents (flags, safety)
 MadGraphBaseCfg (flags, **kwargs)
 MadGraph_LHE_Cfg (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)

Function Documentation

◆ _get_nevents()

python.MadGraphConfig._get_nevents ( flags,
safety )
protected
Helper function to determing number of events to be generated
in MadGraph, based on MaxEvents or nEventsPerJob and a user-provided 
safety factor (the latter defaults to 1.1 to allow for failures 
in showering stage).

Definition at line 12 of file MadGraphConfig.py.

12def _get_nevents(flags, safety):
13 """Helper function to determing number of events to be generated
14 in MadGraph, based on MaxEvents or nEventsPerJob and a user-provided
15 safety factor (the latter defaults to 1.1 to allow for failures
16 in showering stage)."""
17 try:
18 sf = float(safety)
19 except (TypeError, ValueError) as exc:
20 raise RuntimeError(f"safety must be numeric, got {safety}.") from exc
21 if sf <= 0:
22 raise RuntimeError(f"safety must be > 0, got {safety}.")
23
24 base_events = (
25 flags.Exec.MaxEvents
26 if flags.Exec.MaxEvents > 0
27 else flags.Generator.nEventsPerJob
28 )
29
30 return int(base_events * sf)
31
32

◆ MadGraph_LHE_Cfg()

python.MadGraphConfig.MadGraph_LHE_Cfg ( 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 )
Fragment for configuring a standalone (LHE-only) generation step.

This creates starts from MadGraphBaseCfg and creates a MGC instance
that is later used to call the MadGraphUtil functions that steer
the event generation.

All arguments after * are keyword-only to avoid confusion 
between MadGraphControl settings and CA configuration options.

process_definition is required, the rest is optional.

Definition at line 71 of file MadGraphConfig.py.

85):
86 """Fragment for configuring a standalone (LHE-only) generation step.
87
88 This creates starts from MadGraphBaseCfg and creates a MGC instance
89 that is later used to call the MadGraphUtil functions that steer
90 the event generation.
91
92 All arguments after * are keyword-only to avoid confusion
93 between MadGraphControl settings and CA configuration options.
94
95 process_definition is required, the rest is optional.
96 """
97
98 from MadGraphControl.MGC import MGControl
99 import MadGraphControl.MadGraphUtils as MadGraphUtils
100
101 if isinstance(pdf_setting, MadGraphPDFSets):
102 pdf_setting = get_pdf_set(pdf_setting)
103
104 ca, cfg = MadGraphBaseCfg(
105 flags,
106 safety=safety,
107 pdf_setting=pdf_setting,
108 devices=devices,
109 catch_errors=catch_errors,
110 lhe_version=lhe_version,
111 saveProcDir=saveProcDir,
112 keepJpegs=keepJpegs,
113 usePMGSettings=usePMGSettings,
114 )
115
116 run_card_settings = {} if settings is None else dict(settings)
117
118 # Get nEvents
119 run_card_settings["nevents"] = _get_nevents(flags, cfg["safety"])
120
121 # Create the MGC instance
122 mgc = MGControl(
123 process=process_definition,
124 plugin=plugin,
125 keepJpegs=cfg["keepJpegs"],
126 usePMGSettings=cfg["usePMGSettings"],
127 pdf_setting=cfg["pdf_setting"],
128 devices=cfg["devices"],
129 catch_errors=cfg["catch_errors"],
130 )
131
132 # Bind the MGC instance to the MadGraphUtils module,
133 # so that it can be used in the calls to the MadGraphUtils functions
134 # This is not following the CA logic completely, but it avoids
135 # having to pass the MGC instance through multiple function calls.
136 MadGraphUtils.my_MGC_instance = mgc
137
138 # Create the process directory
139 process_dir = mgc.process_dir
140 MadGraphUtils.modify_run_card(
141 process_dir=process_dir,
142 flags=flags,
143 settings=run_card_settings,
144 pdf_setting=cfg["pdf_setting"],
145 )
146
147 # Generate events
148 MadGraphUtils.generate(process_dir=process_dir, flags=flags, pdf_setting=cfg["pdf_setting"])
149 produced_output = MadGraphUtils.arrange_output(
150 process_dir=process_dir,
151 flags=flags,
152 lhe_version=cfg["lhe_version"],
153 saveProcDir=cfg["saveProcDir"],
154 pdf_setting=cfg["pdf_setting"],
155 )
156
157 # Create a symlink to the produced output with the name
158 # requested by the user.
159 requested_output = flags.Output.TXTFileName
160 if requested_output and not os.path.exists(requested_output):
161 if os.path.lexists(requested_output):
162 os.remove(requested_output)
163 candidates = []
164 if produced_output:
165 candidates.append(produced_output)
166 root, _ = os.path.splitext(requested_output)
167 candidates.extend([f"{root}.events", "events.events"])
168 for candidate in candidates:
169 if candidate and os.path.exists(candidate) and candidate != requested_output:
170 os.symlink(os.path.abspath(candidate), requested_output)
171 break
172
173 return ca

◆ MadGraphBaseCfg()

python.MadGraphConfig.MadGraphBaseCfg ( flags,
** kwargs )
Base MadGraph CA fragment. It returns a CA object 
that contains the generator metadata and registers 
default values for steering the MGC object 
(to be created by the top-level config).

Definition at line 33 of file MadGraphConfig.py.

33def MadGraphBaseCfg(flags, **kwargs):
34 """Base MadGraph CA fragment. It returns a CA object
35 that contains the generator metadata and registers
36 default values for steering the MGC object
37 (to be created by the top-level config)."""
38 from MadGraphControl.MGC import (
39 MADGRAPH_CATCH_ERRORS,
40 MADGRAPH_DEVICES,
41 MADGRAPH_PDFSETTING,
42 )
43
44 # Default values for MGC. Use MGC defaults for now, but these
45 # can be declared here in the future.
46 defaults = {
47 "safety": 1.1,
48 "pdf_setting": MADGRAPH_PDFSETTING,
49 "devices": MADGRAPH_DEVICES,
50 "catch_errors": MADGRAPH_CATCH_ERRORS,
51 "lhe_version": 3,
52 "saveProcDir": False,
53 "keepJpegs": False,
54 "usePMGSettings": False,
55 }
56
57 # Create a dictionary with default settings.
58 # This can be used in top-level configs.
59 cfg = {**defaults, **{k: v for k, v in kwargs.items() if v is not None}}
60
61 # Create the CA object adding the generator metadata
62 ca = ComponentAccumulator(EvgenSequenceFactory(EvgenSequence.Generator))
63 ca.merge(
64 GeneratorInfoSvcCfg(flags, Generators=["MadGraph"]),
65 sequenceName=EvgenSequence.Generator.value,
66 )
67
68 return ca, cfg
69
70