Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 07:34:14

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 };
0049 
0050 // Container for trajectory summary info at a specific volume
0051 using VolumeTrajectoryStateContainer =
0052     std::unordered_map<GeometryIdentifier::Value, TrajectoryState>;
0053 
0054 /// @brief Getter for global trajectory info
0055 ///
0056 /// @param multiTraj The MultiTrajectory object
0057 /// @param tipIndex The entry index of trajectory to investigate
0058 ///
0059 /// @return The trajectory summary info
0060 template <typename traj_t>
0061 TrajectoryState trajectoryState(const traj_t& multiTraj, std::size_t tipIndex) {
0062   TrajectoryState trajState;
0063   multiTraj.visitBackwards(tipIndex, [&](const auto& state) {
0064     // Get the volume Id of this surface
0065     const auto& geoID = state.referenceSurface().geometryId();
0066     const auto& volume = geoID.volume();
0067     const auto& layer = geoID.layer();
0068     trajState.nStates++;
0069     auto typeFlags = state.typeFlags();
0070     if (typeFlags.isHole()) {
0071       trajState.nHoles++;
0072     } else if (typeFlags.isOutlier()) {
0073       trajState.nOutliers++;
0074       trajState.outlierChi2.push_back(state.chi2());
0075       trajState.outlierVolume.push_back(volume);
0076       trajState.outlierLayer.push_back(layer);
0077     } else if (typeFlags.isMeasurement()) {
0078       if (typeFlags.isSharedHit()) {
0079         trajState.nSharedHits++;
0080       }
0081       trajState.nMeasurements++;
0082       trajState.measurementChi2.push_back(state.chi2());
0083       trajState.measurementVolume.push_back(volume);
0084       trajState.measurementLayer.push_back(layer);
0085       trajState.chi2Sum += state.chi2();
0086       trajState.NDF += state.calibratedSize();
0087     }
0088   });
0089   return trajState;
0090 }
0091 
0092 /// @brief Getter for trajectory info for different sub-detectors
0093 ///
0094 /// @tparam source_link_t Type of source link
0095 ///
0096 /// @param multiTraj The MultiTrajectory object
0097 /// @param tipIndex The entry index of trajectory to investigate
0098 /// track states at different sub-detectors.
0099 /// @param volumeIds The container for sub-detector Ids
0100 ///
0101 /// @return The trajectory summary info at different sub-detectors (i.e.
0102 /// different volumes)
0103 template <typename traj_t>
0104 VolumeTrajectoryStateContainer trajectoryState(
0105     const traj_t& multiTraj, std::size_t tipIndex,
0106     const std::vector<GeometryIdentifier::Value>& volumeIds) {
0107   VolumeTrajectoryStateContainer trajStateContainer;
0108   multiTraj.visitBackwards(tipIndex, [&](const auto& state) {
0109     // Get the volume Id of this surface
0110     const auto& geoID = state.referenceSurface().geometryId();
0111     const auto& volume = geoID.volume();
0112     const auto& layer = geoID.layer();
0113     // Check if the track info for this sub-detector is requested
0114     if (!rangeContainsValue(volumeIds, volume)) {
0115       return true;
0116     }
0117     // The trajectory state for this volume
0118     auto& trajState = trajStateContainer[volume];
0119     trajState.nStates++;
0120     trajState.NDF += state.calibratedSize();
0121     auto typeFlags = state.typeFlags();
0122     if (typeFlags.isHole()) {
0123       trajState.nHoles++;
0124     } else if (typeFlags.isOutlier()) {
0125       trajState.nOutliers++;
0126       trajState.outlierChi2.push_back(state.chi2());
0127       trajState.outlierVolume.push_back(volume);
0128       trajState.outlierLayer.push_back(layer);
0129     } else if (typeFlags.isMeasurement()) {
0130       if (typeFlags.isSharedHit()) {
0131         trajState.nSharedHits++;
0132       }
0133       trajState.nMeasurements++;
0134       trajState.measurementChi2.push_back(state.chi2());
0135       trajState.measurementVolume.push_back(volume);
0136       trajState.measurementLayer.push_back(layer);
0137       trajState.chi2Sum += state.chi2();
0138     }
0139     return true;
0140   });
0141   return trajStateContainer;
0142 }
0143 
0144 /// @brief Transforms the filtered parameters from a @c TrackStateProxy to free
0145 /// parameters
0146 ///
0147 /// @tparam track_state_proxy_t Type of the @c TrackStateProxy
0148 /// @param [in] gctx Geometry context
0149 /// @param [in] trackStateProxy TrackStateProxy
0150 ///
0151 /// @return Free parameters representation of the filtered parameters
0152 template <typename track_state_proxy_t>
0153 FreeVector freeFiltered(const GeometryContext& gctx,
0154                         const track_state_proxy_t& trackStateProxy) {
0155   return transformBoundToFreeParameters(trackStateProxy.referenceSurface(),
0156                                         gctx, trackStateProxy.filtered());
0157 }
0158 
0159 /// @brief Transforms the smoothed parameters from a @c TrackStateProxy to free
0160 /// parameters
0161 ///
0162 /// @tparam track_state_proxy_t Type of the @c TrackStateProxy
0163 /// @param [in] gctx Geometry context
0164 /// @param [in] trackStateProxy TrackStateProxy
0165 ///
0166 /// @return Free parameters representation of the smoothed parameters
0167 template <typename track_state_proxy_t>
0168 FreeVector freeSmoothed(const GeometryContext& gctx,
0169                         const track_state_proxy_t& trackStateProxy) {
0170   return transformBoundToFreeParameters(trackStateProxy.referenceSurface(),
0171                                         gctx, trackStateProxy.smoothed());
0172 }
0173 }  // namespace Acts::MultiTrajectoryHelpers