[yoda-svn] r408 - in trunk: . include/YODA src

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Dec 6 16:10:44 GMT 2011


Author: buckley
Date: Tue Dec  6 16:10:44 2011
New Revision: 408

Log:
Adding normalize() methods to Histo1D/2D.

Modified:
   trunk/ChangeLog
   trunk/include/YODA/Histo1D.h
   trunk/include/YODA/Histo2D.h
   trunk/src/Histo2D.cc
   trunk/src/Scatter3D.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Tue Dec  6 15:44:34 2011	(r407)
+++ trunk/ChangeLog	Tue Dec  6 16:10:44 2011	(r408)
@@ -1,5 +1,7 @@
 2011-12-06  Andy Buckley  <andy.buckley at cern.ch>
 
+	* Adding normalize() methods to Histo1D/2D.
+
 	* Adding weighted RMS calculating methods to Dbn1D, Dbn2D and
 	Bin1D/2D.
 

Modified: trunk/include/YODA/Histo1D.h
==============================================================================
--- trunk/include/YODA/Histo1D.h	Tue Dec  6 15:44:34 2011	(r407)
+++ trunk/include/YODA/Histo1D.h	Tue Dec  6 16:10:44 2011	(r408)
@@ -113,6 +113,16 @@
     }
 
 
+    /// Normalize the (visible) histo area to the @a normto value.
+    ///
+    /// If @a includeoverflows is true, the original normalisation is computed with
+    /// the overflow bins included, so that the resulting visible normalisation can
+    /// be less than @a normto. This is probably what you want.
+    void normalize(double normto=1.0, bool includeoverflows=true) {
+      _axis.scaleW(normto / integral(includeoverflows));
+    }
+
+
     /// Merge together the bin range with indices from @a from to @a to, inclusive
     void mergeBins(size_t from, size_t to) {
       _axis.mergeBins(from, to);

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Tue Dec  6 15:44:34 2011	(r407)
+++ trunk/include/YODA/Histo2D.h	Tue Dec  6 16:10:44 2011	(r408)
@@ -60,7 +60,7 @@
       : AnalysisObject("Histo2D", path, title),
       _axis(binedges)
     { }
-    
+
     /// Constructor accepting the bin edges on X and Y axis.
     Histo2D(const std::vector<double>& xedges, const std::vector<double>& yedges,
             const std::string& path="", const std::string& title="")
@@ -109,6 +109,17 @@
       _axis.scaleW(scalefactor);
     }
 
+
+    /// Normalize the (visible) histo "volume" to the @a normto value.
+    ///
+    /// If @a includeoverflows is true, the original normalisation is computed with
+    /// the overflow bins included, so that the resulting visible normalisation can
+    /// be less than @a normto. This is probably what you want.
+    void normalize(double normto=1.0, bool includeoverflows=true) {
+      _axis.scaleW(normto / integral(includeoverflows));
+    }
+
+
     /// Scale the dimensions
     void scaleXY(double scaleX = 1.0, double scaleY = 1.0) {
       _axis.scaleXY(scaleX, scaleY);
@@ -223,21 +234,17 @@
       return _axis.getBinIndex(coordX, coordY);
     }
 
-    /// @todo Deprecated, remove
-    const size_t numBinsTotal() const {
-      return _axis.numBins();
-    }
-
+    /// Number of bins
     const size_t numBins() const {
       return _axis.numBins();
     }
 
-    /// Return number of bins along X axis
+    /// Number of bins along the x axis
     const size_t numBinsX() const {
       return _axis.numBinsX();
     }
 
-    /// Return the number of bins along Y axis
+    /// Number of bins along the y axis
     const size_t numBinsY() const{
       return _axis.numBinsY();
     }

Modified: trunk/src/Histo2D.cc
==============================================================================
--- trunk/src/Histo2D.cc	Tue Dec  6 15:44:34 2011	(r407)
+++ trunk/src/Histo2D.cc	Tue Dec  6 16:10:44 2011	(r408)
@@ -219,7 +219,7 @@
   Scatter3D divide(const Histo2D& numer, const Histo2D& denom) {
     if (numer != denom) throw GridError("The two histos are not equivalently binned!");
     Scatter3D tmp;
-    for (size_t i = 0; i < numer.numBinsTotal(); ++i) {
+    for (size_t i = 0; i < numer.numBins(); ++i) {
       const HistoBin2D& b1 = numer.bin(i);
       const HistoBin2D& b2 = denom.binByCoord(b1.midpoint().first, b1.midpoint().second);
       const HistoBin2D& bL = b1 + b2;
@@ -240,7 +240,7 @@
       tmp.addPoint(x, exminus, explus, y, eyminus, eyplus, z, ez, ez);
     }
 
-    assert(tmp.numPoints() == numer.numBinsTotal());
+    assert(tmp.numPoints() == numer.numBins());
     return tmp;
   }
 

Modified: trunk/src/Scatter3D.cc
==============================================================================
--- trunk/src/Scatter3D.cc	Tue Dec  6 15:44:34 2011	(r407)
+++ trunk/src/Scatter3D.cc	Tue Dec  6 16:10:44 2011	(r408)
@@ -30,7 +30,7 @@
     Scatter3D ret;
     ret.setAnnotations(h.annotations());
     ret.setAnnotation("Type", h.type());
-    for (size_t i = 0; i < h.numBinsTotal(); ++i) {
+    for (size_t i = 0; i < h.numBins(); ++i) {
       const HistoBin2D& bin = h.bin(i);
 
       const double x = bin.focus().first;


More information about the yoda-svn mailing list