|
[yoda-svn] r406 - in trunk: . include/YODA srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Dec 6 15:26:06 GMT 2011
Author: buckley Date: Tue Dec 6 15:26:05 2011 New Revision: 406 Log: Adding a (weighted) RMS calculating method to Dbn1D. Modified: trunk/ChangeLog trunk/include/YODA/Dbn1D.h trunk/src/Dbn1D.cc Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Tue Nov 8 02:29:58 2011 (r405) +++ trunk/ChangeLog Tue Dec 6 15:26:05 2011 (r406) @@ -1,5 +1,9 @@ +2011-12-06 Andy Buckley <andy.buckley at cern.ch> + + * Adding a (weighted) RMS calculating method to Dbn1D. + 2011-09-03 Dave Mallows <dave.mallows at gmail.com> - + * Fixed ReaderAIDA: x-value and low y-error interchanged when filling Scatter2D. Modified: trunk/include/YODA/Dbn1D.h ============================================================================== --- trunk/include/YODA/Dbn1D.h Tue Nov 8 02:29:58 2011 (r405) +++ trunk/include/YODA/Dbn1D.h Tue Dec 6 15:26:05 2011 (r406) @@ -134,6 +134,12 @@ /// Synonym for interface compatibility with Dbn2D double xStdErr() const { return stdErr(); } + + /// Weighted RMS, \f$ \sqrt{ 1/N_\text{eff} \sum_i w_i x^2_i } \f$, of distribution. + double rms() const; + /// Synonym for interface compatibility with Dbn2D + double xRms() const { return rms(); } + //@} Modified: trunk/src/Dbn1D.cc ============================================================================== --- trunk/src/Dbn1D.cc Tue Nov 8 02:29:58 2011 (r405) +++ trunk/src/Dbn1D.cc Tue Dec 6 15:26:05 2011 (r406) @@ -32,7 +32,7 @@ // Weighted variance defined as // sig2 = ( sum(wx**2) * sum(w) - sum(wx)**2 ) / ( sum(w)**2 - sum(w**2) ) // see http://en.wikipedia.org/wiki/Weighted_mean - if (isZero(effNumEntries(), 0.0)) { + if (effNumEntries() == 0) { throw LowStatsError("Requested width of a distribution with no net fill weights"); } else if (fuzzyLessEquals(effNumEntries(), 1.0)) { throw LowStatsError("Requested width of a distribution with only one effective entry"); @@ -43,7 +43,7 @@ throw WeightError("Undefined weighted variance"); } /// @todo Isn't this sensitive to the overall scale of the weights? - /// Shouldn't it check if den is bigger then num by a set number of + /// Shouldn't it check if den is bigger then num by a set number of /// orders of magnitude and vice versa? if (fabs(num) < 1E-10 && fabs(den) < 1E-10) { throw WeightError("Numerically unstable weights in width calculation"); @@ -63,6 +63,17 @@ } + double Dbn1D::rms() const { + // Weighted RMS defined as + // rms = \sqrt{ 1/N_eff \sum_i w_i x^2_i } + if (effNumEntries() == 0) { + throw LowStatsError("Requested RMS of a distribution with no net fill weights"); + } + const double meansq = sumWX2() / effNumEntries(); + return std::sqrt(meansq); + } + + Dbn1D& Dbn1D::add(const Dbn1D& d) { _numFills += d._numFills; _sumW += d._sumW;
More information about the yoda-svn mailing list |