File indexing completed on 2025-01-18 09:12:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/EventData/TransformationHelpers.hpp"
0013 #include "Acts/Geometry/DetectorElementBase.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/Result.hpp"
0016 #include "ActsFatras/EventData/Hit.hpp"
0017
0018 #include <array>
0019 #include <functional>
0020 #include <utility>
0021
0022 namespace ActsFatras {
0023
0024
0025
0026
0027
0028
0029
0030 template <typename generator_t>
0031 using SingleParameterSmearFunction =
0032 std::function<Acts::Result<std::pair<double, double>>(double,
0033 generator_t&)>;
0034
0035
0036
0037
0038
0039
0040
0041
0042 template <typename generator_t, std::size_t kSize>
0043 struct BoundParametersSmearer {
0044 using ParametersVector = Acts::ActsVector<kSize>;
0045 using CovarianceMatrix = Acts::ActsSquareMatrix<kSize>;
0046 using Result = Acts::Result<std::pair<ParametersVector, CovarianceMatrix>>;
0047
0048
0049 std::array<Acts::BoundIndices, kSize> indices{};
0050 std::array<SingleParameterSmearFunction<generator_t>, kSize> smearFunctions{};
0051 std::array<bool, kSize> forcePositive = {};
0052
0053 static constexpr std::size_t size() { return kSize; }
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 Result operator()(generator_t& rng, const Hit& hit,
0064 const Acts::Surface& surface,
0065 const Acts::GeometryContext& geoCtx) const {
0066
0067
0068
0069 const auto tolerance =
0070 surface.associatedDetectorElement() != nullptr
0071 ? surface.associatedDetectorElement()->thickness()
0072 : Acts::s_onSurfaceTolerance;
0073
0074
0075
0076 Acts::Result<Acts::BoundVector> boundParamsRes =
0077 Acts::transformFreeToBoundParameters(hit.position(), hit.time(),
0078 hit.direction(), 0, surface,
0079 geoCtx, tolerance);
0080
0081 if (!boundParamsRes.ok()) {
0082 return boundParamsRes.error();
0083 }
0084
0085 const auto& boundParams = *boundParamsRes;
0086
0087 ParametersVector par = ParametersVector::Zero();
0088 CovarianceMatrix cov = CovarianceMatrix::Zero();
0089 for (std::size_t i = 0; i < kSize; ++i) {
0090 auto res = smearFunctions[i](boundParams[indices[i]], rng);
0091 if (!res.ok()) {
0092 return Result::failure(res.error());
0093 }
0094 auto [value, stddev] = res.value();
0095 par[i] = value;
0096 if (forcePositive[i]) {
0097 par[i] = std::abs(value);
0098 }
0099 cov(i, i) = stddev * stddev;
0100 }
0101
0102 return Result::success(std::make_pair(par, cov));
0103 }
0104 };
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 template <typename generator_t, std::size_t kSize>
0117 struct FreeParametersSmearer {
0118 using ParametersVector = Acts::ActsVector<kSize>;
0119 using CovarianceMatrix = Acts::ActsSquareMatrix<kSize>;
0120 using Result = Acts::Result<std::pair<ParametersVector, CovarianceMatrix>>;
0121
0122
0123 std::array<Acts::FreeIndices, kSize> indices{};
0124 std::array<SingleParameterSmearFunction<generator_t>, kSize> smearFunctions;
0125
0126 static constexpr std::size_t size() { return kSize; }
0127
0128
0129
0130
0131
0132
0133
0134
0135 Result operator()(generator_t& rng, const Hit& hit) const {
0136
0137
0138 Acts::FreeVector freeParams;
0139 freeParams.segment<3>(Acts::eFreePos0) = hit.position();
0140 freeParams[Acts::eFreeTime] = hit.time();
0141 freeParams.segment<3>(Acts::eFreeDir0) = hit.direction();
0142 freeParams[Acts::eFreeQOverP] = 0;
0143
0144 ParametersVector par = ParametersVector::Zero();
0145 CovarianceMatrix cov = CovarianceMatrix::Zero();
0146 for (std::size_t i = 0; i < kSize; ++i) {
0147 auto res = smearFunctions[i](freeParams[indices[i]], rng);
0148 if (!res.ok()) {
0149 return Result::failure(res.error());
0150 }
0151 auto [value, stddev] = res.value();
0152 par[i] = value;
0153 cov(i, i) = stddev * stddev;
0154 }
0155
0156 return Result::success(std::make_pair(par, cov));
0157 }
0158 };
0159
0160 }