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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Sat Nov 24 20:30:48 GMT 2012


Author: buckley
Date: Sat Nov 24 20:30:48 2012
New Revision: 548

Log:
Improvements to ROOT converters, visiting some TODOs, and bumping version to 0.6beta0, which will now get a public tarball

Modified:
   trunk/ChangeLog
   trunk/TODO
   trunk/configure.ac
   trunk/include/YODA/ROOTCnv.h

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Wed Nov 21 09:47:53 2012	(r547)
+++ trunk/ChangeLog	Sat Nov 24 20:30:48 2012	(r548)
@@ -1,3 +1,11 @@
+2012-11-24  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Bump version to 0.6beta0
+
+	* Adding more ROOT converters. Who knows how to make TProfiles
+	from scratch, but Histo1D and Scatter2D are covered, which should
+	be enough to get started with, at least.
+
 2012-11-16  Andy Buckley  <andy.buckley at cern.ch>
 
 	* Adding yoda-config

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Wed Nov 21 09:47:53 2012	(r547)
+++ trunk/TODO	Sat Nov 24 20:30:48 2012	(r548)
@@ -3,14 +3,9 @@
 
 NOW
 
-* Remove non-const bin access from Histos and Profiles
-   cf. David D's point re. consistency via email on 7/8/2012
 
 * Auto-determine input and output formats (= readers/writers) from file extn (AB)
 
-* Add Axis2D -> Histo2D/Profile2D bin adding and erasing. (AB)
-   Adding 2D operator support and bin-adding/erasing
-
 * Make Python interface test scripts (DM,AB)
    Test Histo2D and Scatter2D from Python
 
@@ -20,19 +15,21 @@
 
 * Add stdErr to HistoBinXD (AB)
 
-* WriterFlat, for Scatter2D representations only. (HH)
-
 * 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
 
-* Optionally configurable ROOT writer.
+* Remove non-const bin access from Histos and Profiles?
+   cf. David D's point re. consistency via email on 7/8/2012
+   In practice they can't be removed as they are used internally. Attempting to
+   make them protected/private didn't work due to requirements of the Python
+   wrapper code... leaving it be for now.
+
+* Add Axis2D -> Histo2D/Profile2D bin adding and erasing. (AB)
+   Adding 2D operator support and bin-adding/erasing
 
 * Add a Counter type (mostly a UI/persistency wrapper on Dbn1D) (AB)
    "Binning"/"axis" option on arbitrary types, particularly strings? ->

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	Wed Nov 21 09:47:53 2012	(r547)
+++ trunk/configure.ac	Sat Nov 24 20:30:48 2012	(r548)
@@ -1,7 +1,7 @@
 ## Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([YODA],[0.5.0beta0],[yoda at projects.hepforge.org],[YODA])
+AC_INIT([YODA],[0.6.0beta0],[yoda at projects.hepforge.org],[YODA])
 AM_INIT_AUTOMAKE
 #AC_CONFIG_SRCDIR([src/Bin1D.cc])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

Modified: trunk/include/YODA/ROOTCnv.h
==============================================================================
--- trunk/include/YODA/ROOTCnv.h	Wed Nov 21 09:47:53 2012	(r547)
+++ trunk/include/YODA/ROOTCnv.h	Sat Nov 24 20:30:48 2012	(r548)
@@ -98,10 +98,12 @@
   //@{
 
   /// @brief Convert a YODA Histo1D to a ROOT 1D histogram
+  ///
+  /// @todo Check/improve/extend -- needs SetBinError or not?
   inline TH1D toTH1D(const Histo1D& h) {
     // Work out bin edges first
     std::vector<double> edges;
-    edges.reserve(h.numBins());
+    edges.reserve(h.numBins()+1);
     edges.push_back(h.bin(0).lowEdge());
     for (size_t i = 0; i < h.numBins(); ++i) {
       HistoBin1D& b = h.bin(i);
@@ -109,12 +111,12 @@
       if (!fuzzyEquals(edges.back(), b.highEdge())) edges.push_back(b.highEdge());
     }
     // Book ROOT histogram
-    TH1D rtn(h.name(), h.title(), edges.size()-1, &edges[0]);
+    TH1D rtn(h.name().c_str(), h.title().c_str(), edges.size()-1, &edges[0]);
     rtn.Sumw2();
     TArrayD& sumw2s = *rtn.GetSumw2();
     for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
       try {
-        HistoBin1D& b = h.binByCoord(rtn.GetBinCenter(i)); // throws if in a gap
+        Bin1D& b = h.binByCoord(rtn.GetBinCenter(i)); // throws if in a gap
         rtn.SetBinContent(i, b.sumW());
         sumw2s[i] = b.sumW2();
       } catch (const Exception& e) {  }
@@ -125,15 +127,78 @@
     sumw2s[0] = h.underflow().sumW2();
     sumw2s[rtn.GetNbinsX()+1] = h.overflow().sumW2();
     // Labels
-    if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel"));
-    if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel"));
+    if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel").c_str());
+    if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel").c_str());
     return rtn;
   }
 
 
-  /// @todo toTProfile: Profile1D -> TProfile
+  /// @brief Convert a YODA Scatter2D to a ROOT TH1D
 
-  /// @todo toTGraphAsymmErrs: Scatter2D -> TGraphAsymmErrs
+
+  /// @brief Convert a YODA Profile1D to a ROOT TProfile
+  ///
+  /// @todo Check/improve/extend. How to set all the y-weights in ROOT profiles?
+  inline TProfile toTProfile(const Profile1D& p) {
+    // Work out bin edges first
+    std::vector<double> edges;
+    edges.reserve(p.numBins()+1);
+    edges.push_back(p.bin(0).lowEdge());
+    for (size_t i = 0; i < p.numBins(); ++i) {
+      Bin1D& b = p.bin(i);
+      if (!fuzzyEquals(edges.back(), b.lowEdge())) edges.push_back(b.lowEdge());
+      if (!fuzzyEquals(edges.back(), b.highEdge())) edges.push_back(b.highEdge());
+    }
+    // Book ROOT histogram
+    TProfile rtn(p.name().c_str(), p.title().c_str(), edges.size()-1, &edges[0]);
+    rtn.Sumw2();
+    TArrayD& sumw2s = *rtn.GetSumw2();
+    for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
+      try {
+        ProfileBin1D& b = p.binByCoord(rtn.GetBinCenter(i)); // throws if in a gap
+        /// @todo This part is probably wrong -- also need to do something with GetW,
+        ///   GetW2, GetB, GetB2, and/or GetBinSumw2? ROOT docs are 100% useless...
+        rtn.SetBinContent(i, b.sumW());
+        sumw2s[i] = b.sumW2();
+      } catch (const Exception& e) {  }
+    }
+    // Overflows
+    rtn.SetBinContent(0, p.underflow().sumW());
+    rtn.SetBinContent(rtn.GetNbinsX()+1, p.overflow().sumW());
+    sumw2s[0] = p.underflow().sumW2();
+    sumw2s[rtn.GetNbinsX()+1] = p.overflow().sumW2();
+    // Labels
+    if (p.hasAnnotation("XLabel")) rtn.SetXTitle(p.annotation("XLabel").c_str());
+    if (p.hasAnnotation("YLabel")) rtn.SetYTitle(p.annotation("YLabel").c_str());
+    return rtn;
+  }
+
+
+  /// @brief Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors
+  ///
+  /// @todo Check/improve/extend.
+  inline TGraphAsymmErrors toTGraph(const Scatter2D& s) {
+    TVectorF xs(s.numPoints()), ys(s.numPoints());
+    TVectorF exls(s.numPoints()), exhs(s.numPoints());
+    TVectorF eyls(s.numPoints()), eyhs(s.numPoints());
+    for (size_t i = 0; i < s.numPoints(); ++i) {
+      Point2D& p = s.bin(i);
+      xs[i] = p.x();
+      ys[i] = p.y();
+      exls[i] = p.xErrMinus();
+      exhs[i] = p.xErrPlus();
+      eyls[i] = p.yErrMinus();
+      eyhs[i] = p.yErrPlus();
+    }
+    // Make the ROOT object... mm, the constructors don't take name+title, unlike all this histos!
+    TGraphAsymmErrors rtn(xs, ys, exls, exhs, eyls, eyhs);
+    rtn.SetName(s.name().c_str());
+    rtn.SetTitle(s.title().c_str());
+    // Labels
+    if (s.hasAnnotation("XLabel")) rtn.GetXaxis()->SetTitle(s.annotation("XLabel").c_str());
+    if (s.hasAnnotation("YLabel")) rtn.GetYaxis()->SetTitle(s.annotation("YLabel").c_str());
+    return rtn;
+  }
 
   //@}
 


More information about the yoda-svn mailing list