EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParametersSmearer.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParametersSmearer.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 
11 #include <utility>
12 
16 
17 namespace ActsFatras {
18 
19 namespace detail {
20 
24 using SmearFunction =
25  std::function<Acts::Result<std::pair<double, double>>(double)>;
26 
40 template <typename values_t, typename covariance_t>
42  void operator()(size_t idx, Eigen::MatrixBase<values_t>& values,
43  Eigen::MatrixBase<covariance_t>& covariances,
44  const SmearFunction& sFunction, Acts::Result<void>& result) {
45  auto sResult = sFunction(values[idx]);
46  if (sResult.ok()) {
47  const auto& smeared = sResult.value();
48  values[idx] = smeared.first;
49  covariances(idx, idx) = smeared.second * smeared.second;
50  } else {
51  result = Acts::Result<void>(sResult.error());
52  }
53  }
54 };
55 
60 template <typename indices_t, indices_t... kParameters>
62  using StorageSequence = std::make_index_sequence<sizeof...(kParameters)>;
63 
71  template <typename values_t, typename covariance_t>
73  Eigen::MatrixBase<values_t>& values,
74  Eigen::MatrixBase<covariance_t>& covariances,
75  const std::array<SmearFunction, sizeof...(kParameters)>& sFunctions) {
76  return runImpl(values, covariances, sFunctions, StorageSequence{});
77  }
78 
79  template <typename values_t, typename covariance_t, std::size_t... kStorage>
81  Eigen::MatrixBase<values_t>& values,
82  Eigen::MatrixBase<covariance_t>& covariances,
83  const std::array<SmearFunction, sizeof...(kParameters)>& sFunctions,
84  std::index_sequence<kStorage...>) {
85  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(values_t, sizeof...(kParameters));
86  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(
87  covariance_t, sizeof...(kParameters), sizeof...(kParameters));
88  static_assert(sizeof...(kParameters) == sizeof...(kStorage),
89  "Parameters and storage index packs must have the same size");
90 
91  Acts::Result<void> result;
93  ((scs(kStorage, values, covariances, sFunctions[kStorage], result)), ...);
94  return result;
95  }
96 };
97 
98 } // namespace detail
99 } // namespace ActsFatras