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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Nov 16 14:06:53 GMT 2012


Author: buckley
Date: Fri Nov 16 14:06:52 2012
New Revision: 541

Log:
Adding toIntegralHisto(Histo1D&) function.

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

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Thu Nov 15 18:26:09 2012	(r540)
+++ trunk/ChangeLog	Fri Nov 16 14:06:52 2012	(r541)
@@ -1,3 +1,7 @@
+2012-11-16  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Adding toIntegralHisto(Histo1D&) function.
+
 2012-11-15  Dave Mallows  <dave.mallows at gmail.com>
 
 	* Commited numerous changes to Axis2D. Axis2D now uses BinSearcher as

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Thu Nov 15 18:26:09 2012	(r540)
+++ trunk/TODO	Fri Nov 16 14:06:52 2012	(r541)
@@ -22,16 +22,16 @@
 
 * WriterFlat, for Scatter2D representations only. (HH)
 
-* Transform 1D differential to integral histos and vice versa.
-   Bins have to be contiguous. Scatter -> Scatter, and Histo1D -> Scatter (AB)
+* Add a goodness of fit test collection (AB)
+   Simple GoF measures, such as chi2 of a bin and of a histo (chained), for 1D
+   and 2D Histos, Profiles and Scatters. Also KS (later)?
 
+* ROOT analysis type converter functions
+   In YODA/ROOTCnv.h -- pure header library to avoid bild-time ROOT dependence
 
 
 NEXT
 
-* ROOT analysis type converter functions
-   In YODA/ROOTCnv.h -- pure header library to avoid bild-time ROOT dependence
-
 * Optionally configurable ROOT writer.
 
 * Add a Counter type (mostly a UI/persistency wrapper on Dbn1D) (AB)
@@ -66,6 +66,8 @@
 
 * ReaderFlat -> Scatter2D
 
+* Simple ntupling, done well :-)
+
 * Allow comments on ends of YODA format data lines in ReaderYODA (HH)
    Ignore anything after "#" on data lines -- use this to write convenience
    height & error info for each bin since not obvious from sumWX2 etc.

Modified: trunk/include/YODA/Histo1D.h
==============================================================================
--- trunk/include/YODA/Histo1D.h	Thu Nov 15 18:26:09 2012	(r540)
+++ trunk/include/YODA/Histo1D.h	Fri Nov 16 14:06:52 2012	(r541)
@@ -277,11 +277,15 @@
       return sumW(includeoverflows);
     }
 
-    /// Get the integrated area of the histogram between bins @a binindex1 and @a binindex2.
+    /// @brief Get the integrated area of the histogram between bins @a binindex1 and @a binindex2.
+    ///
+    /// NB. The area of bin @a binindex2 is not included in the returned
+    /// value. To include the underflow and overflow areas, you should add them
+    /// explicitly with the underflow() and overflow() methods.
     double integral(size_t binindex1, size_t binindex2) const {
       assert(binindex1 > binindex2);
       if (binindex1 >= numBins()) throw RangeError("binindex1 is out of range");
-      if (binindex2 >= numBins()) throw RangeError("binindex2 is out of range");
+      if (binindex2 > numBins()) throw RangeError("binindex2 is out of range");
       double rtn = 0;
       for (size_t i = binindex1; i < binindex2; ++i) {
         rtn += bin(i).area();
@@ -393,6 +397,13 @@
   /// histograms: the errors must be treated as correlated
   Scatter2D efficiency(const Histo1D& accepted, const Histo1D& total);
 
+  /// @brief Convert a Histo1D to a Scatter2D representing the integral of the histogram
+  ///
+  /// NB. The integral histo errors are calculated as sqrt(binvalue), as if they
+  /// are uncorrelated. This is not in general true for integral histograms, so if you
+  /// need accurate errors you should explicitly monitor bin-to-bin correlations.
+  Scatter2D toIntegralHisto(const Histo1D& h, bool includeunderflow=true);
+
   //@}
 
 

Modified: trunk/src/Histo1D.cc
==============================================================================
--- trunk/src/Histo1D.cc	Thu Nov 15 18:26:09 2012	(r540)
+++ trunk/src/Histo1D.cc	Fri Nov 16 14:06:52 2012	(r541)
@@ -163,4 +163,20 @@
   }
 
 
+  // Convert a Histo1D to a Scatter2D representing the integral of the histogram
+  Scatter2D toIntegralHisto(const Histo1D& h, bool includeunderflow) {
+    /// @todo Check that the histogram binning has no gaps, otherwise throw a BinningError
+    Scatter2D tmp = mkScatter(h);
+    double integral = includeunderflow ? h.underflow().sumW() : 0.0;
+    for (size_t i = 0; i < h.numBins(); ++i) {
+      Point2D& point = tmp.point(i);
+      integral += h.bin(i).sumW();
+      const double err = sqrt(integral);
+      point.setY(integral);
+      point.setYErr(err, err);
+    }
+    return tmp;
+  }
+
+
 }


More information about the yoda-svn mailing list