All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EnsembleRatio.cxx
Go to the documentation of this file.
2 
4 
5 #include "TGraphAsymmErrors.h"
6 #include "TH1.h"
7 
8 namespace ana
9 {
10  //----------------------------------------------------------------------
12  const EnsembleSpectrum& denom)
13  : fNom(num.Nominal(), denom.Nominal())
14  {
15  assert(num.NUniverses() == denom.NUniverses());
16  fUnivs.reserve(num.NUniverses());
17  for(unsigned int i = 0; i < num.NUniverses(); ++i)
18  fUnivs.emplace_back(num.Universe(i), denom.Universe(i));
19  }
20 
21  //----------------------------------------------------------------------
22  TGraphAsymmErrors* EnsembleRatio::ErrorBand() const
23  {
24  std::unique_ptr<TH1D> hnom(fNom.ToTH1());
25 
26  std::vector<std::unique_ptr<TH1D>> hunivs;
27  hunivs.reserve(fUnivs.size());
28  for(const Ratio& u: fUnivs) hunivs.emplace_back(u.ToTH1());
29 
30  TGraphAsymmErrors* g = new TGraphAsymmErrors;
31 
32  for(int binIdx = 0; binIdx < hnom->GetNbinsX()+2; ++binIdx){
33  const double xnom = hnom->GetXaxis()->GetBinCenter(binIdx);
34  const double ynom = hnom->GetBinContent(binIdx);
35  g->SetPoint(binIdx, xnom, ynom);
36 
37  const double dx = hnom->GetXaxis()->GetBinWidth(binIdx);
38 
39  std::vector<double> ys;
40  ys.reserve(hunivs.size());
41  for(const std::unique_ptr<TH1D>& hu: hunivs){
42  ys.push_back(hu->GetBinContent(binIdx));
43  }
44 
45  // 1 sigma
46  const double y0 = FindQuantile(.5-0.6827/2, ys);
47  const double y1 = FindQuantile(.5+0.6827/2, ys);
48 
49  // It's theoretically possible for the central value to be outside the
50  // error bands - clamp to zero in that case
51  g->SetPointError(binIdx, dx/2, dx/2,
52  std::max(ynom-y0, 0.),
53  std::max(y1-ynom, 0.));
54  } // end for binIdx
55 
56  return g;
57  }
58 
59  //----------------------------------------------------------------------
61  {
62  assert(rhs.NUniverses() == fUnivs.size());
63  fNom *= rhs.fNom;
64  for(unsigned int i = 0; i < fUnivs.size(); ++i)
65  fUnivs[i] *= rhs.fUnivs[i];
66  return *this;
67  }
68 
69  //----------------------------------------------------------------------
71  {
72  EnsembleRatio ret = *this;
73  ret *= rhs;
74  return ret;
75  }
76 
77  //----------------------------------------------------------------------
79  {
80  assert(rhs.NUniverses() == fUnivs.size());
81  fNom /= rhs.fNom;
82  for(unsigned int i = 0; i < fUnivs.size(); ++i)
83  fUnivs[i] /= rhs.fUnivs[i];
84  return *this;
85  }
86 
87  //----------------------------------------------------------------------
89  {
90  EnsembleRatio ret = *this;
91  ret /= rhs;
92  return ret;
93  }
94 }
EnsembleRatio & operator/=(const EnsembleRatio &rhs)
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:116
EnsembleRatio operator/(const EnsembleRatio &rhs) const
double FindQuantile(double frac, std::vector< double > &xs)
process_name opflashCryoW ana
BEGIN_PROLOG g
TGraphAsymmErrors * ErrorBand() const
EnsembleRatio & operator*=(const EnsembleRatio &rhs)
EnsembleRatio(const EnsembleSpectrum &nom, const EnsembleSpectrum &denom)
Represent the ratio between two spectra.
Definition: Ratio.h:8
unsigned int NUniverses() const
Definition: EnsembleRatio.h:19
std::vector< Ratio > fUnivs
Definition: EnsembleRatio.h:36
EnsembleRatio operator*(const EnsembleRatio &rhs) const
Spectrum Universe(unsigned int i) const
unsigned int NUniverses() const