EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StraightLineStepper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file StraightLineStepper.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 
11 // Workaround for building on clang+libstdc++
13 
24 
25 #include <cmath>
26 #include <functional>
27 
28 namespace Acts {
29 
36  public:
39  using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
40  using CurvilinearState =
41  std::tuple<CurvilinearTrackParameters, Jacobian, double>;
42  using BField = NullBField;
43 
46  struct State {
48  State() = delete;
49 
60  template <typename parameters_t>
61  explicit State(std::reference_wrapper<const GeometryContext> gctx,
62  std::reference_wrapper<const MagneticFieldContext> /*mctx*/,
63  const parameters_t& par, NavigationDirection ndir = forward,
64  double ssize = std::numeric_limits<double>::max(),
65  double stolerance = s_onSurfaceTolerance)
66  : pos(par.position(gctx)),
67  dir(par.unitDirection()),
68  p(par.absoluteMomentum()),
69  q(par.charge()),
70  t(par.time()),
71  navDir(ndir),
72  stepSize(ndir * std::abs(ssize)),
73  tolerance(stolerance),
74  geoContext(gctx) {
75  if (par.covariance()) {
76  // Get the reference surface for navigation
77  const auto& surface = par.referenceSurface();
78  // set the covariance transport flag to true and copy
79  covTransport = true;
80  cov = BoundSymMatrix(*par.covariance());
81  surface.initJacobianToGlobal(gctx, jacToGlobal, pos, dir,
82  par.parameters());
83  }
84  }
85 
87  BoundToFreeMatrix jacToGlobal = BoundToFreeMatrix::Zero();
88 
90  FreeMatrix jacTransport = FreeMatrix::Identity();
91 
93  Jacobian jacobian = Jacobian::Identity();
94 
96  FreeVector derivative = FreeVector::Zero();
97 
99  bool covTransport = false;
100  Covariance cov = Covariance::Zero();
101 
103  Vector3D pos = Vector3D(0., 0., 0.);
104 
106  Vector3D dir = Vector3D(1., 0., 0.);
107 
109  double p = 0.;
110 
112  double q = 0.;
113 
115  double t = 0.;
116 
119 
121  double pathAccumulated = 0.;
122 
125 
126  // Previous step size for overstep estimation (ignored for SL stepper)
127  double previousStepSize = 0.;
128 
131 
132  // Cache the geometry context of this propagation
133  std::reference_wrapper<const GeometryContext> geoContext;
134  };
135 
138  using state_type = State;
139 
141  StraightLineStepper() = default;
142 
151  void resetState(
152  State& state, const BoundVector& boundParams, const BoundSymMatrix& cov,
154  const double stepSize = std::numeric_limits<double>::max()) const;
155 
161  Vector3D getField(State& /*state*/, const Vector3D& /*pos*/) const {
162  // get the field from the cell
163  return Vector3D(0., 0., 0.);
164  }
165 
169  Vector3D position(const State& state) const { return state.pos; }
170 
174  Vector3D direction(const State& state) const { return state.dir; }
175 
179  double momentum(const State& state) const { return state.p; }
180 
184  double charge(const State& state) const { return state.q; }
185 
189  double time(const State& state) const { return state.t; }
190 
194  double overstepLimit(const State& /*state*/) const {
195  return s_onSurfaceTolerance;
196  }
197 
209  State& state, const Surface& surface, const BoundaryCheck& bcheck) const {
210  return detail::updateSingleSurfaceStatus<StraightLineStepper>(
211  *this, state, surface, bcheck);
212  }
213 
222  template <typename object_intersection_t>
223  void updateStepSize(State& state, const object_intersection_t& oIntersection,
224  bool release = true) const {
225  detail::updateSingleStepSize<StraightLineStepper>(state, oIntersection,
226  release);
227  }
228 
234  void setStepSize(State& state, double stepSize,
236  state.previousStepSize = state.stepSize;
237  state.stepSize.update(stepSize, stype, true);
238  }
239 
243  void releaseStepSize(State& state) const {
245  }
246 
250  std::string outputStepSize(const State& state) const {
251  return state.stepSize.toString();
252  }
253 
266  BoundState boundState(State& state, const Surface& surface) const;
267 
278  CurvilinearState curvilinearState(State& state) const;
279 
284  void update(State& state, const FreeVector& parameters,
285  const Covariance& covariance) const;
286 
294  void update(State& state, const Vector3D& uposition,
295  const Vector3D& udirection, double up, double time) const;
296 
302  void covarianceTransport(State& state) const;
303 
315  void covarianceTransport(State& state, const Surface& surface) const;
316 
327  template <typename propagator_state_t>
328  Result<double> step(propagator_state_t& state) const {
329  // use the adjusted step size
330  const auto h = state.stepping.stepSize;
331  // time propagates along distance as 1/b = sqrt(1 + m²/p²)
332  const auto dtds = std::hypot(1., state.options.mass / state.stepping.p);
333  // Update the track parameters according to the equations of motion
334  state.stepping.pos += h * state.stepping.dir;
335  state.stepping.t += h * dtds;
336  // Propagate the jacobian
337  if (state.stepping.covTransport) {
338  // The step transport matrix in global coordinates
339  FreeMatrix D = FreeMatrix::Identity();
340  D.block<3, 3>(0, 4) = ActsSymMatrixD<3>::Identity() * h;
341  // Extend the calculation by the time propagation
342  // Evaluate dt/dlambda
343  D(3, 7) = h * state.options.mass * state.options.mass *
344  (state.stepping.q == 0. ? 1. : state.stepping.q) /
345  (state.stepping.p * dtds);
346  // Set the derivative factor the time
347  state.stepping.derivative(3) = dtds;
348  // Update jacobian and derivative
349  state.stepping.jacTransport = D * state.stepping.jacTransport;
350  state.stepping.derivative.template head<3>() = state.stepping.dir;
351  }
352  // state the path length
353  state.stepping.pathAccumulated += h;
354 
355  // return h
356  return h;
357  }
358 };
359 
360 } // namespace Acts