Analysis Software
Documentation for sPHENIX simulation 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 
17 
18 #include <array>
19 #include <functional>
20 #include <utility>
21 
22 namespace ActsFatras {
23 
30 template <typename generator_t>
32  std::function<Acts::Result<std::pair<double, double>>(double,
33  generator_t&)>;
34 
42 template <typename generator_t, size_t kSize>
48 
50  std::array<Acts::BoundIndices, kSize> indices{};
51  std::array<SingleParameterSmearFunction<generator_t>, kSize> smearFunctions{};
52 
53  static constexpr size_t size() { return kSize; }
54 
63  Result operator()(generator_t& rng, const Hit& hit,
64  const Acts::Surface& surface,
65  const Acts::GeometryContext& geoCtx) const {
66  // We use the thickness of the detector element as tolerance, because Geant4
67  // treats the Surfaces as volumes and thus it is not ensured, that each hit
68  // lies exactly on the Acts::Surface
69  const auto tolerance =
70  surface.associatedDetectorElement() != nullptr
73 
74  // construct full bound parameters. they are probably not all needed, but it
75  // is easier to just create them all and then select the requested ones.
76  Acts::Result<Acts::BoundVector> boundParamsRes =
78  hit.position(), hit.time(), hit.direction(), 0, surface, geoCtx,
79  tolerance);
80 
81  if (!boundParamsRes.ok()) {
82  return boundParamsRes.error();
83  }
84 
85  const auto& boundParams = *boundParamsRes;
86 
87  ParametersVector par = ParametersVector::Zero();
88  CovarianceMatrix cov = CovarianceMatrix::Zero();
89  for (int i = 0; i < static_cast<int>(kSize); ++i) {
90  auto res = smearFunctions[i](boundParams[indices[i]], rng);
91  if (not res.ok()) {
92  return Result::failure(res.error());
93  }
94  auto [value, stddev] = res.value();
95  par[i] = value;
96  cov(i, i) = stddev * stddev;
97  }
98 
99  return Result::success(std::make_pair(par, cov));
100  }
101 };
102 
113 template <typename generator_t, size_t kSize>
119 
121  std::array<Acts::FreeIndices, kSize> indices{};
122  std::array<SingleParameterSmearFunction<generator_t>, kSize> smearFunctions;
123 
124  static constexpr size_t size() { return kSize; }
125 
133  Result operator()(generator_t& rng, const Hit& hit) const {
134  // construct full free parameters. they are probably not all needed, but it
135  // is easier to just create them all and then select the requested ones.
136  Acts::FreeVector freeParams;
137  freeParams.segment<3>(Acts::eFreePos0) = hit.position();
138  freeParams[Acts::eFreeTime] = hit.time();
139  freeParams.segment<3>(Acts::eFreeDir0) = hit.direction();
140  freeParams[Acts::eFreeQOverP] = 0;
141 
142  ParametersVector par = ParametersVector::Zero();
143  CovarianceMatrix cov = CovarianceMatrix::Zero();
144  for (size_t i = 0; i < kSize; ++i) {
145  auto res = smearFunctions[i](freeParams[indices[i]], rng);
146  if (not res.ok()) {
147  return Result::failure(res.error());
148  }
149  auto [value, stddev] = res.value();
150  par[i] = value;
151  cov(i, i) = stddev * stddev;
152  }
153 
154  return Result::success(std::make_pair(par, cov));
155  }
156 };
157 
158 } // namespace ActsFatras