EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterSet.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParameterSet.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 
23 
24 #include <optional>
25 #include <type_traits>
26 
27 namespace Acts {
28 
29 // Parameter sets corresponding to the full parameters vector
32 
76 template <typename parameter_indices_t, parameter_indices_t... params>
77 class ParameterSet {
78  private:
80  static constexpr unsigned int kNumberOfParameters = sizeof...(params);
82  static constexpr unsigned int kSizeMax =
83  detail::kParametersSize<parameter_indices_t>;
84 
85  // static assert to check that the template parameters are consistent
86  static_assert(
88  "parameter identifiers are not sorted");
89  static_assert(
90  detail::are_within<unsigned int, 0, kSizeMax,
91  static_cast<unsigned int>(params)...>::value,
92  "parameter identifiers must be greater or "
93  "equal to zero and smaller than the total number of parameters");
94  static_assert(kNumberOfParameters > 0,
95  "number of stored parameters can not be zero");
96  static_assert(
98  "number of stored parameters can not exceed number of total parameters");
99 
100  public:
108 
119  template <typename... Tail>
121  std::optional<CovarianceMatrix> cov,
122  std::enable_if_t<sizeof...(Tail) + 1 == kNumberOfParameters, Scalar> head,
123  Tail... values)
125  if (cov) {
126  m_optCovariance = std::move(*cov);
127  }
128  detail::initialize_parset<parameter_indices_t, params...>::init_vals(
129  *this, head, values...);
130  }
131 
144  ParameterSet(std::optional<CovarianceMatrix> cov,
145  const ParametersVector& values)
147  if (cov) {
148  m_optCovariance = std::move(*cov);
149  }
150  detail::initialize_parset<parameter_indices_t, params...>::init_vec(*this,
151  values);
152  }
153 
154  // this class does not have a custom default constructor and thus should not
155  // provide any custom default cstors, dstor, or assignment. see ISOCPP C.20.
156 
166  template <parameter_indices_t parameter>
167  static constexpr size_t getIndex() {
168  return detail::get_position<parameter_indices_t, parameter,
169  params...>::value;
170  }
171 
183  template <size_t index>
184  static constexpr parameter_indices_t getParameterIndex() {
185  return detail::at_index<parameter_indices_t, index, params...>::value;
186  }
187 
197  template <parameter_indices_t parameter>
199  return m_vValues(getIndex<parameter>());
200  }
201 
207  const ParametersVector& getParameters() const { return m_vValues; }
208 
219  template <parameter_indices_t parameter>
221  m_vValues(getIndex<parameter>()) =
223  value);
224  }
225 
236  detail::initialize_parset<parameter_indices_t, params...>::init_vec(*this,
237  values);
238  }
239 
251  template <parameter_indices_t parameter>
252  bool contains() const {
253  return detail::is_contained<parameter_indices_t, parameter,
254  params...>::value;
255  }
256 
265  const std::optional<CovarianceMatrix>& getCovariance() const {
266  return m_optCovariance;
267  }
268 
281  template <parameter_indices_t parameter>
283  if (m_optCovariance) {
284  size_t index = getIndex<parameter>();
285  return sqrt((*m_optCovariance)(index, index));
286  } else {
287  return -1;
288  }
289  }
290 
299 
334  m_vValues, projector() * other);
335  }
336 
369  ParametersVector residual(const ParameterSet& otherParSet) const {
371  m_vValues, otherParSet.m_vValues);
372  }
373 
384  static const ProjectionMatrix& projector() { return sProjector; }
385 
391  static constexpr unsigned int size() { return kNumberOfParameters; }
392 
407  }
408 
410  bool operator==(const ParameterSet& other) const {
411  return (this == &other) or ((m_vValues == other.m_vValues) and
412  (m_optCovariance == other.m_optCovariance));
413  }
415  bool operator!=(const ParameterSet& other) const { return !(*this == other); }
416 
417  private:
419  ParametersVector m_vValues{ParametersVector::Zero()};
421  std::optional<CovarianceMatrix> m_optCovariance{std::nullopt};
422 
425 };
426 
427 template <typename parameter_indices_t, parameter_indices_t... kParameters>
428 const typename ParameterSet<parameter_indices_t,
429  kParameters...>::ProjectionMatrix
430  ParameterSet<parameter_indices_t, kParameters...>::sProjector =
431  detail::make_projection_matrix<
432  kSizeMax, static_cast<unsigned int>(kParameters)...>::init();
433 
434 } // namespace Acts