yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
Scatter2D.cc
Go to the documentation of this file.
1 #include "YODA/Scatter2D.h"
2 #include "YODA/Histo1D.h"
3 #include "YODA/Profile1D.h"
4 #include <sstream>
5 
6 namespace YODA {
7 
8 
10  Scatter2D mkScatter(const Histo1D& h, bool usefocus) {
11  Scatter2D rtn;
12  for (const std::string& a : h.annotations())
13  rtn.setAnnotation(a, h.annotation(a));
14  rtn.setAnnotation("Type", h.type()); // might override the copied ones
15  for (const HistoBin1D& b : h.bins()) {
16  const double x = usefocus ? b.xFocus() : b.xMid();
17  const double ex_m = x - b.xMin();
18  const double ex_p = b.xMax() - x;
19 
20  double y;
21  try {
22  y = b.height();
23  } catch (const Exception&) { // LowStatsError or WeightError
24  y = std::numeric_limits<double>::quiet_NaN();
25  }
26  double ey;
27  try {
28  ey = b.heightErr();
29  } catch (const Exception&) { // LowStatsError or WeightError
30  ey = std::numeric_limits<double>::quiet_NaN();
31  }
32 
33  const Point2D pt(x, y, ex_m, ex_p, ey, ey);
34  rtn.addPoint(pt);
35  }
36  assert(h.numBins() == rtn.numPoints());
37  return rtn;
38  }
39 
40 
42  Scatter2D mkScatter(const Profile1D& p, bool usefocus, bool usestddev) {
43  Scatter2D rtn;
44  for (const std::string& a : p.annotations())
45  rtn.setAnnotation(a, p.annotation(a));
46  rtn.setAnnotation("Type", p.type());
47  for (const ProfileBin1D& b : p.bins()) {
48  const double x = usefocus ? b.xFocus() : b.xMid();
49  const double ex_m = x - b.xMin();
50  const double ex_p = b.xMax() - x;
51 
52  double y;
53  try {
54  y = b.mean();
55  } catch (const Exception&) { // LowStatsError or WeightError
56  y = std::numeric_limits<double>::quiet_NaN();
57  }
58  double ey;
59  try {
60  ey = usestddev ? b.stdDev() : b.stdErr();
61  } catch (const Exception&) { // LowStatsError or WeightError
62  ey = std::numeric_limits<double>::quiet_NaN();
63  }
64 
65  const Point2D pt(x, y, ex_m, ex_p, ey, ey);
66  rtn.addPoint(pt);
67  }
68  assert(p.numBins() == rtn.numPoints());
69  return rtn;
70  }
71 
72  const std::vector<std::string> Scatter2D::variations() const {
73  std::vector<std::string> vecvariations;
74  for (auto &point : this->_points){
75  for (auto &it : point.errMap()){
76  //if the variation is not already in the vector, add it !
77  if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
78  vecvariations.push_back(it.first);
79  }
80  }
81  }
82  return vecvariations;
83  }
84 
85 }
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:216
A very generic data type which is just a collection of 2D data points with errors.
Definition: Scatter2D.h:24
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Profile1D.h:219
Generic unspecialised YODA runtime error.
Definition: Exceptions.h:20
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
A one-dimensional histogram.
Definition: Histo1D.h:26
A Bin1D specialised for handling histogram-type information.
Definition: HistoBin1D.h:21
Point2D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter2D.h:197
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:179
const std::vector< std::string > variations() const
Get the list of variations stored in the points.
Definition: Scatter2D.cc:72
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
std::vector< YODA::ProfileBin1D > & bins()
Access the bin vector.
Definition: Profile1D.h:235
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
A Bin1D specialised for handling profile-type information.
Definition: ProfileBin1D.h:23
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Histo1D.h:195
virtual std::string type() const
Get name of the analysis object type.
A one-dimensional profile histogram.
Definition: Profile1D.h:33
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point2D.h:381
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
A 2D data point to be contained in a Scatter2D.
Definition: Point2D.h:18