-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathAlignment.hpp
More file actions
246 lines (207 loc) · 8.97 KB
/
Alignment.hpp
File metadata and controls
246 lines (207 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#pragma once
#include "Acts/Definitions/Alignment.hpp"
#include "Acts/EventData/BoundTrackParameters.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"
#include "ActsAlignment/Kernel/detail/AlignmentEngine.hpp"
#include <limits>
#include <map>
#include <vector>
namespace ActsAlignment {
using AlignedTransformUpdater =
std::function<bool(Acts::SurfacePlacementBase*,
const Acts::GeometryContext&, const Acts::Transform3&)>;
template <typename Updater>
concept AlignedTransformUpdaterConcept =
requires(Updater updater, Acts::SurfacePlacementBase* detElem,
const Acts::GeometryContext& ctx, const Acts::Transform3& trf) {
{ updater(detElem, ctx, trf) } -> std::same_as<bool>;
};
///
/// @brief Options for align() call
///
/// @tparam fit_options_t The fit options type
template <typename fit_options_t>
struct AlignmentOptions {
/// Deleted default constructor
AlignmentOptions() = delete;
/// AlignmentOptions
///
/// @param fOptions The fit options
/// @param aTransformUpdater The updater to update aligned transform
/// @param aDetElements The alignable detector elements
/// @param chi2CufOff The alignment chi2 tolerance
/// @param deltaChi2CutOff The change of chi2 within a few iterations
/// @param maxIters The alignment maximum iterations
AlignmentOptions(
const fit_options_t& fOptions,
const AlignedTransformUpdater& aTransformUpdater,
const std::vector<Acts::SurfacePlacementBase*>& aDetElements = {},
double chi2CutOff = 0.5,
const std::pair<std::size_t, double>& deltaChi2CutOff = {5, 0.01},
std::size_t maxIters = 5,
const std::map<unsigned int, AlignmentMask>& iterState = {})
: fitOptions(fOptions),
alignedTransformUpdater(aTransformUpdater),
alignedDetElements(aDetElements),
averageChi2ONdfCutOff(chi2CutOff),
deltaAverageChi2ONdfCutOff(deltaChi2CutOff),
maxIterations(maxIters),
iterationState(iterState) {}
// The fit options
fit_options_t fitOptions;
/// The updater to the aligned transform
AlignedTransformUpdater alignedTransformUpdater = nullptr;
// The detector elements to be aligned
std::vector<Acts::SurfacePlacementBase*> alignedDetElements;
// The alignment tolerance to determine if the alignment is covered
double averageChi2ONdfCutOff = 0.5;
// The delta of average chi2/ndf within a couple of iterations to determine if
// alignment is converged
std::pair<std::size_t, double> deltaAverageChi2ONdfCutOff = {5, 0.01};
// The maximum number of iterations to run alignment
std::size_t maxIterations = 5;
// The alignment mask for different iterations
std::map<unsigned int, AlignmentMask> iterationState;
};
/// @brief Alignment result struct
///
struct AlignmentResult {
// The change of alignment parameters
Acts::DynamicVector deltaAlignmentParameters;
// The aligned parameters for detector elements
std::unordered_map<Acts::SurfacePlacementBase*, Acts::Transform3>
alignedParameters;
// The covariance of alignment parameters
Acts::DynamicMatrix alignmentCovariance;
// The average chi2/ndf (ndf is the measurement dim)
double averageChi2ONdf = std::numeric_limits<double>::max();
// The delta chi2
double deltaChi2 = std::numeric_limits<double>::max();
// The chi2
double chi2 = 0;
// The measurement dimension from all tracks
std::size_t measurementDim = 0;
// The alignment degree of freedom
std::size_t alignmentDof = 0;
// The number of tracks used for alignment
std::size_t numTracks = 0;
// The indexed alignable surfaces
std::unordered_map<const Acts::Surface*, std::size_t> idxedAlignSurfaces;
Acts::Result<void> result{Acts::Result<void>::success()};
};
/// @brief KalmanFitter-based alignment implementation
///
/// @tparam fitter_t Type of the fitter class
template <typename fitter_t>
struct Alignment {
// @TODO: Redefine in terms of Track object
/// Default constructor is deleted
Alignment() = delete;
/// Constructor from arguments
explicit Alignment(fitter_t fitter,
std::unique_ptr<const Acts::Logger> _logger =
Acts::getDefaultLogger("Alignment",
Acts::Logging::INFO))
: m_fitter(std::move(fitter)), m_logger{std::move(_logger)} {}
/// @brief evaluate alignment state for a single track
///
/// @tparam source_link_t Source link type identifying uncalibrated input
/// measurements.
/// @tparam fit_options_t The fit options type
///
/// @param gctx The current geometry context object
/// @param sourceLinks The fittable uncalibrated measurements
/// @param sParameters The initial track parameters
/// @param fitOptions The fit Options steering the fit
/// @param idxedAlignSurfaces The idxed surfaces to be aligned
/// @param alignMask The alignment mask (same for all detector element for the
/// moment)
///
/// @result The alignment state for a single track
template <typename source_link_t, typename fit_options_t>
Acts::Result<detail::TrackAlignmentState> evaluateTrackAlignmentState(
const Acts::GeometryContext& gctx,
const std::vector<source_link_t>& sourceLinks,
const Acts::BoundTrackParameters& sParameters,
const fit_options_t& fitOptions,
const std::unordered_map<const Acts::Surface*, std::size_t>&
idxedAlignSurfaces,
const AlignmentMask& alignMask) const;
/// @brief calculate the alignment parameters delta
///
/// @tparam trajectory_container_t The trajectories container type
/// @tparam start_parameters_container_t The initial parameters container type
/// @tparam fit_options_t The fit options type
///
/// @param trajectoryCollection The collection of trajectories as input of
/// fitting
/// @param startParametersCollection The collection of starting parameters as
/// input of fitting
/// @param fitOptions The fit Options steering the fit
/// @param alignResult [in, out] The aligned result
/// @param alignMask The alignment mask (same for all measurements now)
template <typename trajectory_container_t,
typename start_parameters_container_t, typename fit_options_t>
void calculateAlignmentParameters(
const trajectory_container_t& trajectoryCollection,
const start_parameters_container_t& startParametersCollection,
const fit_options_t& fitOptions, AlignmentResult& alignResult,
const AlignmentMask& alignMask = AlignmentMask::All) const;
/// @brief calculate the alignment parameters delta from a set of
/// TrackAlignmentStates
///
/// @param TrackStateCollection The collection of TrackAlignmentStates
/// as input of fitting
/// @param alignResult [in, out] The aligned result
/// @param alignMask The alignment mask (same for all measurements now)
void calculateAlignmentParameters(
const std::vector<detail::TrackAlignmentState>& trackAlignmentStates,
AlignmentResult& alignResult) const;
/// @brief update the detector element alignment parameters
///
/// @param gctx The geometry context
/// @param alignedDetElements The detector elements to be aligned
/// @param alignedTransformUpdater The updater for updating the aligned
/// @param alignResult [in, out] The aligned result
Acts::Result<void> updateAlignmentParameters(
const Acts::GeometryContext& gctx,
const std::vector<Acts::SurfacePlacementBase*>& alignedDetElements,
const AlignedTransformUpdaterConcept auto& alignedTransformUpdater,
AlignmentResult& alignResult) const;
/// @brief Alignment implementation
///
/// @tparam trajectory_container_t The trajectories container type
/// @tparam start_parameters_container_t The initial parameters container type
/// @tparam fit_options_t The fit options type
///
/// @param trajectoryCollection The collection of trajectories as input of
/// fitting
/// @param startParametersCollection The collection of starting parameters as
/// input of fitting
/// @param alignOptions The alignment options
///
/// @result The alignment result
template <typename trajectory_container_t,
typename start_parameters_container_t, typename fit_options_t>
Acts::Result<AlignmentResult> align(
const trajectory_container_t& trajectoryCollection,
const start_parameters_container_t& startParametersCollection,
const AlignmentOptions<fit_options_t>& alignOptions) const;
private:
// The fitter
fitter_t m_fitter;
std::unique_ptr<const Acts::Logger> m_logger;
const Acts::Logger& logger() const { return *m_logger; }
};
} // namespace ActsAlignment
#include "ActsAlignment/Kernel/Alignment.ipp"