BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitAlg/KalFitAlg-00-07-55-p03/src/lpav/Lpar.cxx
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// Package: <package>
4// Module: Lpar
5//
6// Description: <one line class summary>
7//
8// Implimentation:
9// <Notes on implimentation>
10//
11// Author: KATAYAMA Nobuhiko
12// Created: Fri Feb 6 10:21:49 JST 1998
13
14
15#include <iostream>
16
17// system include files
18#include <cmath>
19// user include files
20#include "KalFitAlg/lpav/Lpar.h"
21using CLHEP::HepVector;
22using CLHEP::Hep3Vector;
23using CLHEP::HepMatrix;
24using CLHEP::HepSymMatrix;
25//
26// constants, enums and typedefs
27//
28// static data member definitions
29//
30const double Lpar::BELLE_ALPHA(333.564095);
31
32// constructors and destructor
33//
34// Lpar::Lpar(double x1, double y1, double x2, double y2, double x3, double y3) {
35// circle(x1, y1, x2, y2, x3, y3);
36// }
37Lpar::Cpar::Cpar(const Lpar&l) {
38 m_cu = l.kappa();
39 if (l.alpha() !=0 && l.beta() !=0)
40 m_fi = atan2(l.alpha(), -l.beta());
41 else m_fi = 0;
42 if(m_fi<0) m_fi+=2*M_PI;
43 m_da = 2 * l.gamma()/ (1 + sqrt (1 + 4 * l.kappa() * l.gamma()));
44 m_cfi = cos(m_fi);
45 m_sfi = sin(m_fi);
46}
47
48// Lpar::Lpar( const Lpar& )
49// {
50// }
51
53{
54}
55
56//
57// assignment operators
58//
59// const Lpar& Lpar::operator=( const Lpar& )
60// {
61// }
62
63//
64// comparison operators
65//
66// bool Lpar::operator==( const Lpar& ) const
67// {
68// }
69
70// bool Lpar::operator!=( const Lpar& ) const
71// {
72// }
73
74//
75// member functions
76//
77void Lpar::circle(double x1, double y1, double x2, double y2,
78 double x3, double y3) {
79 double a;
80 double b;
81 double c;
82 double delta = (x1-x2)*(y1-y3) - (y1-y2)*(x1-x3);
83 if(delta==0) {
84 //
85 // three points are on a line.
86 //
87 m_kappa = 0;
88 double r12sq = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
89 if (r12sq>0) {
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);
94 } else {
95 double r13sq = (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3);
96 if (r13sq>0) {
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);
101 } else {
102 double r23sq = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3);
103 if (r23sq>0) {
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);
108 } else {
109 m_alpha = 1;
110 m_beta = 0;
111 m_gamma = 0;
112 }
113 }
114 }
115 } else {
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);
122 c = sqrt(csq);
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;
129 }
130}
131
132HepMatrix Lpar::dldc() const
133#ifdef BELLE_OPTIMIZED_RETURN
134return vret(3,4);
135{
136#else
137{
138 HepMatrix vret(3,4);
139#endif
140 Cpar cp(*this);
141 double xi = cp.xi();
142 double s = cp.sfi();
143 double c = cp.cfi();
144 vret(1,1) = 2*cp.da()*s;
145 vret(1,2) = -2*cp.da()*c;
146 vret(1,3) = cp.da()*cp.da();
147 vret(1,4) = 1;
148 vret(2,1) = xi*c;
149 vret(2,2) = xi*s;
150 vret(2,3) = 0;
151 vret(2,4) = 0;
152 vret(3,1) = 2*cp.cu()*s;
153 vret(3,2) = -2*cp.cu()*c;
154 vret(3,3) = xi;
155 vret(3,4) = 0;
156 return vret;
157}
158
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);
165 if(dir==0) {
166 x = (- m_alpha * t_kr2g - m_beta * rs) / t_xi2;
167 y = (- m_beta * t_kr2g + m_alpha * rs) / t_xi2;
168 } else {
169 x = (- m_alpha * t_kr2g + m_beta * rs) / t_xi2;
170 y = (- m_beta * t_kr2g - m_alpha * rs) / t_xi2;
171 }
172 return true;
173}
174
175double Lpar::x(double r) const {
176 double t_x, t_y;
177 xy(r, t_x, t_y);
178 return t_x;
179}
180
181double Lpar::y(double r) const {
182 double t_x, t_y;
183 xy(r, t_x, t_y);
184 return t_y;
185}
186
187double Lpar::phi(double r,int dir) const {
188 double x, y;
189 if (!xy(r,x,y, dir)) return -1;
190 double p = atan2(y,x);
191 if (p<0) p += (2*M_PI);
192 return p;
193}
194
195void Lpar::xhyh(double x, double y, double &xh, double &yh) const {
196 double ddm = dr(x, y);
197 if (ddm==0) {
198 xh = x;
199 yh = y;
200 return;
201 }
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;
205}
206
207double Lpar::s(double x, double y) const {
208 double xh, yh, xx, yy;
209 xhyh(x, y, xh, yh);
210 double fk = fabs(kappa());
211 if (fk==0) return 0;
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);
216 return sp / 2 / fk;
217}
218
219double Lpar::s(double r, int dir) const {
220 double d0 = da();
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());
225 return (M_PI-asin(b))/fabs(kappa());
226}
227
228HepVector Lpar::center() const
229#ifdef BELLE_OPTIMIZED_RETURN
230return v(3);
231{
232#else
233{
234 HepVector v(3);
235#endif
236 v(1) = xc();
237 v(2) = yc();
238 v(3) = 0;
239 return(v);
240}
241
242int intersect(const Lpar&lp1, const Lpar&lp2, HepVector&v1, HepVector&v2) {
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);
248 if(dc<fabs(0.5/lp1.kappa())+fabs(0.5/lp2.kappa())) {
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()) -
255 2.0 * a3 * lp1.kappa() * lp2.kappa();
256 if(c1!=0) {
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;
263 if (root>=0) {
264 root = sqrt(root);
265 double rad2[2];
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]);
275 v1(3) = 0;
276 v2(1) = dinv * (ab1 + ac1 * rad2[1]);
277 v2(2) = dinv * (ab2 + ac2 * rad2[1]);
278 v2(3) = 0;
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]);
284 Lpar::Cpar cp1(lp1);
285 Lpar::Cpar cp2(lp2);
286 for(int j=0;j<2;j++) {
287 double s1,s2;
288 if(j==0) {
289 s1 = lp1.s(v1(1),v1(2));
290 s2 = lp2.s(v1(1),v1(2));
291 } else {
292 s1 = lp1.s(v2(1),v2(2));
293 s2 = lp2.s(v2(1),v2(2));
294 }
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());
300 double cosphi12 = f;
301 }
302 return 2;
303 }
304 }
305 }
306 }
307 return 0;
308}
309
310//
311// const member functions
312//
313
314//
315// static member functions
316//
317
318std::ostream& operator<<(std::ostream &o, Lpar &s) {
319 return o << " al=" << s.m_alpha << " be=" << s.m_beta
320 << " ka=" << s.m_kappa << " ga=" << s.m_gamma;
321}
322
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
std::string root
Definition: CalibModel.cxx:39
Double_t phi2
Double_t x[10]
Double_t phi1
int dc[18]
Definition: EvtPycont.cc:41
XmlRpcServer s
Definition: HelloServer.cpp:11
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
Definition: KarLud.h:35
#define M_PI
Definition: TConstant.h:4
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
TCanvas * c1
Definition: tau_mode.c:75