yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
Scatter3D.cc
Go to the documentation of this file.
1 #include "YODA/Scatter3D.h"
2 #include "YODA/Histo2D.h"
3 #include "YODA/Profile2D.h"
4 #include "YODA/Exceptions.h"
5 #include <sstream>
6 
7 namespace YODA {
8 
9 
10  Scatter3D mkScatter(const Histo2D& h, bool usefocus) {
11  Scatter3D rtn;
12  for (const std::string& a : h.annotations())
13  rtn.setAnnotation(a, h.annotation(a));
14  rtn.setAnnotation("Type", h.type());
15  for (size_t i = 0; i < h.numBins(); ++i) {
16  const HistoBin2D& b = h.bin(i);
17 
19 
20  double x = b.xMid();
21  if (usefocus) {
22  try {
23  x = b.xFocus();
24  } catch (const LowStatsError& lse) {
25  x = b.xMid();
26  }
27  }
28  const double exminus = x - b.xMin();
29  const double explus = b.xMax() - x;
30 
31  double y = b.yMid();
32  if (usefocus) {
33  try {
34  y = b.yFocus();
35  } catch (const LowStatsError& lse) {
36  y = b.yMid();
37  }
38  }
39  const double eyminus = y - b.yMin();
40  const double eyplus = b.yMax() - y;
41 
43 
44  const double z = b.height();
45  const double ez = b.heightErr();
46 
47  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
48  }
49 
50  return rtn;
51  }
52 
53 
54  Scatter3D mkScatter(const Profile2D& h, bool usefocus, bool usestddev) {
55  Scatter3D rtn;
56  for (const std::string& a : h.annotations())
57  rtn.setAnnotation(a, h.annotation(a));
58  rtn.setAnnotation("Type", h.type());
59  for (size_t i = 0; i < h.numBins(); ++i) {
60  const ProfileBin2D& b = h.bin(i);
61 
63 
64  double x = b.xMid();
65  if (usefocus) {
66  try {
67  x = b.xFocus();
68  } catch (const LowStatsError& lse) {
69  x = b.xMid();
70  }
71  }
72  const double exminus = x - b.xMin();
73  const double explus = b.xMax() - x;
74 
75  double y = b.yMid();
76  if (usefocus) {
77  try {
78  y = b.yFocus();
79  } catch (const LowStatsError& lse) {
80  y = b.yMid();
81  }
82  }
83  const double eyminus = y - b.yMin();
84  const double eyplus = b.yMax() - y;
85 
87 
88 
89  double z;
90  try {
91  z = b.mean();
92  } catch (const LowStatsError& lse) {
93  z = std::numeric_limits<double>::quiet_NaN();
94  }
95  double ez;
96  try {
97  ez = usestddev ? b.stdDev() : b.stdErr();
98  } catch (const LowStatsError& lse) {
99  ez = std::numeric_limits<double>::quiet_NaN();
100  }
101 
102  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
103  }
104 
105  return rtn;
106  }
107 
108 
109  const std::vector<std::string> Scatter3D::variations() const {
110  std::vector<std::string> vecvariations;
111  for (auto &point : this->_points){
112  for (auto &it : point.errMap()){
113  //if the variation is not already in the vector, add it !
114  if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
115  vecvariations.push_back(it.first);
116  }
117  }
118  }
119  return vecvariations;
120  }
121 
122 }
double yFocus() const
The mean y position in the bin, or the y midpoint if that is not available.
Definition: Bin2D.h:212
A Bin1D specialised for handling profile-type information.
Definition: ProfileBin2D.h:23
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:163
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:142
const std::vector< std::string > variations() const
Get the list of variations stored in the points.
Definition: Scatter3D.cc:109
double stdErr() const
The standard error on the mean.
Definition: ProfileBin2D.h:134
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:158
double stdDev() const
The std deviation of the z distribution about the mean.
Definition: ProfileBin2D.h:124
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:147
double xMid() const
Middle of the bin in x.
Definition: Bin2D.h:169
ProfileBin2D & bin(size_t index)
Access a bin by index (non-const)
Definition: Profile2D.h:252
Point3D & point(size_t index)
Get a reference to the point with index index.
Definition: Scatter3D.h:214
A two-dimensional profile histogram.
Definition: Profile2D.h:31
Errors relating to insufficient (effective) statistics.
Definition: Exceptions.h:72
double mean() const
The mean of the z distribution.
Definition: ProfileBin2D.h:119
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
double xFocus() const
The mean x position in the bin, or the x midpoint if that is not available.
Definition: Bin2D.h:207
size_t numBins() const
Number of bins of this axis (not counting under/over flow)
Definition: Profile2D.h:268
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9
double height() const
The height of a bin.
Definition: HistoBin2D.h:106
A very generic data type which is just a collection of 3D data points with errors.
Definition: Scatter3D.h:24
A Bin2D specialised for handling histogram-type information.
Definition: HistoBin2D.h:21
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point3D.h:465
virtual std::string type() const
Get name of the analysis object type.
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:266
double heightErr() const
Error on height.
Definition: HistoBin2D.h:111
A two-dimensional histogram.
Definition: Histo2D.h:31
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
size_t numBins() const
Number of bins.
Definition: Histo2D.h:283
double yMid() const
Middle of the bin in y.
Definition: Bin2D.h:174
void addPoint(const Point3D &pt)
Insert a new point.
Definition: Scatter3D.h:233
std::vector< std::string > annotations() const