16#ifndef ROOT7_RHistImpl
17#define ROOT7_RHistImpl
33namespace Experimental {
35template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
41using AxisIter_t = std::array<RAxisBase::const_iterator, NDIMS>;
56 return static_cast<int>(
a) &
static_cast<int>(
b);
71template <
int DIMENSIONS>
179 virtual std::unique_ptr<RHistImplBase>
Clone()
const = 0;
184 virtual void FillN(
const std::span<const CoordArray_t>
xN,
const std::span<const Weight_t>
weightN) = 0;
187 virtual void FillN(
const std::span<const CoordArray_t>
xN) = 0;
271template <
int IDX,
class AXISTUPLE>
272struct RGetNBinsNoOverCount;
276 int operator()(
const AXES &axes)
const {
return std::get<0>(axes).GetNBinsNoOver(); }
279template <
int I,
class AXES>
295template <
int IDX,
class AXISTUPLE>
296struct RGetNBinsCount;
303template <
int I,
class AXES>
327template <
int I,
class AXES>
328struct RFillIterRange;
336template <
int I,
class AXES>
349template <
int I,
int NDIMS,
typename BINS,
class AXES>
350struct RGetNRegularBinsBefore;
352template <
int NDIMS,
typename BINS,
class AXES>
358template <
int I,
int NDIMS,
typename BINS,
class AXES>
384template <
int I,
int NDIMS,
typename BINS,
class AXES>
385struct RComputeGlobalBin;
387template <
int NDIMS,
typename BINS,
class AXES>
395template <
int I,
int NDIMS,
typename BINS,
class AXES>
421template <
int I,
int NDIMS,
class AXES>
422struct RComputeLocalBinsInitialisation;
424template <
int NDIMS,
class AXES>
426 void operator()(std::array<int, NDIMS-1> , std::array<int, NDIMS-1> ,
const AXES & )
const
430template <
int I,
int NDIMS,
class AXES>
450template <
int I,
int NDIMS,
class AXES>
451struct RComputeLocalBins;
453template <
int NDIMS,
class AXES>
456 int &, std::array<int, NDIMS-1> ,
457 std::array<int, NDIMS-1> ,
int ,
462template <
int I,
int NDIMS,
class AXES>
472 static_cast<int>(!std::get<I>(axes).CanGrow());
496 * std::get<I>(axes).GetNBinsNoOver()
521 std::get<I>(axes).GetNBinsNoOver()
549template <
int I,
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
550struct RComputeLocalBinsRaw;
552template <
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
558template <
int I,
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
574template <
int I,
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
575struct RComputeGlobalBinRaw;
577template <
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
585template <
int I,
int NDIMS,
typename BINS,
class AXES,
class BINTYPE>
603template <
int I,
int NDIMS,
typename BINS,
class AXES>
604struct RVirtualBinsToLocalBins;
606template <
int NDIMS,
typename BINS,
class AXES>
612template <
int I,
int NDIMS,
typename BINS,
class AXES>
619 }
else if ((!std::get<thisAxis>(axes).CanGrow()) && (
virtualBins[
thisAxis] == (std::get<thisAxis>(axes).GetNBins() - 1))) {
637template <
int I,
int NDIMS,
typename BINS,
class AXES>
638struct RLocalBinsToVirtualBins;
640template <
int NDIMS,
typename BINS,
class AXES>
646template <
int I,
int NDIMS,
typename BINS,
class AXES>
664template <
int I,
int NDIMS,
typename BINS,
typename COORD,
class AXES>
665struct RFindLocalBins;
667template <
int NDIMS,
typename BINS,
typename COORD,
class AXES>
673template <
int I,
int NDIMS,
typename BINS,
typename COORD,
class AXES>
685template <
int I,
int NDIMS,
typename BINS,
typename COORD,
class AXES>
686struct RLocalBinsToCoords;
688template <
int NDIMS,
typename BINS,
typename COORD,
class AXES>
694template <
int I,
int NDIMS,
typename BINS,
typename COORD,
class AXES>
723 static_assert(
sizeof...(AXISCONFIG) == DATA::GetNDim(),
"Number of axes must equal histogram dimension");
725 friend typename DATA::Hist_t;
733 template <
int NDIMS = DATA::GetNDim()>
744 std::unique_ptr<ImplBase_t>
Clone()
const override {
745 return std::unique_ptr<ImplBase_t>(
new RHistImpl(*
this));
766 template <
int NDIMS,
typename BINTYPE>
779 template <
int NDIMS,
typename BINTYPE>
814 [](
int bin) { return bin >= 1; })) {
815 for (
int bin = 0; bin <
NDIMS; bin++)
871 for (
int bin = 0; bin <
NDIMS; ++bin)
1052 void FillN(
const std::span<const CoordArray_t>
xN,
const std::span<const Weight_t>
weightN)
final
1061 for (
size_t i = 0; i <
xN.size(); ++i) {
1069 void FillN(
const std::span<const CoordArray_t>
xN)
final
1071 for (
auto &&
x:
xN) {
1105 AxisIterRange_t<DATA::GetNDim()>
1151template <
class DATA>
#define R__LOG_ERROR(...)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Interface class for RHistImpl.
Weight_t & GetBinContent(int binidx)
Get the bin content (sum of weights) for bin index binidx (non-const).
int GetNOverflowBins() const noexcept final
Get the number of under- and overflow bins of this histogram, excluding all regular bins.
RHistImplBase(const RHistImplBase &)=default
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.
int GetNBinsNoOver() const noexcept final
Get the number of bins in this histogram, excluding possible under- and overflow bins.
RHistImplBase(RHistImplBase &&)=default
Hist::CoordArray_t< DATA::GetNDim()> CoordArray_t
Type of the coordinates.
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.
virtual void FillN(const std::span< const CoordArray_t > xN)=0
Interface function to fill a vector or array of coordinates.
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< const CoordArray_t > xN, const std::span< const 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.
std::array< int, DATA::GetNDim()> BinArray_t
Type of the local per-axis bin indices.
RHistImplBase(std::string_view title, size_t numBins, size_t numOverflowBins)
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.
typename DATA::Weight_t Weight_t
Type of the bin content (and thus weights).
RHistImplBase(size_t numBins, size_t numOverflowBins)
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 GetNOverflowBins() const noexcept=0
Number of under- and overflow bins of this histogram, excluding all regular bins.
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)
std::array< int, DIMENSIONS > BinArray_t
Type of the local per-axis bin indices.
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 int GetNBinsNoOver() const noexcept=0
Number of bins of this histogram, excluding all overflow and underflow bins.
virtual CoordArray_t GetBinTo(int binidx) const =0
Get the upper edge in all dimensions of the bin with index binidx.
virtual BinArray_t GetLocalBins(int binidx) const =0
Given the index of the bin, determine the local per-axis bins x.
std::string fTitle
The histogram's 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 int GetBinIndexAndGrow(const CoordArray_t &x) const =0
Given the coordinate x, determine the index of the bin, possibly growing axes for which x is out of r...
virtual int GetBinIndexFromLocalBins(const BinArray_t &x) const =0
Given the local per-axis bins x, determine the index of the bin.
virtual double GetBinUncertainty(int binidx) const =0
Get the uncertainty of the bin with index binidx.
virtual double GetBinContentAsDouble(int binidx) const =0
The bin content, cast to double.
virtual const RAxisBase & GetAxis(int iAxis) const =0
Get a base-class view on axis with index iAxis.
virtual CoordArray_t GetBinCenter(int binidx) const =0
Get the center in all dimensions of the bin with index binidx.
virtual AxisIterRange_t GetRange() const =0
Get an AxisIterRange_t for the whole histogram, excluding under- and overflow.
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.
BinArray_t GetLocalBins(int binidx) const final
Get the local per-axis bin indices x for the given bin index, using ComputeLocalBins().
int GetBinIndexAndGrow(const CoordArray_t &x) const final
Get the bin index for the given coordinates x, growing the axes as needed.
int ComputeGlobalBinRaw(const BinArray_t &zeroBasedLocalBins, BINTYPE GetNBinType) const
Computes a zero-based global bin index, given...
const_iterator end() const noexcept
void(RHistImplBase::*)(const CoordArray_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
AxisIterRange_t< DATA::GetNDim()> GetRange() const final
Get the begin() and end() for each axis.
BinArray_t ComputeLocalBins(int global_bin) const
Computes the local per-axis bin indices of a certain bin on an NDIMS-dimensional 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 coordinates of the bin with index binidx.
int GetBinIndexFromLocalBins(const BinArray_t &x) const final
Get the bin index for the given local per-axis bin indices x, using ComputeGlobalBin().
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 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
Get the bin index for the given coordinates x.
BinArray_t VirtualBinsToLocalBins(const BinArray_t &virtualBins) const
Converts zero-based virtual bins where the underflow bin has index 0 and the overflow bin has index N...
const RAxisBase & GetAxis(int iAxis) const final
Normalized axes access, converting from actual axis type to base class.
typename Hist::AxisIterRange_t< NDIMS > AxisIterRange_t
int ComputeGlobalBin(BinArray_t &local_bins) const
Computes the global index of a certain bin on an NDIMS-dimensional histogram, knowing the local per-a...
typename ImplBase_t::BinArray_t BinArray_t
double GetBinUncertainty(int binidx) const final
Return the uncertainties for the given bin index.
bool HasBinUncertainty() const final
Whether this histogram's statistics provide storage for uncertainties, or whether uncertainties are d...
typename ImplBase_t::Weight_t Weight_t
std::unique_ptr< ImplBase_t > Clone() const override
RHistBinIter< ImplBase_t > iterator
void FillN(const std::span< const CoordArray_t > xN, const std::span< const Weight_t > weightN) final
Fill an array of weightN to the bins specified by coordinates xN.
BinArray_t ComputeLocalBinsRaw(int zeroBasedGlobalBin, BINTYPE GetNBinType) const
Computes zero-based local bin indices, given...
const std::tuple< AXISCONFIG... > & GetAxes() const
Get the axes of this histogram.
CoordArray_t GetBinTo(int binidx) const final
Get the coordinates of the high limit of the bin with index binidx.
void FillN(const std::span< const CoordArray_t > xN) final
Fill an array of weightN to the bins specified by coordinates xN.
CoordArray_t GetBinFrom(int binidx) const final
Get the coordinates of the low limit of the bin with index binidx.
BinArray_t LocalBinsToVirtualBins(const BinArray_t &localBins) const
Converts local axis bins from the standard kUnderflowBin/kOverflowBin for under/overflow bin indexing...
iterator begin() noexcept
RHistBinIter< const ImplBase_t > const_iterator
typename ImplBase_t::CoordArray_t CoordArray_t
Random const_iterator through bins.
Histogram axis base class.
virtual int GetNBinsNoOver() const noexcept=0
Get the number of bins, excluding under- and overflow.
static constexpr const int kUnderflowBin
Index of the underflow bin, if any.
static constexpr const int kOverflowBin
Index of the overflow bin, if any.
int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
Objects used to configure the different axis types.
const_iterator begin() const
const_iterator end() const
EOverflow
Kinds of under- and overflow handling.
@ kUnderflow
Include underflows.
@ kNoOverflow
Exclude under- and overflows.
@ kOverflow
Include overflows.
@ kUnderOver
Include both under- and overflows.
bool operator&(EOverflow a, EOverflow b)
std::array< RAxisBase::const_iterator, NDIMS > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
std::array< AxisIter_t< NDIMS >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
EFindStatus
Status of FindBin(x) and FindAdjustedBin(x)
@ kValid
The returned bin index is valid.
@ kCanGrow
The coordinate could fit after growing the axis.
int GetNBinsFromAxes(AXISCONFIG... axisArgs)
Get the number of bins in whole hist, including under- and overflow.
EBinCoord
Specifies if the wanted result is the bin's lower edge, center or higher edge.
@ kBinTo
Get the bin high edge.
@ kBinFrom
Get the lower bin edge.
@ kBinCenter
Get the bin center.
int GetNOverflowBinsFromAxes(AXISCONFIG... axisArgs)
Get the number of under- and overflow bins in whole hist, excluding regular bins.
int GetNBinsNoOverFromAxes(AXISCONFIG... axisArgs)
Get the number of bins in whole hist, excluding under- and overflow.
static std::array< const RAxisBase *, sizeof...(AXISCONFIG)> GetAxisView(const AXISCONFIG &... axes) noexcept
RLogChannel & HistLog()
Log channel for Hist diagnostics.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
int operator()(int globalVirtualBin, const AXES &, const BINS &, int, BINTYPE) const
Recursively computes a zero-based global bin index, given...
int operator()(int globalVirtualBin, const AXES &axes, const BINS &zeroBasedLocalBins, int binSize, BINTYPE GetNBinType) const
int operator()(int total_regular_bins_before, const AXES &, const BINS &, const BINS &, const BINS &) const
Recursively gets the total number of regular bins before the current dimension, when computing a glob...
int operator()(int total_regular_bins_before, const AXES &axes, const BINS &virtualBins, const BINS &binSizes, const BINS &localBins) const
void operator()(std::array< int, NDIMS-1 >, std::array< int, NDIMS-1 >, const AXES &) const
Recursively compute some quantities needed for ComputeLocalBins, namely the total number of bins per ...
void operator()(std::array< int, NDIMS-1 > &bins_per_hyperplane, std::array< int, NDIMS-1 > ®ular_bins_per_hyperplane, const AXES &axes) const
void operator()(BINS &, const AXES &, int, BINTYPE) const
Recursively computes zero-based local bin indices, given...
void operator()(BINS &virtualBins, const AXES &axes, int zeroBasedGlobalBin, BINTYPE GetNBinType) const
void operator()(const AXES &, int &, int &, std::array< int, NDIMS-1 >, std::array< int, NDIMS-1 >, int, int) const
Recursively computes the number of regular bins before the current dimension, as well as the number o...
void operator()(const AXES &axes, int &unprocessed_previous_overflow_bin, int &num_regular_bins_before, std::array< int, NDIMS-1 > bins_per_hyperplane, std::array< int, NDIMS-1 > regular_bins_per_hyperplane, int curr_bins_per_hyperplane, int curr_regular_bins_per_hyperplane) const
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &) const
Recursively fills the ranges of all axes, excluding under- and overflow.
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &range, const AXES &axes) const
void operator()(BINS &, const AXES &, const COORD &) const
Find the per-axis local bin indices associated with a certain set of coordinates.
void operator()(BINS &localBins, const AXES &axes, const COORD &coords) const
int operator()(const AXES &axes) const
Recursively gets the total number of bins in whole hist, including under- and overflow.
int operator()(const AXES &axes) const
int operator()(const AXES &axes) const
Recursively gets the total number of bins in whole hist, excluding under- and overflow.
int operator()(const AXES &axes) const
void operator()(BINS &, const AXES &) const
Recursively gets the number of regular bins just before the current dimension.
void operator()(BINS &binSizes, const AXES &axes) const
void operator()(COORD &, const AXES &, const BINS &, EBinCoord) const
Recursively converts local axis bins from the standard kUnderflowBin/kOverflowBin for under/overflow ...
void operator()(COORD &coords, const AXES &axes, const BINS &localBins, EBinCoord kind) const
void operator()(BINS &, const AXES &, const BINS &) const
Recursively converts local axis bins from the standard kUnderflowBin/kOverflowBin for under/overflow ...
void operator()(BINS &virtualBins, const AXES &axes, const BINS &localBins) const
void operator()(BINS &, const AXES &, const BINS &) const
Recursively converts zero-based virtual bins where the underflow bin has index 0 and the overflow bin...
void operator()(BINS &localBins, const AXES &axes, const BINS &virtualBins) const