ATLAS Offline Software
Loading...
Searching...
No Matches
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
 SystematicVariation ()
 effects: standard default constructor guarantee: no-fail
 SystematicVariation (const std::string &val_name)
 effects: constructor from the given members guarantee: strong failures: out of memory II
 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.
bool empty () const
 returns: whether this is an empty systematic, i.e.
const std::string & name () const
 description: the full systematics name, for use in strings, etc.
std::string basename () const
 description: the base name, i.e.
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.
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
std::pair< unsigned, floatgetToyVariation () const
 unpack the toy variation
bool isToyEnsemble () const
 whether this represents a toy ensemble
bool isContinuousEnsemble () const
 whether this represents a continuous ensemble
bool isEnsemble () const
 whether this represents any form of ensemble
bool ensembleContains (const SystematicVariation &sys) const
 whether this is an ensemble that contains the given systematic variation
bool isToyVariation () const
 whether this represents a toy variation
bool isContinuousVariation () const
 whether this represents a continuous variation

Static Public Member Functions

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

Private Attributes

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

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.

Constructor & Destructor Documentation

◆ SystematicVariation() [1/6]

CP::SystematicVariation::SystematicVariation ( )

effects: standard default constructor guarantee: no-fail

Definition at line 163 of file SystematicVariation.cxx.

165 {
166 RCU_NEW_INVARIANT (this);
167 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221

◆ 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 171 of file SystematicVariation.cxx.

173 : m_name (val_name)
174 {
175 RCU_NEW_INVARIANT (this);
176 }
std::string m_name
description: members directly corresponding to accessors

◆ SystematicVariation() [3/6]

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

Definition at line 180 of file SystematicVariation.cxx.

183 : m_name (val_basename + "__" + val_subvariation)
184 {
185 RCU_NEW_INVARIANT (this);
186 }

◆ 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 190 of file SystematicVariation.cxx.

193 {
194 std::string separator = "up";
195 if (val_parameter < 0)
196 {
197 separator = "down";
198 val_parameter *= -1;
199 }
200 std::ostringstream str;
201 str << rint (val_parameter * 10000);
202 std::string number = str.str();
203
204 while (number.size() < 5)
205 number = "0" + number;
206
210 if (number != "00000")
211 {
212 m_name = val_basename + "__" + number.substr (0, number.size()-4)
213 + separator + number.substr (number.size()-4);
214 while (m_name[m_name.size()-1] == '0')
215 m_name.resize (m_name.size()-1);
216 }
217
218 RCU_NEW_INVARIANT (this);
219 }
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186

◆ SystematicVariation() [5/6]

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

Definition at line 224 of file SystematicVariation.cxx.

226 : m_name (val_basename + "__continuous")
227 {
228 RCU_NEW_INVARIANT (this);
229 }

◆ 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 270 of file SystematicVariation.cxx.

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

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 308 of file SystematicVariation.cxx.

310 {
311 RCU_READ_INVARIANT (this);
312
313 std::string::size_type split = m_name.rfind ("__");
314 if (split != std::string::npos)
315 return m_name.substr (0, split);
316 else
317 return m_name;
318 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ 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 290 of file SystematicVariation.cxx.

292 {
293 RCU_READ_INVARIANT (this);
294 return m_name.empty();
295 }

◆ 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 419 of file SystematicVariation.cxx.

421 {
422 if (basename() != sys.basename())
423 return false;
424 if (isContinuousEnsemble() && sys.isContinuousVariation())
425 return true;
426 if (isToyEnsemble() && sys.isToyVariation())
427 return true;
428 return false;
429 }
std::string basename() const
description: the base name, i.e.
bool isToyEnsemble() const
whether this represents a toy ensemble
bool isContinuousEnsemble() const
whether this represents a continuous ensemble

◆ 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 370 of file SystematicVariation.cxx.

372 {
373 // no invariant used
374
375 std::string variation = subvariation();
376
377 const std::size_t prefixSize = 4;
378 const auto split1 = variation.find ("toy_");
379 if (split1 != 0)
380 throw std::runtime_error ("not a toy variation: " + name());
381 const auto split2 = variation.find ("_", split1 + prefixSize);
382 if (split2 == std::string::npos)
383 throw std::runtime_error ("not a toy variation: " + name());
384
385 const auto sub1 = variation.substr (prefixSize, split2 - prefixSize);
386 const auto sub2 = variation.substr (split2 + 1);
387 return std::make_pair (unpackUnsigned (sub1), unpackFloat (sub2, "scale", ""));
388 }
std::string subvariation() const
description: the part of the name that indicates by how many sigmas we varied guarantee: strong failu...
const std::string & name() const
description: the full systematics name, for use in strings, etc.

◆ isContinuousEnsemble()

bool CP::SystematicVariation::isContinuousEnsemble ( ) const

whether this represents a continuous ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 401 of file SystematicVariation.cxx.

403 {
404 // no invariant used
405 return subvariation() == "continuous";
406 }

◆ isContinuousVariation()

bool CP::SystematicVariation::isContinuousVariation ( ) const

whether this represents a continuous variation

Guarantee
strong
Failures
out of memory II

Definition at line 442 of file SystematicVariation.cxx.

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

◆ 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 410 of file SystematicVariation.cxx.

412 {
413 // no invariant used
415 }

◆ isToyEnsemble()

bool CP::SystematicVariation::isToyEnsemble ( ) const

whether this represents a toy ensemble

Guarantee
strong
Failures
out of memory II

Definition at line 392 of file SystematicVariation.cxx.

394 {
395 // no invariant used
396 return subvariation() == "toy_ensemble";
397 }

◆ isToyVariation()

bool CP::SystematicVariation::isToyVariation ( ) const

whether this represents a toy variation

Guarantee
strong
Failures
out of memory II

Definition at line 433 of file SystematicVariation.cxx.

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

◆ 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 262 of file SystematicVariation.cxx.

264 {
265 return SystematicVariation (basename + "__continuous");
266 }
SystematicVariation()
effects: standard default constructor guarantee: no-fail

◆ 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 246 of file SystematicVariation.cxx.

248 {
250 }

◆ 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 254 of file SystematicVariation.cxx.

256 {
257 return SystematicVariation (basename, "toy_ensemble");
258 }

◆ 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 234 of file SystematicVariation.cxx.

237 {
238 RCU_REQUIRE (toyIndex > 0);
239 RCU_REQUIRE (toyScale > 0);
241 (basename, "toy_" + packUnsigned (toyIndex) + "_" + packFloat (toyScale, "scale", ""));
242 }
#define RCU_REQUIRE(x)
Definition Assert.h:196

◆ name()

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

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

guarantee: no-fail

Definition at line 299 of file SystematicVariation.cxx.

301 {
302 RCU_READ_INVARIANT (this);
303 return m_name;
304 }

◆ 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 336 of file SystematicVariation.cxx.

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

◆ 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 322 of file SystematicVariation.cxx.

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

◆ testInvariant()

void CP::SystematicVariation::testInvariant ( ) const

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

Definition at line 157 of file SystematicVariation.cxx.

159 {}

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: