ATLAS Offline Software
Loading...
Searching...
No Matches
CP::SystematicSet Class Reference

Class to wrap a set of SystematicVariations. More...

#include <SystematicSet.h>

Collaboration diagram for CP::SystematicSet:

Public Types

enum  MATCHTYPE { FULL , FULLORCONTINUOUS }
 description: match systematic or continuous version More...
typedef std::set< SystematicVariation >::iterator iterator
typedef std::set< SystematicVariation >::const_iterator const_iterator

Public Member Functions

 SystematicSet ()
 construct an empty set
 SystematicSet (const std::string &systematics)
 construct set by splitting single systematics string
 SystematicSet (const std::vector< std::string > &systematics)
 construct by vector of systematic names
 SystematicSet (const std::vector< SystematicVariation > &systematics)
 construct by vector of SystematicVariation
 SystematicSet (const std::initializer_list< SystematicVariation > &systematics)
 construct with an std::initializer_list
const_iterator begin () const
 description: const iterator to the beginning of the set
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
bool empty () const
 returns: whether the set is empty
size_t size () const
 returns: size of the set
void insert (const SystematicVariation &systematic)
 description: insert a systematic into the set
void insert (const SystematicSet &systematics)
 description: insert a systematic set into this set
void swap (SystematicSet &otherSet)
 description: swap elements of a set
void clear ()
 description: clear the set
bool matchSystematic (const SystematicVariation &systematic, MATCHTYPE type=FULL) const
SystematicSet filterByBaseName (const std::string &basename) const
 description: get the subset of systematics matching basename Should this return a StatusCode instead?
std::set< std::string > getBaseNames () const
 description: get the set of base systematic names from this set
SystematicVariation getSystematicByBaseName (const std::string &basename) const
 description: get the first systematic matching basename
float getParameterByBaseName (const std::string &basename) const
 returns: the parameter value for the given basename
std::pair< unsigned, floatgetToyVariationByBaseName (const std::string &basename) const
 the toy variation for the given basename
std::string name () const
 returns: the systematics joined into a single string.
std::size_t hash () const
 returns: hash value for the joined string.

Static Public Member Functions

static StatusCode filterForAffectingSystematics (const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
 description: filter the systematics for the affected systematics returns: success guarantee: strong failures: out of memory II failures: requesting multiple variations on the same systematic (e.g.

Private Member Functions

std::string joinNames () const
 description: join systematic names into single string
std::size_t computeHash () const
 description: compute and store the hash value

Private Attributes

std::set< SystematicVariationm_sysVariations
 description: the set of systematics encapsulated in this class
CxxUtils::CachedValue< std::string > m_joinedName
 description: cache the joined string, useful for hash
CxxUtils::CachedValue< std::size_t > m_hash
 description: cached hash value for quick retrieval in unordered containers

Detailed Description

Class to wrap a set of SystematicVariations.

Definition at line 30 of file SystematicSet.h.

Member Typedef Documentation

◆ const_iterator

◆ iterator

Definition at line 51 of file SystematicSet.h.

Member Enumeration Documentation

◆ MATCHTYPE

description: match systematic or continuous version

Enumerator
FULL 
FULLORCONTINUOUS 

Definition at line 90 of file SystematicSet.h.

Constructor & Destructor Documentation

◆ SystematicSet() [1/5]

CP::SystematicSet::SystematicSet ( )

construct an empty set

Definition at line 36 of file SystematicSet.cxx.

37 {
38 }

◆ SystematicSet() [2/5]

CP::SystematicSet::SystematicSet ( const std::string & systematics)

construct set by splitting single systematics string

Definition at line 41 of file SystematicSet.cxx.

43 {
44 if (!systematics.empty()) {
45 std::string::size_type split = 0, split2 = 0;
46 while ((split = systematics.find ("-", split2)) != std::string::npos) {
47 m_sysVariations.insert (systematics.substr (split2, split - split2));
48 split2 = split + 1;
49 }
50 m_sysVariations.insert (systematics.substr (split2, split - split2));
51 }
52 }
static const std::vector< std::string > systematics
std::set< SystematicVariation > m_sysVariations
description: the set of systematics encapsulated in this class
SystematicSet()
construct an empty set
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ SystematicSet() [3/5]

CP::SystematicSet::SystematicSet ( const std::vector< std::string > & systematics)

construct by vector of systematic names

Definition at line 56 of file SystematicSet.cxx.

58 {
59 for (const auto & sys : systematics) {
60 m_sysVariations.insert(sys);
61 }
62 }

◆ SystematicSet() [4/5]

CP::SystematicSet::SystematicSet ( const std::vector< SystematicVariation > & systematics)

construct by vector of SystematicVariation

Definition at line 65 of file SystematicSet.cxx.

68 {
69 for (const auto & sys : systematics) {
70 m_sysVariations.insert(sys);
71 }
72 }

◆ SystematicSet() [5/5]

CP::SystematicSet::SystematicSet ( const std::initializer_list< SystematicVariation > & systematics)

construct with an std::initializer_list

Definition at line 76 of file SystematicSet.cxx.

79 {
80 for (const auto & sys : systematics) {
81 m_sysVariations.insert(sys);
82 }
83 }

Member Function Documentation

◆ begin()

const_iterator CP::SystematicSet::begin ( ) const
inline

description: const iterator to the beginning of the set

Definition at line 55 of file SystematicSet.h.

56 { return m_sysVariations.begin(); }

◆ clear()

void CP::SystematicSet::clear ( )

description: clear the set

Definition at line 118 of file SystematicSet.cxx.

119 {
120 m_sysVariations.clear();
121 m_joinedName.reset();
122 m_hash.reset();
123 }
CxxUtils::CachedValue< std::string > m_joinedName
description: cache the joined string, useful for hash
CxxUtils::CachedValue< std::size_t > m_hash
description: cached hash value for quick retrieval in unordered containers

◆ computeHash()

std::size_t CP::SystematicSet::computeHash ( ) const
private

description: compute and store the hash value

Definition at line 312 of file SystematicSet.cxx.

313 {
314 static const std::hash<std::string> hashFunction;
315 return hashFunction(name());
316 }
std::string name() const
returns: the systematics joined into a single string.

◆ empty()

bool CP::SystematicSet::empty ( ) const
inline

returns: whether the set is empty

Definition at line 67 of file SystematicSet.h.

68 { return m_sysVariations.empty(); }

◆ end()

const_iterator CP::SystematicSet::end ( ) const
inline

description: const iterator to the end of the set

Definition at line 59 of file SystematicSet.h.

60 { return m_sysVariations.end(); }

◆ filterByBaseName()

SystematicSet CP::SystematicSet::filterByBaseName ( const std::string & basename) const

description: get the subset of systematics matching basename Should this return a StatusCode instead?

Definition at line 145 of file SystematicSet.cxx.

147 {
148 SystematicSet filteredSysts;
149 for (const auto & sys : m_sysVariations) {
150 if (sys.basename() == basename)
151 filteredSysts.insert(sys);
152 }
153 return filteredSysts;
154 }
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
std::string basename(std::string name)
Definition utils.cxx:207

◆ filterForAffectingSystematics()

StatusCode CP::SystematicSet::filterForAffectingSystematics ( const SystematicSet & systConfig,
const SystematicSet & affectingSystematics,
SystematicSet & filteredSystematics )
static

description: filter the systematics for the affected systematics returns: success guarantee: strong failures: out of memory II failures: requesting multiple variations on the same systematic (e.g.

up & down) failures: requesting an unsupported variation on an otherwise supported systematic (e.g. a 2 sigma variation and the tool only supports 1 sigma variations)

Definition at line 211 of file SystematicSet.cxx.

214 {
215 using namespace msgSystematics;
216
217 // the final filtered systematics to report
219
220 // the map of all requested systematics by base name
221 std::map<std::string,SystematicVariation> requestedMap;
222
223 // the list of all inconsistent systematics we encountered
224 std::set<SystematicVariation> inconsistentList;
225
226 // fill requestedMap, reporting errors in case of duplication
227 for (auto& sys : systConfig)
228 {
229 std::string basename = sys.basename();
230 auto iter = requestedMap.find (basename);
231 if (iter != requestedMap.end())
232 {
233 ANA_MSG_ERROR ("inconsistent systematic variations requested: " << sys << " and " << iter->second);
234 return StatusCode::FAILURE;
235 }
236 requestedMap.insert (std::make_pair (basename, sys));
237 }
238
239 // check which of the systematics match the affecting
240 for (auto& sys : affectingSysts)
241 {
242 std::string basename = sys.basename();
243 auto iter = requestedMap.find (basename);
244 if (iter != requestedMap.end())
245 {
246 if (iter->second == sys ||
247 sys.ensembleContains (iter->second))
248 {
249 result.insert (iter->second);
250 } else
251 {
252 // let's remember this as a potential problem
253 inconsistentList.insert (iter->second);
254 }
255 }
256 }
257
258 // check whether any of of the requested variations matched the
259 // base names of our systematics, but not the systematics
260 // supported
261 for (auto& sys : inconsistentList)
262 {
263 if (result.find (sys) == result.end())
264 {
265 ANA_MSG_ERROR ("unsupported systematic variation " << sys << " requested for systematic " << sys.basename());
266 return StatusCode::FAILURE;
267 }
268 }
269
270 // everything worked out, let's commit now
271 result.swap (filteredSysts);
272 return StatusCode::SUCCESS;
273 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.

◆ find()

iterator CP::SystematicSet::find ( const SystematicVariation & sys) const
inline

description: find an element in the set

Definition at line 63 of file SystematicSet.h.

64 { return m_sysVariations.find(sys); }

◆ getBaseNames()

std::set< std::string > CP::SystematicSet::getBaseNames ( ) const

description: get the set of base systematic names from this set

Definition at line 158 of file SystematicSet.cxx.

159 {
160 std::set<std::string> baseNames;
161 for (const auto & sys : m_sysVariations) {
162 baseNames.insert(sys.basename());
163 }
164 return baseNames;
165 }

◆ getParameterByBaseName()

float CP::SystematicSet::getParameterByBaseName ( const std::string & basename) const

returns: the parameter value for the given basename

Definition at line 191 of file SystematicSet.cxx.

193 {
195 }
SystematicVariation getSystematicByBaseName(const std::string &basename) const
description: get the first systematic matching basename
float parameter() const
description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be...

◆ getSystematicByBaseName()

SystematicVariation CP::SystematicSet::getSystematicByBaseName ( const std::string & basename) const

description: get the first systematic matching basename

Definition at line 170 of file SystematicSet.cxx.

171 {
172 const SystematicVariation* sysMatched = NULL;
173 for (const auto & sys : m_sysVariations) {
174 if(sys.basename() == basename) {
175 if(!sysMatched) sysMatched = &sys;
176 else {
177 std::string error = "SystematicSet::getSystematicByBaseName ERROR: ";
178 error += "Multiple matches for requested basename ";
179 error += basename;
180 // Redundant?
181 //std::cerr << error << std::endl;
182 throw std::runtime_error(error);
183 }
184 }
185 }
186 if(sysMatched) return *sysMatched;
187 return SystematicVariation();
188 }

◆ getToyVariationByBaseName()

std::pair< unsigned, float > CP::SystematicSet::getToyVariationByBaseName ( const std::string & basename) const

the toy variation for the given basename

in case there is no toy variation for the given base name, this returns (0,0)

See also
SystematicVariation::getToyVariation
Guarantee
strong
Failures
not a toy variation
parse errors
out of memory II

Definition at line 199 of file SystematicSet.cxx.

201 {
202 const auto var = getSystematicByBaseName (basename);
203 if (var.empty())
204 return std::make_pair (0, 0);
205 return var.getToyVariation();
206 }

◆ hash()

std::size_t CP::SystematicSet::hash ( ) const

returns: hash value for the joined string.

Caches the hash if not already done

Definition at line 288 of file SystematicSet.cxx.

289 {
290 if(!m_hash.isValid()) {
291 m_hash.set (computeHash());
292 }
293 return *m_hash.ptr();
294 }
std::size_t computeHash() const
description: compute and store the hash value

◆ insert() [1/2]

void CP::SystematicSet::insert ( const SystematicSet & systematics)

description: insert a systematic set into this set

Definition at line 98 of file SystematicSet.cxx.

99 {
100 for (const auto & sys : systematics) {
101 insert(sys);
102 }
103 }
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set

◆ insert() [2/2]

void CP::SystematicSet::insert ( const SystematicVariation & systematic)

description: insert a systematic into the set

Definition at line 87 of file SystematicSet.cxx.

88 {
89 // If insert doesn't change the set, don't change cache flag
90 if(m_sysVariations.insert(systematic).second) {
91 m_joinedName.reset();
92 m_hash.reset();
93 }
94 }

◆ joinNames()

std::string CP::SystematicSet::joinNames ( ) const
private

description: join systematic names into single string

Definition at line 298 of file SystematicSet.cxx.

299 {
300 std::string joinedName;
301 for (const auto & sys : m_sysVariations) {
302 if (!joinedName.empty()) {
303 joinedName += "-";
304 }
305 joinedName += sys.name();
306 }
307 return joinedName;
308 }

◆ matchSystematic()

bool CP::SystematicSet::matchSystematic ( const SystematicVariation & systematic,
MATCHTYPE type = FULL ) const

Definition at line 127 of file SystematicSet.cxx.

129 {
130 if (m_sysVariations.find(systematic) != m_sysVariations.end()) {
131 return true;
132 }
133 if (type == FULLORCONTINUOUS) {
134 const SystematicVariation continuous(systematic.basename(),
136 if (m_sysVariations.find(continuous) != m_sysVariations.end()) {
137 return true;
138 }
139 }
140 return false;
141 }
std::string basename() const
description: the base name, i.e.

◆ name()

std::string CP::SystematicSet::name ( ) const

returns: the systematics joined into a single string.

Caches the name if not already done

Definition at line 277 of file SystematicSet.cxx.

278 {
279 if(!m_joinedName.isValid())
280 {
281 m_joinedName.set (joinNames());
282 }
283 return *m_joinedName.ptr();
284 }
std::string joinNames() const
description: join systematic names into single string

◆ size()

size_t CP::SystematicSet::size ( ) const
inline

returns: size of the set

Definition at line 71 of file SystematicSet.h.

72 { return m_sysVariations.size(); }

◆ swap()

void CP::SystematicSet::swap ( SystematicSet & otherSet)

description: swap elements of a set

Definition at line 107 of file SystematicSet.cxx.

108 {
109 m_sysVariations.swap(otherSet.m_sysVariations);
110 m_joinedName.reset();
111 otherSet.m_joinedName.reset();
112 m_hash.reset();
113 otherSet.m_hash.reset();
114 }
void reset()
Reset the value to invalid.
std::set< SystematicVariation > m_sysVariations
description: the set of systematics encapsulated in this class
CxxUtils::CachedValue< std::string > m_joinedName
description: cache the joined string, useful for hash
CxxUtils::CachedValue< std::size_t > m_hash
description: cached hash value for quick retrieval in unordered containers

Member Data Documentation

◆ m_hash

CxxUtils::CachedValue<std::size_t> CP::SystematicSet::m_hash
private

description: cached hash value for quick retrieval in unordered containers

Definition at line 169 of file SystematicSet.h.

◆ m_joinedName

CxxUtils::CachedValue<std::string> CP::SystematicSet::m_joinedName
private

description: cache the joined string, useful for hash

Definition at line 165 of file SystematicSet.h.

◆ m_sysVariations

std::set<SystematicVariation> CP::SystematicSet::m_sysVariations
private

description: the set of systematics encapsulated in this class

Definition at line 162 of file SystematicSet.h.


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