File indexing completed on 2025-01-18 09:10:48
0001
0002
0003
0004
0005
0006
0007
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
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
0043 using VolumeTrajectoryStateContainer =
0044 std::unordered_map<GeometryIdentifier::Value, TrajectoryState>;
0045
0046
0047
0048
0049
0050
0051
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
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
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
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
0102 const auto& geoID = state.referenceSurface().geometryId();
0103 const auto& volume = geoID.volume();
0104 const auto& layer = geoID.layer();
0105
0106 if (!rangeContainsValue(volumeIds, volume)) {
0107 return true;
0108 }
0109
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
0137
0138
0139
0140
0141
0142
0143
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
0152
0153
0154
0155
0156
0157
0158
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 }