File indexing completed on 2025-01-18 09:10:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Alignment.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/TrackFitting/KalmanFitter.hpp"
0017 #include "Acts/TrackFitting/detail/KalmanGlobalCovariance.hpp"
0018 #include "Acts/Utilities/CalibrationContext.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "Acts/Utilities/Result.hpp"
0021 #include "ActsAlignment/Kernel/AlignmentError.hpp"
0022 #include "ActsAlignment/Kernel/detail/AlignmentEngine.hpp"
0023
0024 #include <limits>
0025 #include <map>
0026 #include <queue>
0027 #include <vector>
0028
0029 namespace ActsAlignment {
0030 using AlignedTransformUpdater =
0031 std::function<bool(Acts::DetectorElementBase*, const Acts::GeometryContext&,
0032 const Acts::Transform3&)>;
0033
0034
0035
0036
0037
0038 template <typename fit_options_t>
0039 struct AlignmentOptions {
0040
0041 AlignmentOptions() = delete;
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 AlignmentOptions(
0053 const fit_options_t& fOptions,
0054 const AlignedTransformUpdater& aTransformUpdater,
0055 const std::vector<Acts::DetectorElementBase*>& aDetElements = {},
0056 double chi2CutOff = 0.5,
0057 const std::pair<std::size_t, double>& deltaChi2CutOff = {5, 0.01},
0058 std::size_t maxIters = 5,
0059 const std::map<unsigned int, AlignmentMask>& iterState = {})
0060 : fitOptions(fOptions),
0061 alignedTransformUpdater(aTransformUpdater),
0062 alignedDetElements(aDetElements),
0063 averageChi2ONdfCutOff(chi2CutOff),
0064 deltaAverageChi2ONdfCutOff(deltaChi2CutOff),
0065 maxIterations(maxIters),
0066 iterationState(iterState) {}
0067
0068
0069 fit_options_t fitOptions;
0070
0071
0072 AlignedTransformUpdater alignedTransformUpdater = nullptr;
0073
0074
0075 std::vector<Acts::DetectorElementBase*> alignedDetElements;
0076
0077
0078 double averageChi2ONdfCutOff = 0.5;
0079
0080
0081
0082 std::pair<std::size_t, double> deltaAverageChi2ONdfCutOff = {5, 0.01};
0083
0084
0085 std::size_t maxIterations = 5;
0086
0087
0088 std::map<unsigned int, AlignmentMask> iterationState;
0089 };
0090
0091
0092
0093 struct AlignmentResult {
0094
0095 Acts::ActsDynamicVector deltaAlignmentParameters;
0096
0097
0098 std::unordered_map<Acts::DetectorElementBase*, Acts::Transform3>
0099 alignedParameters;
0100
0101
0102 Acts::ActsDynamicMatrix alignmentCovariance;
0103
0104
0105 double averageChi2ONdf = std::numeric_limits<double>::max();
0106
0107
0108 double deltaChi2 = std::numeric_limits<double>::max();
0109
0110
0111 double chi2 = 0;
0112
0113
0114 std::size_t measurementDim = 0;
0115
0116
0117 std::size_t alignmentDof = 0;
0118
0119
0120 std::size_t numTracks = 0;
0121
0122
0123 std::unordered_map<const Acts::Surface*, std::size_t> idxedAlignSurfaces;
0124
0125 Acts::Result<void> result{Acts::Result<void>::success()};
0126 };
0127
0128
0129
0130
0131 template <typename fitter_t>
0132 struct Alignment {
0133
0134
0135
0136 Alignment() = delete;
0137
0138
0139 Alignment(fitter_t fitter,
0140 std::unique_ptr<const Acts::Logger> _logger =
0141 Acts::getDefaultLogger("Alignment", Acts::Logging::INFO))
0142 : m_fitter(std::move(fitter)), m_logger{std::move(_logger)} {}
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 template <typename source_link_t, typename start_parameters_t,
0161 typename fit_options_t>
0162 Acts::Result<detail::TrackAlignmentState> evaluateTrackAlignmentState(
0163 const Acts::GeometryContext& gctx,
0164 const std::vector<source_link_t>& sourceLinks,
0165 const start_parameters_t& sParameters, const fit_options_t& fitOptions,
0166 const std::unordered_map<const Acts::Surface*, std::size_t>&
0167 idxedAlignSurfaces,
0168 const AlignmentMask& alignMask) const;
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 template <typename trajectory_container_t,
0184 typename start_parameters_container_t, typename fit_options_t>
0185 void calculateAlignmentParameters(
0186 const trajectory_container_t& trajectoryCollection,
0187 const start_parameters_container_t& startParametersCollection,
0188 const fit_options_t& fitOptions, AlignmentResult& alignResult,
0189 const AlignmentMask& alignMask = AlignmentMask::All) const;
0190
0191
0192
0193
0194
0195
0196
0197 Acts::Result<void> updateAlignmentParameters(
0198 const Acts::GeometryContext& gctx,
0199 const std::vector<Acts::DetectorElementBase*>& alignedDetElements,
0200 const AlignedTransformUpdater& alignedTransformUpdater,
0201 AlignmentResult& alignResult) const;
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216 template <typename trajectory_container_t,
0217 typename start_parameters_container_t, typename fit_options_t>
0218 Acts::Result<AlignmentResult> align(
0219 const trajectory_container_t& trajectoryCollection,
0220 const start_parameters_container_t& startParametersCollection,
0221 const AlignmentOptions<fit_options_t>& alignOptions) const;
0222
0223 private:
0224
0225 fitter_t m_fitter;
0226
0227 std::unique_ptr<const Acts::Logger> m_logger;
0228
0229 const Acts::Logger& logger() const { return *m_logger; }
0230 };
0231 }
0232
0233 #include "ActsAlignment/Kernel/Alignment.ipp"