File indexing completed on 2026-08-26 08:20:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Validation/ParametersOnSurface.hpp"
0010
0011 #include "Acts/Utilities/TrackHelpers.hpp"
0012 #include "Acts/Utilities/VectorHelpers.hpp"
0013 #include "ActsExamples/EventData/AverageSimHits.hpp"
0014 #include "ActsExamples/Utilities/Range.hpp"
0015
0016 #include <utility>
0017
0018 std::optional<Acts::BoundTrackParameters>
0019 ActsExamples::truthParametersOnSurface(
0020 const Acts::GeometryContext& gctx, const Acts::Surface& surface,
0021 Index measurementIndex, const SimParticle& particle,
0022 const SimHitContainer& simHits,
0023 const MeasurementSimHitsMap& measurementSimHitsMap,
0024 const Acts::Logger& logger) {
0025 using Acts::VectorHelpers::phi;
0026 using Acts::VectorHelpers::theta;
0027
0028 using enum Acts::BoundIndices;
0029
0030 const auto indices =
0031 makeRange(measurementSimHitsMap.equal_range(measurementIndex));
0032 if (indices.empty()) {
0033 ACTS_WARNING("No truth hits associated to measurement " << measurementIndex
0034 << " found");
0035 return std::nullopt;
0036 }
0037
0038 const auto [truthLocal, truthPos4, truthUnitDir] =
0039 averageSimHits(gctx, surface, simHits, indices, logger);
0040
0041
0042
0043
0044
0045 const auto simHitIdx0 = indices.begin()->second;
0046 const auto& simHit0 = *simHits.nth(simHitIdx0);
0047 const auto momentum = simHit0.momentum4Before().segment<3>(Acts::eMom0);
0048
0049 Acts::BoundVector params = Acts::BoundVector::Zero();
0050 params[eBoundLoc0] = truthLocal[Acts::ePos0];
0051 params[eBoundLoc1] = truthLocal[Acts::ePos1];
0052 params[eBoundPhi] = phi(truthUnitDir);
0053 params[eBoundTheta] = theta(truthUnitDir);
0054 params[eBoundQOverP] =
0055 particle.hypothesis().qOverP(momentum.norm(), particle.charge());
0056 params[eBoundTime] = truthPos4[Acts::eTime];
0057
0058 return Acts::BoundTrackParameters(surface.getSharedPtr(), params,
0059 std::nullopt, particle.hypothesis());
0060 }
0061
0062 std::optional<Acts::BoundTrackParameters> ActsExamples::recoParametersOnSurface(
0063 const ConstTrackStateProxy& state,
0064 std::optional<TrackParameterType> parameterType,
0065 const Acts::ParticleHypothesis& hypothesis) {
0066 using enum TrackParameterType;
0067
0068 if (!state.hasReferenceSurface()) {
0069 return std::nullopt;
0070 }
0071
0072 const auto stateParameters =
0073 [&]() -> std::optional<std::pair<Acts::BoundVector, Acts::BoundMatrix>> {
0074 if (!parameterType.has_value()) {
0075 if (!state.hasSmoothed() && !state.hasFiltered() &&
0076 !state.hasPredicted()) {
0077 return std::nullopt;
0078 }
0079
0080
0081
0082 return std::pair(state.parameters(), state.covariance());
0083 }
0084 if (parameterType == Predicted && state.hasPredicted()) {
0085 return std::pair(state.predicted(), state.predictedCovariance());
0086 }
0087 if (parameterType == Filtered && state.hasFiltered()) {
0088 return std::pair(state.filtered(), state.filteredCovariance());
0089 }
0090 if (parameterType == Smoothed && state.hasSmoothed()) {
0091 return std::pair(state.smoothed(), state.smoothedCovariance());
0092 }
0093 if (parameterType == Unbiased && state.hasSmoothed() &&
0094 state.hasProjector() && state.hasCalibrated()) {
0095 return Acts::calculateUnbiasedParametersCovariance(
0096 Acts::AnyConstTrackStateProxy{state});
0097 }
0098 return std::nullopt;
0099 }();
0100
0101 if (!stateParameters.has_value()) {
0102 return std::nullopt;
0103 }
0104
0105 return Acts::BoundTrackParameters(state.referenceSurface().getSharedPtr(),
0106 stateParameters->first,
0107 stateParameters->second, hypothesis);
0108 }