23#include <unordered_map>
31namespace Experimental {
57 RAxisBase() noexcept(noexcept(std::
string())) = default;
126 class const_iterator:
public std::iterator<std::random_access_iterator_tag, int , int ,
127 const int * , const int & > {
344 return lhs.fCursor < rhs.fCursor;
350 return lhs.fCursor > rhs.fCursor;
356 return lhs.fCursor <= rhs.fCursor;
362 return lhs.fCursor >= rhs.fCursor;
368 return lhs.fCursor == rhs.fCursor;
374 return lhs.fCursor != rhs.fCursor;
394 static double GetInvBinWidth(
int nbinsNoOver,
double lowOrHigh,
double highOrLow)
396 return nbinsNoOver /
std::fabs(highOrLow - lowOrHigh);
451 int FindBin(
double x)
const noexcept final override
458 bool CanGrow() const noexcept
override {
return false; }
495 return RAxisEquidistant(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
562 bool CanGrow() const noexcept final
override {
return true; }
573 return RAxisGrow(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
609 auto iNotLess = std::lower_bound(bBegin, bEnd,
x);
610 return iNotLess - bBegin;
621#ifdef R__DO_RANGE_CHECKS
634#ifdef R__DO_RANGE_CHECKS
645#ifdef R__DO_RANGE_CHECKS
658#ifdef R__DO_RANGE_CHECKS
673 int FindBin(
double x)
const noexcept final override
704 bool CanGrow() const noexcept final
override {
return false; }
746 :
RAxisGrow(title, labels.size(), 0., static_cast<
double>(labels.size()))
748 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
754 :
RAxisGrow(title, labels.size(), 0., static_cast<
double>(labels.size()))
756 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
773 if (insertResult.second) {
776 insertResult.first->second = idx;
779 return insertResult.first->second;
793 vec.at(kv.second) = kv.first;
816 size_t missing_in_other = 0;
820 auto iter = other.fLabelsIndex.find(kv.first);
821 if (iter == other.fLabelsIndex.cend()) {
823 }
else if (iter->second != kv.second) {
827 if (missing_in_other > 0)
831 if (
fLabelsIndex.size() == other.fLabelsIndex.size() + missing_in_other)
835 for (
const auto &kv: other.fLabelsIndex)
#define R__ERROR_HERE(GROUP)
Random const_iterator through bins.
int operator[](int d) noexcept
const_iterator & operator-=(int d) noexcept
const_iterator operator-(int d) noexcept
int operator-(const const_iterator &j) noexcept
const_iterator operator++(int) noexcept
i++
friend bool operator>(const_iterator lhs, const_iterator rhs) noexcept
i > j
const_iterator operator+(int d) noexcept
int fCursor
Current iteration position.
const int * operator->() const noexcept
const_iterator & operator+=(int d) noexcept
const_iterator & operator--() noexcept
–i
const_iterator & operator++() noexcept
++i
const_iterator operator--(int) noexcept
const_iterator(int cursor) noexcept
Initialize a const_iterator with its position.
friend bool operator<=(const_iterator lhs, const_iterator rhs) noexcept
i <= j
int operator*() const noexcept
friend bool operator<(const_iterator lhs, const_iterator rhs) noexcept
i < j
friend bool operator>=(const_iterator lhs, const_iterator rhs) noexcept
i >= j
friend bool operator==(const_iterator lhs, const_iterator rhs) noexcept
i == j
friend bool operator!=(const_iterator lhs, const_iterator rhs) noexcept
i != j
Histogram axis base class.
int GetFirstBin() const noexcept
Get the bin index for the first bin of the axis.
const_iterator end() const noexcept
Get a const_iterator pointing beyond the last regular bin.
virtual int GetBinIndexForLowEdge(double x) const noexcept=0
If the coordinate x is within 10 ULPs of a bin low edge coordinate, return the bin for which this is ...
int GetNOverflowBins() const noexcept
Get the number of over- and underflow bins: 0 for growable axes, 2 otherwise.
RAxisBase(const RAxisBase &)=default
double GetMinimum() const
Get the low end of the axis range.
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.
double GetMaximum() const
Get the high end of the axis range.
std::string fTitle
Title of this axis, used for graphics / text.
virtual int FindBin(double x) const noexcept=0
Find the adjusted bin index (returning kUnderflowBin for underflow and kOverflowBin for overflow) for...
int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin (or kInvalidBin if CanGrow()).
virtual double GetBinFrom(int bin) const =0
Get the low bin border ("left edge") for the given bin index.
const std::string & GetTitle() const
Get the axis's title.
RAxisBase & operator=(RAxisBase &&)=default
const_iterator begin() const noexcept
Get a const_iterator pointing to the first regular bin.
int GetOverflowBin() const noexcept
Get the bin index for the overflow bin (or kInvalidBin if CanGrow()).
virtual double GetBinCenter(int bin) const =0
Get the bin center for the given bin index.
static constexpr const int kOverflowBin
Index of the overflow bin, if any.
RAxisBase() noexcept(noexcept(std::string()))=default
Default construct a RAxisBase (for use by derived classes for I/O)
virtual bool CanGrow() const noexcept=0
Whether this axis can grow (and thus has no overflow bins).
int AdjustOverflowBinNumber(double rawbin) const
Given rawbin (<0 for underflow, >=GetNBinsNoOver() for overflow), determine the bin number taking int...
int GetLastBin() const noexcept
Get the bin index for the last bin of the axis.
double GetBinTo(int bin) const
Get the high bin border ("right edge") for the given bin index.
virtual bool HasSameBinBordersAs(const RAxisBase &other) const
Check if two axis have the same bin borders.
RAxisBase(RAxisBase &&)=default
static constexpr const int kInvalidBin
Special bin index returned to signify that no bin matches a request.
bool HasSameBinningAs(const RAxisBase &other) const
Check if two axes use the same binning convention, i.e.
int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
RAxisBase & operator=(const RAxisBase &)=default
Objects used to configure the different axis types.
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
const std::string & GetTitle() const
Get the axis's title.
Axis with equidistant bin borders.
RAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high) noexcept
Initialize a RAxisEquidistant.
int GetBinIndexForLowEdge(double x) const noexcept final override
If the coordinate x is within 10 ULPs of a bin low edge coordinate, return the bin for which this is ...
RAxisEquidistant(int nbinsNoOver, double low, double high) noexcept
Initialize a RAxisEquidistant.
double GetBinWidth() const noexcept
Get the width of the bins.
double GetBinCenter(int bin) const final override
Get the bin center for the given bin index.
double FindBinRaw(double x) const noexcept
Find the raw bin index (not adjusted) for the given coordinate.
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
RAxisEquidistant()=default
int GetNBinsNoOver() const noexcept final override
Get the number of bins, excluding under- and overflow.
bool HasSameBinBordersAs(const RAxisBase &other) const override
See RAxisBase::HasSameBinBordersAs.
int FindBin(double x) const noexcept final override
Find the adjusted bin index (returning kUnderflowBin for underflow and kOverflowBin for overflow) for...
double fInvBinWidth
The inverse of the bin width.
double GetBinFrom(int bin) const final override
Get the low bin border for the given bin index.
static double GetInvBinWidth(int nbinsNoOver, double lowOrHigh, double highOrLow)
Determine the inverse bin width.
bool CanGrow() const noexcept override
This axis cannot grow.
unsigned int fNBinsNoOver
Number of bins excluding under- and overflow.
double fLow
The lower limit of the axis.
An axis that can extend its range, keeping the number of its bins unchanged.
RAxisGrow(std::string_view title, int nbins, double low, double high) noexcept
Initialize a RAxisGrow.
int Grow(int toBin)
Grow this axis to make the "virtual bin" toBin in-range.
RAxisGrow(int nbins, double low, double high) noexcept
Initialize a RAxisGrow.
bool CanGrow() const noexcept final override
This axis kind can increase its range.
An axis with non-equidistant bins (also known as "variable binning").
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
double GetBinFrom(int bin) const final override
Get the lower bin border for a given bin index.
bool HasSameBinBordersAs(const RAxisBase &other) const override
See RAxisBase::HasSameBinBordersAs.
RAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a RAxisIrregular from a vector of bin borders.
RAxisIrregular(const std::vector< double > &binborders)
Construct a RAxisIrregular from a vector of bin borders.
int GetBinIndexForLowEdge(double x) const noexcept final override
If the coordinate x is within 10 ULPs of a bin low edge coordinate, return the bin for which this is ...
double GetBinCenter(int bin) const final override
Get the bin center of the bin with the given index.
bool CanGrow() const noexcept final override
This axis cannot be extended.
int GetNBinsNoOver() const noexcept final override
Get the number of bins, excluding under- and overflow.
std::vector< double > fBinBorders
Bin borders, one more than the number of regular bins.
int FindBin(double x) const noexcept final override
Find the bin index (adjusted with under- and overflow) for the given coordinate x.
RAxisIrregular(std::string_view title, std::vector< double > &&binborders) noexcept
Construct a RAxisIrregular from a vector of bin borders.
RAxisIrregular(std::string_view title, const std::vector< double > &binborders)
Construct a RAxisIrregular from a vector of bin borders.
double FindBinRaw(double x) const noexcept
Find the raw bin index (not adjusted) for the given coordinate x.
A RAxisGrow that has a label assigned to each bin and a bin width of 1.
LabelsCmpFlags
Result of an RAxisLabels label set comparison.
@ kLabelsCmpDisordered
The labels shared by both axes do not map into the same bins.
@ kLabelsCmpSubset
The other axis doesn't have some labels from this axis.
@ kLabelsCmpSame
Both axes have the same labels, mapping to the same bins.
@ kLabelsCmpSuperset
The other axis has some labels which this axis doesn't have.
RAxisLabels(const std::vector< std::string > &labels)
Construct a RAxisLables from a vector of strings.
RAxisLabels(const std::vector< std::string_view > &labels)
Construct a RAxisLables from a vector of string_views.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
double GetBinCenterByName(const std::string &label)
Get the center of the bin with label.
int FindBinByName(const std::string &label)
Get the bin index with label.
RAxisLabels(std::string_view title, const std::vector< std::string_view > &labels)
Construct a RAxisLables from a vector of string_views, with title.
RAxisLabels(std::string_view title, const std::vector< std::string > &labels)
Construct a RAxisLables from a vector of strings, with title.
LabelsCmpFlags CompareBinLabels(const RAxisLabels &other) const noexcept
Compare the labels of this axis with those of another axis.
basic_string_view< char > string_view
EAxisCompatibility CanMap(const RAxisEquidistant &target, const RAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
bool operator>=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i >= j
bool operator==(const TString &t, const std::string &s)
bool operator>(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i > j
@ kContains
The source is a subset of bins of the target axis.
@ kIdentical
Source and target axes are identical.
@ kIncompatible
The source axis and target axis have different binning.
@ kSampling
The bins of the source axis have finer granularity, but the bin borders are compatible.
bool operator<(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i < j
REveException operator+(const REveException &s1, const std::string &s2)
bool operator<=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i <= j
bool operator!=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i != j
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Axis_t operator()(const RAxisConfig &cfg) noexcept
Axis_t operator()(const RAxisConfig &cfg) noexcept
Axis_t operator()(const RAxisConfig &cfg)
Axis_t operator()(const RAxisConfig &cfg)
Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived object.