[Rivet-svn] r2565 - in trunk/include: LWH Rivet/Math

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Jul 6 17:57:41 BST 2010


Author: hoeth
Date: Tue Jul  6 17:57:56 2010
New Revision: 2565

Log:
LWH shouldn't depend on Rivet.

Modified:
   trunk/include/LWH/HistogramFactory.h
   trunk/include/Rivet/Math/MathUtils.hh

Modified: trunk/include/LWH/HistogramFactory.h
==============================================================================
--- trunk/include/LWH/HistogramFactory.h	Tue Jul  6 16:19:50 2010	(r2564)
+++ trunk/include/LWH/HistogramFactory.h	Tue Jul  6 17:57:56 2010	(r2565)
@@ -10,7 +10,6 @@
 #include "DataPointSet.h"
 #include "Profile1D.h"
 #include "Tree.h"
-#include "Rivet/Math/MathUtils.hh"
 #include <string>
 #include <stdexcept>
 
@@ -629,9 +628,9 @@
     h->setTitle(path.substr(path.rfind('/') + 1));
     for (int i = 0; i < h1.ax->bins(); ++i) {
       for (int j = 0; j < h2.ax->bins(); ++j) {
-        if (!Rivet::fuzzyEquals(h1.ax->binWidth(i), h2.ax->binWidth(j)) ||
-            !Rivet::fuzzyEquals(h1.ax->binLowerEdge(i), h2.ax->binLowerEdge(j)) ||
-            !Rivet::fuzzyEquals(h1.ax->binUpperEdge(i), h2.ax->binUpperEdge(j))) {
+        if (!fuzzyEquals(h1.ax->binWidth(i), h2.ax->binWidth(j)) ||
+            !fuzzyEquals(h1.ax->binLowerEdge(i), h2.ax->binLowerEdge(j)) ||
+            !fuzzyEquals(h1.ax->binUpperEdge(i), h2.ax->binUpperEdge(j))) {
           continue;
         }
         const double binwidth = h1.ax->binWidth(i);
@@ -936,6 +935,14 @@
 
 
 private:
+  /// Compare two floating point numbers with a degree of fuzziness
+  /// expressed by the fractional @a tolerance parameter.
+  inline bool fuzzyEquals(double a, double b, double tolerance=1E-5) {
+    const double absavg = fabs(a + b)/2.0;
+    const double absdiff = fabs(a - b);
+    const bool rtn = (absavg == 0.0 && absdiff == 0.0) || absdiff/absavg < tolerance;
+    return rtn;
+  }
 
   /** Throw a suitable error. */
   template <typename T>

Modified: trunk/include/Rivet/Math/MathUtils.hh
==============================================================================
--- trunk/include/Rivet/Math/MathUtils.hh	Tue Jul  6 16:19:50 2010	(r2564)
+++ trunk/include/Rivet/Math/MathUtils.hh	Tue Jul  6 17:57:56 2010	(r2565)
@@ -3,6 +3,7 @@
 #define RIVET_MathUtils_HH
 
 #include "Rivet/Math/MathHeader.hh"
+#include <cassert>
 
 namespace Rivet {
 


More information about the Rivet-svn mailing list