CMS 3D CMS Logo

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 63 of file RK4PreciseStep.cc.

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

Referenced by stepWithAccuracy().

64 {
65  return (a.position() - b.position()).mag() + (a.momentum() - b.momentum()).mag() / b.momentum().mag();
66 }
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 7 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()) std::cout << "Accuracy reached, and full step taken in "
23  << nsteps << " steps" << std::endl;
24  return tryStep.first; // we are there
25  }
26  else {
27  remainigStep -= stepSize;
28  // increase step size
29  double factor = std::min( Safety * pow( fabs(eps/tryStep.second),0.2), 4.);
30  stepSize = std::min( stepSize*factor, remainigStep);
31  currentStart = tryStep.first;
32  if (verbose()) std::cout << "Accuracy reached, but " << remainigStep
33  << " remain after " << nsteps << " steps. Step size increased by "
34  << factor << " to " << stepSize << std::endl;
35  }
36  }
37  else {
38  // decrease step size
39  double factor = std::max( Safety * pow( fabs(eps/tryStep.second),0.25), 0.1);
40  stepSize *= factor;
41  if (verbose()) std::cout << "Accuracy not yet reached: delta = " << tryStep.second
42  << ", step reduced by " << factor << " to " << stepSize
43  << ", (R,z)= " << currentStart.position().perp()
44  << ", " << currentStart.position().z() << std::endl;
45  }
46  } while (remainigStep > eps/2);
47 
48  return tryStep.first;
49 }
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:60
step
const Vector3D & position() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::pair< CartesianState, double > RK4PreciseStep::stepWithAccuracy ( const CartesianState start,
const RKCartesianDerivative deriv,
double  step 
) const

Definition at line 52 of file RK4PreciseStep.cc.

References mps_update::diff, and distance().

Referenced by operator()().

54 {
55  RK4OneStep solver;
56  CartesianState one(solver(start, deriv, step));
57  CartesianState firstHalf(solver(start, deriv, step/2));
58  CartesianState secondHalf(solver(firstHalf, deriv, step/2));
59  double diff = distance(one, secondHalf);
60  return std::pair<CartesianState, double>(secondHalf,diff);
61 }
double distance(const CartesianState &a, const CartesianState &b) const
step
bool RK4PreciseStep::verbose ( ) const
private

Definition at line 68 of file RK4PreciseStep.cc.

Referenced by operator()().

69 {
70  return true;
71 }