ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 
 SystematicSet (const std::string &systematics)
 construct set by splitting single systematics string More...
 
 SystematicSet (const std::vector< std::string > &systematics)
 construct by vector of systematic names More...
 
 SystematicSet (const std::vector< SystematicVariation > &systematics)
 construct by vector of SystematicVariation More...
 
 SystematicSet (const std::initializer_list< SystematicVariation > &systematics)
 construct with an std::initializer_list More...
 
const_iterator begin () const
 description: const iterator to the beginning of the set More...
 
const_iterator end () const
 description: const iterator to the end of the set More...
 
iterator find (const SystematicVariation &sys) const
 description: find an element in the set More...
 
bool empty () const
 returns: whether the set is empty More...
 
size_t size () const
 returns: size of the set More...
 
void insert (const SystematicVariation &systematic)
 description: insert a systematic into the set More...
 
void insert (const SystematicSet &systematics)
 description: insert a systematic set into this set More...
 
void swap (SystematicSet &otherSet)
 description: swap elements of a set More...
 
void clear ()
 description: clear the set More...
 
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? More...
 
std::set< std::string > getBaseNames () const
 description: get the set of base systematic names from this set More...
 
SystematicVariation getSystematicByBaseName (const std::string &basename) const
 description: get the first systematic matching basename More...
 
float getParameterByBaseName (const std::string &basename) const
 returns: the parameter value for the given basename More...
 
std::pair< unsigned, float > getToyVariationByBaseName (const std::string &basename) const
 the toy variation for the given basename More...
 
std::string name () const
 returns: the systematics joined into a single string. More...
 
std::size_t hash () const
 returns: hash value for the joined string. More...
 

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. More...
 

Private Member Functions

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

Private Attributes

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

Detailed Description

Class to wrap a set of SystematicVariations.

Definition at line 30 of file SystematicSet.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 52 of file SystematicSet.h.

◆ 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.

42  : SystematicSet()
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  }

◆ 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.

57  : SystematicSet()
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.

67  : SystematicSet()
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.

78  : SystematicSet()
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();
122  m_hash.reset();
123  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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) {
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  }

◆ 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  {
282  }
283  return *m_joinedName.ptr();
284  }

◆ 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);
111  otherSet.m_joinedName.reset();
112  m_hash.reset();
113  otherSet.m_hash.reset();
114  }

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:
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
CxxUtils::CachedValue::reset
void reset()
Reset the value to invalid.
CP::SystematicVariation::CONTINUOUS
@ CONTINUOUS
Definition: SystematicVariation.h:79
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::SystematicSet::joinNames
std::string joinNames() const
description: join systematic names into single string
Definition: SystematicSet.cxx:298
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
CP::SystematicSet::computeHash
std::size_t computeHash() const
description: compute and store the hash value
Definition: SystematicSet.cxx:312
CP::SystematicSet::m_hash
CxxUtils::CachedValue< std::size_t > m_hash
description: cached hash value for quick retrieval in unordered containers
Definition: SystematicSet.h:169
CheckAppliedSFs.systematics
systematics
Definition: CheckAppliedSFs.py:231
CP::SystematicSet::name
std::string name() const
returns: the systematics joined into a single string.
Definition: SystematicSet.cxx:277
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::SystematicSet::FULL
@ FULL
Definition: SystematicSet.h:90
CP::SystematicSet::m_sysVariations
std::set< SystematicVariation > m_sysVariations
description: the set of systematics encapsulated in this class
Definition: SystematicSet.h:162
CP::SystematicSet::getSystematicByBaseName
SystematicVariation getSystematicByBaseName(const std::string &basename) const
description: get the first systematic matching basename
Definition: SystematicSet.cxx:170
CP::SystematicSet::FULLORCONTINUOUS
@ FULLORCONTINUOUS
Definition: SystematicSet.h:90
CP::SystematicSet::m_joinedName
CxxUtils::CachedValue< std::string > m_joinedName
description: cache the joined string, useful for hash
Definition: SystematicSet.h:165
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:87
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
CP::SystematicSet::SystematicSet
SystematicSet()
construct an empty set
Definition: SystematicSet.cxx:36
error
Definition: IImpactPoint3dEstimator.h:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
CP::SystematicVariation::parameter
float parameter() const
description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be...
Definition: SystematicVariation.cxx:340
beamspotman.basename
basename
Definition: beamspotman.py:636