Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:48

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