[Rivet-svn] rivet: Handle BinnedHistogram::fill() calls that don't land in b...

Rivet Mercurial rivet at projects.hepforge.org
Mon Jun 12 14:15:01 BST 2017


details:   https://rivet.hepforge.org/hg/rivet/rev/07aca1ca99ff
branches:  release-2-5-x
changeset: 5815:07aca1ca99ff
user:      Andy Buckley <andy at insectnation.org>
date:      Mon Jun 12 14:01:53 2017 +0100
description:
Handle BinnedHistogram::fill() calls that don't land in bins, via RangeError exception throwing and a minor interface tweak

diffs (truncated from 92 to 50 lines):

--- a/include/Rivet/Tools/BinnedHistogram.hh	Mon Jun 12 11:00:48 2017 +0100
+++ b/include/Rivet/Tools/BinnedHistogram.hh	Mon Jun 12 14:01:53 2017 +0100
@@ -43,12 +43,14 @@
 
 
     /// Fill the histogram in the same bin as @a binval with value @a val and weight @a weight
-    Histo1DPtr fill(const T& binval, double val, double weight);
+    void fill(const T& binval, double val, double weight);
 
 
-    /// Get the histogram in the same bin as @a binval (const)
+    /// @brief Get the histogram in the same bin as @a binval (const)
+    /// @note Throws a RangeError if @a binval doesn't fall in a declared bin
     const Histo1DPtr histo(const T& binval) const;
-    /// Get the histogram in the same bin as @a binval
+    /// @brief Get the histogram in the same bin as @a binval
+    /// @note Throws a RangeError if @a binval doesn't fall in a declared bin
     Histo1DPtr histo(const T& binval);
 
     /// Get the contained histograms (const)
@@ -62,7 +64,7 @@
 
 
     /// Scale histograms taking into account its "external" binwidth, i.e. by scale/binWidth
-    /// @note Urgh...
+    /// @note The Analysis pointer is passed in order to call the analysis' scale(h) method: can we avoid that?
     void scale(const T& scale, Analysis* ana);
 
 
--- a/src/Tools/BinnedHistogram.cc	Mon Jun 12 11:00:48 2017 +0100
+++ b/src/Tools/BinnedHistogram.cc	Mon Jun 12 14:01:53 2017 +0100
@@ -8,9 +8,7 @@
 
   template<typename T>
   const BinnedHistogram<T>& BinnedHistogram<T>::add(const T& binMin, const T& binMax, Histo1DPtr histo) {
-    if (binMin > binMax) {
-      throw Error("Cannot add a binned histogram where the lower bin edge is above the upper edge");
-    }
+    if (binMin > binMax) throw RangeError("Cannot add a binned histogram where the lower bin edge is above the upper edge");
     _histosByUpperBound[binMax] = histo;
     _histosByLowerBound[binMin] = histo;
     bool found = false;
@@ -23,7 +21,7 @@
 
     if (!found){
       _histos.push_back(histo);
-      _binWidths[histo]=binMax-binMin;
+      _binWidths[histo] = binMax-binMin;
     }
 


More information about the Rivet-svn mailing list