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

168 {
169 RCU_NEW_INVARIANT (this);
170 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233

◆ 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 }
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 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 }
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 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 }
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 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 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ 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 }
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 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 }
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
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 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
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 }
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 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);
244 (basename, "toy_" + packUnsigned (toyIndex) + "_" + packFloat (toyScale, "scale", ""));
245 }
#define RCU_REQUIRE(x)
Definition Assert.h:208

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