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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Aug 22 09:56:11 BST 2011


Author: buckley
Date: Mon Aug 22 09:56:10 2011
New Revision: 305

Log:
Reworking the Bin1D inheritance and composition design so that all bin types store a single distribution object -- a Dbn1D for histo bins and a Dbn2D for profile bins.

Modified:
   trunk/ChangeLog
   trunk/TODO
   trunk/include/YODA/Bin1D.h
   trunk/include/YODA/Dbn1D.h
   trunk/include/YODA/Dbn2D.h
   trunk/include/YODA/HistoBin1D.h
   trunk/include/YODA/HistoBin2D.h
   trunk/include/YODA/ProfileBin1D.h
   trunk/include/YODA/Scatter2D.h
   trunk/include/YODA/Scatter3D.h
   trunk/src/Histo1D.cc
   trunk/src/Scatter2D.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/ChangeLog	Mon Aug 22 09:56:10 2011	(r305)
@@ -1,3 +1,9 @@
+2011-08-22  Andy Buckley  <andy at insectnation.org>
+
+	* Reworking the Bin1D inheritance and composition design so that
+	all bin types store a single distribution object -- a Dbn1D for
+	histo bins and a Dbn2D for profile bins.
+
 2011-08-18  Andy Buckley  <andy at insectnation.org>
 
 	* Removing the Profile1D -> ProfileBin1D friendship. This is very

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/TODO	Mon Aug 22 09:56:10 2011	(r305)
@@ -6,28 +6,21 @@
 * Check if the weight2 treatment in Dbn1D is really correct: we're currently
   multiplying it by sign(w). Hmm. (AB)
 
-* Rethink 1D bin inheritance: template Bin1D on dbn type and inherit from
-  Bin1D<Dbn1D> and Bin1D<Dbn2D> for histo and profile bins respectively? (AB)
+* Bin division: add quadratic / binomial error treatment enum option (AB)
 
-* Rework Axis1D to operate as Axis2D does (MICHAL)
-  AB: I'l try to get the Bin1D reworking done before it impacts on this.
+* Rebinning: merges of n adjacent bins (AB for 1D)
 
-* Explicitly return NaN for profile histo points with no weight? Or throw
-  LowStatsError? (all -- discuss)
+* Add copy constructors and assignment operators for Dbn1D/2D, Scatter2D,
+  Histo/ProfileBin1D, Point2D. (AB)
 
-* Bin division: add quadratic / binomial error treatment enum option (AB)
+* Rework Axis1D to operate as Axis2D does (MICHAL)
 
-* Rebinning: merges of n adjacent bins (AB for 1D)
+* Throw LowStatsError for errors and profile histo points with no fills -- any
+  explicit action needed? (AB)
 
 * Rebinning: global rebinning by integer factor(s) (AB for 1D, MICHAL for 2D)
-  Different rebinning factors for X and Y in 2D? Let's implement for 1D first,
-  to define the conventions for handling the fact that this usually won't be
-  exactly possible.
-
-* Add copy constructors for Dbn1D/2D, Scatter2D, Histo/ProfileBin1D, Point2D/3D, HistoBin2D.
-  Rule of three: also need explicit assignment operator= for all classes
-  with copy constructors? (ANDY and MICHAL for respectively authored classes)
-  MK: All 2/3D classes should be done.
+  Different rebinning factors for X and Y in 2D. Implement for 1D first,
+  to define the conventions.
 
 * Test that a y-binned Histo2D has the same per-y-column stats as an
   equivalently x-binned Profile1D. Perhaps use this as an opportunity to
@@ -43,12 +36,10 @@
   MK: Profile1D done. Outflows done. Needs a check if the outflows for Histo1D are
       done in the right way.
 
-* Use state-setting constructors for Histo and Profile persistency via the
-  Reader classes. (HH)
-
 * New "flat" file format: adapt WriterYODA and fill ReaderYODA. (HH)
   Need to persist the whole-histo Dbn1D/Dbn2Ds, and over/underflows.
-
+  Use state-setting constructors for Histo and Profile persistency via the
+  Reader classes.
 
 
 NEXT

Modified: trunk/include/YODA/Bin1D.h
==============================================================================
--- trunk/include/YODA/Bin1D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/Bin1D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -23,6 +23,9 @@
   /// profile bin types as HistoBin1D and ProfileBin1D.
   /// The lower bin edge is inclusive. This base class provides no fill
   /// method, since the signatures for standard and profile histos differ.
+  ///
+  /// @todo It would also be nice to have an *untemplated* generic Bin1D interface
+  template <class DBN>
   class Bin1D : public Bin {
   public:
 
@@ -46,14 +49,30 @@
 
 
     /// @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)
+    Bin1D(double lowedge, double highedge, const DBN& dbn)
       : _edges( std::make_pair(lowedge, highedge) ),
-        _xdbn(dbnx)
+        _dbn(dbn)
     {
       assert( _edges.second >= _edges.first );
     }
 
+
+    /// Copy constructor
+    Bin1D(const Bin1D<DBN>& b)
+      : _edges(b._edges),
+        _dbn(b._dbn)
+    { }
+
+
+    /// Copy assignment
+    Bin1D& operator = (const Bin1D<DBN>& b) {
+      _edges = b._edges;
+      _dbn = b._dbn;
+      return *this;
+    }
+
     //@}
 
 
@@ -62,14 +81,19 @@
 
     /// Reset this bin
     virtual void reset() {
-      _xdbn.reset();
+      _dbn.reset();
+    }
+
+    /// Rescale as if all fill weights had been different by factor @a scalefactor
+    void scaleW(double scalefactor) {
+      _dbn.scaleW(scalefactor);
     }
 
-    /// Scale
+    /// Scale the x dimension
     void scaleX(double factor) {
       _edges.first *= factor;
       _edges.second *= factor;
-      _xdbn.scaleX(factor);
+      _dbn.scaleX(factor);
     }
 
     //@}
@@ -110,7 +134,7 @@
 
     /// The mean position in the bin, or the midpoint if that is not available.
     double focus() const {
-      if (_xdbn.sumW() != 0) {
+      if (!isZero(sumW())) {
         return xMean();
       } else {
         return midpoint();
@@ -132,22 +156,22 @@
 
     /// Mean value of x-values in the bin.
     double xMean() const {
-      return _xdbn.mean();
+      return _dbn.xMean();
     }
 
     /// The variance of x-values in the bin.
     double xVariance() const {
-      return _xdbn.variance();
+      return _dbn.xVariance();
     }
 
     /// The standard deviation (spread) of x-values in the bin.
     double xStdDev() const {
-      return _xdbn.stdDev();
+      return _dbn.xStdDev();
     }
 
     /// The standard error on the bin focus.
     double xStdError() const {
-      return _xdbn.stdErr();
+      return _dbn.xStdErr();
     }
 
     //@}
@@ -160,27 +184,27 @@
 
     /// The number of entries
     unsigned long numEntries() const {
-      return _xdbn.numEntries();
+      return _dbn.numEntries();
     }
 
     /// The sum of weights
     double sumW() const {
-      return _xdbn.sumW();
+      return _dbn.sumW();
     }
 
     /// The sum of weights squared
     double sumW2() const {
-      return _xdbn.sumW2();
+      return _dbn.sumW2();
     }
 
     /// The sum of x*weight
     double sumWX() const {
-      return _xdbn.sumWX();
+      return _dbn.sumWX();
     }
 
     /// The sum of x^2 * weight
     double sumWX2() const {
-      return _xdbn.sumWX2();
+      return _dbn.sumWX2();
     }
 
     //@}
@@ -188,17 +212,16 @@
 
   public:
 
-
     /// @name Operators
     //@{
 
     /// Add two bins
-    Bin1D& operator += (const Bin1D& b) {
+    Bin1D<DBN>& operator += (const Bin1D<DBN>& b) {
       return add(b);
     }
 
     /// Subtract one bin from another
-    Bin1D& operator -= (const Bin1D& b) {
+    Bin1D<DBN>& operator -= (const Bin1D<DBN>& b) {
       return subtract(b);
     }
 
@@ -211,20 +234,26 @@
     //@{
 
     /// Add two bins (internal, explicitly named version)
-    Bin1D& add(const Bin1D& b) {
+    ///
+    /// This operator is defined for adding two bins with equivalent binning.
+    /// It cannot be used to merge two bins into one larger bin.
+    Bin1D<DBN>& add(const Bin1D<DBN>& b) {
       if (_edges != b._edges) {
         throw LogicError("Attempted to add two bins with different edges");
       }
-      _xdbn += b._xdbn;
+      _dbn += b._dbn;
       return *this;
     }
 
     /// Subtract one bin from another (internal, explicitly named version)
-    Bin1D& subtract(const Bin1D& b) {
+    ///
+    /// This operator is defined for subtracting two bins with equivalent binning.
+    /// It cannot be used to merge two bins into one larger bin.
+    Bin1D<DBN>& subtract(const Bin1D<DBN>& b) {
       if (_edges != b._edges) {
         throw LogicError("Attempted to add two bins with different edges");
       }
-      _xdbn -= b._xdbn;
+      _dbn -= b._dbn;
       return *this;
     }
 
@@ -236,31 +265,40 @@
     /// The bin limits
     std::pair<double,double> _edges;
 
-    // Distribution of weighted x values
-    Dbn1D _xdbn;
+    // Distribution of weighted x (and perhaps y) values
+    DBN _dbn;
 
   };
 
 
+
   /// Add two bins
-  inline Bin1D operator + (const Bin1D& a, const Bin1D& b) {
-    Bin1D rtn = a;
+  ///
+  /// This "add" operator is defined for adding two bins with equivalent binning.
+  /// It cannot be used to merge two bins into one larger bin.
+  template <class DBN>
+  inline Bin1D<DBN> operator + (const Bin1D<DBN>& a, const Bin1D<DBN>& b) {
+    Bin1D<DBN> rtn = a;
     rtn += b;
     return rtn;
   }
 
 
   /// Subtract one bin from another
-  inline Bin1D operator - (const Bin1D& a, const Bin1D& b) {
-    Bin1D rtn = a;
+  ///
+  /// This "subtraction" operator is defined for subtracting two bins with equivalent binning.
+  /// It cannot be used to merge two bins into one larger bin.
+  template <class DBN>
+  inline Bin1D<DBN> operator - (const Bin1D<DBN>& a, const Bin1D<DBN>& b) {
+    Bin1D<DBN> rtn = a;
     rtn -= b;
     return rtn;
   }
 
 
   /// Bin1Ds are compared for axis sorting by lower edge position
-  /// @todo Check for overlaps somewhere... on Axis1D, I guess.
-  inline bool operator<(const Bin1D& a, const Bin1D& b) {
+  template <class DBN>
+  inline bool operator<(const Bin1D<DBN>& a, const Bin1D<DBN>& b) {
     return b.edges().first > a.edges().first;
   }
 

Modified: trunk/include/YODA/Dbn1D.h
==============================================================================
--- trunk/include/YODA/Dbn1D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/Dbn1D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -109,17 +109,27 @@
       // This is ok, even for negative sum(w)
       return _sumWX/_sumW;
     }
+    /// Synonym for interface compatibility with Dbn2D
+    double xMean() const { return mean(); }
+
 
     /// Weighted variance, \f$ \sigma^2 \f$, of distribution.
     double variance() const;
+    /// Synonym for interface compatibility with Dbn2D
+    double xVariance() const { return variance(); }
+
 
     /// Weighted standard deviation, \f$ \sigma \f$, of distribution.
     double stdDev() const {
       return std::sqrt(variance());
     }
+    /// Synonym for interface compatibility with Dbn2D
+    double xStdDev() const { return stdDev(); }
 
     /// Weighted standard error on the mean, \f$ \sim \sigma/\sqrt{N-1} \f$, of distribution.
     double stdErr() const;
+    /// Synonym for interface compatibility with Dbn2D
+    double xStdErr() const { return stdErr(); }
 
     //@}
 

Modified: trunk/include/YODA/Dbn2D.h
==============================================================================
--- trunk/include/YODA/Dbn2D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/Dbn2D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -20,7 +20,8 @@
     }
 
 
-    /// @brief Constructor to set a distribution with a pre-filled state.
+    /// Constructor to set a distribution with a pre-filled state.
+    ///
     /// Principally designed for internal persistency use.
     Dbn2D(unsigned int numEntries, double sumW, double sumW2,
           double sumWX, double sumWX2, double sumWY, double sumWY2, double sumWXY)
@@ -30,14 +31,15 @@
     {  }
 
 
-    /// @brief Copy constructor
-    /// Sets all the parameters using the ones provided from
-    /// an existing Dbn2D.
+    /// Copy constructor
+    ///
+    /// Sets all the parameters using the ones provided from an existing Dbn2D.
     Dbn2D(const Dbn2D& toCopy) {
       _dbnX = toCopy._dbnX;
       _dbnY = toCopy._dbnY;
       _sumWXY = toCopy._sumWXY;
     }
+
     //@}
 
 
@@ -74,11 +76,24 @@
     }
 
 
+    /// Rescale x: needed if x histo bin edges are rescaled.
+    void scaleX(double xscale) {
+      _dbnX.scaleX(xscale);
+      _sumWXY *= xscale;
+    }
+
+
+    /// Rescale y: needed if y histo bin edges are rescaled.
+    void scaleY(double yscale) {
+      _dbnY.scaleX(yscale);
+      _sumWXY *= yscale;
+    }
+
+
     /// Rescale x and y: needed if histo bin edges are rescaled.
-    void scaleXY(double scaleX, double scaleY) {
-      _dbnX.scaleX(scaleX);
-      _dbnY.scaleX(scaleY);
-      _sumWXY *= scaleX*scaleY;
+    void scaleXY(double xscale, double yscale) {
+      scaleX(xscale);
+      scaleY(yscale);
     }
 
     //@}
@@ -203,12 +218,14 @@
     }
 
     /// Transform into a Dbn1D parallel to X axis (dropping Y term)
+    /// @todo Rename
     Dbn1D transformX() {
       Dbn1D ret(_dbnX);
       return ret;
     }
 
     /// Transform into a Dbn1D parallel to Y axis (dropping X term)
+    /// @todo Rename
     Dbn1D transformY() {
       Dbn1D ret(_dbnY);
       return ret;

Modified: trunk/include/YODA/HistoBin1D.h
==============================================================================
--- trunk/include/YODA/HistoBin1D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/HistoBin1D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -19,7 +19,7 @@
   /// This is a 1D bin type, which supports all the operations defined for
   /// a generic Bin1D object, but also supplies the specific member functions
   /// for histogram-type data, as opposed to profile-type.
-  class HistoBin1D : public Bin1D {
+  class HistoBin1D : public Bin1D<Dbn1D> {
 
   public:
 
@@ -39,13 +39,24 @@
 
 
     /// @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)
-      : Bin1D(lowedge, highedge, dbn)
+    HistoBin1D(double lowedge, double highedge, const Dbn1D& dbnx)
+      : Bin1D(lowedge, highedge, dbnx)
     { }
 
 
-    /// @todo Add copy constructor
+    /// Copy constructor
+    HistoBin1D(const HistoBin1D& hb)
+      : Bin1D(hb)
+    { }
+
+
+    /// Copy assignment
+    HistoBin1D& operator = (const HistoBin1D& hb) {
+      Bin1D::operator=(hb);
+      return *this;
+    }
 
     //@}
 
@@ -59,7 +70,7 @@
     void fill(double x, double weight=1.0) {
       assert( _edges.first < _edges.second );
       assert( x >= _edges.first && x < _edges.second );
-      _xdbn.fill(x, weight);
+      _dbn.fill(x, weight);
     }
 
     /// @brief Fill this bin with weight @a weight.
@@ -67,16 +78,6 @@
       fill(midpoint(), weight);
     }
 
-    /// Reset this bin
-    void reset() {
-      Bin1D::reset();
-    }
-
-    /// Rescale as if all fill weights had been different by factor @a scalefactor.
-    void scaleW(double scalefactor) {
-      _xdbn.scaleW(scalefactor);
-    }
-
     //@}
 
 
@@ -84,6 +85,7 @@
 
     /// @name Bin content info
     //@{
+
     /// The area is the sum of weights in the bin, i.e. the
     /// width of the bin has no influence on this figure.
     double area() const {
@@ -94,6 +96,7 @@
     double height() const {
       return area() / width();
     }
+
     //@}
 
 
@@ -105,16 +108,12 @@
     double areaErr() const {
       return sqrt(sumW2());
     }
-    /// @deprecated Synonym for areaErr -- the "Err" form is the de facto standard now in YODA
-    double areaError() const { return areaErr(); }
 
     /// As for the height vs. area, the height error includes a scaling factor
     /// of the bin width, i.e. err_height = sqrt{sum{weights}} / width.
     double heightErr() const {
-      return areaError() / width();
+      return areaErr() / width();
     }
-    /// @deprecated Synonym for heightErr -- the "Err" form is the de facto standard now in YODA
-    double heightError() const { return heightErr(); }
 
     //@}
 
@@ -136,13 +135,13 @@
 
     /// Add two bins (internal, explicitly named version)
     HistoBin1D& add(const HistoBin1D& hb) {
-      Bin1D::add(hb);
+      Bin1D<Dbn1D>::add(hb);
       return *this;
     }
 
     /// Subtract one bin from another (internal, explicitly named version)
     HistoBin1D& subtract(const HistoBin1D& hb) {
-      Bin1D::subtract(hb);
+      Bin1D<Dbn1D>::subtract(hb);
       return *this;
     }
 

Modified: trunk/include/YODA/HistoBin2D.h
==============================================================================
--- trunk/include/YODA/HistoBin2D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/HistoBin2D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -103,20 +103,15 @@
     /// @brief Transformer taking x as the primary axis of ProfileBin1D
     /// @todo Need to think about the name, and clarify what "primary axis" means
     ProfileBin1D transformX() {
-      Dbn1D dbny(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWY(), _dbn.sumWY2());
-      Dbn1D dbnx(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWX(), _dbn.sumWX2());
-      ProfileBin1D ret(xMin(), xMax(), dbnx, dbny);
-
+      ProfileBin1D ret(xMin(), xMax(), Dbn2D(_dbn));
       return ret;
     }
 
     /// @brief Transformer taking y as the primary axis of ProfileBin1D
     /// @todo Need to think about the name, and clarify what "primary axis" means
     ProfileBin1D transformY() {
-      Dbn1D dbny(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWY(), _dbn.sumWY2());
-      Dbn1D dbnx(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWX(), _dbn.sumWX2());
-      ProfileBin1D ret(yMin(), yMax(), dbny, dbnx);
-
+      Dbn2D dbn = _dbn; dbn.flipXY();
+      ProfileBin1D ret(yMin(), yMax(), Dbn2D(dbn));
       return ret;
     }
 

Modified: trunk/include/YODA/ProfileBin1D.h
==============================================================================
--- trunk/include/YODA/ProfileBin1D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/ProfileBin1D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -7,6 +7,7 @@
 #define YODA_ProfileBin1D_h
 
 #include "YODA/Bin1D.h"
+#include "YODA/Dbn2D.h"
 #include "YODA/Exceptions.h"
 
 namespace YODA {
@@ -19,7 +20,7 @@
   /// for profile-type data, as opposed to histogram-type. This means that
   /// extra internal distribution statistics are stored for the extra
   /// "y-direction" specified in the profile fill operation.
-  class ProfileBin1D : public Bin1D {
+  class ProfileBin1D : public Bin1D<Dbn2D> {
   public:
 
     /// @name Constructors
@@ -30,20 +31,32 @@
       : Bin1D(lowedge, highedge)
     { }
 
+
     /// Constructor giving bin low and high edges as a pair.
     ProfileBin1D(const std::pair<double,double>& edges)
       : Bin1D(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)
-      : Bin1D(lowedge, highedge, dbnx),
-        _ydbn(dbny)
+    ProfileBin1D(double lowedge, double highedge, const Dbn2D& dbnxy)
+      : Bin1D(lowedge, highedge, dbnxy)
     {  }
 
-    /// @todo Add copy constructor
+
+    /// Copy constructor
+    ProfileBin1D(const ProfileBin1D& pb)
+      : Bin1D(pb)
+    { }
+
+
+    /// Copy assignment
+    ProfileBin1D& operator = (const ProfileBin1D& pb) {
+      Bin1D::operator=(pb);
+      return *this;
+    }
 
     //@}
 
@@ -52,28 +65,15 @@
     //@{
 
     /// Fill histo by x and y values and weight.
-    void fill(double x, double d, double weight=1.0) {
+    void fill(double x, double y, double weight=1.0) {
       assert( _edges.first < _edges.second );
       assert( x >= _edges.first && x < _edges.second );
-      _xdbn.fill(x, weight);
-      _ydbn.fill(d, weight);
+      _dbn.fill(x, y, weight);
     }
 
-    /// Fill histo with @a weight and y-value @c d at x = bin midpoint.
-    void fillBin(double d, double weight=1.0) {
-      fill(midpoint(), d, weight);
-    }
-
-    /// Reset the bin.
-    void reset() {
-      Bin1D::reset();
-      _ydbn.reset();
-    }
-
-    /// Rescale as if all fill weights had been different by factor @a scalefactor.
-    void scaleW(double scalefactor) {
-      _xdbn.scaleW(scalefactor);
-      _ydbn.scaleW(scalefactor);
+    /// Fill histo with @a weight and y-value @c y at x = bin midpoint.
+    void fillBin(double y, double weight=1.0) {
+      fill(midpoint(), y, weight);
     }
 
     //@}
@@ -85,24 +85,42 @@
     //@{
 
     double mean() const {
-      return _ydbn.mean();
+      return _dbn.yMean();
     }
 
     double stdDev() const {
-      return _ydbn.stdDev();
+      return _dbn.yStdDev();
     }
 
     double variance() const {
-      return _ydbn.variance();
+      return _dbn.yVariance();
     }
 
     double stdErr() const {
-      return _ydbn.stdErr();
+      return _dbn.yStdErr();
     }
 
     //@}
 
 
+    /// @name Raw y distribution statistics
+    //@{
+
+    /// The sum of y*weight
+    double sumWY() const {
+      return _dbn.sumWX();
+    }
+
+    /// The sum of y^2 * weight
+    double sumWY2() const {
+      return _dbn.sumWX2();
+    }
+
+    /// @todo Expose sumXY just for persistency?
+
+    //@}
+
+
   public:
 
     /// Add two bins (for use by Profile1D).
@@ -120,38 +138,16 @@
 
     /// Add two bins (internal, explicitly named version)
     ProfileBin1D& add(const ProfileBin1D& pb) {
-      Bin1D::add(pb);
-      _ydbn += pb._ydbn;
+      Bin1D<Dbn2D>::add(pb);
       return *this;
     }
 
     /// Subtract one bin from another (internal, explicitly named version)
     ProfileBin1D& subtract(const ProfileBin1D& pb) {
-      Bin1D::subtract(pb);
-      _ydbn -= pb._ydbn;
+      Bin1D<Dbn2D>::subtract(pb);
       return *this;
     }
 
-
-  public:
-
-    /// The sum of y*weight
-    double sumWY() const {
-      return _ydbn.sumWX();
-    }
-
-    /// The sum of y^2 * weight
-    double sumWY2() const {
-      return _ydbn.sumWX2();
-    }
-
-
-  private:
-
-    // Distribution of weighted data values
-    Dbn1D _ydbn;
-
-
   };
 
 

Modified: trunk/include/YODA/Scatter2D.h
==============================================================================
--- trunk/include/YODA/Scatter2D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/Scatter2D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -26,6 +26,7 @@
   public:
 
     /// Type of the native Point2D collection
+    typedef Point2D Point;
     typedef Utils::sortedvector<Point2D> Points;
 
 

Modified: trunk/include/YODA/Scatter3D.h
==============================================================================
--- trunk/include/YODA/Scatter3D.h	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/include/YODA/Scatter3D.h	Mon Aug 22 09:56:10 2011	(r305)
@@ -19,7 +19,8 @@
   class Scatter3D : public AnalysisObject {
   public:
 
-    /// Type of the native Point3D collection
+    /// Types of the native Point3D collection
+    typedef Point3D Point;
     typedef std::vector<Point3D> Points;
 
 
@@ -37,7 +38,7 @@
               const std::string& path="", const std::string& title="")
       : AnalysisObject("Scatter3D", path, title),
         _points(points)
-    {  
+    {
       std::sort(_points.begin(), _points.end());
     }
 
@@ -48,7 +49,7 @@
               const std::string& path="", const std::string& title="")
       : AnalysisObject("Scatter3D", path, title)
     {
-      if(x.size() != y.size() || y.size() != z.size() || 
+      if(x.size() != y.size() || y.size() != z.size() ||
          x.size() != ex.size() || y.size() != ey.size() || z.size() != ez.size())
         throw RangeError("There are either different amounts of points on x/y/z vectors or not every of these vectors has properly defined error vectors!");
 
@@ -83,7 +84,7 @@
       if(x.size() != y.size() || y.size() != z.size() ||
          x.size() != exminus.size() || x.size() != explus.size() ||
          y.size() != eyminus.size() || y.size() != eyplus.size() ||
-         z.size() != ezminus.size() || z.size() != ezplus.size()) 
+         z.size() != ezminus.size() || z.size() != ezplus.size())
         throw RangeError("There are either different amounts of points on x/y/z vectors or not every of these vectors has properly defined error vectors!");
 
       for (size_t i = 0; i < x.size(); ++i) {
@@ -274,7 +275,7 @@
 
       ret.addPoint(x, exminus, explus, y, eyminus, eyplus, z, ez, ez);
     }
-    
+
     return ret;
   }
 

Modified: trunk/src/Histo1D.cc
==============================================================================
--- trunk/src/Histo1D.cc	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/src/Histo1D.cc	Mon Aug 22 09:56:10 2011	(r305)
@@ -63,7 +63,7 @@
     if (includeoverflows) return _axis.totalDbn().variance();
     double sigma2 = 0;
     const double mean = this->mean();
-    foreach (const Bin1D& b, bins()) {
+    foreach (const HistoBin1D& b, bins()) {
       const double diff = b.focus() - mean;
       sigma2 += diff * diff * b.sumW();
     }
@@ -87,8 +87,8 @@
     : AnalysisObject("Histo1D", (path.size() == 0) ? s.path() : path, s, s.title())
   {
     std::vector<HistoBin1D> bins;
-    for (Scatter2D::Points::const_iterator p = s.points().begin(); p != s.points().end(); ++p) {
-      bins.push_back(HistoBin1D(p->xMin(), p->xMax()));
+    foreach (const Scatter2D::Point& p, s.points()) {
+      bins.push_back(HistoBin1D(p.xMin(), p.xMax()));
     }
     _axis = Histo1DAxis(bins);
   }
@@ -99,8 +99,8 @@
     : AnalysisObject("Histo1D", (path.size() == 0) ? p.path() : path, p, p.title())
   {
     std::vector<HistoBin1D> bins;
-    for (std::vector<ProfileBin1D>::const_iterator b = p.bins().begin(); b != p.bins().end(); ++b) {
-      bins.push_back(HistoBin1D(b->xMin(), b->xMax()));
+    foreach (const ProfileBin1D& b, p.bins()) {
+      bins.push_back(HistoBin1D(b.xMin(), b.xMax()));
     }
     _axis = Histo1DAxis(bins);
 
@@ -111,6 +111,9 @@
 
 
   /// Divide two histograms
+  ///
+  /// @todo Add QUAD, BINOMIAL enum for error treatment
+  /// @todo Add named operator
   Scatter2D operator / (const Histo1D& numer, const Histo1D& denom) {
     //assert(numer._axis == denom._axis);
     Scatter2D tmp;
@@ -130,7 +133,7 @@
       assert(explus >= 0);
       //
       const double y = b1.height() / b2.height();
-      const double ey = y * sqrt( sqr(b1.heightError()/b1.height()) + sqr(b2.heightError()/b2.height()) );
+      const double ey = y * sqrt( sqr(b1.heightErr()/b1.height()) + sqr(b2.heightErr()/b2.height()) );
       tmp.addPoint(x, exminus, explus, y, ey, ey);
     }
     assert(tmp.numPoints() == numer.numBins());

Modified: trunk/src/Scatter2D.cc
==============================================================================
--- trunk/src/Scatter2D.cc	Sun Aug 21 14:49:13 2011	(r304)
+++ trunk/src/Scatter2D.cc	Mon Aug 22 09:56:10 2011	(r305)
@@ -15,7 +15,7 @@
       const double ex_m = b.focus() - b.lowEdge();
       const double ex_p = b.highEdge() - b.focus();
       const double y = b.height();
-      const double ey = b.heightError();
+      const double ey = b.heightErr();
       const Point2D pt(x, ex_m, ex_p, y, ey, ey);
       rtn.addPoint(pt);
     }


More information about the yoda-svn mailing list