CombineHarvester
SOverBTools.cc
Go to the documentation of this file.
2 #include "TH1.h"
3 #include "TAxis.h"
4 
5 namespace ch {
6 
7 SOverBInfo::SOverBInfo(TH1F const* sig, TH1F const* bkg, unsigned steps,
8  double frac) {
9  double xmin = sig->GetXaxis()->GetXmin();
10  double xmax = sig->GetXaxis()->GetXmax();
11  double step_size = (xmax - xmin) / static_cast<double>(steps);
12  double sig_tot = sig->Integral();
13  double lower_limit = 0;
14  double upper_limit = 0;
15  double ofrac = (1. - frac) / 2.;
16  for (unsigned j = 0; j < steps; ++j) {
17  double integral = ch::IntegrateFloatRange(
18  sig, xmin, xmin + (step_size * static_cast<double>(j)));
19  if (integral / sig_tot > ofrac) {
20  lower_limit = xmin + (step_size * static_cast<double>(j));
21  break;
22  }
23  }
24  for (unsigned j = 0; j < steps; ++j) {
25  double integral = ch::IntegrateFloatRange(
26  sig, xmax - (step_size * static_cast<double>(j)), xmax);
27  if (integral / sig_tot > ofrac) {
28  upper_limit = xmax - (step_size * static_cast<double>(j));
29  break;
30  }
31  }
32  x_lo = lower_limit;
33  x_hi = upper_limit;
34  s = ch::IntegrateFloatRange(sig, lower_limit, upper_limit);
35  b = ch::IntegrateFloatRange(bkg, lower_limit, upper_limit);
36 }
37 
38 double IntegrateFloatRange(TH1F const* hist, double xmin, double xmax) {
39  TAxis const* axis = hist->GetXaxis();
40  int bmin = axis->FindFixBin(xmin);
41  int bmax = axis->FindFixBin(xmax);
42  double integral = hist->Integral(bmin, bmax);
43  integral -= hist->GetBinContent(bmin) * (xmin - axis->GetBinLowEdge(bmin)) /
44  axis->GetBinWidth(bmin);
45  integral -= hist->GetBinContent(bmax) * (axis->GetBinUpEdge(bmax) - xmax) /
46  axis->GetBinWidth(bmax);
47  return integral;
48 }
49 }
Definition: Algorithm.h:10
double IntegrateFloatRange(TH1F const *hist, double xmin, double xmax)
Definition: SOverBTools.cc:38