CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IterativeHelixExtrapolatorToLine.cc
Go to the documentation of this file.
2 #include <iostream>
3 
5  const DirectionType& direction,
6  const float curvature,
7  const PropagationDirection propDir)
8  : theX0(point.x()),
9  theY0(point.y()),
10  theZ0(point.z()),
11  theRho(curvature),
12  theQuadraticSolutionFromStart(point, direction, curvature, propDir),
13  thePropDir(propDir),
14  theCachedS(0),
15  theCachedDPhi(0.),
16  theCachedSDPhi(0.),
17  theCachedCDPhi(1.) {
18  //
19  // Components of direction vector (with correct normalisation)
20  //
21  double px = direction.x();
22  double py = direction.y();
23  double pz = direction.z();
24  double pt = px * px + py * py;
25  double p = sqrt(pt + pz * pz);
26  pt = sqrt(pt);
27  theCosPhi0 = px / pt;
28  theSinPhi0 = py / pt;
29  theCosTheta = pz / p;
30  theSinTheta = pt / p;
31 }
32 
37 std::pair<bool, double> IterativeHelixExtrapolatorToLine::pathLength(const GlobalPoint& point) const {
38  return genericPathLength(point);
39 }
40 
45 std::pair<bool, double> IterativeHelixExtrapolatorToLine::pathLength(const Line& line) const {
46  return genericPathLength(line);
47 }
48 
49 //
50 // Propagation status and path length to intersection
51 //
52 template <class T>
53 std::pair<bool, double> IterativeHelixExtrapolatorToLine::genericPathLength(const T& object) const {
54  //
55  // Constants used for control of convergence
56  //
57  const int maxIterations(100);
58  //
59  // Prepare internal value of the propagation direction and position / direction vectors for iteration
60  //
64  //
65  // Prepare iterations: count and total pathlength
66  //
67  unsigned int iteration(maxIterations + 1);
68  double dSTotal(0.);
69  //
70  // Convergence criterion: maximal lateral displacement in a step < 1um
71  //
72  double maxDeltaS2 = 2 * 1.e-4 / theSinTheta / theSinTheta / fabs(theRho);
73  //
74  bool first(true);
75  while (true) {
76  //
77  // return empty solution vector if no convergence after maxIterations iterations
78  //
79  if (--iteration == 0) {
80  return std::pair<bool, double>(false, 0);
81  }
82  //
83  // Use existing second order object at first pass, create temporary object
84  // for subsequent passes.
85  //
86  std::pair<bool, double> deltaS1;
87  if (first) {
88  first = false;
89  deltaS1 = theQuadraticSolutionFromStart.pathLength(object);
90  } else {
91  HelixExtrapolatorToLine2Order linearCrossing(
92  xnew.x(), xnew.y(), xnew.z(), pnew.x(), pnew.y(), theCosTheta, theSinTheta, theRho, anyDirection);
93  deltaS1 = linearCrossing.pathLength(object);
94  }
95  if (!deltaS1.first)
96  return deltaS1;
97  //
98  // Calculate total pathlength
99  //
100  dSTotal += deltaS1.second;
101  PropagationDirection newDir = dSTotal >= 0 ? alongMomentum : oppositeToMomentum;
102  if (propDir == anyDirection) {
103  propDir = newDir;
104  } else {
105  if (newDir != propDir)
106  return std::pair<bool, double>(false, 0);
107  }
108  //
109  // Check convergence
110  //
111  if (deltaS1.second * deltaS1.second < maxDeltaS2)
112  break;
113  //
114  // Step forward by dSTotal.
115  //
116  xnew = positionInDouble(dSTotal);
117  pnew = directionInDouble(dSTotal);
118  }
119  //
120  // Return result
121  //
122  return std::pair<bool, double>(true, dSTotal);
123 }
124 
125 //
126 // Position on helix after a step of path length s.
127 //
129  // use result in double precision
130  return PositionType(positionInDouble(s));
131 }
132 
133 //
134 // Position on helix after a step of path length s in double precision.
135 //
137  //
138  // Calculate delta phi (if not already available)
139  //
140  if (s != theCachedS) {
141  theCachedS = s;
145  }
146  //
147  // Calculate with appropriate formulation of full helix formula or with
148  // 1st order approximation.
149  //
150  // if ( fabs(theCachedDPhi)>1.e-1 ) {
151  if (fabs(theCachedDPhi) > 1.e-4) {
152  // "standard" helix formula
154  theY0 + (theCosPhi0 * (1. - theCachedCDPhi) + theSinPhi0 * theCachedSDPhi) / theRho,
156  }
157  // else if ( fabs(theCachedDPhi)>theNumericalPrecision ) {
158  // // full helix formula, but avoiding (1-cos(deltaPhi)) for small angles
159  // return PositionTypeDouble(theX0+(-theSinPhi0*theCachedSDPhi*theCachedSDPhi/(1.+theCachedCDPhi)+
160  // theCosPhi0*theCachedSDPhi)/theRho,
161  // theY0+(theCosPhi0*theCachedSDPhi*theCachedSDPhi/(1.+theCachedCDPhi)+
162  // theSinPhi0*theCachedSDPhi)/theRho,
163  // theZ0+theCachedS*theCosTheta);
164  // }
165  else {
166  // Use 1st order.
168  }
169 }
170 
171 //
172 // Direction vector on helix after a step of path length s.
173 //
175  // use result in double precision
176  // DirectionTypeDouble dir = directionInDouble(s);
177  // return DirectionType(dir.x(),dir.y(),dir.z());
178  return DirectionType(directionInDouble(s));
179 }
180 
181 //
182 // Direction vector on helix after a step of path length s in double precision.
183 //
185  //
186  // Calculate delta phi (if not already available)
187  //
188  if (s != theCachedS) {
189  theCachedS = s;
193  }
194 
195  if (fabs(theCachedDPhi) > 1.e-4) {
196  // full helix formula
198  theSinPhi0 * theCachedCDPhi + theCosPhi0 * theCachedSDPhi,
200  } else {
201  // 1st order
203  }
204 }
PositionTypeDouble positionInDouble(double s) const
PositionTypeDouble positionInDouble(double s) const
Position at pathlength s from the starting point in double precision.
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
IterativeHelixExtrapolatorToLine(const PositionType &point, const DirectionType &direction, const float curvature, const PropagationDirection propDir=anyDirection)
DirectionTypeDouble directionInDouble(double s) const
Definition: Line.h:10
Basic3DVector< double > PositionTypeDouble
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PropagationDirection
Basic3DVector< double > DirectionTypeDouble
float float float z
T curvature(T InversePt, const MagneticField &field)
std::pair< bool, double > genericPathLength(const T &object) const
common functionality for extrapolation to line or point
Basic3DVector< float > DirectionType
tuple iteration
Definition: align_cfg.py:5
PositionType position(double s) const override
Basic3DVector< float > PositionType
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
DirectionType direction(double s) const override
std::pair< bool, double > pathLength(const GlobalPoint &point) const override
DirectionTypeDouble directionInDouble(double s) const
Direction at pathlength s from the starting point in double precision.
HelixExtrapolatorToLine2Order theQuadraticSolutionFromStart
std::pair< bool, double > pathLength(const GlobalPoint &point) const override
long double T
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5