Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-20 08:37:49

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/TransformationHelpers.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "Acts/Utilities/Helpers.hpp"
0014 
0015 #include <unordered_map>
0016 
0017 namespace Acts::MultiTrajectoryHelpers {
0018 
0019 /// @brief Struct for brief trajectory summary info
0020 ///
0021 struct TrajectoryState {
0022   /// Total number of track states in trajectory
0023   std::size_t nStates = 0;
0024   /// Number of track states with measurements
0025   std::size_t nMeasurements = 0;
0026   /// Number of track states marked as outliers
0027   std::size_t nOutliers = 0;
0028   /// Number of hole states in trajectory
0029   std::size_t nHoles = 0;
0030   /// Sum of chi-squared values from measurements
0031   double chi2Sum = 0;
0032   /// Chi-squared contribution from each measurement
0033   std::vector<double> measurementChi2 = {};
0034   /// Chi-squared contribution from each outlier
0035   std::vector<double> outlierChi2 = {};
0036   /// Number of degrees of freedom in track fit
0037   std::size_t NDF = 0;
0038   /// Volume identifiers for measurement surfaces
0039   std::vector<unsigned int> measurementVolume = {};
0040   /// Layer identifiers for measurement surfaces
0041   std::vector<unsigned int> measurementLayer = {};
0042   /// Volume identifiers for outlier surfaces
0043   std::vector<unsigned int> outlierVolume = {};
0044   /// Layer identifiers for outlier surfaces
0045   std::vector<unsigned int> outlierLayer = {};
0046   /// Number of hits shared with other tracks
0047   std::size_t nSharedHits = 0;
0048   /// Number of split hits, which other tracks may use without penalty
0049   std::size_t nSplitHits = 0;
0050 };
0051 
0052 // Container for trajectory summary info at a specific volume
0053 using VolumeTrajectoryStateContainer =
0054     std::unordered_map<GeometryIdentifier::Value, TrajectoryState>;
0055 
0056 /// @brief Getter for global trajectory info
0057 ///
0058 /// @param multiTraj The MultiTrajectory object
0059 /// @param tipIndex The entry index of trajectory to investigate
0060 ///
0061 /// @return The trajectory summary info
0062 template <typename traj_t>
0063 TrajectoryState trajectoryState(const traj_t& multiTraj, std::size_t tipIndex) {
0064   TrajectoryState trajState;
0065   multiTraj.visitBackwards(tipIndex, [&](const auto& state) {
0066     // Get the volume Id of this surface
0067     const auto& geoID = state.referenceSurface().geometryId();
0068     const auto& volume = geoID.volume();
0069     const auto& layer = geoID.layer();
0070     trajState.nStates++;
0071     auto typeFlags = state.typeFlags();
0072     if (typeFlags.isHole()) {
0073       trajState.nHoles++;
0074     } else if (typeFlags.isOutlier()) {
0075       trajState.nOutliers++;
0076       trajState.outlierChi2.push_back(state.chi2());
0077       trajState.outlierVolume.push_back(volume);
0078       trajState.outlierLayer.push_back(layer);
0079     } else if (typeFlags.isMeasurement()) {
0080       if (typeFlags.isSharedHit()) {
0081         trajState.nSharedHits++;
0082       }
0083       if (typeFlags.isSplitHit()) {
0084         trajState.nSplitHits++;
0085       }
0086       trajState.nMeasurements++;
0087       trajState.measurementChi2.push_back(state.chi2());
0088       trajState.measurementVolume.push_back(volume);
0089       trajState.measurementLayer.push_back(layer);
0090       trajState.chi2Sum += state.chi2();
0091       trajState.NDF += state.calibratedSize();
0092     }
0093   });
0094   return trajState;
0095 }
0096 
0097 /// @brief Getter for trajectory info for different sub-detectors
0098 ///
0099 /// @tparam source_link_t Type of source link
0100 ///
0101 /// @param multiTraj The MultiTrajectory object
0102 /// @param tipIndex The entry index of trajectory to investigate
0103 /// track states at different sub-detectors.
0104 /// @param volumeIds The container for sub-detector Ids
0105 ///
0106 /// @return The trajectory summary info at different sub-detectors (i.e.
0107 /// different volumes)
0108 template <typename traj_t>
0109 VolumeTrajectoryStateContainer trajectoryState(
0110     const traj_t& multiTraj, std::size_t tipIndex,
0111     const std::vector<GeometryIdentifier::Value>& volumeIds) {
0112   VolumeTrajectoryStateContainer trajStateContainer;
0113   multiTraj.visitBackwards(tipIndex, [&](const auto& state) {
0114     // Get the volume Id of this surface
0115     const auto& geoID = state.referenceSurface().geometryId();
0116     const auto& volume = geoID.volume();
0117     const auto& layer = geoID.layer();
0118     // Check if the track info for this sub-detector is requested
0119     if (!rangeContainsValue(volumeIds, volume)) {
0120       return true;
0121     }
0122     // The trajectory state for this volume
0123     auto& trajState = trajStateContainer[volume];
0124     trajState.nStates++;
0125     trajState.NDF += state.calibratedSize();
0126     auto typeFlags = state.typeFlags();
0127     if (typeFlags.isHole()) {
0128       trajState.nHoles++;
0129     } else if (typeFlags.isOutlier()) {
0130       trajState.nOutliers++;
0131       trajState.outlierChi2.push_back(state.chi2());
0132       trajState.outlierVolume.push_back(volume);
0133       trajState.outlierLayer.push_back(layer);
0134     } else if (typeFlags.isMeasurement()) {
0135       if (typeFlags.isSharedHit()) {
0136         trajState.nSharedHits++;
0137       }
0138       if (typeFlags.isSplitHit()) {
0139         trajState.nSplitHits++;
0140       }
0141       trajState.nMeasurements++;
0142       trajState.measurementChi2.push_back(state.chi2());
0143       trajState.measurementVolume.push_back(volume);
0144       trajState.measurementLayer.push_back(layer);
0145       trajState.chi2Sum += state.chi2();
0146     }
0147     return true;
0148   });
0149   return trajStateContainer;
0150 }
0151 
0152 /// @brief Transforms the filtered parameters from a @c TrackStateProxy to free
0153 /// parameters
0154 ///
0155 /// @tparam track_state_proxy_t Type of the @c TrackStateProxy
0156 /// @param [in] gctx Geometry context
0157 /// @param [in] trackStateProxy TrackStateProxy
0158 ///
0159 /// @return Free parameters representation of the filtered parameters
0160 template <typename track_state_proxy_t>
0161 FreeVector freeFiltered(const GeometryContext& gctx,
0162                         const track_state_proxy_t& trackStateProxy) {
0163   return transformBoundToFreeParameters(trackStateProxy.referenceSurface(),
0164                                         gctx, trackStateProxy.filtered());
0165 }
0166 
0167 /// @brief Transforms the smoothed parameters from a @c TrackStateProxy to free
0168 /// parameters
0169 ///
0170 /// @tparam track_state_proxy_t Type of the @c TrackStateProxy
0171 /// @param [in] gctx Geometry context
0172 /// @param [in] trackStateProxy TrackStateProxy
0173 ///
0174 /// @return Free parameters representation of the smoothed parameters
0175 template <typename track_state_proxy_t>
0176 FreeVector freeSmoothed(const GeometryContext& gctx,
0177                         const track_state_proxy_t& trackStateProxy) {
0178   return transformBoundToFreeParameters(trackStateProxy.referenceSurface(),
0179                                         gctx, trackStateProxy.smoothed());
0180 }
0181 }  // namespace Acts::MultiTrajectoryHelpers