ATLAS Offline Software
Loading...
Searching...
No Matches
SherpaConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5from GeneratorConfig.Sequences import EvgenSequence, EvgenSequenceFactory
6
7# This configuration fragment contains the baseline Sherpa settings
8# and other higher-level configs that the users will call to create
9# the CA object in the setupProcess method of their sample config class
10# in the top-level jO.
11
12# Get logger
13from AthenaCommon.Logging import logging
14log = logging.getLogger("SherpaConfig")
15
16# Helper functions from SherpaUtils
17from Sherpa_i.SherpaUtils import (
18 build_sherpa3_base_fragment,
19 validate_sherpa3_yaml_fragment,
20 write_pretty_fragment
21)
22
23
24def SherpaBaseCfg(flags, name="Sherpa_i", **kwargs):
25 """
26 Public methods for Sherpa CA configuration fragment,
27 migrated from Sherpa_i/share/common/Base_Fragment.py.
28 This is the the method that users should call (if needed)
29 in their jO. We don't want them to change the BaseFragment
30 so we pop it from kwargs before calling the internal function.
31 """
32 kwargs.pop("BaseFragment", None)
33
34 return _SherpaBaseCfg(flags, name=name, **kwargs)
35
36
37def _SherpaBaseCfg(flags, name="Sherpa_i", _base_fragment="", **kwargs):
38 """
39 Internal Sherpa base fragment builder.
40 """
41
42 kwargs.setdefault("PluginCode", "")
43
44 # Build the Base.yaml fragment from an optional internal prefix plus Sherpa3 defaults.
45 base_fragment = _base_fragment
46 if base_fragment and not base_fragment.endswith("\n"):
47 base_fragment += "\n"
48 kwargs["BaseFragment"] = base_fragment + build_sherpa3_base_fragment(flags)
49 validate_sherpa3_yaml_fragment("BaseFragment", kwargs["BaseFragment"])
50 if "RunCard" in kwargs:
51 validate_sherpa3_yaml_fragment("RunCard", kwargs["RunCard"])
52
53 # Create CA object and add Sherpa algorithm
54 ca = ComponentAccumulator(EvgenSequenceFactory(EvgenSequence.Generator))
55 ca.addEventAlgo(CompFactory.Sherpa_i(name, **kwargs))
56
57 # Announce generator to service
58 from GeneratorConfig.GeneratorInfoSvcConfig import GeneratorInfoSvcCfg
59 ca.merge(GeneratorInfoSvcCfg(flags, Generators=["Sherpa"]))
60
61 return ca
62
63
64def Sherpa3_PDF4LHC21_Cfg(flags, **kwargs):
65 """Fragment for setting up Sherpa 3 with the PDF4LHC21 tune"""
66
67 from os import environ
68 sherpa_version = environ.get("SHERPAVER")
69 if sherpa_version is None:
70 raise RuntimeError("SHERPAVER is not set in the environment.")
71 if not sherpa_version.startswith("3."):
72 raise RuntimeError("Sherpa3_PDF4LHC21_Cfg requires Sherpa 3.")
73
74 # Nominal PDF settings
75 pdf_fragment = write_pretty_fragment(
76 """
77 PDF_LIBRARY: LHAPDFSherpa
78 USE_PDF_ALPHAS: 1
79 PDF_SET: PDF4LHC21_40_pdfas
80 """
81 )
82
83 # Enable PDF variations by default
84 pdf_fragment += write_pretty_fragment(
85 """
86 PDF_VARIATIONS:
87 - PDF4LHC21_40_pdfas*
88 - MSHT20nnlo_as118
89 - CT18NNLO_as_0118
90 - NNPDF31_nnlo_as_0118_hessian
91 - NNPDF40_nnlo_as_01180_hessian
92 - CT18ANNLO
93 - CT18XNNLO
94 - CT18ZNNLO
95 """
96 )
97
98 # Append PDF settings through the internal BaseFragment prefix and create the CA object.
99 ca = _SherpaBaseCfg(flags, _base_fragment=pdf_fragment, **kwargs)
100
101 # Broadcast tune to service
102 from GeneratorConfig.GeneratorInfoSvcConfig import GeneratorInfoSvcCfg
103 ca.merge(GeneratorInfoSvcCfg(flags, Tune="PDF4LHC21"))
104
105 return ca
SherpaBaseCfg(flags, name="Sherpa_i", **kwargs)
Sherpa3_PDF4LHC21_Cfg(flags, **kwargs)
_SherpaBaseCfg(flags, name="Sherpa_i", _base_fragment="", **kwargs)