yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
Scatter1D.cc
Go to the documentation of this file.
1 #include "YODA/Scatter1D.h"
2 #include "YODA/Counter.h"
3 #include <sstream>
4 #include "yaml-cpp/yaml.h"
5 #ifdef YAML_NAMESPACE
6 #define YAML YAML_NAMESPACE
7 #endif
8 
9 namespace YODA {
10 
11 
14  Scatter1D rtn;
15  for (const std::string& a : c.annotations())
16  rtn.setAnnotation(a, c.annotation(a));
17  rtn.setAnnotation("Type", c.type()); // might override the copied ones
18  Point1D pt(c.val(), c.err());
19  pt.setParent(&rtn);
20  rtn.addPoint(pt);
21  return rtn;
22  }
23 
24 
26  if (this->_variationsParsed) { return;}
27  if (!(this->hasAnnotation("ErrorBreakdown"))) { return; }
28  YAML::Node errorBreakdown;
29  errorBreakdown = YAML::Load(this->annotation("ErrorBreakdown"));
30 
31  if (errorBreakdown.size()) {
32  for (size_t thisPointIndex = 0; thisPointIndex < this->numPoints(); ++thisPointIndex) {
33  Point1D &thispoint = this->_points[thisPointIndex];
34  YAML::Node variations = errorBreakdown[thisPointIndex];
35  for (const auto& variation : variations) {
36  const std::string variationName = variation.first.as<std::string>();
37  double eyp = variation.second["up"].as<double>();
38  double eym = variation.second["dn"].as<double>();
39  thispoint.setXErrs(eym,eyp,variationName);
40  }
41  }
42  this-> _variationsParsed =true;
43  }
44  }
45 
46 
48  std::vector<std::string> Scatter1D::variations() const {
50  std::vector<std::string> vecvariations;
51  for (auto& point : this->_points) {
52  for (auto& it : point.errMap()) {
53  // if the variation is not already in the vector, add it!
54  if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()) {
55  vecvariations.push_back(it.first);
56  }
57  }
58  }
59  return vecvariations;
60  }
61 
62 }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter1D.h:164
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:201
A weighted counter.
Definition: Counter.h:24
void setParent(Scatter *parent)
Definition: Point.h:114
void parseVariations()
Definition: Scatter1D.cc:25
double val(bool=false) const
Get the value.
Definition: Counter.h:146
Point1D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter1D.h:182
A 1D data point to be contained in a Scatter1D.
Definition: Point1D.h:18
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
std::vector< std::string > variations() const
Get the list of variations stored in the points.
Definition: Scatter1D.cc:48
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:13
double err() const
Definition: Counter.h:151
virtual std::string type() const
Get name of the analysis object type.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point1D.h:234
void setXErrs(double ex, std::string source="")
Set symmetric x error (alias)
Definition: Point1D.h:141
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
std::vector< std::string > annotations() const