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 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 95 of file SystematicsSvc.cxx.

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 }
#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 256 of file SystematicsSvc.cxx.

258 {
259 if (m_systematicsList.empty()) {
260 ANA_MSG_INFO ("no systematics were run.");
261 }
262 else{
263 for (const CP::SystematicVariation& mysys : m_affectingSystematics)
264 {
265 // this logic checks whether a systematic is recommended and
266 // affecting, or only affecting. if it is only the later, it
267 // reports the systematic in parenthesis to set it apart.
268 if (m_recommendedSystematics.find (mysys) == m_recommendedSystematics.end())
269 ANA_MSG_INFO ("found systematic: (" << mysys << ")");
270 else
271 ANA_MSG_INFO ("found systematic: " << mysys);
272 }
273
274 if(m_systematicsRegex!=".*") {
275 ANA_MSG_INFO("Systematics regex '" << m_systematicsRegex << "' matched:");
276 for(const CP::SystematicSet& mysys : makeSystematicsVector()) {
277 ANA_MSG_INFO (" '" << mysys.name() << "'");
278 }
279 }
280 }
281 return StatusCode::SUCCESS;
282 }
#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 209 of file SystematicsSvc.cxx.

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 }

◆ getDecorSystematics()

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

Definition at line 150 of file SystematicsSvc.cxx.

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 }
virtual CP::SystematicSet getDecorSystematics(const std::string &objectName, const std::string &decorName) const override

◆ getObjectSystematics()

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

Definition at line 117 of file SystematicsSvc.cxx.

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 }

◆ initialize()

StatusCode CP::SystematicsSvc::initialize ( )
overridevirtual

Definition at line 29 of file SystematicsSvc.cxx.

31 {
32 if (!std::isfinite (m_sigmaRecommended) ||
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 }
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 222 of file SystematicsSvc.cxx.

226 {
227 if (name.empty())
228 {
229 ANA_MSG_ERROR ("not allowed to make systematic name for empty string");
230 return StatusCode::FAILURE;
231 }
232
233 result = name;
234
235 const auto sysSplit = result.find ("%SYS%");
236 if (sysSplit == std::string::npos)
237 {
238 if (!sys.empty())
239 {
240 ANA_MSG_ERROR ("can't set systematics on name without \"%SYS%\": \"" << name << "\" sys=" << sys.name());
241 return StatusCode::FAILURE;
242 }
243 } else
244 {
245 std::string sysName = sys.name();
246 if (sysName.empty())
248 result.replace (sysSplit, 5, sysName);
249 }
250
251 return StatusCode::SUCCESS;
252 }
Gaudi::Property< std::string > m_nominalSystematicsName
nominal systematics name

◆ makeSystematicsVector()

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

Definition at line 52 of file SystematicsSvc.cxx.

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 }
#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 193 of file SystematicsSvc.cxx.

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 }

◆ setDecorSystematics()

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

Definition at line 171 of file SystematicsSvc.cxx.

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 }
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 130 of file SystematicsSvc.cxx.

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 }

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 91 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 95 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 99 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 103 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 107 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 86 of file SystematicsSvc.h.

86{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 82 of file SystematicsSvc.h.

82{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 69 of file SystematicsSvc.h.

69{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 111 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 73 of file SystematicsSvc.h.

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

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