YODA is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.3.1
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 
6 namespace YODA {
7 
8 
9  // Add two scatters
10  Scatter3D add(const Scatter3D& , const Scatter3D& ) {
12  throw Exception("Implement me!");
13  Scatter3D tmp;
14  return tmp;
15  }
16 
17 
18  // Subtract two scatters
19  Scatter3D subtract(const Scatter3D& , const Scatter3D& ) {
21  throw Exception("Implement me!");
22  Scatter3D tmp;
23  return tmp;
24  }
25 
26 
28 
29 
30  Scatter3D mkScatter(const Histo2D& h, bool usefocus) {
31  Scatter3D rtn;
32  BOOST_FOREACH (const std::string& a, h.annotations())
33  rtn.setAnnotation(a, h.annotation(a));
34  rtn.setAnnotation("Type", h.type());
35  for (size_t i = 0; i < h.numBins(); ++i) {
36  const HistoBin2D& b = h.bin(i);
37 
38  const double x = usefocus ? b.xFocus() : b.xMid();
39  const double exminus = x - b.xMin();
40  const double explus = b.xMax() - x;
41 
42  const double y = usefocus ? b.yFocus() : b.yMid();
43  const double eyminus = y - b.yMin();
44  const double eyplus = b.yMax() - y;
45 
46  const double z = b.height();
47  const double ez = b.heightErr();
48 
49  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
50  }
51 
52  return rtn;
53  }
54 
55 
56  Scatter3D mkScatter(const Profile2D& h, bool usefocus) {
57  Scatter3D rtn;
58  BOOST_FOREACH (const std::string& a, h.annotations())
59  rtn.setAnnotation(a, h.annotation(a));
60  rtn.setAnnotation("Type", h.type());
61  for (size_t i = 0; i < h.numBins(); ++i) {
62  const ProfileBin2D& b = h.bin(i);
63 
64  const double x = usefocus ? b.xFocus() : b.xMid();
65  const double exminus = x - b.xMin();
66  const double explus = b.xMax() - x;
67 
68  const double y = usefocus ? b.yFocus() : b.yMid();
69  const double eyminus = y - b.yMin();
70  const double eyplus = b.yMax() - y;
71 
72  double z;
73  try {
74  z = b.mean();
75  } catch (const LowStatsError& lse) {
76  z = 0.0;
77  }
78  double ez;
79  try {
80  ez = b.stdErr();
81  } catch (const LowStatsError& lse) {
82  ez = 0.0;
83  }
84 
85  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
86  }
87 
88  return rtn;
89  }
90 
91 
93  Scatter3D divide(const Scatter3D& numer, const Scatter3D& denom) {
94  Scatter3D tmp;
95  for (size_t i = 0; i < numer.numPoints(); ++i) {
96  const Point3D& p1 = numer.point(i);
97  const Point3D& p2 = denom.point(i);
98 
99  // Assemble the x value and error
100  if (!fuzzyEquals(p1.xMin(), p2.xMin()) || !fuzzyEquals(p1.xMax(), p2.xMax()))
101  throw BinningError("Point x 'bins' are not equivalent");
102  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
103  const double x = (p1.xMin() + p1.xMax()) / 2.0;
104  const double exminus = x - p1.xMin();
105  const double explus = p1.xMax() - x;
106 
107  // Assemble the y value and error
108  if (!fuzzyEquals(p1.yMin(), p2.yMin()) || !fuzzyEquals(p1.yMax(), p2.yMax()))
109  throw BinningError("Point x 'bins' are not equivalent");
110  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
111  const double y = (p1.yMin() + p1.yMax()) / 2.0;
112  const double eyminus = y - p1.yMin();
113  const double eyplus = p1.yMax() - y;
114 
115  double z = 0;
116  double ez = 0;
117  if (p1.z() == 0 || p2.z() == 0) {
119  //throw LowStatsError("Requested division of empty bin");
120  } else {
121  z = p1.z() / p2.z();
123  ez = z * sqrt( sqr(p1.yErrAvg()/p1.z()) + sqr(p2.yErrAvg()/p2.z()) );
124  }
125  tmp.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
126  }
127  assert(tmp.numPoints() == numer.numPoints());
128  return tmp;
129  }
130 
131 
132 }
A Bin1D specialised for handling profile-type information.
Definition: ProfileBin2D.h:23
double xFocus() const
The mean x position in the bin, or the x midpoint if that is not available.
Definition: Bin2D.h:195
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter3D.h:181
double xMid() const
Middle of the bin in x.
Definition: Bin2D.h:163
Generic unspecialised YODA runtime error.
Definition: Exceptions.h:20
size_t numBins() const
Number of bins.
Definition: Histo2D.h:260
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:141
double yFocus() const
The mean y position in the bin, or the y midpoint if that is not available.
Definition: Bin2D.h:200
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:68
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:136
std::string type() const
Get name of the analysis object type for persisting.
Definition: Profile2D.h:124
ProfileBin2D & bin(size_t index)
Access a bin by index (non-const)
Definition: Profile2D.h:243
const std::vector< std::string > annotations() const
Get all the annotation names.
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:205
size_t numBins() const
Number of bins of this axis (not counting under/over flow)
Definition: Profile2D.h:256
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
Point3D & point(size_t index)
Get a reference to the point with index index.
Definition: Scatter3D.h:199
A two-dimensional profile histogram.
Definition: Profile2D.h:30
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
A 3D data point to be contained in a Scatter3D.
Definition: Point3D.h:17
double stdErr() const
The standard error on the mean.
Definition: ProfileBin2D.h:134
Errors relating to insufficient (effective) statistics.
Definition: Exceptions.h:72
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:152
double z() const
Get z value.
Definition: Point3D.h:105
Error for general binning problems.
Definition: Exceptions.h:27
double mean() const
The mean of the z distribution.
Definition: ProfileBin2D.h:119
virtual std::string type() const
Get name of the analysis object type, for persistency.
double height() const
The height of a bin.
Definition: HistoBin2D.h:106
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:219
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
double yMax() const
Get value plus positive y-error.
Definition: Point3D.h:243
double yMid() const
Middle of the bin in y.
Definition: Bin2D.h:168
A very generic data type which is just a collection of 3D data points with errors.
Definition: Scatter3D.h:23
A Bin2D specialised for handling histogram-type information.
Definition: HistoBin2D.h:21
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:247
double heightErr() const
Error on height.
Definition: HistoBin2D.h:111
double yMin() const
Get value minus negative y-error.
Definition: Point3D.h:238
A two-dimensional histogram.
Definition: Histo2D.h:30
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:157
double xMin() const
Get value minus negative x-error.
Definition: Point3D.h:175
void addPoint(const Point3D &pt)
Insert a new point.
Definition: Scatter3D.h:218
double xMax() const
Get value plus positive x-error.
Definition: Point3D.h:180
double yErrAvg() const
Get average y-error value.
Definition: Point3D.h:206