47
48
49
50
51
54 double delta1(10*prec);
55 double delta2(10*prec);
56 unsigned niter(0);
57 static const unsigned maxiter(20);
58 while(niter < maxiter &&
59 ( delta1 > prec || delta2 > prec ) ){
60
63 if(niter == 0) pos1b = pos1;
71 double m1,
m2, q1, q2;
72 double r1, r2, xc1,xc2,yc1,yc2,sr1,sr2;
73 if(curv1 == 0) {
74
75 if(dir1[0] == 0){
77 }else{
79 }
80 q1 = pos1.y()-pos1.x()*
m1;
81 }else{
82
83 r1 = (1- dir1[2]*dir1[2])/curv1;
84 sr1=r1;
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;
90 }
91 if(curv2 == 0) {
92 if(dir2[0] == 0){
94 }else{
96 }
97 q2 = pos2.y()-pos2.x()*
m2;
98 }else{
99 r2 = (1-dir2[2]*dir2[2])/curv2;
100 sr2 = r2;
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;
106 }
107 double xint, yint, xint1, xint2, yint1, yint2, absdoca;
108 _docaxy = 0;
110
111
112
113 if(curv1==0 && curv2==0){
114
115 interTwoLines(
m1, q1,
m2, q2, xint, yint);
116 }
117
118
119
120 if(curv1 !=0 && curv2 !=0){
121
122 double cdist = sqrt((xc1-xc2)*(xc1-xc2)+(yc1-yc2)*(yc1-yc2));
123
124 if (fabs(cdist) < 1.e-12 ) {
125
127 "TrkPocaXY:: the two circles have the same center...");
128 return;
129 }
130
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());
137
138
139 if(dist1<dist2){
140 xint = xint1;
141 yint = yint1;
142 } else {
143 xint = xint2;
144 yint = yint2;
145 }
146 }
147
148
149
150 if ( (fabs(r1-r2) > cdist) ||
151 ( cdist > (r1+r2) )) {
152
153
154 double m = (yc1-yc2)/(xc1-xc2);
155 double q = yc1 - m*xc1;
156
157
158
159 double xint1, yint1, xint2, yint2, zOfDCrossT1;
160
161 interLineCircle(m,
q, xc1, yc1, r1, xint1, yint1, xint2, yint2);
162
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;
169#endif
170
171 double dist1_3 = pow((xint1-xint3),2.) + pow((yint1-yint3),2.);
172 double dist2_4 = pow((xint2-xint4),2.) + pow((yint2-yint4),2.);
173
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];
178 } else {
179 xint = 0.5*(xint2+xint4);
180 yint = 0.5*(yint2+yint4);
181 zOfDCrossT1 = (xint4-xint2)*dir1[1]-(yint4-yint2)*dir1[0];
182 }
183 _docaxy = absdoca;
184 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
185 }
186 if( cdist > (r1+r2) ) {
187 absdoca = cdist - (r1+r2);
188#ifdef MDCPATREC_DEBUG
189 cout << "ErrMsg(debugging) doing separated circles in TrkPocaXY"<< endl;
190#endif
191
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];
198 } else {
199 xint = 0.5*(xint1+xint4);
200 yint = 0.5*(yint1+yint4);
201 zOfDCrossT1 = (xint4-xint2)*dir1[1]-(yint4-yint2)*dir1[0];
202 }
203 _docaxy = absdoca;
204 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
205 }
206 }
207 }
208
209
210
211 if((curv1 == 0 && curv2 !=0) || (curv1 != 0 && curv2 == 0)) {
212
213 HepVector dirT;
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;}
217
218 double dist = fabs((m*xc-yc+
q)/sqrt(1+m*m));
219 if(dist <= r) {
220
221
222
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());
228
229 if(dist1<dist2){
230 xint = xint1;
231 yint = yint1;
232 } else {
233 xint = xint2;
234 yint = yint2;
235 }
236 } else {
237#ifdef MDCPATREC_DEBUG
238 cout << "ErrMsg(debugging) doing separated line-circle in TrkPocaXY"<<endl;
239#endif
240
241
242
243 double mperp = -1./m;
244 double qperp = yc - mperp*xc;
245
246
247
248 interLineCircle(mperp, qperp, xc, yc, r, xint1,yint1,xint2,yint2);
249
250 double xint3,yint3;
251 interTwoLines(m,
q, mperp, qperp, xint3, yint3);
252
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];
261 }
262 else {
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];
268 }
269 _docaxy = absdoca;
270 if( zOfDCrossT1 > 0) _docaxy = -absdoca;
271 }
272 }
273
274
275
280 if(poca1.status().success() && poca2.status().success()) {
281 delta1 = fabs(
_flt1 - poca1.flt1());
282 delta2 = fabs(
_flt2 - poca2.flt1());
283 _flt1 = poca1.flt1();
284 _flt2 = poca2.flt1();
285 }else{
286#ifdef MDCPATREC_WARNING
287 cout << "ErrMsg(warning)" << " poca fialure " << endl;
288#endif
289 if(poca1.status().failure())
_status=poca1.status();
290 break;
291 }
292 niter++;
293 }
294#ifdef MDCPATREC_DEBUG
295 cout <<"ErrMsg(debugging)" <<"TrkPocaXY iterations = " << niter-1
296 <<
" flight lengths " <<
_flt1 <<
" " <<
_flt2 << endl
297 << " deltas " << delta1 <<" " << delta2 << endl;
298#endif
299 if(niter == maxiter){
300#ifdef MDCPATREC_ROUTINE
301 cout << "ErrMsg(routine)" << "TrkPocaXY:: did not converge" << endl;
302#endif
304 }
305}
****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
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)