22 return a.name() < b.name();
28 return a.name() == b.name();
45 std::string packUnsigned (
unsigned value)
60 unsigned unpackUnsigned (
const std::string& value)
62 std::istringstream
str (value);
65 throw std::runtime_error (
"failed to parse \"" + value +
"\" into an unsigned");
68 throw std::runtime_error (
"failed to parse \"" + value +
"\" into an unsigned");
80 std::string packFloat (
float value,
const std::string& plus,
81 const std::string& minus)
83 std::string separator = plus;
91 std::ostringstream
str;
92 str << rint (value * 10000);
110 bool unpackFloatHelper (
const std::string& value,
111 const std::string& separator,
114 if (!separator.empty())
116 std::string::size_type
split =
value.rfind (separator);
117 if (
split != std::string::npos)
120 if (!(
str >> result))
121 throw std::runtime_error (
"failed to parse into a float: " + value);
124 throw std::runtime_error (
"failed to parse into a float: " + value);
140 float unpackFloat (
const std::string& value,
const std::string& plus,
141 const std::string& minus)
144 if (unpackFloatHelper (value, plus, result))
146 if (unpackFloatHelper (value, minus, result))
151 throw std::runtime_error (
"failed to parse into a float: " + value);
157 void SystematicVariation ::
158 testInvariant ()
const
163 SystematicVariation ::
164 SystematicVariation ()
171 SystematicVariation ::
172 SystematicVariation (
const std::string& val_name)
180 SystematicVariation ::
181 SystematicVariation (
const std::string& val_basename,
182 const std::string& val_subvariation)
183 :
m_name (val_basename +
"__" + val_subvariation)
190 SystematicVariation ::
191 SystematicVariation (
const std::string& val_basename,
194 std::string separator =
"up";
195 if (val_parameter < 0)
200 std::ostringstream
str;
201 str << rint (val_parameter * 10000);
224 SystematicVariation ::
225 SystematicVariation (
const std::string& val_basename,
CONTINUOUS_ARG)
226 :
m_name (val_basename +
"__continuous")
235 makeToyVariation (
const std::string&
basename,
236 unsigned toyIndex,
float toyScale)
241 (
basename,
"toy_" + packUnsigned (toyIndex) +
"_" + packFloat (toyScale,
"scale",
""));
247 makeContinuousEnsemble (
const std::string&
basename)
255 makeToyEnsemble (
const std::string&
basename)
263 makeContinuous (
const std::string&
basename)
270 SystematicVariation ::
271 SystematicVariation (
const std::set<SystematicVariation>&
systematics,
272 const std::string& val_basename)
276 for (std::set<SystematicVariation>::const_iterator
280 if (sys->basename() == val_basename)
290 bool SystematicVariation ::
299 const std::string& SystematicVariation ::
308 std::string SystematicVariation ::
313 std::string::size_type
split =
m_name.rfind (
"__");
314 if (
split != std::string::npos)
322 std::string SystematicVariation ::
323 subvariation ()
const
327 std::string::size_type
split =
m_name.rfind (
"__");
328 if (
split != std::string::npos)
336 float SystematicVariation ::
344 if (
split != std::string::npos)
355 if (
split != std::string::npos)
370 std::pair<unsigned,float> SystematicVariation ::
371 getToyVariation ()
const
377 const std::size_t prefixSize = 4;
378 const auto split1 = variation.find (
"toy_");
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());
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",
""));
392 bool SystematicVariation ::
393 isToyEnsemble ()
const
401 bool SystematicVariation ::
402 isContinuousEnsemble ()
const
410 bool SystematicVariation ::
419 bool SystematicVariation ::
433 bool SystematicVariation ::
434 isToyVariation ()
const
436 static const std::regex pattern (
".*__toy_[0-9]+_[0-9]+((scale)[0-9]{1,4})?");
437 return regex_match (
m_name, pattern);
442 bool SystematicVariation ::
443 isContinuousVariation ()
const
445 static const std::regex pattern (
".*__[0-9]+((up)|(down))([0-9]{1,4})?");
446 return regex_match (
m_name, pattern);
453 return str << obj.name();
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
static const std::vector< std::string > systematics
bool operator==(const CP::SystematicVariation &a, const CP::SystematicVariation &b)
bool operator<(const CP::SystematicVariation &a, const CP::SystematicVariation &b)
SystematicVariation()
effects: standard default constructor guarantee: no-fail
CONTINUOUS_ARG
effects: constructor for indicating continuous systematics guarantee: strong failures: out of memory ...
std::string subvariation() const
description: the part of the name that indicates by how many sigmas we varied guarantee: strong failu...
std::string basename() const
description: the base name, i.e.
std::string m_name
description: members directly corresponding to accessors
bool isToyEnsemble() const
whether this represents a toy ensemble
bool isContinuousEnsemble() const
whether this represents a continuous ensemble
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Select isolated Photons, Electrons and Muons.
std::ostream & operator<<(std::ostream &out, const std::pair< FIRST, SECOND > &pair)
Helper print operator.
std::string str(const TrigT2MbtsBits_v1 &trigT2MbtsBits)
std::string basename(std::string name)
std::string number(const double &d, const std::string &s)