File indexing completed on 2025-07-13 07:50:26
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 <memory>
0016 #include <vector>
0017
0018 namespace Acts {
0019
0020
0021
0022 class IAxis {
0023 public:
0024
0025 virtual ~IAxis() = default;
0026
0027
0028
0029
0030 virtual bool isEquidistant() const = 0;
0031
0032
0033
0034
0035 virtual bool isVariable() const = 0;
0036
0037
0038
0039 virtual AxisType getType() const = 0;
0040
0041
0042
0043
0044 virtual AxisBoundaryType getBoundaryType() const = 0;
0045
0046
0047
0048 virtual std::vector<double> getBinEdges() const = 0;
0049
0050
0051
0052
0053 virtual double getMin() const = 0;
0054
0055
0056
0057
0058 virtual double getMax() const = 0;
0059
0060
0061
0062
0063 virtual std::size_t getNBins() const = 0;
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 static std::unique_ptr<IAxis> createEquidistant(
0076 AxisBoundaryType aBoundaryType, double min, double max,
0077 std::size_t nbins);
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 static std::unique_ptr<IAxis> createVariable(
0088 AxisBoundaryType aBoundaryType, const std::vector<double>& edges);
0089
0090
0091
0092
0093
0094
0095
0096 template <typename callable_t>
0097 decltype(auto) visit(const callable_t& callable) const {
0098 auto switchOnType =
0099 [this, &callable]<AxisBoundaryType bdt>(AxisBoundaryTypeTag<bdt>) {
0100 switch (getType()) {
0101 using enum AxisType;
0102 case Equidistant:
0103 return callable(
0104 dynamic_cast<const Axis<AxisType::Equidistant, bdt>&>(*this));
0105 case Variable:
0106 return callable(
0107 dynamic_cast<const Axis<AxisType::Variable, bdt>&>(*this));
0108 default:
0109 throw std::logic_error("Unknown axis type");
0110 }
0111 };
0112
0113 switch (getBoundaryType()) {
0114 using enum AxisBoundaryType;
0115 case Open:
0116 return switchOnType(AxisOpen);
0117 case Bound:
0118 return switchOnType(AxisBound);
0119 case Closed:
0120 return switchOnType(AxisClosed);
0121 default:
0122 throw std::logic_error("Unknown axis type");
0123 }
0124 }
0125
0126
0127
0128
0129
0130 friend bool operator==(const IAxis& lhs, const IAxis& rhs) {
0131 return lhs.getType() == rhs.getType() &&
0132 lhs.getBoundaryType() == rhs.getBoundaryType() &&
0133 lhs.getMin() == rhs.getMin() && lhs.getMax() == rhs.getMax() &&
0134 lhs.getNBins() == rhs.getNBins() &&
0135 lhs.getBinEdges() == rhs.getBinEdges();
0136 }
0137
0138
0139
0140
0141
0142 friend std::ostream& operator<<(std::ostream& os, const IAxis& axis) {
0143 axis.toStream(os);
0144 return os;
0145 }
0146
0147 protected:
0148
0149
0150 virtual void toStream(std::ostream& os) const = 0;
0151 };
0152
0153 template <typename T>
0154 concept AxisConcept = std::derived_from<T, IAxis>;
0155
0156 }