|
[yoda-svn] r423 - trunk/include/YODAblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Dec 8 12:10:51 GMT 2011
Author: hoeth Date: Thu Dec 8 12:10:51 2011 New Revision: 423 Log: Cleanup and bugfixes in Dbn*D.h, especially 2D and 3D Modified: trunk/include/YODA/Dbn1D.h trunk/include/YODA/Dbn2D.h trunk/include/YODA/Dbn3D.h Modified: trunk/include/YODA/Dbn1D.h ============================================================================== --- trunk/include/YODA/Dbn1D.h Thu Dec 8 10:42:04 2011 (r422) +++ trunk/include/YODA/Dbn1D.h Thu Dec 8 12:10:51 2011 (r423) @@ -38,7 +38,7 @@ /// @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) { + Dbn1D(unsigned long numEntries, double sumW, double sumW2, double sumWX, double sumWX2) { _numFills = numEntries; _sumW = sumW; _sumW2 = sumW2; @@ -47,7 +47,16 @@ } - /// @todo Add copy constructor + /// Copy constructor + /// + /// Sets all the parameters using the ones provided from an existing Dbn1D. + Dbn1D(const Dbn1D& toCopy) { + _numFills = toCopy._numFills; + _sumW = toCopy._sumW; + _sumW2 = toCopy._sumW2; + _sumWX = toCopy._sumWX; + _sumWX2 = toCopy._sumWX2; + } //@} @@ -72,12 +81,10 @@ /// Rescale as if all fill weights had been different by factor @a scalefactor. void scaleW(double scalefactor) { - const double sf = scalefactor; - const double sf2 = sf*sf; - _sumW *= sf; - _sumW2 *= sf2; - _sumWX *= sf; - _sumWX2 *= sf2; + _sumW *= scalefactor; + _sumW2 *= scalefactor*scalefactor; + _sumWX *= scalefactor; + _sumWX2 *= scalefactor; } @@ -89,22 +96,8 @@ //@} - public: - /// @name High-level info - //@{ - - // bool isUnfilled() const { - // return (numEntries() == 0); - // } - - // bool isEmpty() const { - // return (sumW() == 0) - // } - - //@} - /// @name Distribution statistics //@{ @@ -171,7 +164,7 @@ return _sumWX; } - /// The sum of x^2 * weight + /// The sum of x^2*weight double sumWX2() const { return _sumWX2; } Modified: trunk/include/YODA/Dbn2D.h ============================================================================== --- trunk/include/YODA/Dbn2D.h Thu Dec 8 10:42:04 2011 (r422) +++ trunk/include/YODA/Dbn2D.h Thu Dec 8 12:10:51 2011 (r423) @@ -1,3 +1,8 @@ +// -*- C++ -*- +// +// This file is part of YODA -- Yet more Objects for Data Analysis +// Copyright (C) 2008-2011 The YODA collaboration (see AUTHORS for details) +// #ifndef YODA_Dbn2D_h #define YODA_Dbn2D_h @@ -7,14 +12,14 @@ namespace YODA { - /// A representation of the vital statistics of a 2D distribution + /// @brief A 2D distribution class Dbn2D { public: /// @name Constructors //@{ - /// Default constructor + /// Default constructor of a new distribution. Dbn2D() { reset(); } @@ -23,12 +28,12 @@ /// Constructor to set a distribution with a pre-filled state. /// /// Principally designed for internal persistency use. - Dbn2D(unsigned int numEntries, double sumW, double sumW2, + Dbn2D(unsigned long numEntries, double sumW, double sumW2, double sumWX, double sumWX2, double sumWY, double sumWY2, double sumWXY) : _dbnX(numEntries, sumW, sumW2, sumWX, sumWX2), _dbnY(numEntries, sumW, sumW2, sumWY, sumWY2), _sumWXY(sumWXY) - { } + { } /// Copy constructor @@ -64,7 +69,7 @@ void reset() { _dbnX.reset(); _dbnY.reset(); - _sumWXY = 0.0; + _sumWXY = 0; } @@ -98,6 +103,8 @@ //@} + public: + /// @name Distribution statistics //@{ @@ -139,7 +146,7 @@ /// Weighted standard error on the \f$ y \f$ mean, \f$ \sim \sigma_y/\sqrt{N-1} \f$, of distribution. double yStdErr() const { - return _dbnY.stdDev(); + return _dbnY.stdErr(); } /// Weighted RMS, \f$ \sqrt{ \sum{w x^2}/\sum{w} } \f$, of distribution. @@ -183,17 +190,17 @@ return _dbnX.sumWX(); } + /// The sum of x^2*weight + double sumWX2() const { + return _dbnX.sumWX2(); + } + /// The sum of y*weight double sumWY() const { return _dbnY.sumWX(); } - /// The sum of x*x*weight - double sumWX2() const { - return _dbnX.sumWX2(); - } - - /// The sum of y*y*weight + /// The sum of y^2*weight double sumWY2() const { return _dbnY.sumWX2(); } Modified: trunk/include/YODA/Dbn3D.h ============================================================================== --- trunk/include/YODA/Dbn3D.h Thu Dec 8 10:42:04 2011 (r422) +++ trunk/include/YODA/Dbn3D.h Thu Dec 8 12:10:51 2011 (r423) @@ -1,3 +1,8 @@ +// -*- C++ -*- +// +// This file is part of YODA -- Yet more Objects for Data Analysis +// Copyright (C) 2008-2011 The YODA collaboration (see AUTHORS for details) +// #ifndef YODA_Dbn3D_h #define YODA_Dbn3D_h @@ -7,44 +12,52 @@ namespace YODA { - /// A representation of the vital statistics of a 3D distribution + /// @brief A 2D distribution class Dbn3D { public: - /// @name COnstructors + /// @name Constructors //@{ - /// Default constructor + /// Default constructor of a new distribution. Dbn3D() { reset(); } - /// Unpersisting constructor - Dbn3D(unsigned int numEntries, double sumW, double sumW2, double sumWX, - double sumWX2, double sumWY, double sumWY2, double sumWZ, double sumWZ2, + + /// Constructor to set a distribution with a pre-filled state. + /// + /// Principally designed for internal persistency use. + Dbn3D(unsigned long numEntries, double sumW, double sumW2, + double sumWX, double sumWX2, double sumWY, double sumWY2, double sumWZ, double sumWZ2, double sumWXY, double sumWXZ, double sumWYZ, double sumWXYZ) : _dbnX(numEntries, sumW, sumW2, sumWX, sumWX2), - _dbnY(numEntries, sumW, sumW2, sumWY, sumWY2), - _dbnZ(numEntries, sumW, sumW2, sumWZ, sumWZ2), - _sumWXY(sumWXY), - _sumWXZ(sumWXZ), - _sumWYZ(sumWYZ), - _sumWXYZ(sumWYZ) + _dbnY(numEntries, sumW, sumW2, sumWY, sumWY2), + _dbnZ(numEntries, sumW, sumW2, sumWZ, sumWZ2), + _sumWXY(sumWXY), _sumWXZ(sumWXZ), _sumWYZ(sumWYZ), _sumWXYZ(sumWYZ) { } + /// Copy constructor + /// + /// Sets all the parameters using the ones provided from an existing Dbn3D. Dbn3D(const Dbn3D& toCopy) { _dbnX = toCopy._dbnX; _dbnY = toCopy._dbnY; + _dbnZ = toCopy._dbnZ; _sumWXY = toCopy._sumWXY; + _sumWXZ = toCopy._sumWXZ; + _sumWYZ = toCopy._sumWYZ; + _sumWXYZ = toCopy._sumWXYZ; } //@} + /// @name Modifiers //@{ - /// Fill, providing coordinates as three distinct numbers. + /// Fill, providing the fill coordinates as three different numbers. void fill(double valX, double valY, double valZ, double weight=1.0) { _dbnX.fill(valX, weight); _dbnY.fill(valY, weight); @@ -55,18 +68,27 @@ _sumWXYZ += weight*valX*valY*valZ; } - /// Reset to the unfilled state + + /// Fill, providing the fill coordinates as a vector. + void fill(std::vector<double> val, double weight=1.0) { + assert (val.size() == 3); + fill(val[0], val[1], val[2], weight); + } + + + /// Reset the distribution to an unfilled state. void reset() { _dbnX.reset(); _dbnY.reset(); _dbnZ.reset(); - _sumWXY = 0.0; - _sumWXZ = 0.0; - _sumWYZ = 0.0; - _sumWXYZ = 0.0; + _sumWXY = 0; + _sumWXZ = 0; + _sumWYZ = 0; + _sumWXYZ = 0; } - /// Rescale the weights by a scalefactor + + /// Rescale as if all fill weights had been different by factor @a scalefactor. void scaleW(double scalefactor) { _dbnX.scaleW(scalefactor); _dbnY.scaleW(scalefactor); @@ -77,7 +99,8 @@ _sumWXYZ *= scalefactor; } - /// Scale x axis: scale X edges + + /// Rescale x: needed if x histo bin edges are rescaled. void scaleX(double xscale) { _dbnX.scaleX(xscale); _sumWXY *= xscale; @@ -85,7 +108,8 @@ _sumWXYZ *= xscale; } - /// Scale y axis: scale Y edges + + /// Rescale y: needed if y histo bin edges are rescaled. void scaleY(double yscale) { _dbnY.scaleX(yscale); _sumWXY *= yscale; @@ -93,7 +117,8 @@ _sumWXYZ *= yscale; } - /// Scale z axis: scale Z edges + + /// Rescale z: needed if z histo bin edges are rescaled. void scaleZ(double zscale) { _dbnZ.scaleX(zscale); _sumWXZ *= zscale; @@ -101,21 +126,29 @@ _sumWXYZ *= zscale; } + + /// Rescale x and y: needed if histo bin edges are rescaled. void scaleXY(double xscale, double yscale) { scaleX(xscale); scaleY(yscale); } + + /// Rescale x and z: needed if histo bin edges are rescaled. void scaleXZ(double xscale, double zscale) { scaleX(xscale); scaleZ(zscale); } + + /// Rescale y and z: needed if histo bin edges are rescaled. void scaleYZ(double yscale, double zscale) { scaleY(yscale); scaleZ(zscale); } + + /// Rescale x, y and z: needed if histo bin edges are rescaled. void scaleXYZ(double xscale, double yscale, double zscale) { scaleX(xscale); scaleY(yscale); @@ -124,121 +157,167 @@ //@} + public: + + /// @name Distribution statistics //@{ + + /// Weighted mean, \f$ \bar{x} \f$, of distribution. double xMean() const { return _dbnX.mean(); } + /// Weighted mean, \f$ \bar{y} \f$, of distribution. double yMean() const { return _dbnY.mean(); } + /// Weighted mean, \f$ \bar{z} \f$, of distribution. double zMean() const { return _dbnZ.mean(); } + /// Weighted \f$ x \f$ variance, \f$ \sigma_x^2 \f$, of distribution. double xVariance() const { return _dbnX.variance(); } + /// Weighted \f$ y \f$ variance, \f$ \sigma_y^2 \f$, of distribution. double yVariance() const { return _dbnY.variance(); } + /// Weighted \f$ z \f$ variance, \f$ \sigma_z^2 \f$, of distribution. double zVariance() const { return _dbnZ.variance(); } + /// Weighted \f$ x \f$ standard deviation, \f$ \sigma_x \f$, of distribution. double xStdDev() const { return _dbnX.stdDev(); } + /// Weighted \f$ y \f$ standard deviation, \f$ \sigma_y \f$, of distribution. double yStdDev() const { return _dbnY.stdDev(); } + /// Weighted \f$ z \f$ standard deviation, \f$ \sigma_z \f$, of distribution. double zStdDev() const { return _dbnZ.stdDev(); } + /// Weighted standard error on the \f$ x \f$ mean, \f$ \sim \sigma_x/\sqrt{N-1} \f$, of distribution. double xStdErr() const { return _dbnX.stdErr(); } + /// Weighted standard error on the \f$ y \f$ mean, \f$ \sim \sigma_y/\sqrt{N-1} \f$, of distribution. double yStdErr() const { return _dbnY.stdErr(); } + /// Weighted standard error on the \f$ z \f$ mean, \f$ \sim \sigma_z/\sqrt{N-1} \f$, of distribution. double zStdErr() const { return _dbnZ.stdErr(); } + /// Weighted RMS, \f$ \sqrt{ \sum{w x^2}/\sum{w} } \f$, of distribution. + double xRMS() const { + return _dbnX.rms(); + } + + /// Weighted RMS, \f$ \sqrt{ \sum{w y^2}/\sum{w} } \f$, of distribution. + double yRMS() const { + return _dbnY.rms(); + } + + /// Weighted RMS, \f$ \sqrt{ \sum{w z^2}/\sum{w} } \f$, of distribution. + double zRMS() const { + return _dbnZ.rms(); + } + //@} + /// @name Raw distribution running sums //@{ - /// Number of entries - size_t numEntries() const { + /// Number of entries (number of times @c fill was called, ignoring weights) + unsigned long numEntries() const { return _dbnX.numEntries(); } + /// Effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$ double effNumEntries() const { return _dbnX.effNumEntries(); } + /// The sum of weights double sumW() const { return _dbnX.sumW(); } + /// The sum of weights squared double sumW2() const { return _dbnX.sumW2(); } + /// The sum of x*weight double sumWX() const { return _dbnX.sumWX(); } + /// The sum of x^2*weight double sumWX2() const { return _dbnX.sumWX2(); } + /// The sum of y*weight double sumWY() const { return _dbnY.sumWX(); } + /// The sum of y^2*weight double sumWY2() const { return _dbnY.sumWX2(); } + /// The sum of z*weight double sumWZ() const { return _dbnZ.sumWX(); } + /// The sum of z^2*weight double sumWZ2() const { return _dbnZ.sumWX2(); } + /// The sum of x*y*weight double sumWXY() const { return _sumWXY; } + /// The sum of x*z*weight double sumWXZ() const { return _sumWXZ; } + /// The sum of y*z*weight double sumWYZ() const { return _sumWXZ; } + /// The sum of x*y*z*weight double sumWXYZ() const { return _sumWXYZ; } //@} - // @name Operators + + /// @name Operators //@{ /// Add two dbns @@ -246,47 +325,61 @@ return add(d); } - /// Substract two dbns + /// Subtract one dbn from another Dbn3D& operator -= (const Dbn3D& d) { return subtract(d); } - /// Interchange X and Y subdistribution + /// @brief Interchange X and Y subdistributions + /// Mostly used for operations on total distribution of an Axis void flipXY() { Dbn1D temp(_dbnX); _dbnX = _dbnY; _dbnY = temp; } + /// @brief Interchange X and Z subdistributions + /// Mostly used for operations on total distribution of an Axis void flipXZ() { Dbn1D temp(_dbnX); _dbnX = _dbnZ; _dbnZ = temp; } + /// @brief Interchange Y and Z subdistributions + /// Mostly used for operations on total distribution of an Axis void flipYZ() { Dbn1D temp(_dbnY); _dbnY = _dbnZ; _dbnZ = temp; } - /// Transform into a Dbn1D parallel to X axis + /// Transform into a Dbn1D parallel to X axis (dropping Y and Z terms) + /// @todo Rename Dbn1D transformX() { - return _dbnX; + Dbn1D ret(_dbnX); + return ret; } + /// Transform into a Dbn1D parallel to Y axis (dropping X and Z terms) + /// @todo Rename Dbn1D transformY() { - return _dbnY; + Dbn1D ret(_dbnY); + return ret; } + /// Transform into a Dbn1D parallel to Z axis (dropping X and Y terms) + /// @todo Rename Dbn1D transformZ() { - return _dbnZ; + Dbn1D ret(_dbnZ); + return ret; } //@} + protected: - /// Add two dbns + /// Add two dbns (internal, explicitly named version) Dbn3D& add(const Dbn3D& d) { _dbnX += d._dbnX; _dbnY += d._dbnY; @@ -298,6 +391,7 @@ return *this; } + /// Subtract one dbn from another (internal, explicitly named version) Dbn3D& subtract(const Dbn3D& d) { _dbnX -= d._dbnX; _dbnY -= d._dbnY; @@ -309,27 +403,31 @@ return *this; } + private: + /// @name Storage - // @{ + //@{ - /// The x moments and the pure-weight quantities are stored in a 1D 'x' distribution + /// The x moments and the pure-weight quantities are stored in a 1D "x" distribution Dbn1D _dbnX; - /// The y moments are stored in a 1D 'y' distribution + /// The y moments are stored in a 1D "y" distribution Dbn1D _dbnY; - /// The z moments are stored in a 1D 'z' distribution + /// The z moments are stored in a 1D "z" distribution Dbn1D _dbnZ; - /// Cross-terms + /// The higher-order "cross-term" that can't be handled using the 1D distributions double _sumWXY; double _sumWXZ; double _sumWYZ; double _sumWXYZ; //@} + }; + /// Add two dbns inline Dbn3D operator + (const Dbn3D& a, const Dbn3D& b) { Dbn3D rtn = a; @@ -337,13 +435,14 @@ return rtn; } + /// Subtract one dbn from another inline Dbn3D operator - (const Dbn3D& a, const Dbn3D& b) { Dbn3D rtn = a; rtn -= b; return rtn; } -} -#endif +} +#endif
More information about the yoda-svn mailing list |