File indexing completed on 2025-01-18 09:11:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013
0014 #include <iosfwd>
0015 #include <vector>
0016
0017 namespace Acts {
0018
0019
0020
0021 class IAxis {
0022 public:
0023
0024
0025
0026 virtual bool isEquidistant() const = 0;
0027
0028
0029
0030
0031 virtual bool isVariable() const = 0;
0032
0033
0034
0035 virtual AxisType getType() const = 0;
0036
0037
0038
0039
0040 virtual AxisBoundaryType getBoundaryType() const = 0;
0041
0042
0043
0044 virtual std::vector<double> getBinEdges() const = 0;
0045
0046
0047
0048
0049 virtual double getMin() const = 0;
0050
0051
0052
0053
0054 virtual double getMax() const = 0;
0055
0056
0057
0058
0059 virtual std::size_t getNBins() const = 0;
0060
0061
0062
0063
0064
0065
0066
0067 template <typename callable_t>
0068 decltype(auto) visit(const callable_t& callable) const {
0069 auto switchOnType =
0070 [this, &callable]<AxisBoundaryType bdt>(AxisBoundaryTypeTag<bdt>) {
0071 switch (getType()) {
0072 using enum AxisType;
0073 case Equidistant:
0074 return callable(
0075 dynamic_cast<const Axis<AxisType::Equidistant, bdt>&>(*this));
0076 case Variable:
0077 return callable(
0078 dynamic_cast<const Axis<AxisType::Variable, bdt>&>(*this));
0079 default:
0080 throw std::logic_error("Unknown axis type");
0081 }
0082 };
0083
0084 switch (getBoundaryType()) {
0085 using enum AxisBoundaryType;
0086 case Open:
0087 return switchOnType(AxisOpen);
0088 case Bound:
0089 return switchOnType(AxisBound);
0090 case Closed:
0091 return switchOnType(AxisClosed);
0092 default:
0093 throw std::logic_error("Unknown axis type");
0094 }
0095 }
0096
0097
0098
0099
0100
0101 friend bool operator==(const IAxis& lhs, const IAxis& rhs) {
0102 return lhs.getType() == rhs.getType() &&
0103 lhs.getBoundaryType() == rhs.getBoundaryType() &&
0104 lhs.getMin() == rhs.getMin() && lhs.getMax() == rhs.getMax() &&
0105 lhs.getNBins() == rhs.getNBins() &&
0106 lhs.getBinEdges() == rhs.getBinEdges();
0107 }
0108
0109
0110
0111
0112
0113 friend std::ostream& operator<<(std::ostream& os, const IAxis& axis) {
0114 axis.toStream(os);
0115 return os;
0116 }
0117
0118 protected:
0119
0120
0121 virtual void toStream(std::ostream& os) const = 0;
0122 };
0123
0124 template <typename T>
0125 concept AxisConcept = std::derived_from<T, IAxis>;
0126
0127 }