ATLAS Offline Software
Functions
widthestimators::binned Namespace Reference

Functions

template<typename T >
std::vector< double > get_cum_sum (const T &histo, bool normed=false)
 cumulative sum (e.g. More...
 
template<typename T >
std::pair< double, double > find_window (const T &histo, double prob=PROB_1SIGMA)
 return smallest window (first value, second value) containing prob fraction of the events More...
 
template<typename T >
double smallest_interval (const T &histo, double prob=PROB_1SIGMA)
 
template<typename T >
double s68 (const T &histo)
 
template<typename T >
double s90 (const T &histo)
 

Function Documentation

◆ find_window()

template<typename T >
std::pair<double, double> widthestimators::binned::find_window ( const T &  histo,
double  prob = PROB_1SIGMA 
)

return smallest window (first value, second value) containing prob fraction of the events

Definition at line 59 of file widthestimators.h.

60  {
61  if (histo->GetNbinsX() <= 3 || histo->Integral() == 0.)
62  {
63  return std::make_pair<double>(0, 0);
64  }
65 
66  std::vector<double> cum_sum = get_cum_sum(histo, true);
67  double min_width = histo->GetBinCenter(histo->GetNbinsX()) - histo->GetBinCenter(1);
68  std::pair<int, int> window_bin(0, histo->GetNbinsX() + 1);
69 
70  for (int ibin = 0; ibin != histo->GetNbinsX() + 1; ++ibin)
71  {
72  const double target_prob = prob + cum_sum[ibin];
73  if (target_prob > 1)
74  break;
75 
76  const auto up_it = std::upper_bound(cum_sum.begin() + ibin, cum_sum.end(), target_prob);
77  const auto end_bin = std::distance(cum_sum.begin(), up_it);
78  const double width = histo->GetBinCenter(end_bin) - histo->GetBinCenter(ibin);
79 
80  if (width < min_width)
81  {
82  min_width = width;
83  window_bin.first = ibin;
84  window_bin.second = end_bin;
85  }
86  }
87  return std::make_pair<double>(histo->GetBinCenter(window_bin.first), histo->GetBinCenter(window_bin.second));
88  }

◆ get_cum_sum()

template<typename T >
std::vector<double> widthestimators::binned::get_cum_sum ( const T &  histo,
bool  normed = false 
)

cumulative sum (e.g.

(non-normalized) empirical CDF)

Definition at line 37 of file widthestimators.h.

38  {
39  // use double since it can be weighted
40  std::vector<double> cum_sum(histo->GetNbinsX() + 2);
41 
42  std::partial_sum(
43  histo->GetArray(),
44  histo->GetArray() + histo->GetNbinsX() + 2,
45  cum_sum.begin());
46 
47  if (normed)
48  {
49  const double last_value = cum_sum.back();
50  std::transform(cum_sum.begin(), cum_sum.end(), cum_sum.begin(),
51  [&last_value](auto &c) { return c / last_value; });
52  }
53 
54  return cum_sum;
55  }

◆ s68()

template<typename T >
double widthestimators::binned::s68 ( const T &  histo)

Definition at line 98 of file widthestimators.h.

◆ s90()

template<typename T >
double widthestimators::binned::s90 ( const T &  histo)

Definition at line 101 of file widthestimators.h.

101 { return smallest_interval(histo, 0.90); }

◆ smallest_interval()

template<typename T >
double widthestimators::binned::smallest_interval ( const T &  histo,
double  prob = PROB_1SIGMA 
)

Definition at line 91 of file widthestimators.h.

92  {
93  const auto window = find_window(histo, prob);
94  return 0.5 * (window.second - window.first);
95  }
widthestimators::binned::find_window
std::pair< double, double > find_window(const T &histo, double prob=PROB_1SIGMA)
return smallest window (first value, second value) containing prob fraction of the events
Definition: widthestimators.h:59
widthestimators::binned::smallest_interval
double smallest_interval(const T &histo, double prob=PROB_1SIGMA)
Definition: widthestimators.h:91
widthestimators::binned::get_cum_sum
std::vector< double > get_cum_sum(const T &histo, bool normed=false)
cumulative sum (e.g.
Definition: widthestimators.h:37
covarianceTool.prob
prob
Definition: covarianceTool.py:678
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
widthestimators::PROB_1SIGMA
const double PROB_1SIGMA
Definition: widthestimators.h:29
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
python.compressB64.c
def c
Definition: compressB64.py:93