File indexing completed on 2024-04-06 12:31:29
0001 #include "TrackingTools/GeomPropagators/interface/IterativeHelixExtrapolatorToLine.h"
0002 #include <iostream>
0003
0004 IterativeHelixExtrapolatorToLine::IterativeHelixExtrapolatorToLine(const PositionType& point,
0005 const DirectionType& direction,
0006 const float curvature,
0007 const PropagationDirection propDir)
0008 : theX0(point.x()),
0009 theY0(point.y()),
0010 theZ0(point.z()),
0011 theRho(curvature),
0012 theQuadraticSolutionFromStart(point, direction, curvature, propDir),
0013 thePropDir(propDir),
0014 theCachedS(0),
0015 theCachedDPhi(0.),
0016 theCachedSDPhi(0.),
0017 theCachedCDPhi(1.) {
0018
0019
0020
0021 double px = direction.x();
0022 double py = direction.y();
0023 double pz = direction.z();
0024 double pt = px * px + py * py;
0025 double p = sqrt(pt + pz * pz);
0026 pt = sqrt(pt);
0027 theCosPhi0 = px / pt;
0028 theSinPhi0 = py / pt;
0029 theCosTheta = pz / p;
0030 theSinTheta = pt / p;
0031 }
0032
0033
0034
0035
0036
0037 std::pair<bool, double> IterativeHelixExtrapolatorToLine::pathLength(const GlobalPoint& point) const {
0038 return genericPathLength(point);
0039 }
0040
0041
0042
0043
0044
0045 std::pair<bool, double> IterativeHelixExtrapolatorToLine::pathLength(const Line& line) const {
0046 return genericPathLength(line);
0047 }
0048
0049
0050
0051
0052 template <class T>
0053 std::pair<bool, double> IterativeHelixExtrapolatorToLine::genericPathLength(const T& object) const {
0054
0055
0056
0057 const int maxIterations(100);
0058
0059
0060
0061 PropagationDirection propDir = thePropDir;
0062 PositionTypeDouble xnew(theX0, theY0, theZ0);
0063 DirectionTypeDouble pnew(theCosPhi0, theSinPhi0, theCosTheta / theSinTheta);
0064
0065
0066
0067 unsigned int iteration(maxIterations + 1);
0068 double dSTotal(0.);
0069
0070
0071
0072 double maxDeltaS2 = 2 * 1.e-4 / theSinTheta / theSinTheta / fabs(theRho);
0073
0074 bool first(true);
0075 while (true) {
0076
0077
0078
0079 if (--iteration == 0) {
0080 return std::pair<bool, double>(false, 0);
0081 }
0082
0083
0084
0085
0086 std::pair<bool, double> deltaS1;
0087 if (first) {
0088 first = false;
0089 deltaS1 = theQuadraticSolutionFromStart.pathLength(object);
0090 } else {
0091 HelixExtrapolatorToLine2Order linearCrossing(
0092 xnew.x(), xnew.y(), xnew.z(), pnew.x(), pnew.y(), theCosTheta, theSinTheta, theRho, anyDirection);
0093 deltaS1 = linearCrossing.pathLength(object);
0094 }
0095 if (!deltaS1.first)
0096 return deltaS1;
0097
0098
0099
0100 dSTotal += deltaS1.second;
0101 PropagationDirection newDir = dSTotal >= 0 ? alongMomentum : oppositeToMomentum;
0102 if (propDir == anyDirection) {
0103 propDir = newDir;
0104 } else {
0105 if (newDir != propDir)
0106 return std::pair<bool, double>(false, 0);
0107 }
0108
0109
0110
0111 if (deltaS1.second * deltaS1.second < maxDeltaS2)
0112 break;
0113
0114
0115
0116 xnew = positionInDouble(dSTotal);
0117 pnew = directionInDouble(dSTotal);
0118 }
0119
0120
0121
0122 return std::pair<bool, double>(true, dSTotal);
0123 }
0124
0125
0126
0127
0128 HelixLineExtrapolation::PositionType IterativeHelixExtrapolatorToLine::position(double s) const {
0129
0130 return PositionType(positionInDouble(s));
0131 }
0132
0133
0134
0135
0136 HelixLineExtrapolation::PositionTypeDouble IterativeHelixExtrapolatorToLine::positionInDouble(double s) const {
0137
0138
0139
0140 if (s != theCachedS) {
0141 theCachedS = s;
0142 theCachedDPhi = theCachedS * theRho * theSinTheta;
0143 theCachedSDPhi = sin(theCachedDPhi);
0144 theCachedCDPhi = cos(theCachedDPhi);
0145 }
0146
0147
0148
0149
0150
0151 if (fabs(theCachedDPhi) > 1.e-4) {
0152
0153 return PositionTypeDouble(theX0 + (-theSinPhi0 * (1. - theCachedCDPhi) + theCosPhi0 * theCachedSDPhi) / theRho,
0154 theY0 + (theCosPhi0 * (1. - theCachedCDPhi) + theSinPhi0 * theCachedSDPhi) / theRho,
0155 theZ0 + theCachedS * theCosTheta);
0156 }
0157
0158
0159
0160
0161
0162
0163
0164
0165 else {
0166
0167 return theQuadraticSolutionFromStart.positionInDouble(theCachedS);
0168 }
0169 }
0170
0171
0172
0173
0174 HelixLineExtrapolation::DirectionType IterativeHelixExtrapolatorToLine::direction(double s) const {
0175
0176
0177
0178 return DirectionType(directionInDouble(s));
0179 }
0180
0181
0182
0183
0184 HelixLineExtrapolation::DirectionTypeDouble IterativeHelixExtrapolatorToLine::directionInDouble(double s) const {
0185
0186
0187
0188 if (s != theCachedS) {
0189 theCachedS = s;
0190 theCachedDPhi = theCachedS * theRho * theSinTheta;
0191 theCachedSDPhi = sin(theCachedDPhi);
0192 theCachedCDPhi = cos(theCachedDPhi);
0193 }
0194
0195 if (fabs(theCachedDPhi) > 1.e-4) {
0196
0197 return DirectionTypeDouble(theCosPhi0 * theCachedCDPhi - theSinPhi0 * theCachedSDPhi,
0198 theSinPhi0 * theCachedCDPhi + theCosPhi0 * theCachedSDPhi,
0199 theCosTheta / theSinTheta);
0200 } else {
0201
0202 return theQuadraticSolutionFromStart.directionInDouble(theCachedS);
0203 }
0204 }