16 #ifndef ROOT7_THistImpl 17 #define ROOT7_THistImpl 31 namespace Experimental {
33 template <
int DIMENSIONS,
class PRECISION,
34 template <
int D_,
class P_,
template <
class P__>
class STORAGE>
class... STAT>
40 using AxisIter_t = std::array<TAxisBase::const_iterator, NDIM>;
55 return static_cast<int>(
a) & static_cast<int>(b);
70 template <
int DIMENSIONS>
85 static constexpr
int GetNDim() {
return DIMENSIONS; }
88 virtual int GetNBins()
const noexcept = 0;
91 const std::string &
GetTitle()
const {
return fTitle; }
97 virtual int GetBinIndexAndGrow(
const CoordArray_t &x) = 0;
100 virtual CoordArray_t GetBinCenter(
int binidx)
const = 0;
108 virtual double GetBinUncertainty(
int binidx)
const = 0;
112 virtual bool HasBinUncertainty()
const = 0;
115 virtual double GetBinContentAsDouble(
int binidx)
const = 0;
120 virtual TAxisView GetAxis(
int iAxis)
const = 0;
141 template <
class DATA>
170 virtual void FillN(
const std::array_view<CoordArray_t> xN,
const std::array_view<Weight_t> weightN) = 0;
173 virtual void FillN(
const std::array_view<CoordArray_t> xN) = 0;
196 virtual double GetBinUncertainty(
const CoordArray_t &x)
const = 0;
200 int GetNBins() const noexcept final {
return fStatistics.size(); }
232 template <
int IDX,
class AXISTUPLE>
235 template <
class AXES>
237 int operator()(
const AXES &axes)
const {
return std::get<0>(axes).GetNBins(); }
240 template <
int I,
class AXES>
245 template <
class... AXISCONFIG>
248 using axesTuple = std::tuple<AXISCONFIG...>;
249 return TGetBinCount<
sizeof...(AXISCONFIG) - 1, axesTuple>()(axesTuple{axisArgs...});
252 template <
int IDX,
class HISTIMPL,
class AXES,
bool GROW>
256 template <
class HISTIMPL,
class AXES,
bool GROW>
266 template <
int I,
class HISTIMPL,
class AXES,
bool GROW>
271 constexpr
const int thisAxis = HISTIMPL::GetNDim() -
I - 1;
272 int bin = std::get<thisAxis>(axes).FindBin(x[thisAxis]);
273 if (GROW && std::get<thisAxis>(axes).CanGrow() && (bin < 0 || bin > std::get<thisAxis>(axes).GetNBinsNoOver())) {
274 hist->GrowAxis(
I, x[thisAxis]);
281 TGetBinIndex<
I - 1, HISTIMPL, AXES, GROW>()(hist, axes, x, status) * std::get<thisAxis>(axes).GetNBins();
285 template <
int I,
class AXES>
289 template <
class AXES>
292 const std::array<
Hist::EOverflow, std::tuple_size<AXES>::value> & )
const 299 template <
int I,
class AXES>
302 const std::array<
Hist::EOverflow, std::tuple_size<AXES>::value> &over)
const 305 range[0][
I] = std::get<I>(axes).begin_with_underflow();
307 range[0][
I] = std::get<I>(axes).begin();
309 range[1][
I] = std::get<I>(axes).end_with_overflow();
311 range[1][
I] = std::get<I>(axes).end();
322 template <
int I,
class COORD,
class AXES>
326 template <
class COORD,
class AXES>
333 template <
int I,
class COORD,
class AXES>
337 int axisbin = binidx % std::get<I>(axes).GetNBins();
338 size_t coordidx = std::tuple_size<AXES>::value -
I - 1;
340 case EBinCoord::kBinFrom: coord[coordidx] = std::get<I>(axes).GetBinFrom(axisbin);
break;
341 case EBinCoord::kBinCenter: coord[coordidx] = std::get<I>(axes).GetBinCenter(axisbin);
break;
342 case EBinCoord::kBinTo: coord[coordidx] = std::get<I>(axes).GetBinTo(axisbin);
break;
344 TFillBinCoord<I - 1, COORD, AXES>()(coord, axes, kind, binidx / std::get<I>(axes).GetNBins());
348 template <
class... AXISCONFIG>
351 std::array<TAxisView,
sizeof...(AXISCONFIG)> axisViews = {{TAxisView(axes)...}};
360 template <
class DATA,
class... AXISCONFIG>
362 static_assert(
sizeof...(AXISCONFIG) == DATA::GetNDim(),
"Number of axes must equal histogram dimension");
364 friend typename DATA::Hist_t;
371 template <
int NDIM = DATA::GetNDim()>
398 for (
auto binref: *
this)
399 op(binref.GetCenter(), binref.GetContent());
406 for (
auto binref: *
this)
407 op(binref.GetCenter(), binref.GetContent(), binref.GetUncertainty());
411 const std::tuple<AXISCONFIG...> &
GetAxes()
const {
return fAxes; }
414 TAxisView
GetAxis(
int iAxis)
const final {
return std::apply(Internal::GetAxisView<AXISCONFIG...>, fAxes)[iAxis]; }
472 void FillN(
const std::array_view<CoordArray_t> xN,
const std::array_view<Weight_t> weightN)
final 475 if (xN.size() != weightN.size()) {
476 R__ERROR_HERE(
"HIST") <<
"Not the same number of points and weights!";
481 for (
size_t i = 0; i < xN.size(); ++i) {
482 Fill(xN[i], weightN[i]);
489 void FillN(
const std::array_view<CoordArray_t> xN)
final 499 int bin = GetBinIndexAndGrow(x);
500 this->GetStat().Fill(x, bin, w);
506 int bin = GetBinIndex(
x);
508 return ImplBase_t::GetBinContent(bin);
513 double GetBinUncertainty(
int binidx)
const final {
return this->GetStat().GetBinUncertainty(binidx); }
518 const int bin = GetBinIndex(
x);
519 return this->GetBinUncertainty(bin);
533 std::array<std::array<TAxisBase::const_iterator, DATA::GetNDim()>, 2> ret;
559 template <
class DATA,
class... AXISCONFIG>
563 template <
class DATA,
class... AXISCONFIG>
568 template <
class DATA,
class... AXISCONFIG>
576 template <
class DATA>
579 THistImplRuntime(std::array<
TAxisConfig, DATA::GetNDim()>&& axisCfg);
int GetNBins() const noexcept final
Get the number of bins in this histogram, including possible under- and overflow bins.
Exclude under- and overflows.
DATA Stat_t
Type of the statistics (bin content, uncertainties etc).
void AddBinContent(int binidx, Weight_t w)
Add w to the bin at index bin.
CoordArray_t GetBinFrom(int binidx) const final
Get the coordinate of the low limit of the bin.
basic_string_view< char > string_view
int operator()(HISTIMPL *, const AXES &, const typename HISTIMPL::CoordArray_t &, TAxisBase::EFindStatus &status) const
Namespace for new ROOT classes and functions.
Weight_t GetBinContent(const CoordArray_t &x) const final
Get the content of the bin at position x.
void operator()(COORD &coord, const AXES &axes, EBinCoord kind, int binidx) const
double GetBinContentAsDouble(int binidx) const final
Get the bin content (sum of weights) for bin index binidx, cast to double.
bool operator &(EOverflow a, EOverflow b)
Interface class for THistImpl.
int GetBinIndexAndGrow(const CoordArray_t &x) final
Gets the bin index for coordinate x, growing the axes as needed and possible.
typename Hist::AxisIterRange_t< NDIM > AxisIterRange_t
Weight_t GetBinContent(int binidx) const
Get the bin content (sum of weights) for bin index binidx.
Weight_t & GetBinContent(int binidx)
Get the bin content (sum of weights) for bin index binidx (non-const).
void operator()(COORD &, const AXES &, EBinCoord, int) const
Iterates over the bins of a THist or THistImpl.
std::tuple< AXISCONFIG... > fAxes
The histogram's axes.
void GrowAxis(int, double)
Grow the axis number iAxis to fit the coordinate 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.
Common view on a TAxis, no matter what its kind.
const_iterator begin() const noexcept
int operator()(const AXES &axes) const
const std::tuple< AXISCONFIG... > & GetAxes() const
Get the axes of this histogram.
EFindStatus
Status of FindBin(x)
int GetNBinsFromAxes(AXISCONFIG... axisArgs)
Stat_t & GetStat() noexcept
Non-const access to statistics.
std::string fTitle
Histogram title.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
void FillN(const std::array_view< CoordArray_t > xN) 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...
static void GetRange(const char *comments, Double_t &xmin, Double_t &xmax, Double_t &factor)
Parse comments to search for a range specifier of the style: [xmin,xmax] or [xmin,xmax,nbits] [0,1] [-10,100]; [-pi,pi], [-pi/2,pi/4],[-2pi,2*pi] [-10,100,16] [0,0,8] if nbits is not specified, or nbits <2 or nbits>32 it is set to 32 if (xmin==0 and xmax==0 and nbits <=16) the double word will be converted to a float and its mantissa truncated to nbits significative bits.
iterator begin() noexcept
THistImplPrecisionAgnosticBase(std::string_view title)
TCoordArray< DIMENSIONS > CoordArray_t
AxisIterRange_t< DATA::GetNDim()> GetRange(const std::array< Hist::EOverflow, DATA::GetNDim()> &withOverUnder) const final
Get the begin() and end() for each axis.
const_iterator end() const noexcept
bool HasBinUncertainty() const final
Whether this histogram's statistics provide storage for uncertainties, or whether uncertainties are d...
Include both under- and overflows.
void(THistImplBase::*)(const CoordArray_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
void Fill(const CoordArray_t &x, Weight_t w=1.)
Add a single weight w to the bin at coordinate x.
Objects used to configure the different axis types.
const Stat_t & GetStat() const noexcept
Const access to statistics.
typename DATA::Weight_t Weight_t
Type of the bin content (and thus weights).
Represents a bin reference.
CoordArray_t GetBinTo(int binidx) const final
Get the coordinate of the high limit of the bin.
void Apply(std::function< void(THistBinRef< const ImplBase_t >)> op) const final
Apply a function (lambda) to all bins of the histogram.
void ApplyXC(std::function< void(const CoordArray_t &, Weight_t)> op) const final
Apply a function (lambda) to all bins of the histogram.
static constexpr int GetNDim()
Number of dimensions of the coordinates.
THistImplBase(std::string_view title, size_t numBins)
double GetBinUncertainty(int binidx) const final
Return the uncertainties for the given bin.
The returned bin index is valid.
virtual ~THistImplPrecisionAgnosticBase()
TAxisView GetAxis(int iAxis) const final
Normalized axes access, converting the actual axis to TAxisConfig.
static std::array< TAxisView, sizeof...(AXISCONFIG)> GetAxisView(const AXISCONFIG &... axes) noexcept
Base class for THistImplBase that abstracts out the histogram's PRECISION.
Hist::AxisIterRange_t< DIMENSIONS > AxisIterRange_t
Range type.
Stat_t fStatistics
The histogram's bin content, uncertainties etc.
void FillN(const std::array_view< CoordArray_t > xN, const std::array_view< Weight_t > weightN) final
Fill an array of weightN to the bins specified by coordinates xN.
typedef void((*Func_t)())
double GetBinUncertainty(const CoordArray_t &x) const final
Get the bin uncertainty for the bin at coordinate x.
Fill range with begin() and end() of all axes, including under/overflow as specified by over...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
int operator()(const AXES &axes) const
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &) const
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.
Fill coord with low bin edge or center or high bin edge of all axes.
Coordinate could fit after growing the axis.
std::array< AxisIter_t< NDIM >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
int operator()(HISTIMPL *hist, const AXES &axes, const typename HISTIMPL::CoordArray_t &x, TAxisBase::EFindStatus &status) const
CoordArray_t GetBinCenter(int binidx) const final
Get the center coordinate of the bin.
EOverflow
Kinds of under- and overflow handling.
decltype(auto) constexpr apply(F &&f, Tuple &&t)
const std::string & GetTitle() const
Get the histogram title.
#define R__ERROR_HERE(GROUP)
THistImplBase(size_t numBins)
std::array< TAxisBase::const_iterator, NDIM > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
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