File indexing completed on 2026-03-28 07:45:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/EventData/SubspaceHelpers.hpp"
0012 #include "Acts/EventData/TrackStatePropMask.hpp"
0013 #include "Acts/EventData/TrackStateType.hpp"
0014 #include "Acts/EventData/Types.hpp"
0015 #include "Acts/Utilities/EigenConcepts.hpp"
0016 #include "Acts/Utilities/HashedString.hpp"
0017
0018 #include <algorithm>
0019 #include <ranges>
0020 #include <string_view>
0021
0022 namespace Acts {
0023
0024 namespace detail_tsp {
0025 inline constexpr HashedString kPreviousKey = hashString("previous");
0026 inline constexpr HashedString kChi2Key = hashString("chi2");
0027 inline constexpr HashedString kPathLengthKey = hashString("pathLength");
0028 inline constexpr HashedString kTypeFlagsKey = hashString("typeFlags");
0029 inline constexpr HashedString kPredictedKey = hashString("predicted");
0030 inline constexpr HashedString kFilteredKey = hashString("filtered");
0031 inline constexpr HashedString kSmoothedKey = hashString("smoothed");
0032 inline constexpr HashedString kJacobianKey = hashString("jacobian");
0033 inline constexpr HashedString kProjectorKey = hashString("projector");
0034 inline constexpr HashedString kUncalibratedKey =
0035 hashString("uncalibratedSourceLink");
0036 inline constexpr HashedString kCalibratedKey = hashString("calibrated");
0037 inline constexpr HashedString kCalibratedCovKey = hashString("calibratedCov");
0038 inline constexpr HashedString kMeasDimKey = hashString("measdim");
0039 inline constexpr HashedString kNextKey = hashString("next");
0040
0041 }
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 template <typename Derived, bool read_only>
0052 class TrackStateProxyCommon {
0053 protected:
0054
0055 using IndexType = Acts::TrackIndexType;
0056
0057
0058
0059 constexpr Derived& derived() { return static_cast<Derived&>(*this); }
0060
0061
0062 constexpr const Derived& derived() const {
0063 return static_cast<const Derived&>(*this);
0064 }
0065
0066 public:
0067
0068
0069 TrackIndexType previous() const {
0070 return derived()
0071 .template component<TrackIndexType, detail_tsp::kPreviousKey>();
0072 }
0073
0074
0075
0076 TrackIndexType& previous()
0077 requires(!read_only)
0078 {
0079 return derived()
0080 .template component<TrackIndexType, detail_tsp::kPreviousKey>();
0081 }
0082
0083
0084
0085 bool hasPrevious() const { return previous() != kTrackIndexInvalid; }
0086
0087
0088
0089 bool hasPredicted() const { return derived().has(detail_tsp::kPredictedKey); }
0090
0091
0092
0093 bool hasFiltered() const { return derived().has(detail_tsp::kFilteredKey); }
0094
0095
0096
0097 bool hasSmoothed() const { return derived().has(detail_tsp::kSmoothedKey); }
0098
0099
0100
0101 bool hasJacobian() const { return derived().has(detail_tsp::kJacobianKey); }
0102
0103
0104
0105 bool hasProjector() const { return derived().has(detail_tsp::kProjectorKey); }
0106
0107
0108
0109 bool hasUncalibratedSourceLink() const {
0110 return derived().has(detail_tsp::kUncalibratedKey);
0111 }
0112
0113
0114
0115 bool hasCalibrated() const {
0116 return derived().has(detail_tsp::kCalibratedKey);
0117 }
0118
0119
0120
0121
0122
0123 using ParametersMap =
0124 typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CoefficientsMap;
0125
0126 using ConstParametersMap =
0127 typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CoefficientsMap;
0128
0129 using CovarianceMap =
0130 typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CovarianceMap;
0131
0132 using ConstCovarianceMap =
0133 typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CovarianceMap;
0134
0135
0136 using EffectiveCalibratedMap =
0137 typename detail_tsp::DynamicSizeTypes<false>::CoefficientsMap;
0138
0139 using ConstEffectiveCalibratedMap =
0140 typename detail_tsp::DynamicSizeTypes<true>::CoefficientsMap;
0141
0142
0143 using EffectiveCalibratedCovarianceMap =
0144 typename detail_tsp::DynamicSizeTypes<false>::CovarianceMap;
0145
0146 using ConstEffectiveCalibratedCovarianceMap =
0147 typename detail_tsp::DynamicSizeTypes<true>::CovarianceMap;
0148
0149
0150
0151
0152
0153 ConstParametersMap predicted() const {
0154 assert(hasPredicted());
0155 const auto parIndex =
0156 derived().template component<IndexType>(detail_tsp::kPredictedKey);
0157 return derived().parametersAtIndex(parIndex);
0158 }
0159
0160
0161
0162 ParametersMap predicted()
0163 requires(!read_only)
0164 {
0165 assert(hasPredicted());
0166 const auto parIndex =
0167 derived().template component<IndexType>(detail_tsp::kPredictedKey);
0168 return derived().parametersAtIndexMutable(parIndex);
0169 }
0170
0171
0172
0173 ConstCovarianceMap predictedCovariance() const {
0174 assert(hasPredicted());
0175 const auto covIndex =
0176 derived().template component<IndexType>(detail_tsp::kPredictedKey);
0177 return derived().covarianceAtIndex(covIndex);
0178 }
0179
0180
0181
0182 CovarianceMap predictedCovariance()
0183 requires(!read_only)
0184 {
0185 assert(hasPredicted());
0186 const auto covIndex =
0187 derived().template component<IndexType>(detail_tsp::kPredictedKey);
0188 return derived().covarianceAtIndexMutable(covIndex);
0189 }
0190
0191
0192
0193 ConstParametersMap filtered() const {
0194 assert(hasFiltered());
0195 const auto parIndex =
0196 derived().template component<IndexType>(detail_tsp::kFilteredKey);
0197 return derived().parametersAtIndex(parIndex);
0198 }
0199
0200
0201
0202 ParametersMap filtered()
0203 requires(!read_only)
0204 {
0205 const auto parIndex =
0206 derived().template component<IndexType>(detail_tsp::kFilteredKey);
0207 return derived().parametersAtIndexMutable(parIndex);
0208 }
0209
0210
0211
0212 ConstCovarianceMap filteredCovariance() const {
0213 assert(hasFiltered());
0214 const auto covIndex =
0215 derived().template component<IndexType>(detail_tsp::kFilteredKey);
0216 return derived().covarianceAtIndex(covIndex);
0217 }
0218
0219
0220
0221 CovarianceMap filteredCovariance()
0222 requires(!read_only)
0223 {
0224 const auto covIndex =
0225 derived().template component<IndexType>(detail_tsp::kFilteredKey);
0226 return derived().covarianceAtIndexMutable(covIndex);
0227 }
0228
0229
0230
0231 ConstParametersMap smoothed() const {
0232 assert(hasSmoothed());
0233 const auto parIndex =
0234 derived().template component<IndexType>(detail_tsp::kSmoothedKey);
0235 return derived().parametersAtIndex(parIndex);
0236 }
0237
0238
0239
0240 ParametersMap smoothed()
0241 requires(!read_only)
0242 {
0243 assert(hasSmoothed());
0244 const auto parIndex =
0245 derived().template component<IndexType>(detail_tsp::kSmoothedKey);
0246 return derived().parametersAtIndexMutable(parIndex);
0247 }
0248
0249
0250
0251 ConstCovarianceMap smoothedCovariance() const {
0252 assert(hasSmoothed());
0253 const auto covIndex =
0254 derived().template component<IndexType>(detail_tsp::kSmoothedKey);
0255 return derived().covarianceAtIndex(covIndex);
0256 }
0257
0258
0259
0260 CovarianceMap smoothedCovariance()
0261 requires(!read_only)
0262 {
0263 assert(hasSmoothed());
0264 const auto covIndex =
0265 derived().template component<IndexType>(detail_tsp::kSmoothedKey);
0266 return derived().covarianceAtIndexMutable(covIndex);
0267 }
0268
0269
0270
0271 double pathLength() const {
0272 return derived().template component<double, detail_tsp::kPathLengthKey>();
0273 }
0274
0275
0276
0277 double& pathLength()
0278 requires(!read_only)
0279 {
0280 return derived().template component<double, detail_tsp::kPathLengthKey>();
0281 }
0282
0283
0284
0285 ConstTrackStateTypeMap typeFlags() const {
0286 const auto& raw = derived()
0287 .template component<ConstTrackStateTypeMap::raw_type,
0288 detail_tsp::kTypeFlagsKey>();
0289 return ConstTrackStateTypeMap{raw};
0290 }
0291
0292
0293
0294 MutableTrackStateTypeMap typeFlags()
0295 requires(!read_only)
0296 {
0297 auto& raw = derived()
0298 .template component<MutableTrackStateTypeMap::raw_type,
0299 detail_tsp::kTypeFlagsKey>();
0300 return MutableTrackStateTypeMap{raw};
0301 }
0302
0303
0304
0305 float chi2() const {
0306 return derived().template component<float, detail_tsp::kChi2Key>();
0307 }
0308
0309
0310
0311 float& chi2()
0312 requires(!read_only)
0313 {
0314 return derived().template component<float, detail_tsp::kChi2Key>();
0315 }
0316
0317
0318
0319 BoundSubspaceIndices projectorSubspaceIndices() const {
0320 assert(hasProjector());
0321 const auto& serialized =
0322 derived()
0323 .template component<SerializedSubspaceIndices,
0324 detail_tsp::kProjectorKey>();
0325 return deserializeSubspaceIndices<eBoundSize>(serialized);
0326 }
0327
0328
0329
0330 template <std::size_t measdim>
0331 SubspaceIndices<measdim> projectorSubspaceIndices() const {
0332 BoundSubspaceIndices boundSubspace = projectorSubspaceIndices();
0333 SubspaceIndices<measdim> subspace;
0334 std::copy(boundSubspace.begin(), boundSubspace.begin() + measdim,
0335 subspace.begin());
0336 return subspace;
0337 }
0338
0339
0340
0341 VariableBoundSubspaceHelper projectorSubspaceHelper() const {
0342 BoundSubspaceIndices boundSubspace = projectorSubspaceIndices();
0343 std::span<std::uint8_t> validSubspaceIndices(
0344 boundSubspace.begin(),
0345 boundSubspace.begin() + derived().calibratedSize());
0346 return VariableBoundSubspaceHelper(validSubspaceIndices);
0347 }
0348
0349
0350
0351 template <std::size_t measdim>
0352 FixedBoundSubspaceHelper<measdim> projectorSubspaceHelper() const {
0353 SubspaceIndices<measdim> subspace = projectorSubspaceIndices<measdim>();
0354 return FixedBoundSubspaceHelper<measdim>(subspace);
0355 }
0356
0357
0358
0359
0360 template <std::ranges::sized_range index_range_t>
0361 void setProjectorSubspaceIndices(const index_range_t& subspaceIndices)
0362 requires(!read_only &&
0363 std::convertible_to<std::ranges::range_value_t<index_range_t>,
0364 std::uint8_t>)
0365 {
0366 assert(derived().template has<detail_tsp::kProjectorKey>());
0367 assert(subspaceIndices.size() <= eBoundSize);
0368 BoundSubspaceIndices boundSubspace{};
0369 std::transform(subspaceIndices.begin(), subspaceIndices.end(),
0370 boundSubspace.begin(),
0371 [](auto i) { return static_cast<std::uint8_t>(i); });
0372 derived()
0373 .template component<SerializedSubspaceIndices,
0374 detail_tsp::kProjectorKey>() =
0375 serializeSubspaceIndices(boundSubspace);
0376 }
0377
0378
0379
0380 TrackStatePropMask getMask() const {
0381 using PM = TrackStatePropMask;
0382 PM mask = PM::None;
0383 if (hasPredicted()) {
0384 mask |= PM::Predicted;
0385 }
0386 if (hasFiltered()) {
0387 mask |= PM::Filtered;
0388 }
0389 if (hasSmoothed()) {
0390 mask |= PM::Smoothed;
0391 }
0392 if (hasJacobian()) {
0393 mask |= PM::Jacobian;
0394 }
0395 if (hasCalibrated()) {
0396 mask |= PM::Calibrated;
0397 }
0398 return mask;
0399 }
0400
0401
0402
0403 ConstParametersMap parameters() const {
0404 if (hasSmoothed()) {
0405 return smoothed();
0406 } else if (hasFiltered()) {
0407 return filtered();
0408 }
0409 return predicted();
0410 }
0411
0412
0413
0414 ConstCovarianceMap covariance() const {
0415 if (hasSmoothed()) {
0416 return smoothedCovariance();
0417 } else if (hasFiltered()) {
0418 return filteredCovariance();
0419 }
0420 return predictedCovariance();
0421 }
0422
0423
0424
0425 ConstEffectiveCalibratedMap effectiveCalibrated() const {
0426 const double* data = derived().calibratedData();
0427 const auto size = derived().calibratedSize();
0428 return ConstEffectiveCalibratedMap{data, size};
0429 }
0430
0431
0432
0433 EffectiveCalibratedMap effectiveCalibrated()
0434 requires(!read_only)
0435 {
0436 double* data = derived().calibratedDataMutable();
0437 const auto size = derived().calibratedSize();
0438 return EffectiveCalibratedMap{data, size};
0439 }
0440
0441
0442
0443 ConstEffectiveCalibratedCovarianceMap effectiveCalibratedCovariance() const {
0444 const double* data = derived().calibratedCovarianceData();
0445 const auto size = derived().calibratedSize();
0446 return ConstEffectiveCalibratedCovarianceMap{data, size, size};
0447 }
0448
0449
0450
0451 EffectiveCalibratedCovarianceMap effectiveCalibratedCovariance()
0452 requires(!read_only)
0453 {
0454 double* data = derived().calibratedCovarianceDataMutable();
0455 const auto size = derived().calibratedSize();
0456 return EffectiveCalibratedCovarianceMap{data, size, size};
0457 }
0458
0459
0460
0461
0462 template <std::size_t measdim>
0463 typename TrackStateTraits<measdim, true>::Calibrated calibrated() const {
0464 assert(derived().calibratedSize() == static_cast<TrackIndexType>(measdim));
0465 const double* data = derived().calibratedData();
0466 return typename TrackStateTraits<measdim, true>::Calibrated(data);
0467 }
0468
0469
0470
0471
0472 template <std::size_t measdim>
0473 typename TrackStateTraits<measdim, false>::Calibrated calibrated()
0474 requires(!read_only)
0475 {
0476 assert(derived().calibratedSize() == static_cast<TrackIndexType>(measdim));
0477 double* data = derived().calibratedDataMutable();
0478 return typename TrackStateTraits<measdim, false>::Calibrated(data);
0479 }
0480
0481
0482
0483
0484 template <std::size_t measdim>
0485 typename TrackStateTraits<measdim, true>::CalibratedCovariance
0486 calibratedCovariance() const {
0487 assert(derived().calibratedSize() == static_cast<TrackIndexType>(measdim));
0488 const double* data = derived().calibratedCovarianceData();
0489 return typename TrackStateTraits<measdim, true>::CalibratedCovariance(data);
0490 }
0491
0492
0493
0494
0495 template <std::size_t measdim>
0496 typename TrackStateTraits<measdim, false>::CalibratedCovariance
0497 calibratedCovariance()
0498 requires(!read_only)
0499 {
0500 assert(derived().calibratedSize() == static_cast<TrackIndexType>(measdim));
0501 double* data = derived().calibratedCovarianceDataMutable();
0502 return
0503 typename TrackStateTraits<measdim, false>::CalibratedCovariance(data);
0504 }
0505
0506
0507
0508
0509
0510
0511 template <typename val_t, typename cov_t>
0512 void allocateCalibrated(const Eigen::DenseBase<val_t>& val,
0513 const Eigen::DenseBase<cov_t>& cov)
0514 requires(!read_only && Concepts::eigen_base_is_fixed_size<val_t> &&
0515 Concepts::eigen_bases_have_same_num_rows<val_t, cov_t> &&
0516 Concepts::eigen_base_is_square<cov_t> &&
0517 Eigen::PlainObjectBase<val_t>::RowsAtCompileTime <=
0518 static_cast<std::underlying_type_t<BoundIndices>>(eBoundSize))
0519 {
0520 constexpr std::size_t measdim =
0521 static_cast<std::size_t>(val_t::RowsAtCompileTime);
0522 derived().allocateCalibrated(measdim);
0523 calibrated<measdim>() = val;
0524 calibratedCovariance<measdim>() = cov;
0525 }
0526 };
0527
0528 }