|
[yoda-svn] r256 - in trunk: include/YODA src testsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgWed Aug 17 11:22:01 BST 2011
Author: mkawalec Date: Wed Aug 17 11:22:00 2011 New Revision: 256 Log: Added/fixed bin merging, some serious compilation-time bugs. Modified: trunk/include/YODA/Axis2D.h trunk/include/YODA/Bin2D.h trunk/include/YODA/Histo2D.h trunk/include/YODA/HistoBin2D.h trunk/src/Bin2D.cc trunk/src/Dbn1D.cc trunk/src/Histo2D.cc trunk/tests/TestHisto2D.cc Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Tue Aug 16 15:41:37 2011 (r255) +++ trunk/include/YODA/Axis2D.h Wed Aug 17 11:22:00 2011 (r256) @@ -4,7 +4,6 @@ #include "YODA/AnalysisObject.h" #include "YODA/Exceptions.h" #include "YODA/Bin.h" -#include "YODA/Utils/sortedvector.h" #include "YODA/Utils/cachedvector.h" #include "YODA/Utils/MathUtils.h" #include "YODA/Dbn2D.h" @@ -14,6 +13,7 @@ #include <cmath> #include <algorithm> #include <limits> +#include <sys/time.h> /// @todo Remove this: don't use namespace std in API headers since it pollutes users' namespace. using namespace std; @@ -68,6 +68,7 @@ /// Constructor provided with a vector of bin delimiters Axis2D(const vector<Segment>& binLimits) { _mkAxis(binLimits); + if(isGriddy()) _setOutflows(); } @@ -82,6 +83,7 @@ } } _mkAxis(binLimits); + _setOutflows(); } @@ -97,6 +99,8 @@ for (size_t i = 0; i < _bins.size(); ++i) { _bins[i] = bins[i]; } + _regenDelimiters(); + if(isGriddy()) _setOutflows(); } //@} @@ -114,8 +118,9 @@ /// for merging for '+' operator (codewise it should be the same thing). void addBin(const vector<Segment>& binLimits) { _mkAxis(binLimits); + _outflows.resize(0); } - + /// @brief Bin addition operator /// This operator is supplied with whe extreamal coordinates of just /// one bin. It then launches the standard bin addition procedure. @@ -127,10 +132,39 @@ //@} - /// @name Helper functions //@{ + /// Outflow filler + void fillOutflows(double x, double y, double weight) { + if(x < _lowEdgeX && y > _highEdgeY) _outflows[0][0].fill(x, y, 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, weight); + } + else if(x > _highEdgeX && y > _highEdgeY) _outflows[2][0].fill(x, y, 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, weight); + } + else if(x > _highEdgeX && y < _lowEdgeY) _outflows[4][0].fill(x, y, 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, weight); + } + else if(x < _lowEdgeX && y < _lowEdgeY) _outflows[6][0].fill(x, y, 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, weight); + } + + } + + /// @brief Bin merging /// Try to merge a certain amount of bins void mergeBins(size_t from, size_t to) { @@ -248,7 +282,15 @@ const Bins& bins() const { return _bins; } - + + /// Get the outflows (non-const version) + vector<vector<Dbn2D> >& outflows() { + return _outflows; + } + /// Get the outflows (const version) + const vector<vector<Dbn2D> >& outflows() const { + return _outflows; + } /// Get the bin with a given index (non-const version) BIN& bin(size_t index) { @@ -444,6 +486,21 @@ private: + void _setOutflows() { + _outflows.resize(8); + + _outflows[0].resize(1); + _outflows[1].resize(_binHashSparse.second.size()); + _outflows[2].resize(1); + _outflows[3].resize(_binHashSparse.first.size()); + _outflows[4].resize(1); + _outflows[5].resize(_binHashSparse.second.size()); + _outflows[6].resize(1); + _outflows[7].resize(_binHashSparse.first.size()); + + } + + /// @brief Segment validator function /// /// This a 'dispatcher' function. It checks if the segment in question @@ -789,6 +846,7 @@ // /// @todo Need many (binned?) outflows instead. This can't work at the moment. // Dbn2D _underflow; // Dbn2D _overflow; + vector<vector<Dbn2D> > _outflows; /// The total distribution Dbn2D _dbn; Modified: trunk/include/YODA/Bin2D.h ============================================================================== --- trunk/include/YODA/Bin2D.h Tue Aug 16 15:41:37 2011 (r255) +++ trunk/include/YODA/Bin2D.h Wed Aug 17 11:22:00 2011 (r256) @@ -6,7 +6,6 @@ #include <string> #include <utility> #include <vector> -#include <iostream> #include <cassert> /// @todo Remove this: don't use namespace std in API headers since it pollutes users' namespace. Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Tue Aug 16 15:41:37 2011 (r255) +++ trunk/include/YODA/Histo2D.h Wed Aug 17 11:22:00 2011 (r256) @@ -101,7 +101,7 @@ /// Check if this binning is a grid /// @todo Really expose this on the public API? - int isGriddy() { + bool isGriddy() { return _axis.isGriddy(); } Modified: trunk/include/YODA/HistoBin2D.h ============================================================================== --- trunk/include/YODA/HistoBin2D.h Tue Aug 16 15:41:37 2011 (r255) +++ trunk/include/YODA/HistoBin2D.h Wed Aug 17 11:22:00 2011 (r256) @@ -3,7 +3,9 @@ #include "YODA/Bin2D.h" #include "YODA/Exceptions.h" + #include <cmath> +#include <sys/time.h> namespace YODA { @@ -40,8 +42,8 @@ //@{ /// A fill() function accepting coordinates as spearate numbers - void fill(double coordX, double coordY, double weight=1.0) { - _dbn.fill(coordX, coordY, weight); + void fill(double X, double Y, double weight=1.0) { + _dbn.fill(X, Y, weight); } /// A fill() function accepting the coordinates as std::pair Modified: trunk/src/Bin2D.cc ============================================================================== --- trunk/src/Bin2D.cc Tue Aug 16 15:41:37 2011 (r255) +++ trunk/src/Bin2D.cc Wed Aug 17 11:22:00 2011 (r256) @@ -10,6 +10,8 @@ using namespace std; namespace YODA { + typedef typename std::pair<double, double> Point; + typedef typename std::pair<Point, Point> Segment; Bin2D::Bin2D(double lowedgeX, double lowedgeY, double highedgeX, double highedgeY) { @@ -25,18 +27,17 @@ } - // Bin2D::Bin2D(std::vector<std::pair<std::pair<double,double>, - // std::pair<double,double> > > edges) { - // if (edges.size() != 4) { - // throw RangeError("The edge vector does not define a full rectangle!"); - // } - // _edges.first.first = edges[0].first.first; - // _edges.first.second = edges[0].first.second; - // _edges.second.first = edges[1].second.first; - // _edges.second.second = edges[1].second.second; + Bin2D::Bin2D(const std::vector<Segment>& edges) { + if (edges.size() != 4) { + throw RangeError("The edge vector does not define a full rectangle!"); + } + _edges.first.first = edges[0].first.first; + _edges.first.second = edges[0].first.second; + _edges.second.first = edges[1].second.first; + _edges.second.second = edges[1].second.second; - // isReal = true; - // } + isReal = true; + } void Bin2D::scaleXY(double scaleX, double scaleY) { Modified: trunk/src/Dbn1D.cc ============================================================================== --- trunk/src/Dbn1D.cc Tue Aug 16 15:41:37 2011 (r255) +++ trunk/src/Dbn1D.cc Wed Aug 17 11:22:00 2011 (r256) @@ -4,7 +4,6 @@ // Copyright (C) 2008-2011 The YODA collaboration (see AUTHORS for details) // #include "YODA/Dbn1D.h" -#include <iostream> namespace YODA { Modified: trunk/src/Histo2D.cc ============================================================================== --- trunk/src/Histo2D.cc Tue Aug 16 15:41:37 2011 (r255) +++ trunk/src/Histo2D.cc Wed Aug 17 11:22:00 2011 (r256) @@ -17,21 +17,14 @@ int Histo2D::fill(double x, double y, double weight) { - // Fill the normal bins - int index = findBinIndex(x, y); - if (index != -1) { - HistoBin2D& b = bin(index); + _axis.totalDbn().fill(x, y, weight); - // Fill the total and outflow distributions - _axis.totalDbn().fill(x, y, weight); - /// @todo Fill the underflow and overflow nicely - - b.fill(x, y, weight); + int index = _axis.getBinIndex(x, y); + if(index != -1) { + HistoBin2D& bin = _axis.bin(index); + bin.fill(x, y, weight); } - - // else if (x < _axis.lowEdgeX()) { _axis.underflow().fill(x, y, weight); } - // else if (x >= _axis.highEdgeX()) { _axis.overflow().fill(x, y, weight); } - else throw GridError("You are trying to fill an empty space on a grid!"); + else if(_axis.outflows().size() == 8) _axis.fillOutflows(x, y, weight); return index; } Modified: trunk/tests/TestHisto2D.cc ============================================================================== --- trunk/tests/TestHisto2D.cc Tue Aug 16 15:41:37 2011 (r255) +++ trunk/tests/TestHisto2D.cc Wed Aug 17 11:22:00 2011 (r256) @@ -47,12 +47,6 @@ printStats(h); - cout << h.numBinsTotal() << endl; - h.addBin(0.1, 0.1, 0.2, 0.2); - h.addBin(110, 0, 200, 12.100); - h.addBin(16.0, 200, 17.0, 300); - - /// Trying to fill a bin. gettimeofday(&startTime, NULL); for (int i=0; i < 2000; i++) { @@ -71,6 +65,12 @@ cout << "Performance is not sufficient. Probably broken caches?" << endl; return -1; } + cout << h.numBinsTotal() << endl; + h.addBin(0.1, 0.1, 0.2, 0.2); + h.addBin(110, 0, 200, 12.100); + h.addBin(16.0, 200, 17.0, 300); + + printStats(h, false); cout << h.numBinsTotal() << endl;
More information about the yoda-svn mailing list |