Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalculateResiduals.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CalculateResiduals.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
13 
14 #include <cassert>
15 
16 #include <Eigen/Core>
17 
18 namespace Acts {
19 namespace detail {
20 
34 template <typename index_container_t, typename measured_t, typename residuals_t>
36  const index_container_t& indices,
37  const BoundVector& reference,
38  const Eigen::MatrixBase<measured_t>& measured,
39  Eigen::MatrixBase<residuals_t>& residuals) {
40  using OutputScalar = typename residuals_t::Scalar;
41 
42  EIGEN_STATIC_ASSERT_VECTOR_ONLY(measured_t);
43  EIGEN_STATIC_ASSERT_VECTOR_ONLY(residuals_t);
44  assert((size <= eBoundSize) and "Measured subspace is too large");
45  assert((size <= measured.size()) and "Inconsistent measured size");
46  assert((size <= residuals.size()) and "Inconsistent residuals size");
47 
48  for (size_t i = 0; i < size; ++i) {
49  size_t fullIndex = indices[i];
50  // this is neither elegant nor smart but it is the simplest solution.
51  //
52  // only phi must be handled specially here. the theta limits can only be
53  // correctly handled if phi is updated, too. since we can not ensure that
54  // both are available, it is probably less error-prone to treat theta as a
55  // regular, unrestricted parameter.
56  if (fullIndex == eBoundPhi) {
57  residuals[i] = difference_periodic<OutputScalar>(
58  measured[i], reference[fullIndex],
59  static_cast<OutputScalar>(2 * M_PI));
60  } else {
61  residuals[i] = measured[i] - reference[fullIndex];
62  }
63  }
64 }
65 
79 template <typename index_container_t, typename measured_t, typename residuals_t>
81  const index_container_t& indices,
82  const FreeVector& reference,
83  const Eigen::MatrixBase<measured_t>& measured,
84  Eigen::MatrixBase<residuals_t>& residuals) {
85  EIGEN_STATIC_ASSERT_VECTOR_ONLY(measured_t);
86  EIGEN_STATIC_ASSERT_VECTOR_ONLY(residuals_t);
87  assert((size <= eFreeSize) and "Measured subspace is too large");
88  assert((size <= measured.size()) and "Inconsistent measured size");
89  assert((size <= residuals.size()) and "Inconsistent residuals size");
90 
91  for (size_t i = 0; i < size; ++i) {
92  // all free parameters are unrestricted. no need to call parameter traits
93  residuals[i] = measured[i] - reference[indices[i]];
94  }
95 }
96 
97 } // namespace detail
98 } // namespace Acts