15 #ifndef ROOT7_THistImpl
16 #define ROOT7_THistImpl
28 template<
int NDIM>
using AxisIter_t = std::array<TAxisBase::const_iterator, NDIM>;
41 return static_cast<int>(
a) & static_cast<int>(b);
56 template <
int DIMENSIONS>
60 using Coord_t = std::array<double, DIMENSIONS>;
65 constexpr
int GetNDim()
const {
return DIMENSIONS; }
101 GetRange(
const std::array<Hist::EOverflow, DIMENSIONS>& withOverUnder)
const = 0;
113 template<
int DIMENSIONS,
class PRECISION>
161 return std::get<0>(axes).GetNBins();
166 template <
int I,
class AXES>
169 return std::get<I>(axes).GetNBins() *
TGetBinCount<
I - 1, AXES>()(axes);
174 template <
int IDX,
class HISTIMPL,
class AXES,
bool GROW>
178 template <
class HISTIMPL,
class AXES,
bool GROW>
187 template <
int I,
class HISTIMPL,
class AXES,
bool GROW>
191 int bin = std::get<I>(axes).FindBin(x[
I]);
192 if (GROW && std::get<I>(axes).CanGrow()
193 && (bin < 0 || bin > std::get<I>(axes).GetNBinsNoOver())) {
194 hist->GrowAxis(I, x[I]);
200 return bin +
TGetBinIndex<I - 1, HISTIMPL, AXES, GROW>()(hist, axes, x, status)
201 * std::get<I>(axes).GetNBins();
218 template<
int I,
class AXES>
224 range[0][
I] = std::get<I>(axes).begin_with_underflow();
226 range[0][
I] = std::get<I>(axes).begin();
228 range[1][
I] = std::get<I>(axes).end_with_overflow();
230 range[1][
I] = std::get<I>(axes).end();
252 template<
int I,
class COORD,
class AXES>
255 int axisbin = binidx % std::get<I>(axes).GetNBins();
259 coord[coordidx] = std::get<I>(axes).GetBinFrom(axisbin);
262 coord[coordidx] = std::get<I>(axes).GetBinCenter(axisbin);
265 coord[coordidx] = std::get<I>(axes).GetBinTo(axisbin);
269 binidx / std::get<I>(axes).GetNBins());
275 template <
class... AXISCONFIG>
276 static std::array<
TAxisView,
sizeof...(AXISCONFIG)>
278 std::array<TAxisView,
sizeof...(AXISCONFIG)> axisViews = {
288 template <
int DIMENSIONS,
class PRECISION>
class THist;
292 template <
int DIMENSIONS,
class PRECISION,
class STATISTICS,
class... AXISCONFIG>
295 static_assert(
sizeof...(AXISCONFIG) == DIMENSIONS,
296 "Number of axes must equal histogram dimension");
297 friend class THist<DIMENSIONS, PRECISION>;
324 THistImpl(STATISTICS statConfig, AXISCONFIG... axisArgs);
335 return std::apply(Internal::GetAxisView<AXISCONFIG...>,
fAxes)[iAxis];
344 decltype(
fAxes),
false>()(
nullptr,
fAxes,
x, status);
395 if (xN.size() != weightN.size()) {
396 R__ERROR_HERE(
"HIST") <<
"Not the same number of points and weights!";
401 for (
int i = 0; i < xN.size(); ++i) {
402 Fill(xN[i], weightN[i]);
403 STATISTICS::Fill(xN[i], weightN[i]);
411 for (
int i = 0; i < xN.size(); ++i) {
413 STATISTICS::Fill(xN[i]);
419 return STATISTICS::GetBinUncertainties(binidx, *
this);
427 STATISTICS::Fill(x, w);
441 return fContent[binidx];
448 AxisIterRange_t<DIMENSIONS>
449 GetRange(
const std::array<Hist::EOverflow, DIMENSIONS>& withOverUnder)
const final {
450 std::array<std::array<TAxisBase::const_iterator, DIMENSIONS>, 2> ret;
466 template <
int DIMENSIONS,
class PRECISION,
class STATISTICS,
class... AXISCONFIG>
468 STATISTICS(statConfig), fAxes{axisArgs...}, fContent(GetNBins())
474 template <
int DIMENSIONS,
class PRECISION>
475 class THistImplRuntime:
public THistImplBase<DIMENSIONS, PRECISION> {
477 THistImplRuntime(std::array<TAxisConfig, DIMENSIONS>&& axisCfg);
PRECISION Weight_t
Type of the bin content (and thus weights).
Fill coord with low bin edge or center or high bin edge of all axes.
int GetBinIndex(const Coord_t &x) const final
Gets the bin index for coordinate x; returns -1 if there is no such bin, e.g.
bool operator&(EOverflow a, EOverflow b)
std::array< TAxisBase::const_iterator, NDIM > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
Exclude under- and overflows.
int operator()(const AXES &axes) const
Coordinate could fit after growing the axis.
Namespace for new ROOT classes and functions.
static std::array< TAxisView, sizeof...(AXISCONFIG)> GetAxisView(const AXISCONFIG &...axes) noexcept
virtual void FillN(const std::array_view< Coord_t > xN, const std::array_view< Weight_t > weightN)=0
Interface function to fill a vector or array of coordinates with corresponding weights.
Common view on a TAxis, no matter what its kind.
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &range, const AXES &axes, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &over) const
std::vector< PRECISION > fContent
The histogram's bin content.
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &) const
virtual int GetBinIndexAndGrow(const Coord_t &x)=0
Given the coordinate x, determine the index of the bin, possibly growing axes for which x is out of r...
THistImpl(STATISTICS statConfig, AXISCONFIG...axisArgs)
int GetBinIndexAndGrow(const Coord_t &x) final
Gets the bin index for coordinate x, growing the axes as needed and possible.
virtual Coord_t GetBinCenter(int binidx) const =0
Get the center in all dimensions of the bin with index binidx.
typename THistImplPrecisionAgnosticBase< DIMENSIONS >::Coord_t Coord_t
Type of a coordinate: an array of DIMENSIONS doubles.
void AddBinContent(int bin, Weight_t w)
Add w to the bin at index bin.
virtual double GetBinContentAsDouble(int binidx) const =0
The bin content, cast to double.
int operator()(HISTIMPL *hist, const AXES &axes, const typename HISTIMPL::Coord_t &x, TAxisBase::EFindStatus &status) const
PRECISION GetBinContent(const Coord_t &x) const
Get the content of the bin at position x.
Coord_t GetBinCenter(int binidx) const final
Get the center coordinate of the bin.
std::vector< double > GetBinUncertainties(int binidx) const final
Return the uncertainties for the given bin.
void operator()(COORD &coord, const AXES &axes, EBinCoord kind, int binidx) const
constexpr int GetNDim() const
Number of dimensions of this histogram.
virtual Coord_t GetBinFrom(int binidx) const =0
Get the lower edge in all dimensions of the bin with index binidx.
double GetBinContentAsDouble(int binidx) const final
Get the bin content (sum of weights) for bin index binidx, cast to double.
void(THistImplBase::*)(const Coord_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
void FillN(const std::array_view< Coord_t > xN, const std::array_view< Weight_t > weightN) final
Fill an array of weightN to the bins specified by coordinates xN.
virtual int GetBinIndex(const Coord_t &x) const =0
Given the coordinate x, determine the index of the bin.
typename ImplBase_t::Coord_t Coord_t
virtual int GetNBins() const =0
Number of bins of this histogram, including all overflow and underflow bins.
Coord_t GetBinTo(int binidx) const final
Get the coordinate of the high limit of the bin.
virtual Coord_t GetBinTo(int binidx) const =0
Get the upper edge in all dimensions of the bin with index binidx.
virtual ~THistImplPrecisionAgnosticBase()
std::array< AxisIter_t< NDIM >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
typename Hist::AxisIterRange_t< NDIM > AxisIterRange_t
int operator()(HISTIMPL *, const AXES &, const typename HISTIMPL::Coord_t &, TAxisBase::EFindStatus &status) const
void Fill(const Coord_t &x, Weight_t w=1.)
Add a single weight w to the bin at coordinate x.
PRECISION GetBinContent(int binidx) const final
Get the content of the bin at bin index binidx.
void FillN(const std::array_view< Coord_t > xN) final
Fill an array of weightN to the bins specified by coordinates xN.
virtual FillFunc_t GetFillFunc() const =0
Retrieve the pointer to the overridden Fill(x, w) function.
virtual std::vector< double > GetBinUncertainties(int binidx) const =0
The bin's uncertainty.
virtual TAxisView GetAxis(int iAxis) const =0
Get a TAxisView on axis with index iAxis.
Fill range with begin() and end() of all axes, including under/overflow as specified by over...
The returned bin index is valid.
AxisIterRange_t< DIMENSIONS > GetRange(const std::array< Hist::EOverflow, DIMENSIONS > &withOverUnder) const final
Get the begin() and end() for each axis.
int GetNBins() const final
Get the number of bins in this histograms, including possible under- and overflow bins...
std::array< double, DIMENSIONS > Coord_t
Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
typedef void((*Func_t)())
Base class for THistImplBase that abstracts out the histogram's PRECISION.
virtual Hist::AxisIterRange_t< DIMENSIONS > GetRange(const std::array< Hist::EOverflow, DIMENSIONS > &withOverUnder) const =0
Get a Hist::AxisIterRange_t for the whole histogram, possibly restricting the range to non-overflow b...
int operator()(const AXES &axes) const
#define R__ERROR_HERE(GROUP)
Coord_t GetBinFrom(int binidx) const final
Get the coordinate of the low limit of the bin.
void operator()(COORD &, const AXES &, EBinCoord, int) const
FillFunc_t GetFillFunc() const final
Retrieve the fill function for this histogram implementation, to prevent the virtual function call fo...
Include both under- and overflows.
EOverflow
Kinds of under- and overflow handling.
EFindStatus
Status of FindBin(x)
Interface class for THistImpl.
void GrowAxis(int, double)
Grow the axis number iAxis to fit the coordinate x.
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
virtual PRECISION GetBinContent(int binidx) const =0
Get the bin content (sum of weights) for bin index binidx.
TAxisView GetAxis(int iAxis) const final
Normalized axes access, converting the actual axis to TAxisConfig.
std::tuple< AXISCONFIG...> fAxes
The histogram's axes.
const std::tuple< AXISCONFIG...> & GetAxes() const
Get the axes of this histogram.