EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DifferenceCalculator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DifferenceCalculator.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-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 
12 
13 #include <utility>
14 
15 #include <Eigen/Core>
16 
17 namespace Acts {
18 namespace detail {
19 
24 template <typename indices_t, indices_t... kParameters>
26  using StorageSequence = std::make_index_sequence<sizeof...(kParameters)>;
27 
33  template <typename lhs_t, typename rhs_t>
34  static auto run(const Eigen::MatrixBase<lhs_t>& lhs,
35  const Eigen::MatrixBase<rhs_t>& rhs) {
36  return runImpl(lhs, rhs, StorageSequence{});
37  }
38 
39  template <typename lhs_t, typename rhs_t, std::size_t... kStorage>
40  static auto runImpl(const Eigen::MatrixBase<lhs_t>& lhs,
41  const Eigen::MatrixBase<rhs_t>& rhs,
42  std::index_sequence<kStorage...>)
43  -> std::decay_t<decltype((lhs - rhs).eval())> {
44  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(lhs_t, rhs_t);
45  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(lhs_t, sizeof...(kParameters));
46  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(rhs_t, sizeof...(kParameters));
47  static_assert(sizeof...(kParameters) == sizeof...(kStorage),
48  "Parameters and storage index packs must have the same size");
49 
50  std::decay_t<decltype((lhs - rhs).eval())> residuals;
51  ((residuals[kStorage] =
53  lhs[kStorage], rhs[kStorage])),
54  ...);
55  return residuals;
56  }
57 };
58 
59 } // namespace detail
60 } // namespace Acts