Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F7878540
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
22 KB
Subscribers
None
View Options
diff --git a/src/Scatter1D.cc b/src/Scatter1D.cc
--- a/src/Scatter1D.cc
+++ b/src/Scatter1D.cc
@@ -1,57 +1,59 @@
#include "YODA/Scatter1D.h"
#include "YODA/Counter.h"
#include <sstream>
#include "yaml-cpp/yaml.h"
#ifdef YAML_NAMESPACE
#define YAML YAML_NAMESPACE
#endif
namespace YODA {
/// Make a Scatter1D representation of a Histo1D
Scatter1D mkScatter(const Counter& c) {
Scatter1D rtn;
for (const std::string& a : c.annotations())
rtn.setAnnotation(a, c.annotation(a));
rtn.setAnnotation("Type", c.type()); // might override the copied ones
- rtn.addPoint(c.val(), c.err());
+ Point1D pt(c.val(), c.err());
+ pt.setParentAO(&rtn);
+ rtn.addPoint(pt);
return rtn;
}
void Scatter1D::parseVariations() {
if (this-> _variationsParsed) { return;}
if (!(this->hasAnnotation("ErrorBreakdown"))) { return; }
YAML::Node errorBreakdown;
errorBreakdown = YAML::Load(this->annotation("ErrorBreakdown"));
if (errorBreakdown.size()) {
for (unsigned int thisPointIndex=0 ; thisPointIndex< this->numPoints() ; ++thisPointIndex){
Point1D &thispoint = this->_points[thisPointIndex];
YAML::Node variations = errorBreakdown[thisPointIndex];
for (const auto& variation : variations) {
const std::string variationName = variation.first.as<std::string>();
double eyp = variation.second["up"].as<double>();
double eym = variation.second["dn"].as<double>();
thispoint.setXErrs(eym,eyp,variationName);
}
}
this-> _variationsParsed =true;
}
}
const std::vector<std::string> Scatter1D::variations() const {
std::vector<std::string> vecvariations;
for (auto &point : this->_points){
for (auto &it : point.errMap()){
//if the variation is not already in the vector, add it !
if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
vecvariations.push_back(it.first);
}
}
}
return vecvariations;
}
}
diff --git a/src/Scatter3D.cc b/src/Scatter3D.cc
--- a/src/Scatter3D.cc
+++ b/src/Scatter3D.cc
@@ -1,146 +1,149 @@
#include "YODA/Scatter3D.h"
#include "YODA/Histo2D.h"
#include "YODA/Profile2D.h"
#include "YODA/Exceptions.h"
#include <sstream>
#include "yaml-cpp/yaml.h"
#ifdef YAML_NAMESPACE
#define YAML YAML_NAMESPACE
#endif
namespace YODA {
Scatter3D mkScatter(const Histo2D& h, bool usefocus) {
Scatter3D rtn;
for (const std::string& a : h.annotations())
rtn.setAnnotation(a, h.annotation(a));
rtn.setAnnotation("Type", h.type());
for (size_t i = 0; i < h.numBins(); ++i) {
const HistoBin2D& b = h.bin(i);
/// SAME FOR ALL 2D BINS
double x = b.xMid();
if (usefocus) {
try {
x = b.xFocus();
} catch (const LowStatsError& lse) {
x = b.xMid();
}
}
const double exminus = x - b.xMin();
const double explus = b.xMax() - x;
double y = b.yMid();
if (usefocus) {
try {
y = b.yFocus();
} catch (const LowStatsError& lse) {
y = b.yMid();
}
}
const double eyminus = y - b.yMin();
const double eyplus = b.yMax() - y;
/// END SAME FOR ALL 2D BINS
const double z = b.height();
const double ez = b.heightErr();
- rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
+
+ Point3D pt(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
+ pt.setParentAO(&rtn);
+ rtn.addPoint(pt);
}
return rtn;
}
Scatter3D mkScatter(const Profile2D& h, bool usefocus, bool usestddev) {
Scatter3D rtn;
for (const std::string& a : h.annotations())
rtn.setAnnotation(a, h.annotation(a));
rtn.setAnnotation("Type", h.type());
for (size_t i = 0; i < h.numBins(); ++i) {
const ProfileBin2D& b = h.bin(i);
/// SAME FOR ALL 2D BINS
double x = b.xMid();
if (usefocus) {
try {
x = b.xFocus();
} catch (const LowStatsError& lse) {
x = b.xMid();
}
}
const double exminus = x - b.xMin();
const double explus = b.xMax() - x;
double y = b.yMid();
if (usefocus) {
try {
y = b.yFocus();
} catch (const LowStatsError& lse) {
y = b.yMid();
}
}
const double eyminus = y - b.yMin();
const double eyplus = b.yMax() - y;
/// END SAME FOR ALL 2D BINS
double z;
try {
z = b.mean();
} catch (const LowStatsError& lse) {
z = std::numeric_limits<double>::quiet_NaN();
}
double ez;
try {
ez = usestddev ? b.stdDev() : b.stdErr(); ///< Control z-error scheme via usestddev arg
} catch (const LowStatsError& lse) {
ez = std::numeric_limits<double>::quiet_NaN();
}
rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
}
return rtn;
}
void Scatter3D::parseVariations() {
if (this-> _variationsParsed) { return; }
if (!(this->hasAnnotation("ErrorBreakdown"))) { return;}
YAML::Node errorBreakdown;
errorBreakdown = YAML::Load(this->annotation("ErrorBreakdown"));
if (errorBreakdown.size()) {
for (unsigned int thisPointIndex=0 ; thisPointIndex< this->numPoints() ; ++thisPointIndex){
Point3D &thispoint = this->_points[thisPointIndex];
YAML::Node variations = errorBreakdown[thisPointIndex];
for (const auto& variation : variations) {
const std::string variationName = variation.first.as<std::string>();
double eyp = variation.second["up"].as<double>();
double eym = variation.second["dn"].as<double>();
thispoint.setZErrs(eym,eyp,variationName);
}
}
this-> _variationsParsed =true;
}
}
const std::vector<std::string> Scatter3D::variations() const {
std::vector<std::string> vecvariations;
for (auto &point : this->_points){
for (auto &it : point.errMap()){
//if the variation is not already in the vector, add it !
if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
vecvariations.push_back(it.first);
}
}
}
return vecvariations;
}
}
diff --git a/src/WriterYODA.cc b/src/WriterYODA.cc
--- a/src/WriterYODA.cc
+++ b/src/WriterYODA.cc
@@ -1,402 +1,385 @@
// -*- C++ -*-
//
// This file is part of YODA -- Yet more Objects for Data Analysis
// Copyright (C) 2008-2018 The YODA collaboration (see AUTHORS for details)
//
#include "YODA/WriterYODA.h"
#include "yaml-cpp/yaml.h"
#ifdef YAML_NAMESPACE
#define YAML YAML_NAMESPACE
#endif
#include <iostream>
#include <iomanip>
using namespace std;
namespace YODA {
/// Singleton creation function
Writer& WriterYODA::create() {
static WriterYODA _instance;
_instance.setPrecision(6);
return _instance;
}
// Format version:
// - V1/empty = make-plots annotations style
// - V2 = YAML annotations
static const int YODA_FORMAT_VERSION = 2;
// Version-formatting helper function
inline string _iotypestr(const string& baseiotype) {
ostringstream os;
os << "YODA_" << Utils::toUpper(baseiotype) << "_V" << YODA_FORMAT_VERSION;
return os.str();
}
void WriterYODA::_writeAnnotations(std::ostream& os, const AnalysisObject& ao) {
os << scientific << setprecision(_precision);
for (const string& a : ao.annotations()) {
if (a.empty()) continue;
/// @todo Write out floating point annotations as scientific notation
string ann = ao.annotation(a);
// remove stpurious line returns at the end of a string so that we don't
// end up with two line returns.
ann.erase(std::remove(ann.begin(), ann.end(), '\n'), ann.end());
os << a << ": " << ann << "\n";
}
os << "---\n";
}
void WriterYODA::writeCounter(std::ostream& os, const Counter& c) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("COUNTER") << " " << c.path() << "\n";
_writeAnnotations(os, c);
os << "# sumW\t sumW2\t numEntries\n";
os << c.sumW() << "\t" << c.sumW2() << "\t" << c.numEntries() << "\n";
os << "END " << _iotypestr("COUNTER") << "\n\n";
os.flags(oldflags);
}
void WriterYODA::writeHisto1D(std::ostream& os, const Histo1D& h) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("HISTO1D") << " " << h.path() << "\n";
_writeAnnotations(os, h);
try {
//if ( h.totalDbn().effNumEntries() > 0 ) {
os << "# Mean: " << h.xMean() << "\n";
os << "# Area: " << h.integral() << "\n";
} catch (LowStatsError& e) {
//
}
os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
os << "Total \tTotal \t";
os << h.totalDbn().sumW() << "\t" << h.totalDbn().sumW2() << "\t";
os << h.totalDbn().sumWX() << "\t" << h.totalDbn().sumWX2() << "\t";
os << h.totalDbn().numEntries() << "\n";
os << "Underflow\tUnderflow\t";
os << h.underflow().sumW() << "\t" << h.underflow().sumW2() << "\t";
os << h.underflow().sumWX() << "\t" << h.underflow().sumWX2() << "\t";
os << h.underflow().numEntries() << "\n";
os << "Overflow\tOverflow\t";
os << h.overflow().sumW() << "\t" << h.overflow().sumW2() << "\t";
os << h.overflow().sumWX() << "\t" << h.overflow().sumWX2() << "\t";
os << h.overflow().numEntries() << "\n";
os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t numEntries\n";
for (const HistoBin1D& b : h.bins()) {
os << b.xMin() << "\t" << b.xMax() << "\t";
os << b.sumW() << "\t" << b.sumW2() << "\t";
os << b.sumWX() << "\t" << b.sumWX2() << "\t";
os << b.numEntries() << "\n";
}
os << "END " << _iotypestr("HISTO1D") << "\n\n";
os.flags(oldflags);
}
void WriterYODA::writeHisto2D(std::ostream& os, const Histo2D& h) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("HISTO2D") << " " << h.path() << "\n";
_writeAnnotations(os, h);
try {
//if ( h.totalDbn().numEntries() > 0 )
os << "# Mean: (" << h.xMean() << ", " << h.yMean() << ")\n";
os << "# Volume: " << h.integral() << "\n";
} catch (LowStatsError& e) {
//
}
os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n";
// Total distribution
const Dbn2D& td = h.totalDbn();
os << "Total \tTotal \t";
os << td.sumW() << "\t" << td.sumW2() << "\t";
os << td.sumWX() << "\t" << td.sumWX2() << "\t";
os << td.sumWY() << "\t" << td.sumWY2() << "\t";
os << td.sumWXY() << "\t";
os << td.numEntries() << "\n";
// Outflows
/// @todo Disabled for now, reinstate with a *full* set of outflow info to allow marginalisation
os << "# 2D outflow persistency not currently supported until API is stable\n";
// for (int ix = -1; ix <= 1; ++ix) {
// for (int iy = -1; iy <= 1; ++iy) {
// if (ix == 0 && iy == 0) continue;
// os << "Outflow\t" << ix << ":" << iy << "\t";
// const Dbn2D& d = h.outflow(ix, iy);
// os << d.sumW() << "\t" << d.sumW2() << "\t";
// os << d.sumWX() << "\t" << d.sumWX2() << "\t";
// os << d.sumWY() << "\t" << d.sumWY2() << "\t";
// os << d.sumWXY() << "\t";
// os << d.numEntries() << "\n";
// }
// }
// Bins
os << "# xlow\t xhigh\t ylow\t yhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwxy\t numEntries\n";
for (const HistoBin2D& b : h.bins()) {
os << b.xMin() << "\t" << b.xMax() << "\t";
os << b.yMin() << "\t" << b.yMax() << "\t";
os << b.sumW() << "\t" << b.sumW2() << "\t";
os << b.sumWX() << "\t" << b.sumWX2() << "\t";
os << b.sumWY() << "\t" << b.sumWY2() << "\t";
os << b.sumWXY() << "\t";
os << b.numEntries() << "\n";
}
os << "END " << _iotypestr("HISTO2D") << "\n\n";
os.flags(oldflags);
}
void WriterYODA::writeProfile1D(std::ostream& os, const Profile1D& p) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("PROFILE1D") << " " << p.path() << "\n";
_writeAnnotations(os, p);
os << "# ID\t ID\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
os << "Total \tTotal \t";
os << p.totalDbn().sumW() << "\t" << p.totalDbn().sumW2() << "\t";
os << p.totalDbn().sumWX() << "\t" << p.totalDbn().sumWX2() << "\t";
os << p.totalDbn().sumWY() << "\t" << p.totalDbn().sumWY2() << "\t";
os << p.totalDbn().numEntries() << "\n";
os << "Underflow\tUnderflow\t";
os << p.underflow().sumW() << "\t" << p.underflow().sumW2() << "\t";
os << p.underflow().sumWX() << "\t" << p.underflow().sumWX2() << "\t";
os << p.underflow().sumWY() << "\t" << p.underflow().sumWY2() << "\t";
os << p.underflow().numEntries() << "\n";
os << "Overflow\tOverflow\t";
os << p.overflow().sumW() << "\t" << p.overflow().sumW2() << "\t";
os << p.overflow().sumWX() << "\t" << p.overflow().sumWX2() << "\t";
os << p.overflow().sumWY() << "\t" << p.overflow().sumWY2() << "\t";
os << p.overflow().numEntries() << "\n";
os << "# xlow\t xhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t numEntries\n";
for (const ProfileBin1D& b : p.bins()) {
os << b.xMin() << "\t" << b.xMax() << "\t";
os << b.sumW() << "\t" << b.sumW2() << "\t";
os << b.sumWX() << "\t" << b.sumWX2() << "\t";
os << b.sumWY() << "\t" << b.sumWY2() << "\t";
os << b.numEntries() << "\n";
}
os << "END " << _iotypestr("PROFILE1D") << "\n\n";
os.flags(oldflags);
}
void WriterYODA::writeProfile2D(std::ostream& os, const Profile2D& p) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("PROFILE2D") << " " << p.path() << "\n";
_writeAnnotations(os, p);
os << "# sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
// Total distribution
const Dbn3D& td = p.totalDbn();
os << "Total \tTotal \t";
os << td.sumW() << "\t" << td.sumW2() << "\t";
os << td.sumWX() << "\t" << td.sumWX2() << "\t";
os << td.sumWY() << "\t" << td.sumWY2() << "\t";
os << td.sumWZ() << "\t" << td.sumWZ2() << "\t";
os << td.sumWXY() << "\t"; // << td.sumWXZ() << "\t" << td.sumWYZ() << "\t";
os << td.numEntries() << "\n";
// Outflows
/// @todo Disabled for now, reinstate with a *full* set of outflow info to allow marginalisation
os << "# 2D outflow persistency not currently supported until API is stable\n";
// for (int ix = -1; ix <= 1; ++ix) {
// for (int iy = -1; iy <= 1; ++iy) {
// if (ix == 0 && iy == 0) continue;
// os << "Outflow\t" << ix << ":" << iy << "\t";
// const Dbn3D& d = p.outflow(ix, iy);
// os << d.sumW() << "\t" << d.sumW2() << "\t";
// os << d.sumWX() << "\t" << d.sumWX2() << "\t";
// os << d.sumWY() << "\t" << d.sumWY2() << "\t";
// os << d.sumWZ() << "\t" << d.sumWZ2() << "\t";
// os << d.sumWXY() << "\t"; // << d.sumWXZ() << "\t" << d.sumWYZ() << "\t";
// os << d.numEntries() << "\n";
// }
// }
// Bins
os << "# xlow\t xhigh\t ylow\t yhigh\t sumw\t sumw2\t sumwx\t sumwx2\t sumwy\t sumwy2\t sumwz\t sumwz2\t sumwxy\t numEntries\n";
for (const ProfileBin2D& b : p.bins()) {
os << b.xMin() << "\t" << b.xMax() << "\t";
os << b.yMin() << "\t" << b.yMax() << "\t";
os << b.sumW() << "\t" << b.sumW2() << "\t";
os << b.sumWX() << "\t" << b.sumWX2() << "\t";
os << b.sumWY() << "\t" << b.sumWY2() << "\t";
os << b.sumWZ() << "\t" << b.sumWZ2() << "\t";
os << b.sumWXY() << "\t"; // << b.sumWXZ() << "\t" << b.sumWYZ() << "\t";
os << b.numEntries() << "\n";
}
os << "END " << _iotypestr("PROFILE2D") << "\n\n";
os.flags(oldflags);
}
void WriterYODA::writeScatter1D(std::ostream& os, const Scatter1D& s) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("SCATTER1D") << " " << s.path() << "\n";
//first write the Variations, a dummy annotation which
//contains the additional columns which will be written out
//for sytematic variations
YAML::Emitter out;
out << YAML::Flow ;
out << s.variations();
//os << "Variations" << ": " << out.c_str() << "\n";
// then write the regular annotations
_writeAnnotations(os, s);
std::vector<std::string> variations= s.variations();
//write headers
std::string headers="# xval\t ";
for (const auto &source : variations){
headers+=" xerr-"+source+"\t xerr+"+source+"\t";
}
os << headers << "\n";
//write points
for (const Point1D& pt : s.points()) {
// fill central value
os << pt.x();
// fill errors for variations. The first should always be "" which is nominal.
// Assumes here that all points in the Scatter have the same
// variations... if not a range error will get thrown from
// the point when the user tries to access a variation it
// doesn't have... @todo maybe better way to do this?
for (const auto &source : variations){
os << "\t" << pt.xErrMinus(source) << "\t" << pt.xErrPlus(source) ;
}
os << "\n";
}
os << "END " << _iotypestr("SCATTER1D") << "\n\n";
os << flush;
os.flags(oldflags);
}
void WriterYODA::writeScatter2D(std::ostream& os, const Scatter2D& s) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
-
os << "BEGIN " << _iotypestr("SCATTER2D") << " " << s.path() << "\n";
//first write the Variations, a dummy annotation which
//contains the additional columns which will be written out
//for sytematic variations
YAML::Emitter out;
out << YAML::Flow << YAML::BeginMap;
int counter=0;
std::vector<std::string> variations= s.variations();
- //write ErrBreakdown Annotation
- for (const Point2D& pt : s.points()) {
- out << YAML::Key << counter;
- out << YAML::Value << YAML::BeginMap;
- for (const auto &source : variations){
- if (source.length()==0) continue;
- out << YAML::Key << source;
- out << YAML::Value << YAML::BeginMap;
- out << YAML::Key << "dn" << YAML::Value << pt.yErrMinus(source);
- out << YAML::Key << "up" << YAML::Value << pt.yErrPlus(source);
- out << YAML::EndMap;
- }
- out << YAML::EndMap;
- }
- out << YAML::EndMap;
- os << "ErrorBreakdown" << ": " << out.c_str() << "\n";
- // then write the regular annotations
+ // write annotations
_writeAnnotations(os, s);
//write headers
/// @todo Change ordering to {vals} {errs} {errs} ...
std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t";
//for (const auto &source : variations){
// headers+=" yerr-"+source+"\t yerr+"+source+"\t";
//}
os << headers << "\n";
//write points
for (const Point2D& pt : s.points()) {
/// @todo Change ordering to {vals} {errs} {errs} ...
// fill central value
os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
os << pt.y();
// fill errors for variations. The first should always be "" which is nominal.
// Assumes here that all points in the Scatter have the same
// variations... if not a range error will get thrown from
// the point when the user tries to access a variation it
// doesn't have... @todo maybe better way to do this?
//for (const auto &source : variations){
os << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() ;
// }
os << "\n";
}
os << "END " << _iotypestr("SCATTER2D") << "\n\n";
os << flush;
os.flags(oldflags);
}
void WriterYODA::writeScatter3D(std::ostream& os, const Scatter3D& s) {
ios_base::fmtflags oldflags = os.flags();
os << scientific << showpoint << setprecision(_precision);
os << "BEGIN " << _iotypestr("SCATTER3D") << " " << s.path() << "\n";
//first write the Variations, a dummy annotation which
//contains the additional columns which will be written out
//for sytematic variations
YAML::Emitter out;
out << YAML::Flow ;
out << s.variations();
// then write the regular annotations
_writeAnnotations(os, s);
std::vector<std::string> variations= s.variations();
//write headers
/// @todo Change ordering to {vals} {errs} {errs} ...
std::string headers="# xval\t xerr-\t xerr+\t yval\t yerr-\t yerr+\t zval\t ";
for (const auto &source : variations){
headers+=" zerr-"+source+"\t zerr+"+source+"\t";
}
os << headers << "\n";
//write points
for (const Point3D& pt : s.points()) {
/// @todo Change ordering to {vals} {errs} {errs} ...
// fill central value
os << pt.x() << "\t" << pt.xErrMinus() << "\t" << pt.xErrPlus() << "\t";
os << pt.y() << "\t" << pt.yErrMinus() << "\t" << pt.yErrPlus() << "\t";
os << pt.z();
// fill errors for variations. The first should always be "" which is nominal.
// Assumes here that all points in the Scatter have the same
// variations... if not a range error will get thrown from
// the point when the user tries to access a variation it
// doesn't have... @todo maybe better way to do this?
for (const auto &source : variations){
os << "\t" << pt.zErrMinus(source) << "\t" << pt.zErrPlus(source) ;
}
os << "\n";
}
os << "END " << _iotypestr("SCATTER3D") << "\n\n";
os << flush;
os.flags(oldflags);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 19, 6:14 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3805543
Default Alt Text
(22 KB)
Attached To
rYODAHG yodahg
Event Timeline
Log In to Comment