Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Alignment.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Alignment.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
23 
24 #include <limits>
25 #include <map>
26 #include <queue>
27 #include <vector>
28 
29 namespace ActsAlignment {
31  std::function<bool(Acts::DetectorElementBase*, const Acts::GeometryContext&,
32  const Acts::Transform3&)>;
38 template <typename fit_options_t>
41  AlignmentOptions() = delete;
42 
51 
53  const fit_options_t& fOptions,
54  const AlignedTransformUpdater& aTransformUpdater,
55  const std::vector<Acts::DetectorElementBase*>& aDetElements = {},
56  double chi2CutOff = 0.5,
57  const std::pair<size_t, double>& deltaChi2CutOff = {5, 0.01},
58  size_t maxIters = 5,
59  const std::map<unsigned int, AlignmentMask>& iterState = {})
60  : fitOptions(fOptions),
61  alignedTransformUpdater(aTransformUpdater),
62  alignedDetElements(aDetElements),
63  averageChi2ONdfCutOff(chi2CutOff),
64  deltaAverageChi2ONdfCutOff(deltaChi2CutOff),
65  maxIterations(maxIters),
66  iterationState(iterState) {}
67 
68  // The fit options
69  fit_options_t fitOptions;
70 
73 
74  // The detector elements to be aligned
75  std::vector<Acts::DetectorElementBase*> alignedDetElements;
76 
77  // The alignment tolerance to determine if the alignment is covered
78  double averageChi2ONdfCutOff = 0.5;
79 
80  // The delta of average chi2/ndf within a couple of iterations to determine if
81  // alignment is converged
82  std::pair<size_t, double> deltaAverageChi2ONdfCutOff = {5, 0.01};
83 
84  // The maximum number of iterations to run alignment
85  size_t maxIterations = 5;
86 
87  // The alignment mask for different iterations
88  std::map<unsigned int, AlignmentMask> iterationState;
89 };
90 
94  // The change of alignment parameters
96 
97  // The aligned parameters for detector elements
98  std::unordered_map<Acts::DetectorElementBase*, Acts::Transform3>
100 
101  // The covariance of alignment parameters
103 
104  // The average chi2/ndf (ndf is the measurement dim)
105  double averageChi2ONdf = std::numeric_limits<double>::max();
106 
107  // The delta chi2
108  double deltaChi2 = std::numeric_limits<double>::max();
109 
110  // The chi2
111  double chi2 = 0;
112 
113  // The measurement dimension from all tracks
114  size_t measurementDim = 0;
115 
116  // The alignment degree of freedom
117  size_t alignmentDof = 0;
118 
119  // The number of tracks used for alignment
120  size_t numTracks = 0;
121 
122  // The indexed alignable surfaces
123  std::unordered_map<const Acts::Surface*, size_t> idxedAlignSurfaces;
124 
126 };
127 
131 template <typename fitter_t>
132 struct Alignment {
133  // @TODO: Redefine in terms of Track object
134 
136  Alignment() = delete;
137 
139  Alignment(fitter_t fitter,
140  std::unique_ptr<const Acts::Logger> _logger =
142  : m_fitter(std::move(fitter)), m_logger{std::move(_logger)} {}
143 
160  template <typename source_link_t, typename start_parameters_t,
161  typename fit_options_t>
162  Acts::Result<detail::TrackAlignmentState> evaluateTrackAlignmentState(
164  const std::vector<source_link_t>& sourcelinks,
165  const start_parameters_t& sParameters, const fit_options_t& fitOptions,
166  const std::unordered_map<const Acts::Surface*, size_t>&
167  idxedAlignSurfaces,
168  const AlignmentMask& alignMask) const;
169 
183  template <typename trajectory_container_t,
184  typename start_parameters_container_t, typename fit_options_t>
186  const trajectory_container_t& trajectoryCollection,
187  const start_parameters_container_t& startParametersCollection,
188  const fit_options_t& fitOptions, AlignmentResult& alignResult,
189  const AlignmentMask& alignMask = AlignmentMask::All) const;
190 
199  const std::vector<Acts::DetectorElementBase*>& alignedDetElements,
200  const AlignedTransformUpdater& alignedTransformUpdater,
201  AlignmentResult& alignResult) const;
202 
216  template <typename trajectory_container_t,
217  typename start_parameters_container_t, typename fit_options_t>
219  const trajectory_container_t& trajectoryCollection,
220  const start_parameters_container_t& startParametersCollection,
221  const AlignmentOptions<fit_options_t>& alignOptions) const;
222 
223  private:
224  // The fitter
225  fitter_t m_fitter;
226 
227  std::unique_ptr<const Acts::Logger> m_logger;
228 
229  const Acts::Logger& logger() const { return *m_logger; }
230 };
231 } // namespace ActsAlignment
232