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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Aug 11 01:35:05 BST 2011


Author: buckley
Date: Thu Aug 11 01:35:04 2011
New Revision: 233

Log:
Reworking, fixing and tidying of persistency constructors and Histto2D slicing. Work still needed to clean up these classes and review the proposed API.

Modified:
   trunk/ChangeLog
   trunk/include/YODA/Bin1D.h
   trunk/include/YODA/Dbn1D.h
   trunk/include/YODA/Histo2D.h
   trunk/include/YODA/HistoBin1D.h
   trunk/include/YODA/ProfileBin1D.h
   trunk/src/Bin1D.cc
   trunk/src/HistoBin1D.cc
   trunk/src/ProfileBin1D.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/ChangeLog	Thu Aug 11 01:35:04 2011	(r233)
@@ -1,3 +1,12 @@
+2011-08-11  Andy Buckley  <andy at insectnation.org>
+
+	* Various typo fixes and comments relating to persistency
+	constructors, Histo2D slicing, etc.
+
+	* Changing the HistoBin1D state-setting constructors (aargh, these
+	should *not* have already existed) to take Dbn1D as an argument
+	rather than a long list of doubles.
+
 2011-08-01  Andy Buckley  <andy at insectnation.org>
 
 	* Adding tests to check that implicit construction of Weights

Modified: trunk/include/YODA/Bin1D.h
==============================================================================
--- trunk/include/YODA/Bin1D.h	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/include/YODA/Bin1D.h	Thu Aug 11 01:35:04 2011	(r233)
@@ -20,15 +20,18 @@
   class Bin1D : public Bin {
   public:
 
-    /// @name Constructors, giving bin low and high edges. 
+    /// @name Constructors, giving bin low and high edges.
     //@{
+
+    /// Init a new, empty bin with a pair of edges.
     Bin1D(double lowedge, double highedge);
 
-    Bin1D(std::pair<double,double> edges);
+    /// Init a new, empty bin with a pair of edges.
+    Bin1D(const std::pair<double,double>& edges);
 
-    /// A constructor for cutting along a given axis:
-    Bin1D(double lowedge, double highedge, unsigned long numFills, 
-          double sumW, double sumW2, double sumWX, double sumWX2);
+    /// @brief Init a bin with all the components of a fill history.
+    /// Mainly intended for internal persistency use.
+    Bin1D(double lowedge, double highedge, const Dbn1D& dbnx);
 
     //@}
 

Modified: trunk/include/YODA/Dbn1D.h
==============================================================================
--- trunk/include/YODA/Dbn1D.h	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/include/YODA/Dbn1D.h	Thu Aug 11 01:35:04 2011	(r233)
@@ -21,14 +21,29 @@
   /// sampled distribution. It is used to provide this information in bins
   /// and for the "hidden" \f$ y \f$ distribution in profile histogram bins.
   class Dbn1D {
-  friend class Bin1D;
   public:
 
-    /// Constructor.
+    /// @name Constructors
+    //@{
+
+    /// Default constructor of a new distribution.
     Dbn1D() {
       reset();
     }
 
+    /// @brief Constructor to set a distribution with a pre-filled state.
+    /// Principally designed for internal persistency use.
+    Dbn1D(unsigned int numEntries, double sumW, double sumW2, double sumWX, double sumWX2) {
+      _numFills = numEntries;
+      _sumW = sumW;
+      _sumW2 = sumW2;
+      _sumWX = sumWX;
+      _sumWX2 = sumWX2;
+    }
+
+    //@}
+
+
     /// @name Modifiers
     //@{
 
@@ -49,10 +64,10 @@
       _sumWX2 *= sf2;
     }
 
-    /// Rescale the edges
+    /// Rescale x: needed if histo bin edges are rescaled.
     void scaleX(double factor) {
-        _sumWX *= factor;
-        _sumWX2 *= factor*factor;
+      _sumWX *= factor;
+      _sumWX2 *= factor*factor;
     }
 
     //@}

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/include/YODA/Histo2D.h	Thu Aug 11 01:35:04 2011	(r233)
@@ -38,21 +38,20 @@
     //@{
 
     /// Constructor giving range and number of bins.
-    /// @todo Remove binning enum stuff
     Histo2D(size_t nbinsX, double lowerX, double upperX,
             size_t nbinsY, double lowerY, double upperY,
             const std::string& path="", const std::string& title="")
       : AnalysisObject("Histo2D", path, title),
-        _axis(nbinsX, lowerX, upperX,
-              nbinsY, lowerY, upperY)
+        _axis(nbinsX, lowerX, upperX, nbinsY, lowerY, upperY)
     { }
-    /* A default constructor. One needs to provide two points 
-     * (top-right and bottom-left) for each rectangular bin that 
-     * is created. It is assumed that the binedges vector is nonempty (why btw?).
-     */
-    Histo2D(const std::vector<std::pair<std::pair<double,double>, pair<double,double> > >& binedges, 
-            const std::string& path="", 
-            const std::string& title="") 
+
+    /// A default constructor. One needs to provide two points
+    /// (top-right and bottom-left) for each rectangular bin that
+    /// is created. It is assumed that the binedges vector is nonempty (why btw?).
+    /// @todo Drop the pairings -- it is more natural, less contrived, and cleaner in code as xlow/high and ylow/high
+    Histo2D(const std::vector<std::pair<std::pair<double,double>, pair<double,double> > >& binedges,
+            const std::string& path="",
+            const std::string& title="")
       : AnalysisObject("Histo2D", path, title),
       _axis(binedges)
     { }
@@ -60,8 +59,6 @@
     /// Copy constructor with optional new path
     Histo2D(const Histo2D& h, const std::string& path="");
 
-
-
     //@}
 
 
@@ -96,19 +93,19 @@
     int isGriddy() {
         return _axis.isGriddy();
     }
-    
+
     /// Rescale as if all fill weights had been different by factor @a scalefactor.
     void scaleW(double scalefactor) {
       _axis.scaleW(scalefactor);
     }
-    
+
     /// Scale the dimensions
     void scale(double scaleX = 1.0, double scaleY = 1.0) {
       _axis.scale(scaleX, scaleY);
     }
 
-    
-    //Adding bins
+
+    /// Adding bins
     void addBin(const vector<pair<pair<double,double>, pair<double,double> > > coords) {
         _axis.addBin(coords);
     }
@@ -119,6 +116,7 @@
     }
 
     //@}
+
   public:
 
     /// @name Bin accessors
@@ -187,7 +185,7 @@
     const Dbn2D& underflow() const {
         return _axis.underflow();
     }
-    
+
     /// Return underflow (non-const version)
     Dbn2D& underflow() {
         return _axis.underflow();
@@ -202,7 +200,7 @@
     Dbn2D& overflow() {
         return _axis.overflow();
     }
-   
+
     /// Return a total number of bins in Histo(non-const version)
     unsigned int numBinsTotal() {
         return _axis.numBinsTotal();
@@ -213,24 +211,27 @@
     }
 
     /// Hash returner (non-const version)
+    /// @todo This needs a typedef
     std::pair<Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > >,
               Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > > > getHash() {
         return _axis.getHash();
     }
-    
+
     /// Hash returner (const version)
+    /// @todo This needs a typedef
     const std::pair<Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > >,
                     Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > > > getHash() const {
         return _axis.getHash();
     }
     //@}
+
   public:
 
     /// @name Whole histo data
     //@{
 
-    /// Get the total area of the histogram
-    //TODO: This does not work!!
+    /// Get the total volume of the histogram
+    // @todo This does not work!! (AB: Explain what you mean!)
     double integral(bool includeoverflows=true) const {
       return sumW(includeoverflows);
     }
@@ -259,6 +260,7 @@
 
     //@}
 
+
   public:
 
     /// @name Adding and subtracting histograms
@@ -269,7 +271,7 @@
       _axis += toAdd._axis;
       return *this;
     }
-    
+
     /// Subtract another histogram from this one
     Histo2D& operator -= (const Histo2D& toSubtract) {
       _axis -= toSubtract._axis;
@@ -278,44 +280,57 @@
 
     //@}
 
-    ///Creates a Histo1D from Histo2D 
-    /** This function cuts Histo2D parallely to the X axis 
-      * at the specified Y coordinate:
-      */
-    Histo1D cutterX(double atY) {
-        if(atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid");
-        HistoBin2D first = binByCoord(lowEdgeX(), atY);
-        vector<HistoBin1D> temp;
-        temp.push_back(HistoBin1D(first.lowEdgeX(), first.highEdgeX(), first.numEntries(),
-                       first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2()));
-
-        for(double i = first.xMax() + first.widthX()/2; i < highEdgeX(); i+=first.widthX()){
-            HistoBin2D tempBin = binByCoord(i, atY);
-            temp.push_back(HistoBin1D(tempBin.lowEdgeX(), tempBin.highEdgeX(), tempBin.numEntries(),
-                           tempBin.sumW(), tempBin.sumW2(), tempBin.sumWX(), tempBin.sumWX2()));
-        }
 
-        Histo1D ret(temp);
-        return ret;
+    /// @name Slicing operators
+    //@{
+
+    /// Create a Histo1D for the bin slice parallel to the x axis at the specified y coordinate
+    /// @todo It's not really *at* the specified y coord: it's for the corresponding bin row.
+    /// @todo Checking that there is such a thing as a continuous row?
+    /// @todo Change the name!
+    Histo1D cutterX(double atY) {
+      if (atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid");
+      vector<HistoBin1D> tempBins;
+      /// @todo Make all Bin1D constructions happen in loop, to reduce code duplication
+      const HistoBin2D& first = binByCoord(lowEdgeX(), atY);
+      Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
+      tempBins.push_back(HistoBin1D(first.lowEdgeX(), first.highEdgeX(), dbn));
+      for (double i = first.xMax() + first.widthX()/2; i < highEdgeX(); i += first.widthX()) {
+        const HistoBin2D& b2 = binByCoord(i, atY);
+        Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        tempBins.push_back(HistoBin1D(b2.lowEdgeX(), b2.highEdgeX(), dbn2));
+      }
+      return Histo1D(tempBins);
     }
-    
-    Histo1D cutterY(double atX) {
-        if(atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid");
-        HistoBin2D first = binByCoord(lowEdgeX(), atX);
-        vector<HistoBin1D> temp;
-        temp.push_back(HistoBin1D(first.lowEdgeY(), first.highEdgeY(), first.numEntries(),
-                                  first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2()));
-
-        for(double i = first.yMax() + first.widthY()/2; i < highEdgeY(); i+=first.widthY()){
-            HistoBin2D tempBin = binByCoord(atX, i);
-            temp.push_back(HistoBin1D(tempBin.lowEdgeY(), tempBin.highEdgeY(), tempBin.numEntries(),
-                           tempBin.sumW(), tempBin.sumW2(), tempBin.sumWX(), tempBin.sumWX2()));
-        }
 
-        Histo1D ret(temp);
-        return ret;
+
+    /// Create a Histo1D for the bin slice parallel to the y axis at the specified x coordinate
+    /// @todo It's not really *at* the specified x coord: it's for the corresponding bin row.
+    /// @todo Checking that there is such a thing as a continuous row?
+    /// @todo Change the name!
+    Histo1D cutterY(double atX) {
+      if (atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid");
+      vector<HistoBin1D> tempBins;
+      /// @todo Make all Bin1D constructions happen in loop, to reduce code duplication
+      const HistoBin2D& first = binByCoord(atX, lowEdgeY());
+      Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
+      tempBins.push_back(HistoBin1D(first.lowEdgeY(), first.highEdgeY(), dbn));
+      for (double i = first.yMax() + first.widthY()/2; i < highEdgeY(); i += first.widthY()) {
+        const HistoBin2D& b2 = binByCoord(atX, i);
+        Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        tempBins.push_back(HistoBin1D(b2.lowEdgeY(), b2.highEdgeY(), dbn2));
+      }
+      return Histo1D(tempBins);
     }
 
+
+    /// @todo Create x-wise and y-wise conversions to Profile1D
+
+
+    //@}
+
+
+
   private:
 
     /// @name Bin data

Modified: trunk/include/YODA/HistoBin1D.h
==============================================================================
--- trunk/include/YODA/HistoBin1D.h	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/include/YODA/HistoBin1D.h	Thu Aug 11 01:35:04 2011	(r233)
@@ -20,10 +20,17 @@
 
     /// @name Constructor giving bin low and high edges.
     //@{
+
+    /// Init a new, empty bin with a pair of edges.
     HistoBin1D(double lowedge, double highedge);
-    HistoBin1D(std::pair<double,double> edges);
-    HistoBin1D(double lowedge, double highedge, unsigned long numFills,
-               double sumW, double sumW2, double sumWX, double sumWX2);
+
+    /// Init a new, empty bin with a pair of edges.
+    HistoBin1D(const std::pair<double,double>& edges);
+
+    /// @brief Init a bin with all the components of a fill history.
+    /// Mainly intended for internal persistency use.
+    HistoBin1D(double lowedge, double highedge, const Dbn1D& dbn);
+
     //@}
 
 
@@ -67,6 +74,7 @@
     }
     //@}
 
+
     /// @name Error info
     //@{
 

Modified: trunk/include/YODA/ProfileBin1D.h
==============================================================================
--- trunk/include/YODA/ProfileBin1D.h	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/include/YODA/ProfileBin1D.h	Thu Aug 11 01:35:04 2011	(r233)
@@ -28,7 +28,12 @@
     ProfileBin1D(double lowedge, double highedge);
 
     /// Constructor giving bin low and high edges as a pair.
-    ProfileBin1D(std::pair<double,double> edges);
+    ProfileBin1D(const std::pair<double,double>& edges);
+
+    /// @brief Init a profile bin with all the components of a fill history.
+    /// Mainly intended for internal persistency use.
+    ProfileBin1D(double lowedge, double highedge,
+                 const Dbn1D& dbnx, const Dbn1D& dbny);
 
     //@}
 

Modified: trunk/src/Bin1D.cc
==============================================================================
--- trunk/src/Bin1D.cc	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/src/Bin1D.cc	Thu Aug 11 01:35:04 2011	(r233)
@@ -19,21 +19,18 @@
   }
 
 
-  Bin1D::Bin1D(std::pair<double, double> edges)
+  Bin1D::Bin1D(const std::pair<double, double>& edges)
     : _edges( edges )
   {
     assert( _edges.second >= _edges.first );
   }
 
-  Bin1D::Bin1D(double lowedge, double highedge, unsigned long numFills,
-               double sumW, double sumW2, double sumWX, double sumWX2) 
-               :_edges( make_pair(lowedge, highedge) ) 
+
+  Bin1D::Bin1D(double lowedge, double highedge, const Dbn1D& dbnx)
+    : _edges( make_pair(lowedge, highedge) ),
+      _xdbn(dbnx)
   {
-    _xdbn._numFills =   numFills;
-    _xdbn._sumW =       sumW;
-    _xdbn._sumW2 =      sumW2;
-    _xdbn._sumWX =      sumWX;
-    _xdbn._sumWX2 =     sumWX2;
+    assert( _edges.second >= _edges.first );
   }
 
 

Modified: trunk/src/HistoBin1D.cc
==============================================================================
--- trunk/src/HistoBin1D.cc	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/src/HistoBin1D.cc	Thu Aug 11 01:35:04 2011	(r233)
@@ -16,13 +16,13 @@
   { }
 
 
-  HistoBin1D::HistoBin1D(std::pair<double, double> edges)
+  HistoBin1D::HistoBin1D(const std::pair<double, double>& edges)
     : Bin1D(edges)
   { }
 
-  HistoBin1D::HistoBin1D(double low, double high, unsigned long numFills, double sumW,
-                         double sumW2, double sumWX, double sumWX2)
-    : Bin1D(low, high, numFills, sumW, sumW2, sumWX, sumWX2)
+
+  HistoBin1D::HistoBin1D(double low, double high, const Dbn1D& dbn)
+    : Bin1D(low, high, dbn)
   { }
 
 

Modified: trunk/src/ProfileBin1D.cc
==============================================================================
--- trunk/src/ProfileBin1D.cc	Wed Aug 10 11:37:18 2011	(r232)
+++ trunk/src/ProfileBin1D.cc	Thu Aug 11 01:35:04 2011	(r233)
@@ -14,11 +14,18 @@
   { }
 
 
-  ProfileBin1D::ProfileBin1D(std::pair<double,double> edges)
+  ProfileBin1D::ProfileBin1D(const std::pair<double,double>& edges)
     : Bin1D(edges)
   { }
 
 
+  ProfileBin1D::ProfileBin1D(double lowedge, double highedge,
+                             const Dbn1D& dbnx, const Dbn1D& dbny)
+    : Bin1D(lowedge, highedge, dbnx),
+      _ydbn(dbny)
+  {  }
+
+
   void ProfileBin1D::fill(double x, double d, double w) {
     assert( _edges.first < _edges.second );
     assert( x >= _edges.first && x < _edges.second );


More information about the yoda-svn mailing list