Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:00

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 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 #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 struct InputTrack {
0022   template <typename input_track_t>
0023   explicit InputTrack(const input_track_t* inputTrack)
0024       : m_type{typeid(inputTrack)}, m_ptr{inputTrack} {}
0025 
0026   InputTrack() = delete;
0027   InputTrack(const InputTrack&) = default;
0028   InputTrack(InputTrack&&) = default;
0029   InputTrack& operator=(const InputTrack&) = default;
0030   InputTrack& operator=(InputTrack&&) = default;
0031 
0032   bool operator==(const InputTrack& other) const {
0033     return m_ptr == other.m_ptr;
0034   }
0035 
0036   template <typename input_track_t>
0037   bool operator==(const input_track_t* other) const {
0038     return m_ptr == other;
0039   }
0040 
0041   template <typename T>
0042   const T* as() const {
0043     using ptr_t = const T*;
0044     if (m_type != typeid(ptr_t)) {
0045       throw std::bad_any_cast();
0046     }
0047     return static_cast<ptr_t>(m_ptr);
0048   }
0049 
0050   friend std::ostream& operator<<(std::ostream& os, const InputTrack& track) {
0051     os << track.m_ptr;
0052     return os;
0053   }
0054 
0055   friend bool operator<(const InputTrack& lhs, const InputTrack& rhs) {
0056     return lhs.m_ptr < rhs.m_ptr;
0057   }
0058 
0059   friend struct std::hash<Acts::InputTrack>;
0060 
0061   static BoundTrackParameters extractParameters(const InputTrack& track) {
0062     return *track.as<BoundTrackParameters>();
0063   }
0064 
0065   using Extractor = Acts::Delegate<BoundTrackParameters(const InputTrack&)>;
0066 
0067  private:
0068   std::type_index m_type;
0069   const void* m_ptr;
0070 };
0071 
0072 /// @class TrackAtVertex
0073 ///
0074 /// @brief Defines a track at vertex object
0075 struct TrackAtVertex {
0076   /// Deleted default constructor
0077   TrackAtVertex() = delete;
0078 
0079   /// @brief Parameterized constructor
0080   ///
0081   /// @param chi2perTrack Chi2 of track
0082   /// @param paramsAtVertex Fitted perigee parameter
0083   /// @param originalTrack Original perigee parameter
0084   TrackAtVertex(double chi2perTrack, const BoundTrackParameters& paramsAtVertex,
0085                 InputTrack originalTrack)
0086       : fittedParams(paramsAtVertex),
0087         originalParams(originalTrack),
0088         chi2Track(chi2perTrack) {}
0089 
0090   /// @brief Constructor with default chi2
0091   ///
0092   /// @param paramsAtVertex Fitted perigee parameter
0093   /// @param originalTrack Original perigee parameter
0094   TrackAtVertex(const BoundTrackParameters& paramsAtVertex,
0095                 InputTrack originalTrack)
0096       : fittedParams(paramsAtVertex), originalParams(originalTrack) {}
0097 
0098   /// Fitted perigee
0099   BoundTrackParameters fittedParams;
0100 
0101   /// Original input parameters
0102   InputTrack originalParams;
0103 
0104   /// Chi2 of track
0105   double chi2Track = 0;
0106 
0107   /// Number degrees of freedom
0108   /// Note: Can be different from integer value
0109   /// since annealing can result in effective
0110   /// non-interger values
0111   double ndf = 0;
0112 
0113   /// Value of the compatibility of the track to the actual vertex, based
0114   /// on the estimation of the 3d distance between the track and the vertex
0115   double vertexCompatibility = 0;
0116 
0117   /// Weight of track in fit
0118   double trackWeight = 1;
0119 
0120   /// The linearized state of the track at vertex
0121   LinearizedTrack linearizedState;
0122 
0123   /// Is already linearized
0124   bool isLinearized = false;
0125 };
0126 
0127 }  // namespace Acts
0128 
0129 template <>
0130 struct std::hash<Acts::InputTrack> {
0131   std::size_t operator()(const Acts::InputTrack& track) const noexcept {
0132     return std::hash<const void*>{}(track.m_ptr);
0133   }
0134 };