11 bool isFirstALine = firstGTP->charge() == 0. || firstGTP->magneticField().inTesla(firstGTP->position()).z() == 0.;
12 bool isSecondALine = secondGTP->charge() == 0. || secondGTP->magneticField().inTesla(secondGTP->position()).z() == 0.;
13 if (isFirstALine && !isSecondALine) {
16 }
else if (!isFirstALine && isSecondALine) {
21 <<
"Error in track charge: " 22 <<
"One of the tracks has to be charged, and the other not." << endl
23 <<
"Track Charges: " << firstGTP->charge() <<
" and " << secondGTP->charge();
27 Hn = theH->momentum().mag();
28 Ln = theL->momentum().mag();
30 if (Hn == 0. || Ln == 0.) {
31 edm::LogWarning(
"TwoTrackMinimumDistanceHelixLine") <<
"Momentum of input trajectory is zero.";
41 theLp = theL->momentum();
49 const double Bc2kH = theH->magneticField().inTesla(hOrig).z() * 2.99792458e-3;
53 edm::LogWarning(
"TwoTrackMinimumDistanceHelixLine") <<
"Magnetic field at point " << hOrig <<
" is zero.";
57 theh = -Hn / (theH->charge() * Bc2kH) *
sqrt(1 - (((theH->momentum().z() * theH->momentum().z()) / (Hn * Hn))));
59 thetanlambdaH = -theH->momentum().z() / (theH->charge() * Bc2kH * theh);
61 thePhiH0 = theH->momentum().phi();
62 thesinPhiH0 =
sin(thePhiH0);
63 thecosPhiH0 =
cos(thePhiH0);
65 aa = (
X + theh * thesinPhiH0) * (py2 + pz2) -
px * (
py *
Y + pz *
Z);
66 bb = (
Y - theh * thecosPhiH0) * (px2 + pz2) -
py * (
px *
X + pz *
Z);
67 cc = pz * theh * thetanlambdaH;
69 ee = theh * (px2 - py2);
70 ff = (px2 + py2) * theh * thetanlambdaH * thetanlambdaH;
72 baseFct = thetanlambdaH * (
Z * (px2 + py2) - pz * (
px *
X +
py *
Y));
78 double thesinPhiH =
sin(thePhiH);
79 double thecosPhiH =
cos(thePhiH);
84 fct -=
ff * (thePhiH - thePhiH0);
85 fct += thecosPhiH * aa;
86 fct += thesinPhiH * bb;
87 fct +=
cc * (thePhiH - thePhiH0) * (
px * thecosPhiH +
py * thesinPhiH);
88 fct +=
cc * (
px * (thesinPhiH - thesinPhiH0) -
py * (thecosPhiH - thecosPhiH0));
89 fct +=
dd * (thesinPhiH * (thesinPhiH - thesinPhiH0) - thecosPhiH * (thecosPhiH - thecosPhiH0));
90 fct += ee * thecosPhiH * thesinPhiH;
97 derivative +=
cc * (thePhiH - thePhiH0) * (
py * thecosPhiH -
px * thesinPhiH);
99 derivative +=
dd * (4 * thecosPhiH * thesinPhiH - thecosPhiH * thesinPhiH0 - thesinPhiH * thecosPhiH0);
100 derivative += ee * (thecosPhiH * thecosPhiH - thesinPhiH * thesinPhiH);
108 pointsUpdated =
false;
109 firstGTP = &theFirstGTP;
110 secondGTP = &theSecondGTP;
112 if (updateCoeffs()) {
117 double fctVal, derVal, dPhiH;
120 double x1 = thePhiH0 -
M_PI, x2 = thePhiH0 +
M_PI;
121 for (
int j = 1;
j <= themaxiter; ++
j) {
122 oneIteration(thePhiH, fctVal, derVal);
123 dPhiH = fctVal / derVal;
125 if ((x1 - thePhiH) * (thePhiH - x2) < 0.0) {
126 LogDebug(
"TwoTrackMinimumDistanceHelixLine") <<
"Jumped out of brackets in root finding. Will be moved closer.";
127 thePhiH += (dPhiH * 0.8);
129 if (fabs(dPhiH) <
qual) {
134 LogDebug(
"TwoTrackMinimumDistanceHelixLine") <<
"Number of steps exceeded. Has not converged.";
140 if (firstGTP == theL)
141 return theL->momentum().phi();
147 if (secondGTP == theL)
148 return theL->momentum().phi();
154 if (firstGTP == theL)
155 return pair<GlobalPoint, GlobalPoint>(linePoint, helixPoint);
157 return pair<GlobalPoint, GlobalPoint>(helixPoint, linePoint);
161 if (firstGTP == theL)
162 return pair<double, double>(linePath, helixPath);
164 return pair<double, double>(helixPath, linePath);
170 helixPoint =
GlobalPoint(theH->position().x() + theh * (
sin(thePhiH) - thesinPhiH0),
171 theH->position().y() + theh * (-
cos(thePhiH) + thecosPhiH0),
172 theH->position().z() + theh * (thetanlambdaH * (thePhiH - thePhiH0)));
173 helixPath = (thePhiH - thePhiH0) * (theh *
sqrt(1 + thetanlambdaH * thetanlambdaH));
176 tL = (-
diff.dot(theLp)) / (Ln * Ln);
178 GlobalPoint(theL->position().x() + tL *
px, theL->position().y() + tL *
py, theL->position().z() + tL * pz);
179 linePath = tL * theLp.
mag();
180 pointsUpdated =
true;
Derivative< X, A >::type derivative(const A &_)
uint32_t cc[maxCellsPerHit]
Sin< T >::type sin(const T &t)
Global3DPoint GlobalPoint
bool oneIteration(double &thePhiH, double &fct, double &derivative) const
Cos< T >::type cos(const T &t)
std::pair< double, double > pathLength() const
double secondAngle() const
double firstAngle() const
Log< level::Warning, false > LogWarning
std::pair< GlobalPoint, GlobalPoint > points() const
bool calculate(const GlobalTrajectoryParameters &, const GlobalTrajectoryParameters &, const float qual=.0001)
Global3DVector GlobalVector