EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Measurement.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Measurement.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 
15 #include "Acts/Geometry/Volume.hpp"
18 
19 #include <memory>
20 #include <ostream>
21 #include <type_traits>
22 #include <utility>
23 
24 namespace Acts {
25 
26 // forward declarations
27 class Surface;
28 
29 namespace detail {
31 template <typename T>
32 struct ReferenceObject {};
33 template <>
35  using type = Surface;
36 };
37 template <>
39  using type = Volume;
40 };
41 } // namespace detail
42 
68 template <typename source_link_t, typename parameter_indices_t,
69  parameter_indices_t... params>
70 class Measurement {
71  // check type conditions
72  static_assert(SourceLinkConcept<source_link_t>,
73  "Source link does not fulfill SourceLinkConcept");
74 
75  // type of the underlying ParameterSet object
76  using ParamSet = ParameterSet<parameter_indices_t, params...>;
77 
78  public:
79  using Scalar = typename ParamSet::Scalar;
90 
92  Measurement() = delete;
93 
103  template <typename... Tail>
104  Measurement(std::shared_ptr<const RefObject> referenceObject,
105  const source_link_t& source, CovarianceMatrix cov,
106  typename std::enable_if<sizeof...(Tail) + 1 == sizeof...(params),
107  Scalar>::type head,
108  Tail... values)
109  : m_oParameters(std::move(cov), head, values...),
110  m_pReferenceObject(std::move(referenceObject)),
111  m_sourceLink(source) {
112  assert(m_pReferenceObject);
113  }
114 
124  Measurement(std::shared_ptr<const RefObject> referenceObject,
125  const source_link_t& source, CovarianceMatrix cov,
126  ParametersVector vec)
127  : m_oParameters(std::move(cov), std::move(vec)),
128  m_pReferenceObject(std::move(referenceObject)),
129  m_sourceLink(source) {
130  assert(m_pReferenceObject);
131  }
132 
133  virtual ~Measurement() = default;
134 
146  m_sourceLink(copy.m_sourceLink) {}
147 
157  : m_oParameters(std::move(other.m_oParameters)),
158  m_pReferenceObject(std::move(other.m_pReferenceObject)),
159  m_sourceLink(std::move(other.m_sourceLink)) {}
160 
168  Measurement<source_link_t, parameter_indices_t, params...>& operator=(
170  // check for self-assignment
171  if (&rhs != this) {
175  }
176  return *this;
177  }
178 
186  Measurement<source_link_t, parameter_indices_t, params...>& operator=(
188  m_oParameters = std::move(rhs.m_oParameters);
189  m_pReferenceObject = std::move(rhs.m_pReferenceObject);
190  m_sourceLink = std::move(rhs.m_sourceLink);
191  return *this;
192  }
193 
203  template <parameter_indices_t parameter>
204  Scalar get() const {
205  return m_oParameters.template getParameter<parameter>();
206  }
207 
215  const ParametersVector& parameters() const {
216  return m_oParameters.getParameters();
217  }
218 
222  const CovarianceMatrix& covariance() const {
223  return *m_oParameters.getCovariance();
224  }
225 
235  template <parameter_indices_t parameter>
236  Scalar uncertainty() const {
237  return m_oParameters.template getUncertainty<parameter>();
238  }
239 
243  static constexpr unsigned int size() { return ParamSet::size(); }
244 
251  const RefObject& referenceObject() const { return *m_pReferenceObject; }
252 
259  const source_link_t& sourceLink() const { return m_sourceLink; }
260 
278  return m_oParameters.residual(trackPars);
279  }
280 
285  virtual bool operator==(const Measurement<source_link_t, parameter_indices_t,
286  params...>& rhs) const {
287  return ((m_oParameters == rhs.m_oParameters) &&
288  (m_pReferenceObject == rhs.m_pReferenceObject) &&
289  (m_sourceLink == rhs.m_sourceLink));
290  }
291 
297  bool operator!=(const Measurement<source_link_t, parameter_indices_t,
298  params...>& rhs) const {
299  return !(*this == rhs);
300  }
301 
303  static const ProjectionMatrix& projector() { return ParamSet::projector(); }
304 
305  friend std::ostream& operator<<(
306  std::ostream& out,
308  m.print(out);
309  return out;
310  }
311 
312  protected:
313  virtual std::ostream& print(std::ostream& out) const {
314  out << sizeof...(params) << "D measurement: ";
315  int dummy[sizeof...(params)] = {(out << params << ", ", 0)...};
316  dummy[0] = dummy[0];
317  out << std::endl;
318  out << "measured values:" << std::endl;
319  out << parameters() << std::endl;
320  out << "covariance matrix:" << std::endl;
321  out << covariance() << std::endl;
322  return out;
323  }
324 
325  private:
327  std::shared_ptr<const RefObject> m_pReferenceObject =
328  nullptr;
329  source_link_t m_sourceLink;
330 };
331 
336 template <typename source_link_t>
338  template <BoundIndices... pars>
339  struct meas_factory {
340  using type = Measurement<source_link_t, BoundIndices, pars...>;
341  };
342 
343  using type = typename detail::type_generator_t<BoundIndices, meas_factory>;
344 };
345 
346 template <typename source_link_t>
348  template <FreeIndices... pars>
349  struct meas_factory {
350  using type = Measurement<source_link_t, FreeIndices, pars...>;
351  };
352 
353  using type = typename detail::type_generator_t<FreeIndices, meas_factory>;
354 };
355 
359 template <typename source_link_t>
360 using FittableMeasurement =
362 
363 template <typename source_link_t>
366 } // namespace Acts