CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions
RK4PreciseStep Class Reference

#include <RK4PreciseStep.h>

Public Member Functions

double distance (const CartesianState &a, const CartesianState &b) const
 
CartesianState operator() (const CartesianState &start, const RKCartesianDerivative &deriv, double step, double eps) const
 
std::pair< CartesianState, double > stepWithAccuracy (const CartesianState &start, const RKCartesianDerivative &deriv, double step) const
 

Private Member Functions

bool verbose () const
 

Detailed Description

Definition at line 10 of file RK4PreciseStep.h.

Member Function Documentation

double RK4PreciseStep::distance ( const CartesianState a,
const CartesianState b 
) const

Definition at line 60 of file RK4PreciseStep.cc.

References Basic3DVector< T >::mag(), mag(), CartesianState::momentum(), and CartesianState::position().

Referenced by stepWithAccuracy().

60  {
61  return (a.position() - b.position()).mag() + (a.momentum() - b.momentum()).mag() / b.momentum().mag();
62 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const Vector3D & momentum() const
const Vector3D & position() const
CartesianState RK4PreciseStep::operator() ( const CartesianState start,
const RKCartesianDerivative deriv,
double  step,
double  eps 
) const

Definition at line 6 of file RK4PreciseStep.cc.

References gather_cfg::cout, mps_splice::currentStart, SiStripPI::max, min(), Basic3DVector< T >::perp(), CartesianState::position(), funct::pow(), command_line::start, stepWithAccuracy(), verbose(), and Basic3DVector< T >::z().

9  {
10  const double Safety = 0.9;
11  double remainigStep = step;
12  double stepSize = step;
14  int nsteps = 0;
15  std::pair<CartesianState, double> tryStep;
16 
17  do {
18  tryStep = stepWithAccuracy(currentStart, deriv, stepSize);
19  nsteps++;
20  if (tryStep.second < eps) {
21  if (remainigStep - stepSize < eps / 2) {
22  if (verbose())
23  std::cout << "Accuracy reached, and full step taken in " << nsteps << " steps" << std::endl;
24  return tryStep.first; // we are there
25  } else {
26  remainigStep -= stepSize;
27  // increase step size
28  double factor = std::min(Safety * pow(fabs(eps / tryStep.second), 0.2), 4.);
29  stepSize = std::min(stepSize * factor, remainigStep);
30  currentStart = tryStep.first;
31  if (verbose())
32  std::cout << "Accuracy reached, but " << remainigStep << " remain after " << nsteps
33  << " steps. Step size increased by " << factor << " to " << stepSize << std::endl;
34  }
35  } else {
36  // decrease step size
37  double factor = std::max(Safety * pow(fabs(eps / tryStep.second), 0.25), 0.1);
38  stepSize *= factor;
39  if (verbose())
40  std::cout << "Accuracy not yet reached: delta = " << tryStep.second << ", step reduced by " << factor << " to "
41  << stepSize << ", (R,z)= " << currentStart.position().perp() << ", " << currentStart.position().z()
42  << std::endl;
43  }
44  } while (remainigStep > eps / 2);
45 
46  return tryStep.first;
47 }
WorkSpace int float eps
bool verbose() const
T z() const
Cartesian z coordinate.
std::pair< CartesianState, double > stepWithAccuracy(const CartesianState &start, const RKCartesianDerivative &deriv, double step) const
T min(T a, T b)
Definition: MathUtil.h:58
T perp() const
Magnitude of transverse component.
int currentStart
Definition: mps_splice.py:66
tuple cout
Definition: gather_cfg.py:144
step
Definition: StallMonitor.cc:94
const Vector3D & position() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
std::pair< CartesianState, double > RK4PreciseStep::stepWithAccuracy ( const CartesianState start,
const RKCartesianDerivative deriv,
double  step 
) const

Definition at line 49 of file RK4PreciseStep.cc.

References change_name::diff, distance(), and SiPixelPI::one.

Referenced by operator()().

51  {
52  RK4OneStep solver;
53  CartesianState one(solver(start, deriv, step));
54  CartesianState firstHalf(solver(start, deriv, step / 2));
55  CartesianState secondHalf(solver(firstHalf, deriv, step / 2));
56  double diff = distance(one, secondHalf);
57  return std::pair<CartesianState, double>(secondHalf, diff);
58 }
double distance(const CartesianState &a, const CartesianState &b) const
step
Definition: StallMonitor.cc:94
bool RK4PreciseStep::verbose ( ) const
private

Definition at line 64 of file RK4PreciseStep.cc.

Referenced by operator()().

64 { return true; }