yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
Estimate.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_Estimate_h
7#define YODA_Estimate_h
8
9#include "YODA/Exceptions.h"
10#include "YODA/Dbn.h"
11#include "YODA/Transformation.h"
14#include <cmath>
15#include <map>
16#include <string>
17#include <regex>
18#include <utility>
19
20namespace YODA {
21
29 class Estimate {
30 public:
31
33
34
36 Estimate() { reset(); }
37
38
42 Estimate(double v, std::map<std::string,std::pair<double,double>>& errors)
43 : _value(v), _error(errors) { }
44
45
47 Estimate(const double v, const std::pair<double,double>& e, const std::string& source = "")
48 : _value(v) { setErr(e, source); }
49
53 Estimate(const Estimate& toCopy) {
54 _value = toCopy._value;
55 _error = toCopy._error;
56 }
57
61 Estimate(Estimate&& toMove) {
62 _value = std::move(toMove._value);
63 _error = std::move(toMove._error);
64 }
65
69 Estimate& operator=(const Estimate& toCopy) noexcept {
70 if (this != &toCopy) {
71 _value = toCopy._value;
72 _error = toCopy._error;
73 }
74 return *this;
75 }
76
80 Estimate& operator=(Estimate&& toMove) noexcept {
81 if (this != &toMove) {
82 _value = std::move(toMove._value);
83 _error = std::move(toMove._error);
84 }
85 return *this;
86 }
87
89
90
92
93
95 Estimate& add(const Estimate& toAdd, const std::string& pat_uncorr="^stat|^uncor" ) {
96 setVal(val() + toAdd.val());
97 std::smatch match;
98 const std::regex re(pat_uncorr, std::regex_constants::icase);
99 for (const std::string& src : toAdd.sources()) {
100 if (!hasSource(src)) setErr(toAdd.errDownUp(src), src);
101 else if (std::regex_search(src, match, re)) {
102 // treat as uncorrelated between AOs:
103 // add in quadrature
104 const auto [l_dn,l_up] = errDownUp(src);
105 const auto [r_dn,r_up] = toAdd.errDownUp(src);
106 const double new_dn = std::sqrt(l_dn*l_dn + r_dn*r_dn);
107 const double new_up = std::sqrt(l_up*l_up + r_up*r_up);
108 setErr({-new_dn,new_up}, src);
109 }
110 else {
111 // treat as correlated between AOs: add linearly
112 const auto [l_dn,l_up] = errDownUp(src);
113 const auto [r_dn,r_up] = toAdd.errDownUp(src);
114 setErr({l_dn+r_dn, l_up+r_up}, src);
115 }
116 }
117 return *this;
118 }
119 //
120 Estimate& operator+=(const Estimate& toAdd) {
121 return add(toAdd);
122 }
123
125 Estimate& subtract(const Estimate& toSubtract, const std::string& pat_uncorr="^stat|^uncor" ) {
126 setVal(val() - toSubtract.val());
127 std::smatch match;
128 const std::regex re(pat_uncorr, std::regex_constants::icase);
129 for (const std::string& src : toSubtract.sources()) {
130 if (!hasSource(src)) setErr(toSubtract.errDownUp(src), src);
131 else if (std::regex_search(src, match, re)) {
132 // treat as uncorrelated between AOs: add in quadrature
133 const auto [l_dn,l_up] = errDownUp(src);
134 const auto [r_dn,r_up] = toSubtract.errDownUp(src);
135 const double new_dn = std::sqrt(l_dn*l_dn + r_dn*r_dn);
136 const double new_up = std::sqrt(l_up*l_up + r_up*r_up);
137 setErr({-new_dn,new_up}, src);;
138 }
139 else {
140 // treat as correlated between AOs: add linearly
141 const auto [l_dn,l_up] = errDownUp(src);
142 const auto [r_dn,r_up] = toSubtract.errDownUp(src);
143 setErr({l_dn+r_dn, l_up+r_up}, src);
144 }
145 }
146 return *this;
147 }
148 //
149 Estimate& operator-=(const Estimate& toSubtract) {
150 return subtract(toSubtract);
151 }
152
154
156
157
159 void setValue(const double value) noexcept { _value = value; }
160
162 void setVal(const double val) noexcept { setValue(val); }
163
165 void setErr(const std::pair<double, double> &err, const std::string& source = "") {
166 const std::string& s = Utils::toUpper(source);
167 if (s == "TOTAL")
168 throw UserError("Use empty string for the total uncertainty!");
169 _error[source] = err;
170 }
171
176 void setErr(const double err, const std::string& source = "") {
177 setErr({-fabs(err),fabs(err)}, source);
178 }
179
181 void set(const double val, const std::pair<double, double> &err, const std::string source = "") {
182 setVal(val);
183 setErr(err, source);
184 }
185
186
188 void set(const double val, const double err, const std::string& source = "") {
189 setVal(val);
190 setErr(err, source);
191 }
192
194 void reset() noexcept {
195 _value = std::numeric_limits<double>::quiet_NaN();
196 _error.clear();
197 }
198
199
201 void scale(const double scalefactor) noexcept {
202 _value *= scalefactor;
203 for (auto& item : _error) {
204 item.second = { item.second.first * scalefactor, item.second.second * scalefactor };
205 }
206 }
207
209 void scale(const Trf<1>& trf) {
210 trf.transform(_value, _error);
211 }
212
214 void transform(const Trf<1>& trf) {
215 scale(trf);
216 }
217
219 void renameSource(const std::string& old_label, const std::string& new_label) {
220 if (!hasSource(old_label)) {
221 throw UserError("Error map has no such key: "+old_label);
222 }
223 auto entry = _error.extract(old_label);
224 entry.key() = new_label;
225 _error.insert(std::move(entry));
226 }
227
228 // Remove error source @a source
229 void rmSource(const std::string& source) {
230 if (hasSource(source)) {
231 _error.erase(source);
232 }
233 }
234
235 // Clear the error breakdown
236 void rmErrs() {
237 _error.clear();
238 }
239
241
242 public:
243
244
246
247
249 double val() const noexcept { return _value; }
250
255 std::pair<double,double> errDownUp(const std::string& source = "") const {
256 const size_t count = _error.count(source);
257 if (!count)
258 throw RangeError("Error map has no such key: "+source);
259 return _error.at(source);
260 }
261
263 std::pair<double,double> err(const std::string& source = "") const {
264 return errDownUp(source);
265 }
266
268 std::pair<double,double> errNegPos(std::string source = "") const {
269 return _downUp2NegPos( errDownUp(source) );
270 }
271
273 double errNeg(const std::string& source = "") const {
274 return errNegPos(source).first;
275 }
276
278 double errPos(const std::string& source = "") const {
279 return errNegPos(source).second;
280 }
281
283 double errDown(const std::string& source = "") const {
284 return errDownUp(source).first;
285 }
286
288 double errUp(const std::string& source = "") const {
289 return errDownUp(source).second;
290 }
291
293 double errAvg(const std::string& source = "") const {
294 return _average(errDownUp(source));
295 }
296
299 double errEnv(const std::string& source = "") const {
300 return _envelope(errDownUp(source));
301 }
302
304 std::pair<double,double> relErrDownUp(const std::string& source = "") const {
305 auto [dn,up] = errDownUp(source);
306 dn = _value != 0 ? dn/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
307 up = _value != 0 ? up/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
308 return {dn,up};
309 }
310
312 std::pair<double,double> relErr(const std::string& source = "") const {
313 return relErrDownUp(source);
314 }
315
317 double relErrDown(const std::string& source = "") const {
318 return relErr(source).first;
319 }
320
322 double relErrUp(const std::string& source = "") const {
323 return relErr(source).second;
324 }
325
328 double relErrAvg(const std::string& source = "") const {
329 return _average(relErrDownUp(source));
330 }
331
334 double relErrEnv(const std::string& source = "") const {
335 return _envelope(relErrDownUp(source));
336 }
337
340 double valMax(const std::string& source = "") const {
341 return val() + errPos(source);
342 }
343
346 double valMin(const std::string& source = "") const {
347 return val() + errNeg(source);
348 }
349
358 std::pair<double,double> quadSum(const std::string& pat_match = "") const noexcept {
359 const bool check_match = pat_match != ""; std::smatch match;
360 const std::regex re(pat_match, std::regex_constants::icase);
361 // interpret as { neg , pos } quad sums
362 std::pair<double, double> ret = { 0., 0. };
363 for (const auto& item : _error) {
364 if (item.first == "") continue;
365 if (check_match && !std::regex_search(item.first, match, re)) continue;
366 const auto [dn,up] = _downUp2NegPos(item.second);
367 ret.first += dn*dn;
368 ret.second += up*up;
369 }
370 return { - std::sqrt(ret.first), std::sqrt(ret.second) };
371 }
372
374 double quadSumNeg(const std::string& pat_match = "") const noexcept {
375 return quadSum(pat_match).first;
376 }
377
379 double quadSumPos(const std::string& pat_match = "") const noexcept {
380 return quadSum(pat_match).second;
381 }
382
384 double quadSumAvg(const std::string& pat_match = "") const noexcept {
385 return _average(quadSum(pat_match));
386 }
387
390 double quadSumEnv(const std::string& pat_match = "") const noexcept {
391 return _envelope(quadSum(pat_match));
392 }
393
396 double quadSumMax(const std::string& pat_match = "") const {
397 return val() + quadSumPos(pat_match);
398 }
399
402 double quadSumMin(const std::string& pat_match = "") const {
403 return val() + quadSumNeg(pat_match);
404 }
405
410 std::pair<double,double> totalErr(const std::string& pat_match = "") const noexcept {
411 // check if the user specified the total uncertainty
412 if (pat_match == "" && _error.count("")) return _downUp2NegPos(_error.at(""));
413 // otherwise return quadrature sum
414 return quadSum(pat_match);
415 }
416
418 double totalErrNeg(const std::string& pat_match = "") const noexcept {
419 return totalErr(pat_match).first;
420 }
421
423 double totalErrPos(const std::string& pat_match = "") const noexcept {
424 return totalErr(pat_match).second;
425 }
426
429 double totalErrAvg(const std::string& pat_match = "") const {
430 return _average(totalErr(pat_match));
431 }
432
435 double totalErrEnv(const std::string& pat_match = "") const {
436 return _envelope(totalErr(pat_match));
437 }
438
441 double totalErrMax(const std::string& pat_match = "") const {
442 return val() + totalErrPos(pat_match);
443 }
444
447 double totalErrMin(const std::string& pat_match = "") const {
448 return val() + totalErrNeg(pat_match);
449 }
450
452 double valueErr(const std::string& pat_match = "") const {
453 return fabs(totalErrAvg(pat_match));
454 }
455
457 std::pair<double,double> relTotalErr(const std::string& pat_match = "") const noexcept {
458 auto [neg,pos] = totalErr(pat_match);
459 neg = _value != 0 ? neg/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
460 pos = _value != 0 ? pos/fabs(_value) : std::numeric_limits<double>::quiet_NaN();
461 return {neg,pos};
462 }
463
465 double relTotalErrNeg(const std::string& pat_match = "") const noexcept {
466 return relTotalErr(pat_match).first;
467 }
468
470 double relTotalErrPos(const std::string& pat_match = "") const noexcept {
471 return relTotalErr(pat_match).second;
472 }
473
476 double relTotalErrAvg(const std::string& pat_match = "") const noexcept {
477 return _average(relTotalErr(pat_match));
478 }
479
482 double relTotalErrEnv(const std::string& pat_match = "") const noexcept {
483 return _envelope(relTotalErr(pat_match));
484 }
485
487 std::vector<std::string> sources() const noexcept {
488 std::vector<std::string> keys;
489 for (const auto& item : _error) keys.push_back(item.first);
490 return keys;
491 }
492
494 bool hasSource(const std::string& key) const noexcept {
495 return _error.count(key);
496 }
497
499 size_t numErrs() const noexcept {
500 return _error.size();
501 }
502
504
506
507
508 size_t _lengthContent(bool fixed_length = false) const noexcept {
509 const size_t nErrs = fixed_length? 1 : numErrs();
510 return 2*(nErrs + 1);
511 }
512
513 std::vector<double> _serializeContent(bool fixed_length = false) const noexcept {
514 std::vector<double> rtn;
515 const size_t nErrs = fixed_length? 1 : numErrs();
516 rtn.reserve(2*(nErrs + 1));
517 rtn.push_back(_value);
518 if (fixed_length) {
519 rtn.push_back(1.0);
520 rtn.push_back(totalErrNeg());
521 rtn.push_back(totalErrPos());
522 return rtn;
523 }
524 rtn.push_back((double)_error.size());
525 for (const auto& item : _error) {
526 rtn.push_back(item.second.first);
527 rtn.push_back(item.second.second);
528 }
529 return rtn;
530 }
531
532 void _deserializeContent(const std::vector<double>& data, bool fixed_length = false) {
533
534 if (data.size() < 2)
535 throw UserError("Length of serialized data should be at least 2!");
536
537 if (2*(fixed_length? 1 : data[1]) != (data.size() - 2))
538 throw UserError("Expected "+std::to_string(data[1])+" error pairs!");
539
540 reset();
541 size_t idx = 0;
542 auto itr = data.cbegin();
543 const auto itrEnd = data.cend();
544 while (itr != itrEnd) {
545 if (!idx) {
546 _value = *itr; ++itr; ++itr;
547 }
548 else {
549 std::string name("source" + std::to_string(idx));
550 const double dn = *itr; ++itr;
551 const double up = *itr; ++itr;
552 setErr({dn, up}, name);
553 }
554 ++idx;
555 }
556 if (numErrs() == 1) renameSource("source1", "");
557 }
558
559 std::vector<std::string> serializeSources() const noexcept {
560 return sources();
561 }
562
563 void deserializeSources(const std::vector<std::string>& data) {
564
565 const size_t nErrs = numErrs();
566 if (data.size() != nErrs)
567 throw UserError("Expected " + std::to_string(nErrs) + " error source labels!");
568
569 for (size_t i = 0; i < data.size(); ++i) {
570 const std::string name("source" + std::to_string(i+1));
571 if (!_error.count(name))
572 throw UserError("Key names have already been updated!");
573 renameSource(name, data[i]);
574 }
575
576 }
577
578 // @}
579
580 private:
581
583
584
588 std::pair<double,double> _downUp2NegPos(const std::pair<double,double> &e) const noexcept {
589 const auto [dn,up] = e;
590 if (dn < 0. && up < 0.) {
591 // both negative
592 const double env = std::min(dn, up);
593 return {env, 0.};
594 }
595 else if (dn < 0.) {
596 // dn negative, up positive
597 return {dn,up};
598 }
599 else if (up < 0.) {
600 // up negative, dn positive
601 return {up, dn};
602 }
603 // else: both positive
604 const double env = std::max(dn, up);
605 return {0., env};
606 }
607
609 double _average(const std::pair<double,double> &err) const noexcept {
610 return 0.5*(fabs(err.first) + fabs(err.second));
611 }
612
614 double _envelope(const std::pair<double,double> &err) const noexcept {
615 return std::max(fabs(err.first), fabs(err.second));
616 }
617
619
620
622
623
625 double _value;
626
633 std::map<std::string, std::pair<double,double>> _error;
634
636
637 public:
638
640
641
642 std::string _toString() const noexcept {
643 std::string res ="";
644 res += ("value="+ std::to_string(_value));
645 for (const auto& item : _error) {
646 const std::string name = item.first == ""? "user-supplied total " : "";
647 res += (", " + name + "error("+ item.first);
648 res += (")={ "+ std::to_string(item.second.first));
649 res += (", "+ std::to_string(item.second.second)+" }");
650 }
651 return res;
652 }
653
655 };
656
657
659
660
662 inline Estimate operator + (Estimate lhs, const Estimate& rhs) {
663 lhs += rhs;
664 return lhs;
665 }
666
669 lhs += std::move(rhs);
670 return lhs;
671 }
672
674 inline Estimate operator - (Estimate lhs, const Estimate& rhs) {
675 lhs -= rhs;
676 return lhs;
677 }
678
681 lhs -= std::move(rhs);
682 return lhs;
683 }
684
686 inline Estimate divide(const Estimate& numer, const Estimate& denom,
687 const std::string& pat_uncorr="^stat|^uncor") {
688
689 Estimate rtn;
690 if (denom.val()) rtn.setVal(numer.val() / denom.val());
691 const double newVal = rtn.val();
692
693 // get error sources
694 std::vector<std::string> sources = numer.sources();
695 std::vector<std::string> tmp = denom.sources();
696 sources.insert(std::end(sources),
697 std::make_move_iterator(std::begin(tmp)),
698 std::make_move_iterator(std::end(tmp)));
699 std::sort(sources.begin(), sources.end());
700 sources.erase( std::unique(sources.begin(), sources.end()), sources.end() );
701
702 std::smatch match;
703 const std::regex re(pat_uncorr, std::regex_constants::icase);
704 for (const std::string& src : sources) {
705 if (std::regex_search(src, match, re)) {
706 // treat as uncorrelated between AOs:
707 // add relative errors in quadrature
708 double n_dn = 0.0, n_up = 0.0;
709 if (numer.hasSource(src)) {
710 n_dn = numer.relErrDown(src);
711 n_up = numer.relErrUp(src);
712 }
713 double d_dn = 0.0, d_up = 0.0;
714 if (denom.hasSource(src)) {
715 d_dn = denom.relErrDown(src);
716 d_up = denom.relErrUp(src);
717 }
718 const double new_dn = fabs(newVal) * std::sqrt(n_dn*n_dn + d_dn*d_dn);
719 const double new_up = fabs(newVal) * std::sqrt(n_up*n_up + d_up*d_up);
720 rtn.setErr({-new_dn,new_up}, src);
721 }
722 else {
723 // treat as correlated between AOs:
724 // work out correlated ratio: R+dR = (N+dN)/(D+dD)
725 double n_dn = numer.val(), n_up = numer.val();
726 if (numer.hasSource(src)) {
727 n_dn += numer.errDown(src);
728 n_up += numer.errUp(src);
729 }
730 double d_dn = denom.val(), d_up = denom.val();
731 if (denom.hasSource(src)) {
732 d_dn += denom.errDown(src);
733 d_up += denom.errUp(src);
734 }
735 double new_dn = std::numeric_limits<double>::quiet_NaN();
736 double new_up = std::numeric_limits<double>::quiet_NaN();
737 if (d_dn) new_dn = n_dn / d_dn - newVal;
738 if (d_up) new_up = n_up / d_up - newVal;
739 rtn.setErr({new_dn, new_up}, src);
740 }
741 }
742
743 return rtn;
744 }
745
747 inline Estimate operator / (const Estimate& numer, const Estimate& denom) {
748 return divide(numer, denom);
749 }
750
752 inline Estimate operator / (Estimate&& numer, const Estimate& denom) {
753 return divide(std::move(numer), denom);
754 }
755
757 inline Estimate operator / (const Estimate& numer, Estimate&& denom) {
758 return divide(numer, std::move(denom));
759 }
760
762 inline Estimate operator / (Estimate&& numer, Estimate&& denom) {
763 return divide(std::move(numer), std::move(denom));
764 }
765
767 inline Estimate efficiency(const Estimate& accepted, const Estimate& total,
768 const std::string& pat_uncorr="^stat|^uncor") {
769
773 const double acc_val = accepted.val();
774 const double tot_val = total.val();
775 if (acc_val > tot_val)
776 throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator: "
777 + Utils::toStr(acc_val) + " / " + Utils::toStr(tot_val));
778
779 Estimate rtn = divide(accepted, total, pat_uncorr);
780
781 // get error sources
782 std::vector<std::string> sources = accepted.sources();
783 std::vector<std::string> tmp = total.sources();
784 sources.insert(std::end(sources),
785 std::make_move_iterator(std::begin(tmp)),
786 std::make_move_iterator(std::end(tmp)));
787 std::sort(sources.begin(), sources.end());
788 sources.erase( std::unique(sources.begin(), sources.end()), sources.end() );
789
790 // set binomial error for uncorrelated error sources
791 std::smatch match;
792 const double eff = rtn.val();
793 const std::regex re(pat_uncorr, std::regex_constants::icase);
794 for (const std::string& src : sources) {
795 double err = std::numeric_limits<double>::quiet_NaN();
796 if (!tot_val) {
797 rtn.setErr({-err,err}, src);
798 continue;
799 }
800 else if (std::regex_search(src, match, re)) {
801 const double acc_err = accepted.relTotalErrAvg();
802 const double tot_err = total.totalErrAvg();
803 err = sqrt(std::abs( ((1-2*eff)*sqr(acc_err) + sqr(eff)*sqr(tot_err)) / sqr(tot_val) ));
804 rtn.setErr({-err,err}, src);
805 continue;
806 }
807 }
808
809 return rtn;
810 }
811
813
814}
815
816#endif
A point estimate (base class for the Estimate)
Definition Estimate.h:29
void scale(const double scalefactor) noexcept
Rescale as if value and uncertainty had been different by factor scalefactor.
Definition Estimate.h:201
Estimate & add(const Estimate &toAdd, const std::string &pat_uncorr="^stat|^uncor")
Add two Estimates.
Definition Estimate.h:95
size_t numErrs() const noexcept
The number of error sources in the error map.
Definition Estimate.h:499
std::pair< double, double > relErrDownUp(const std::string &source="") const
The relative signed error pair with respect to the central value.
Definition Estimate.h:304
std::pair< double, double > errNegPos(std::string source="") const
The signed negative and positive uncertainty component.
Definition Estimate.h:268
void setErr(const double err, const std::string &source="")
Set a symmetric uncertainty component.
Definition Estimate.h:176
Estimate(double v, std::map< std::string, std::pair< double, double > > &errors)
Constructor to set an Estimate with a pre-filled state.
Definition Estimate.h:42
double relTotalErrPos(const std::string &pat_match="") const noexcept
The relative positive total uncertainty on the central value.
Definition Estimate.h:470
void setErr(const std::pair< double, double > &err, const std::string &source="")
Set a signed uncertainty component.
Definition Estimate.h:165
double totalErrNeg(const std::string &pat_match="") const noexcept
The negative total uncertainty.
Definition Estimate.h:418
double quadSumAvg(const std::string &pat_match="") const noexcept
The unsigned average of the two quad-sum-based total uncertainty components.
Definition Estimate.h:384
double quadSumMin(const std::string &pat_match="") const
The minimal shift of the central value from the quad-sum-based total uncertainty components.
Definition Estimate.h:402
Estimate & operator+=(const Estimate &toAdd)
Definition Estimate.h:120
double totalErrPos(const std::string &pat_match="") const noexcept
The positive total uncertainty.
Definition Estimate.h:423
std::pair< double, double > relErr(const std::string &source="") const
Convenience alias for relErrDownUp.
Definition Estimate.h:312
std::vector< std::string > sources() const noexcept
The list of error source names.
Definition Estimate.h:487
void transform(const Trf< 1 > &trf)
Generalised transformations with functors.
Definition Estimate.h:214
double totalErrMax(const std::string &pat_match="") const
The maximal shift of the central value from the total uncertainty components.
Definition Estimate.h:441
void setValue(const double value) noexcept
Set the central value of this estimator.
Definition Estimate.h:159
double errDown(const std::string &source="") const
The signed error due to the systematic downward variation.
Definition Estimate.h:283
double totalErrMin(const std::string &pat_match="") const
The minimal shift of the central value from the total uncertainty components.
Definition Estimate.h:447
Estimate & operator=(Estimate &&toMove) noexcept
Definition Estimate.h:80
double valueErr(const std::string &pat_match="") const
The unsigned average total uncertainty.
Definition Estimate.h:452
double relTotalErrNeg(const std::string &pat_match="") const noexcept
The relative negative total uncertainty on the central value.
Definition Estimate.h:465
double totalErrAvg(const std::string &pat_match="") const
The average of the total downward/upward uncertainty shifts, which are taken to be the signed quadrat...
Definition Estimate.h:429
double errPos(const std::string &source="") const
The signed positive uncertainty component.
Definition Estimate.h:278
double quadSumNeg(const std::string &pat_match="") const noexcept
The negative component of the quad-sum-based total uncertainty components.
Definition Estimate.h:374
double relErrEnv(const std::string &source="") const
The relative unsigned symmetrised error from the largest component of the downwards/upwards shifts wi...
Definition Estimate.h:334
void deserializeSources(const std::vector< std::string > &data)
Definition Estimate.h:563
double quadSumPos(const std::string &pat_match="") const noexcept
The positive component of the quad-sum-based total uncertainty components.
Definition Estimate.h:379
double errAvg(const std::string &source="") const
The unsigned error from an average of the downwards/upwards shifts.
Definition Estimate.h:293
double relErrUp(const std::string &source="") const
The relative positive error with respect to the central value.
Definition Estimate.h:322
Estimate & operator=(const Estimate &toCopy) noexcept
Definition Estimate.h:69
void rmSource(const std::string &source)
Definition Estimate.h:229
Estimate & operator-=(const Estimate &toSubtract)
Definition Estimate.h:149
void rmErrs()
Definition Estimate.h:236
void scale(const Trf< 1 > &trf)
Generalised transformations with functors.
Definition Estimate.h:209
std::pair< double, double > totalErr(const std::string &pat_match="") const noexcept
The total uncertainty.
Definition Estimate.h:410
double relErrAvg(const std::string &source="") const
The relative uncertainty from an average of the downward/upward shifts with respect to the central va...
Definition Estimate.h:328
double errUp(const std::string &source="") const
The signed error due to the systematic upward variation.
Definition Estimate.h:288
double val() const noexcept
The central value.
Definition Estimate.h:249
Estimate(Estimate &&toMove)
Definition Estimate.h:61
double errEnv(const std::string &source="") const
The unsigned symmetrised error from the largest component of the downwards/upwards shifts.
Definition Estimate.h:299
double relTotalErrEnv(const std::string &pat_match="") const noexcept
The unsigned symmetrised error from the largest downward/upward components of the relative total quad...
Definition Estimate.h:482
double totalErrEnv(const std::string &pat_match="") const
The unsigned symmetrised uncertainty from the largest of the downward/upward shifts of the quad-sum-b...
Definition Estimate.h:435
Estimate()
Default constructor of a new distribution.
Definition Estimate.h:36
void set(const double val, const std::pair< double, double > &err, const std::string source="")
Set both central value and uncertainty component.
Definition Estimate.h:181
void setVal(const double val) noexcept
Alias for setValue.
Definition Estimate.h:162
std::vector< std::string > serializeSources() const noexcept
Definition Estimate.h:559
void set(const double val, const double err, const std::string &source="")
Set both central value and uncertainty component.
Definition Estimate.h:188
void renameSource(const std::string &old_label, const std::string &new_label)
Replace a source label in the error breakdown.
Definition Estimate.h:219
double valMax(const std::string &source="") const
The maximal shift of the central value according to systematic variation source.
Definition Estimate.h:340
double quadSumMax(const std::string &pat_match="") const
The maximal shift of the central value from the quad-sum-based total uncertainty components.
Definition Estimate.h:396
double errNeg(const std::string &source="") const
The signed negative uncertainty component.
Definition Estimate.h:273
std::pair< double, double > err(const std::string &source="") const
Convenience alias for errorDownUp(source)
Definition Estimate.h:263
double relTotalErrAvg(const std::string &pat_match="") const noexcept
The relative average of the quad-sum-based total downward/upward uncertainty components.
Definition Estimate.h:476
Estimate & subtract(const Estimate &toSubtract, const std::string &pat_uncorr="^stat|^uncor")
Subtract one Estimate from another.
Definition Estimate.h:125
std::pair< double, double > quadSum(const std::string &pat_match="") const noexcept
The quadrature sum of uncertainty components.
Definition Estimate.h:358
Estimate(const Estimate &toCopy)
Definition Estimate.h:53
double valMin(const std::string &source="") const
The minimal shift of the central value according to systematic variation source.
Definition Estimate.h:346
std::pair< double, double > errDownUp(const std::string &source="") const
The signed absolute error on the central value.
Definition Estimate.h:255
double relErrDown(const std::string &source="") const
The relative negative error with respect to the central value.
Definition Estimate.h:317
Estimate(const double v, const std::pair< double, double > &e, const std::string &source="")
Alternative constructor to set an Estimate with value and uncertainty.
Definition Estimate.h:47
bool hasSource(const std::string &key) const noexcept
Returns true/false if the error map contains key.
Definition Estimate.h:494
double quadSumEnv(const std::string &pat_match="") const noexcept
The unsigned symmetrised uncertainty from the largest of the quad-sum-based total uncertainty compone...
Definition Estimate.h:390
void reset() noexcept
Reset the internal values.
Definition Estimate.h:194
std::pair< double, double > relTotalErr(const std::string &pat_match="") const noexcept
The relative negative/positive total uncertainty with respect to the central value.
Definition Estimate.h:457
Error for e.g. use of invalid bin ranges.
Definition Exceptions.h:34
void transform(double &val, Args &&... args) const
Transform value val.
Error for problems introduced outside YODA, to put it nicely.
Definition Exceptions.h:100
Anonymous namespace to limit visibility.
BinnedDbn< DbnN, AxisT... > operator+(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Add two BinnedDbn objects.
Definition BinnedDbn.h:1060
BinnedEstimate< AxisT... > operator/(const BinnedDbn< DbnN, AxisT... > &numer, const BinnedDbn< DbnN, AxisT... > &denom)
Definition BinnedDbn.h:1133
NUM sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.h:216
BinnedEstimate< AxisT... > efficiency(const BinnedDbn< DbnN, AxisT... > &accepted, const BinnedDbn< DbnN, AxisT... > &total)
Calculate a binned efficiency ratio of two BinnedDbn objects.
Definition BinnedDbn.h:1162
BinnedDbn< DbnN, AxisT... > operator-(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Subtract one BinnedDbn object from another.
Definition BinnedDbn.h:1076
BinnedEstimate< AxisT... > divide(const BinnedDbn< DbnN, AxisT... > &numer, const BinnedDbn< DbnN, AxisT... > &denom)
Divide two BinnedDbn objects.
Definition BinnedDbn.h:1092