25#include <initializer_list>
29namespace Experimental {
32template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
36template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
38HistFromImpl(std::unique_ptr<typename RHist<DIMENSIONS, PRECISION, STAT...>::ImplBase_t> pHistImpl);
52template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
70 static constexpr int GetNDim() noexcept {
return DIMENSIONS; }
92 explicit RHist(std::array<RAxisConfig, DIMENSIONS> axes);
95 RHist(std::string_view histTitle, std::array<RAxisConfig, DIMENSIONS> axes);
98 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 1>::type>
104 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 1>::type>
109 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 2>::type>
115 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 2>::type>
121 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 3>::type>
128 template <int ENABLEIF_NDIM = DIMENSIONS, class = typename std::enable_if<ENABLEIF_NDIM == 3>::type>
137 std::unique_ptr<ImplBase_t>
TakeImpl() &&
noexcept {
return std::move(
fImpl); }
145 void FillN(
const std::span<const CoordArray_t> xN,
const std::span<const Weight_t> weightN)
noexcept
147 fImpl->FillN(xN, weightN);
154 void FillN(std::initializer_list<const CoordArray_t> xN, std::initializer_list<const Weight_t> weightN)
noexcept
156 fImpl->FillN(std::span<const CoordArray_t>(xN.begin(), xN.end()), std::span<const Weight_t>(weightN.begin(), weightN.end()));
160 void FillN(
const std::span<const CoordArray_t> xN)
noexcept {
fImpl->FillN(xN); }
164 void FillN(std::initializer_list<const CoordArray_t> xN)
noexcept {
165 fImpl->FillN(std::span<const CoordArray_t>(xN.begin(), xN.end()));
186 std::swap(
fImpl, other.fImpl);
197 friend RHist HistFromImpl<>(std::unique_ptr<ImplBase_t>);
201template <
int DIMENSIONS,
class PRECISION>
209template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
219template <
int NDIM,
int IDIM,
class DATA,
class... PROCESSEDAXISCONFIG>
223 template <RAxisConfig::EKind KIND>
224 std::unique_ptr<Detail::RHistImplBase<DATA>>
225 MakeNextAxis(std::string_view title,
const std::array<RAxisConfig, NDIM> &axes,
226 PROCESSEDAXISCONFIG... processedAxisArgs)
230 using HistImpl_t =
RHistImplGen<NDIM, IDIM + 1, DATA, PROCESSEDAXISCONFIG..., NextAxis_t>;
231 return HistImpl_t()(title, axes, processedAxisArgs..., nextAxis);
246 std::unique_ptr<Detail::RHistImplBase<DATA>>
operator()(std::string_view title,
247 const std::array<RAxisConfig, NDIM> &axes,
248 PROCESSEDAXISCONFIG... processedAxisArgs)
250 switch (axes[IDIM].GetKind()) {
252 case RAxisConfig::kGrow:
return MakeNextAxis<RAxisConfig::kGrow>(title, axes, processedAxisArgs...);
261template <
int NDIM,
class DATA,
class... PROCESSEDAXISCONFIG>
266 std::unique_ptr<HistImplBase_t>
267 operator()(std::string_view title,
const std::array<
RAxisConfig, DATA::GetNDim()> &, PROCESSEDAXISCONFIG... axisArgs)
270 return std::make_unique<HistImplt_t>(title, axisArgs...);
275template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
278 Internal::RHistImplGen<
RHist::GetNDim(), 0,
285template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
290template <
int DIMENSIONS,
class PRECISION,
template <
int D_,
class P_>
class...
STAT>
295 ret.fFillFunc = pHistImpl->GetFillFunc();
296 std::swap(ret.fImpl, pHistImpl);
336template <
int DIMENSIONS,
class PRECISION,
337 template <
int D_,
class P_>
class... STAT_TO,
338 template <
int D_,
class P_>
class... STAT_FROM>
343 const auto& fromImpl = *from.
GetImpl();
344 for (
int dim = 0; dim < DIMENSIONS; ++dim) {
345 if (!toImpl.GetAxis(dim).HasSameBinningAs(fromImpl.GetAxis(dim))) {
346 throw std::runtime_error(
"Attempted to add RHists with incompatible axis binning");
352 toImpl.GetStat().Add(fromImpl.GetStat());
#define R__LOG_ERROR(...)
Iterates over the bins of a RHist or RHistImpl.
Interface class for RHistImpl.
void(RHistImplBase::*)(const CoordArray_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
Hist::CoordArray_t< DATA::GetNDim()> CoordArray_t
Type of the coordinates.
Hist::AxisIterRange_t< DIMENSIONS > AxisIterRange_t
Range type.
Objects used to configure the different axis types.
@ kGrow
represents a RAxisGrow
@ kEquidistant
represents a RAxisEquidistant
@ kIrregular
represents a RAxisIrregular
Basic histogram statistics, keeping track of the bin content and the total number of calls to Fill().
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
ImplBase_t * GetImpl() const noexcept
Access the ImplBase_t this RHist points to.
static constexpr int GetNDim() noexcept
Number of dimensions of the coordinates.
void FillN(const std::span< const CoordArray_t > xN) noexcept
Convenience overload: FillN() with weight 1.
PRECISION Weight_t
The type of weights.
Weight_t GetBinContent(const CoordArray_t &x) const
Get the content of the bin at x.
int64_t GetEntries() const noexcept
Get the number of entries this histogram was filled with.
double GetBinUncertainty(const CoordArray_t &x) const
Get the uncertainty on the content of the bin at x.
RHist(std::string_view histTitle, const RAxisConfig &xaxis, const RAxisConfig &yaxis)
Constructor overload that's only available for a 2-dimensional histogram, also passing the histogram ...
const_iterator end() const
RHist(const RAxisConfig &xaxis, const RAxisConfig &yaxis)
Constructor overload that's only available for a 2-dimensional histogram.
void FillN(std::initializer_list< const CoordArray_t > xN, std::initializer_list< const Weight_t > weightN) noexcept
For each coordinate in xN, add weightN[i] to the bin at coordinate xN[i].
typename ImplBase_t::FillFunc_t FillFunc_t
Pointer type to HistImpl_t::Fill, for faster access.
RHist(const RAxisConfig &xaxis, const RAxisConfig &yaxis, const RAxisConfig &zaxis)
Constructor overload that's only available for a 3-dimensional histogram.
void FillN(const std::span< const CoordArray_t > xN, const std::span< const Weight_t > weightN) noexcept
For each coordinate in xN, add weightN[i] to the bin at coordinate xN[i].
typename ImplBase_t::AxisIterRange_t AxisRange_t
Range.
void Fill(const CoordArray_t &x, Weight_t weight=(Weight_t) 1) noexcept
Add weight to the bin containing coordinate x.
RHist(std::string_view histTitle, std::array< RAxisConfig, DIMENSIONS > axes)
Constructor overload taking the histogram title.
Detail::RHistBinIter< ImplBase_t > const_iterator
const_iterator begin() const
RHist(std::string_view histTitle, const RAxisConfig &xaxis, const RAxisConfig &yaxis, const RAxisConfig &zaxis)
Constructor overload that's only available for a 3-dimensional histogram, also passing the histogram ...
void swap(RHist< DIMENSIONS, PRECISION, STAT... > &other) noexcept
Swap *this and other.
std::unique_ptr< ImplBase_t > fImpl
The actual histogram implementation.
std::unique_ptr< ImplBase_t > TakeImpl() &&noexcept
"Steal" the ImplBase_t this RHist points to.
RHist(const RHist &other)
void FillN(std::initializer_list< const CoordArray_t > xN) noexcept
Convenience overload: FillN() with weight 1.
RHist(const RAxisConfig &xaxis)
Constructor overload that's only available for a 1-dimensional histogram.
RHist(std::array< RAxisConfig, DIMENSIONS > axes)
Create a histogram from an array of axes (RAxisConfigs).
FillFunc_t fFillFunc
Pointer to RHistImpl::Fill() member function.
typename ImplBase_t::CoordArray_t CoordArray_t
The coordinates type: a DIMENSIONS-dimensional std::array of double.
RHist(std::string_view histTitle, const RAxisConfig &xaxis)
Constructor overload that's only available for a 1-dimensional histogram, also passing the histogram ...
class RHist< DIMENSIONS, PRECISION, STAT... > HistFromImpl(std::unique_ptr< typename RHist< DIMENSIONS, PRECISION, STAT... >::ImplBase_t > pHistImpl)
Adopt an external, stand-alone RHistImpl. The RHist will take ownership.
void Add(RHist< DIMENSIONS, PRECISION, STAT_TO... > &to, const RHist< DIMENSIONS, PRECISION, STAT_FROM... > &from)
Add two histograms.
RLogChannel & HistLog()
Log channel for Hist diagnostics.
void swap(RHist< DIMENSIONS, PRECISION, STAT... > &a, RHist< DIMENSIONS, PRECISION, STAT... > &b) noexcept
Swap two histograms.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived object.
std::unique_ptr< HistImplBase_t > operator()(std::string_view title, const std::array< RAxisConfig, DATA::GetNDim()> &, PROCESSEDAXISCONFIG... axisArgs)
Generate RHist::fImpl from RHist constructor arguments.
std::unique_ptr< Detail::RHistImplBase< DATA > > MakeNextAxis(std::string_view title, const std::array< RAxisConfig, NDIM > &axes, PROCESSEDAXISCONFIG... processedAxisArgs)
Select the template argument for the next axis type, and "recurse" into RHistImplGen for the next axi...
std::unique_ptr< Detail::RHistImplBase< DATA > > operator()(std::string_view title, const std::array< RAxisConfig, NDIM > &axes, PROCESSEDAXISCONFIG... processedAxisArgs)
Make a RHistImpl-derived object reflecting the RAxisConfig array.