ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
CP::SystematicVariation Class Reference

#include <SystematicVariation.h>

Collaboration diagram for CP::SystematicVariation:

Public Types

enum  CONTINUOUS_ARG { CONTINUOUS }
 effects: constructor for indicating continuous systematics guarantee: strong failures: out of memory II More...
 

Public Member Functions

void testInvariant () const
 effects: test the invariant of this object guarantee: no-fail More...
 
 SystematicVariation ()
 effects: standard default constructor guarantee: no-fail More...
 
 SystematicVariation (const std::string &val_name)
 effects: constructor from the given members guarantee: strong failures: out of memory II More...
 
 SystematicVariation (const std::string &val_basename, const std::string &val_subvariation)
 
 SystematicVariation (const std::string &val_basename, float val_parameter)
 
 SystematicVariation (const std::string &val_basename, CONTINUOUS_ARG)
 
 SystematicVariation (const std::set< CP::SystematicVariation > &systematics, const std::string &val_basename)
 effects: this constructor picks the systematic from the set of systematics based on the basename. More...
 
bool empty () const
 returns: whether this is an empty systematic, i.e. More...
 
const std::string & name () const
 description: the full systematics name, for use in strings, etc. More...
 
std::string basename () const
 description: the base name, i.e. More...
 
std::string subvariation () const
 description: the part of the name that indicates by how many sigmas we varied guarantee: strong failures: out of memory II warning: an empty subvariation is not the same as requesting the nuisance parameter to be 0. More...
 
float parameter () const
 description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be parsed into a number guarantee: no-fail More...
 
std::pair< unsigned, float > getToyVariation () const
 unpack the toy variation More...
 
bool isToyEnsemble () const
 whether this represents a toy ensemble More...
 
bool isContinuousEnsemble () const
 whether this represents a continuous ensemble More...
 
bool isEnsemble () const
 whether this represents any form of ensemble More...
 
bool ensembleContains (const SystematicVariation &sys) const
 whether this is an ensemble that contains the given systematic variation More...
 
bool isToyVariation () const
 whether this represents a toy variation More...
 
bool isContinuousVariation () const
 whether this represents a continuous variation More...
 

Static Public Member Functions

static SystematicVariation makeToyVariation (const std::string &basename, unsigned toyIndex, float toyScale)
 constructor for toy systematics More...
 
static SystematicVariation makeToyEnsemble (const std::string &basename)
 constructor for toy systematics ensemble More...
 
static SystematicVariation makeContinuousEnsemble (const std::string &basename)
 constructor for continuous systematics ensemble More...
 
static SystematicVariation makeContinuous (const std::string &basename)
 Named constructor for continuous systematics. More...
 

Private Attributes

std::string m_name
 description: members directly corresponding to accessors More...
 

Detailed Description

Definition at line 46 of file SystematicVariation.h.

Member Enumeration Documentation

◆ CONTINUOUS_ARG

effects: constructor for indicating continuous systematics guarantee: strong failures: out of memory II

Enumerator
CONTINUOUS 

Definition at line 79 of file SystematicVariation.h.

79 {CONTINUOUS};

Constructor & Destructor Documentation

◆ SystematicVariation() [1/6]

CP::SystematicVariation::SystematicVariation ( )

effects: standard default constructor guarantee: no-fail

Definition at line 166 of file SystematicVariation.cxx.

168  {
169  RCU_NEW_INVARIANT (this);
170  }

◆ SystematicVariation() [2/6]

CP::SystematicVariation::SystematicVariation ( const std::string &  val_name)

effects: constructor from the given members guarantee: strong failures: out of memory II

Definition at line 174 of file SystematicVariation.cxx.

176  : m_name (val_name)
177  {
178  RCU_NEW_INVARIANT (this);
179  }

◆ SystematicVariation() [3/6]

CP::SystematicVariation::SystematicVariation ( const std::string &  val_basename,
const std::string &  val_subvariation 
)

Definition at line 183 of file SystematicVariation.cxx.

186  : m_name (val_basename + "__" + val_subvariation)
187  {
188  RCU_NEW_INVARIANT (this);
189  }

◆ SystematicVariation() [4/6]

CP::SystematicVariation::SystematicVariation ( const std::string &  val_basename,
float  val_parameter 
)

rationale: in case the parameter is ~0 we initialize this to an empty systematic, since we are essentially not requesting anything

Definition at line 193 of file SystematicVariation.cxx.

196  {
197  std::string separator = "up";
198  if (val_parameter < 0)
199  {
200  separator = "down";
201  val_parameter *= -1;
202  }
203  std::ostringstream str;
204  str << rint (val_parameter * 10000);
205  std::string number = str.str();
206 
207  while (number.size() < 5)
208  number = "0" + number;
209 
213  if (number != "00000")
214  {
215  m_name = val_basename + "__" + number.substr (0, number.size()-4)
216  + separator + number.substr (number.size()-4);
217  while (m_name[m_name.size()-1] == '0')
218  m_name.resize (m_name.size()-1);
219  }
220 
221  RCU_NEW_INVARIANT (this);
222  }

◆ SystematicVariation() [5/6]

CP::SystematicVariation::SystematicVariation ( const std::string &  val_basename,
CONTINUOUS_ARG   
)

Definition at line 227 of file SystematicVariation.cxx.

229  : m_name (val_basename + "__continuous")
230  {
231  RCU_NEW_INVARIANT (this);
232  }

◆ SystematicVariation() [6/6]

CP::SystematicVariation::SystematicVariation ( const std::set< CP::SystematicVariation > &  systematics,
const std::string &  val_basename 
)

effects: this constructor picks the systematic from the set of systematics based on the basename.

if multiple systematics with the same basename are in the set, it picks one of them. if no systematic has this basename it is initialized to the empty systematic. guarantee: strong failures: out of memory II rationale: this is meant to be used inside CP tools, so they can more easily pick up systematics they care about (in certain situations).

Definition at line 273 of file SystematicVariation.cxx.

276  {
277  RCU_NEW_INVARIANT (this);
278 
279  for (std::set<SystematicVariation>::const_iterator
280  sys = systematics.begin(),
281  end = systematics.end(); sys != end; ++ sys)
282  {
283  if (sys->basename() == val_basename)
284  {
285  *this = *sys;
286  return;
287  }
288  }
289  }

Member Function Documentation

◆ basename()

std::string CP::SystematicVariation::basename ( ) const

description: the base name, i.e.

without the part that specifies by how many sigmas we varied guarantee: strong failures: out of memory II

Definition at line 311 of file SystematicVariation.cxx.

313  {
314  RCU_READ_INVARIANT (this);
315 
316  std::string::size_type split = m_name.rfind ("__");
317  if (split != std::string::npos)
318  return m_name.substr (0, split);
319  else
320  return m_name;
321  }

◆ empty()

bool CP::SystematicVariation::empty ( ) const

returns: whether this is an empty systematic, i.e.

whether we can safely ignore it guarantee: no-fail rationale: there are a number of cases in which a systematic may become initialized to nothing, e.g. when choosing a 0 parameter. this is an easy way to check for it.

Definition at line 293 of file SystematicVariation.cxx.

295  {
296  RCU_READ_INVARIANT (this);
297  return m_name.empty();
298  }

◆ ensembleContains()

bool CP::SystematicVariation::ensembleContains ( const SystematicVariation sys) const

whether this is an ensemble that contains the given systematic variation

Guarantee
strong
Failures
out of memory II

Definition at line 422 of file SystematicVariation.cxx.

424  {
425  if (basename() != sys.basename())
426  return false;
427  if (isContinuousEnsemble() && sys.isContinuousVariation())
428  return true;
429  if (isToyEnsemble() && sys.isToyVariation())
430  return true;
431  return false;
432  }

◆ getToyVariation()

std::pair< unsigned, float > CP::SystematicVariation::getToyVariation ( ) const

unpack the toy variation

Returns
the index of the toy, and the scale
Guarantee
strong
Failures
out of memory II
parse errors
not a toy variation

Definition at line 373 of file SystematicVariation.cxx.

375  {
376  // no invariant used
377 
378  std::string variation = subvariation();
379 
380  const std::size_t prefixSize = 4;
381  const auto split1 = variation.find ("toy_");
382  if (split1 != 0)
383  RCU_THROW_MSG ("not a toy variation: " + name());
384  const auto split2 = variation.find ("_", split1 + prefixSize);
385  if (split2 == std::string::npos)
386  RCU_THROW_MSG ("not a toy variation: " + name());
387 
388  const auto sub1 = variation.substr (prefixSize, split2 - prefixSize);
389  const auto sub2 = variation.substr (split2 + 1);
390  return std::make_pair (unpackUnsigned (sub1), unpackFloat (sub2, "scale", ""));
391  }

◆ isContinuousEnsemble()

bool CP::SystematicVariation::isContinuousEnsemble ( ) const

whether this represents a continuous ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 404 of file SystematicVariation.cxx.

406  {
407  // no invariant used
408  return subvariation() == "continuous";
409  }

◆ isContinuousVariation()

bool CP::SystematicVariation::isContinuousVariation ( ) const

whether this represents a continuous variation

Guarantee
strong
Failures
out of memory II

Definition at line 445 of file SystematicVariation.cxx.

447  {
448  static const std::regex pattern (".*__[0-9]+((up)|(down))([0-9]{1,4})?");
449  return regex_match (m_name, pattern);
450  }

◆ isEnsemble()

bool CP::SystematicVariation::isEnsemble ( ) const

whether this represents any form of ensemble

this can be used to check whether this is a valid variation to pass into ISystematicsTool::applySystematicVariation

Guarantee
strong
Failures
out of memory II

Definition at line 413 of file SystematicVariation.cxx.

415  {
416  // no invariant used
417  return isToyEnsemble() || isContinuousEnsemble();
418  }

◆ isToyEnsemble()

bool CP::SystematicVariation::isToyEnsemble ( ) const

whether this represents a toy ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 395 of file SystematicVariation.cxx.

397  {
398  // no invariant used
399  return subvariation() == "toy_ensemble";
400  }

◆ isToyVariation()

bool CP::SystematicVariation::isToyVariation ( ) const

whether this represents a toy variation

Guarantee
strong
Failures
out of memory II

Definition at line 436 of file SystematicVariation.cxx.

438  {
439  static const std::regex pattern (".*__toy_[0-9]+_[0-9]+((scale)[0-9]{1,4})?");
440  return regex_match (m_name, pattern);
441  }

◆ makeContinuous()

SystematicVariation CP::SystematicVariation::makeContinuous ( const std::string &  basename)
static

Named constructor for continuous systematics.

rationale: Introduced because the enum-based constructor was getting confused with the float one above in PyROOT.

Definition at line 265 of file SystematicVariation.cxx.

267  {
268  return SystematicVariation (basename + "__continuous");
269  }

◆ makeContinuousEnsemble()

SystematicVariation CP::SystematicVariation::makeContinuousEnsemble ( const std::string &  basename)
static

constructor for continuous systematics ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 249 of file SystematicVariation.cxx.

251  {
253  }

◆ makeToyEnsemble()

SystematicVariation CP::SystematicVariation::makeToyEnsemble ( const std::string &  basename)
static

constructor for toy systematics ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 257 of file SystematicVariation.cxx.

259  {
260  return SystematicVariation (basename, "toy_ensemble");
261  }

◆ makeToyVariation()

SystematicVariation CP::SystematicVariation::makeToyVariation ( const std::string &  basename,
unsigned  toyIndex,
float  toyScale 
)
static

constructor for toy systematics

Guarantee
strong
Failures
out of memory II

Definition at line 237 of file SystematicVariation.cxx.

240  {
241  RCU_REQUIRE (toyIndex > 0);
242  RCU_REQUIRE (toyScale > 0);
243  return SystematicVariation
244  (basename, "toy_" + packUnsigned (toyIndex) + "_" + packFloat (toyScale, "scale", ""));
245  }

◆ name()

const std::string & CP::SystematicVariation::name ( ) const

description: the full systematics name, for use in strings, etc.

guarantee: no-fail

Definition at line 302 of file SystematicVariation.cxx.

304  {
305  RCU_READ_INVARIANT (this);
306  return m_name;
307  }

◆ parameter()

float CP::SystematicVariation::parameter ( ) const

description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be parsed into a number guarantee: no-fail

Definition at line 339 of file SystematicVariation.cxx.

341  {
342  RCU_READ_INVARIANT (this);
343 
344  std::string subvariation = this->subvariation();
345 
346  std::string::size_type split = subvariation.rfind ("up");
347  if (split != std::string::npos)
348  {
349  std::istringstream str (subvariation.substr (0, split) + "." + subvariation.substr (split + 2));
350  float result;
351  if (str >> result)
352  return result;
353  else
354  return 0;
355  }
356 
357  split = subvariation.rfind ("down");
358  if (split != std::string::npos)
359  {
360  std::istringstream str (subvariation.substr (0, split) + "." + subvariation.substr (split + 4));
361  float result;
362  if (str >> result)
363  return -result;
364  else
365  return 0;
366  }
367 
368  return 0;
369  }

◆ subvariation()

std::string CP::SystematicVariation::subvariation ( ) const

description: the part of the name that indicates by how many sigmas we varied guarantee: strong failures: out of memory II warning: an empty subvariation is not the same as requesting the nuisance parameter to be 0.

it is a systematic that doesn't have multiple subvariations

Definition at line 325 of file SystematicVariation.cxx.

327  {
328  RCU_READ_INVARIANT (this);
329 
330  std::string::size_type split = m_name.rfind ("__");
331  if (split != std::string::npos)
332  return m_name.substr (split + 2);
333  else
334  return "";
335  }

◆ testInvariant()

void CP::SystematicVariation::testInvariant ( ) const

effects: test the invariant of this object guarantee: no-fail

Definition at line 158 of file SystematicVariation.cxx.

160  {
161  //RCU_INVARIANT (this != 0);
162  }

Member Data Documentation

◆ m_name

std::string CP::SystematicVariation::m_name
private

description: members directly corresponding to accessors

Definition at line 264 of file SystematicVariation.h.


The documentation for this class was generated from the following files:
CP::SystematicVariation::SystematicVariation
SystematicVariation()
effects: standard default constructor guarantee: no-fail
Definition: SystematicVariation.cxx:167
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
CP::SystematicVariation::CONTINUOUS
@ CONTINUOUS
Definition: SystematicVariation.h:79
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::SystematicVariation::basename
std::string basename() const
description: the base name, i.e.
Definition: SystematicVariation.cxx:312
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
CP::SystematicVariation::name
const std::string & name() const
description: the full systematics name, for use in strings, etc.
Definition: SystematicVariation.cxx:303
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
python.selection.number
number
Definition: selection.py:20
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
str
Definition: BTagTrackIpAccessor.cxx:11
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
CP::SystematicVariation::subvariation
std::string subvariation() const
description: the part of the name that indicates by how many sigmas we varied guarantee: strong failu...
Definition: SystematicVariation.cxx:326
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
CP::SystematicVariation::isToyEnsemble
bool isToyEnsemble() const
whether this represents a toy ensemble
Definition: SystematicVariation.cxx:396
CP::SystematicVariation::isContinuousEnsemble
bool isContinuousEnsemble() const
whether this represents a continuous ensemble
Definition: SystematicVariation.cxx:405
CP::SystematicVariation::m_name
std::string m_name
description: members directly corresponding to accessors
Definition: SystematicVariation.h:264
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233