ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoopProtection.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LoopProtection.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 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 
13 
14 namespace Acts {
15 namespace detail {
16 
17 template <typename path_arborter_t>
26  template <typename propagator_state_t, typename stepper_t>
27  void operator()(propagator_state_t& state, const stepper_t& stepper) const {
28  // Estimate the loop protection limit
29  if (state.options.loopProtection) {
30  // Get the field at the start position
31  Vector3D field =
32  stepper.getField(state.stepping, stepper.position(state.stepping));
33  const double B = field.norm();
34  if (B != 0.) {
35  // Transverse component at start is taken for the loop protection
36  const double p = stepper.momentum(state.stepping);
37  // Calculate the full helix path
38  const double helixPath = state.stepping.navDir * 2 * M_PI * p / B;
39  // And set it as the loop limit if it overwrites the internal limit
40  auto& pathAborter =
41  state.options.abortList.template get<path_arborter_t>();
42  double loopLimit = state.options.loopFraction * helixPath;
43  double pathLimit = pathAborter.internalLimit;
44  if (loopLimit * loopLimit < pathLimit * pathLimit) {
45  pathAborter.internalLimit = loopLimit;
46  debugLog(state, [&] {
47  std::stringstream dstream;
48  dstream << "Path aborter limit set to ";
49  dstream << loopLimit << " (full helix = " << helixPath << ")";
50  return dstream.str();
51  });
52  }
53  }
54  }
55  }
56 
69  template <typename propagator_state_t>
70  void debugLog(propagator_state_t& state,
71  const std::function<std::string()>& logAction) const {
72  if (state.options.debug) {
73  std::vector<std::string> lines;
74  std::string input = logAction();
75  boost::split(lines, input, boost::is_any_of("\n"));
76  for (const auto& line : lines) {
77  std::stringstream dstream;
78  dstream << '\n';
79  dstream << " ∞ " << std::setw(state.options.debugPfxWidth)
80  << " loop protection "
81  << " | ";
82  dstream << std::setw(state.options.debugMsgWidth) << line << '\n';
83  state.options.debugString += dstream.str();
84  }
85  }
86  }
87 };
88 
89 } // namespace detail
90 } // namespace Acts