ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
Sherpa_i
python
SherpaUtils.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
from
AthenaCommon.SystemOfUnits
import
GeV
4
5
# Get logger
6
from
AthenaCommon.Logging
import
logging
7
log = logging.getLogger(
"SherpaConfig"
)
8
9
10
def
write_pretty_fragment
(text):
11
"""
12
Keep multiline fragments readable in source code while preserving output indentation.
13
Sherpa_i C++ currently strips the first line and final character of the incoming string,
14
so we intentionally prepend a blank line and append a trailing newline.
15
"""
16
from
textwrap
import
dedent
17
return
"\n"
+ dedent(text).
strip
(
"\n"
) +
"\n"
18
19
20
def
validate_sherpa3_yaml_fragment
(fragment_name, fragment_text):
21
"""Validate Sherpa 3 YAML input."""
22
if
fragment_text
is
None
:
23
return
24
25
text = fragment_text
if
isinstance(fragment_text, str)
else
str(fragment_text)
26
if
not
text.strip():
27
return
28
29
try
:
30
import
yaml
31
except
Exception
as
exc:
32
log.warning(f
"YAML validation skipped for {fragment_name} (could not import yaml: {exc})"
)
33
return
34
35
try
:
36
yaml.compose(text)
37
except
Exception
as
exc:
38
mark = getattr(exc,
"problem_mark"
,
None
)
39
problem = getattr(exc,
"problem"
,
None
)
40
location =
""
41
if
mark
is
not
None
:
42
location = f
" (line {mark.line + 1}, column {mark.column + 1})"
43
44
detail = problem
if
problem
else
str(exc).splitlines()[0]
45
raise
RuntimeError(f
"{fragment_name} is invalid YAML{location}: {detail}"
)
46
47
48
def
_default_particle_data
():
49
"""Default particle data used in Sherpa base fragments"""
50
return
{
51
# mb consistent with McProductionCommonParametersMC15 and https://cds.cern.ch/record/2047636
52
"5"
: {
"mass"
:
"4.95"
,
"width"
:
"0."
},
53
"6"
: {
"mass"
:
"1.725E+02"
,
"width"
:
"1.32E+00"
},
54
"15"
: {
"mass"
:
"1.777"
,
"width"
:
"2.26735e-12"
},
55
"23"
: {
"mass"
:
"91.1876"
,
"width"
:
"2.4952"
},
56
"24"
: {
"mass"
:
"80.399"
,
"width"
:
"2.085"
},
57
}
58
59
60
def
build_sherpa3_base_fragment
(flags):
61
"""Build the Sherpa 3 BaseFragment YAML string."""
62
particle_data =
_default_particle_data
()
63
64
base_fragment =
write_pretty_fragment
(
65
f
"""
66
BEAMS: 2212
67
BEAM_ENERGIES: {flags.Beam.Energy / GeV}
68
69
MAX_PROPER_LIFETIME: 10.0
70
HEPMC_TREE_LIKE: 1
71
PRETTY_PRINT: Off
72
EXTERNAL_RNG: Atlas_RNG
73
74
OVERWEIGHT_THRESHOLD: 10
75
MC@NLO:
76
HPSMODE: 0
77
78
SCALE_VARIATIONS:
79
- 4.0*
80
81
PARTICLE_DATA:
82
"""
83
)
84
85
# Add particle data
86
for
pdg_id
in
sorted(particle_data, key=int):
87
values = particle_data[pdg_id]
88
base_fragment += (
89
f
" {pdg_id}:\n"
90
f
" Mass: {values['mass']}\n"
91
f
" Width: {values['width']}\n"
92
)
93
94
# Add hardcoded partial widths for H, W, Z decays
95
# and OpenLoops parameters
96
base_fragment +=
write_pretty_fragment
(
97
"""
98
EW_SCHEME: Gmu
99
GF: 1.166397e-5
100
101
HARD_DECAYS:
102
Enabled: true
103
Channels:
104
"6 -> 24 5": { Width: 1.32 }
105
"-6 -> -24 -5": { Width: 1.32 }
106
"25 -> 5 -5": { Width: 2.35e-3 }
107
"25 -> 15 -15": { Width: 2.57e-4 }
108
"25 -> 13 -13": { Width: 8.91e-7 }
109
"25 -> 4 -4": { Width: 1.18e-4 }
110
"25 -> 3 -3": { Width: 1.00e-6 }
111
"25 -> 21 21": { Width: 3.49e-4 }
112
"25 -> 22 22": { Width: 9.28e-6 }
113
"24 -> 2 -1": { Width: 0.7041 }
114
"24 -> 4 -3": { Width: 0.7041 }
115
"24 -> 12 -11": { Width: 0.2256 }
116
"24 -> 14 -13": { Width: 0.2256 }
117
"24 -> 16 -15": { Width: 0.2256 }
118
"-24 -> -2 1": { Width: 0.7041 }
119
"-24 -> -4 3": { Width: 0.7041 }
120
"-24 -> -12 11": { Width: 0.2256 }
121
"-24 -> -14 13": { Width: 0.2256 }
122
"-24 -> -16 15": { Width: 0.2256 }
123
"23 -> 1 -1": { Width: 0.3828 }
124
"23 -> 2 -2": { Width: 0.2980 }
125
"23 -> 3 -3": { Width: 0.3828 }
126
"23 -> 4 -4": { Width: 0.2980 }
127
"23 -> 5 -5": { Width: 0.3828 }
128
"23 -> 11 -11": { Width: 0.0840 }
129
"23 -> 12 -12": { Width: 0.1663 }
130
"23 -> 13 -13": { Width: 0.0840 }
131
"23 -> 14 -14": { Width: 0.1663 }
132
"23 -> 15 -15": { Width: 0.0840 }
133
"23 -> 16 -16": { Width: 0.1663 }
134
OL_PARAMETERS:
135
preset: 2
136
write_parameters: 1
137
"""
138
)
139
140
# Add OpenLoops prefix if available in environment
141
from
os
import
environ
142
openloops_path = environ.get(
"OPENLOOPSPATH"
)
143
if
openloops_path:
144
base_fragment += f
"OL_PREFIX: {openloops_path}\n"
145
else
:
146
log.warning(
"OPENLOOPSPATH not set"
)
147
148
return
base_fragment
SiliconTech::strip
@ strip
Definition
FPGATrackSimTypes.h:25
python.SherpaUtils.build_sherpa3_base_fragment
build_sherpa3_base_fragment(flags)
Definition
SherpaUtils.py:60
python.SherpaUtils.write_pretty_fragment
write_pretty_fragment(text)
Definition
SherpaUtils.py:10
python.SherpaUtils._default_particle_data
_default_particle_data()
Definition
SherpaUtils.py:48
python.SherpaUtils.validate_sherpa3_yaml_fragment
validate_sherpa3_yaml_fragment(fragment_name, fragment_text)
Definition
SherpaUtils.py:20
Generated on
for ATLAS Offline Software by
1.17.0