yoda is hosted by Hepforge, IPPP Durham
 YODA - Yet more Objects for Data Analysis  1.9.0
Counter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2021 The YODA collaboration (see AUTHORS for details)
5 //
6 #include "YODA/Counter.h"
7
8 #include <cmath>
9 #include <iostream>
10 using namespace std;
11
12 namespace YODA {
13
14
16  Counter::Counter(const Counter& c, const std::string& path)
17  : AnalysisObject("Counter", (path.size() == 0) ? c.path() : path, c, c.title())
18  {
19  _dbn = c._dbn;
20  }
21
22
23  // Divide two counters
25  Scatter1D divide(const Counter& numer, const Counter& denom) {
26  Scatter1D rtn;
27  if (denom.val() != 0) {
28  const double val = numer.val() / denom.val();
31  } else {
33  }
34  return rtn;
35  }
36
37
38  // Calculate a histogrammed efficiency ratio of two histograms
40  Scatter1D efficiency(const Counter& accepted, const Counter& total) {
41  Scatter1D tmp = divide(accepted, total);
42  assert(tmp.numPoints() == 1);
43
45
46  // Check that the numerator is consistent with being a subset of the denominator (NOT effNumEntries here!)
47  if (accepted.numEntries() > total.numEntries() || accepted.sumW() > total.sumW())
48  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator");
49
50  // If no entries on the denominator, set eff = err = 0 and move to the next bin
53  double eff = std::numeric_limits<double>::quiet_NaN();
54  double err = std::numeric_limits<double>::quiet_NaN();
55  if (total.sumW() != 0) {
56  eff = accepted.sumW() / total.sumW(); //< Actually this is already calculated by the division...
57  err = sqrt(abs( ((1-2*eff)*accepted.sumW2() + sqr(eff)*total.sumW2()) / sqr(total.sumW()) ));
58  }
59
61
62  tmp.point(0).setX(eff, err);
63  return tmp;
64  }
65
66
67 }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter1D.h:164
Insert a new point.
Definition: Scatter1D.h:201
STL namespace.
double sumW2(bool=false) const
Get the sum of squared weights.
Definition: Counter.h:143
A weighted counter.
Definition: Counter.h:24
double numEntries(bool=false) const
Get the number of fills.
Definition: Counter.h:134
Error for problems introduced outside YODA, to put it nicely.
Definition: Exceptions.h:100
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:208
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
Definition: MathUtils.h:214
double err() const
Definition: Counter.h:151
AnalysisObject is the base class for histograms and scatters.
double relErr() const
Definition: Counter.h:156
void setX(double x)
Set x value.
Definition: Point1D.h:84
Scatter1D efficiency(const Counter &accepted, const Counter &total)
Calculate an efficiency ratio of two counters.
Definition: Counter.cc:40
double sumW(bool=false) const
Get the sum of weights.
Definition: Counter.h:140