20 #include <initializer_list>
22 #include <unordered_map>
25 #include "RStringView.h"
29 namespace Experimental {
74 if (rawbin < 0)
return 0;
91 public std::iterator<std::random_access_iterator_tag,
93 const int * , const int & > {
183 TAxisBase(std::string_view title,
int nbinsNoOver,
bool canGrow) noexcept:
268 return lhs.fCursor < rhs.fCursor;
274 return lhs.fCursor > rhs.fCursor;
280 return lhs.fCursor <= rhs.fCursor;
286 return lhs.fCursor >= rhs.fCursor;
292 return lhs.fCursor == rhs.fCursor;
298 return lhs.fCursor != rhs.fCursor;
367 TAxisConfig(std::string_view title,
const std::vector<double> &binborders):
376 TAxisConfig(std::string_view title, std::vector<double> &&binborders) noexcept:
385 TAxisConfig(std::string_view title,
const std::vector<std::string_view> &labels):
395 TAxisConfig(std::string_view title, std::vector<std::string> &&labels):
430 static double GetInvBinWidth(
int nbinsNoOver,
double lowOrHigh,
double highOrLow) {
431 return nbinsNoOver / std::abs(highOrLow - lowOrHigh);
443 double high,
bool canGrow) noexcept:
454 explicit TAxisEquidistant(
int nbinsNoOver,
double low,
double high,
bool canGrow) noexcept:
480 double high) noexcept:
495 static bool CanGrow() noexcept {
return false; }
539 return lhs.GetNBins() == rhs.GetNBins()
540 && lhs.GetMinimum() == rhs.GetMinimum()
541 && lhs.GetInverseBinWidth() == rhs.GetInverseBinWidth();
561 double high) noexcept:
637 #ifdef R__DO_RANGE_CHECKS
640 #endif // R__DO_RANGE_CHECKS
649 #ifdef R__DO_RANGE_CHECKS
652 #endif // R__DO_RANGE_CHECKS
657 explicit TAxisIrregular(std::string_view title,
const std::vector<double> &binborders):
659 #ifdef R__DO_RANGE_CHECKS
662 #endif // R__DO_RANGE_CHECKS
669 explicit TAxisIrregular(std::string_view title, std::vector<double> &&binborders) noexcept:
671 #ifdef R__DO_RANGE_CHECKS
674 #endif // R__DO_RANGE_CHECKS
686 auto iNotLess = std::lower_bound(bBegin, bEnd,
x);
687 int rawbin = iNotLess - bBegin;
706 return std::numeric_limits<double>::min();
708 return std::numeric_limits<double>::max();
719 return std::numeric_limits<double>::min();
732 return std::numeric_limits<double>::max();
737 static bool CanGrow() noexcept {
return false; }
768 explicit TAxisLabels(std::string_view title,
const std::vector<std::string_view> &labels):
769 TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size())) {
770 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
775 explicit TAxisLabels(std::string_view title,
const std::vector<std::string> &labels):
776 TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size())) {
777 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
782 explicit TAxisLabels(
const std::vector<std::string_view> &labels):
792 if (insertResult.second) {
795 insertResult.first->second = idx;
798 return insertResult.first->second;
808 std::vector <std::string_view> vec(
fLabelsIndex.size());
810 vec.at(kv.second) = kv.first;
820 template<TAxisConfig::EKind>
829 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
838 return TAxisGrow(cfg.GetTitle(), cfg.GetNBinsNoOver(),
839 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
949 TAxisEquidistant &source) noexcept;
TAxisView(const TAxisEquidistant &equi)
Construct a view on a TAxisEquidistant, TAxisGrow or TAxisLabel.
TAxisBase(std::string_view title, int nbinsNoOver, bool canGrow) noexcept
Construct a TAxisBase.
TAxisConfig(std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders.
const_iterator operator+(int d) noexcept
TAxisLabels(std::string_view title, const std::vector< std::string > &labels)
Construct a TAxisLables from a vector of strings, with title.
TAxisBase & operator=(const TAxisBase &)=default
const_iterator begin() const noexcept
Get a const_iterator pointing to the first non-underflow bin.
double GetMinimum() const noexcept
Get the low end of the axis range.
double GetBinCenter(int i) const noexcept
Get the bin center of bin index i. Forwards to the underlying axis.
TAxisConfig(const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders.
const_iterator operator++(int) noexcept
i++
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
double GetBinTo(int bin) const noexcept
Get the higher bin border for a given bin index.
TAxisLabels(const std::vector< std::string > &labels)
Construct a TAxisLables from a vector of strings.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
Axis_t operator()(const TAxisConfig &cfg)
const_iterator & operator--() noexcept
–i
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
TAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a TAxisEquidistant.
bool CanGrow() const
This axis kind can increase its range.
double GetBinTo(int bin) const noexcept
Get the high bin border for the given bin index.
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
const TAxisIrregular * GetAsIrregular() const
Get the axis as a TAxisIrregular; returns nullptr if it's a TAxisEquidistant.
Common view on a TAxis, no matter what its kind.
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
Axis with equidistant bin borders.
double GetBinFrom(int bin) const noexcept
Get the lower bin border for a given bin index.
TAxisConfig(Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to.
double GetFrom() const
Get the lower axis limit.
EFindStatus
Status of FindBin(x)
std::vector< double > fBinBorders
Bin borders of the TAxisIrregular.
const int * operator*() const noexcept
int FindBin(double x) const noexcept
Find the bin index corresponding to coordinate x.
const_iterator end_with_overflow() const noexcept
Get a const_iterator pointing right beyond the overflow bin.
const TAxisEquidistant * GetAsEquidistant() const
Get the axis as a TAxisEquidistant; returns nullptr if it's a TAxisIrregular.
The bins of the source axis have finer granularity, but the bin borders are compatible.
TAxisEquidistant()=default
std::vector< double > fBinBorders
Bin borders, one more than the number of non-overflow bins.
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
double GetBinFrom(int i) const noexcept
Get the minimal coordinate of bin index i. Forwards to the underlying axis.
int AdjustOverflowBinNumber(int rawbin) const
Given rawbin (<0 for underflow, >= GetNBinsNoOver() for overflow), determine the actual bin number ta...
double GetTo() const
Get the upper axis limit.
represents a TAxisEquidistant
const_iterator begin_with_underflow() const noexcept
Get a const_iterator pointing the underflow bin.
int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin.
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
TAxisEquidistant(int nbinsNoOver, double low, double high) noexcept
Initialize a TAxisEquidistant.
An axis that can extend its range, keeping the number of its bins unchanged.
EAxisCompatibility CanMap(TAxisEquidistant &target, TAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
double GetBinFrom(int bin) const noexcept
Get the low bin border for the given bin index.
TAxisConfig(const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels.
bool operator>=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i >= j
TAxisIrregular(std::string_view title, std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
double GetBinCenter(const std::string &label)
Get the center of the bin with label.
friend bool operator>(const_iterator lhs, const_iterator rhs) noexcept
i > j
TAxisBase(int nbinsNoOver, bool canGrow) noexcept
Construct a TAxisBase.
bool operator<(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i < j
const std::string & GetTitle() const
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
EKind fKind
The kind of axis represented by this configuration.
TAxisConfig(std::string_view title, int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to, and axis title.
const TAxisEquidistant * fEqui
View on a TAxisEquidistant, TAxisGrow or TAxisLabel.
Objects used to configure the different axis types.
unsigned int fNBins
Number of bins including under- and overflow.
TAxisConfig(std::string_view title, const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders and title.
TAxisGrow(std::string_view title, int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
Random const_iterator through bins.
const TAxisIrregular * fIrr
View on a TAxisIrregular.
TAxisIrregular(std::string_view title, const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
double GetBinCenter(int bin) const noexcept
Get the bin center for the given bin index.
int Grow(int toBin)
Grow this axis to make the "virtual bin" toBin in-range.
friend bool operator<=(const_iterator lhs, const_iterator rhs) noexcept
i <= j
TAxisConfig(int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to.
friend bool operator>=(const_iterator lhs, const_iterator rhs) noexcept
i >= j
int GetNOverflowBins() const noexcept
Get the number of over- and underflow bins: 0 for growable axes, 2 otherwise.
const_iterator & operator++() noexcept
++i
const_iterator operator--(int) noexcept
represents a TAxisIrregular
Axis_t operator()(const TAxisConfig &cfg)
TAxisConfig(std::string_view title, int nbins, double from, double to, EKind kind)
Represents a TAxisEquidistant with nbins from from to to, and axis title.
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
int GetBinIndex(const std::string &label)
Get the bin index with label.
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
double fInvBinWidth
The inverse of the bin width.
static constexpr const int kIgnoreBin
FindBin() returns this bin to signal that the bin number is invalid.
TAxisConfig(std::vector< std::string > &&labels)
Represents a TAxisLabels with labels.
double fLow
The lower limit of the axis.
const std::string & GetTitle() const
bool operator==(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i == j
int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
int GetOverflowBin() const noexcept
Get the bin index for the underflow bin (or the next bin outside range if CanGrow()).
bool operator>(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i > j
The returned bin index is valid.
TAxisEquidistant(int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a TAxisEquidistant.
int GetBinIndexForLowEdge(double x) const noexcept
If the coordinate x is a bin low edge (within 1E-6 of the coordinate), return the bin for which this ...
TAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders and title.
std::string fTitle
Title of this axis, used for graphics / text.
TAxisGrow(int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
const_iterator operator-(int d) noexcept
An axis with non-equidistant bins (also known as "variable binning").
TAxisView(const TAxisIrregular &irr)
Construct a view on a TAxisIrregular.
int operator->() const noexcept
bool IsUnderflowBin(int bin) const noexcept
Whether the bin index is referencing a bin lower than the axis range.
bool operator!=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i != j
TAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high) noexcept
Initialize a TAxisEquidistant.
TAxisBase()
Default construct a TAxisBase (for use by derived classes for I/O)
double GetBinTo(int i) const noexcept
Get the maximal coordinate of bin index i. Forwards to the underlying axis.
friend bool operator<(const_iterator lhs, const_iterator rhs) noexcept
i < j
static bool CanGrow() noexcept
This axis cannot be extended.
EKind GetKind() const noexcept
Get the axis kind represented by this TAxisConfig.
static double GetInvBinWidth(int nbinsNoOver, double lowOrHigh, double highOrLow)
Determine the inverse bin width.
The source is a subset of bins of the target axis.
TAxisLabels(const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views.
const_iterator(int cursor) noexcept
Initialize a const_iterator with its position.
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
friend bool operator!=(const_iterator lhs, const_iterator rhs) noexcept
i != j
Converts a TAxisConfig of whatever kind to the corresponding TAxisBase-derived object.
double GetBinWidth() const noexcept
Get the width of the bins.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
double GetBinCenter(int bin) const noexcept
Get the bin center of the bin with the given index.
TAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
Histogram axis base class.
TAxisConfig(std::string_view title, std::vector< std::string > &&labels)
Represents a TAxisLabels with labels and title.
int fCursor
Current iteration position.
const_iterator & operator-=(int d) noexcept
TAxisConfig(std::string_view title, Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to, and axis title.
A TAxisGrow that has a label assigned to each bin and a bin width of 1.
Source and target axes are identical.
int GetNBins() const noexcept
Get the number of bins. Forwards to the underlying axis.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
friend bool operator==(const_iterator lhs, const_iterator rhs) noexcept
i == j
Axis_t operator()(const TAxisConfig &cfg) noexcept
The source axis and target axis have different binning.
Coordinate could fit after growing the axis.
bool IsOverflowBin(int bin) const noexcept
Whether the bin index is referencing a bin higher than the axis range.
const bool fCanGrow
Whether this axis can grow (and thus has no overflow bins).
static bool CanGrow() noexcept
This axis cannot grow.
double GetMaximum() const noexcept
Get the high end of the axis range.
int FindBin(double x) const noexcept
Find the bin index for the given coordinate.
TAxisIrregular(const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
TAxisLabels(std::string_view title, const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views, with title.
const_iterator & operator+=(int d) noexcept
#define R__ERROR_HERE(GROUP)
std::vector< std::string > fLabels
Bin labels for a TAxisLabels.
bool operator<=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i <= j
Axis_t operator()(const TAxisConfig &cfg) noexcept
TAxisConfig(std::string_view title, const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels and title.