21 #include <unordered_map> 28 namespace Experimental {
73 if (rawbin < 0)
return 0;
90 public std::iterator<std::random_access_iterator_tag,
92 const int * , const int & > {
156 const int *
operator*() const noexcept {
return &fCursor; }
267 return lhs.fCursor < rhs.fCursor;
273 return lhs.fCursor > rhs.fCursor;
279 return lhs.fCursor <= rhs.fCursor;
285 return lhs.fCursor >= rhs.fCursor;
291 return lhs.fCursor == rhs.fCursor;
297 return lhs.fCursor != rhs.fCursor;
311 double fInvBinWidth = 0.;
317 static double GetInvBinWidth(
int nbinsNoOver,
double lowOrHigh,
double highOrLow) {
318 return nbinsNoOver / std::abs(highOrLow - lowOrHigh);
328 explicit TAxisEquidistant(
int nbinsNoOver,
double low,
double high,
bool canGrow) noexcept:
329 TAxisBase(nbinsNoOver, canGrow), fLow(std::min(low, high)),
330 fInvBinWidth(GetInvBinWidth(nbinsNoOver, low, high)) { }
341 double high,
bool canGrow) noexcept:
342 TAxisBase(title, nbinsNoOver, canGrow), fLow(low),
343 fInvBinWidth(GetInvBinWidth(nbinsNoOver, low, high)) { }
368 double high) noexcept:
375 int rawbin = (
x - fLow) * fInvBinWidth;
380 static bool CanGrow() noexcept {
return false; }
400 return fLow + (bin - 0.5) / fInvBinWidth;
407 return fLow + (bin - 1) / fInvBinWidth;
414 return GetBinFrom(bin + 1);
417 int GetBinIndexForLowEdge(
double x)
const noexcept;
424 return lhs.GetNBins() == rhs.GetNBins()
425 && lhs.GetMinimum() == rhs.GetMinimum()
426 && lhs.GetInverseBinWidth() == rhs.GetInverseBinWidth();
446 double high) noexcept:
516 TAxisBase(binborders.size() - 1, CanGrow()), fBinBorders(binborders) {
517 #ifdef R__DO_RANGE_CHECKS 518 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
520 #endif // R__DO_RANGE_CHECKS 528 TAxisBase(binborders.size() - 1, CanGrow()), fBinBorders(std::move(binborders)) {
529 #ifdef R__DO_RANGE_CHECKS 530 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
532 #endif // R__DO_RANGE_CHECKS 538 TAxisBase(title, binborders.size() - 1, CanGrow()), fBinBorders(binborders) {
539 #ifdef R__DO_RANGE_CHECKS 540 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
542 #endif // R__DO_RANGE_CHECKS 550 TAxisBase(title, binborders.size() - 1, CanGrow()), fBinBorders(std::move(binborders)) {
551 #ifdef R__DO_RANGE_CHECKS 552 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
554 #endif // R__DO_RANGE_CHECKS 561 const auto bBegin = fBinBorders.begin();
562 const auto bEnd = fBinBorders.end();
563 auto iNotLess = std::lower_bound(bBegin, bEnd,
x);
564 int rawbin = iNotLess - bBegin;
583 return std::numeric_limits<double>::min();
585 return std::numeric_limits<double>::max();
586 return 0.5 * (fBinBorders[bin - 1] + fBinBorders[bin]);
596 return std::numeric_limits<double>::min();
599 return fBinBorders[bin - 1];
609 return std::numeric_limits<double>::max();
610 return GetBinFrom(bin + 1);
614 static bool CanGrow() noexcept {
return false; }
617 const std::vector<double> &
GetBinBorders() const noexcept {
return fBinBorders; }
645 explicit TAxisLabels(
const std::vector<std::string_view> &labels):
646 TAxisGrow(labels.size(), 0., static_cast<double>(labels.size())) {
647 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
648 fLabelsIndex[std::string(labels[i])] = i;
653 TAxisGrow(labels.size(), 0., static_cast<double>(labels.size())) {
654 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
655 fLabelsIndex[labels[i]] = i;
660 TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size())) {
661 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
662 fLabelsIndex[std::string(labels[i])] = i;
667 TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size())) {
668 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
669 fLabelsIndex[labels[i]] = i;
674 auto insertResult = fLabelsIndex.insert({label, -1});
675 if (insertResult.second) {
677 int idx = fLabelsIndex.size() - 1;
678 insertResult.first->second = idx;
681 return insertResult.first->second;
686 return GetBinIndex(label) - 0.5;
691 std::vector <std::string_view> vec(fLabelsIndex.size());
692 for (
const auto &kv: fLabelsIndex)
693 vec.at(kv.second) = kv.first;
725 TAxisBase(title, nbins, kind == kGrow), fKind(kind), fBinBorders(2)
730 fBinBorders[0] = from;
747 TAxisConfig(title, nbins, from, to, kEquidistant) {}
764 TAxisBase(binborders.size() - 1, false ), fKind(kIrregular),
765 fBinBorders(binborders) { }
769 TAxisBase(title, binborders.size() - 1, false ), fKind(kIrregular),
770 fBinBorders(binborders) { }
774 TAxisBase(binborders.size() - 1,
false ), fKind(kIrregular),
775 fBinBorders(std::move(binborders)) { }
779 TAxisBase(title, binborders.size() - 1,
false ), fKind(kIrregular),
780 fBinBorders(std::move(binborders)) { }
786 fLabels(labels.
begin(), labels.
end()) { }
792 fLabels(labels.
begin(), labels.
end()) { }
798 fLabels(labels.
begin(), labels.
end()) { }
804 fLabels(labels.
begin(), labels.
end()) { }
821 TAxisBase(ax), fKind(kIrregular), fBinBorders(ax.GetBinBorders()) { }
827 for (
auto &&lab: labels)
828 fLabels.emplace_back(std::string(lab));
836 const std::vector<double> &
GetBinBorders() const noexcept {
return fBinBorders; }
839 const std::vector <std::string> &
GetBinLabels() const noexcept {
return fLabels; }
847 template<TAxisConfig::EKind>
856 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
865 return TAxisGrow(cfg.GetTitle(), cfg.GetNBinsNoOver(),
866 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
925 double GetFrom()
const {
return GetBinFrom(1); }
double GetFrom() const
Get the lower axis limit.
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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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.
TAxisConfig(const TAxisEquidistant &ax)
Build a TAxisConfig from a TAxisEquidistant.
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
TAxisConfig(const TAxisLabels &ax)
Build a TAxisConfig from a TAxisLabels.
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.
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.
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.
double GetTo() const
Get the upper axis limit.
TAxisConfig(Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to.
EFindStatus
Status of FindBin(x)
std::vector< double > fBinBorders
Bin borders of the TAxisIrregular.
const int * operator*() const noexcept
int AdjustOverflowBinNumber(int rawbin) const
Given rawbin (<0 for underflow, >= GetNBinsNoOver() for overflow), determine the actual bin number ta...
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.
The bins of the source axis have finer granularity, but the bin borders are compatible.
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.
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.
const TAxisIrregular * GetAsIrregular() const
Get the axis as a TAxisIrregular; returns nullptr if it's a TAxisEquidistant.
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.
TAxisBase(int nbinsNoOver, bool canGrow) noexcept
Construct a TAxisBase.
bool operator<(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i < j
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.
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.
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.
TAxisConfig(int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to.
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.
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...
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.
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()).
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
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.
TAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders.
std::string fTitle
Title of this axis, used for graphics / text.
TAxisGrow(int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
bool CanGrow() const
This axis kind can increase its range.
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.
const TAxisEquidistant * GetAsEquidistant() const
Get the axis as a TAxisEquidistant; returns nullptr if it's a TAxisIrregular.
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.
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.
TAxisConfig(const TAxisIrregular &ax)
Build a TAxisConfig from a TAxisIrregular.
const std::string & GetTitle() const
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
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.
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.
Axis_t operator()(const TAxisConfig &cfg) noexcept
The source axis and target axis have different binning.
Coordinate could fit after growing the axis.
TAxisConfig(const TAxisGrow &ax)
Build a TAxisConfig from a TAxisGrow.
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.
const std::string & GetTitle() const
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.