16#ifndef ROOT7_RHistImpl
17#define ROOT7_RHistImpl
31namespace Experimental {
33template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class... STAT>
39using AxisIter_t = std::array<RAxisBase::const_iterator, NDIM>;
54 return static_cast<int>(
a) &
static_cast<int>(
b);
69template <
int DIMENSIONS>
84 static constexpr int GetNDim() {
return DIMENSIONS; }
166 virtual std::unique_ptr<RHistImplBase>
Clone()
const = 0;
171 virtual void FillN(
const std::span<CoordArray_t> xN,
const std::span<Weight_t> weightN) = 0;
174 virtual void FillN(
const std::span<CoordArray_t> xN) = 0;
233template <
int IDX,
class AXISTUPLE>
238 int operator()(
const AXES &axes)
const {
return std::get<0>(axes).GetNBins(); }
241template <
int I,
class AXES>
246template <
class... AXISCONFIG>
249 using axesTuple = std::tuple<AXISCONFIG...>;
250 return RGetBinCount<
sizeof...(AXISCONFIG) - 1, axesTuple>()(axesTuple{axisArgs...});
253template <
int IDX,
class HISTIMPL,
class AXES,
bool GROW>
257template <
class HISTIMPL,
class AXES,
bool GROW>
267template <
int I,
class HISTIMPL,
class AXES,
bool GROW>
272 constexpr const int thisAxis = HISTIMPL::GetNDim() -
I - 1;
273 int bin = std::get<thisAxis>(axes).FindBin(
x[thisAxis]);
274 if (GROW && std::get<thisAxis>(axes).CanGrow() && (bin < 0 || bin > std::get<thisAxis>(axes).GetNBinsNoOver())) {
275 hist->GrowAxis(
I,
x[thisAxis]);
282 RGetBinIndex<
I - 1, HISTIMPL, AXES, GROW>()(hist, axes,
x, status) * std::get<thisAxis>(axes).GetNBins();
286template <
int I,
class AXES>
287struct RFillIterRange;
293 const std::array<
Hist::EOverflow, std::tuple_size<AXES>::value> & )
const
300template <
int I,
class AXES>
303 const std::array<
Hist::EOverflow, std::tuple_size<AXES>::value> &over)
const
306 range[0][
I] = std::get<I>(axes).begin_with_underflow();
308 range[0][
I] = std::get<I>(axes).begin();
310 range[1][
I] = std::get<I>(axes).end_with_overflow();
312 range[1][
I] = std::get<I>(axes).end();
323template <
int I,
class COORD,
class AXES>
327template <
class COORD,
class AXES>
334template <
int I,
class COORD,
class AXES>
338 int axisbin = binidx % std::get<I>(axes).GetNBins();
339 size_t coordidx = std::tuple_size<AXES>::value -
I - 1;
343 case EBinCoord::kBinTo: coord[coordidx] = std::get<I>(axes).GetBinTo(axisbin);
break;
345 RFillBinCoord<
I - 1, COORD, AXES>()(coord, axes, kind, binidx / std::get<I>(axes).GetNBins());
349template <
class... AXISCONFIG>
361template <
class DATA,
class... AXISCONFIG>
363 static_assert(
sizeof...(AXISCONFIG) == DATA::GetNDim(),
"Number of axes must equal histogram dimension");
365 friend typename DATA::Hist_t;
372 template <
int NDIM = DATA::GetNDim()>
383 std::unique_ptr<ImplBase_t>
Clone()
const override {
384 return std::unique_ptr<ImplBase_t>(
new RHistImpl(*
this));
403 for (
auto binref: *
this)
404 op(binref.GetCenter(), binref.GetContent());
411 for (
auto binref: *
this)
412 op(binref.GetCenter(), binref.GetContent(), binref.GetUncertainty());
477 void FillN(
const std::span<CoordArray_t> xN,
const std::span<Weight_t> weightN)
final
480 if (xN.size() != weightN.size()) {
481 R__ERROR_HERE(
"HIST") <<
"Not the same number of points and weights!";
486 for (
size_t i = 0; i < xN.size(); ++i) {
487 Fill(xN[i], weightN[i]);
494 void FillN(
const std::span<CoordArray_t> xN)
final
505 this->
GetStat().Fill(x, bin, w);
564template <
class DATA,
class... AXISCONFIG>
568template <
class DATA,
class... AXISCONFIG>
573template <
class DATA,
class... AXISCONFIG>
584 RHistImplRuntime(std::array<
RAxisConfig, DATA::GetNDim()>&& axisCfg);
#define R__ERROR_HERE(GROUP)
typedef void((*Func_t)())
Iterates over the bins of a RHist or RHistImpl.
Represents a bin reference.
Interface class for RHistImpl.
Weight_t & GetBinContent(int binidx)
Get the bin content (sum of weights) for bin index binidx (non-const).
RHistImplBase(const RHistImplBase &)=default
virtual void ApplyXC(std::function< void(const CoordArray_t &, Weight_t)>) const =0
Apply a function (lambda) to all bins of the histogram.
virtual void FillN(const std::span< CoordArray_t > xN)=0
Interface function to fill a vector or array of coordinates.
void(RHistImplBase::*)(const CoordArray_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
virtual double GetBinUncertainty(const CoordArray_t &x) const =0
Get the bin uncertainty for the bin at coordinate x.
void AddBinContent(int binidx, Weight_t w)
Add w to the bin at index bin.
RHistImplBase(RHistImplBase &&)=default
RHistImplBase(size_t numBins)
Hist::CoordArray_t< DATA::GetNDim()> CoordArray_t
Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
virtual std::unique_ptr< RHistImplBase > Clone() const =0
DATA Stat_t
Type of the statistics (bin content, uncertainties etc).
Stat_t & GetStat() noexcept
Non-const access to statistics.
RHistImplBase(std::string_view title, size_t numBins)
Weight_t GetBinContent(int binidx) const
Get the bin content (sum of weights) for bin index binidx.
const Stat_t & GetStat() const noexcept
Const access to statistics.
Stat_t fStatistics
The histogram's bin content, uncertainties etc.
virtual void FillN(const std::span< CoordArray_t > xN, const std::span< Weight_t > weightN)=0
Interface function to fill a vector or array of coordinates with corresponding weights.
virtual Weight_t GetBinContent(const CoordArray_t &x) const =0
Get the bin content (sum of weights) for the bin at coordinate x.
virtual void Apply(std::function< void(RHistBinRef< const RHistImplBase >)>) const =0
Apply a function (lambda) to all bins of the histogram.
double GetBinContentAsDouble(int binidx) const final
Get the bin content (sum of weights) for bin index binidx, cast to double.
int GetNBins() const noexcept final
Get the number of bins in this histogram, including possible under- and overflow bins.
virtual void ApplyXCE(std::function< void(const CoordArray_t &, Weight_t, double)>) const =0
Apply a function (lambda) to all bins of the histogram.
typename DATA::Weight_t Weight_t
Type of the bin content (and thus weights).
virtual FillFunc_t GetFillFunc() const =0
Retrieve the pointer to the overridden Fill(x, w) function.
Base class for RHistImplBase that abstracts out the histogram's PRECISION.
virtual int GetBinIndexAndGrow(const CoordArray_t &x)=0
Given the coordinate x, determine the index of the bin, possibly growing axes for which x is out of r...
virtual ~RHistImplPrecisionAgnosticBase()
virtual int GetBinIndex(const CoordArray_t &x) const =0
Given the coordinate x, determine the index of the bin.
RHistImplPrecisionAgnosticBase(std::string_view title)
virtual RAxisView GetAxis(int iAxis) const =0
Get a RAxisView on axis with index iAxis.
RHistImplPrecisionAgnosticBase(RHistImplPrecisionAgnosticBase &&)=default
virtual int GetNBins() const noexcept=0
Number of bins of this histogram, including all overflow and underflow bins.
virtual bool HasBinUncertainty() const =0
Whether this histogram's statistics provide storage for uncertainties, or whether uncertainties are d...
virtual AxisIterRange_t GetRange(const std::array< Hist::EOverflow, DIMENSIONS > &withOverUnder) const =0
Get a AxisIterRange_t for the whole histogram, possibly restricting the range to non-overflow bins.
virtual CoordArray_t GetBinTo(int binidx) const =0
Get the upper edge in all dimensions of the bin with index binidx.
std::string fTitle
Histogram title.
RHistImplPrecisionAgnosticBase()=default
RHistImplPrecisionAgnosticBase(const RHistImplPrecisionAgnosticBase &)=default
const std::string & GetTitle() const
Get the histogram title.
Hist::AxisIterRange_t< DIMENSIONS > AxisIterRange_t
Range type.
static constexpr int GetNDim()
Number of dimensions of the coordinates.
virtual double GetBinUncertainty(int binidx) const =0
The bin's uncertainty.
virtual double GetBinContentAsDouble(int binidx) const =0
The bin content, cast to double.
virtual CoordArray_t GetBinCenter(int binidx) const =0
Get the center in all dimensions of the bin with index binidx.
virtual CoordArray_t GetBinFrom(int binidx) const =0
Get the lower edge in all dimensions of the bin with index binidx.
void Fill(const CoordArray_t &x, Weight_t w=1.)
Add a single weight w to the bin at coordinate x.
int GetBinIndexAndGrow(const CoordArray_t &x) final
Gets the bin index for coordinate x, growing the axes as needed and possible.
const_iterator end() const noexcept
void ApplyXC(std::function< void(const CoordArray_t &, Weight_t)> op) const final
Apply a function (lambda) to all bins of the histogram.
double GetBinUncertainty(const CoordArray_t &x) const final
Get the bin uncertainty for the bin at coordinate x.
const_iterator begin() const noexcept
CoordArray_t GetBinCenter(int binidx) const final
Get the center coordinate of the bin.
void FillN(const std::span< CoordArray_t > xN, const std::span< Weight_t > weightN) final
Fill an array of weightN to the bins specified by coordinates xN.
FillFunc_t GetFillFunc() const final
Retrieve the fill function for this histogram implementation, to prevent the virtual function call fo...
std::tuple< AXISCONFIG... > fAxes
The histogram's axes.
void Apply(std::function< void(RHistBinRef< const ImplBase_t >)> op) const final
Apply a function (lambda) to all bins of the histogram.
void GrowAxis(int, double)
Grow the axis number iAxis to fit the coordinate x.
Weight_t GetBinContent(const CoordArray_t &x) const final
Get the content of the bin at position x.
int GetBinIndex(const CoordArray_t &x) const final
Gets the bin index for coordinate x; returns -1 if there is no such bin, e.g.
void FillN(const std::span< CoordArray_t > xN) final
Fill an array of weightN to the bins specified by coordinates xN.
AxisIterRange_t< DATA::GetNDim()> GetRange(const std::array< Hist::EOverflow, DATA::GetNDim()> &withOverUnder) const final
Get the begin() and end() for each axis.
double GetBinUncertainty(int binidx) const final
Return the uncertainties for the given bin.
bool HasBinUncertainty() const final
Whether this histogram's statistics provide storage for uncertainties, or whether uncertainties are d...
std::unique_ptr< ImplBase_t > Clone() const override
RHistBinIter< ImplBase_t > iterator
virtual void ApplyXCE(std::function< void(const CoordArray_t &, Weight_t, double)> op) const final
Apply a function (lambda) to all bins of the histogram.
typename Hist::AxisIterRange_t< NDIM > AxisIterRange_t
const std::tuple< AXISCONFIG... > & GetAxes() const
Get the axes of this histogram.
RAxisView GetAxis(int iAxis) const final
Normalized axes access, converting the actual axis to RAxisConfig.
CoordArray_t GetBinTo(int binidx) const final
Get the coordinate of the high limit of the bin.
CoordArray_t GetBinFrom(int binidx) const final
Get the coordinate of the low limit of the bin.
iterator begin() noexcept
RHistBinIter< const ImplBase_t > const_iterator
typename ImplBase_t::CoordArray_t CoordArray_t
Random const_iterator through bins.
EFindStatus
Status of FindBin(x)
@ kValid
The returned bin index is valid.
@ kCanGrow
Coordinate could fit after growing the axis.
Objects used to configure the different axis types.
Common view on a RAxis, no matter what its kind.
basic_string_view< char > string_view
EOverflow
Kinds of under- and overflow handling.
@ kUnderflow
Include underflows.
@ kNoOverflow
Exclude under- and overflows.
@ kOverflow
Include overflows.
@ kUnderOver
Include both under- and overflows.
std::array< AxisIter_t< NDIM >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
std::array< RAxisBase::const_iterator, NDIM > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
bool operator&(EOverflow a, EOverflow b)
RCoordArray< DIMENSIONS > CoordArray_t
int GetNBinsFromAxes(AXISCONFIG... axisArgs)
@ kBinTo
Get the bin high edge.
@ kBinFrom
Get the lower bin edge.
@ kBinCenter
Get the bin center.
static std::array< RAxisView, sizeof...(AXISCONFIG)> GetAxisView(const AXISCONFIG &... axes) noexcept
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Namespace for new ROOT classes and functions.
void operator()(COORD &, const AXES &, EBinCoord, int) const
Fill coord with low bin edge or center or high bin edge of all axes.
void operator()(COORD &coord, const AXES &axes, EBinCoord kind, int binidx) const
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &) const
Fill range with begin() and end() of all axes, including under/overflow as specified by over.
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
int operator()(const AXES &axes) const
int operator()(const AXES &axes) const
int operator()(HISTIMPL *, const AXES &, const typename HISTIMPL::CoordArray_t &, RAxisBase::EFindStatus &status) const
int operator()(HISTIMPL *hist, const AXES &axes, const typename HISTIMPL::CoordArray_t &x, RAxisBase::EFindStatus &status) const