12 bool isFirstALine = firstGTP->charge() == 0. || firstGTP->magneticField().inTesla(firstGTP->position()).z() == 0.;
13 bool isSecondALine = secondGTP->charge() == 0. || secondGTP->magneticField().inTesla(secondGTP->position()).z() == 0.;
14 if (isFirstALine && !isSecondALine ) {
17 }
else if (!isFirstALine && isSecondALine) {
22 <<
"Error in track charge: " 23 <<
"One of the tracks has to be charged, and the other not." << endl
24 <<
"Track Charges: "<<firstGTP->charge() <<
" and " <<secondGTP->charge();
28 Hn = theH->momentum().mag();
29 Ln = theL->momentum().mag();
31 if ( Hn == 0. || Ln == 0. )
34 <<
"Momentum of input trajectory is zero.";
44 theLp = theL->momentum();
45 px = theLp.x(); px2 = px*px;
46 py = theLp.y(); py2 = py*py;
47 pz = theLp.z(); pz2 = pz*pz;
49 const double Bc2kH = theH->magneticField().inTesla(hOrig).z() * 2.99792458e-3;
55 <<
"Magnetic field at point " << hOrig <<
" is zero.";
59 theh= - Hn / (theH->charge() * Bc2kH ) *
60 sqrt( 1 - ( ( (theH->momentum().z()*theH->momentum().z()) / (Hn*Hn) )));
62 thetanlambdaH = - theH->momentum().z() / ( theH->charge() * Bc2kH * theh);
64 thePhiH0 = theH->momentum().phi();
65 thesinPhiH0=
sin(thePhiH0);
66 thecosPhiH0=
cos(thePhiH0);
68 aa = (
X + theh*thesinPhiH0)*(py2 + pz2) - px*(py*
Y + pz*
Z);
69 bb = (
Y - theh*thecosPhiH0)*(px2 + pz2) - py*(px*
X + pz*
Z);
70 cc = pz*theh*thetanlambdaH;
72 ee = theh*(px2 - py2);
73 ff = (px2 + py2)*theh*thetanlambdaH*thetanlambdaH;
75 baseFct = thetanlambdaH * (
Z*(px2+py2) - pz*(px*
X + py*
Y));
81 double & thePhiH,
double & fct,
double &
derivative )
const 84 double thesinPhiH =
sin(thePhiH);
85 double thecosPhiH =
cos(thePhiH);
90 fct -=
ff*(thePhiH - thePhiH0);
91 fct += thecosPhiH * aa;
92 fct += thesinPhiH * bb;
93 fct += cc*(thePhiH - thePhiH0)*(px * thecosPhiH + py * thesinPhiH);
94 fct += cc * (px * (thesinPhiH - thesinPhiH0) - py * (thecosPhiH - thecosPhiH0));
95 fct +=
dd * (thesinPhiH* (thesinPhiH - thesinPhiH0) -
96 thecosPhiH*(thecosPhiH - thecosPhiH0));
97 fct += ee * thecosPhiH * thesinPhiH;
101 derivative = baseDer;
102 derivative += - thesinPhiH * aa;
103 derivative += thecosPhiH * bb;
104 derivative += cc*(thePhiH - thePhiH0)*(py * thecosPhiH - px * thesinPhiH);
105 derivative += 2* cc*(px * thecosPhiH + py * thesinPhiH);
106 derivative +=
dd *(4 * thecosPhiH * thesinPhiH - thecosPhiH * thesinPhiH0 -
107 thesinPhiH * thecosPhiH0);
108 derivative += ee * (thecosPhiH*thecosPhiH-thesinPhiH*thesinPhiH);
117 pointsUpdated =
false;
118 firstGTP = &theFirstGTP;
119 secondGTP = &theSecondGTP;
121 if ( updateCoeffs () )
127 double fctVal, derVal, dPhiH;
131 for (
int j=1; j<=themaxiter; ++j) {
132 oneIteration(thePhiH, fctVal, derVal);
135 if ((x1-thePhiH)*(thePhiH-x2) < 0.0) {
136 LogDebug (
"TwoTrackMinimumDistanceHelixLine")
137 <<
"Jumped out of brackets in root finding. Will be moved closer.";
138 thePhiH += (dPhiH*0.8);
140 if (fabs(dPhiH) < qual) {
145 LogDebug (
"TwoTrackMinimumDistanceHelixLine")
146 <<
"Number of steps exceeded. Has not converged.";
153 if (firstGTP==theL)
return theL->momentum().phi();
159 if (secondGTP==theL)
return theL->momentum().phi();
166 return pair<GlobalPoint, GlobalPoint> (linePoint, helixPoint);
167 else return pair<GlobalPoint, GlobalPoint> (helixPoint, linePoint);
173 return pair<double, double> (linePath, helixPath);
174 else return pair<double, double> (helixPath, linePath);
179 if (pointsUpdated)
return;
181 theH->position().x() + theh * (
sin ( thePhiH) - thesinPhiH0 ),
182 theH->position().y() + theh * ( -
cos ( thePhiH) + thecosPhiH0 ),
183 theH->position().z() + theh * ( thetanlambdaH * ( thePhiH- thePhiH0 ))
185 helixPath = ( thePhiH- thePhiH0 ) * (theh*
sqrt(1+thetanlambdaH*thetanlambdaH)) ;
188 tL = ( -
diff.dot(theLp)) / (Ln*Ln);
190 theL->position().x() + tL * px,
191 theL->position().y() + tL * py,
192 theL->position().z() + tL * pz );
193 linePath = tL * theLp.
mag();
194 pointsUpdated =
true;
Derivative< X, A >::type derivative(const A &_)
bool oneIteration(double &thePhiH, double &fct, double &derivative) const
Sin< T >::type sin(const T &t)
Global3DPoint GlobalPoint
Cos< T >::type cos(const T &t)
double secondAngle() const
std::pair< double, double > pathLength() const
double firstAngle() const
std::pair< GlobalPoint, GlobalPoint > points() const
bool calculate(const GlobalTrajectoryParameters &, const GlobalTrajectoryParameters &, const float qual=.0001)
Global3DVector GlobalVector