yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
YODA::DbnBase< N > Class Template Reference

A 1D distribution. More...

#include <Dbn.h>

Inheritance diagram for YODA::DbnBase< N >:
YODA::Dbn< DbnN > YODA::Dbn< N >

Public Types

using BaseT = DbnBase< N >
 
using FillDim = std::integral_constant< size_t, N >
 
using DataSize = std::integral_constant< size_t, 1+2 *(N+1)+(N *(N-1)/2)>
 

Public Member Functions

Constructors
 DbnBase ()
 Default constructor of a new distribution.
 
template<size_t dim = N, typename = std::enable_if_t<(dim < 2)>>
 DbnBase (const double numEntries, const std::array< double, N+1 > &sumW, const std::array< double, N+1 > &sumW2)
 Constructor to set a distribution with a pre-filled state.
 
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
 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.
 
 DbnBase (const DbnBase &)=default
 
 DbnBase (DbnBase &&)=default
 
DbnBaseoperator= (const DbnBase &)=default
 
DbnBaseoperator= (DbnBase &&)=default
 
Modifiers
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.
 
template<typename... Args>
void fill (Args &&... args)
 Templated convenience overload of fill method.
 
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 moments), sum of squared weights sumW2 (and corresponding moments).
 
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 moments), sum of squared weights sumW2 (and corresponding moments).
 
void set (const DbnBase< N > &other)
 Set a sample with other.
 
void set (DbnBase< N > &&other)
 Set a sample with other.
 
void reset ()
 Reset the internal counters.
 
void scaleW (const double scalefactor)
 Rescale as if all fill weights had been different by factor scalefactor.
 
void scale (const size_t dim, const double factor)
 
Distribution statistics
double errW () const
 The absolute error on sumW.
 
double relErrW () const
 The relative error on sumW.
 
double mean (const size_t i) const
 Weighted mean, $ \bar{x} $, of distribution.
 
double variance (const size_t i) const
 Weighted variance, $ \sigma^2 $, of distribution.
 
double stdDev (const size_t i) const
 Weighted standard deviation, $ \sigma $, of distribution.
 
double stdErr (const size_t i) const
 Weighted standard error on the mean, $ \sim \sigma/\sqrt{N-1} $, of distribution.
 
double relStdErr (const size_t i) const
 Relative weighted standard error on the mean, $ \sim \sigma/\sqrt{N-1} $, of distribution.
 
double RMS (const size_t i) const
 Weighted RMS, $ \sqrt{ \sum{w x^2}/\sum{w} } $, of distribution.
 
Raw distribution running sums
double numEntries () const
 Number of entries (number of times fill was called, ignoring weights)
 
double effNumEntries () const
 Effective number of entries $ = (\sum w)^2 / \sum w^2 $.
 
double sumW () const
 The sum of weights.
 
double sumW2 () const
 The sum of weights squared.
 
double sumW (const size_t i) const
 The sum of x*weight.
 
double sumW2 (const size_t i) const
 The sum of x^2*weight.
 
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
double crossTerm (const size_t A1, const size_t A2) const
 The second-order cross term between axes k and l.
 
size_t dim () const
 
I/O
std::string toString () const
 String representation of the DbnBase for debugging.
 
Reduce operations
template<typename... size_t>
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 DbnBase.
 
template<size_t... Is>
DbnBase< sizeof...(Is)> reduceTo (std::index_sequence< Is... >) const
 Same as above but using an std::integer_sequence.
 
template<size_t... axes>
auto reduce () const
 Reduce operation that produces a lower-dimensional DbnBase removing the specified axes for the new DbnBase.
 
Operators
DbnBaseoperator+= (const DbnBase &d)
 Add two DbnBases.
 
DbnBaseoperator+= (DbnBase &&d)
 Add two DbnBases.
 
DbnBaseoperator-= (const DbnBase &d)
 Subtract one DbnBase from another.
 
DbnBaseoperator-= (DbnBase &&d)
 Subtract one DbnBase from another.
 

Detailed Description

template<size_t N>
class YODA::DbnBase< N >

A 1D distribution.

This class is used internally by YODA to centralise the calculation of statistics of unbounded, unbinned sampled distributions. Each distribution fill contributes a weight, $ w $, and a value, $ x $. By storing the total number of fills (ignoring weights), $ \sum w $, $ \sum w^2
$, $ \sum wx $, and $ \sum wx^2 $, the Dbn can calculate the mean and spread ( $ \sigma^2 $, $ \sigma $ and $ \hat{\sigma}
$) of the sampled distribution. It is used to provide this information in bins and for the "hidden" $ y $ distribution in profile histogram bins.

Definition at line 86 of file Dbn.h.

Member Typedef Documentation

◆ BaseT

template<size_t N>
using YODA::DbnBase< N >::BaseT = DbnBase<N>

Definition at line 89 of file Dbn.h.

◆ DataSize

template<size_t N>
using YODA::DbnBase< N >::DataSize = std::integral_constant<size_t, 1 + 2*(N+1) + (N*(N-1)/2)>

Definition at line 91 of file Dbn.h.

◆ FillDim

template<size_t N>
using YODA::DbnBase< N >::FillDim = std::integral_constant<size_t, N>

Definition at line 90 of file Dbn.h.

Constructor & Destructor Documentation

◆ DbnBase() [1/5]

template<size_t N>
YODA::DbnBase< N >::DbnBase ( )
inline

Default constructor of a new distribution.

Definition at line 97 of file Dbn.h.

97{ reset(); }
void reset()
Reset the internal counters.
Definition Dbn.h:232

References YODA::DbnBase< N >::reset().

◆ DbnBase() [2/5]

template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim < 2)>>
YODA::DbnBase< N >::DbnBase ( const double  numEntries,
const std::array< double, N+1 > &  sumW,
const std::array< double, N+1 > &  sumW2 
)
inline

Constructor to set a distribution with a pre-filled state.

Principally designed for internal persistency use.

Note
No cross-term possible for 0- and 1D.

Definition at line 105 of file Dbn.h.

106 : _numEntries(numEntries), _sumW(sumW), _sumW2(sumW2) { }
double sumW() const
The sum of weights.
Definition Dbn.h:320
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition Dbn.h:309
double sumW2() const
The sum of weights squared.
Definition Dbn.h:325

◆ DbnBase() [3/5]

template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
YODA::DbnBase< N >::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 
)
inline

Constructor to set a distribution with a pre-filled state.

Principally designed for internal persistency use.

Note
Includes second-order cross-terms.

Definition at line 113 of file Dbn.h.

115 : _numEntries(numEntries), _sumW(sumW), _sumW2(sumW2), _sumWcross(sumWcross) { }

◆ DbnBase() [4/5]

template<size_t N>
YODA::DbnBase< N >::DbnBase ( const DbnBase< N > &  )
default

Copy constructor

Sets all the parameters using the ones provided from an existing DbnBase.

◆ DbnBase() [5/5]

template<size_t N>
YODA::DbnBase< N >::DbnBase ( DbnBase< N > &&  )
default

Move constructor

Sets all the parameters using the ones provided from an existing DbnBase.

Member Function Documentation

◆ crossTerm()

template<size_t N>
template<size_t dim = N, typename = std::enable_if_t<(dim >= 2)>>
double YODA::DbnBase< N >::crossTerm ( const size_t  A1,
const size_t  A2 
) const
inline

The second-order cross term between axes k and l.

Definition at line 341 of file Dbn.h.

341 {
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 }

Referenced by YODA::DbnBase< N >::reduceTo().

◆ dim()

template<size_t N>
size_t YODA::DbnBase< N >::dim ( ) const
inline

Definition at line 357 of file Dbn.h.

357{ return N; }

Referenced by YODA::DbnBase< N >::scale().

◆ effNumEntries()

template<size_t N>
double YODA::DbnBase< N >::effNumEntries ( ) const
inline

Effective number of entries $ = (\sum w)^2 / \sum w^2 $.

Definition at line 314 of file Dbn.h.

314 {
315 if (_sumW2.at(0) == 0) return 0;
316 return _sumW.at(0)*_sumW.at(0) / _sumW2.at(0);
317 }

◆ errW()

template<size_t N>
double YODA::DbnBase< N >::errW ( ) const

The absolute error on sumW.

Definition at line 506 of file Dbn.h.

506 {
507 return sqrt(sumW2(0));
508 }

◆ fill() [1/2]

template<size_t N>
template<typename... Args>
void YODA::DbnBase< N >::fill ( Args &&...  args)
inline

Templated convenience overload of fill method.

Example:

fill(3.0, 2.1, 3.4, 3.0) // To fill value (X=3.0,Y=2.1,Z=3.0) with weight 3.0

Definition at line 162 of file Dbn.h.

162 {
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 }
NUM sqr(NUM a)
Named number-type squaring operation.
Definition MathUtils.h:216

References YODA::sqr().

◆ fill() [2/2]

template<size_t N>
void YODA::DbnBase< N >::fill ( const std::array< double, N >  vals,
const double  weight = 1.0,
const double  fraction = 1.0 
)
inline

Contribute a sample at val (from an array) with weight weight.

If you use brace enclosed initializer list and call this method in this way: fill({1,2,3}, 2, 3) and get error from compiler with this note: "no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::array<double, 0>’", it likely means that your value dimension doesn't match distribution's.

Definition at line 152 of file Dbn.h.

152 {
153 fill(vals, weight, fraction, std::make_index_sequence<N>{});
154 }
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

References YODA::DbnBase< N >::fill().

Referenced by YODA::Dbn< 1 >::fill(), YODA::Dbn< 3 >::fill(), YODA::Dbn< 2 >::fill(), YODA::Dbn< 0 >::fill(), YODA::Dbn< 0 >::fill(), YODA::Dbn< 1 >::fill(), YODA::Dbn< 2 >::fill(), YODA::Dbn< 3 >::fill(), and YODA::DbnBase< N >::fill().

◆ mean()

template<size_t N>
double YODA::DbnBase< N >::mean ( const size_t  i) const

Weighted mean, $ \bar{x} $, of distribution.

Definition at line 519 of file Dbn.h.

519 {
520 return YODA::mean(sumW(i), sumW(0));
521 }
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition MathUtils.h:391

References YODA::mean().

Referenced by YODA::DbnStorage< DbnN, AxisT >::mean(), and YODA::DbnBase< N >::toString().

◆ numEntries()

template<size_t N>
double YODA::DbnBase< N >::numEntries ( ) const
inline

Number of entries (number of times fill was called, ignoring weights)

Definition at line 309 of file Dbn.h.

309 {
310 return _numEntries;
311 }

Referenced by YODA::Dbn< 0 >::set(), and YODA::DbnBase< N >::set().

◆ operator+=() [1/2]

template<size_t N>
DbnBase< N > & YODA::DbnBase< N >::operator+= ( const DbnBase< N > &  d)

Add two DbnBases.

Definition at line 551 of file Dbn.h.

551 {
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 }

◆ operator+=() [2/2]

template<size_t N>
DbnBase< N > & YODA::DbnBase< N >::operator+= ( DbnBase< N > &&  d)

Add two DbnBases.

Definition at line 565 of file Dbn.h.

565 {
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 }

◆ operator-=() [1/2]

template<size_t N>
DbnBase< N > & YODA::DbnBase< N >::operator-= ( const DbnBase< N > &  d)

Subtract one DbnBase from another.

Definition at line 579 of file Dbn.h.

579 {
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 }

◆ operator-=() [2/2]

template<size_t N>
DbnBase< N > & YODA::DbnBase< N >::operator-= ( DbnBase< N > &&  d)

Subtract one DbnBase from another.

Definition at line 593 of file Dbn.h.

593 {
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 }

◆ operator=() [1/2]

template<size_t N>
DbnBase & YODA::DbnBase< N >::operator= ( const DbnBase< N > &  )
default

Copy assignment

Sets all the parameters using the ones provided from an existing DbnBase.

◆ operator=() [2/2]

template<size_t N>
DbnBase & YODA::DbnBase< N >::operator= ( DbnBase< N > &&  )
default

Move assignment

Sets all the parameters using the ones provided from an existing DbnBase.

◆ reduce()

template<size_t N>
template<size_t... axes>
auto YODA::DbnBase< N >::reduce ( ) const
inline

Reduce operation that produces a lower-dimensional DbnBase removing the specified axes for the new DbnBase.

Definition at line 415 of file Dbn.h.

415 {
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 }
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

References YODA::DbnBase< N >::reduceTo().

◆ reduceTo() [1/2]

template<size_t N>
template<typename... size_t>
DbnBase< sizeof...(size_t)> YODA::DbnBase< N >::reduceTo ( size_t...  axes) const
inline

Reduce operation that produces a lower-dimensional DbnBase keeping only the specified axes in the new DbnBase.

Definition at line 383 of file Dbn.h.

383 {
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 }
DbnBase()
Default constructor of a new distribution.
Definition Dbn.h:97
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

References YODA::DbnBase< N >::crossTerm().

Referenced by YODA::DbnBase< N >::reduce(), and YODA::DbnBase< N >::reduceTo().

◆ reduceTo() [2/2]

template<size_t N>
template<size_t... Is>
DbnBase< sizeof...(Is)> YODA::DbnBase< N >::reduceTo ( std::index_sequence< Is... >  ) const
inline

Same as above but using an std::integer_sequence.

Definition at line 408 of file Dbn.h.

408 {
409 return reduceTo(Is...);
410 }

References YODA::DbnBase< N >::reduceTo().

◆ relErrW()

template<size_t N>
double YODA::DbnBase< N >::relErrW ( ) const

The relative error on sumW.

Definition at line 511 of file Dbn.h.

511 {
512 if (effNumEntries() == 0) {
513 return std::numeric_limits<double>::quiet_NaN();
514 }
515 return errW()/sumW(0);
516 }
double errW() const
The absolute error on sumW.
Definition Dbn.h:506
double effNumEntries() const
Effective number of entries .
Definition Dbn.h:314

References YODA::effNumEntries().

◆ relStdErr()

template<size_t N>
double YODA::DbnBase< N >::relStdErr ( const size_t  i) const

Relative weighted standard error on the mean, $ \sim \sigma/\sqrt{N-1} $, of distribution.

Definition at line 537 of file Dbn.h.

537 {
538 if (effNumEntries() == 0) {
539 return std::numeric_limits<double>::quiet_NaN();
540 }
541 return stdErr(i) / mean(i);
542 }
double mean(const size_t i) const
Weighted mean, , of distribution.
Definition Dbn.h:519
double stdErr(const size_t i) const
Weighted standard error on the mean, , of distribution.
Definition Dbn.h:531

References YODA::effNumEntries(), YODA::mean(), and YODA::stdErr().

◆ reset()

template<size_t N>
void YODA::DbnBase< N >::reset ( )
inline

Reset the internal counters.

Definition at line 232 of file Dbn.h.

232 {
233 _numEntries= 0;
234 _sumW.fill(0);
235 _sumW2.fill(0);
236 _sumWcross.fill(0);
237 }

Referenced by YODA::DbnBase< N >::DbnBase().

◆ RMS()

template<size_t N>
double YODA::DbnBase< N >::RMS ( const size_t  i) const

Weighted RMS, $ \sqrt{ \sum{w x^2}/\sum{w} } $, of distribution.

Definition at line 546 of file Dbn.h.

546 {
547 return YODA::RMS(sumW2(i), sumW(0), sumW2());
548 }
double RMS(const double sumWX2, const double sumW, const double sumW2)
Calculate the weighted RMS of a sample.
Definition MathUtils.h:489

References YODA::RMS().

Referenced by YODA::DbnStorage< DbnN, AxisT >::rms(), and YODA::DbnBase< N >::toString().

◆ scale()

template<size_t N>
void YODA::DbnBase< N >::scale ( const size_t  dim,
const double  factor 
)
inline

Definition at line 254 of file Dbn.h.

254 {
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 }
size_t dim() const
Definition Dbn.h:357

References YODA::DbnBase< N >::dim(), and YODA::sqr().

◆ scaleW()

template<size_t N>
void YODA::DbnBase< N >::scaleW ( const double  scalefactor)
inline

Rescale as if all fill weights had been different by factor scalefactor.

Definition at line 241 of file Dbn.h.

241 {
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 }

References YODA::sqr().

◆ set() [1/4]

template<size_t N>
void YODA::DbnBase< N >::set ( const DbnBase< N > &  other)
inline

Set a sample with other.

Definition at line 222 of file Dbn.h.

222 {
223 if (this != &other) *this = other;
224 }

◆ set() [2/4]

template<size_t N>
void YODA::DbnBase< N >::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 
)
inline

Set a sample with array-based number of entries numEntries, sum of weights sumW (and corresponding moments), sum of squared weights sumW2 (and corresponding moments).

Definition at line 197 of file Dbn.h.

199 {
200 _numEntries = numEntries;
201 _sumW = sumW;
202 _sumW2 = sumW2;
203 _sumWcross = sumWcross;
204 }

References YODA::DbnBase< N >::numEntries(), YODA::DbnBase< N >::sumW(), and YODA::DbnBase< N >::sumW2().

Referenced by YODA::Dbn< 0 >::set().

◆ set() [3/4]

template<size_t N>
void YODA::DbnBase< N >::set ( const double  numEntries,
const std::vector< double > &  sumW,
const std::vector< double > &  sumW2,
const std::vector< double > &  sumWcross = {} 
)
inline

Set a sample with vector-based number of entries numEntries, sum of weights sumW (and corresponding moments), sum of squared weights sumW2 (and corresponding moments).

Definition at line 209 of file Dbn.h.

211 {}) {
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 }

◆ set() [4/4]

template<size_t N>
void YODA::DbnBase< N >::set ( DbnBase< N > &&  other)
inline

Set a sample with other.

Definition at line 227 of file Dbn.h.

227 {
228 if (this != &other) *this = std::move(other);
229 }

◆ stdDev()

template<size_t N>
double YODA::DbnBase< N >::stdDev ( const size_t  i) const
inline

Weighted standard deviation, $ \sigma $, of distribution.

Definition at line 291 of file Dbn.h.

291{ return std::sqrt(variance(i)); }
double variance(const size_t i) const
Weighted variance, , of distribution.
Definition Dbn.h:525

References YODA::DbnBase< N >::variance().

◆ stdErr()

template<size_t N>
double YODA::DbnBase< N >::stdErr ( const size_t  i) const

Weighted standard error on the mean, $ \sim \sigma/\sqrt{N-1} $, of distribution.

Definition at line 531 of file Dbn.h.

531 {
532 return YODA::stdErr(sumW(i), sumW(0), sumW2(i), sumW2(0));
533 }
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

References YODA::stdErr().

Referenced by YODA::DbnStorage< DbnN, AxisT >::stdErr().

◆ sumW() [1/2]

template<size_t N>
double YODA::DbnBase< N >::sumW ( ) const
inline

The sum of weights.

Definition at line 320 of file Dbn.h.

320 {
321 return _sumW.at(0);
322 }

Referenced by YODA::Dbn< 0 >::Dbn(), YODA::Dbn< 1 >::Dbn(), YODA::Dbn< 2 >::Dbn(), YODA::Dbn< 3 >::Dbn(), YODA::Dbn< 0 >::set(), YODA::DbnBase< N >::set(), and YODA::DbnBase< N >::toString().

◆ sumW() [2/2]

template<size_t N>
double YODA::DbnBase< N >::sumW ( const size_t  i) const
inline

The sum of x*weight.

Definition at line 330 of file Dbn.h.

330 {
331 return _sumW.at(i);
332 }

◆ sumW2() [1/2]

template<size_t N>
double YODA::DbnBase< N >::sumW2 ( ) const
inline

The sum of weights squared.

Definition at line 325 of file Dbn.h.

325 {
326 return _sumW2.at(0);
327 }

Referenced by YODA::Dbn< 0 >::set(), and YODA::DbnBase< N >::set().

◆ sumW2() [2/2]

template<size_t N>
double YODA::DbnBase< N >::sumW2 ( const size_t  i) const
inline

The sum of x^2*weight.

Definition at line 335 of file Dbn.h.

335 {
336 return _sumW2.at(i);
337 }

◆ toString()

template<size_t N>
std::string YODA::DbnBase< N >::toString ( ) const
inline

String representation of the DbnBase for debugging.

Definition at line 365 of file Dbn.h.

365 {
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 }
double RMS(const size_t i) const
Weighted RMS, , of distribution.
Definition Dbn.h:546

References YODA::DbnBase< N >::mean(), YODA::DbnBase< N >::RMS(), and YODA::DbnBase< N >::sumW().

◆ variance()

template<size_t N>
double YODA::DbnBase< N >::variance ( const size_t  i) const

Weighted variance, $ \sigma^2 $, of distribution.

Definition at line 525 of file Dbn.h.

525 {
526 return YODA::variance(sumW(i), sumW(0), sumW2(i), sumW2(0));
527 }
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

References YODA::variance().

Referenced by YODA::DbnBase< N >::stdDev(), and YODA::DbnStorage< DbnN, AxisT >::variance().


The documentation for this class was generated from the following file: