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