File indexing completed on 2025-09-15 08:13:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014 #include "Acts/Utilities/VectorHelpers.hpp"
0015
0016 #include <functional>
0017 #include <memory>
0018
0019 namespace Acts {
0020
0021 template <class T>
0022 class ObjectSorterT {
0023 public:
0024
0025
0026
0027 explicit ObjectSorterT(AxisDirection aDir) : m_sortingDirection(aDir) {}
0028
0029
0030
0031
0032
0033
0034
0035 bool operator()(T one, T two) const {
0036 using VectorHelpers::eta;
0037 using VectorHelpers::perp;
0038 using VectorHelpers::phi;
0039 using enum AxisDirection;
0040 switch (m_sortingDirection) {
0041
0042 case AxisX: {
0043 return one.x() < two.x();
0044 }
0045
0046 case AxisY: {
0047 return one.y() < two.y();
0048 }
0049
0050 case AxisZ: {
0051 return one.z() < two.z();
0052 }
0053
0054 case AxisR: {
0055 return perp(one) < perp(two);
0056 }
0057
0058 case AxisPhi: {
0059 return phi(one) < phi(two);
0060 }
0061
0062 case AxisEta: {
0063 return eta(one) < eta(two);
0064 }
0065
0066 default: {
0067 return one.norm() < two.norm();
0068 }
0069 }
0070 }
0071
0072 AxisDirection sortingDirection() const { return m_sortingDirection; }
0073
0074 private:
0075 AxisDirection m_sortingDirection;
0076 };
0077
0078
0079 template <class T>
0080 class DistanceSorterT {
0081 public:
0082
0083
0084
0085
0086 DistanceSorterT(AxisDirection aDir, Vector3 reference)
0087 : m_sortingDirection(aDir),
0088 m_reference(reference),
0089 m_refR(VectorHelpers::perp(reference)),
0090 m_refPhi(VectorHelpers::phi(reference)),
0091 m_refEta(VectorHelpers::eta(reference)) {}
0092
0093
0094
0095
0096
0097
0098
0099 bool operator()(T one, T two) const {
0100 using Acts::VectorHelpers::eta;
0101 using Acts::VectorHelpers::perp;
0102 using Acts::VectorHelpers::phi;
0103
0104
0105 switch (m_sortingDirection) {
0106
0107 case AxisDirection::AxisX: {
0108 double diffOneX = one.x() - m_reference.x();
0109 double diffTwoX = two.x() - m_reference.x();
0110 return std::abs(diffOneX) < std::abs(diffTwoX);
0111 }
0112
0113 case AxisDirection::AxisY: {
0114 double diffOneY = one.y() - m_reference.y();
0115 double diffTwoY = two.y() - m_reference.y();
0116 return std::abs(diffOneY) < std::abs(diffTwoY);
0117 }
0118
0119 case AxisDirection::AxisZ: {
0120 double diffOneZ = one.z() - m_reference.z();
0121 double diffTwoZ = two.z() - m_reference.z();
0122 return std::abs(diffOneZ) < std::abs(diffTwoZ);
0123 }
0124
0125 case AxisDirection::AxisR: {
0126 double diffOneR = perp(one) - m_refR;
0127 double diffTwoR = perp(two) - m_refR;
0128 return std::abs(diffOneR) < std::abs(diffTwoR);
0129 }
0130
0131 case AxisDirection::AxisPhi: {
0132 double diffOnePhi = phi(one) - m_refPhi;
0133 double diffTwoPhi = phi(two) - m_refPhi;
0134 return std::abs(diffOnePhi) < std::abs(diffTwoPhi);
0135 }
0136
0137 case AxisDirection::AxisEta: {
0138 double diffOneEta = eta(one) - m_refEta;
0139 double diffTwoEta = eta(two) - m_refEta;
0140 return std::abs(diffOneEta) < std::abs(diffTwoEta);
0141 }
0142
0143 default: {
0144 T diffOne(one - m_reference);
0145 T diffTwo(two - m_reference);
0146 return diffOne.mag2() < diffTwo.mag2();
0147 }
0148 }
0149 }
0150
0151 private:
0152 AxisDirection m_sortingDirection;
0153 T m_reference;
0154 double m_refR;
0155 double m_refPhi;
0156 double m_refEta;
0157 };
0158
0159 template <class T>
0160 class GeometryObjectSorterT {
0161 public:
0162
0163
0164
0165
0166
0167 GeometryObjectSorterT(const GeometryContext& gctx, AxisDirection aDir,
0168 std::shared_ptr<const Transform3> transform = nullptr)
0169 : m_context(gctx),
0170 m_objectSorter(aDir),
0171 m_transform(std::move(transform)) {}
0172
0173
0174
0175
0176
0177
0178
0179 bool operator()(T one, T two) const {
0180
0181 Vector3 posOne = m_transform
0182 ? m_transform->inverse() *
0183 one->referencePosition(
0184 m_context, m_objectSorter.sortingDirection())
0185 : one->referencePosition(
0186 m_context, m_objectSorter.sortingDirection());
0187 Vector3 posTwo = m_transform
0188 ? m_transform->inverse() *
0189 two->referencePosition(
0190 m_context, m_objectSorter.sortingDirection())
0191 : two->referencePosition(
0192 m_context, m_objectSorter.sortingDirection());
0193
0194 return m_objectSorter.operator()(posOne, posTwo);
0195 }
0196
0197 protected:
0198 std::reference_wrapper<const GeometryContext> m_context;
0199 ObjectSorterT<Vector3> m_objectSorter;
0200 std::shared_ptr<const Transform3> m_transform;
0201 };
0202 }