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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Aug 22 12:12:17 BST 2011


Author: buckley
Date: Mon Aug 22 12:12:17 2011
New Revision: 317

Log:
Adding named division operator for Histo2D, and cleaning up Scatter3D header include chain. I had to resolve some not-really-conflicts, so please update, Michal (and use 2 space indents ;-) ).

Modified:
   trunk/include/YODA/Histo1D.h
   trunk/include/YODA/Histo2D.h
   trunk/include/YODA/Scatter2D.h
   trunk/include/YODA/Scatter3D.h
   trunk/src/Histo2D.cc
   trunk/src/Scatter3D.cc
   trunk/tests/TestPoint3D.cc

Modified: trunk/include/YODA/Histo1D.h
==============================================================================
--- trunk/include/YODA/Histo1D.h	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/include/YODA/Histo1D.h	Mon Aug 22 12:12:17 2011	(r317)
@@ -295,7 +295,7 @@
   Scatter2D divide(const Histo1D& numer, const Histo1D& denom);
 
 
-  /// Divide two histograms
+  /// Divide two histograms, with an uncorrelated error treatment
   inline Scatter2D operator / (const Histo1D& numer, const Histo1D& denom) {
     return divide(numer, denom);
   }

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/include/YODA/Histo2D.h	Mon Aug 22 12:12:17 2011	(r317)
@@ -7,13 +7,14 @@
 #define YODA_Histo2D_h
 
 #include "YODA/AnalysisObject.h"
+#include "YODA/Profile1D.h"
+#include "YODA/Histo1D.h"
+#include "YODA/Scatter3D.h"
 #include "YODA/HistoBin2D.h"
 #include "YODA/HistoBin1D.h"
 #include "YODA/Dbn2D.h"
 #include "YODA/Axis2D.h"
-#include "YODA/Profile1D.h"
 #include "YODA/Exceptions.h"
-#include "YODA/Histo1D.h"
 
 #include <vector>
 
@@ -64,8 +65,9 @@
     Histo2D(const Histo2D& h, const std::string& path="")
       : AnalysisObject("Histo2D", (path.size() == 0) ? h.path() : path, h, h.title())
     {
+      /// @todo Clean... avoid committing this sort of thing if possible!
       cout << "lsadlksdjflksdhkjf" << endl;
-      if(_axis.outflows().size() == h._axis.outflows().size()) cout << "equals" << endl;
+      if (_axis.outflows().size() == h._axis.outflows().size()) cout << "equals" << endl;
       else cout << "non" << endl;
       _axis = h._axis;
     }
@@ -309,14 +311,14 @@
     /// Note that the created histogram will not have correctly filled underflow and overflow bins.
     /// @todo It's not really *at* the specified x coord: it's for the corresponding bin row.
     /// @todo Change the name!
-    Histo1D cutterY(double atX, const std::string& path="", const std::string& title=""); 
+    Histo1D cutterY(double atX, const std::string& path="", const std::string& title="");
 
 
     /// @brief X-wise Profile1D creator from Histo2D
     Profile1D mkProfileX();
 
     /// @brief Y-wise Profile1D creator from Histo2D
-    Profile1D mkProfileY(); 
+    Profile1D mkProfileY();
     //@}
 
 
@@ -338,26 +340,47 @@
   //@{
 
   /// Add two histograms
-  inline Histo2D operator + (const Histo2D& first, const Histo2D& second) {
+  inline Histo2D add(const Histo2D& first, const Histo2D& second) {
     Histo2D tmp = first;
     tmp += second;
     return tmp;
   }
 
+
+  /// Add two histograms
+  inline Histo2D operator + (const Histo2D& first, const Histo2D& second) {
+    return add(first, second);
+  }
+
+
   /// Subtract two histograms
-  inline Histo2D operator - (const Histo2D& first, const Histo2D& second) {
+  inline Histo2D subtract(const Histo2D& first, const Histo2D& second) {
     Histo2D tmp = first;
     tmp -= second;
     return tmp;
   }
 
+
+  /// Subtract two histograms
+  inline Histo2D operator - (const Histo2D& first, const Histo2D& second) {
+    return subtract(first, second);
+  }
+
+
   /// @todo Multiply histograms?
 
+
   /// @brief Divide two histograms
   ///
   /// Keep in mind that for the following to work, two Histos must
   /// be _exactly_ the same, including the ghost bins.
-  Scatter3D operator / (const Histo2D& numer, const Histo2D& denom);
+  Scatter3D divide(const Histo2D& numer, const Histo2D& denom);
+
+
+  /// Divide two histograms, with an uncorrelated error treatment
+  inline Scatter3D operator / (const Histo2D& numer, const Histo2D& denom) {
+    return divide(numer, denom);
+  }
 
   //@}
 

Modified: trunk/include/YODA/Scatter2D.h
==============================================================================
--- trunk/include/YODA/Scatter2D.h	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/include/YODA/Scatter2D.h	Mon Aug 22 12:12:17 2011	(r317)
@@ -17,6 +17,7 @@
 namespace YODA {
 
 
+  // Forward declarations
   class Histo1D;
   class Profile1D;
 
@@ -284,6 +285,7 @@
 
     Points _points;
 
+    /// @todo Needed? Isn't this now stored on AnalysisObject?
     std::string _myaotype;
 
   };

Modified: trunk/include/YODA/Scatter3D.h
==============================================================================
--- trunk/include/YODA/Scatter3D.h	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/include/YODA/Scatter3D.h	Mon Aug 22 12:12:17 2011	(r317)
@@ -8,13 +8,15 @@
 
 #include "YODA/AnalysisObject.h"
 #include "YODA/Point3D.h"
-#include "YODA/Histo2D.h"
-
 #include <utility>
 
 namespace YODA {
 
 
+  // Forward declarations
+  class Histo2D;
+
+
   /// A very generic data type which is just a collection of 3D data points with errors
   class Scatter3D : public AnalysisObject {
   public:
@@ -207,19 +209,22 @@
     }
 
 
-  /// Equality operator
-  bool operator == (const Scatter3D& other) {
-    return _points == other._points;
-  }
+    /// Equality operator
+    bool operator == (const Scatter3D& other) {
+      return _points == other._points;
+    }
+
+    /// Non-equality operator
+    bool operator != (const Scatter3D& other) {
+      return ! operator == (other);
+    }
 
-  bool operator != (const Scatter3D& other) {
-    return ! operator == (other);
-  }
 
   private:
 
     Points _points;
 
+    /// @todo Needed? Isn't this now stored on AnalysisObject?
     std::string _myaotype;
 
   };
@@ -254,30 +259,7 @@
   //@{
 
   /// Make a Scatter3D representation of a Histo2D
-  inline Scatter3D mkScatter(const Histo2D& h) {
-    Scatter3D ret;
-    ret.setAnnotations(h.annotations());
-    ret.setAnnotation("Type", h.type());
-    for(size_t i = 0; i < h.numBinsTotal(); ++i) {
-      const HistoBin2D& bin = h.bin(i);
-
-      const double x = bin.focus().first;
-      const double y = bin.focus().second;
-
-      const double exminus = x - bin.xMin();
-      const double explus = bin.xMax() - x;
-
-      const double eyminus = y - bin.yMin();
-      const double eyplus = bin.yMax() - y;
-
-      const double z = bin.height();
-      const double ez = bin.heightErr();
-
-      ret.addPoint(x, exminus, explus, y, eyminus, eyplus, z, ez, ez);
-    }
-
-    return ret;
-  }
+  Scatter3D mkScatter(const Histo2D& h);
 
   /// Make a Scatter3D representation of a Profile2D
   /// @todo Implement!

Modified: trunk/src/Histo2D.cc
==============================================================================
--- trunk/src/Histo2D.cc	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/src/Histo2D.cc	Mon Aug 22 12:12:17 2011	(r317)
@@ -119,7 +119,7 @@
         tempBins.push_back(HistoBin1D(b2.lowEdgeY(), b2.highEdgeY(), dbn2));
       }
 
-      /// Setting under/over flows
+      // Setting under/over flows
       Dbn2D underflow;
       underflow += _axis.outflows()[1][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
 
@@ -127,7 +127,7 @@
       overflow += _axis.outflows()[5][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
       Dbn2D total = _axis.totalDbn();
 
-      /// Making sure that we rotate our distributions, as we are cutting paralell to Y axis now
+      // Making sure that we rotate our distributions, as we are cutting parallel to Y axis now
       total.flipXY();
       underflow.flipXY();
       overflow.flipXY();
@@ -135,6 +135,7 @@
       return Histo1D(tempBins, total.transformX(), underflow.transformX(), overflow.transformX(), path, title);
     }
 
+
     Profile1D Histo2D::mkProfileX() {
       if (!_axis.isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
 
@@ -206,13 +207,13 @@
       /// And constructing a profile 1D from all this data
       Profile1D ret(prof, td, underflow, overflow);
       return ret;
-
     }
-  
-  /// @todo Check how finding the correct bins works in the case of 
+
+
+  /// @todo Check how finding the correct bins works in the case of
   /// a sparse representation, and if it is decent, code it in here.
-  Scatter3D operator / (const Histo2D& numer, const Histo2D& denom) {
-    if(numer != denom) throw GridError("The two Histos are not the same!");
+  Scatter3D divide(const Histo2D& numer, const Histo2D& denom) {
+    if (numer != denom) throw GridError("The two histos are not equivalently binned!");
     Scatter3D tmp;
     for (size_t i = 0; i < numer.numBinsTotal(); ++i) {
       const HistoBin2D& b1 = numer.bin(i);

Modified: trunk/src/Scatter3D.cc
==============================================================================
--- trunk/src/Scatter3D.cc	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/src/Scatter3D.cc	Mon Aug 22 12:12:17 2011	(r317)
@@ -23,6 +23,35 @@
   }
 
 
+  //////////////////////////
+
+
+  Scatter3D mkScatter(const Histo2D& h) {
+    Scatter3D ret;
+    ret.setAnnotations(h.annotations());
+    ret.setAnnotation("Type", h.type());
+    for (size_t i = 0; i < h.numBinsTotal(); ++i) {
+      const HistoBin2D& bin = h.bin(i);
+
+      const double x = bin.focus().first;
+      const double y = bin.focus().second;
+
+      const double exminus = x - bin.xMin();
+      const double explus = bin.xMax() - x;
+
+      const double eyminus = y - bin.yMin();
+      const double eyplus = bin.yMax() - y;
+
+      const double z = bin.height();
+      const double ez = bin.heightErr();
+
+      ret.addPoint(x, exminus, explus, y, eyminus, eyplus, z, ez, ez);
+    }
+
+    return ret;
+  }
+
+
   /// Divide two scatters
   Scatter3D divide(const Scatter3D& numer, const Scatter3D& denom) {
     Scatter3D tmp;

Modified: trunk/tests/TestPoint3D.cc
==============================================================================
--- trunk/tests/TestPoint3D.cc	Mon Aug 22 11:50:43 2011	(r316)
+++ trunk/tests/TestPoint3D.cc	Mon Aug 22 12:12:17 2011	(r317)
@@ -16,40 +16,40 @@
   Point3D p2(1, 2, 3);
   cout << "Checking if everything was set correctly:" << endl;
   cout << "x = " << p2.x() << ", y = " << p2.y() << ", z = " << p2.z() << endl;
-  
-  if(!fuzzyEquals(p2.x(), 1) || !fuzzyEquals(p2.y(), 2) || !fuzzyEquals(p2.z(), 3)){
+
+  if (!fuzzyEquals(p2.x(), 1) || !fuzzyEquals(p2.y(), 2) || !fuzzyEquals(p2.z(), 3)){
     cout << "One of the coordinates  was not set correctly!" << endl;
     return -1;
   }
-  if(!fuzzyEquals(p2.xErrMinus(), p2.xErrPlus()) || 
-     !fuzzyEquals(p2.xErrPlus(), p2.yErrMinus()) ||
-     !fuzzyEquals(p2.yErrMinus(), p2.yErrPlus()) ||
-     !fuzzyEquals(p2.yErrPlus(), p2.zErrMinus()) ||
-     !fuzzyEquals(p2.zErrMinus(), p2.zErrPlus()) ||
-     !fuzzyEquals(p2.zErrPlus(), 0)) {
+  if (!fuzzyEquals(p2.xErrMinus(), p2.xErrPlus()) ||
+      !fuzzyEquals(p2.xErrPlus(), p2.yErrMinus()) ||
+      !fuzzyEquals(p2.yErrMinus(), p2.yErrPlus()) ||
+      !fuzzyEquals(p2.yErrPlus(), p2.zErrMinus()) ||
+      !fuzzyEquals(p2.zErrMinus(), p2.zErrPlus()) ||
+      !fuzzyEquals(p2.zErrPlus(), 0)) {
     cout << "Errors were not set correctly!" << endl;
     return -1;
-}
+  }
 
   cout << "Creating a Point3D (constructor with explicit assymetric errors)" << endl;
   Point3D p3(1, 2, 3, 1, 2, 1, 2, 1, 2);
-  
+
   cout << "Checking if everything was set correctly:" << endl;
   cout << "x = " << p3.x() << ", y = " << p3.y() << ", z = " << p3.z() << endl;
 
-  if(!fuzzyEquals(p3.x(), 1) || !fuzzyEquals(p3.y(), 2) || !fuzzyEquals(p3.z(), 3)){
+  if (!fuzzyEquals(p3.x(), 1) || !fuzzyEquals(p3.y(), 2) || !fuzzyEquals(p3.z(), 3)){
     cout << "One of the coordinates  was not set correctly!" << endl;
     return -1;
   }
-  if(!fuzzyEquals(p3.xErrMinus(), 1) || 
-     !fuzzyEquals(p3.xErrPlus(), 2) ||
-     !fuzzyEquals(p3.yErrMinus(), 1) ||
-     !fuzzyEquals(p3.yErrPlus(), 2) ||
-     !fuzzyEquals(p3.zErrMinus(), 1) ||
-     !fuzzyEquals(p3.zErrPlus(), 2)) {
+  if (!fuzzyEquals(p3.xErrMinus(), 1) ||
+      !fuzzyEquals(p3.xErrPlus(), 2) ||
+      !fuzzyEquals(p3.yErrMinus(), 1) ||
+      !fuzzyEquals(p3.yErrPlus(), 2) ||
+      !fuzzyEquals(p3.zErrMinus(), 1) ||
+      !fuzzyEquals(p3.zErrPlus(), 2)) {
     cout << "Errors were not set correctly!" << endl;
     return -1;
-}
+  }
 
   cout << "Creating a Point3D (constructor with assymetric, std::pair errrors)" << endl;
   pair<double, double> err = make_pair(1, 2);
@@ -58,31 +58,28 @@
   cout << "Checking if everything was set correctly:" << endl;
   cout << "x = " << p4.x() << ", y = " << p4.y() << ", z = " << p4.z() << endl;
 
-  if(!fuzzyEquals(p4.x(), 1) || !fuzzyEquals(p4.y(), 2) || !fuzzyEquals(p4.z(), 3)){
+  if (!fuzzyEquals(p4.x(), 1) || !fuzzyEquals(p4.y(), 2) || !fuzzyEquals(p4.z(), 3)){
     cout << "One of the coordinates  was not set correctly!" << endl;
     return -1;
   }
-  if(!fuzzyEquals(p4.xErrMinus(), 1) || 
-     !fuzzyEquals(p4.xErrPlus(), 2) ||
-     !fuzzyEquals(p4.yErrMinus(), 1) ||
-     !fuzzyEquals(p4.yErrPlus(), 2) ||
-     !fuzzyEquals(p4.zErrMinus(), 1) ||
-     !fuzzyEquals(p4.zErrPlus(), 2)) {
+  if (!fuzzyEquals(p4.xErrMinus(), 1) ||
+      !fuzzyEquals(p4.xErrPlus(), 2) ||
+      !fuzzyEquals(p4.yErrMinus(), 1) ||
+      !fuzzyEquals(p4.yErrPlus(), 2) ||
+      !fuzzyEquals(p4.zErrMinus(), 1) ||
+      !fuzzyEquals(p4.zErrPlus(), 2)) {
     cout << "Errors were not set correctly!" << endl;
     return -1;
-
-}
+  }
 
   cout << "And a quick performance check: " << endl;
   struct timeval startTime;
   struct timeval endTime;
 
-  size_t num = 100000;
-  Point3D points[num];
+  const size_t num = 100000;
   gettimeofday(&startTime, NULL);
-  for(size_t i = 0; i < num; i++) points[i] =  Point3D(1, 1, 1, 1, 2, 1, 2, 1, 2);
+  vector<Point3D> points(num, Point3D(1, 1, 1, 1, 2, 1, 2, 1, 2));
   gettimeofday(&endTime, NULL);
-
   double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
   double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
   cout << "Time to make 100k Points3D is: " << tE - tS << "s" << endl;


More information about the yoda-svn mailing list