Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:47:21

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/TrackParameters.hpp"
0012 #include "Acts/Utilities/Delegate.hpp"
0013 #include "Acts/Vertexing/LinearizedTrack.hpp"
0014 
0015 #include <any>
0016 #include <functional>
0017 #include <typeindex>
0018 
0019 namespace Acts {
0020 
0021 /// Type-erased wrapper around an input track pointer.
0022 struct InputTrack {
0023   /// Construct from input track pointer
0024   /// @param inputTrack Pointer to the input track
0025   template <typename input_track_t>
0026   explicit InputTrack(const input_track_t* inputTrack)
0027       : m_type{typeid(inputTrack)}, m_ptr{inputTrack} {}
0028 
0029   InputTrack() = delete;
0030   /// Copy constructor
0031   InputTrack(const InputTrack&) = default;
0032   /// Move constructor
0033   InputTrack(InputTrack&&) = default;
0034   /// Copy assignment
0035   /// @return Reference to this object
0036   InputTrack& operator=(const InputTrack&) = default;
0037   /// Move assignment
0038   /// @return Reference to this object
0039   InputTrack& operator=(InputTrack&&) = default;
0040 
0041   /// Equality comparison with another InputTrack
0042   /// @param other The other InputTrack to compare with
0043   /// @return True if equal
0044   bool operator==(const InputTrack& other) const {
0045     return m_ptr == other.m_ptr;
0046   }
0047 
0048   /// Equality comparison with a raw pointer
0049   /// @param other The pointer to compare with
0050   /// @return True if equal
0051   template <typename input_track_t>
0052   bool operator==(const input_track_t* other) const {
0053     return m_ptr == other;
0054   }
0055 
0056   /// Comparison operator for ordering
0057   /// @param other The other InputTrack to compare with
0058   /// @return True if this is less than other
0059   bool operator<(const InputTrack& other) const { return m_ptr < other.m_ptr; }
0060 
0061   /// Cast to the original pointer type
0062   /// @return Pointer to the original track object
0063   template <typename T>
0064   const T* as() const {
0065     using ptr_t = const T*;
0066     if (m_type != typeid(ptr_t)) {
0067       throw std::bad_any_cast();
0068     }
0069     return static_cast<ptr_t>(m_ptr);
0070   }
0071 
0072   friend std::ostream& operator<<(std::ostream& os, const InputTrack& track) {
0073     os << track.m_ptr;
0074     return os;
0075   }
0076 
0077   friend struct std::hash<Acts::InputTrack>;
0078 
0079   /// Extract track parameters from an InputTrack
0080   /// @param track The input track
0081   /// @return The bound track parameters
0082   static BoundTrackParameters extractParameters(const InputTrack& track) {
0083     return *track.as<BoundTrackParameters>();
0084   }
0085 
0086   /// Function type for extracting track parameters
0087   using Extractor = Acts::Delegate<BoundTrackParameters(const InputTrack&)>;
0088 
0089  private:
0090   std::type_index m_type;
0091   const void* m_ptr;
0092 };
0093 
0094 /// @class TrackAtVertex
0095 ///
0096 /// @brief Defines a track at vertex object
0097 struct TrackAtVertex {
0098   /// Deleted default constructor
0099   TrackAtVertex() = delete;
0100 
0101   /// @brief Parameterized constructor
0102   ///
0103   /// @param chi2perTrack Chi2 of track
0104   /// @param paramsAtVertex Fitted perigee parameter
0105   /// @param originalTrack Original perigee parameter
0106   TrackAtVertex(double chi2perTrack, const BoundTrackParameters& paramsAtVertex,
0107                 InputTrack originalTrack)
0108       : fittedParams(paramsAtVertex),
0109         originalParams(originalTrack),
0110         chi2Track(chi2perTrack) {}
0111 
0112   /// @brief Constructor with default chi2
0113   ///
0114   /// @param paramsAtVertex Fitted perigee parameter
0115   /// @param originalTrack Original perigee parameter
0116   TrackAtVertex(const BoundTrackParameters& paramsAtVertex,
0117                 InputTrack originalTrack)
0118       : fittedParams(paramsAtVertex), originalParams(originalTrack) {}
0119 
0120   /// Fitted perigee
0121   BoundTrackParameters fittedParams;
0122 
0123   /// Original input parameters
0124   InputTrack originalParams;
0125 
0126   /// Chi2 of track
0127   double chi2Track = 0;
0128 
0129   /// Number degrees of freedom
0130   /// Note: Can be different from integer value
0131   /// since annealing can result in effective
0132   /// non-interger values
0133   double ndf = 0;
0134 
0135   /// Value of the compatibility of the track to the actual vertex, based
0136   /// on the estimation of the 3d distance between the track and the vertex
0137   double vertexCompatibility = 0;
0138 
0139   /// Weight of track in fit
0140   double trackWeight = 1;
0141 
0142   /// The linearized state of the track at vertex
0143   LinearizedTrack linearizedState;
0144 
0145   /// Is already linearized
0146   bool isLinearized = false;
0147 };
0148 
0149 }  // namespace Acts
0150 
0151 template <>
0152 struct std::hash<Acts::InputTrack> {
0153   std::size_t operator()(const Acts::InputTrack& track) const noexcept {
0154     return std::hash<const void*>{}(track.m_ptr);
0155   }
0156 };