EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UncorrelatedHitSmearer.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file UncorrelatedHitSmearer.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 
19 
20 #include <functional>
21 
22 namespace ActsFatras {
23 
27 using SmearFunction =
28  std::function<Acts::Result<std::pair<double, double>>(double)>;
29 
33 struct SmearInput {
36  SmearInput(std::reference_wrapper<const Hit> hit_,
37  std::reference_wrapper<const Acts::GeometryContext> geoContext_,
38  std::shared_ptr<const Acts::Surface> surface_ = nullptr)
39  : hit(hit_), geoContext(geoContext_), surface(surface_) {}
40 
41  SmearInput() = delete;
42 
43  std::reference_wrapper<const Hit> hit;
44  std::reference_wrapper<const Acts::GeometryContext> geoContext;
45  std::shared_ptr<const Acts::Surface> surface = nullptr;
46 };
47 
57 template <Acts::BoundIndices... kParameters>
68  operator()(const SmearInput& sInput,
69  const std::array<SmearFunction, sizeof...(kParameters)>&
70  sFunctions) const {
71  using ParSet = Acts::ParameterSet<Acts::BoundIndices, kParameters...>;
72  using Result = Acts::Result<ParSet>;
73  using ParametersSmearer =
75 
76  if (sInput.surface == nullptr) {
77  return Result(ActsFatras::DigitizationError::NoSurfaceDefined);
78  }
79 
80  const auto& hit = sInput.hit.get();
81 
82  auto dir = hit.unitDirection();
83  auto gltResult =
84  sInput.surface->globalToLocal(sInput.geoContext, hit.position(), dir);
85  if (not gltResult.ok()) {
86  return Result(Acts::SurfaceError::GlobalPositionNotOnSurface);
87  }
88  const auto& lPosition = gltResult.value();
89 
90  typename ParSet::FullParametersVector fParameters;
91  fParameters.setZero();
92  fParameters.template segment<2>(0) = lPosition;
93  fParameters[Acts::eBoundPhi] = Acts::VectorHelpers::phi(dir);
95  fParameters[Acts::eBoundTime] = hit.time();
96  typename ParSet::ParametersVector sParameters =
97  ParSet::projector() * fParameters;
98 
99  typename ParSet::CovarianceMatrix sCovariance;
100  sCovariance.setZero();
101 
102  auto smearResult =
103  ParametersSmearer::run(sParameters, sCovariance, sFunctions);
104  if (not smearResult.ok()) {
105  return Result(smearResult.error());
106  }
107  return ParSet{sCovariance, sParameters};
108  }
109 };
110 
114 template <Acts::FreeIndices... kParameters>
126  operator()(const SmearInput& sInput,
127  const std::array<SmearFunction, sizeof...(kParameters)>&
128  sFunctions) const {
129  using ParSet = Acts::ParameterSet<Acts::FreeIndices, kParameters...>;
130  using Result = Acts::Result<ParSet>;
131  using ParametersSmearer =
133 
134  const auto& hit = sInput.hit.get();
135 
136  typename ParSet::FullParametersVector fParameters;
137  fParameters.setZero();
138  fParameters.template segment<4>(0) = hit.position4();
139  fParameters.template segment<3>(4) = hit.unitDirection();
140  typename ParSet::ParametersVector sParameters =
141  ParSet::projector() * fParameters;
142  typename ParSet::CovarianceMatrix sCovariance;
143  sCovariance.setZero();
144 
145  auto smearResult =
146  ParametersSmearer::run(sParameters, sCovariance, sFunctions);
147  if (not smearResult.ok()) {
148  return Result(smearResult.error());
149  }
150  return ParSet{sCovariance, sParameters};
151  }
152 };
153 
154 } // namespace ActsFatras