yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
Dbn.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_Dbn_h
7#define YODA_Dbn_h
8
9#include "YODA/Exceptions.h"
10#include "YODA/Utils/DbnUtils.h"
13#include <cmath>
14#include <string>
15#include <array>
16
17namespace YODA {
18
22 namespace {
23
25 template <size_t ... Is>
26 constexpr bool has_match(const size_t i, std::integer_sequence<size_t, Is...>) {
27 return ((i == Is) || ...);
28 }
29
31 template<typename INT>
32 constexpr std::integer_sequence<INT>
33 concat_sequences(std::integer_sequence<INT>){
34 return {};
35 }
36
38 template<typename INT, INT... s, INT... t>
39 constexpr std::integer_sequence<INT,s...,t...>
40 concat_sequences(std::integer_sequence<INT, s...>, std::integer_sequence<INT, t...>){
41 return {};
42 }
43
45 template<typename INT, INT... s, INT... t, class... R>
46 constexpr auto
47 concat_sequences(std::integer_sequence<INT, s...>, std::integer_sequence<INT, t...>, R...) {
48 return concat_sequences(std::integer_sequence<INT,s...,t...>{}, R{}...);
49 }
50
53 template<class INT, INT a, class CHECK>
54 constexpr auto AxisFilterSingle(std::integer_sequence<INT, a>, CHECK pass) {
55 if constexpr (pass(a))
56 return std::integer_sequence<INT, a>{};
57 else
58 return std::integer_sequence<INT>{};
59 }
60
64 template<class INT, INT... b, class CHECK>
65 constexpr auto AxisFilter(std::integer_sequence<INT, b...>, [[maybe_unused]] CHECK pass) {
66 if constexpr (sizeof...(b) > 0) // non empty sequence
67 return concat_sequences(AxisFilterSingle(std::integer_sequence<INT, b>{}, pass)...);
68 else // empty sequence case
69 return std::integer_sequence<INT>{};
70 }
71
72 }
73
85 template <size_t N>
86 class DbnBase {
87 public:
88
90 using FillDim = std::integral_constant<size_t, N>;
91 using DataSize = std::integral_constant<size_t, 1 + 2*(N+1) + (N*(N-1)/2)>;
92
94
95
97 DbnBase() { reset(); }
98
99
104 template<size_t dim = N, typename = std::enable_if_t<(dim < 2)>>
105 DbnBase(const double numEntries, const std::array<double,N+1>& sumW, const std::array<double,N+1>& sumW2)
106 : _numEntries(numEntries), _sumW(sumW), _sumW2(sumW2) { }
107
112 template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
113 DbnBase(const double numEntries, const std::array<double,N+1>& sumW, const std::array<double,N+1>& sumW2,
114 const std::array<double,N*(N-1)/2>& sumWcross)
115 : _numEntries(numEntries), _sumW(sumW), _sumW2(sumW2), _sumWcross(sumWcross) { }
116
120 DbnBase(const DbnBase&) = default;
121
125 DbnBase(DbnBase&&) = default;
126
130 DbnBase& operator = (const DbnBase&) = default;
131
136
138
139
141
142
143
152 void fill(const std::array<double, N> vals, const double weight = 1.0, const double fraction = 1.0) {
153 fill(vals, weight, fraction, std::make_index_sequence<N>{});
154 }
155
161 template <typename... Args>
162 void fill(Args&&... args) {
163 // N + 2 - dimension + 2 default parameters
164 static_assert(sizeof...(args) <= N + 2,
165 "Value's dimension doesn't match distribution's dimension.");
166 std::array<double, sizeof...(args)> vals = {{args...}};
167 double weight = 1.0;
168 double fraction = 1.0;
169 if (vals.size() > N) {
170 weight = vals[N];
171 if (vals.size() > N + 1) fraction = vals[N + 1];
172 }
173 const double sf = fraction * weight;
174 _numEntries += fraction;
175 _sumW.at(0) += sf;
176 _sumW2.at(0) += fraction*sqr(weight);
177 for (unsigned int i = 0; i < N; ++i) {
178 _sumW.at(i + 1) += sf * vals.at(i);
179 _sumW2.at(i + 1) += sf * sqr(vals.at(i));
180 }
181
182 if constexpr(N >= 2) {
183 size_t idx = 0;
184 for (size_t i = 0; i < (N-1); ++i) {
185 for (size_t j = i+1; j < N; ++j) {
186 _sumWcross.at(idx++) += sf * vals.at(i) * vals.at(j);
187 }
188 }
189 }
190
191 }
192
193
197 void set(const double numEntries, const std::array<double,N+1>& sumW,
198 const std::array<double,N+1>& sumW2,
199 const std::array<double,N*(N-1)/2>& sumWcross) {
200 _numEntries = numEntries;
201 _sumW = sumW;
202 _sumW2 = sumW2;
203 _sumWcross = sumWcross;
204 }
205
209 void set(const double numEntries, const std::vector<double>& sumW,
210 const std::vector<double>& sumW2,
211 const std::vector<double>& sumWcross = {}) {
212 if (!(sumW.size() <= (N + 1) || sumW2.size() <= (N + 1) || sumWcross.size() <= (N*(N-1)/2)))
213 throw UserError("Value's dimension doesn't match distribution's dimension.");
214 _numEntries = numEntries;
215 std::copy_n(std::make_move_iterator(sumW.begin()), sumW.size(), _sumW.begin());
216 std::copy_n(std::make_move_iterator(sumW2.begin()), sumW2.size(), _sumW2.begin());
217 std::copy_n(std::make_move_iterator(sumWcross.begin()), sumWcross.size(), _sumWcross.begin());
218 }
219
220
222 void set(const DbnBase<N>& other) {
223 if (this != &other) *this = other;
224 }
225
227 void set(DbnBase<N>&& other) {
228 if (this != &other) *this = std::move(other);
229 }
230
232 void reset() {
233 _numEntries= 0;
234 _sumW.fill(0);
235 _sumW2.fill(0);
236 _sumWcross.fill(0);
237 }
238
239
241 void scaleW(const double scalefactor) {
242 _sumW.at(0) *= scalefactor;
243 _sumW2.at(0) *= sqr(scalefactor);
244 for (size_t i = 0; i< N; ++i) {
245 // first- and second-order moments
246 _sumW.at(i+1) *= scalefactor;
247 _sumW2.at(i+1) *= scalefactor;
248 }
249 for (size_t i = 0; i < _sumWcross.size(); ++i) {
250 _sumWcross.at(i) *= scalefactor;
251 }
252 }
253
254 void scale(const size_t dim, const double factor) {
255 if (dim >= N)
256 throw RangeError("Dimension index should be less than "+std::to_string(N));
257 _sumW.at(dim+1) *= factor;
258 _sumW2.at(dim+1) *= sqr(factor);
259 size_t idx = 0;
260 for (size_t i = 0; i < (N-1); ++i) {
261 for (size_t j = i+1; j < N; ++j) {
262 if (i == dim || j == dim) {
263 _sumWcross.at(idx++) *= factor;
264 }
265 }
266 } // end of double loop
267 }
268
269
271
272 public:
273
274
276
277
279 double errW() const;
280
282 double relErrW() const;
283
285 double mean(const size_t i) const;
286
288 double variance(const size_t i) const;
289
291 double stdDev(const size_t i) const { return std::sqrt(variance(i)); }
292
294 double stdErr(const size_t i) const;
295
297 double relStdErr(const size_t i) const;
298
300 double RMS(const size_t i) const;
301
303
304
306
307
309 double numEntries() const {
310 return _numEntries;
311 }
312
314 double effNumEntries() const {
315 if (_sumW2.at(0) == 0) return 0;
316 return _sumW.at(0)*_sumW.at(0) / _sumW2.at(0);
317 }
318
320 double sumW() const {
321 return _sumW.at(0);
322 }
323
325 double sumW2() const {
326 return _sumW2.at(0);
327 }
328
330 double sumW(const size_t i) const {
331 return _sumW.at(i);
332 }
333
335 double sumW2(const size_t i) const {
336 return _sumW2.at(i);
337 }
338
340 template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
341 double crossTerm(const size_t A1, const size_t A2) const {
342 if (A1 >= N || A2 >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
343 if (A1 >= A2) throw RangeError("Indices need to be different for cross term");
344
345 size_t idx = 0;
346 for (size_t i = 0; i < (N-1); ++i) {
347 for (size_t j = i+1; j < N; ++j) {
348 if (i == A1 && j == A2) break;
349 ++idx;
350 }
351 if (i == A1) break;
352 }
353
354 return _sumWcross.at(idx);
355 }
356
357 size_t dim() const { return N; }
358
360
363
365 std::string toString() const {
366 std::string res ="";
367 res += ("numEntries="+ std::to_string(_numEntries)) ;
368 if (sumW()) {
369 res += (", Mean="+ std::to_string(mean(0))) ;
370 res += (", RMS="+ std::to_string(RMS(0))) ;
371 }
372 return res;
373 }
374
376
378 // @{
379
382 template<typename... size_t>
383 DbnBase<sizeof...(size_t)> reduceTo(size_t... axes) const {
384 if constexpr (N == sizeof...(axes)) { return *this; } // keep all axes
385 else {
386 // only select the axis moments to keep (0 is sumW, 1...N are the axis moments)
387 std::array<double, sizeof...(axes)+1> newSumW = { _sumW[0], _sumW[axes+1]... };
388 std::array<double, sizeof...(axes)+1> newSumW2 = { _sumW2[0], _sumW2[axes+1]... };
389 if constexpr (sizeof...(axes) < 2) {
390 return DbnBase<sizeof...(axes)>(_numEntries, newSumW, newSumW2);
391 }
392 else {
393 constexpr auto newDim = sizeof...(axes);
394 std::array<double, newDim*(newDim-1)/2> newSumWcross;
395 unsigned int idx = 0;
396 for (unsigned int i : {axes...}) {
397 for (unsigned int j : {axes...}) {
398 if (i < j) { newSumWcross.at(idx) = crossTerm(i, j); ++idx; }
399 }
400 }
401 return DbnBase<sizeof...(axes)>(_numEntries, newSumW, newSumW2, newSumWcross);
402 }
403 }
404 }
405
407 template<size_t... Is>
408 DbnBase<sizeof...(Is)> reduceTo(std::index_sequence<Is...>) const {
409 return reduceTo(Is...);
410 }
411
414 template<size_t... axes>
415 auto reduce() const {
416 constexpr auto new_axes = AxisFilter(std::make_index_sequence<N>{},
417 [](size_t i) { return !has_match(i, std::integer_sequence<size_t, axes...>{}); }
418 );
419 return reduceTo(new_axes);
420 }
421
422 // @}
423
425
426
427 size_t _lengthContent() const noexcept {
428 return DataSize::value;
429 }
430
431 std::vector<double> _serializeContent() const noexcept {
432 std::vector<double> rtn;
433 rtn.reserve(DataSize::value);
434 rtn.insert(rtn.end(), _sumW.begin(), _sumW.end());
435 rtn.insert(rtn.end(), _sumW2.begin(), _sumW2.end());
436 rtn.insert(rtn.end(), _sumWcross.begin(), _sumWcross.end());
437 rtn.push_back(_numEntries);
438 return rtn;
439 }
440
441 void _deserializeContent(const std::vector<double>& data) {
442
443 if (data.size() != DataSize::value)
444 throw UserError("Length of serialized data should be "+std::to_string(DataSize::value)+"!");
445
446 auto itr = data.cbegin();
447 std::copy_n(itr, _sumW.size(), _sumW.begin());
448 std::copy_n(itr+N+1, _sumW2.size(), _sumW2.begin());
449 std::copy_n(itr+2*(N+1), _sumWcross.size(), _sumWcross.begin());
450 _numEntries = *(itr + 2*(N+1) + (N*(N-1)/2));
451
452 }
453
454 // @}
455
457
458
461
464
467
470
472
473 private:
474
476
477
478 double _numEntries;
479
481 std::array<double, N+1> _sumW; //indexed by dimension
482
484 std::array<double, N+1> _sumW2; //indexed by dimension
485
487 std::array<double, N*(N-1)/2> _sumWcross;
488
490
492
493
495 template <size_t... I>
496 void fill(const std::array<double, N> vals, const double weight, const double fraction,
497 std::index_sequence<I...>) {
498 fill(vals[I]..., weight, fraction);
499 }
500
502 };
503
504
505 template <size_t N>
506 double DbnBase<N>::errW() const {
507 return sqrt(sumW2(0));
508 }
509
510 template <size_t N>
511 double DbnBase<N>::relErrW() const {
512 if (effNumEntries() == 0) {
513 return std::numeric_limits<double>::quiet_NaN();
514 }
515 return errW()/sumW(0);
516 }
517
518 template <size_t N>
519 double DbnBase<N>::mean(const size_t i) const {
520 return YODA::mean(sumW(i), sumW(0));
521 }
522
523
524 template <size_t N>
525 double DbnBase<N>::variance(const size_t i) const {
526 return YODA::variance(sumW(i), sumW(0), sumW2(i), sumW2(0));
527 }
528
529
530 template <size_t N>
531 double DbnBase<N>::stdErr(const size_t i) const {
532 return YODA::stdErr(sumW(i), sumW(0), sumW2(i), sumW2(0));
533 }
534
535
536 template <size_t N>
537 double DbnBase<N>::relStdErr(const size_t i) const {
538 if (effNumEntries() == 0) {
539 return std::numeric_limits<double>::quiet_NaN();
540 }
541 return stdErr(i) / mean(i);
542 }
543
544
545 template <size_t N>
546 double DbnBase<N>::RMS(const size_t i) const {
547 return YODA::RMS(sumW2(i), sumW(0), sumW2());
548 }
549
550 template <size_t N>
552 _numEntries += d._numEntries;
553 for (size_t i = 0; i <= N; ++i) {
554 _sumW.at(i) += d._sumW.at(i);
555 _sumW2.at(i) += d._sumW2.at(i);
556 }
557 for (size_t i = 0; i < _sumWcross.size(); ++i) {
558 _sumWcross.at(i) += d._sumWcross.at(i);
559 }
560 return *this;
561 }
562
563
564 template <size_t N>
566 _numEntries += std::move(d._numEntries);
567 for (size_t i = 0; i <= N; ++i) {
568 _sumW.at(i) += std::move(d._sumW.at(i));
569 _sumW2.at(i) += std::move(d._sumW2.at(i));
570 }
571 for (size_t i = 0; i < _sumWcross.size(); ++i) {
572 _sumWcross.at(i) += std::move(d._sumWcross.at(i));
573 }
574 return *this;
575 }
576
577
578 template <size_t N>
580 _numEntries -= d._numEntries;
581 for (unsigned int i =0; i<= N ; ++i) {
582 _sumW.at(i) -= d._sumW.at(i);
583 _sumW2.at(i) += d._sumW2.at(i);
584 }
585 for (size_t i = 0; i < _sumWcross.size(); ++i) {
586 _sumWcross.at(i) -= d._sumWcross.at(i);
587 }
588 return *this;
589 }
590
591
592 template <size_t N>
594 _numEntries -= std::move(d._numEntries);
595 for (unsigned int i =0; i<= N ; ++i) {
596 _sumW.at(i) -= std::move(d._sumW.at(i));
597 _sumW2.at(i) += std::move(d._sumW2.at(i));
598 }
599 for (size_t i = 0; i < _sumWcross.size(); ++i) {
600 _sumWcross.at(i) -= std::move(d._sumWcross.at(i));
601 }
602 return *this;
603 }
604
605
607 template <size_t N>
608 inline DbnBase<N> operator + (DbnBase<N> first, const DbnBase<N>& second) {
609 first += second;
610 return first;
611 }
612
614 template <size_t N>
615 inline DbnBase<N> operator + (DbnBase<N> first, DbnBase<N>&& second) {
616 first += std::move(second);
617 return first;
618 }
619
621 template <size_t N>
622 inline DbnBase<N> operator - (DbnBase<N> first, const DbnBase<N>& second) {
623 first -= second;
624 return first;
625 }
626
628 template <size_t N>
629 inline DbnBase<N> operator - (DbnBase<N> first, DbnBase<N>&& second) {
630 first -= std::move(second);
631 return first;
632 }
633
634
636 template<size_t N>
637 class Dbn : public DbnBase<N> {
638 public:
641 using BaseT::operator=;
642
643 };
644
646 template<>
647 class Dbn<0> : public DbnBase<0> {
648 public:
649
651 using BaseT::BaseT;
652 using BaseT::operator=;
653
654 Dbn() : BaseT() {}
655
656 Dbn(const double numEntries, const double sumW, const double sumW2)
657 : BaseT(numEntries, {sumW} , {sumW2}) { }
658
659 Dbn(const BaseT& other) : BaseT(other) {}
660
661 Dbn(BaseT&& other) : BaseT(std::move(other)) {}
662
663 void fill(const std::array<double, 0>& vals, const double weight = 1.0, const double fraction = 1.0) {
664 BaseT::fill(vals, weight, fraction);
665 }
666
667 void fill(const double weight=1.0, const double fraction=1.0) { BaseT::fill({}, weight, fraction); }
668
669 void set(const double numEntries, const double sumW, const double sumW2) {
671 }
672
673 };
674
675
677 template<>
678 class Dbn<1> : public DbnBase<1>,
679 public XDbnMixin<Dbn<1>> {
680 public:
681
683 using BaseT::BaseT;
684 using BaseT::operator=;
685
686 Dbn() : BaseT() {}
687
688 Dbn(const double numEntries, const double sumW, const double sumW2, const double sumWX, const double sumWX2)
689 : BaseT(numEntries, {sumW, sumWX} , {sumW2, sumWX2}) { }
690
691 Dbn(const BaseT& other) : BaseT(other) {}
692
693 Dbn(BaseT&& other) : BaseT(std::move(other)) {}
694
695 void fill(const std::array<double, 1>& vals, const double weight = 1.0, const double fraction = 1.0) {
696 BaseT::fill(vals, weight, fraction);
697 }
698
699 void fill(const double val, const double weight=1.0, const double fraction=1.0) {
700 BaseT::fill({val}, weight, fraction);
701 }
702
703 };
704
705
707 template<>
708 class Dbn<2> : public DbnBase<2>,
709 public XDbnMixin<Dbn<2>>,
710 public YDbnMixin<Dbn<2>> {
711 public:
712
714 using BaseT::BaseT;
715 using BaseT::operator=;
716
717 Dbn() : BaseT() {}
718
719 Dbn(const double numEntries, const double sumW, const double sumW2, const double sumWX, const double sumWX2,
720 const double sumWY, const double sumWY2, const double sumWXY)
721 : BaseT(numEntries, {sumW, sumWX, sumWY} , {sumW2, sumWX2, sumWY2}, {sumWXY}) { }
722
723 Dbn(const BaseT& other) : BaseT(other) {}
724
725 Dbn(BaseT&& other) : BaseT(std::move(other)) {}
726
727 void fill(const std::array<double, 2>& vals, const double weight = 1.0, const double fraction = 1.0) {
728 BaseT::fill(vals, weight, fraction);
729 }
730
731 void fill(const double valX, const double valY, const double weight=1.0, const double fraction=1.0) {
732 BaseT::fill({valX, valY}, weight, fraction);
733 }
734
735
736 };
737
738
740 template<>
741 class Dbn<3> : public DbnBase<3>,
742 public XDbnMixin<Dbn<3>>,
743 public YDbnMixin<Dbn<3>>,
744 public ZDbnMixin<Dbn<3>> {
745 public:
746
748 using BaseT::BaseT;
749 using BaseT::operator=;
750
751 Dbn() : BaseT() {}
752
753 Dbn(const double numEntries, const double sumW, const double sumW2,
754 const double sumWX, const double sumWX2,
755 const double sumWY, const double sumWY2,
756 const double sumWZ, const double sumWZ2,
757 const double sumWXY, const double sumWXZ, const double sumWYZ)
758 : BaseT(numEntries, {sumW, sumWX, sumWY, sumWZ} , {sumW2, sumWX2, sumWY2, sumWZ2}, {sumWXY, sumWXZ, sumWYZ}) { }
759
760 Dbn(const BaseT& other) : BaseT(other) {}
761
762 Dbn(BaseT&& other) : BaseT(std::move(other)) {}
763
764 void fill(const std::array<double, 3>& vals, const double weight = 1.0, const double fraction = 1.0) {
765 BaseT::fill(vals, weight, fraction);
766 }
767
768 void fill(const double valX, const double valY, const double valZ, const double weight=1.0, const double fraction=1.0) {
769 BaseT::fill({valX, valY, valZ}, weight, fraction);
770 }
771
772 };
773
775 using Dbn0D = Dbn<0>;
776 using Dbn1D = Dbn<1>;
777 using Dbn2D = Dbn<2>;
778 using Dbn3D = Dbn<3>;
779}
780
781#endif
A 1D distribution.
Definition Dbn.h:86
DbnBase(DbnBase &&)=default
DbnBase & operator+=(const DbnBase &d)
Add two DbnBases.
Definition Dbn.h:551
double RMS(const size_t i) const
Weighted RMS, , of distribution.
Definition Dbn.h:546
DbnBase & operator=(const DbnBase &)=default
DbnBase< sizeof...(size_t)> reduceTo(size_t... axes) const
Reduce operation that produces a lower-dimensional DbnBase keeping only the specified axes in the new...
Definition Dbn.h:383
DbnBase & operator-=(const DbnBase &d)
Subtract one DbnBase from another.
Definition Dbn.h:579
DbnBase()
Default constructor of a new distribution.
Definition Dbn.h:97
void set(DbnBase< N > &&other)
Set a sample with other.
Definition Dbn.h:227
DbnBase(const DbnBase &)=default
void reset()
Reset the internal counters.
Definition Dbn.h:232
void set(const double numEntries, const std::vector< double > &sumW, const std::vector< double > &sumW2, const std::vector< double > &sumWcross={})
Set a sample with vector-based number of entries numEntries, sum of weights sumW (and corresponding m...
Definition Dbn.h:209
void set(const double numEntries, const std::array< double, N+1 > &sumW, const std::array< double, N+1 > &sumW2, const std::array< double, N *(N-1)/2 > &sumWcross)
Set a sample with array-based number of entries numEntries, sum of weights sumW (and corresponding mo...
Definition Dbn.h:197
double stdDev(const size_t i) const
Weighted standard deviation, , of distribution.
Definition Dbn.h:291
auto reduce() const
Reduce operation that produces a lower-dimensional DbnBase removing the specified axes for the new Db...
Definition Dbn.h:415
std::string toString() const
String representation of the DbnBase for debugging.
Definition Dbn.h:365
std::integral_constant< size_t, 1+2 *(N+1)+(N *(N-1)/2)> DataSize
Definition Dbn.h:91
void fill(const std::array< double, N > vals, const double weight=1.0, const double fraction=1.0)
Contribute a sample at val (from an array) with weight weight.
Definition Dbn.h:152
double errW() const
The absolute error on sumW.
Definition Dbn.h:506
double mean(const size_t i) const
Weighted mean, , of distribution.
Definition Dbn.h:519
DbnBase< sizeof...(Is)> reduceTo(std::index_sequence< Is... >) const
Same as above but using an std::integer_sequence.
Definition Dbn.h:408
double relErrW() const
The relative error on sumW.
Definition Dbn.h:511
DbnBase(const double numEntries, const std::array< double, N+1 > &sumW, const std::array< double, N+1 > &sumW2, const std::array< double, N *(N-1)/2 > &sumWcross)
Constructor to set a distribution with a pre-filled state.
Definition Dbn.h:113
double effNumEntries() const
Effective number of entries .
Definition Dbn.h:314
void set(const DbnBase< N > &other)
Set a sample with other.
Definition Dbn.h:222
size_t dim() const
Definition Dbn.h:357
void fill(Args &&... args)
Templated convenience overload of fill method.
Definition Dbn.h:162
double variance(const size_t i) const
Weighted variance, , of distribution.
Definition Dbn.h:525
double sumW(const size_t i) const
The sum of x*weight.
Definition Dbn.h:330
double sumW() const
The sum of weights.
Definition Dbn.h:320
void scaleW(const double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition Dbn.h:241
void scale(const size_t dim, const double factor)
Definition Dbn.h:254
double sumW2(const size_t i) const
The sum of x^2*weight.
Definition Dbn.h:335
double stdErr(const size_t i) const
Weighted standard error on the mean, , of distribution.
Definition Dbn.h:531
std::integral_constant< size_t, N > FillDim
Definition Dbn.h:90
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition Dbn.h:309
double crossTerm(const size_t A1, const size_t A2) const
The second-order cross term between axes k and l.
Definition Dbn.h:341
double sumW2() const
The sum of weights squared.
Definition Dbn.h:325
double relStdErr(const size_t i) const
Relative weighted standard error on the mean, , of distribution.
Definition Dbn.h:537
Partial template specialisation for Dbn0D.
Definition Dbn.h:647
void set(const double numEntries, const double sumW, const double sumW2)
Definition Dbn.h:669
void fill(const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:667
Dbn(const BaseT &other)
Definition Dbn.h:659
void fill(const std::array< double, 0 > &vals, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:663
Dbn(BaseT &&other)
Definition Dbn.h:661
Dbn(const double numEntries, const double sumW, const double sumW2)
Definition Dbn.h:656
Partial template specialisation with CRTP for x-methods.
Definition Dbn.h:679
void fill(const double val, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:699
Dbn(const BaseT &other)
Definition Dbn.h:691
void fill(const std::array< double, 1 > &vals, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:695
Dbn(const double numEntries, const double sumW, const double sumW2, const double sumWX, const double sumWX2)
Definition Dbn.h:688
Dbn(BaseT &&other)
Definition Dbn.h:693
Partial template specialisation with CRTP for x- and y-methods.
Definition Dbn.h:710
void fill(const std::array< double, 2 > &vals, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:727
void fill(const double valX, const double valY, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:731
Dbn(BaseT &&other)
Definition Dbn.h:725
Dbn(const double numEntries, const double sumW, const double sumW2, const double sumWX, const double sumWX2, const double sumWY, const double sumWY2, const double sumWXY)
Definition Dbn.h:719
Dbn(const BaseT &other)
Definition Dbn.h:723
Partial template specialisation with CRTP for x-, y- and z-methods.
Definition Dbn.h:744
Dbn(BaseT &&other)
Definition Dbn.h:762
void fill(const std::array< double, 3 > &vals, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:764
Dbn(const BaseT &other)
Definition Dbn.h:760
Dbn(const double numEntries, const double sumW, const double sumW2, const double sumWX, const double sumWX2, const double sumWY, const double sumWY2, const double sumWZ, const double sumWZ2, const double sumWXY, const double sumWXZ, const double sumWYZ)
Definition Dbn.h:753
void fill(const double valX, const double valY, const double valZ, const double weight=1.0, const double fraction=1.0)
Definition Dbn.h:768
User-facing Dbn class inheriting from DbnBase.
Definition Dbn.h:637
Error for e.g. use of invalid bin ranges.
Definition Exceptions.h:34
Error for problems introduced outside YODA, to put it nicely.
Definition Exceptions.h:100
Anonymous namespace to limit visibility.
double stdErr(const double sumWX, const double sumW, const double sumWX2, const double sumW2)
Calculate the weighted standard error of a sample.
Definition MathUtils.h:470
double RMS(const double sumWX2, const double sumW, const double sumW2)
Calculate the weighted RMS of a sample.
Definition MathUtils.h:489
BinnedDbn< DbnN, AxisT... > operator+(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Add two BinnedDbn objects.
Definition BinnedDbn.h:1060
NUM sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.h:216
BinnedDbn< DbnN, AxisT... > operator-(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Subtract one BinnedDbn object from another.
Definition BinnedDbn.h:1076
double variance(const double sumWX, const double sumW, const double sumWX2, const double sumW2)
Calculate the weighted variance of a sample.
Definition MathUtils.h:421
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition MathUtils.h:391
double effNumEntries(const double sumW, const double sumW2)
Calculate the effective number of entries of a sample.
Definition MathUtils.h:375
CRTP mixin introducing convenience aliases along X axis.
Definition DbnUtils.h:23
CRTP mixin introducing convenience aliases along Y axis.
Definition DbnUtils.h:49
CRTP mixin introducing convenience aliases along Z axis.
Definition DbnUtils.h:81