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 groupAdapter =
18 [](
auto& ,
auto&& ,
double ,
double ) {
23 template <
typename GroupAxisT,
typename... AxisT>
24 class HistoGroup :
public YODA::FillableStorage<sizeof...(AxisT) + 1, BinnedHistoPtr<AxisT...>, GroupAxisT>,
25 public YODA::Fillable {
28 using BaseT = YODA::FillableStorage<
sizeof...(AxisT) + 1, BinnedHistoPtr<AxisT...>, GroupAxisT>;
29 using BinContentT = BinnedHistoPtr<AxisT...>;
30 using FillDim = std::integral_constant<size_t,
sizeof...(AxisT) + 1>;
33 : BaseT(groupAdapter<FillDim{}, BinContentT, GroupAxisT>) { }
35 HistoGroup(
const std::vector<GroupAxisT>& edges)
36 : BaseT(YODA::Axis<GroupAxisT>(edges), groupAdapter<FillDim{}, BinContentT, GroupAxisT>) { }
38 HistoGroup(std::initializer_list<GroupAxisT>&& edges)
39 : BaseT(YODA::Axis<GroupAxisT>(std::move(edges)), groupAdapter<FillDim{}, BinContentT, GroupAxisT>) {
42 int fill(GroupAxisT tmpCoord, AxisT... coords,
const double weight = 1.0,
const double fraction = 1.0) {
43 auto& bin = BaseT::binAt(tmpCoord);
44 if (!bin.raw())
return -1;
45 return bin->fill({coords...}, weight, fraction);
69 size_t dim() const noexcept {
74 double numEntries(
const bool includeOverflows =
true) const noexcept {
76 for (
const auto& b : BaseT::bins(includeOverflows)) {
77 if (!b.get())
continue;
78 n += b->numEntries(includeOverflows);
84 double effNumEntries(
const bool includeOverflows =
true) const noexcept {
86 for (
const auto& b : BaseT::bins(includeOverflows)) {
87 if (!b.get())
continue;
88 n += b->effNumEntries(includeOverflows);
94 double sumW(
const bool includeOverflows =
true) const noexcept {
96 for (
const auto& b : BaseT::bins(includeOverflows)) {
97 if (!b.get())
continue;
98 sumw += b->sumW(includeOverflows);
104 double sumW2(
const bool includeOverflows =
true) const noexcept {
106 for (
const auto& b : BaseT::bins(includeOverflows)) {
107 if (!b.get())
continue;
108 sumw2 += b->sumW2(includeOverflows);
114 vector<double>
sumWGroup(
const bool includeOverflows =
true) const noexcept {
116 rtn.reserve(BaseT::numBins(
true));
117 for (
const auto& b : BaseT::bins(
true)) {
122 rtn.push_back(b->sumW(includeOverflows));
128 double integral(
const bool includeOverflows =
true) const noexcept {
129 return sumW(includeOverflows);
134 return sqrt(
sumW2(includeOverflows));
142 void divByGroupWidth() const noexcept {
143 for (
auto& bin : BaseT::bins(
true,
true)) {
144 if (!bin.get())
continue;
145 const double bw = bin.dVol();
146 if (bw) bin->scaleW(1.0 / bw);
151 void scaleW(
const double scalefactor)
noexcept {
152 for (
auto& bin : BaseT::bins(
true,
true)) {
153 if (!bin.get())
continue;
154 bin->scaleW(scalefactor);
159 void scale(
const size_t i,
const double scalefactor)
noexcept {
160 for (
auto& bin : BaseT::bins(
true,
true)) {
161 if (!bin.get())
continue;
162 bin->scale(i, scalefactor);
169 void normalize(
const double normto = 1.0,
const bool includeOverflows =
true) {
170 for (
auto& bin : BaseT::bins(
true,
true)) {
171 if (!bin.get())
continue;
172 if (bin->integral(includeOverflows) != 0.) bin->normalize(normto, includeOverflows);
179 void normalizeGroup(
const double normto = 1.0,
const bool includeOverflows =
true) {
180 const double oldintegral =
integral(includeOverflows);
181 if (oldintegral == 0) {
182 MSG_DEBUG(
"Attempted to normalize a histogram group with null area; skipping.");
185 scaleW(normto / oldintegral);
194 string logname =
"Rivet.HistoGroup";
202 template <
typename GroupAxisT,
typename... AxisT>
203 using HistoGroupPtr = std::shared_ptr<HistoGroup<GroupAxisT, AxisT...>>;
204 using Histo1DGroupPtr = HistoGroupPtr<double, double>;
205 using Histo2DGroupPtr = HistoGroupPtr<double, double, double>;
void normalize(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:169
void scaleW(const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor.
Definition HistoGroup.hh:151
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:159
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:114
size_t dim() const noexcept
Total dimension of the object (number of fill axes + filled value).
Definition HistoGroup.hh:69
double integralError(const bool includeOverflows=true) const noexcept
Get the total volume error of the histogram group.
Definition HistoGroup.hh:133
Log & getLog() const
Get a Log object based on the name() property of the calling analysis object.
Definition HistoGroup.hh:193
double sumW(const bool includeOverflows=true) const noexcept
Calculates sum of weights in histo group.
Definition HistoGroup.hh:94
double integral(const bool includeOverflows=true) const noexcept
Get the total volume of the histogram group.
Definition HistoGroup.hh:128
size_t fillDim() const noexcept
Fill dimension of the object (number of conent axes + temprary axis).
Definition HistoGroup.hh:64
void normalizeGroup(const double normto=1.0, const bool includeOverflows=true)
Normalize the (visible) histo "volume" to the normto value.
Definition HistoGroup.hh:179
double numEntries(const bool includeOverflows=true) const noexcept
Get the number of fills (fractional fills are possible).
Definition HistoGroup.hh:74
double sumW2(const bool includeOverflows=true) const noexcept
Calculates sum of squared weights in histo group.
Definition HistoGroup.hh:104
double effNumEntries(const bool includeOverflows=true) const noexcept
Get the effective number of fills.
Definition HistoGroup.hh:84
void reset() noexcept
Reset the histogram.
Definition HistoGroup.hh:54
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
static Log & getLog(const std::string &name)
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
Definition LHCbCommon.hh:9