yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
Stats.h
Go to the documentation of this file.
1 #include "YODA/Histo1D.h"
2 #include "YODA/Scatter2D.h"
3 
4 namespace YODA {
5 
6 
8  double chi2(const HistoBin1D& b1, const HistoBin1D& b2) {
10  const double diff = b1.height() - b2.height();
11  return sqr(diff) / add_quad(b1.heightErr(), b2.heightErr()); //< Histo errs are symmetric
12  }
13 
15  double chi2(const Histo1D& h1, const Histo1D& h2) {
17  double hist_chi2 = 0;
18  BOOST_FOREACH (size_t i = 0; i < h1.numBins(); ++i) {
19  hist_chi2 += chi2(h1.bin(i), h2.bin(i));
20  }
21  return hist_chi2;
22  }
23 
24 
25 
27  double chi2(const ProfileBin1D& b1, const ProfileBin1D& b2) {
29  const double diff = b1.mean() - b2.mean();
30  return sqr(diff) / add_quad(b1.stdErr(), b2.stdErr()); //< Profile histo errs are symmetric
31  }
32 
34  double chi2(const Profile1D& h1, const Profile1D& h2) {
36  double hist_chi2 = 0;
37  BOOST_FOREACH (size_t i = 0; i < h1.numBins(); ++i) {
38  hist_chi2 += chi2(h1.bin(i), h2.bin(i));
39  }
40  return hist_chi2;
41  }
42 
43 
44 
47  double chi2(const Point2D& p1, const Point2D& p2) {
49  const double diff = p1.y() - p2.y();
50  const double err1 = (diff > 0) ? p1.yErrMinus() : p1.yErrPlus(); //< Scatter errs are asymmetric
51  const double err2 = (diff > 0) ? p2.yErrPlus() : p2.yErrMinus(); //< Scatter errs are asymmetric
52  return sqr(diff) / add_quad(err1, err2);
53  }
54 
56  double chi2(const Scatter2D& s1, const Scatter2D& s2) {
58  double hist_chi2 = 0;
59  BOOST_FOREACH (size_t i = 0; i < s1.numPoints(); ++i) {
60  hist_chi2 += chi2(s1.point(i), s2.point(i));
61  }
62  return hist_chi2;
63  }
64 
65 
66 }
A very generic data type which is just a collection of 2D data points with errors.
Definition: Scatter2D.h:24
double y() const
Get y value.
Definition: Point2D.h:112
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Profile1D.h:219
A one-dimensional histogram.
Definition: Histo1D.h:26
double heightErr() const
Definition: HistoBin1D.h:116
double yErrPlus(std::string source="") const
Get positive y-error value.
Definition: Point2D.h:223
A Bin1D specialised for handling histogram-type information.
Definition: HistoBin1D.h:21
double yErrMinus(std::string source="") const
Get negative y-error value.
Definition: Point2D.h:217
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207
Point2D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter2D.h:197
double chi2(const HistoBin1D &b1, const HistoBin1D &b2)
Definition: Stats.h:8
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:179
double stdErr() const
The standard error on the mean.
Definition: ProfileBin1D.h:126
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:213
A Bin1D specialised for handling profile-type information.
Definition: ProfileBin1D.h:23
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:217
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Histo1D.h:195
double height() const
The height is defined as area/width.
Definition: HistoBin1D.h:98
double mean() const
The mean of the y distribution.
Definition: ProfileBin1D.h:111
A one-dimensional profile histogram.
Definition: Profile1D.h:33
ProfileBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Profile1D.h:242
A 2D data point to be contained in a Scatter2D.
Definition: Point2D.h:18