Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019-2020 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/MultiTrajectory.hpp"
0012 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0013 #include "Acts/Utilities/ThrowAssert.hpp"
0014 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0015 #include "ActsExamples/EventData/Track.hpp"
0016 
0017 #include <algorithm>
0018 #include <unordered_map>
0019 #include <vector>
0020 
0021 namespace ActsExamples {
0022 
0023 /// Store reconstructed trajectories from track finding/fitting.
0024 ///
0025 /// It contains a MultiTrajectory with a vector of entry indices for
0026 /// individual trajectories, and a map of fitted parameters indexed by the
0027 /// entry index. In case of track fitting, there is at most one trajectory
0028 /// in the MultiTrajectory; In case of track finding, there could be
0029 /// multiple trajectories in the MultiTrajectory.
0030 struct Trajectories final {
0031  public:
0032   /// (Reconstructed) trajectory with multiple states.
0033   using MultiTrajectory = Acts::ConstVectorMultiTrajectory;
0034   /// Fitted parameters identified by indices in the multi trajectory.
0035   using IndexedParameters =
0036       std::unordered_map<Acts::MultiTrajectoryTraits::IndexType,
0037                          TrackParameters>;
0038 
0039   /// Default construct an empty object. Required for container compatibility
0040   /// and to signal an error.
0041   Trajectories() = default;
0042   /// Construct from fitted multi trajectory and parameters.
0043   ///
0044   /// @param multiTraj The multi trajectory
0045   /// /// @param tTips Tip indices that identify valid trajectories
0046   /// @param parameters Fitted track parameters indexed by trajectory index
0047   Trajectories(const MultiTrajectory& multiTraj,
0048                const std::vector<Acts::MultiTrajectoryTraits::IndexType>& tTips,
0049                const IndexedParameters& parameters)
0050       : m_multiTrajectory(&multiTraj),
0051         m_trackTips(tTips),
0052         m_trackParameters(parameters) {}
0053 
0054   /// Return true if there exists no valid trajectory.
0055   bool empty() const { return m_trackTips.empty(); }
0056 
0057   /// Access the underlying multi trajectory.
0058   const MultiTrajectory& multiTrajectory() const {
0059     throw_assert(m_multiTrajectory != nullptr, "MultiTrajectory is null");
0060     return *m_multiTrajectory;
0061   }
0062 
0063   /// Access the tip indices that identify valid trajectories.
0064   const std::vector<Acts::MultiTrajectoryTraits::IndexType>& tips() const {
0065     return m_trackTips;
0066   }
0067 
0068   /// Check if a trajectory exists for the given index.
0069   ///
0070   /// @param entryIndex The trajectory entry index
0071   /// @return Whether there is trajectory with provided entry index
0072   bool hasTrajectory(Acts::MultiTrajectoryTraits::IndexType entryIndex) const {
0073     return (0 < std::count(m_trackTips.begin(), m_trackTips.end(), entryIndex));
0074   }
0075 
0076   /// Check if fitted track parameters exists for the given index.
0077   ///
0078   /// @param entryIndex The trajectory entry index
0079   /// @return Whether having fitted track parameters or not
0080   bool hasTrackParameters(
0081       Acts::MultiTrajectoryTraits::IndexType entryIndex) const {
0082     return (0 < m_trackParameters.count(entryIndex));
0083   }
0084 
0085   /// Access the fitted track parameters for the given index.
0086   ///
0087   /// @param entryIndex The trajectory entry index
0088   /// @return The fitted track parameters of the trajectory
0089   const TrackParameters& trackParameters(
0090       Acts::MultiTrajectoryTraits::IndexType entryIndex) const {
0091     auto it = m_trackParameters.find(entryIndex);
0092     if (it == m_trackParameters.end()) {
0093       throw std::runtime_error(
0094           "No fitted track parameters for trajectory with entry index = " +
0095           std::to_string(entryIndex));
0096     }
0097     return it->second;
0098   }
0099 
0100  private:
0101   // The track container
0102   const MultiTrajectory* m_multiTrajectory{nullptr};
0103   // The entry indices of trajectories stored in multiTrajectory
0104   std::vector<Acts::MultiTrajectoryTraits::IndexType> m_trackTips = {};
0105   // The fitted parameters at the provided surface for individual trajectories
0106   IndexedParameters m_trackParameters = {};
0107 };
0108 
0109 /// Container for multiple trajectories.
0110 using TrajectoriesContainer = std::vector<Trajectories>;
0111 
0112 }  // namespace ActsExamples