2#ifndef RIVET_HISTOGROUP_HH
3#define RIVET_HISTOGROUP_HH
5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/Tools/RivetYODA.hh"
15 template <
size_t FillDim,
typename T,
typename AxisT>
16 typename YODA::FillableStorage<FillDim, T, AxisT>::FillAdapterT
17 groupAdapter = [](
auto& ,
auto&& ,
double ,
double ) { };
21 template <
typename GroupAxisT,
typename... AxisT>
22 class HistoGroup :
public YODA::FillableStorage<sizeof...(AxisT)+1, BinnedHistoPtr<AxisT...>, GroupAxisT>,
23 public YODA::Fillable {
28 using FillDim = std::integral_constant<size_t,
sizeof...(AxisT)+1>;
32 HistoGroup(
const std::vector<GroupAxisT>& edges)
33 : BaseT(YODA::Axis<GroupAxisT>(edges), groupAdapter<FillDim{},
BinContentT, GroupAxisT>) { }
35 HistoGroup(std::initializer_list<GroupAxisT>&& edges)
36 : BaseT(YODA::Axis<GroupAxisT>(std::move(edges)), groupAdapter<FillDim{},
BinContentT, GroupAxisT>) { }
38 int fill(GroupAxisT tmpCoord, AxisT... coords,
const double weight = 1.0,
const double fraction = 1.0) {
39 auto& bin = BaseT::binAt(tmpCoord);
40 if (!bin.raw())
return -1;
41 return bin->fill({coords...}, weight, fraction);
50 void reset() noexcept { BaseT::reset(); }
58 size_t fillDim() const noexcept {
return FillDim{}; }
64 double numEntries(
const bool includeOverflows=
true) const noexcept {
66 for (
const auto& b : BaseT::bins(includeOverflows)) {
67 if (!b.get())
continue;
68 n += b->numEntries(includeOverflows);
76 for (
const auto& b : BaseT::bins(includeOverflows)) {
77 if (!b.get())
continue;
78 n += b->effNumEntries(includeOverflows);
84 double sumW(
const bool includeOverflows=
true) const noexcept {
86 for (
const auto& b : BaseT::bins(includeOverflows)) {
87 if (!b.get())
continue;
88 sumw += b->sumW(includeOverflows);
94 double sumW2(
const bool includeOverflows=
true) const noexcept {
96 for (
const auto& b : BaseT::bins(includeOverflows)) {
97 if (!b.get())
continue;
98 sumw2 += b->sumW2(includeOverflows);
104 double integral(
const bool includeOverflows=
true) const noexcept {
105 return sumW(includeOverflows);
110 return sqrt(
sumW2(includeOverflows));
118 void divByGroupWidth() const noexcept {
119 for (
auto& bin : BaseT::bins(true, true)) {
120 if (!bin.get())
continue;
121 const double bw = bin.dVol();
122 if (bw) bin->scaleW(1.0/bw);
127 void scaleW(
const double scalefactor)
noexcept {
128 for (
auto& bin : BaseT::bins(
true,
true)) {
129 if (!bin.get())
continue;
130 bin->scaleW(scalefactor);
135 void scale(
const size_t i,
const double scalefactor)
noexcept {
136 for (
auto& bin : BaseT::bins(
true,
true)) {
137 if (!bin.get())
continue;
138 bin->scale(i, scalefactor);
145 void normalize(
const double normto=1.0,
const bool includeOverflows=
true) {
146 for (
auto& bin : BaseT::bins(
true,
true)) {
147 if (!bin.get())
continue;
148 if (bin->integral(includeOverflows) != 0.) bin->normalize(normto, includeOverflows);
156 const double oldintegral =
integral(includeOverflows);
157 if (oldintegral == 0)
throw WeightError(
"Attempted to normalize a histogram group with null area");
158 scaleW(normto / oldintegral);
168 template <
typename GroupAxisT,
typename... AxisT>
169 using HistoGroupPtr = std::shared_ptr<HistoGroup<GroupAxisT, AxisT...>>;
170 using Histo1DGroupPtr = HistoGroupPtr<double,double>;
171 using Histo2DGroupPtr = HistoGroupPtr<double,double,double>;
Definition HistoGroup.hh:23
void normalize(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:145
void scaleW(const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor.
Definition HistoGroup.hh:127
void scale(const size_t i, const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor along dimension i.
Definition HistoGroup.hh:135
size_t dim() const noexcept
Total dimension of the object (number of fill axes + filled value)
Definition HistoGroup.hh:61
double integralError(const bool includeOverflows=true) const noexcept
Get the total volume error of the histogram group.
Definition HistoGroup.hh:109
double sumW(const bool includeOverflows=true) const noexcept
Calculates sum of weights in histo group.
Definition HistoGroup.hh:84
double integral(const bool includeOverflows=true) const noexcept
Get the total volume of the histogram group.
Definition HistoGroup.hh:104
size_t fillDim() const noexcept
Fill dimension of the object (number of conent axes + temprary axis)
Definition HistoGroup.hh:58
void normalizeGroup(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:155
double numEntries(const bool includeOverflows=true) const noexcept
Get the number of fills (fractional fills are possible).
Definition HistoGroup.hh:64
double sumW2(const bool includeOverflows=true) const noexcept
Calculates sum of squared weights in histo group.
Definition HistoGroup.hh:94
double effNumEntries(const bool includeOverflows=true) const noexcept
Get the effective number of fills.
Definition HistoGroup.hh:74
void reset() noexcept
Reset the histogram.
Definition HistoGroup.hh:50
Definition RivetYODA.hh:1330
Definition MC_CENT_PPB_Projections.hh:10
Errors relating to event/bin weights.
Definition Exceptions.hh:49