12#ifndef ROOT_Rebin2DHelpers
13#define ROOT_Rebin2DHelpers
21#include <initializer_list>
35 newAxis.
Set(nnew, userBins);
37 std::vector<Double_t> edges(nnew + 1);
38 for (
Int_t i = 0; i <= nnew; ++i)
40 newAxis.
Set(nnew, edges.data());
52 std::vector<Int_t> map(nOld + 2);
54 map[nOld + 1] = newAxis.
GetNbins() + 1;
55 for (
Int_t o = 1; o <= nOld; ++o)
74 "Bin edge %d of rebinned histogram does not match any bin edges of the old histogram. "
75 "Result can be inconsistent",
98 if (ngroup <= 0 || ngroup > nOldBins) {
99 hist.
Error(where,
"Illegal value of n%cgroup=%d", axisName, ngroup);
107 if (info.
nNewBins * ngroup != nOldBins) {
108 hist.
Warning(where,
"n%cgroup=%d is not an exact divider of n%cbins=%d.", axisName, ngroup, axisName,
129 Int_t otherStride,
TH1 &hist,
const char *where)
133 auto flowContent = [&](
Int_t flowIndex) {
135 for (
Int_t k = 0; k < nOther; ++k)
136 sum += bins[flowIndex * stride + k * otherStride];
139 if (userBins[0] < oldAxis.
GetXmin() && flowContent(0) != 0.)
140 hist.
Warning(where,
"underflow entries for %c axis will not be used when rebinning", axisName);
142 hist.
Warning(where,
"overflow entries for %c axis will not be used when rebinning", axisName);
152 std::vector<Double_t> xEdges(nx + 1);
153 std::vector<Double_t> yEdges(ny + 1);
154 for (
Int_t i = 0; i <= nx; ++i)
156 for (
Int_t i = 0; i <= ny; ++i)
158 hnew.
SetBins(nx, xEdges.data(), ny, yEdges.data());
168 const std::vector<Int_t> &mapY,
169 std::initializer_list<std::pair<const Double_t *, Double_t *>> arrays)
171 for (
Int_t oy = 0; oy < nOldY + 2; ++oy) {
172 for (
Int_t ox = 0; ox < nOldX + 2; ++ox) {
173 const Int_t oldBin = ox + (nOldX + 2) * oy;
174 const Int_t newBin = mapX[ox] + (nNewX + 2) * mapY[oy];
175 for (
auto const &arr : arrays)
176 arr.second[newBin] += arr.first[oldBin];
int Int_t
Signed integer 4 bytes (int)
Class to manage histogram axis.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
const TArrayD * GetXbins() const
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
TH1 is the base class of all histogram classes in ROOT.
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Redefine x axis parameters.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void DefineRebinnedAxis(const TAxis &oldAxis, Int_t ngroup, Int_t nnew, const Double_t *userBins, Double_t xmin, Double_t xmax, TAxis &newAxis)
Define the axis of the rebinned histogram: either from the user-provided bin edges,...
void WarnAboutUnusedFlowContent(const TAxis &oldAxis, const RebinnedAxisInfo &info, const Double_t *userBins, char axisName, const Double_t *bins, Int_t stride, Int_t nOther, Int_t otherStride, TH1 &hist, const char *where)
Warn when the range of the new axis extends beyond the old one while the corresponding flow bins hold...
void WarnAboutMisalignedEdges(const TAxis &oldAxis, const TAxis &newAxis, TH1 &hist, const char *where)
Warn when a bin edge of the new axis that lies inside the old axis range does not line up with a bin ...
std::vector< Int_t > MakeRebinMap(const TAxis &oldAxis, const TAxis &newAxis)
Map each cell of the old axis (including underflow 0 and overflow n+1) to the cell of the new axis th...
void SetRebinnedBins2D(TH1 &hnew, const TAxis &newXaxis, const TAxis &newYaxis)
Apply the axes of the rebinned histogram, using explicit bin edges if any of the two axes has non-uni...
void MergeRebinnedCells(Int_t nOldX, Int_t nOldY, Int_t nNewX, const std::vector< Int_t > &mapX, const std::vector< Int_t > &mapY, std::initializer_list< std::pair< const Double_t *, Double_t * > > arrays)
Accumulate every old cell (including under- and overflow) into the new cell given by the per-axis bin...
bool SetupRebinnedAxis(const TAxis &oldAxis, Int_t ngroup, const Double_t *userBins, char axisName, TH1 &hist, const char *where, RebinnedAxisInfo &info)
Validate the rebinning parameters for one axis and fill the definition of the rebinned axis and the m...
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Comparing floating points.
The definition of one axis of the rebinned histogram.
Int_t nNewBins
number of bins of the rebinned axis
TAxis newAxis
the rebinned axis
bool truncated
the group count does not divide the old bin count: top bins move to the overflow
std::vector< Int_t > binMap
map from old cell (0..n+1) to new cell
static uint64_t sum(uint64_t i)