Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:22

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // clang-format off
0012 // Workaround for building on clang+libstdc++. Must always be first
0013 #include "Acts/Utilities/detail/ReferenceWrapperAnyCompat.hpp"
0014 // clang-format on
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   /// Constructor from a binning value
0029   ///
0030   /// @param bValue is the value in which the binning is done
0031   ObjectSorterT(BinningValue bValue) : m_binningValue(bValue) {}
0032 
0033   /// Comparison operator
0034   ///
0035   /// @param one first object
0036   /// @param two second object
0037   ///
0038   /// @return boolean indicator
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 the binning value
0044     // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
0045     switch (m_binningValue) {
0046       // compare on x
0047       case binX: {
0048         return one.x() < two.x();
0049       }
0050       // compare on y
0051       case binY: {
0052         return one.y() < two.y();
0053       }
0054       // compare on z
0055       case binZ: {
0056         return one.z() < two.z();
0057       }
0058       // compare on r
0059       case binR: {
0060         return perp(one) < perp(two);
0061       }
0062       // compare on phi
0063       case binPhi: {
0064         return phi(one) < phi(two);
0065       }
0066       // compare on eta
0067       case binEta: {
0068         return eta(one) < eta(two);
0069       }
0070       // default for the moment
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;  ///< the binning value
0081 };
0082 
0083 /// This will check on absolute distance
0084 template <class T>
0085 class DistanceSorterT {
0086  public:
0087   /// Constructor from a binning value
0088   ///
0089   /// @param bValue is the value in which the binning is done
0090   /// @param reference is the reference point
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   /// Comparison operator
0099   ///
0100   /// @tparam one first object
0101   /// @tparam two second object
0102   ///
0103   /// @return boolean indicator
0104   bool operator()(T one, T two) const {
0105     using Acts::VectorHelpers::eta;
0106     using Acts::VectorHelpers::perp;
0107     using Acts::VectorHelpers::phi;
0108     // switch the binning value
0109     // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
0110     switch (m_binningValue) {
0111       // compare on diff x
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       // compare on diff y
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       // compare on diff z
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       // compare on r
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       // compare on phi /// @todo add cyclic value
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       // compare on eta
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       // default for the moment
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;  ///< the binning value
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   /// Constructor from a binning value
0168   ///
0169   /// @param gctx The geometry context to use
0170   /// @param bValue is the value in which the binning is done
0171   /// @param transform is an optional transform to be performed
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   /// Comparison operator
0179   ///
0180   /// @tparam one first object
0181   /// @tparam two second object
0182   ///
0183   /// @return boolean indicator
0184   bool operator()(T one, T two) const {
0185     // get the pos one / pos two
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     // now call the distance sorter
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 }  // namespace Acts