|
[yoda-svn] r281 - in trunk: include/YODA src testsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Aug 18 16:10:33 BST 2011
Author: mkawalec Date: Thu Aug 18 16:10:32 2011 New Revision: 281 Log: Moved isGhost() from Bin2D to Axis2D, by boundling each bin with a bool in a _bins vector. Not properly documented yet. Changed Histo2D division operator to output in the focus of the sum of the two bins. Modified: trunk/include/YODA/Axis2D.h trunk/include/YODA/Bin2D.h trunk/include/YODA/Histo2D.h trunk/src/Bin2D.cc trunk/src/Histo2D.cc trunk/tests/TestHisto2D.cc Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Thu Aug 18 14:55:42 2011 (r280) +++ trunk/include/YODA/Axis2D.h Thu Aug 18 16:10:32 2011 (r281) @@ -48,7 +48,7 @@ // A few helpful typedefs typedef BIN Bin; - typedef typename std::vector<BIN> Bins; + typedef typename std::vector<std::pair<Bin, bool> > Bins; public: @@ -100,8 +100,8 @@ { vector<Segment> binLimits; for (size_t i = 0; i < bins.size(); ++i) { - binLimits.push_back(make_pair(make_pair(bins[i].xMin(), bins[i].yMin()), - make_pair(bins[i].xMax(), bins[i].yMax()))); + binLimits.push_back(make_pair(make_pair(bins[i].first.xMin(), bins[i].first.yMin()), + make_pair(bins[i].first.xMax(), bins[i].first.yMax()))); } _mkAxis(binLimits); for (size_t i = 0; i < _bins.size(); ++i) { @@ -114,7 +114,7 @@ _dbn = totalDbn; } - /// A constructor with specified X and Y axis ticks. + /// A constructor with specified X and Y axis bin limits. Axis2D(const std::vector<double>& xedges, const std::vector<double>& yedges) { vector<Segment> binLimits; @@ -183,7 +183,7 @@ /// Filling a bin if the coordinates point to one. int index = getBinIndex(x, y); - if(index != -1) _bins[index].fill(x, y, weight); + if(index != -1) _bins[index].first.fill(x, y, weight); /// If coordinates point outside any of the bins and /// and the outflows were properly set (i.e. we are dealing @@ -202,8 +202,7 @@ HistoBin2D& start = bin(from); HistoBin2D& end = bin(to); HistoBin2D temp = start; - /// @todo Yuck! - start.isGhost() = true; + _bins[from].second = false; if (start.midpoint().first > end.midpoint().first || start.midpoint().second > end.midpoint().second) @@ -218,18 +217,18 @@ fuzzyEquals(_binHashSparse.first[y].second[x].second.first, start.xMin())) && (_binHashSparse.first[y].second[x].second.second < end.xMax() || fuzzyEquals(_binHashSparse.first[y].second[x].second.second, end.xMax())) && - bin(!_binHashSparse.first[y].second[x].first).isGhost()) + _bins[_binHashSparse.first[y].second[x].first].second) { temp += bin(_binHashSparse.first[y].second[x].first); /// @todo This sort of setting via a reference is quite confusing -- since Axis2D is a friend, /// just use the _isGhost member. Or, better IMO, do all the "ghost" bookkeeping purely on /// the axis and avoid storing an axis implementation feature on *all* the bins. - bin(_binHashSparse.first[y].second[x].first).isGhost() = true; + _bins[_binHashSparse.first[y].second[x].first].second = false; } } } _addEdge(temp.edges(), _binHashSparse, false); - _bins.push_back(temp); + _bins.push_back(make_pair(temp, true)); _binHashSparse.first.regenCache(); _binHashSparse.second.regenCache(); @@ -242,7 +241,7 @@ { _dbn.reset(); for (size_t i = 0; i < _bins.size(); ++i) { - _bins[i].reset(); + _bins[i].first.reset(); } } @@ -314,13 +313,13 @@ /// Get the bin with a given index (non-const version) BIN& bin(size_t index) { if (index >= _bins.size()) throw RangeError("Bin index out of range."); - return _bins[index]; + return _bins[index].first; } /// Get the bin with a given index (const version) const BIN& bin(size_t index) const { if (index >= _bins.size()) throw RangeError("Bin index out of range."); - return _bins[index]; + return _bins[index].first; } @@ -367,9 +366,9 @@ /// interest. const int getBinIndex(double coordX, double coordY) const { for (size_t i = 0; i < _bins.size(); ++i) { - if (_bins[i].xMin() <= coordX && _bins[i].xMax() >= coordX && - _bins[i].yMin() <= coordY && _bins[i].yMax() >= coordY && - !_bins[i].isGhost()) return i; + if (_bins[i].first.xMin() <= coordX && _bins[i].first.xMax() >= coordX && + _bins[i].first.yMin() <= coordY && _bins[i].first.yMax() >= coordY && + _bins[i].second) return i; } return -1; } @@ -409,7 +408,7 @@ /// Now, as we have the map rescaled, we need to update the bins for (size_t i = 0; i < _bins.size(); ++i) { - _bins[i].scaleXY(scaleX, scaleY); + _bins[i].first.scaleXY(scaleX, scaleY); } _dbn.scaleXY(scaleX, scaleY); @@ -435,7 +434,7 @@ } /// @todo Use foreach for situations like this for (size_t i = 0; i < _bins.size(); ++i) { - _bins[i].scaleW(scalefactor); + _bins[i].first.scaleW(scalefactor); } } @@ -463,7 +462,7 @@ throw LogicError("YODA::Histo1D: Cannot add axes with different binnings."); } for (size_t i = 0; i < bins().size(); ++i) { - bins().at(i) += toAdd.bins().at(i); + bin(i) += toAdd.bin(i); } _dbn += toAdd._dbn; return *this; @@ -479,7 +478,7 @@ throw LogicError("YODA::Histo1D: Cannot add axes with different binnings."); } for (size_t i = 0; i < bins().size(); ++i) { - bins().at(i) -= toSubtract.bins().at(i); + bin(i) -= toSubtract.bin(i); } _dbn -= toSubtract._dbn; return *this; @@ -808,7 +807,7 @@ } // Now, create a bin with the edges provided - if (addBin) _bins.push_back(BIN(edges)); + if (addBin) _bins.push_back(make_pair(BIN(edges), true)); } @@ -899,10 +898,10 @@ // Scroll through the bins and set the delimiters. for (size_t i = 0; i < _bins.size(); ++i) { - if (_bins[i].xMin() < lowEdgeX) lowEdgeX = _bins[i].xMin(); - if (_bins[i].xMax() > highEdgeX) highEdgeX = _bins[i].xMax(); - if (_bins[i].yMin() < lowEdgeY) lowEdgeY = _bins[i].yMin(); - if (_bins[i].yMax() > highEdgeY) highEdgeY = _bins[i].yMax(); + if (_bins[i].first.xMin() < lowEdgeX) lowEdgeX = _bins[i].first.xMin(); + if (_bins[i].first.xMax() > highEdgeX) highEdgeX = _bins[i].first.xMax(); + if (_bins[i].first.yMin() < lowEdgeY) lowEdgeY = _bins[i].first.yMin(); + if (_bins[i].first.yMax() > highEdgeY) highEdgeY = _bins[i].first.yMax(); } _lowEdgeX = lowEdgeX; Modified: trunk/include/YODA/Bin2D.h ============================================================================== --- trunk/include/YODA/Bin2D.h Thu Aug 18 14:55:42 2011 (r280) +++ trunk/include/YODA/Bin2D.h Thu Aug 18 16:10:32 2011 (r281) @@ -218,31 +218,7 @@ } //@} - - /// @name _isGhost accessor - /// @todo Improve Doxygen description -- it needs to actually explain what this *means* - /// @todo IMO this would be better implemented as a bookkeeping device on Axis2D, storing - /// a list of bin IDs to not write out -- it's ~purely a persistency trick, right? At the - /// moment we're storing an extra bool on every bin for a feature which will not appear in - /// > 99% of cases. - //@{ - - /// non-const version - /// - /// @todo Improve Doxygen description (including Capitalising like proper text!) - /// @todo What is the point of this method? - bool& isGhost() { - return _isGhost; - } - - /// const version - /// @todo Improve Doxygen description (including Capitalising like proper text!) - const bool isGhost() const { - return _isGhost; - } - - //@} - + protected: /// Boundaries setter @@ -263,12 +239,6 @@ Segment _edges; Dbn2D _dbn; - - protected: - - /// A variable that specifies if the bin should be plotted - bool _isGhost; - }; Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Thu Aug 18 14:55:42 2011 (r280) +++ trunk/include/YODA/Histo2D.h Thu Aug 18 16:10:32 2011 (r281) @@ -73,7 +73,7 @@ /// @brief State-setting constructor /// Mainly intended for internal persistency use. - Histo2D(const std::vector<HistoBin2D>& bins, + Histo2D(const std::vector<std::pair<HistoBin2D, bool> >& bins, const std::vector<std::vector<Dbn2D> >& outflows, const Dbn2D& totalDbn, const std::string& path="", const std::string& title="") @@ -155,23 +155,23 @@ } /// Access the bin vector (non-const version) - std::vector<YODA::HistoBin2D>& bins() { + std::vector<std::pair<YODA::HistoBin2D, bool> >& bins() { return _axis.bins(); } /// Access the bin vector (const version) - const std::vector<YODA::HistoBin2D>& bins() const { + const std::vector<std::pair<YODA::HistoBin2D, bool > >& bins() const { return _axis.bins(); } /// Access a bin by index (non-const version) HistoBin2D& bin(size_t index) { - return _axis.bins()[index]; + return _axis.bin(index); } /// Access a bin by index (const version) const HistoBin2D& bin(size_t index) const { - return _axis.bins()[index]; + return _axis.bin(index); } /// Access a bin by coordinate (non-const version) @@ -461,8 +461,8 @@ /// @brief Divide two histograms /// - /// This uses the midpoint instead of the focus - /// @todo Set the output to be the focus of the new distribution + /// Keep in mind that for the following to work, two Histos must + /// be _exactly_ the same, including the ghost bins. Scatter3D operator / (const Histo2D& numer, const Histo2D& denom); //@} Modified: trunk/src/Bin2D.cc ============================================================================== --- trunk/src/Bin2D.cc Thu Aug 18 14:55:42 2011 (r280) +++ trunk/src/Bin2D.cc Thu Aug 18 16:10:32 2011 (r281) @@ -20,8 +20,6 @@ _edges.first.second = lowedgeY; _edges.second.first = highedgeX; _edges.second.second = highedgeY; - - isGhost() = false; } @@ -33,14 +31,11 @@ _edges.first.second = edges[0].first.second; _edges.second.first = edges[1].second.first; _edges.second.second = edges[1].second.second; - - isGhost() = false; } Bin2D::Bin2D(const Bin2D& b) { _edges = b._edges; _dbn = b._dbn; - _isGhost =b._isGhost; } void Bin2D::scaleXY(double scaleX, double scaleY) { Modified: trunk/src/Histo2D.cc ============================================================================== --- trunk/src/Histo2D.cc Thu Aug 18 14:55:42 2011 (r280) +++ trunk/src/Histo2D.cc Thu Aug 18 16:10:32 2011 (r281) @@ -22,9 +22,7 @@ double Histo2D::sumW(bool includeoverflows) const { if (includeoverflows) return _axis.totalDbn().sumW(); double sumw = 0; - foreach (const Bin& b, bins()) { - sumw += b.sumW(); - } + for(size_t i = 0; i < bins().size(); ++i) sumw += bin(i).sumW(); return sumw; } @@ -32,9 +30,7 @@ double Histo2D::sumW2(bool includeoverflows) const { if (includeoverflows) return _axis.totalDbn().sumW2(); double sumw2 = 0; - foreach (const Bin& b, bins()) { - sumw2 += b.sumW2(); - } + for(size_t i = 0; i < bins().size(); ++i) sumw2+= bin(i).sumW2(); return sumw2; } @@ -43,9 +39,9 @@ if (includeoverflows) return _axis.totalDbn().xMean(); double sumwx = 0; double sumw = 0; - foreach (const Bin2D& b, bins()) { - sumwx += b.sumWX(); - sumw += b.sumW(); + for(size_t i = 0; i < bins().size(); ++i) { + sumwx += bin(i).sumW2(); + sumw += bin(i).sumW(); } return sumwx/sumw; } @@ -55,9 +51,9 @@ if (includeoverflows) return _axis.totalDbn().yMean(); double sumwy = 0; double sumw = 0; - foreach (const Bin2D& b, bins()) { - sumwy += b.sumWY(); - sumw += b.sumW(); + for(size_t i = 0; i < bins().size(); ++i) { + sumwy += bin(i).sumWY(); + sumw += bin(i).sumW(); } return sumwy/sumw; } @@ -67,9 +63,9 @@ if (includeoverflows) return _axis.totalDbn().xVariance(); double sigma2 = 0; const double xMean = this->xMean(); - foreach (const Bin2D& b, bins()) { - const double diff = b.focus().first - xMean; - sigma2 += diff * diff * b.sumW(); + for(size_t i = 0; i < bins().size(); ++i) { + const double diff = bin(i).focus().first - xMean; + sigma2 += diff * diff * bin(i).sumW(); } return sigma2/sumW(); } @@ -79,9 +75,9 @@ if (includeoverflows) return _axis.totalDbn().yVariance(); double sigma2 = 0; const double yMean = this->yMean(); - foreach (const Bin2D& b, bins()) { - const double diff = b.focus().first - yMean; - sigma2 += diff * diff * b.sumW(); + for(size_t i = 0; i < bins().size(); ++i) { + const double diff = bin(i).focus().first - yMean; + sigma2 += diff * diff * bin(i).sumW(); } return sigma2/sumW(); } Modified: trunk/tests/TestHisto2D.cc ============================================================================== --- trunk/tests/TestHisto2D.cc Thu Aug 18 14:55:42 2011 (r280) +++ trunk/tests/TestHisto2D.cc Thu Aug 18 16:10:32 2011 (r281) @@ -40,7 +40,6 @@ gettimeofday(&startTime, NULL); Histo2D h(200, 0, 100, 200, 0, 100); gettimeofday(&endTime, NULL); - cout << h.binByCoord(1,1).isGhost() << endl; double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
More information about the yoda-svn mailing list |