File indexing completed on 2025-01-19 09:23:22
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
0044
0045 switch (m_binningValue) {
0046
0047 case binX: {
0048 return one.x() < two.x();
0049 }
0050
0051 case binY: {
0052 return one.y() < two.y();
0053 }
0054
0055 case binZ: {
0056 return one.z() < two.z();
0057 }
0058
0059 case binR: {
0060 return perp(one) < perp(two);
0061 }
0062
0063 case binPhi: {
0064 return phi(one) < phi(two);
0065 }
0066
0067 case binEta: {
0068 return eta(one) < eta(two);
0069 }
0070
0071 default: {
0072 return one.norm() < two.norm();
0073 }
0074 }
0075 }
0076
0077 BinningValue binningValue() const { return m_binningValue; }
0078
0079 private:
0080 BinningValue m_binningValue;
0081 };
0082
0083
0084 template <class T>
0085 class DistanceSorterT {
0086 public:
0087
0088
0089
0090
0091 DistanceSorterT(BinningValue bValue, Vector3 reference)
0092 : m_binningValue(bValue),
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_binningValue) {
0111
0112 case binX: {
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 binY: {
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 binZ: {
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 binR: {
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 binPhi: {
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 binEta: {
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 BinningValue m_binningValue;
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, BinningValue bValue,
0173 std::shared_ptr<const Transform3> transform = nullptr)
0174 : m_context(gctx),
0175 m_objectSorter(bValue),
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 =
0187 m_transform
0188 ? m_transform->inverse() *
0189 one->binningPosition(m_context, m_objectSorter.binningValue())
0190 : one->binningPosition(m_context, m_objectSorter.binningValue());
0191 Vector3 posTwo =
0192 m_transform
0193 ? m_transform->inverse() *
0194 two->binningPosition(m_context, m_objectSorter.binningValue())
0195 : two->binningPosition(m_context, m_objectSorter.binningValue());
0196
0197 return m_objectSorter.operator()(posOne, posTwo);
0198 }
0199
0200 protected:
0201 std::reference_wrapper<const GeometryContext> m_context;
0202 ObjectSorterT<Vector3> m_objectSorter;
0203 std::shared_ptr<const Transform3> m_transform;
0204 };
0205 }