20#include "KalFitAlg/lpav/Lpar.h"
21using CLHEP::HepVector;
22using CLHEP::Hep3Vector;
23using CLHEP::HepMatrix;
24using CLHEP::HepSymMatrix;
30const double Lpar::BELLE_ALPHA(333.564095);
37Lpar::Cpar::Cpar(
const Lpar&l) {
39 if (l.alpha() !=0 && l.beta() !=0)
40 m_fi = atan2(l.alpha(), -l.beta());
42 if(m_fi<0) m_fi+=2*
M_PI;
43 m_da = 2 * l.gamma()/ (1 + sqrt (1 + 4 * l.
kappa() * l.gamma()));
78 double x3,
double y3) {
82 double delta = (x1-x2)*(y1-y3) - (y1-y2)*(x1-x3);
88 double r12sq = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
90 double r12 = sqrt(r12sq);
91 m_beta = -(x1-x2)/r12;
92 m_alpha = (y1-y2)/r12;
93 m_gamma = - (m_alpha*x1+m_beta*y1);
95 double r13sq = (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3);
97 double r13 = sqrt(r13sq);
98 m_beta = -(x1-x3)/r13;
99 m_alpha = (y1-y3)/r13;
100 m_gamma = - (m_alpha*x3+m_beta*y3);
102 double r23sq = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3);
104 double r23 = sqrt(r23sq);
105 m_beta = -(x2-x3)/r23;
106 m_alpha = (y2-y3)/r23;
107 m_gamma = - (m_alpha*x3+m_beta*y3);
116 double r1sq = x1 * x1 + y1 * y1;
117 double r2sq = x2 * x2 + y2 * y2;
118 double r3sq = x3 * x3 + y3 * y3;
119 a = 0.5 * ( (y1-y3)*(r1sq-r2sq) - (y1-y2)*(r1sq-r3sq)) /
delta;
120 b = 0.5 * (- (x1-x3)*(r1sq-r2sq) + (x1-x2)*(r1sq-r3sq)) /
delta;
121 double csq = (x1-a)*(x1-a) + (y1-
b)*(y1-
b);
123 double csq2 = (x2-a)*(x2-a) + (y2-
b)*(y2-
b);
124 double csq3 = (x3-a)*(x3-a) + (y3-
b)*(y3-
b);
125 m_kappa = 1 / (2 * c);
126 m_alpha = - 2 * a * m_kappa;
127 m_beta = - 2 *
b * m_kappa;
128 m_gamma = (a*a +
b*
b - c*c) * m_kappa;
132HepMatrix Lpar::dldc() const
133#ifdef BELLE_OPTIMIZED_RETURN
144 vret(1,1) = 2*cp.da()*
s;
145 vret(1,2) = -2*cp.da()*c;
146 vret(1,3) = cp.da()*cp.da();
152 vret(3,1) = 2*cp.cu()*
s;
153 vret(3,2) = -2*cp.cu()*c;
159bool Lpar::xy(
double r,
double &x,
double &
y,
int dir)
const {
160 double t_kr2g = kr2g(r);
161 double t_xi2 = xi2();
162 double ro = r * r * t_xi2 - t_kr2g * t_kr2g;
163 if ( ro < 0 )
return false;
164 double rs = sqrt(ro);
166 x = (- m_alpha * t_kr2g - m_beta * rs) / t_xi2;
167 y = (- m_beta * t_kr2g + m_alpha * rs) / t_xi2;
169 x = (- m_alpha * t_kr2g + m_beta * rs) / t_xi2;
170 y = (- m_beta * t_kr2g - m_alpha * rs) / t_xi2;
175double Lpar::x(
double r)
const {
181double Lpar::y(
double r)
const {
189 if (!xy(r,
x,
y, dir))
return -1;
190 double p = atan2(
y,
x);
191 if (p<0) p += (2*
M_PI);
195void Lpar::xhyh(
double x,
double y,
double &xh,
double &yh)
const {
196 double ddm =
dr(x,
y);
202 double kdp1 = 1 + 2 *
kappa() * ddm;
203 xh =
x - ddm * ( 2 *
kappa() *
x + alpha())/kdp1;
204 yh =
y - ddm * ( 2 *
kappa() *
y + beta())/kdp1;
208 double xh, yh, xx, yy;
210 double fk = fabs(
kappa());
212 yy = 2 * fk * ( alpha() * yh - beta() * xh);
213 xx = 2 *
kappa() * ( alpha() * xh + beta() * yh ) + xi2();
214 double sp = atan2(yy, xx);
215 if (sp<0) sp += (2*
M_PI);
221 if (fabs(r)<fabs(d0))
return -1;
222 double b = fabs(
kappa()) * sqrt((r*r-d0*d0)/(1 + 2 *
kappa() * d0));
223 if (fabs(
b)>1)
return -1;
224 if(dir==0)
return asin(
b)/fabs(
kappa());
229#ifdef BELLE_OPTIMIZED_RETURN
243 HepVector cen1(lp1.
center());
244 HepVector cen2(lp2.
center());
245 double dx = cen1(1)-cen2(1);
246 double dy = cen1(2)-cen2(2);
247 double dc = sqrt(dx*dx+dy*dy);
249 double a1 = std::sqrt(lp1.alpha()) + std::sqrt(lp1.beta());
250 double a2 = std::sqrt(lp2.alpha()) + std::sqrt(lp2.beta());
251 double a3 = lp1.alpha()*lp2.alpha() + lp1.beta()*lp2.beta();
252 double det = lp1.alpha()*lp2.beta() - lp1.beta()*lp2.alpha();
253 if(fabs(det)>1e-12) {
254 double c1 = a2 * std::sqrt(lp1.
kappa()) + a1 * std::sqrt(lp2.
kappa()) -
257 double cinv = 1.0 / c1;
258 double c2 = std::sqrt(a3) - 0.5 * (a1 + a2) - 2.0 * a3 *
259 (lp1.gamma() * lp2.
kappa() + lp2.gamma() * lp1.
kappa());
260 double c3 = a2 * std::sqrt(lp1.gamma()) + a1 * std::sqrt(lp2.gamma()) -
261 2.0 * a3 * lp1.gamma() * lp2.gamma();
262 double root = std::sqrt(c2) - 4.0 * c1 * c3;
266 rad2[0] = 0.5 * cinv * (-c2 -
root);
267 rad2[1] = 0.5 * cinv * (-c2 +
root);
268 double ab1 = -(lp2.beta() * lp1.gamma() - lp1.beta() * lp2.gamma());
269 double ab2 = (lp2.alpha() * lp1.gamma() - lp1.alpha() * lp2.gamma());
270 double ac1 = -(lp2.beta() * lp1.
kappa() - lp1.beta() * lp2.
kappa());
271 double ac2 = (lp2.alpha() * lp1.
kappa() - lp1.alpha() * lp2.
kappa());
272 double dinv = 1.0 / det;
273 v1(1) = dinv * (ab1 + ac1 * rad2[0]);
274 v1(2) = dinv * (ab2 + ac2 * rad2[0]);
276 v2(1) = dinv * (ab1 + ac1 * rad2[1]);
277 v2(2) = dinv * (ab2 + ac2 * rad2[1]);
279 double d1 = lp1.
d(v1(1),v1(2));
280 double d2 = lp2.
d(v1(1),v1(2));
281 double d3 = lp1.
d(v2(1),v2(2));
282 double d4 = lp2.
d(v2(1),v2(2));
283 double r = sqrt(rad2[0]);
286 for(
int j=0;j<2;j++) {
289 s1 = lp1.
s(v1(1),v1(2));
290 s2 = lp2.
s(v1(1),v1(2));
292 s1 = lp1.
s(v2(1),v2(2));
293 s2 = lp2.
s(v2(1),v2(2));
295 double phi1 = cp1.fi() + 2 * cp1.cu() * s1;
296 double phi2 = cp2.fi() + 2 * cp2.cu() * s2;
297 double f = (1 + 2 * cp1.cu() * cp1.da()) *
298 (1 + 2 * cp2.cu() * cp2.da()) *
cos(cp1.fi()-cp2.fi());
299 f -= 2 * (lp1.gamma() * lp2.
kappa() + lp2.gamma() * lp1.
kappa());
319 return o <<
" al=" <<
s.m_alpha <<
" be=" <<
s.m_beta
320 <<
" ka=" <<
s.m_kappa <<
" ga=" <<
s.m_gamma;
double sin(const BesAngle a)
double cos(const BesAngle a)
std::ostream & operator<<(std::ostream &o, Lpar &s)
int intersect(const Lpar &lp1, const Lpar &lp2, HepVector &v1, HepVector &v2)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
double dr(double x, double y) const
double d(double x, double y) const
void circle(double x1, double y1, double x2, double y2, double x3, double y3)
double s(double x, double y) const
double phi(double r, int dir=0) const
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")