19#include "CLHEP/Vector/ThreeVector.h"
27 Hep3Vector zaxis(0.0,0.0,1.0);
33 TrkPoca zlinepoca(traj,flt,zline,zlen,prec);
39 _docaxy = zlinepoca.
doca();
54 double delta1(10*prec);
55 double delta2(10*prec);
57 static const unsigned maxiter(20);
58 while(niter < maxiter &&
59 ( delta1 > prec || delta2 > prec ) ){
63 if(niter == 0) pos1b = pos1;
71 double m1, m2, q1, q2;
72 double r1, r2, xc1,xc2,yc1,yc2,sr1,sr2;
80 q1 = pos1.y()-pos1.x()*m1;
83 r1 = (1- dir1[2]*dir1[2])/curv1;
85 if(dir1[0]*dd1[1] - dir1[1]*dd1[0] < 0) sr1 = -r1;
86 double cosphi1 = dir1[0]/sqrt(dir1[0]*dir1[0]+dir1[1]*dir1[1]);
87 double sinphi1 = cosphi1 * dir1[1]/dir1[0];
88 xc1 = pos1.x() - sr1 * sinphi1;
89 yc1 = pos1.y() + sr1 * cosphi1;
97 q2 = pos2.y()-pos2.x()*m2;
99 r2 = (1-dir2[2]*dir2[2])/curv2;
101 if(dir2[0]*dd2[1] - dir2[1]*dd2[0] < 0) sr2 = -r2;
102 double cosphi2 = dir2[0]/sqrt(dir2[0]*dir2[0]+dir2[1]*dir2[1]);
103 double sinphi2 = cosphi2 * dir2[1]/dir2[0];
104 xc2 = pos2.x() - sr2 * sinphi2;
105 yc2 = pos2.y() + sr2 * cosphi2;
107 double xint, yint, xint1, xint2, yint1, yint2, absdoca;
113 if(curv1==0 && curv2==0){
115 interTwoLines(m1, q1, m2, q2, xint, yint);
120 if(curv1 !=0 && curv2 !=0){
122 double cdist = sqrt((xc1-xc2)*(xc1-xc2)+(yc1-yc2)*(yc1-yc2));
124 if (fabs(cdist) < 1.e-12 ) {
127 "TrkPocaXY:: the two circles have the same center...");
131 if ( (fabs(r1-r2) < cdist) && (cdist < r1+r2 ) ) {
132 interTwoCircles(xc1,yc1,r1,xc2,yc2,r2,xint1,yint1,xint2,yint2);
133 double dist1 = (xint1-pos1b.x())*(xint1-pos1b.x()) +
134 (yint1-pos1b.y())*(yint1-pos1b.y());
135 double dist2 = (xint2-pos1b.x())*(xint2-pos1b.x()) +
136 (yint2-pos1b.y())*(yint2-pos1b.y());
150 if ( (fabs(r1-r2) > cdist) ||
151 ( cdist > (r1+r2) )) {
154 double m = (yc1-yc2)/(xc1-xc2);
155 double q = yc1 - m*xc1;
159 double xint1, yint1, xint2, yint2, zOfDCrossT1;
161 interLineCircle(m,
q, xc1, yc1, r1, xint1, yint1, xint2, yint2);
163 double xint3, yint3, xint4, yint4 ;
164 interLineCircle(m,
q, xc2, yc2, r2, xint3, yint3, xint4, yint4);
165 if (fabs(r1-r2) > cdist) {
166 absdoca = fabs(r1-r2)-cdist;
167#ifdef MDCPATREC_DEBUG
168 cout <<
"ErrMsg(debugging) doing nested circles in TrkPocaXY " << endl;
171 double dist1_3 = pow((xint1-xint3),2.) + pow((yint1-yint3),2.);
172 double dist2_4 = pow((xint2-xint4),2.) + pow((yint2-yint4),2.);
174 if(dist1_3<dist2_4) {
175 xint = 0.5*(xint1+xint3);
176 yint = 0.5*(yint1+yint3);
177 zOfDCrossT1 = (xint3-xint1)*dir1[1]-(yint3-yint1)*dir1[0];
179 xint = 0.5*(xint2+xint4);
180 yint = 0.5*(yint2+yint4);
181 zOfDCrossT1 = (xint4-xint2)*dir1[1]-(yint4-yint2)*dir1[0];
184 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
186 if( cdist > (r1+r2) ) {
187 absdoca = cdist - (r1+r2);
188#ifdef MDCPATREC_DEBUG
189 cout <<
"ErrMsg(debugging) doing separated circles in TrkPocaXY"<< endl;
192 double dist2_3 = pow((xint2-xint3),2.) + pow((yint2-yint3),2.);
193 double dist1_4 = pow((xint1-xint4),2.) + pow((yint1-yint4),2.);
194 if (dist2_3<dist1_4){
195 xint = 0.5*(xint2+xint3);
196 yint = 0.5*(yint2+yint3);
197 zOfDCrossT1 = (xint3-xint1)*dir1[1]-(yint3-yint1)*dir1[0];
199 xint = 0.5*(xint1+xint4);
200 yint = 0.5*(yint1+yint4);
201 zOfDCrossT1 = (xint4-xint2)*dir1[1]-(yint4-yint2)*dir1[0];
204 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
211 if((curv1 == 0 && curv2 !=0) || (curv1 != 0 && curv2 == 0)) {
214 double m,
q,r,xc,yc, zOfDCrossT1;
215 if(curv1==0) {m=m1;
q=q1; r=r2; xc=xc2; yc=yc2; dirT=dir2;}
216 else {m=m2;
q=q2; r=r1; xc=xc1; yc=yc1; dirT=dir1;}
218 double dist = fabs((m*xc-yc+
q)/sqrt(1+m*m));
223 interLineCircle(m,
q,xc,yc,r, xint1, yint1, xint2, yint2);
224 double dist1 = (xint1-pos1b.x())*(xint1-pos1b.x()) +
225 (yint1-pos1b.y())*(yint1-pos1b.y());
226 double dist2 = (xint2-pos1b.x())*(xint2-pos1b.x()) +
227 (yint2-pos1b.y())*(yint2-pos1b.y());
237#ifdef MDCPATREC_DEBUG
238 cout <<
"ErrMsg(debugging) doing separated line-circle in TrkPocaXY"<<endl;
243 double mperp = -1./m;
244 double qperp = yc - mperp*xc;
248 interLineCircle(mperp, qperp, xc, yc, r, xint1,yint1,xint2,yint2);
251 interTwoLines(m,
q, mperp, qperp, xint3, yint3);
253 double dist1_3 = pow((xint1-xint3),2.) + pow((yint1-yint3),2.);
254 double dist2_3 = pow((xint2-xint3),2.) + pow((yint2-yint3),2.);
255 if (dist1_3<dist2_3) {
256 xint = 0.5*(xint3 + xint1);
257 yint = 0.5*(yint3 + yint1);
258 absdoca = sqrt((xint3-xint1)*(xint3-xint1)+
259 (yint3-yint1)*(yint3-yint1));
260 zOfDCrossT1 = (xint3-xint1)*dirT[1]-(yint3-yint1)*dirT[0];
263 xint = 0.5*(xint3 + xint2);
264 yint = 0.5*(yint3 + yint2);
265 absdoca = sqrt((xint3-xint2)*(xint3-xint2)+
266 (yint3-yint2)*(yint3-yint2));
267 zOfDCrossT1 = (xint3-xint2)*dirT[1]-(yint3-yint2)*dirT[0];
270 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
286#ifdef MDCPATREC_WARNING
287 cout <<
"ErrMsg(warning)" <<
" poca fialure " << endl;
294#ifdef MDCPATREC_DEBUG
295 cout <<
"ErrMsg(debugging)" <<
"TrkPocaXY iterations = " << niter-1
296 <<
" flight lengths " <<
_flt1 <<
" " <<
_flt2 << endl
297 <<
" deltas " << delta1 <<
" " << delta2 << endl;
299 if(niter == maxiter){
300#ifdef MDCPATREC_ROUTINE
301 cout <<
"ErrMsg(routine)" <<
"TrkPocaXY:: did not converge" << endl;
308TrkPocaXY::interLineCircle(
const double& m,
const double&
q,
309 const double& xc,
const double& yc,
const double& r,
310 double& xint1,
double& yint1,
311 double& xint2,
double& yint2)
315 double alpha = 1 + m*m;
317 double beta = -xc +m*(
q-yc);
319 double gamma = xc*xc + (
q-yc)*(
q-yc) -r*r;
321 double Delta = beta*beta -
alpha*gamma;
326 "TrkPocaXY:: the line and the circle heve no intersections...");
330 else if (fabs(Delta) <1.e-12) {
341 if (xPlus > xMinus) {
357TrkPocaXY::interTwoCircles
358(
const double& xc1,
const double& yc1,
const double& r1,
359 const double& xc2,
const double& yc2,
const double& r2,
360 double& xint1,
double& yint1,
double& xint2,
double& yint2)
364 double A = (xc1*xc1 + yc1*yc1 - r1*r1) - (xc2*xc2 + yc2*yc2 - r2*r2);
366 double B = -xc1 + xc2;
368 double C = -yc1 + yc2;
372 double beta = -xc1 +
B/
C*(yc1+
A/(2*
C));
374 double gamma = xc1*xc1 + (yc1+
A/(2*
C))*(yc1+
A/(2*
C)) - r1*r1;
376 double Delta = beta*beta -
alpha*gamma;
385 else if (fabs(Delta) <1.e-12) {
395 if (xPlus > xMinus) {
406 yint1 = -(
A+2*
B*xint1)/(2*
C);
407 yint2 = -(
A+2*
B*xint2)/(2*
C);
415TrkPocaXY::interTwoLines
416(
const double& m1,
const double& q1,
const double& m2,
const double& q2,
417 double& xint,
double& yint)
421 if (fabs(m1-m2) < 1.e-12) {
430 xint = (q2-q1)/(m1-m2);
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
***************************************************************************************Pseudo Class RRes *****************************************************************************************Parameters and physical constants **Maarten sept ************************************************************************DOUBLE PRECISION xsmu **************************************************************************PARTICLE DATA all others are from PDG *Only resonances with known widths into electron pairs are sept ************************************************************************C Declarations C
virtual HepPoint3D position(double) const =0
virtual Hep3Vector delDirect(double) const =0
virtual Hep3Vector direction(double) const =0
virtual double curvature(double) const =0
void setSuccess(int i, const char *str=0)
void setFailure(int i, const char *str=0)
const TrkErrCode & status() const
TrkPocaXY(const Trajectory &traj, double flt, const HepPoint3D &pt, double precision=1.0e-4)