[Rivet-svn] r4272 - in trunk: . include/Rivet src/Core

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon May 13 21:18:12 BST 2013


Author: buckley
Date: Mon May 13 21:18:12 2013
New Revision: 4272

Log:
Analysis histo booking improvements for Scatter2D, placeholders for 2D histos, and general tidying.

Modified:
   trunk/ChangeLog
   trunk/include/Rivet/Analysis.hh
   trunk/src/Core/Analysis.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Mon May 13 21:17:43 2013	(r4271)
+++ trunk/ChangeLog	Mon May 13 21:18:12 2013	(r4272)
@@ -1,3 +1,8 @@
+2013-05-13  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Analysis histo booking improvements for Scatter2D, placeholders
+	for 2D histos, and general tidying.
+
 2013-05-12  Andy Buckley  <andy.buckley at cern.ch>
 
 	* Adding configure-time differentiation between yaml-cpp API versions 3 and 5.

Modified: trunk/include/Rivet/Analysis.hh
==============================================================================
--- trunk/include/Rivet/Analysis.hh	Mon May 13 21:17:43 2013	(r4271)
+++ trunk/include/Rivet/Analysis.hh	Mon May 13 21:18:12 2013	(r4272)
@@ -21,11 +21,6 @@
 #define vetoEvent                                                       \
   do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0)
 
-/// @def DECLARE_RIVET_PLUGIN
-/// Preprocessor define to prettify the global-object plugin hook mechanism.
-#define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
-
-
 
 namespace Rivet {
 
@@ -357,6 +352,7 @@
 
     /// @name AIDA analysis infrastructure.
     //@{
+
     /// Get the canonical histogram "directory" path for this analysis.
     const std::string histoDir() const;
 
@@ -372,7 +368,7 @@
     //@}
 
 
-    /// @name Internal histogram booking (for use by Analysis sub-classes).
+    /// @name Histogram reference data
     //@{
 
     /// Get reference data for a named histo
@@ -382,146 +378,205 @@
     const YODA::Scatter2D & refData(size_t datasetId,
                                     size_t xAxisId, size_t yAxisId) const;
 
+    //@}
+
+
+    /// @name 1D histogram booking
+    //@{
+
+    /// Book a 1D histogram, using the binnings in the reference data histogram.
+    Histo1DPtr bookHisto1D(const std::string& name,
+                           const std::string& title="",
+                           const std::string& xtitle="",
+                           const std::string& ytitle="");
+
+    /// Book a 1D histogram, using the binnings in the reference data histogram.
+    ///
+    /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way.
+    Histo1DPtr bookHisto1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+                           const std::string& title="",
+                           const std::string& xtitle="",
+                           const std::string& ytitle="");
+
     /// Book a 1D histogram with @a nbins uniformly distributed across the range @a lower - @a upper .
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
     Histo1DPtr bookHisto1D(const std::string& name,
                            size_t nbins, double lower, double upper,
                            const std::string& title="",
-                           const std::string& xtitle="", const std::string& ytitle="");
+                           const std::string& xtitle="",
+                           const std::string& ytitle="");
 
     /// Book a 1D histogram with non-uniform bins defined by the vector of bin edges @a binedges .
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
     Histo1DPtr bookHisto1D(const std::string& name,
-                           const std::vector<double>& binedges, const std::string& title="",
-                           const std::string& xtitle="", const std::string& ytitle="");
+                           const std::vector<double>& binedges,
+                           const std::string& title="",
+                           const std::string& xtitle="",
+                           const std::string& ytitle="");
+
+    //@}
+
+
+    // /// @name 2D histogram booking
+    // //@{
+
+    // /// Book a 2D histogram, using the binnings in the reference data histogram.
+    // Histogram2DPtr bookHisto2D(const std::string& name,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
+
+    // /// Book a 2D histogram, using the binnings in the reference data histogram.
+    // ///
+    // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way.
+    // Histogram2DPtr bookHisto2D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
 
     // /// Book a 2D histogram with @a nxbins and @a nybins uniformly
     // /// distributed across the ranges @a xlower - @a xupper and @a
     // /// ylower - @a yupper respectively along the x- and y-axis.
-    // /// (NB. this returns a pointer rather than a reference since it
-    // /// will have to be stored in the analysis class - there's no
-    // /// point in forcing users to explicitly get the pointer from a
-    // /// reference before they can use it!)
-    // AIDA::IHistogram2D*
-    // bookHistogram2D(const std::string& name,
-    //          size_t nxbins, double xlower, double xupper,
-    //          size_t nybins, double ylower, double yupper,
-    //          const std::string& title="", const std::string& xtitle="",
-    //          const std::string& ytitle="", const std::string& ztitle="");
+    // Histogram2DPtr bookHisto2D(const std::string& name,
+    //                            size_t nxbins, double xlower, double xupper,
+    //                            size_t nybins, double ylower, double yupper,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
 
     // /// Book a 2D histogram with non-uniform bins defined by the
     // /// vectorx of bin edges @a xbinedges and @a ybinedges.
-    // /// (NB. this returns a pointer rather than a reference since it
-    // /// will have to be stored in the analysis class - there's no
-    // /// point in forcing users to explicitly get the pointer from a
-    // /// reference before they can use it!)
-    // AIDA::IHistogram2D*
-    // bookHistogram2D(const std::string& name,
-    //          const std::vector<double>& xbinedges,
-    //          const std::vector<double>& ybinedges,
-    //          const std::string& title="", const std::string& xtitle="",
-    //          const std::string& ytitle="", const std::string& ztitle="");
-
-    /// Book a 1D histogram based on the name in the corresponding AIDA
-    /// file. The binnings will be obtained by reading the bundled AIDA data
-    /// record file with the same filename as the analysis' name() property.
-    Histo1DPtr bookHisto1D(const std::string& name,
-                           const std::string& title="",
-                           const std::string& xtitle="",
-                           const std::string& ytitle="");
+    // Histogram2DPtr bookHisto2D(const std::string& name,
+    //                            const std::vector<double>& xbinedges,
+    //                            const std::vector<double>& ybinedges,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
 
-    /// Book a 1D histogram based on the paper, dataset and x/y-axis IDs in the corresponding
-    /// HepData record. The binnings will be obtained by reading the bundled AIDA data record file
-    /// of the same filename as the analysis' name() property.
-    Histo1DPtr bookHisto1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
-                           const std::string& title="",
-                           const std::string& xtitle="",
-                           const std::string& ytitle="");
-
-    //@}
+    // //@}
 
 
-    /// @name Internal profile histogram booking (for use by Analysis sub-classes).
+    /// @name 1D profile histogram booking
     //@{
 
+    /// Book a 1D profile histogram, using the binnings in the reference data histogram.
+    Profile1DPtr bookProfile1D(const std::string& name,
+                               const std::string& title="",
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
+
+    /// Book a 1D profile histogram, using the binnings in the reference data histogram.
+    ///
+    /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way.
+    Profile1DPtr bookProfile1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+                               const std::string& title="",
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
+
     /// Book a 1D profile histogram with @a nbins uniformly distributed across the range @a lower - @a upper .
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
     Profile1DPtr bookProfile1D(const std::string& name,
                                size_t nbins, double lower, double upper,
                                const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
 
     /// Book a 1D profile histogram with non-uniform bins defined by the vector of bin edges @a binedges .
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
     Profile1DPtr bookProfile1D(const std::string& name,
                                const std::vector<double>& binedges,
                                const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
 
-    /// Book a 1D profile histogram based on the name in the corresponding AIDA
-    /// file. The binnings will be obtained by reading the bundled AIDA data
-    /// record file with the same filename as the analysis' name() property.
-    Profile1DPtr bookProfile1D(const std::string& name, const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
-
-    /// Book a 1D profile histogram based on the paper, dataset and x/y-axis IDs in the corresponding
-    /// HepData record. The binnings will be obtained by reading the bundled AIDA data record file
-    /// of the same filename as the analysis' name() property.
-    Profile1DPtr bookProfile1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
-                               const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
     //@}
 
 
-    /// @name Internal data point set booking (for use by Analysis sub-classes).
+    // /// @name 2D profile histogram booking
+    // //@{
+
+    // /// Book a 2D profile histogram, using the binnings in the reference data histogram.
+    // Profile2DPtr bookProfile2D(const std::string& name,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
+
+    // /// Book a 2D profile histogram, using the binnings in the reference data histogram.
+    // ///
+    // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way.
+    // Profile2DPtr bookProfile2D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
+
+    // /// Book a 2D profile histogram with @a nxbins and @a nybins uniformly
+    // /// distributed across the ranges @a xlower - @a xupper and @a ylower - @a
+    // /// yupper respectively along the x- and y-axis.
+    // Profile2DPtr bookProfile2D(const std::string& name,
+    //                            size_t nxbins, double xlower, double xupper,
+    //                            size_t nybins, double ylower, double yupper,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
+
+    // /// Book a 2D profile histogram with non-uniform bins defined by the vectorx
+    // /// of bin edges @a xbinedges and @a ybinedges.
+    // Profile2DPtr bookProfile2D(const std::string& name,
+    //                            const std::vector<double>& xbinedges,
+    //                            const std::vector<double>& ybinedges,
+    //                            const std::string& title="",
+    //                            const std::string& xtitle="",
+    //                            const std::string& ytitle="",
+    //                            const std::string& ztitle="");
+
+    // //@}
+
+
+    /// @name 2D scatter booking
     //@{
 
-    /// Book a 2-dimensional data point set.
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
-    Scatter2DPtr bookScatter2D(const std::string& name, const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
+    /// Book a 2-dimensional data point set, using the binnings in the reference data histogram.
+    Scatter2DPtr bookScatter2D(const std::string& name,
+                               const std::string& title="",
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
 
+    /// Book a 2-dimensional data point set, using the binnings in the reference data histogram.
+    ///
+    /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way.
+    Scatter2DPtr bookScatter2D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+                               const std::string& title="",
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
 
     /// Book a 2-dimensional data point set with equally spaced points in a range.
-    /// (NB. this returns a pointer rather than a reference since it will
-    /// have to be stored in the analysis class - there's no point in forcing users to explicitly
-    /// get the pointer from a reference before they can use it!)
     Scatter2DPtr bookScatter2D(const std::string& name,
                                size_t npts, double lower, double upper,
                                const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
+                               const std::string& xtitle="",
+                               const std::string& ytitle="");
 
-    /// Book a 2-dimensional data point set based on the corresponding AIDA data
-    /// file. The binnings (x-errors) will be obtained by reading the bundled
-    /// AIDA data record file of the same filename as the analysis' name()
-    /// property.
-    Scatter2DPtr bookScatter2D(const std::string& name, const std::string& title);
-
-    /// Book a 2-dimensional data point set based on the paper, dataset and x/y-axis IDs in the corresponding
-    /// HepData record. The binnings (x-errors) will be obtained by reading the bundled AIDA data record file
-    /// of the same filename as the analysis' name() property.
-    Scatter2DPtr bookScatter2D(size_t datasetId, size_t xAxisId, size_t yAxisId,
-                               const std::string& title="",
-                               const std::string& xtitle="", const std::string& ytitle="");
+    /// Book a 2-dimensional data point set based on provided contiguous bin edges.
+    Scatter2DPtr bookScatter2D(const std::string& hname,
+                               const std::vector<double>& binedges,
+                               const std::string& title,
+                               const std::string& xtitle,
+                               const std::string& ytitle);
 
     //@}
 
+
   public:
+
     /// List of registered plot objects
     const vector<AnalysisObjectPtr> & plots() const {
       return _plotobjects;
     }
 
+
   private:
 
     /// @name Utility functions
@@ -578,5 +633,9 @@
 // Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh
 #include "Rivet/AnalysisBuilder.hh"
 
+/// @def DECLARE_RIVET_PLUGIN
+/// Preprocessor define to prettify the global-object plugin hook mechanism.
+#define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname
+
 
 #endif

Modified: trunk/src/Core/Analysis.cc
==============================================================================
--- trunk/src/Core/Analysis.cc	Mon May 13 21:17:43 2013	(r4271)
+++ trunk/src/Core/Analysis.cc	Mon May 13 21:18:12 2013	(r4272)
@@ -283,17 +283,19 @@
   /////////////////
 
 
-  Profile1DPtr Analysis::bookProfile1D(size_t datasetId, size_t xAxisId,
-                                       size_t yAxisId, const string& title,
-                                       const string& xtitle, const string& ytitle) {
+  Profile1DPtr Analysis::bookProfile1D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+                                       const string& title,
+                                       const string& xtitle,
+                                       const string& ytitle) {
     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
     return bookProfile1D(axisCode, title, xtitle, ytitle);
   }
 
 
-  Profile1DPtr Analysis::bookProfile1D(const string& hname, const string& title,
-                                       const string& xtitle, const string& ytitle)
-  {
+  Profile1DPtr Analysis::bookProfile1D(const string& hname,
+                                       const string& title,
+                                       const string& xtitle,
+                                       const string& ytitle) {
     const Scatter2D & refdata = refData(hname);
     const string path = histoPath(hname);
     Profile1DPtr prof( new Profile1D(refdata, path) );
@@ -309,7 +311,8 @@
   Profile1DPtr Analysis::bookProfile1D(const string& hname,
                                        size_t nbins, double lower, double upper,
                                        const string& title,
-                                       const string& xtitle, const string& ytitle) {
+                                       const string& xtitle,
+                                       const string& ytitle) {
     const string path = histoPath(hname);
     Profile1DPtr prof( new Profile1D(nbins, lower, upper, path, title) );
     addPlot(prof);
@@ -323,7 +326,8 @@
   Profile1DPtr Analysis::bookProfile1D(const string& hname,
                                        const vector<double>& binedges,
                                        const string& title,
-                                       const string& xtitle, const string& ytitle) {
+                                       const string& xtitle,
+                                       const string& ytitle) {
     const string path = histoPath(hname);
     Profile1DPtr prof( new Profile1D(binedges, path, title) );
     addPlot(prof);
@@ -337,68 +341,64 @@
   ///////////////////
 
 
-  Scatter2DPtr Analysis::bookScatter2D(size_t datasetId, size_t xAxisId,
-                                       size_t yAxisId, const string& title,
-                                       const string& xtitle, const string& ytitle) {
+  Scatter2DPtr Analysis::bookScatter2D(size_t datasetId, size_t xAxisId, size_t yAxisId,
+                                       const string& title,
+                                       const string& xtitle,
+                                       const string& ytitle) {
     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
     return bookScatter2D(axisCode, title, xtitle, ytitle);
   }
 
 
-  Scatter2DPtr Analysis::bookScatter2D(const string& hname, const string& title,
-                                       const string& xtitle, const string& ytitle) {
+  Scatter2DPtr Analysis::bookScatter2D(const string& hname,
+                                       const string& title,
+                                       const string& xtitle,
+                                       const string& ytitle) {
+    const Scatter2D& refdata = refData(hname);
     const string path = histoPath(hname);
-    Scatter2DPtr dps( new Scatter2D(path, title) );
-    addPlot(dps);
-    MSG_TRACE("Made data point set " << hname <<  " for " << name());
-    dps->setAnnotation("XLabel", xtitle);
-    dps->setAnnotation("YLabel", ytitle);
-    return dps;
+    Scatter2DPtr s( new Scatter2D(refdata, path) );
+    foreach (Point2D& p, s->points()) p.setY(0, 0);
+    addPlot(s);
+    MSG_TRACE("Made scatter " << hname <<  " for " << name());
+    s->setTitle(title);
+    s->setAnnotation("XLabel", xtitle);
+    s->setAnnotation("YLabel", ytitle);
+    return s;
+
   }
 
 
   Scatter2DPtr Analysis::bookScatter2D(const string& hname,
                                        size_t npts, double lower, double upper,
                                        const string& title,
-                                       const string& xtitle, const string& ytitle) {
+                                       const string& xtitle,
+                                       const string& ytitle) {
     Scatter2DPtr dps = bookScatter2D(hname, title, xtitle, ytitle);
     const double binwidth = (upper-lower)/npts;
     for (size_t pt = 0; pt < npts; ++pt) {
       const double bincentre = lower + (pt + 0.5) * binwidth;
-      // @todo YODA check
       dps->addPoint(bincentre, 0, binwidth/2.0, 0);
-      // IMeasurement* meas = dps->point(pt)->coordinate(0);
-      // meas->setValue(bincentre);
-      // meas->setErrorPlus(binwidth/2.0);
-      // meas->setErrorMinus(binwidth/2.0);
     }
     return dps;
   }
 
-  // @todo YODA
-  // Scatter2DPtr Analysis::bookScatter2D(size_t datasetId, size_t xAxisId,
-  //                       size_t yAxisId, const string& title,
-  //                       const string& xtitle, const string& ytitle) {
-  //   // Get the bin edges (only read the AIDA file once)
-  //   _cacheXAxisData();
-  //   // Build the axis code
-  //   const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
-  //   //const map<string, vector<DPSXPoint> > xpoints = getDPSXValsErrs(papername);
-  //   MSG_TRACE("Using DPS x-positions for " << name() << ":" << axisCode);
-  //   Scatter2DPtr dps = bookScatter2D(axisCode, title, xtitle, ytitle);
-  //   const vector<Point2D> xpts = _dpsData.find(axisCode)->second;
-  //   foreach ( const Point2D & pt, xpts ) {
-  //     // \todo YODA check
-  //     dps->addPoint(pt.x(), pt.xErrMinus(), pt.xErrPlus(), 0, 0, 0);
-  //     // dps->addPoint(xpts[pt].val, xpts[pt].errminus, xpts[pt].errplus, 0, 0, 0);
-  //     // IMeasurement* meas = dps->point(pt)->coordinate(0);
-  //     // meas->setValue(xpts[pt].val);
-  //     // meas->setErrorPlus(xpts[pt].errplus);
-  //     // meas->setErrorMinus(xpts[pt].errminus);
-  //   }
-  //   MSG_TRACE("Made DPS " << axisCode <<  " for " << name());
-  //   return dps;
-  // }
+
+  Scatter2DPtr Analysis::bookScatter2D(const string& hname,
+                                       const vector<double>& binedges,
+                                       const string& title,
+                                       const string& xtitle,
+                                       const string& ytitle) {
+    Scatter2DPtr dps = bookScatter2D(hname, title, xtitle, ytitle);
+    for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
+      const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
+      const double binwidth = binedges[pt+1] - binedges[pt];
+      dps->addPoint(bincentre, 0, binwidth/2.0, 0);
+    }
+    return dps;
+  }
+
+
+  /////////////////////
 
 
   void Analysis::divide(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const {


More information about the Rivet-svn mailing list