|
[yoda-svn] r379 - in trunk: include/YODA srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgSun Aug 28 21:30:57 BST 2011
Author: mkawalec Date: Sun Aug 28 21:30:56 2011 New Revision: 379 Log: Added missing files, some fixes and some things patched just to compile now. Added: trunk/include/YODA/ProfileBin2D.h Modified: trunk/include/YODA/Axis2D.h trunk/src/Histo2D.cc trunk/src/Profile1D.cc trunk/src/Profile2D.cc Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Sun Aug 28 15:11:13 2011 (r378) +++ trunk/include/YODA/Axis2D.h Sun Aug 28 21:30:56 2011 (r379) @@ -188,7 +188,7 @@ /// @name Modifiers //@{ - /// @brief Fill operator + /// @brief Fill operator in 2D /// /// Called when it is wanted to fill a certain position on an Axis int fill(double x, double y, double weight) { @@ -207,6 +207,19 @@ return index; } + /// @brief Fill operator for the 3D case + /// For a detailed description, please see the 2D one. + int fill(double x, double y, double z, double weight) { + _dbn.fill(x, y, z, weight); + + int index = getBinIndex(x,y); + if (index != -1) _bins[index].fill(x, y, z, weight); + + else if (_outflows.size() == 8) _fillOutflows(x, y, z, weight); + return index; + } + + /// Merge a range of bins, given the bin IDs of points at the lower-left and upper-right. void mergeBins(size_t from, size_t to) { @@ -656,7 +669,7 @@ } - /// Outflow filler + /// 2D Outflow filler /// The function checks which outflow the coordinates are in /// and fills the right one. void _fillOutflows(double x, double y, double weight) { @@ -686,6 +699,35 @@ } } + + /// 3D outflow filler + void _fillOutflows(double x, double y, double z, double weight) { + if (x < _lowEdgeX && y > _highEdgeY) _outflows[0][0].fill(x, y, z, weight); + else if (x > _lowEdgeX && x < _highEdgeX && y > _highEdgeY) + { + size_t element = _binaryS(_binHashSparse.second, x, 0, _binHashSparse.second.size()); + _outflows[1][element].fill(x, y, z, weight); + } + else if (x > _highEdgeX && y > _highEdgeY) _outflows[2][0].fill(x, y, z, weight); + else if (x > _highEdgeX && y > _lowEdgeY && y < _highEdgeY) + { + size_t element = _binaryS(_binHashSparse.first, y, 0, _binHashSparse.first.size()); + _outflows[3][element].fill(x, y, z, weight); + } + else if (x > _highEdgeX && y < _lowEdgeY) _outflows[4][0].fill(x, y, z, weight); + else if (x > _lowEdgeX && x < _highEdgeX && y < _lowEdgeY) + { + size_t element = _binaryS(_binHashSparse.second, x, 0, _binHashSparse.second.size()); + _outflows[5][element].fill(x, y, z, weight); + } + else if (x < _lowEdgeX && y < _lowEdgeY) _outflows[6][0].fill(x, y, z, weight); + else if (x < _lowEdgeX && y > _lowEdgeY && y < _highEdgeY) + { + size_t element = _binaryS(_binHashSparse.first, y, 0, _binHashSparse.first.size()); + _outflows[7][element].fill(x, y, z, weight); + } + + } /// @brief Checks if our bins form a grid. /// Added: trunk/include/YODA/ProfileBin2D.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/include/YODA/ProfileBin2D.h Sun Aug 28 21:30:56 2011 (r379) @@ -0,0 +1,140 @@ +#ifndef YODA_ProfileBin2D_h +#define YODA_ProfileBin2D_h + +#include "YODA/Bin2D.h" +#include "YODA/Dbn3D.h" +#include "YODA/Exceptions.h" + +namespace YODA { + + class ProfileBin2D : public Bin2D<Dbn3D> { + public: + + /// @name Constructors + //@{ + + /// Constructor giving lowedgesX/Y + ProfileBin2D(double lowX, double lowY, double highX, double highY) + : Bin2D(lowX, lowY, highX, highY) + { } + + ProfileBin2D(const std::vector<std::pair<std::pair<double,double>,std::pair<double,double> > >& edges) + : Bin2D(edges) + { } + + /// Unpersisting constructor + ProfileBin2D(double lowX, double lowY, double highX, double highY, + const Dbn3D& dbnxyz) + : Bin2D(lowX, lowY, highX, highY) + { } + + /// Copy constructor + ProfileBin2D(const ProfileBin2D& pb) + : Bin2D(pb) + { } + + /// Copy assignment + ProfileBin2D& operator = (const ProfileBin2D& pb) { + Bin2D::operator=(pb); + return *this; + } + + //@} + + /// @name Modifiers + //@{ + + /// Fill by x, y, z values and weight + void fill(double x, double y, double z, double weight=1.0) { + assert(x >= xMin() && x <= xMax() && y >= yMin() && y <= yMax()); + _dbn.fill(x, y, z, weight); + } + + /// Fill the bin at the midpoint with a given z value + void fillBin(double z, double weight=1.0){ + fill(midpoint().first, midpoint().second, z, weight); + } + + //@} + + public: + + /// @name Bin content info + //@{ + + double mean() const { + return _dbn.zMean(); + } + + double stdDev() const { + return _dbn.zStdDev(); + } + + double variance() const { + return _dbn.zVariance(); + } + + double stdErr() const { + return _dbn.zStdErr(); + } + + //@} + + /// @name Raw z distribution statistics + //@{ + + ///@todo: Check if it is correct + + /// The sum of z*weight + double sumWZ() const { + return _dbn.sumWX(); + } + + double sumWZ2() const { + return _dbn.sumWX2(); + } + + //@} + + public: + + /// Add two bins (for use by Profile2D) + ProfileBin2D& operator += (const ProfileBin2D& toAdd) { + return add(toAdd); + } + + ProfileBin2D& operator -= (const ProfileBin2D& toSubtract) { + return subtract(toSubtract); + } + + protected: + + /// Add two bins + ProfileBin2D& add(const ProfileBin2D& pb) { + Bin2D<Dbn3D>::add(pb); + return *this; + } + + /// Subtract one bin from another + ProfileBin2D& subtract(const ProfileBin2D& pb) { + Bin2D<Dbn3D>::subtract(pb); + return *this; + } + }; + + inline ProfileBin2D operator + (const ProfileBin2D& a, const ProfileBin2D& b) { + ProfileBin2D rtn(a); + rtn += a; + return rtn; + } + + inline ProfileBin2D operator - (const ProfileBin2D& a, const ProfileBin2D& b) { + ProfileBin2D rtn(a); + rtn -= a; + return rtn; + } + +} + +#endif + Modified: trunk/src/Histo2D.cc ============================================================================== --- trunk/src/Histo2D.cc Sun Aug 28 15:11:13 2011 (r378) +++ trunk/src/Histo2D.cc Sun Aug 28 21:30:56 2011 (r379) @@ -224,8 +224,8 @@ assert(fuzzyEquals(b1.midpoint().first, b2.midpoint().first)); assert(fuzzyEquals(b1.midpoint().second, b2.midpoint().second)); - const double x = bL.focus().first; - const double y = bL.focus().second; + const double x = bL.focus().first/2; + const double y = bL.focus().second/2; const double exminus = x - bL.xMin(); const double explus = bL.xMax() - x; Modified: trunk/src/Profile1D.cc ============================================================================== --- trunk/src/Profile1D.cc Sun Aug 28 15:11:13 2011 (r378) +++ trunk/src/Profile1D.cc Sun Aug 28 21:30:56 2011 (r379) @@ -92,6 +92,7 @@ for (size_t i = 0; i < numer.numBins(); ++i) { const ProfileBin1D& b1 = numer.bin(i); const ProfileBin1D& b2 = denom.bin(i); + assert(fuzzyEquals(b1.focus(), b2.focus())); const double x = b1.focus(); assert(fuzzyEquals(b1.xMin(), b2.xMin())); Modified: trunk/src/Profile2D.cc ============================================================================== --- trunk/src/Profile2D.cc Sun Aug 28 15:11:13 2011 (r378) +++ trunk/src/Profile2D.cc Sun Aug 28 21:30:56 2011 (r379) @@ -1,3 +1,72 @@ #include "YODA/Profile2D.h" +#include "YODA/Scatter3D.h" +#include "YODA/Histo2D.h" -namespace YODA { } +namespace YODA { + + void Profile2D::fill(double x, double y, double z, double weight) { + _axis.fill(x, y, z, weight); + } + + double Profile2D::sumW(bool includeoverflows) const { + if (includeoverflows) return _axis.totalDbn().sumW2(); + double sumw = 0; + foreach (const ProfileBin2D& b, bins()) { + sumw += b.sumW(); + } + return sumw; + } + + double Profile2D::sumW2(bool includeoverflows) const { + if (includeoverflows) return _axis.totalDbn().sumW2(); + double sumw = 0; + foreach (const ProfileBin2D& b, bins()) { + sumw += b.sumW(); + } + return sumw; + } + + /// Constructor from a Scatter3D's binning, with optional new path + Profile2D::Profile2D(const Scatter3D& s, const std::string& path) + : AnalysisObject("Profile2D", (path.size() == 0) ? s.path() : path, s, s.title()) + { + throw "IMPLEMENT"; + std::vector<ProfileBin2D> bins; + foreach (const Scatter3D::Point& p, s.points()) { + bins.push_back(ProfileBin2D(p.xMin(), p.yMin(), p.xMax(), p.yMax())); + } + //_axis = Profile2DAxis(bins); + } + + /// Constructor from a Histo2D's binning, with optional new path + Profile2D::Profile2D(const Histo2D& h, const std::string& path) + : AnalysisObject("Profile2D", (path.size() == 0) ? h.path() : path, h, h.title()) + { + throw "IMPLEMENT"; + Bins bins; + //foreach (const Histo2D::Bin<Dbn2D>& b, h.bins()) { + // bins.push_back(ProfileBin2D(b.xMin(), b.yMin(), b.xMax(), b.yMax())); + //} + //_axis = Profile2DAxis(bins); + } + + /// Divide two profile histograms + Scatter3D divide(const Profile2D& numer, const Profile2D& denom) { + throw "IMPLEMENT!"; + //assert(numer._axis == denom._axis); + Scatter3D tmp; + for (size_t i = 0; i < numer.numBins(); ++i) { + const ProfileBin2D& b1 = numer.bin(i); + const ProfileBin2D& b2 = denom.bin(i); + const ProfileBin2D& bA = b1 + b2; + + assert(fuzzyEquals(b1.focus().first, b2.focus().first)); + assert(fuzzyEquals(b1.focus().second, b2.focus().second)); + + const double x = bA.focus().first/2; + const double y = bA.focus().second/2; + const double z = b1.mean()/b2.mean();; + } + } + //return Scatter3D(); + }
More information about the yoda-svn mailing list |