test
CMS 3D CMS Logo

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