ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
SystematicsHandles
Root
SystematicsSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
SystematicsHandles/SystematicsSvc.h
>
13
14
#include <
AsgMessaging/MessageCheck.h
>
15
#include <
PATInterfaces/MakeSystematicsVector.h
>
16
#include <algorithm>
17
#include <cassert>
18
#include <cmath>
19
#include <regex>
20
#include <functional>
21
22
//
23
// method implementations
24
//
25
26
namespace
CP
27
{
28
29
StatusCode SystematicsSvc ::
30
initialize ()
31
{
32
if
(!std::isfinite (
m_sigmaRecommended
) ||
33
m_sigmaRecommended
< 0)
34
{
35
ANA_MSG_ERROR
(
"invalid value for sigmaRecommended: "
<<
m_sigmaRecommended
);
36
return
StatusCode::FAILURE;
37
}
38
39
if
(
m_sigmaRecommended
!= 0)
40
{
41
if
(!
m_systematicsList
.empty())
42
{
43
ANA_MSG_ERROR
(
"can't specify both sigmaRecommended and systematicsList"
);
44
return
StatusCode::FAILURE;
45
}
46
}
47
return
StatusCode::SUCCESS;
48
}
49
50
51
52
std::vector<CP::SystematicSet> SystematicsSvc ::
53
makeSystematicsVector ()
const
54
{
55
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
56
std::vector<CP::SystematicSet> systematicsVector;
57
58
if
(
m_sigmaRecommended
!= 0)
59
{
60
assert (
m_sigmaRecommended
> 0);
61
62
CP::MakeSystematicsVector
sys;
63
sys.setSigma (
m_sigmaRecommended
);
64
sys.calc (m_recommendedSystematics);
65
66
std::regex expr (
m_systematicsRegex
.value());
67
for
(
const
CP::SystematicSet
& mysys : sys.result(
""
))
68
{
69
if
(!regex_match (mysys.name(), expr))
70
{
71
ANA_MSG_DEBUG
(
"skipping systematic: "
<< mysys.name());
72
}
else
{
73
ANA_MSG_DEBUG
(
"configuring systematic: "
<< mysys.name());
74
systematicsVector.push_back (mysys);
75
}
76
}
77
}
else
if
(
m_systematicsList
.empty())
78
{
79
// take an empty property as running just the central
80
// systematics set. implication is that you can't really run
81
// doing nothing, but that ought to be Ok.
82
systematicsVector.push_back (
CP::SystematicSet
());
83
}
else
84
{
85
for
(
const
std::string& sysName :
m_systematicsList
)
86
systematicsVector.push_back (
CP::SystematicSet
(sysName));
87
}
88
89
assert (!systematicsVector.empty());
90
return
systematicsVector;
91
}
92
93
94
95
StatusCode SystematicsSvc ::
96
addSystematics (
const
CP::SystematicSet
& recommended,
97
const
CP::SystematicSet
& affecting)
const
98
{
99
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
100
101
for
(
const
CP::SystematicVariation
& mysys : recommended)
102
{
103
if
(affecting.
find
(mysys) == affecting.
end
())
104
{
105
ANA_MSG_ERROR
(
"systematic is only registered as recommended, not affecting: "
<< mysys);
106
return
StatusCode::FAILURE;
107
}
108
}
109
110
m_affectingSystematics.insert (affecting);
111
m_recommendedSystematics.insert (recommended);
112
return
StatusCode::SUCCESS;
113
}
114
115
116
117
CP::SystematicSet
SystematicsSvc ::
118
getObjectSystematics (
const
std::string&
name
)
const
119
{
120
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
121
auto
iter = m_objectSystematics.find (
name
);
122
if
(iter != m_objectSystematics.end())
123
return
iter->second;
124
else
125
return
CP::SystematicSet
();
126
}
127
128
129
130
StatusCode SystematicsSvc ::
131
setObjectSystematics (
const
std::string&
name
,
132
const
CP::SystematicSet
&
systematics
)
const
133
{
134
auto
mysystematics =
systematics
;
135
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
136
for
(
const
CP::SystematicVariation
& mysys :
systematics
)
137
{
138
if
(m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
139
{
140
ANA_MSG_ERROR
(
"systematic is set as object systematic, but not affecting: "
<< mysys);
141
return
StatusCode::FAILURE;
142
}
143
}
144
m_objectSystematics[
name
] = std::move (mysystematics);
145
return
StatusCode::SUCCESS;
146
}
147
148
149
150
CP::SystematicSet
SystematicsSvc ::
151
getDecorSystematics (
const
std::string& objectName,
152
const
std::string& decorName)
const
153
{
154
const
std::string
name
= objectName +
"."
+ decorName;
155
std::unique_lock<std::mutex>
lock
(
m_systematicsMutex
);
156
auto
iter = m_decorSystematics.find (
name
);
157
if
(iter != m_decorSystematics.end())
158
return
iter->second;
159
auto
jter = m_copies.find (objectName);
160
if
(jter != m_copies.end())
161
{
162
const
std::string& copyName = jter->second;
163
lock
.unlock();
164
return
getDecorSystematics
(copyName, decorName);
165
}
166
return
CP::SystematicSet
();
167
}
168
169
170
171
StatusCode SystematicsSvc ::
172
setDecorSystematics (
const
std::string& objectName,
173
const
std::string& decorName,
174
const
CP::SystematicSet
&
systematics
)
const
175
{
176
const
std::string
name
= objectName +
"."
+ decorName;
177
auto
mysystematics =
systematics
;
178
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
179
for
(
const
CP::SystematicVariation
& mysys :
systematics
)
180
{
181
if
(m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
182
{
183
ANA_MSG_ERROR
(
"systematic is set as object systematic, but not affecting: "
<< mysys);
184
return
StatusCode::FAILURE;
185
}
186
}
187
m_decorSystematics[
name
] = std::move (mysystematics);
188
return
StatusCode::SUCCESS;
189
}
190
191
192
193
StatusCode SystematicsSvc ::
194
registerCopy (
const
std::string& fromName,
195
const
std::string& toName)
const
196
{
197
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
198
auto
emplace_result = m_copies.try_emplace (toName, fromName);
199
if
(emplace_result.second ==
false
)
200
{
201
ANA_MSG_ERROR
(
"duplicate copy registered for name "
<< toName);
202
return
StatusCode::FAILURE;
203
}
204
return
StatusCode::SUCCESS;
205
}
206
207
208
209
std::string SystematicsSvc ::
210
getCopySource (
const
std::string& toName)
const
211
{
212
std::lock_guard<std::mutex>
lock
(
m_systematicsMutex
);
213
auto
iter = m_copies.find (toName);
214
if
(iter == m_copies.end())
215
return
""
;
216
else
217
return
iter->second;
218
}
219
220
221
222
std::vector<std::string> SystematicsSvc ::
223
getObjectDecorations (
const
std::string&
name
)
const
224
{
225
std::vector<std::string> result;
226
std::unique_lock<std::mutex>
lock
(
m_systematicsMutex
);
227
228
// First get decorations from the copy source (if any)
229
auto
iter = m_copies.find (
name
);
230
if
(iter != m_copies.end())
231
{
232
const
std::string copyName = iter->second;
233
lock
.unlock();
234
result =
getObjectDecorations
(copyName);
235
lock
.lock();
236
}
237
238
// Then add decorations registered directly on this object
239
const
std::string prefix =
name
+
"."
;
240
for
(
const
auto
& entry : m_decorSystematics)
241
{
242
if
(entry.first.compare(0, prefix.size(), prefix) == 0)
243
{
244
std::string decor = entry.first.substr(prefix.size());
245
if
(std::find(result.begin(), result.end(), decor) == result.end())
246
result.push_back (std::move(decor));
247
}
248
}
249
return
result;
250
}
251
252
253
254
StatusCode SystematicsSvc ::
255
makeSystematicsName (std::string& result,
256
const
std::string&
name
,
257
const
CP::SystematicSet
& sys)
const
258
{
259
if
(
name
.empty())
260
{
261
ANA_MSG_ERROR
(
"not allowed to make systematic name for empty string"
);
262
return
StatusCode::FAILURE;
263
}
264
265
result =
name
;
266
267
const
auto
sysSplit = result.find (
"%SYS%"
);
268
if
(sysSplit == std::string::npos)
269
{
270
if
(!sys.empty())
271
{
272
ANA_MSG_ERROR
(
"can't set systematics on name without \"%SYS%\": \""
<<
name
<<
"\" sys="
<< sys.name());
273
return
StatusCode::FAILURE;
274
}
275
}
else
276
{
277
std::string sysName = sys.name();
278
if
(sysName.empty())
279
sysName =
m_nominalSystematicsName
;
280
result.replace (sysSplit, 5, sysName);
281
}
282
283
return
StatusCode::SUCCESS;
284
}
285
286
287
288
StatusCode SystematicsSvc ::
289
finalize ()
290
{
291
if
(
m_systematicsList
.empty()) {
292
ANA_MSG_INFO
(
"no systematics were run."
);
293
}
294
else
{
295
for
(
const
CP::SystematicVariation
& mysys : m_affectingSystematics)
296
{
297
// this logic checks whether a systematic is recommended and
298
// affecting, or only affecting. if it is only the later, it
299
// reports the systematic in parenthesis to set it apart.
300
if
(m_recommendedSystematics.find (mysys) == m_recommendedSystematics.end())
301
ANA_MSG_INFO
(
"found systematic: ("
<< mysys <<
")"
);
302
else
303
ANA_MSG_INFO
(
"found systematic: "
<< mysys);
304
}
305
306
if
(
m_systematicsRegex
!=
".*"
) {
307
ANA_MSG_INFO
(
"Systematics regex '"
<<
m_systematicsRegex
<<
"' matched:"
);
308
for
(
const
CP::SystematicSet
& mysys :
makeSystematicsVector
()) {
309
ANA_MSG_INFO
(
" '"
<< mysys.name() <<
"'"
);
310
}
311
}
312
}
313
return
StatusCode::SUCCESS;
314
}
315
}
MessageCheck.h
macros for messaging and checking status codes
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
MakeSystematicsVector.h
systematics
static const std::vector< std::string > systematics
Definition
MuonTriggerSFFilesTest.cxx:23
SystematicsSvc.h
CP::MakeSystematicsVector
This class handles turning the list of systematics into the actual list of nuisance parameter points ...
Definition
MakeSystematicsVector.h:34
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition
SystematicSet.h:31
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition
SystematicSet.h:59
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition
SystematicSet.h:63
CP::SystematicVariation
Definition
SystematicVariation.h:47
CP::SystematicsSvc::m_nominalSystematicsName
Gaudi::Property< std::string > m_nominalSystematicsName
nominal systematics name
Definition
SystematicsSvc.h:88
CP::SystematicsSvc::makeSystematicsVector
virtual std::vector< CP::SystematicSet > makeSystematicsVector() const override
Definition
SystematicsSvc.cxx:53
CP::SystematicsSvc::m_systematicsList
Gaudi::Property< std::vector< std::string > > m_systematicsList
the names of the systematics to request
Definition
SystematicsSvc.h:71
CP::SystematicsSvc::m_sigmaRecommended
Gaudi::Property< float > m_sigmaRecommended
load all recommended systematics at the given number of sigmas
Definition
SystematicsSvc.h:84
CP::SystematicsSvc::m_systematicsMutex
std::mutex m_systematicsMutex
a mutex for accessing the above mutable members
Definition
SystematicsSvc.h:113
CP::SystematicsSvc::m_systematicsRegex
Gaudi::Property< std::string > m_systematicsRegex
the regular expression for filterinf systematics
Definition
SystematicsSvc.h:75
CP::SystematicsSvc::getDecorSystematics
virtual CP::SystematicSet getDecorSystematics(const std::string &objectName, const std::string &decorName) const override
Definition
SystematicsSvc.cxx:151
CP::SystematicsSvc::getObjectDecorations
virtual std::vector< std::string > getObjectDecorations(const std::string &name) const override
Definition
SystematicsSvc.cxx:223
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
xAOD::name
name
Definition
TriggerMenuJson_v1.cxx:29
Generated on
for ATLAS Offline Software by
1.17.0