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; }
68 virtual int GetNBins()
const = 0;
71 virtual int GetBinIndex(
const Coord_t&
x)
const = 0;
74 virtual int GetBinIndexAndGrow(
const Coord_t& x) = 0;
77 virtual Coord_t GetBinCenter(
int binidx)
const = 0;
79 virtual Coord_t GetBinFrom(
int binidx)
const = 0;
81 virtual Coord_t GetBinTo(
int binidx)
const = 0;
85 virtual std::vector<double> GetBinUncertainties(
int binidx)
const = 0;
88 virtual double GetBinContentAsDouble(
int binidx)
const = 0;
93 virtual TAxisView GetAxis(
int iAxis)
const = 0;
101 GetRange(
const std::array<Hist::EOverflow, DIMENSIONS>& withOverUnder)
const = 0;
113 template<
int DIMENSIONS,
class PRECISION>
137 virtual PRECISION GetBinContent(
int binidx)
const = 0;
142 return (
double) GetBinContent(binidx);
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();
258 case EBinCoord::kBinFrom:
259 coord[coordidx] = std::get<I>(axes).GetBinFrom(axisbin);
262 coord[coordidx] = std::get<I>(axes).GetBinCenter(axisbin);
264 case EBinCoord::kBinTo:
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>;
312 decltype(fAxes)>()(fAxes);
324 THistImpl(STATISTICS statConfig, AXISCONFIG... axisArgs);
331 const std::tuple<AXISCONFIG...>&
GetAxes()
const {
return fAxes; }
335 return std::apply(Internal::GetAxisView<AXISCONFIG...>, fAxes)[iAxis];
344 decltype(fAxes),
false>()(
nullptr, fAxes,
x, status);
358 (
this, 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);
424 int bin = GetBinIndexAndGrow(x);
426 AddBinContent(bin, w);
427 STATISTICS::Fill(x, w);
432 int bin = GetBinIndex(x);
434 return GetBinContent(bin);
441 return fContent[binidx];
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.
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
Common view on a TAxis, no matter what its kind.
FillFunc_t GetFillFunc() const final
Retrieve the fill function for this histogram implementation, to prevent the virtual function call fo...
TAxisView GetAxis(int iAxis) const final
Normalized axes access, converting the actual axis to TAxisConfig.
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.
Coord_t GetBinTo(int binidx) const final
Get the coordinate of the high limit of the bin.
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &) const
PRECISION GetBinContent(int binidx) const final
Get the content of the bin at bin index binidx.
double GetBinContentAsDouble(int binidx) const final
Get the bin content (sum of weights) for bin index binidx, cast to double.
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.
void AddBinContent(int bin, Weight_t w)
Add w to the bin at index bin.
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.
void operator()(COORD &coord, const AXES &axes, EBinCoord kind, int binidx) const
constexpr int GetNDim() const
Number of dimensions of this histogram.
std::vector< double > GetBinUncertainties(int binidx) const final
Return the uncertainties for the given bin.
void(THistImplBase::*)(const Coord_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
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.
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.
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...
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.
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.
void FillN(const std::array_view< Coord_t > xN) final
Fill an array of weightN to the bins specified by coordinates xN.
Coord_t GetBinCenter(int binidx) const final
Get the center coordinate of the bin.
Fill range with begin() and end() of all axes, including under/overflow as specified by over...
The returned bin index is valid.
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.
int operator()(const AXES &axes) const
#define R__ERROR_HERE(GROUP)
void operator()(COORD &, const AXES &, EBinCoord, int) const
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.
Coord_t GetBinFrom(int binidx) const final
Get the coordinate of the low limit of the bin.
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
std::tuple< AXISCONFIG... > fAxes
The histogram's axes.
const std::tuple< AXISCONFIG... > & GetAxes() const
Get the axes of this histogram.