ATLAS Offline Software
Loading...
Searching...
No Matches
CP::SystematicsSvc Class Referencefinal

the canonical implementation of ISystematicsSvc More...

#include <SystematicsSvc.h>

Inheritance diagram for CP::SystematicsSvc:
Collaboration diagram for CP::SystematicsSvc:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual std::vector< CP::SystematicSetmakeSystematicsVector () const override
virtual StatusCode addSystematics (const CP::SystematicSet &recommended, const CP::SystematicSet &affecting) const override
virtual CP::SystematicSet getObjectSystematics (const std::string &name) const override
virtual StatusCode setObjectSystematics (const std::string &name, const CP::SystematicSet &systematics) const override
virtual CP::SystematicSet getDecorSystematics (const std::string &objectName, const std::string &decorName) const override
virtual StatusCode setDecorSystematics (const std::string &objectName, const std::string &decorName, const CP::SystematicSet &systematics) const override
virtual StatusCode registerCopy (const std::string &fromName, const std::string &toName) const override
virtual std::string getCopySource (const std::string &toName) const override
virtual std::vector< std::string > getObjectDecorations (const std::string &name) const override
virtual StatusCode makeSystematicsName (std::string &result, const std::string &name, const CP::SystematicSet &sys) const override

Private Attributes

Gaudi::Property< std::vector< std::string > > m_systematicsList {this, "systematicsList", {}, "the list of systematics to run"}
 the names of the systematics to request
Gaudi::Property< std::string > m_systematicsRegex {this, "systematicsRegex", "(.*)", "systematics filter regex"}
 the regular expression for filterinf systematics
Gaudi::Property< floatm_sigmaRecommended {this, "sigmaRecommended", 0, "the sigma with which to run recommended systematics"}
 load all recommended systematics at the given number of sigmas
Gaudi::Property< std::string > m_nominalSystematicsName {this, "nominalSystematicsName", "NOSYS", "the name to use for the nominal systematic (instead of the empty string)"}
 nominal systematics name
SystematicSet m_affectingSystematics ATLAS_THREAD_SAFE
 the list of affecting systematics
SystematicSet m_recommendedSystematics ATLAS_THREAD_SAFE
 the list of recommended systematics
std::unordered_map< std::string, CP::SystematicSet > m_objectSystematics ATLAS_THREAD_SAFE
 the list of per-object systematics
std::unordered_map< std::string, CP::SystematicSet > m_decorSystematics ATLAS_THREAD_SAFE
 the list of per-object-and-decoration systematics
std::unordered_map< std::string, std::string > m_copies ATLAS_THREAD_SAFE
 the map of registered copies
std::mutex m_systematicsMutex
 a mutex for accessing the above mutable members

Detailed Description

the canonical implementation of ISystematicsSvc

Definition at line 23 of file SystematicsSvc.h.

Member Function Documentation

◆ addSystematics()

StatusCode CP::SystematicsSvc::addSystematics ( const CP::SystematicSet & recommended,
const CP::SystematicSet & affecting ) const
overridevirtual

Definition at line 96 of file SystematicsSvc.cxx.

99 {
100 std::lock_guard<std::mutex> lock (m_systematicsMutex);
101
102 for (const CP::SystematicVariation& mysys : recommended)
103 {
104 if (affecting.find (mysys) == affecting.end())
105 {
106 ANA_MSG_ERROR ("systematic is only registered as recommended, not affecting: " << mysys);
107 return StatusCode::FAILURE;
108 }
109 }
110
111 m_affectingSystematics.insert (affecting);
112 m_recommendedSystematics.insert (recommended);
113 return StatusCode::SUCCESS;
114 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
const_iterator end() const
description: const iterator to the end of the set
iterator find(const SystematicVariation &sys) const
description: find an element in the set
std::mutex m_systematicsMutex
a mutex for accessing the above mutable members

◆ finalize()

StatusCode CP::SystematicsSvc::finalize ( )
overridevirtual

Definition at line 289 of file SystematicsSvc.cxx.

291 {
292 if (m_systematicsList.empty()) {
293 ANA_MSG_INFO ("no systematics were run.");
294 }
295 else{
296 for (const CP::SystematicVariation& mysys : m_affectingSystematics)
297 {
298 // this logic checks whether a systematic is recommended and
299 // affecting, or only affecting. if it is only the later, it
300 // reports the systematic in parenthesis to set it apart.
301 if (m_recommendedSystematics.find (mysys) == m_recommendedSystematics.end())
302 ANA_MSG_INFO ("found systematic: (" << mysys << ")");
303 else
304 ANA_MSG_INFO ("found systematic: " << mysys);
305 }
306
307 if(m_systematicsRegex!=".*") {
308 ANA_MSG_INFO("Systematics regex '" << m_systematicsRegex << "' matched:");
309 for(const CP::SystematicSet& mysys : makeSystematicsVector()) {
310 ANA_MSG_INFO (" '" << mysys.name() << "'");
311 }
312 }
313 }
314 return StatusCode::SUCCESS;
315 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
virtual std::vector< CP::SystematicSet > makeSystematicsVector() const override
Gaudi::Property< std::vector< std::string > > m_systematicsList
the names of the systematics to request
Gaudi::Property< std::string > m_systematicsRegex
the regular expression for filterinf systematics

◆ getCopySource()

std::string CP::SystematicsSvc::getCopySource ( const std::string & toName) const
overridevirtual

Definition at line 210 of file SystematicsSvc.cxx.

212 {
213 std::lock_guard<std::mutex> lock (m_systematicsMutex);
214 auto iter = m_copies.find (toName);
215 if (iter == m_copies.end())
216 return "";
217 else
218 return iter->second;
219 }

◆ getDecorSystematics()

CP::SystematicSet CP::SystematicsSvc::getDecorSystematics ( const std::string & objectName,
const std::string & decorName ) const
overridevirtual

Definition at line 151 of file SystematicsSvc.cxx.

154 {
155 const std::string name = objectName + "." + decorName;
156 std::unique_lock<std::mutex> lock (m_systematicsMutex);
157 auto iter = m_decorSystematics.find (name);
158 if (iter != m_decorSystematics.end())
159 return iter->second;
160 auto jter = m_copies.find (objectName);
161 if (jter != m_copies.end())
162 {
163 const std::string& copyName = jter->second;
164 lock.unlock();
165 return getDecorSystematics (copyName, decorName);
166 }
167 return CP::SystematicSet ();
168 }
virtual CP::SystematicSet getDecorSystematics(const std::string &objectName, const std::string &decorName) const override

◆ getObjectDecorations()

std::vector< std::string > CP::SystematicsSvc::getObjectDecorations ( const std::string & name) const
overridevirtual

Definition at line 223 of file SystematicsSvc.cxx.

225 {
226 std::vector<std::string> result;
227 std::unique_lock<std::mutex> lock (m_systematicsMutex);
228
229 // First get decorations from the copy source (if any)
230 auto iter = m_copies.find (name);
231 if (iter != m_copies.end())
232 {
233 const std::string copyName = iter->second;
234 lock.unlock();
235 result = getObjectDecorations (copyName);
236 lock.lock();
237 }
238
239 // Then add decorations registered directly on this object
240 const std::string prefix = name + ".";
241 for (const auto& entry : m_decorSystematics)
242 {
243 if (entry.first.compare(0, prefix.size(), prefix) == 0)
244 {
245 std::string decor = entry.first.substr(prefix.size());
246 if (std::find(result.begin(), result.end(), decor) == result.end())
247 result.push_back (std::move(decor));
248 }
249 }
250 return result;
251 }
virtual std::vector< std::string > getObjectDecorations(const std::string &name) const override

◆ getObjectSystematics()

CP::SystematicSet CP::SystematicsSvc::getObjectSystematics ( const std::string & name) const
overridevirtual

Definition at line 118 of file SystematicsSvc.cxx.

120 {
121 std::lock_guard<std::mutex> lock (m_systematicsMutex);
122 auto iter = m_objectSystematics.find (name);
123 if (iter != m_objectSystematics.end())
124 return iter->second;
125 else
126 return CP::SystematicSet ();
127 }

◆ initialize()

StatusCode CP::SystematicsSvc::initialize ( )
overridevirtual

Definition at line 30 of file SystematicsSvc.cxx.

32 {
33 if (!std::isfinite (m_sigmaRecommended) ||
35 {
36 ANA_MSG_ERROR ("invalid value for sigmaRecommended: " << m_sigmaRecommended);
37 return StatusCode::FAILURE;
38 }
39
40 if (m_sigmaRecommended != 0)
41 {
42 if (!m_systematicsList.empty())
43 {
44 ANA_MSG_ERROR ("can't specify both sigmaRecommended and systematicsList");
45 return StatusCode::FAILURE;
46 }
47 }
48 return StatusCode::SUCCESS;
49 }
Gaudi::Property< float > m_sigmaRecommended
load all recommended systematics at the given number of sigmas

◆ makeSystematicsName()

StatusCode CP::SystematicsSvc::makeSystematicsName ( std::string & result,
const std::string & name,
const CP::SystematicSet & sys ) const
overridevirtual

Definition at line 255 of file SystematicsSvc.cxx.

259 {
260 if (name.empty())
261 {
262 ANA_MSG_ERROR ("not allowed to make systematic name for empty string");
263 return StatusCode::FAILURE;
264 }
265
266 result = name;
267
268 const auto sysSplit = result.find ("%SYS%");
269 if (sysSplit == std::string::npos)
270 {
271 if (!sys.empty())
272 {
273 ANA_MSG_ERROR ("can't set systematics on name without \"%SYS%\": \"" << name << "\" sys=" << sys.name());
274 return StatusCode::FAILURE;
275 }
276 } else
277 {
278 std::string sysName = sys.name();
279 if (sysName.empty())
281 result.replace (sysSplit, 5, sysName);
282 }
283
284 return StatusCode::SUCCESS;
285 }
Gaudi::Property< std::string > m_nominalSystematicsName
nominal systematics name

◆ makeSystematicsVector()

std::vector< CP::SystematicSet > CP::SystematicsSvc::makeSystematicsVector ( ) const
overridevirtual

Definition at line 53 of file SystematicsSvc.cxx.

55 {
56 std::lock_guard<std::mutex> lock (m_systematicsMutex);
57 std::vector<CP::SystematicSet> systematicsVector;
58
59 if (m_sigmaRecommended != 0)
60 {
61 assert (m_sigmaRecommended > 0);
62
63 CP::MakeSystematicsVector sys;
64 sys.setSigma (m_sigmaRecommended);
65 sys.calc (m_recommendedSystematics);
66
67 std::regex expr (m_systematicsRegex.value());
68 for (const CP::SystematicSet& mysys : sys.result(""))
69 {
70 if (!regex_match (mysys.name(), expr))
71 {
72 ANA_MSG_DEBUG ("skipping systematic: " << mysys.name());
73 } else {
74 ANA_MSG_DEBUG ("configuring systematic: " << mysys.name());
75 systematicsVector.push_back (mysys);
76 }
77 }
78 } else if (m_systematicsList.empty())
79 {
80 // take an empty property as running just the central
81 // systematics set. implication is that you can't really run
82 // doing nothing, but that ought to be Ok.
83 systematicsVector.push_back (CP::SystematicSet ());
84 } else
85 {
86 for (const std::string& sysName : m_systematicsList)
87 systematicsVector.push_back (CP::SystematicSet (sysName));
88 }
89
90 assert (!systematicsVector.empty());
91 return systematicsVector;
92 }
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.

◆ registerCopy()

StatusCode CP::SystematicsSvc::registerCopy ( const std::string & fromName,
const std::string & toName ) const
overridevirtual

Definition at line 194 of file SystematicsSvc.cxx.

197 {
198 std::lock_guard<std::mutex> lock (m_systematicsMutex);
199 auto emplace_result = m_copies.try_emplace (toName, fromName);
200 if (emplace_result.second == false)
201 {
202 ANA_MSG_ERROR ("duplicate copy registered for name " << toName);
203 return StatusCode::FAILURE;
204 }
205 return StatusCode::SUCCESS;
206 }

◆ setDecorSystematics()

StatusCode CP::SystematicsSvc::setDecorSystematics ( const std::string & objectName,
const std::string & decorName,
const CP::SystematicSet & systematics ) const
overridevirtual

Definition at line 172 of file SystematicsSvc.cxx.

176 {
177 const std::string name = objectName + "." + decorName;
178 auto mysystematics = systematics;
179 std::lock_guard<std::mutex> lock (m_systematicsMutex);
180 for (const CP::SystematicVariation& mysys : systematics)
181 {
182 if (m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
183 {
184 ANA_MSG_ERROR ("systematic is set as object systematic, but not affecting: " << mysys);
185 return StatusCode::FAILURE;
186 }
187 }
188 m_decorSystematics[name] = std::move (mysystematics);
189 return StatusCode::SUCCESS;
190 }
static const std::vector< std::string > systematics

◆ setObjectSystematics()

StatusCode CP::SystematicsSvc::setObjectSystematics ( const std::string & name,
const CP::SystematicSet & systematics ) const
overridevirtual

Definition at line 131 of file SystematicsSvc.cxx.

134 {
135 auto mysystematics = systematics;
136 std::lock_guard<std::mutex> lock (m_systematicsMutex);
137 for (const CP::SystematicVariation& mysys : systematics)
138 {
139 if (m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
140 {
141 ANA_MSG_ERROR ("systematic is set as object systematic, but not affecting: " << mysys);
142 return StatusCode::FAILURE;
143 }
144 }
145 m_objectSystematics[name] = std::move (mysystematics);
146 return StatusCode::SUCCESS;
147 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/5]

SystematicSet m_affectingSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of affecting systematics

Definition at line 93 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [2/5]

SystematicSet m_recommendedSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of recommended systematics

Definition at line 97 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [3/5]

std::unordered_map<std::string,CP::SystematicSet> m_objectSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of per-object systematics

Definition at line 101 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [4/5]

std::unordered_map<std::string,CP::SystematicSet> m_decorSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of per-object-and-decoration systematics

Definition at line 105 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [5/5]

std::unordered_map<std::string,std::string> m_copies CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the map of registered copies

Definition at line 109 of file SystematicsSvc.h.

◆ m_nominalSystematicsName

Gaudi::Property<std::string> CP::SystematicsSvc::m_nominalSystematicsName {this, "nominalSystematicsName", "NOSYS", "the name to use for the nominal systematic (instead of the empty string)"}
private

nominal systematics name

Definition at line 88 of file SystematicsSvc.h.

88{this, "nominalSystematicsName", "NOSYS", "the name to use for the nominal systematic (instead of the empty string)"};

◆ m_sigmaRecommended

Gaudi::Property<float> CP::SystematicsSvc::m_sigmaRecommended {this, "sigmaRecommended", 0, "the sigma with which to run recommended systematics"}
private

load all recommended systematics at the given number of sigmas

The idea here is that this allows to run a simple analysis by itself without having to generate the list of systematics manually.

Definition at line 84 of file SystematicsSvc.h.

84{this, "sigmaRecommended", 0, "the sigma with which to run recommended systematics"};

◆ m_systematicsList

Gaudi::Property<std::vector<std::string> > CP::SystematicsSvc::m_systematicsList {this, "systematicsList", {}, "the list of systematics to run"}
private

the names of the systematics to request

Definition at line 71 of file SystematicsSvc.h.

71{this, "systematicsList", {}, "the list of systematics to run"};

◆ m_systematicsMutex

std::mutex CP::SystematicsSvc::m_systematicsMutex
mutableprivate

a mutex for accessing the above mutable members

Definition at line 113 of file SystematicsSvc.h.

◆ m_systematicsRegex

Gaudi::Property<std::string> CP::SystematicsSvc::m_systematicsRegex {this, "systematicsRegex", "(.*)", "systematics filter regex"}
private

the regular expression for filterinf systematics

Definition at line 75 of file SystematicsSvc.h.

75{this, "systematicsRegex", "(.*)", "systematics filter regex"};

The documentation for this class was generated from the following files: