File indexing completed on 2025-02-23 09:14:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Utilities/Axis.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013 #include "Acts/Utilities/Grid.hpp"
0014 #include "Acts/Utilities/IAxis.hpp"
0015
0016 namespace Acts {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 class ProtoAxis {
0028 public:
0029
0030
0031
0032
0033
0034 ProtoAxis(AxisDirection aDir, Acts::AxisBoundaryType abType,
0035 const std::vector<double>& edges);
0036
0037
0038
0039
0040
0041
0042
0043
0044 ProtoAxis(AxisDirection aDir, AxisBoundaryType abType, double minE,
0045 double maxE, std::size_t nbins);
0046
0047
0048
0049
0050
0051
0052
0053
0054 ProtoAxis(AxisDirection aDir, AxisBoundaryType abType, std::size_t nbins);
0055
0056 ProtoAxis(const ProtoAxis&) = delete;
0057 ProtoAxis& operator=(const ProtoAxis&) = delete;
0058 ProtoAxis(ProtoAxis&&) = default;
0059 ProtoAxis& operator=(ProtoAxis&&) = default;
0060
0061
0062
0063
0064 AxisDirection getAxisDirection() const;
0065
0066
0067
0068
0069 const IAxis& getAxis() const;
0070
0071
0072
0073
0074
0075
0076
0077
0078 void setRange(double minE, double maxE);
0079
0080
0081 bool isAutorange() const;
0082
0083
0084
0085 std::string toString() const;
0086
0087 private:
0088
0089
0090 void toStream(std::ostream& os) const;
0091
0092
0093 AxisDirection m_axisDir = AxisDirection::AxisX;
0094
0095
0096 std::unique_ptr<IAxis> m_axis = nullptr;
0097
0098
0099 bool m_autorange = false;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108
0109 template <typename payload_t>
0110 std::unique_ptr<IGrid> makeGrid(const ProtoAxis& a) {
0111 if (a.isAutorange()) {
0112 throw std::invalid_argument(
0113 "ProtoAxis::makeGrid: Auto-range of the proto axis is not (yet) "
0114 "resolved, call setRange() first.");
0115 }
0116
0117 return a.getAxis().visit(
0118 [&]<typename AxisTypeA>(const AxisTypeA& axis) -> std::unique_ptr<IGrid> {
0119 using GridType = Grid<payload_t, AxisTypeA>;
0120 return std::make_unique<GridType>(axis);
0121 });
0122 }
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 template <typename payload_t>
0133 std::unique_ptr<IGrid> makeGrid(const ProtoAxis& a, const ProtoAxis& b) {
0134
0135 if (a.getAxisDirection() == b.getAxisDirection()) {
0136 throw std::invalid_argument(
0137 "ProtoAxis::makeGrid: Axes must have different directions");
0138 }
0139
0140 if (a.isAutorange() || b.isAutorange()) {
0141 throw std::invalid_argument(
0142 "ProtoAxis::makeGrid: Auto-range of the proto axis is not (yet) "
0143 "resolved, call setRange() first.");
0144 }
0145
0146 return a.getAxis().visit([&]<typename AxisTypeA>(const AxisTypeA& axisA)
0147 -> std::unique_ptr<IGrid> {
0148 return b.getAxis().visit([&]<typename AxisTypeB>(const AxisTypeB& axisB)
0149 -> std::unique_ptr<IGrid> {
0150 using GridType = Grid<payload_t, AxisTypeA, AxisTypeB>;
0151 return std::make_unique<GridType>(axisA, axisB);
0152 });
0153 });
0154 }
0155
0156 }