[Rivet-svn] r2640 - in trunk: include/Rivet src/Tools

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Aug 3 23:41:48 BST 2010


Author: holsch
Date: Tue Aug  3 23:41:48 2010
New Revision: 2640

Log:
Add DPSXYPoint object that in addition to what DPSXPoint is capable of also holds y-values and y-errors. Also added a function that reads this information from data files

Modified:
   trunk/include/Rivet/RivetAIDA.fhh
   trunk/include/Rivet/RivetAIDA.hh
   trunk/src/Tools/RivetAIDA.cc

Modified: trunk/include/Rivet/RivetAIDA.fhh
==============================================================================
--- trunk/include/Rivet/RivetAIDA.fhh	Mon Aug  2 22:08:28 2010	(r2639)
+++ trunk/include/Rivet/RivetAIDA.fhh	Tue Aug  3 23:41:48 2010	(r2640)
@@ -35,6 +35,18 @@
     double errplus;
   };
 
+  /// Container for x-axis point details
+  struct DPSXYPoint {
+    DPSXYPoint(double xval, double xerrminus, double xerrplus, double yval, double yerrminus, double yerrplus) :
+      xval(xval), xerrminus(xerrminus), xerrplus(xerrplus), yval(yval), yerrminus(yerrminus), yerrplus(yerrplus) { }
+    double xval;
+    double xerrminus;
+    double xerrplus;
+    double yval;
+    double yerrminus;
+    double yerrplus;
+  };
+
 }
 
 #endif

Modified: trunk/include/Rivet/RivetAIDA.hh
==============================================================================
--- trunk/include/Rivet/RivetAIDA.hh	Mon Aug  2 22:08:28 2010	(r2639)
+++ trunk/include/Rivet/RivetAIDA.hh	Tue Aug  3 23:41:48 2010	(r2640)
@@ -33,6 +33,8 @@
 
   const map<string, vector<DPSXPoint> > getDPSXValsErrs(string papername);
 
+  const map<string, vector<DPSXYPoint> > getDPSXYValsErrs(string papername);
+
   /// Get the file system path to the AIDA reference file for this paper.
   const string getDataPath(string papername);
 

Modified: trunk/src/Tools/RivetAIDA.cc
==============================================================================
--- trunk/src/Tools/RivetAIDA.cc	Mon Aug  2 22:08:28 2010	(r2639)
+++ trunk/src/Tools/RivetAIDA.cc	Tue Aug  3 23:41:48 2010	(r2640)
@@ -42,6 +42,87 @@
   }
 
 
+  const map<string, vector<DPSXYPoint> > getDPSXYValsErrs(string papername) {
+    // Get filename
+    const string xmlfile = getDatafilePath(papername);
+
+    // Open AIDA XML file
+    TiXmlDocument doc(xmlfile);
+    doc.LoadFile();
+    if (doc.Error()) {
+      string err = "Error in " + string(doc.Value());
+      err += ": " + string(doc.ErrorDesc());
+      cerr << err << endl;
+      throw Error(err);
+    }
+
+    // Return value, to be populated
+    map<string, vector<DPSXYPoint> > rtn;
+
+    try {
+      // Walk down tree to get to the <paper> element
+      const TiXmlNode* aidaN = doc.FirstChild("aida");
+      if (!aidaN) throw Error("Couldn't get <aida> root element");
+      for (const TiXmlNode* dpsN = aidaN->FirstChild("dataPointSet"); dpsN; dpsN = dpsN->NextSibling()) {
+        const TiXmlElement* dpsE = dpsN->ToElement();
+        const string plotname = dpsE->Attribute("name");
+        const string plotpath = dpsE->Attribute("path");
+        /// Check path to make sure that this is a reference histogram.
+        if (plotpath.find("/REF") != 0) {
+          cerr << "Skipping non-reference histogram " << plotname << endl;
+          continue;
+        }
+
+        /// @todo Check that "path" matches filename
+        vector<DPSXYPoint> points;
+        for (const TiXmlNode* dpN = dpsN->FirstChild("dataPoint"); dpN; dpN = dpN->NextSibling()) {
+          const TiXmlNode* xMeasN = dpN->FirstChild("measurement");
+          const TiXmlNode* yMeasN = xMeasN->NextSibling();
+          if (xMeasN && yMeasN)  {
+            const TiXmlElement* xMeasE = xMeasN->ToElement();
+            const TiXmlElement* yMeasE = yMeasN->ToElement();
+            const string xcentreStr   = xMeasE->Attribute("value");
+            const string xerrplusStr  = xMeasE->Attribute("errorPlus");
+            const string xerrminusStr = xMeasE->Attribute("errorMinus");
+            const string ycentreStr   = yMeasE->Attribute("value");
+            const string yerrplusStr  = yMeasE->Attribute("errorPlus");
+            const string yerrminusStr = yMeasE->Attribute("errorMinus");
+            //if (!centreStr) throw Error("Couldn't get a valid bin centre");
+            //if (!errplusStr) throw Error("Couldn't get a valid bin err+");
+            //if (!errminusStr) throw Error("Couldn't get a valid bin err-");
+            istringstream xssC(xcentreStr);
+            istringstream xssP(xerrplusStr);
+            istringstream xssM(xerrminusStr);
+            istringstream yssC(ycentreStr);
+            istringstream yssP(yerrplusStr);
+            istringstream yssM(yerrminusStr);
+            double xcentre, xerrplus, xerrminus, ycentre, yerrplus, yerrminus;
+            xssC >> xcentre; xssP >> xerrplus; xssM >> xerrminus;
+            yssC >> ycentre; yssP >> yerrplus; yssM >> yerrminus;
+            //cout << "  " << centre << " + " << errplus << " - " << errminus << endl;
+            DPSXYPoint pt(xcentre, xerrminus, xerrplus, ycentre, yerrminus, yerrplus);
+            points.push_back(pt);
+          } else {
+            cerr << "Couldn't get <measurement> tag" << endl;
+            /// @todo Throw an exception here?
+          }
+        }
+
+        // Add to the map
+        rtn[plotname] = points;
+      }
+
+    }
+    // Write out the error
+    /// @todo Rethrow as a general XML failure.
+    catch (std::exception& e) {
+      cerr << e.what() << endl;
+      throw;
+    }
+
+    // Return
+    return rtn;
+  }
 
   const map<string, vector<DPSXPoint> > getDPSXValsErrs(string papername) {
     // Get filename


More information about the Rivet-svn mailing list