ATLAS Offline Software
Loading...
Searching...
No Matches
Herwig7CAConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3"""
4This module contains all the CA fragments for Herwig7.
5
6It is analogous to MadGraphConfig.py but more CA friendly since it avoids side effects.
7It creates the Athena Herwig7 algorithm, hands the flags to the
8control object H7C, and adds the configured algorithm to the evgen
9sequence. The actual execution happens later when Athena runs the sequence.
10"""
11
12from textwrap import dedent
13
14from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
15from AthenaConfiguration.ComponentFactory import CompFactory
16from GeneratorConfig.Sequences import EvgenSequence, EvgenSequenceFactory
17
18from Herwig7_i.H7C import H7C
19
20
22 """Default local pre-commands for built-in matrix-element setups"""
23 return dedent(
24 """
25 ## =================================================
26 ## Local Pre-Commands from Herwig7ConfigBuiltinME.py
27 ## =================================================
28
29 # > no local pre-commands at the moment
30 """
31 )
32
33
35 """Default local post-commands for built-in matrix-element setups"""
36 return dedent(
37 f"""
38 ## ==================================================
39 ## Local Post-Commands from Herwig7ConfigBuiltinME.py
40 ## ==================================================
41
42 saverun {run_name} /Herwig/Generators/EventGenerator
43 """
44 )
45
46
47def _finalize_h7c_commands(h7c, shower_var=True):
48 """
49 Add the necessary settings fir beams, energy, seed,
50 etc. It uses the h7c object which inherits from Hw7Config,
51 so several of the methods called below are defined in the parent class.
52 """
53 h7c.default_commands += h7c.beam_commands()
54 h7c.default_commands += h7c.energy_commands()
55 h7c.default_commands += h7c.random_seed_commands()
56
57 if not h7c.set_printout_commands:
58 h7c.default_commands += h7c.printout_commands()
59 if not h7c.set_physics_parameter_commands:
60 h7c.default_commands += h7c.physics_parameter_commands()
61 if not h7c.set_technical_parameter_commands:
62 h7c.default_commands += h7c.technical_parameter_commands()
63
64 h7c.enable_angularShowerScaleVariations(shower_var)
65
66
68 name="Herwig7",
69 run_name="Herwig",
70 **kwargs):
71 """This is the CA equivalent of Herwig7Config.py"""
72
73 commands = kwargs.pop("commands", None)
74 shower_var = kwargs.pop("shower_var", True)
75 cleanup_herwig_scratch = kwargs.pop("cleanup_herwig_scratch", False)
76 local_pre_commands = kwargs.pop("local_pre_commands", None)
77 local_post_commands = kwargs.pop("local_post_commands", None)
78 me_pdf_order = kwargs.pop("me_pdf_order", None)
79 me_pdf_name = kwargs.pop("me_pdf_name", None)
80 mpi_pdf_name = kwargs.pop("mpi_pdf_name", None)
81 shower_pdf_order = kwargs.pop("shower_pdf_order", None)
82 shower_pdf_name = kwargs.pop("shower_pdf_name", None)
83
84 # Pop the tune - we don't want the user to set it in the jO
85 # and we also don't want to forward it to the C++ instance
86 # via the herwig7 object below
87 kwargs.pop("tune", None)
88
89 # Instantiate H7 algorithm with base settings
90 # TODO: add deduplication using GeneratorSettingsLayer as done in Pythia
91 herwig7 = CompFactory.Herwig7(name, **kwargs)
92 h7c = H7C(
93 flags,
94 run_name=run_name,
95 local_pre_commands=local_pre_commands,
96 local_post_commands=local_post_commands
97 )
98 h7c.add_flags(flags)
99
100 if me_pdf_name is not None:
101 h7c.me_pdf_commands(order=me_pdf_order or "NLO", name=me_pdf_name)
102
103 if mpi_pdf_name is not None:
104 h7c.mpi_pdf_commands(name=mpi_pdf_name)
105
106 if shower_pdf_name is not None:
107 h7c.shower_pdf_commands(order=shower_pdf_order or "LO", name=shower_pdf_name)
108
109 if commands:
110 h7c.add_commands(dedent(commands))
111
112 _finalize_h7c_commands(h7c, shower_var=shower_var)
113
114 from Herwig7_i import Herwig7Control as hw7Control
115
116 run_settings = hw7Control.render_infile(h7c)
117 hw7Control.configure_algorithm(
118 herwig7,
119 hw7Control.get_runfile_name(h7c.run_name),
120 h7c.random_seed,
121 me_pdf_name=h7c.me_pdf_name,
122 mpi_pdf_name=h7c.mpi_pdf_name,
123 cleanup_herwig_scratch=cleanup_herwig_scratch,
124 run_settings=run_settings,
125 )
126
127 # The algorithm is scheduled here. Athena executes it later with the evgen sequence
128 # so that there are no side effects.
129 ca = ComponentAccumulator(EvgenSequenceFactory(EvgenSequence.Generator))
130 ca.addEventAlgo(herwig7)
131
132 from GeneratorConfig.GeneratorInfoSvcConfig import GeneratorInfoSvcCfg
133 ca.merge(
134 GeneratorInfoSvcCfg(flags,
135 Generators=["Herwig7"],
136 Tune=hw7Control.default_tune_name()
137 )
138 )
139
140 return ca
141
142
144 name="Herwig7",
145 run_name="Herwig",
146 **kwargs):
147 """This is the CA equivalent of Herwig7ConfigBuiltinME.py"""
148
149 kwargs.setdefault("local_pre_commands", _builtin_me_local_pre_commands)
150 kwargs.setdefault("local_post_commands", lambda: _builtin_me_local_post_commands(run_name))
151
152 # Get CA from base fragment
153 return Herwig7BaseCfg(
154 flags,
155 name=name,
156 run_name=run_name,
157 **kwargs
158 )
Definition H7C.py:1
_finalize_h7c_commands(h7c, shower_var=True)
Herwig7BuiltinMECfg(flags, name="Herwig7", run_name="Herwig", **kwargs)
_builtin_me_local_post_commands(run_name)
Herwig7BaseCfg(flags, name="Herwig7", run_name="Herwig", **kwargs)