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