5#ifndef ROOT_RRegularAxis
6#define ROOT_RRegularAxis
61 RRegularAxis(std::uint64_t nNormalBins, std::pair<double, double> interval,
bool enableFlowBins =
true)
64 if (nNormalBins == 0) {
65 throw std::invalid_argument(
"nNormalBins must be > 0");
67 if (!std::isfinite(
fLow)) {
68 throw std::invalid_argument(
"low must be a finite value, but is " + std::to_string(
fLow));
70 if (!std::isfinite(
fHigh)) {
71 throw std::invalid_argument(
"high must be a finite value, but is " + std::to_string(
fHigh));
74 std::string msg =
"high must be > low, but " + std::to_string(
fLow) +
" >= " + std::to_string(
fHigh);
75 throw std::invalid_argument(msg);
93 throw std::invalid_argument(
"bin must be inside the axis");
104 throw std::invalid_argument(
"bin must be inside the axis");
126 bool underflow =
x <
fLow;
128 bool overflow = !(
x <
fHigh);
131 }
else if (overflow) {
164 std::uint64_t bin = index.
GetIndex();
192 throw std::invalid_argument(
"begin must be a normal bin");
195 throw std::invalid_argument(
"begin must be inside the axis");
198 throw std::invalid_argument(
"end must be a normal bin");
201 throw std::invalid_argument(
"end must be inside or past the axis");
203 if (!(end >= begin)) {
204 throw std::invalid_argument(
"end must be >= begin");
231 throw std::runtime_error(
"sum operation makes dimension disappear");
239 const auto &range = sliceSpec.
GetRange();
240 if (!range.IsInvalid()) {
241 std::uint64_t begin = 0;
242 std::uint64_t end = nNormalBins;
243 if (range.GetBegin().IsNormal()) {
244 begin = range.GetBegin().GetIndex();
250 if (range.GetEnd().IsNormal()) {
251 end = range.GetEnd().GetIndex();
253 if (end < nNormalBins) {
257 nNormalBins = end - begin;
261 if (nNormalBins % opRebin->GetNGroup() != 0) {
262 throw std::runtime_error(
"rebin operation does not divide number of normal bins");
264 nNormalBins /= opRebin->GetNGroup();
269 bool enableFlowBins =
true;
270 return RRegularAxis(nNormalBins, {low, high}, enableFlowBins);
274 void Streamer(
TBuffer &) {
throw std::runtime_error(
"unable to store RRegularAxis"); }
A bin index with special values for underflow and overflow bins.
bool IsNormal() const
A bin index is normal iff it is not one of the special values.
std::uint64_t GetIndex() const
Return the index for a normal bin.
static RBinIndex Underflow()
std::uint64_t GetTotalNBins() const
RBinIndexRange GetNormalRange(RBinIndex begin, RBinIndex end) const
Get a range of normal bins.
RRegularAxis Slice(const RSliceSpec &sliceSpec) const
Slice this axis according to the specification.
bool fEnableFlowBins
Whether underflow and overflow bins are enabled.
friend bool operator==(const RRegularAxis &lhs, const RRegularAxis &rhs)
RBinIndexRange GetFullRange() const
Get the full range of all bins.
double ComputeHighEdge(std::uint64_t bin) const
Compute the high edge of a bin.
double fInvBinWidth
The cached inverse of the bin width to speed up ComputeLinearizedIndex.
RRegularAxis(std::uint64_t nNormalBins, std::pair< double, double > interval, bool enableFlowBins=true)
Construct a regular axis object.
double ComputeLowEdge(std::uint64_t bin) const
Compute the low edge of a bin.
std::uint64_t fNNormalBins
The number of normal bins.
double fLow
The lower end of the axis interval.
RBinIndexRange GetNormalRange() const
Get the range of all normal bins.
void Streamer(TBuffer &)
ROOT Streamer function to throw when trying to store an object of this class.
double fHigh
The upper end of the axis interval.
RLinearizedIndex GetLinearizedIndex(RBinIndex index) const
Compute the linarized index for a single argument.
std::uint64_t GetNNormalBins() const
Specification of a slice operation along one dimension.
const ROperationSum * GetOperationSum() const
const ROperationRebin * GetOperationRebin() const
const RBinIndexRange & GetRange() const
Buffer base class used for serializing objects.
static RBinIndexRange CreateBinIndexRange(RBinIndex begin, RBinIndex end, std::uint64_t nNormalBins)
Internal function to create RBinIndexRange.
Namespace for ROOT features in testing.
A linearized index that can be invalid.