Analysis Software
Documentation for sPHENIX simulation 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 
18 template <typename path_aborter_t, typename propagator_state_t,
19  typename stepper_t>
20 void setupLoopProtection(propagator_state_t& state, const stepper_t& stepper,
21  path_aborter_t& pathAborter, bool releaseLimit,
22  const Logger& logger) {
23  if (!state.options.loopProtection) {
24  return;
25  }
26 
27  if (releaseLimit) {
28  pathAborter.internalLimit =
29  state.options.direction * std::numeric_limits<double>::max();
30  }
31 
32  // Get the field at the start position
33  auto fieldRes =
34  stepper.getField(state.stepping, stepper.position(state.stepping));
35  if (!fieldRes.ok()) {
36  // there's no great way to return the error here, so resort to warning
37  // and not applying the loop protection in this case
38  ACTS_WARNING("Field lookup was unsuccessful, this is very likely an error");
39  return;
40  }
41  const Vector3 field = *fieldRes;
42  const double B = field.norm();
43  if (B == 0) {
44  return;
45  }
46 
47  // Transverse component at start is taken for the loop protection
48  const double p = stepper.absoluteMomentum(state.stepping);
49  // Calculate the full helix path
50  const double helixPath = state.options.direction * 2 * M_PI * p / B;
51  // And set it as the loop limit if it overwrites the internal limit
52  const double loopLimit = state.options.loopFraction * helixPath;
53  const double previousLimit = pathAborter.internalLimit;
54  if (std::abs(loopLimit) < std::abs(previousLimit)) {
55  pathAborter.internalLimit = loopLimit;
56 
57  ACTS_VERBOSE("Path aborter limit set to "
58  << loopLimit << " (full helix = " << helixPath
59  << ", previous limit = " << previousLimit << ")");
60  } else {
61  ACTS_VERBOSE("Path aborter limit not updated to "
62  << loopLimit << " (full helix = " << helixPath
63  << ", previous limit = " << previousLimit << ")");
64  }
65 }
66 
67 } // namespace detail
68 } // namespace Acts