9#include "CLHEP/Matrix/Vector.h"
10#include "CLHEP/Matrix/SymMatrix.h"
21 else if(lay < 10) i = 1;
22 else if(lay < 12) i = 2;
23 else if(lay < 14) i = 3;
24 else if(lay < 16) i = 4;
25 else if(lay < 18) i = 5;
26 else if(lay < 20) i = 6;
30 if(1 == iEnd) iEP = i;
31 else return iEP = i + 8;
36 val[0] = veca[1]*vecb[2] - veca[2]*vecb[1];
37 val[1] = veca[2]*vecb[0] - veca[0]*vecb[2];
38 val[2] = veca[0]*vecb[1] - veca[1]*vecb[0];
42 double veca[3],
double vecb[3],
43 double &d,
double &za,
double &zb,
int fgZcal){
49 double seca[3], secb[3];
53 for(i=0; i<3; i++) vst[i] = sta[i] - stb[i];
57 m2 = vp[0]*vp[0] + vp[1]*vp[1] + vp[2]*vp[2];
59 for(i=0; i<3; i++) vp[i] /= modvp;
62 for(i=0; i<3; i++) d += vst[i] * vp[i];
64 if( 0 == fgZcal )
return 1;
66 double veca00 = veca[0]*veca[0];
67 double veca11 = veca[1]*veca[1];
68 double veca22 = veca[2]*veca[2];
70 double veca01 = veca[0]*veca[1];
71 double veca02 = veca[0]*veca[2];
72 double veca12 = veca[1]*veca[2];
74 double vecb00 = vecb[0]*vecb[0];
75 double vecb11 = vecb[1]*vecb[1];
76 double vecb22 = vecb[2]*vecb[2];
77 double vecb01 = vecb[0]*vecb[1];
78 double vecb02 = vecb[0]*vecb[2];
79 double vecb12 = vecb[1]*vecb[2];
81 seca[0] = veca[1]*vecb01 + veca[2]*vecb02 - veca[0]*(vecb11 + vecb22);
82 seca[1] = veca[0]*vecb01 + veca[2]*vecb12 - veca[1]*(vecb00 + vecb22);
83 seca[2] = veca[0]*vecb02 + veca[1]*vecb12 - veca[2]*(vecb00 + vecb11);
85 secb[0] = vecb[1]*veca01 + vecb[2]*veca02 - vecb[0]*(veca11 + veca22);
86 secb[1] = vecb[0]*veca01 + vecb[2]*veca12 - vecb[1]*(veca00 + veca22);
87 secb[2] = vecb[0]*veca02 + vecb[1]*veca12 - vecb[2]*(veca00 + veca11);
90 tpa += seca[i] * (sta[i] - stb[i]);
91 twb += secb[i] * (stb[i] - sta[i]);
95 za = veca[2] * tpa + sta[2];
96 zb = vecb[2] * twb + stb[2];
102 double wirev[],
double &zwire,
int fgZcal){
109 ps[0] = trkpar[0] *
cos(trkpar[1]);
110 ps[1] = trkpar[0] *
sin(trkpar[1]);
123 double wirev[],
double &zwire,
double zini){
125 double x0 = trkpar[0] *
cos(trkpar[1]);
126 double y0 = trkpar[0] *
sin(trkpar[1]);
127 double z0 = trkpar[3];
128 double phi0 = trkpar[1] +
HFPI;
129 double g = 1000 / (0.3 *
BFIELD * trkpar[2]);
130 double tanl = trkpar[4];
132 double wx = wirev[0];
133 double wy = wirev[1];
134 double wz = wirev[2];
139 CLHEP::HepVector c(2, 0);
140 c[0] = phi0 + (zini - z0) / (g * tanl);
141 c[1] = (zini - wirest[2]) / wz;
145 double xh = x0 + g * (
sin(phi) -
sin(phi0));
146 double yh = y0 + g * (-
cos(phi) +
cos(phi0));
147 double zh = z0 + g * tanl * (phi - phi0);
148 double xw = wirest[0] + wx*
t;
149 double yw = wirest[1] + wy*
t;
150 double zw = wirest[2] + wz*
t;
151 double doca = sqrt( (xh-xw)*(xh-xw) + (yh-yw)*(yh-yw) + (zh-zw)*(zh-zw) );
157 CLHEP::HepVector a(2, 0);
158 CLHEP::HepSymMatrix omega(2, 0);
162 a[0] = (x0 - g*
sin(phi0) - wirest[0] - wx*
t) *
cos(phi)
163 + (y0 + g*
cos(phi0) - wirest[1] - wy*
t) *
sin(phi)
164 + (z0 + g*tanl*phi - g*tanl*phi0 - wirest[2] - wz*
t) * tanl;
165 a[1] = (x0 + g*
sin(phi) - g*
sin(phi0) - wirest[0] - wx*
t) * wx
166 + (y0 - g*
cos(phi) + g*
cos(phi0) - wirest[1] - wy*
t) * wy
167 + (z0 + g*tanl*phi - g*tanl*phi0 - wirest[2] - wz*
t) * wz;
168 omega[0][0] = 0 - (x0 - g*
sin(phi0) - wirest[0] - wx*
t) *
sin(phi)
169 + (y0 + g*
cos(phi0) - wirest[1] - wy*
t) *
cos(phi) + g*tanl*tanl;
170 omega[0][1] = -wx*
cos(phi) - wy*
sin(phi) - wz*tanl;
171 omega[1][0] = g * (wx*
cos(phi) + wy*
sin(phi) + wz*tanl);
172 omega[1][1] = -wx*wx - wy*wy - wz*wz;
175 cc = c - omega.inverse(ifail) * a;
179 xh = x0 + g * (
sin(phi) -
sin(phi0));
180 yh = y0 + g * (-
cos(phi) +
cos(phi0));
181 zh = z0 + g * tanl * (phi - phi0);
182 xw = wirest[0] + wx*
t;
183 yw = wirest[1] + wy*
t;
184 zw = wirest[2] + wz*
t;
185 doca = sqrt( (xh-xw)*(xh-xw) + (yh-yw)*(yh-yw) + (zh-zw)*(zh-zw) );
194 a[0] = (x0 - g*
sin(phi0) - wirest[0] - wx*
t) *
cos(phi)
195 + (y0 + g*
cos(phi0) - wirest[1] - wy*
t) *
sin(phi)
196 + (z0 + g*tanl*phi - g*tanl*phi0 - wirest[2] - wz*
t) * tanl;
197 a[1] = (x0 + g*
sin(phi) - g*
sin(phi0) - wirest[0] - wx*
t) * wx
198 + (y0 - g*
cos(phi) + g*
cos(phi0) - wirest[1] - wy*
t) * wy
199 + (z0 + g*tanl*phi - g*tanl*phi0 - wirest[2] - wz*
t) * wz;
200 if((fabs(a[0]) < 0.001) && (fabs(a[1]) < 0.001))
break;
212 xh = x0 + g * (
sin(phi) -
sin(phi0));
213 yh = y0 + g * (-
cos(phi) +
cos(phi0));
214 zh = z0 + g * tanl * (phi - phi0);
215 xw = wirest[0] + wx*
t;
216 yw = wirest[1] + wy*
t;
217 zw = wirest[2] + wz*
t;
218 doca = sqrt( (xh-xw)*(xh-xw) + (yh-yw)*(yh-yw) + (zh-zw)*(zh-zw) );
248 double wirev[],
double &zwire,
double phiIni){
249 double x0 = trkpar[0] *
cos(trkpar[1]);
250 double y0 = trkpar[0] *
sin(trkpar[1]);
251 double z0 = trkpar[3];
252 double phi0 = trkpar[1] +
HFPI;
253 if(phi0 >
PI2) phi0 -=
PI2;
254 double g = 1000 / (0.3 *
BFIELD * trkpar[2]);
255 double tanl = trkpar[4];
284 if(dphi >
PI) dphi -=
PI2;
285 if(dphi < -
PI) dphi +=
PI2;
287 trkst[0] = x0 + g * (
sin(phi) -
sin(phi0));
288 trkst[1] = y0 + g * (-
cos(phi) +
cos(phi0));
290 trkst[2] = z0 + g * tanl * dphi;
296 dist2Line(trkst, wirest, trkv, wirev, doca, ztrk, zwire);
298 phiNew = phi0 + (ztrk - z0) / (g*tanl);
299 if(fabs(phiNew - phi) < 1.0E-8)
break;
367 double whitPos[],
double zini){
373 double ten = wpos[6];
374 double a = 9.47e-06 / (2 * ten);
375 double dx = wpos[0] - wpos[3];
376 double dz = wpos[2] - wpos[5];
377 double length = sqrt(dx*dx + dz*dz);
380 if(whitPos[2] < 0.5*
length) ztan = whitPos[2];
386 double sinalf = dx / sqrt(dx*dx + dz*dz);
387 double cosalf = dz / sqrt(dx*dx + dz*dz);
388 double tanalf = dx / dz;
391 double rLayer = sqrt((wpos[3] * wpos[3]) + (wpos[4] * wpos[4]));
392 double phiIni =
getPhiIni(trkpar, rLayer, posIni);
395 std::cout <<
"ERROR: wire position error in getdocaLine() !!!"
407 xyz[0] = (zc - wpos[5]) * tanalf + wpos[3];
408 xyz[1] = a*zp*zp + (wpos[1] - wpos[4])*zp/
length
413 dxyz[1] = 2.0 * a * zp + (wpos[1] - wpos[4]) /
length;
419 if( fabs(zc-ztan) < 0.5 )
break;
420 else if( fabs(ztan) > (0.5*
length) ){
428 whitPos[1] = a*zp*zp + (wpos[1] - wpos[4])*zp/
length
430 whitPos[0] = (ztan - wpos[5]) * tanalf + wpos[3];
435 double dr = trkpar[0];
436 double fi0 = trkpar[1];
437 double kap = trkpar[2];
440 double phi0 = fi0 +
HFPI;
441 if(phi0 >
PI2) phi0 -=
PI2;
442 double g = 1000 / (0.3 * 1.0 * kap);
444 double aa = rw*rw - (dr-g)*(dr-g) - g*g;
445 double bb = 2*g*(dr - g);
447 double dd = acos(cc);
450 if(kap > 0) phi = phi0 + dd;
451 else phi = phi0 - dd;
454 if(phi < 0) phi +=
PI2;
456 double x0 = dr *
cos(fi0);
457 double y0 = dr *
sin(fi0);
458 pos[0] = x0 + g * (
sin(phi) -
sin(phi0));
459 pos[1] = y0 + g * (-
cos(phi) +
cos(phi0));
461 if(kap > 0) pos[2] = trkpar[3] + g * trkpar[4] * dd;
462 else pos[2] = trkpar[3] - g * trkpar[4] * dd;
double sin(const BesAngle a)
double cos(const BesAngle a)
bool getDoca(double trkpar[], double wpos[], double &doca, double whitPos[], double zini)
int dist2Line(double sta[3], double stb[3], double veca[3], double vecb[3], double &d, double &za, double &zb, int fgZcal=1)
double docaHelixWire(double trkpar[], double wirest[], double wirev[], double &zwire, double zini)
int getEpId(int lay, int iEnd)
double docaHelixWireNewton(double trkpar[], double wirest[], double wirev[], double &zwire, double zini)
double docaLineWire(double trkpar[], double wirest[], double wirev[], double &zwire, int fgZcal=1)
double getPhiIni(double trkpar[], double rLayer, double pos[])
void expd(double veca[3], double vecb[3], double val[3])