53 cout <<
" Please set momenta first!" << endl;
57 if (!solved) mt2_bisect();
61 void mt2::set_momenta(
double* pa0,
double* pb0,
double* pmiss0)
73 Easq = masq+pax*pax+pay*pay;
83 Ebsq = mbsq+pbx*pbx+pby*pby;
86 pmissx = pmiss0[1]; pmissy = pmiss0[2];
87 pmissxsq = pmissx*pmissx;
88 pmissysq = pmissy*pmissy;
94 temp = pax; pax = pbx; pbx = temp;
95 temp = pay; pay = pby; pby = temp;
96 temp = Ea; Ea = Eb; Eb = temp;
97 temp = Easq; Easq = Ebsq; Ebsq = temp;
98 temp = masq; masq = mbsq; mbsq = temp;
99 temp = ma; ma = mb; mb = temp;
102 if (Ea > Eb) scale = Ea/100.;
103 else scale = Eb/100.;
105 if (sqrt(pmissxsq+pmissysq)/100 > scale) scale = sqrt(pmissxsq+pmissysq)/100;
107 double scalesq = scale * scale;
112 pax = pax/scale; pay = pay/scale;
113 pbx = pbx/scale; pby = pby/scale;
114 Ea = Ea/scale; Eb = Eb/scale;
118 pmissx = pmissx/scale;
119 pmissy = pmissy/scale;
120 pmissxsq = pmissxsq/scalesq;
121 pmissysq = pmissysq/scalesq;
122 mn = mn_unscale/scale;
129 void mt2::set_mn(
double mn0)
132 mn_unscale = fabs(mn0);
133 mn = mn_unscale/scale;
139 cout <<
" pax = " << pax*scale <<
"; pay = " << pay*scale <<
"; ma = " << ma*scale <<
";"<< endl;
140 cout <<
" pbx = " << pbx*scale <<
"; pby = " << pby*scale <<
"; mb = " << mb*scale <<
";"<< endl;
141 cout <<
" pmissx = " << pmissx*scale <<
"; pmissy = " << pmissy*scale <<
";"<< endl;
142 cout <<
" mn = " << mn_unscale<<
";" << endl;
146 void mt2::mt2_massless()
151 theta = atan(pay/pax);
155 double pxtemp,pytemp;
156 Easq = pax*pax+pay*pay;
157 Ebsq = pbx*pbx+pby*pby;
161 pxtemp = pax*c+pay*s;
164 pxtemp = pbx*c+pby*s;
165 pytemp = -s*pbx+c*pby;
168 pxtemp = pmissx*c+pmissy*s;
169 pytemp = -s*pmissx+c*pmissy;
173 a2 = 1-pbx*pbx/(Ebsq);
174 b2 = -pbx*pby/(Ebsq);
175 c2 = 1-pby*pby/(Ebsq);
177 d21 = (Easq*pbx)/Ebsq;
178 d20 = - pmissx + (pbx*(pbx*pmissx + pby*pmissy))/Ebsq;
179 e21 = (Easq*pby)/Ebsq;
180 e20 = - pmissy + (pby*(pbx*pmissx + pby*pmissy))/Ebsq;
181 f22 = -(Easq*Easq/Ebsq);
182 f21 = -2*Easq*(pbx*pmissx + pby*pmissy)/Ebsq;
183 f20 = mnsq + pmissxsq + pmissysq - (pbx*pmissx + pby*pmissy)*(pbx*pmissx + pby*pmissy)/Ebsq;
186 double Deltasq_low, Deltasq_high;
187 int nsols_high, nsols_low;
189 Deltasq_low = Deltasq0 + precision;
190 nsols_low = nsols_massless(Deltasq_low);
194 mt2_b = (double) sqrt(Deltasq0+mnsq);
206 double Deltasq_high1, Deltasq_high2;
207 Deltasq_high1 = 2*Eb*sqrt(pmissx*pmissx+pmissy*pmissy+mnsq)-2*pbx*pmissx-2*pby*pmissy;
208 Deltasq_high2 = 2*Ea*mn;
210 if(Deltasq_high1 < Deltasq_high2) Deltasq_high = Deltasq_high2;
211 else Deltasq_high = Deltasq_high1;
213 nsols_high=nsols_massless(Deltasq_high);
216 if (nsols_high == nsols_low)
222 double minmass, maxmass;
224 maxmass = sqrt(mnsq + Deltasq_high);
227 Deltasq_high = mass*mass - mnsq;
229 nsols_high = nsols_massless(Deltasq_high);
240 cout<<
"Deltasq_high not found at event " << nevt <<endl;
243 mt2_b = (double)sqrt(Deltasq_low+mnsq);
248 if(nsols_high == nsols_low)
250 cout <<
"error: nsols_low=nsols_high=" << nsols_high << endl;
251 cout <<
"Deltasq_high=" << Deltasq_high << endl;
252 cout <<
"Deltasq_low= "<< Deltasq_low << endl;
254 mt2_b = sqrt(mnsq + Deltasq_low);
257 double minmass, maxmass;
258 minmass = sqrt(Deltasq_low+mnsq);
259 maxmass = sqrt(Deltasq_high+mnsq);
260 while(maxmass - minmass > precision)
262 double Delta_mid, midmass, nsols_mid;
263 midmass = (minmass+maxmass)/2.;
264 Delta_mid = midmass * midmass - mnsq;
265 nsols_mid = nsols_massless(Delta_mid);
266 if(nsols_mid != nsols_low) maxmass = midmass;
267 if(nsols_mid == nsols_low) minmass = midmass;
273 int mt2::nsols_massless(
double Dsq)
276 delta = Dsq/(2*Easq);
279 f1 = f12*delta*delta+f10;
282 f2 = f22*delta*delta+f21*delta+f20;
285 if (pax > 0) a = Ea/Dsq;
287 if (pax > 0) b = -Dsq/(4*Ea)+mnsq*Ea/Dsq;
288 else b = Dsq/(4*Ea)-mnsq*Ea/Dsq;
290 double A4,A3,A2,A1,A0;
294 A2 = (2*a*a2*b+c2+2*a*d2)/(Easq);
295 A1 = (2*b*b2+2*e2)/(Easq*Ea);
296 A0 = (a2*b*b+2*b*d2+f2)/(Easq*Easq);
298 long double A0sq, A1sq, A2sq, A3sq, A4sq;
305 long double B3, B2, B1, B0;
310 long double C2, C1, C0;
311 C2 = -(A2/2 - 3*A3sq/(16*A4));
312 C1 = -(3*A1/4. -A2*A3/(8*A4));
313 C0 = -A0 + A1*A3/(16*A4);
315 D1 = -B1 - (B3*C1*C1/C2 - B3*C0 -B2*C1)/C2;
316 D0 = -B0 - B3 *C0 *C1/(C2*C2)+ B2*C0/C2;
319 E0 = -C0 - C2*D0*D0/(D1*D1) + C1*D0/D1;
321 long double t1,t2,t3,t4,t5;
331 nsol = signchange_n(t1,t2,t3,t4,t5)-signchange_p(t1,t2,t3,t4,t5);
332 if( nsol < 0 ) nsol=0;
338 void mt2::mt2_bisect()
354 Deltasq0 = ma*(ma + 2*mn);
358 a1 = 1-pax*pax/(Easq);
359 b1 = -pax*pay/(Easq);
360 c1 = 1-pay*pay/(Easq);
361 d1 = -pax*(Deltasq0-masq)/(2*Easq);
362 e1 = -pay*(Deltasq0-masq)/(2*Easq);
363 a2 = 1-pbx*pbx/(Ebsq);
364 b2 = -pbx*pby/(Ebsq);
365 c2 = 1-pby*pby/(Ebsq);
366 d2 = -pmissx+pbx*(Deltasq0-mbsq)/(2*Ebsq)+pbx*(pbx*pmissx+pby*pmissy)/(Ebsq);
367 e2 = -pmissy+pby*(Deltasq0-mbsq)/(2*Ebsq)+pby*(pbx*pmissx+pby*pmissy)/(Ebsq);
368 f2 = pmissx*pmissx+pmissy*pmissy-((Deltasq0-mbsq)/(2*Eb)+
369 (pbx*pmissx+pby*pmissy)/Eb)*((Deltasq0-mbsq)/(2*Eb)+
370 (pbx*pmissx+pby*pmissy)/Eb)+mnsq;
374 x0 = (c1*d1-b1*e1)/(b1*b1-a1*c1);
375 y0 = (a1*e1-b1*d1)/(b1*b1-a1*c1);
379 double dis=a2*x0*x0+2*b2*x0*y0+c2*y0*y0+2*d2*x0+2*e2*y0+f2;
383 mt2_b = (double) sqrt(mnsq+Deltasq0);
396 d21 = (Easq*pbx)/Ebsq;
397 d20 = ((masq - mbsq)*pbx)/(2.*Ebsq) - pmissx +
398 (pbx*(pbx*pmissx + pby*pmissy))/Ebsq;
399 e21 = (Easq*pby)/Ebsq;
400 e20 = ((masq - mbsq)*pby)/(2.*Ebsq) - pmissy +
401 (pby*(pbx*pmissx + pby*pmissy))/Ebsq;
402 f22 = -Easq*Easq/Ebsq;
403 f21 = (-2*Easq*((masq - mbsq)/(2.*Eb) + (pbx*pmissx + pby*pmissy)/Eb))/Eb;
404 f20 = mnsq + pmissx*pmissx + pmissy*pmissy -
405 ((masq - mbsq)/(2.*Eb) + (pbx*pmissx + pby*pmissy)/Eb)
406 *((masq - mbsq)/(2.*Eb) + (pbx*pmissx + pby*pmissy)/Eb);
411 double Deltasq_high1;
414 Deltasq_high1 = 2*Eb*sqrt(p2x0*p2x0+p2y0*p2y0+mnsq)-2*pbx*p2x0-2*pby*p2y0+mbsq;
418 double Deltasq_high2, Deltasq_high21, Deltasq_high22;
419 Deltasq_high21 = 2*Eb*sqrt(pmissx*pmissx+pmissy*pmissy+mnsq)-2*pbx*pmissx-2*pby*pmissy+mbsq;
420 Deltasq_high22 = 2*Ea*mn+masq;
422 if ( Deltasq_high21 < Deltasq_high22 ) Deltasq_high2 = Deltasq_high22;
423 else Deltasq_high2 = Deltasq_high21;
427 if(Deltasq_high1 < Deltasq_high2) Deltasq_high = Deltasq_high1;
428 else Deltasq_high = Deltasq_high2;
432 Deltasq_low = Deltasq0;
435 if( nsols(Deltasq_low) > 0 )
438 mt2_b = (double) sqrt(mnsq+Deltasq0);
442 int nsols_high, nsols_low;
444 nsols_low = nsols(Deltasq_low);
451 nsols_high = nsols(Deltasq_high);
453 if(nsols_high == nsols_low || nsols_high == 4)
456 foundhigh = find_high(Deltasq_high);
459 cout <<
"Deltasq_high not found at event " << nevt << endl;
460 mt2_b = sqrt( Deltasq_low + mnsq );
466 while(sqrt(Deltasq_high+mnsq) - sqrt(Deltasq_low+mnsq) > precision)
468 double Deltasq_mid,nsols_mid;
470 Deltasq_mid = (Deltasq_high+Deltasq_low)/2.;
471 nsols_mid = nsols(Deltasq_mid);
473 if ( nsols_mid == 4 )
475 Deltasq_high = Deltasq_mid;
477 find_high(Deltasq_high);
482 if(nsols_mid != nsols_low) Deltasq_high = Deltasq_mid;
483 if(nsols_mid == nsols_low) Deltasq_low = Deltasq_mid;
485 mt2_b = (double) sqrt( mnsq + Deltasq_high);
489 int mt2::find_high(
double & Deltasq_high)
492 x0 = (c1*d1-b1*e1)/(b1*b1-a1*c1);
493 y0 = (a1*e1-b1*d1)/(b1*b1-a1*c1);
494 double Deltasq_low = (mn + ma)*(mn + ma) - mnsq;
497 double Deltasq_mid = (Deltasq_high + Deltasq_low)/2.;
498 int nsols_mid = nsols(Deltasq_mid);
499 if ( nsols_mid == 2 )
501 Deltasq_high = Deltasq_mid;
504 else if (nsols_mid == 4)
506 Deltasq_high = Deltasq_mid;
509 else if (nsols_mid ==0)
511 d1 = -pax*(Deltasq_mid-masq)/(2*Easq);
512 e1 = -pay*(Deltasq_mid-masq)/(2*Easq);
513 d2 = -pmissx + pbx*(Deltasq_mid - mbsq)/(2*Ebsq)
514 + pbx*(pbx*pmissx+pby*pmissy)/(Ebsq);
515 e2 = -pmissy + pby*(Deltasq_mid - mbsq)/(2*Ebsq)
516 + pby*(pbx*pmissx+pby*pmissy)/(Ebsq);
517 f2 = pmissx*pmissx+pmissy*pmissy-((Deltasq_mid-mbsq)/(2*Eb)+
518 (pbx*pmissx+pby*pmissy)/Eb)*((Deltasq_mid-mbsq)/(2*Eb)+
519 (pbx*pmissx+pby*pmissy)/Eb)+mnsq;
521 double dis = a2*x0*x0 + 2*b2*x0*y0 + c2*y0*y0 + 2*d2*x0 + 2*e2*y0 + f2;
522 if (dis < 0) Deltasq_high = Deltasq_mid;
523 else Deltasq_low = Deltasq_mid;
526 }
while ( Deltasq_high - Deltasq_low > 0.001);
529 int mt2::scan_high(
double & Deltasq_high)
536 double tempmass, maxmass;
538 maxmass = sqrt(mnsq + Deltasq_high);
539 if (nevt == 32334) cout <<
"Deltasq_high = " << Deltasq_high << endl;
542 Deltasq_high = mass*mass - mnsq;
543 nsols_high = nsols(Deltasq_high);
554 int mt2::nsols(
double Dsq)
556 double delta = (Dsq-masq)/(2*Easq);
561 f1 = f12*delta*delta+f10;
564 f2 = f22*delta*delta+f21*delta+f20;
568 long double A4, A3, A2, A1, A0;
571 -4*a2*b1*b2*c1 + 4*a1*b2*b2*c1 +a2*a2*c1*c1 +
572 4*a2*b1*b1*c2 - 4*a1*b1*b2*c2 - 2*a1*a2*c1*c2 +
576 (-4*a2*b2*c1*d1 + 8*a2*b1*c2*d1 - 4*a1*b2*c2*d1 - 4*a2*b1*c1*d2 +
577 8*a1*b2*c1*d2 - 4*a1*b1*c2*d2 - 8*a2*b1*b2*e1 + 8*a1*b2*b2*e1 +
578 4*a2*a2*c1*e1 - 4*a1*a2*c2*e1 + 8*a2*b1*b1*e2 - 8*a1*b1*b2*e2 -
579 4*a1*a2*c1*e2 + 4*a1*a1*c2*e2)/Ea;
583 (4*a2*c2*d1*d1 - 4*a2*c1*d1*d2 - 4*a1*c2*d1*d2 + 4*a1*c1*d2*d2 -
584 8*a2*b2*d1*e1 - 8*a2*b1*d2*e1 + 16*a1*b2*d2*e1 +
585 4*a2*a2*e1*e1 + 16*a2*b1*d1*e2 - 8*a1*b2*d1*e2 -
586 8*a1*b1*d2*e2 - 8*a1*a2*e1*e2 + 4*a1*a1*e2*e2 - 4*a2*b1*b2*f1 +
587 4*a1*b2*b2*f1 + 2*a2*a2*c1*f1 - 2*a1*a2*c2*f1 +
588 4*a2*b1*b1*f2 - 4*a1*b1*b2*f2 - 2*a1*a2*c1*f2 + 2*a1*a1*c2*f2)/Easq;
591 (-8*a2*d1*d2*e1 + 8*a1*d2*d2*e1 + 8*a2*d1*d1*e2 - 8*a1*d1*d2*e2 -
592 4*a2*b2*d1*f1 - 4*a2*b1*d2*f1 + 8*a1*b2*d2*f1 + 4*a2*a2*e1*f1 -
593 4*a1*a2*e2*f1 + 8*a2*b1*d1*f2 - 4*a1*b2*d1*f2 - 4*a1*b1*d2*f2 -
594 4*a1*a2*e1*f2 + 4*a1*a1*e2*f2)/(Easq*Ea);
597 (-4*a2*d1*d2*f1 + 4*a1*d2*d2*f1 + a2*a2*f1*f1 +
598 4*a2*d1*d1*f2 - 4*a1*d1*d2*f2 - 2*a1*a2*f1*f2 +
599 a1*a1*f2*f2)/(Easq*Easq);
601 long double A0sq, A1sq, A2sq, A3sq, A4sq;
608 long double B3, B2, B1, B0;
614 long double C2, C1, C0;
615 C2 = -(A2/2 - 3*A3sq/(16*A4));
616 C1 = -(3*A1/4. -A2*A3/(8*A4));
617 C0 = -A0 + A1*A3/(16*A4);
620 D1 = -B1 - (B3*C1*C1/C2 - B3*C0 -B2*C1)/C2;
621 D0 = -B0 - B3 *C0 *C1/(C2*C2)+ B2*C0/C2;
624 E0 = -C0 - C2*D0*D0/(D1*D1) + C1*D0/D1;
626 long double t1,t2,t3,t4,t5;
637 nsol = signchange_n(t1,t2,t3,t4,t5) - signchange_p(t1,t2,t3,t4,t5);
640 if (nsol < 0) nsol = 0;
646 inline int mt2::signchange_n(
long double t1,
long double t2,
long double t3,
long double t4,
long double t5)
656 inline int mt2::signchange_p(
long double t1,
long double t2,
long double t3,
long double t4,
long double t5)
#define RELATIVE_PRECISION
#define ABSOLUTE_PRECISION