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 37 of file SystematicSet.cxx.

38  {
39  }

◆ SystematicSet() [2/5]

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

construct set by splitting single systematics string

Definition at line 42 of file SystematicSet.cxx.

43  : SystematicSet()
44  {
45  if (!systematics.empty()) {
46  std::string::size_type split = 0, split2 = 0;
47  while ((split = systematics.find ("-", split2)) != std::string::npos) {
48  m_sysVariations.insert (systematics.substr (split2, split - split2));
49  split2 = split + 1;
50  }
51  m_sysVariations.insert (systematics.substr (split2, split - split2));
52  }
53  }

◆ SystematicSet() [3/5]

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

construct by vector of systematic names

Definition at line 57 of file SystematicSet.cxx.

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

◆ SystematicSet() [4/5]

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

construct by vector of SystematicVariation

Definition at line 66 of file SystematicSet.cxx.

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

◆ SystematicSet() [5/5]

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

construct with an std::initializer_list

Definition at line 77 of file SystematicSet.cxx.

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

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 119 of file SystematicSet.cxx.

120  {
121  m_sysVariations.clear();
123  m_hash.reset();
124  }

◆ computeHash()

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

description: compute and store the hash value

Definition at line 313 of file SystematicSet.cxx.

314  {
315  static const std::hash<std::string> hashFunction;
316  //static boost::hash<std::string> hashFunction;
317  return hashFunction(name());
318  }

◆ 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 146 of file SystematicSet.cxx.

148  {
149  SystematicSet filteredSysts;
150  for (const auto & sys : m_sysVariations) {
151  if (sys.basename() == basename)
152  filteredSysts.insert(sys);
153  }
154  return filteredSysts;
155  }

◆ 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 212 of file SystematicSet.cxx.

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

◆ 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 159 of file SystematicSet.cxx.

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

◆ getParameterByBaseName()

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

returns: the parameter value for the given basename

Definition at line 192 of file SystematicSet.cxx.

194  {
196  }

◆ getSystematicByBaseName()

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

description: get the first systematic matching basename

Definition at line 171 of file SystematicSet.cxx.

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

◆ 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 200 of file SystematicSet.cxx.

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

◆ 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 289 of file SystematicSet.cxx.

290  {
291  if(!m_hash.isValid()) {
292  m_hash.set (computeHash());
293  }
294  return *m_hash.ptr();
295  }

◆ insert() [1/2]

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

description: insert a systematic set into this set

Definition at line 99 of file SystematicSet.cxx.

100  {
101  for (const auto & sys : systematics) {
102  insert(sys);
103  }
104  }

◆ insert() [2/2]

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

description: insert a systematic into the set

Definition at line 88 of file SystematicSet.cxx.

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

◆ joinNames()

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

description: join systematic names into single string

Definition at line 299 of file SystematicSet.cxx.

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

◆ matchSystematic()

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

Definition at line 128 of file SystematicSet.cxx.

130  {
131  if (m_sysVariations.find(systematic) != m_sysVariations.end()) {
132  return true;
133  }
134  if (type == FULLORCONTINUOUS) {
135  const SystematicVariation continuous(systematic.basename(),
137  if (m_sysVariations.find(continuous) != m_sysVariations.end()) {
138  return true;
139  }
140  }
141  return false;
142  }

◆ 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 278 of file SystematicSet.cxx.

279  {
280  if(!m_joinedName.isValid())
281  {
283  }
284  return *m_joinedName.ptr();
285  }

◆ 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 108 of file SystematicSet.cxx.

109  {
110  m_sysVariations.swap(otherSet.m_sysVariations);
112  otherSet.m_joinedName.reset();
113  m_hash.reset();
114  otherSet.m_hash.reset();
115  }

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:1394
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:299
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:313
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
CP::SystematicSet::name
std::string name() const
returns: the systematics joined into a single string.
Definition: SystematicSet.cxx:278
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
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:171
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
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
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:37
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:640