2#ifndef RIVET_HISTOGROUP_HH
3#define RIVET_HISTOGROUP_HH
5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/Tools/Logging.hh"
7#include "Rivet/Tools/RivetYODA.hh"
16 template <
size_t FillDim,
typename T,
typename AxisT>
17 typename YODA::FillableStorage<FillDim, T, AxisT>::FillAdapterT
18 groupAdapter = [](
auto& ,
auto&& ,
double ,
double ) { };
22 template <
typename GroupAxisT,
typename... AxisT>
23 class HistoGroup :
public YODA::FillableStorage<sizeof...(AxisT)+1, BinnedHistoPtr<AxisT...>, GroupAxisT>,
24 public YODA::Fillable {
29 using FillDim = std::integral_constant<size_t,
sizeof...(AxisT)+1>;
33 HistoGroup(
const std::vector<GroupAxisT>& edges)
34 : BaseT(YODA::Axis<GroupAxisT>(edges), groupAdapter<FillDim{},
BinContentT, GroupAxisT>) { }
36 HistoGroup(std::initializer_list<GroupAxisT>&& edges)
37 : BaseT(YODA::Axis<GroupAxisT>(std::move(edges)), groupAdapter<FillDim{},
BinContentT, GroupAxisT>) { }
39 int fill(GroupAxisT tmpCoord, AxisT... coords,
const double weight = 1.0,
const double fraction = 1.0) {
40 auto& bin = BaseT::binAt(tmpCoord);
41 if (!bin.raw())
return -1;
42 return bin->fill({coords...}, weight, fraction);
51 void reset() noexcept { BaseT::reset(); }
59 size_t fillDim() const noexcept {
return FillDim{}; }
65 double numEntries(
const bool includeOverflows=
true) const noexcept {
67 for (
const auto& b : BaseT::bins(includeOverflows)) {
68 if (!b.get())
continue;
69 n += b->numEntries(includeOverflows);
77 for (
const auto& b : BaseT::bins(includeOverflows)) {
78 if (!b.get())
continue;
79 n += b->effNumEntries(includeOverflows);
85 double sumW(
const bool includeOverflows=
true) const noexcept {
87 for (
const auto& b : BaseT::bins(includeOverflows)) {
88 if (!b.get())
continue;
89 sumw += b->sumW(includeOverflows);
95 double sumW2(
const bool includeOverflows=
true) const noexcept {
97 for (
const auto& b : BaseT::bins(includeOverflows)) {
98 if (!b.get())
continue;
99 sumw2 += b->sumW2(includeOverflows);
105 vector<double>
sumWGroup(
const bool includeOverflows=
true) const noexcept {
107 rtn.reserve(BaseT::numBins(
true));
108 for (
const auto& b : BaseT::bins(
true)) {
113 rtn.push_back( b->sumW(includeOverflows) );
119 double integral(
const bool includeOverflows=
true) const noexcept {
120 return sumW(includeOverflows);
125 return sqrt(
sumW2(includeOverflows));
133 void divByGroupWidth() const noexcept {
134 for (
auto& bin : BaseT::bins(true, true)) {
135 if (!bin.get())
continue;
136 const double bw = bin.dVol();
137 if (bw) bin->scaleW(1.0/bw);
142 void scaleW(
const double scalefactor)
noexcept {
143 for (
auto& bin : BaseT::bins(
true,
true)) {
144 if (!bin.get())
continue;
145 bin->scaleW(scalefactor);
150 void scale(
const size_t i,
const double scalefactor)
noexcept {
151 for (
auto& bin : BaseT::bins(
true,
true)) {
152 if (!bin.get())
continue;
153 bin->scale(i, scalefactor);
160 void normalize(
const double normto=1.0,
const bool includeOverflows=
true) {
161 for (
auto& bin : BaseT::bins(
true,
true)) {
162 if (!bin.get())
continue;
163 if (bin->integral(includeOverflows) != 0.) bin->normalize(normto, includeOverflows);
171 const double oldintegral =
integral(includeOverflows);
172 if (oldintegral == 0) {
173 MSG_DEBUG(
"Attempted to normalize a histogram group with null area; skipping.");
176 scaleW(normto / oldintegral);
185 string logname =
"Rivet.HistoGroup";
194 template <
typename GroupAxisT,
typename... AxisT>
195 using HistoGroupPtr = std::shared_ptr<HistoGroup<GroupAxisT, AxisT...>>;
196 using Histo1DGroupPtr = HistoGroupPtr<double,double>;
197 using Histo2DGroupPtr = HistoGroupPtr<double,double,double>;
Definition HistoGroup.hh:24
void normalize(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:160
void scaleW(const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor.
Definition HistoGroup.hh:142
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:150
vector< double > sumWGroup(const bool includeOverflows=true) const noexcept
Return the vector of sum of weights for each histo in the group.
Definition HistoGroup.hh:105
size_t dim() const noexcept
Total dimension of the object (number of fill axes + filled value)
Definition HistoGroup.hh:62
double integralError(const bool includeOverflows=true) const noexcept
Get the total volume error of the histogram group.
Definition HistoGroup.hh:124
Log & getLog() const
Get a Log object based on the name() property of the calling analysis object.
Definition HistoGroup.hh:184
double sumW(const bool includeOverflows=true) const noexcept
Calculates sum of weights in histo group.
Definition HistoGroup.hh:85
double integral(const bool includeOverflows=true) const noexcept
Get the total volume of the histogram group.
Definition HistoGroup.hh:119
size_t fillDim() const noexcept
Fill dimension of the object (number of conent axes + temprary axis)
Definition HistoGroup.hh:59
void normalizeGroup(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:170
double numEntries(const bool includeOverflows=true) const noexcept
Get the number of fills (fractional fills are possible).
Definition HistoGroup.hh:65
double sumW2(const bool includeOverflows=true) const noexcept
Calculates sum of squared weights in histo group.
Definition HistoGroup.hh:95
double effNumEntries(const bool includeOverflows=true) const noexcept
Get the effective number of fills.
Definition HistoGroup.hh:75
void reset() noexcept
Reset the histogram.
Definition HistoGroup.hh:51
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
static Log & getLog(const std::string &name)
Definition RivetYODA.hh:1330
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:182
Definition MC_CENT_PPB_Projections.hh:10