[yoda-svn] r473 - in trunk: include/YODA src

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Jul 2 16:19:37 BST 2012


Author: hoeth
Date: Mon Jul  2 16:19:37 2012
New Revision: 473

Log:
sanity checks for low statistics and catching some exceptions when booking a Scatter2D from a low-stat histogram or profile

Modified:
   trunk/include/YODA/Dbn1D.h
   trunk/src/Dbn1D.cc
   trunk/src/Scatter2D.cc

Modified: trunk/include/YODA/Dbn1D.h
==============================================================================
--- trunk/include/YODA/Dbn1D.h	Mon Jul  2 14:52:32 2012	(r472)
+++ trunk/include/YODA/Dbn1D.h	Mon Jul  2 16:19:37 2012	(r473)
@@ -7,6 +7,7 @@
 #define YODA_Dbn1D_h
 
 #include "YODA/Exceptions.h"
+#include "YODA/Utils/MathUtils.h"
 #include <cmath>
 
 namespace YODA {
@@ -146,6 +147,7 @@
 
     /// Effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$
     double effNumEntries() const {
+      if (isZero(_sumW2)) return 0;
       return _sumW*_sumW / _sumW2;
     }
 

Modified: trunk/src/Dbn1D.cc
==============================================================================
--- trunk/src/Dbn1D.cc	Mon Jul  2 14:52:32 2012	(r472)
+++ trunk/src/Dbn1D.cc	Mon Jul  2 16:19:37 2012	(r473)
@@ -4,7 +4,6 @@
 // Copyright (C) 2008-2012 The YODA collaboration (see AUTHORS for details)
 //
 #include "YODA/Dbn1D.h"
-#include "YODA/Utils/MathUtils.h"
 
 namespace YODA {
 
@@ -20,7 +19,7 @@
 
 
   double Dbn1D::mean() const {
-    if (isZero(effNumEntries(), 0.0)) {
+    if (effNumEntries() == 0) {
       throw LowStatsError("Requested mean of a distribution with no net fill weights");
     }
     // This is ok, even for negative sum(w)
@@ -39,7 +38,7 @@
     }
     const double num = _sumWX2*_sumW - _sumWX*_sumWX;
     const double den = _sumW*_sumW - _sumW2;
-    if (den == 0) {
+    if (isZero(den)) {
       throw WeightError("Undefined weighted variance");
     }
     /// @todo Isn't this sensitive to the overall scale of the weights?

Modified: trunk/src/Scatter2D.cc
==============================================================================
--- trunk/src/Scatter2D.cc	Mon Jul  2 14:52:32 2012	(r472)
+++ trunk/src/Scatter2D.cc	Mon Jul  2 16:19:37 2012	(r473)
@@ -33,8 +33,18 @@
       const double x = b.focus();
       const double ex_m = b.focus() - b.lowEdge();
       const double ex_p = b.highEdge() - b.focus();
-      const double y = b.mean();
-      const double ey = b.stdErr();
+      double y;
+      try {
+        y = b.mean();
+      } catch (const LowStatsError& lse) {
+        y = 0.0;
+      }
+      double ey;
+      try {
+        ey = b.stdErr();
+      } catch (const LowStatsError& lse) {
+        ey = 0.0;
+      }
       const Point2D pt(x, y, ex_m, ex_p, ey, ey);
       rtn.addPoint(pt);
     }


More information about the yoda-svn mailing list