CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitAlg/KalFitAlg-00-15-20/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//
30
31
32namespace KalmanFit{
33
34const double Lpar::BELLE_ALPHA(333.564095);
35
36// constructors and destructor
37//
38// Lpar::Lpar(double x1, double y1, double x2, double y2, double x3, double y3) {
39// circle(x1, y1, x2, y2, x3, y3);
40// }
41Lpar::Cpar::Cpar(const Lpar&l) {
42 m_cu = l.kappa();
43 if (l.alpha() !=0 && l.beta() !=0)
44 m_fi = atan2(l.alpha(), -l.beta());
45 else m_fi = 0;
46 if(m_fi<0) m_fi+=2*M_PI;
47 m_da = 2 * l.gamma()/ (1 + sqrt (1 + 4 * l.kappa() * l.gamma()));
48 m_cfi = cos(m_fi);
49 m_sfi = sin(m_fi);
50}
51
52// Lpar::Lpar( const Lpar& )
53// {
54// }
55
57{
58}
59
60//
61// assignment operators
62//
63// const Lpar& Lpar::operator=( const Lpar& )
64// {
65// }
66
67//
68// comparison operators
69//
70// bool Lpar::operator==( const Lpar& ) const
71// {
72// }
73
74// bool Lpar::operator!=( const Lpar& ) const
75// {
76// }
77
78//
79// member functions
80//
81void Lpar::circle(double x1, double y1, double x2, double y2,
82 double x3, double y3) {
83 double a;
84 double b;
85 double c;
86 double delta = (x1-x2)*(y1-y3) - (y1-y2)*(x1-x3);
87 if(delta==0) {
88 //
89 // three points are on a line.
90 //
91 m_kappa = 0;
92 double r12sq = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
93 if (r12sq>0) {
94 double r12 = sqrt(r12sq);
95 m_beta = -(x1-x2)/r12;
96 m_alpha = (y1-y2)/r12;
97 m_gamma = - (m_alpha*x1+m_beta*y1);
98 } else {
99 double r13sq = (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3);
100 if (r13sq>0) {
101 double r13 = sqrt(r13sq);
102 m_beta = -(x1-x3)/r13;
103 m_alpha = (y1-y3)/r13;
104 m_gamma = - (m_alpha*x3+m_beta*y3);
105 } else {
106 double r23sq = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3);
107 if (r23sq>0) {
108 double r23 = sqrt(r23sq);
109 m_beta = -(x2-x3)/r23;
110 m_alpha = (y2-y3)/r23;
111 m_gamma = - (m_alpha*x3+m_beta*y3);
112 } else {
113 m_alpha = 1;
114 m_beta = 0;
115 m_gamma = 0;
116 }
117 }
118 }
119 } else {
120 double r1sq = x1 * x1 + y1 * y1;
121 double r2sq = x2 * x2 + y2 * y2;
122 double r3sq = x3 * x3 + y3 * y3;
123 a = 0.5 * ( (y1-y3)*(r1sq-r2sq) - (y1-y2)*(r1sq-r3sq)) / delta;
124 b = 0.5 * (- (x1-x3)*(r1sq-r2sq) + (x1-x2)*(r1sq-r3sq)) / delta;
125 double csq = (x1-a)*(x1-a) + (y1-b)*(y1-b);
126 c = sqrt(csq);
127 double csq2 = (x2-a)*(x2-a) + (y2-b)*(y2-b);
128 double csq3 = (x3-a)*(x3-a) + (y3-b)*(y3-b);
129 m_kappa = 1 / (2 * c);
130 m_alpha = - 2 * a * m_kappa;
131 m_beta = - 2 * b * m_kappa;
132 m_gamma = (a*a + b*b - c*c) * m_kappa;
133 }
134}
135
136HepMatrix Lpar::dldc() const
137#ifdef BELLE_OPTIMIZED_RETURN
138return vret(3,4);
139{
140#else
141{
142 HepMatrix vret(3,4);
143#endif
144 Cpar cp(*this);
145 double xi = cp.xi();
146 double s = cp.sfi();
147 double c = cp.cfi();
148 vret(1,1) = 2*cp.da()*s;
149 vret(1,2) = -2*cp.da()*c;
150 vret(1,3) = cp.da()*cp.da();
151 vret(1,4) = 1;
152 vret(2,1) = xi*c;
153 vret(2,2) = xi*s;
154 vret(2,3) = 0;
155 vret(2,4) = 0;
156 vret(3,1) = 2*cp.cu()*s;
157 vret(3,2) = -2*cp.cu()*c;
158 vret(3,3) = xi;
159 vret(3,4) = 0;
160 return vret;
161}
162
163bool Lpar::xy(double r, double &x, double &y, int dir) const {
164 double t_kr2g = kr2g(r);
165 double t_xi2 = xi2();
166 double ro = r * r * t_xi2 - t_kr2g * t_kr2g;
167 if ( ro < 0 ) return false;
168 double rs = sqrt(ro);
169 if(dir==0) {
170 x = (- m_alpha * t_kr2g - m_beta * rs) / t_xi2;
171 y = (- m_beta * t_kr2g + m_alpha * rs) / t_xi2;
172 } else {
173 x = (- m_alpha * t_kr2g + m_beta * rs) / t_xi2;
174 y = (- m_beta * t_kr2g - m_alpha * rs) / t_xi2;
175 }
176 return true;
177}
178
179double Lpar::x(double r) const {
180 double t_x, t_y;
181 xy(r, t_x, t_y);
182 return t_x;
183}
184
185double Lpar::y(double r) const {
186 double t_x, t_y;
187 xy(r, t_x, t_y);
188 return t_y;
189}
190
191double Lpar::phi(double r,int dir) const {
192 double x, y;
193 if (!xy(r,x,y, dir)) return -1;
194 double p = atan2(y,x);
195 if (p<0) p += (2*M_PI);
196 return p;
197}
198
199void Lpar::xhyh(double x, double y, double &xh, double &yh) const {
200 double ddm = dr(x, y);
201 if (ddm==0) {
202 xh = x;
203 yh = y;
204 return;
205 }
206 double kdp1 = 1 + 2 * kappa() * ddm;
207 xh = x - ddm * ( 2 * kappa() * x + alpha())/kdp1;
208 yh = y - ddm * ( 2 * kappa() * y + beta())/kdp1;
209}
210
211double Lpar::s(double x, double y) const {
212 double xh, yh, xx, yy;
213 xhyh(x, y, xh, yh);
214 double fk = fabs(kappa());
215 if (fk==0) return 0;
216 yy = 2 * fk * ( alpha() * yh - beta() * xh);
217 xx = 2 * kappa() * ( alpha() * xh + beta() * yh ) + xi2();
218 double sp = atan2(yy, xx);
219 if (sp<0) sp += (2*M_PI);
220 return sp / 2 / fk;
221}
222
223double Lpar::s(double r, int dir) const {
224 double d0 = da();
225 if (fabs(r)<fabs(d0)) return -1;
226 double b = fabs(kappa()) * sqrt((r*r-d0*d0)/(1 + 2 * kappa() * d0));
227 if (fabs(b)>1) return -1;
228 if(dir==0)return asin(b)/fabs(kappa());
229 return (M_PI-asin(b))/fabs(kappa());
230}
231
232HepVector Lpar::center() const
233#ifdef BELLE_OPTIMIZED_RETURN
234return v(3);
235{
236#else
237{
238 HepVector v(3);
239#endif
240 v(1) = xc();
241 v(2) = yc();
242 v(3) = 0;
243 return(v);
244}
245
246int intersect(const Lpar&lp1, const Lpar&lp2, HepVector&v1, HepVector&v2) {
247 HepVector cen1(lp1.center());
248 HepVector cen2(lp2.center());
249 double dx = cen1(1)-cen2(1);
250 double dy = cen1(2)-cen2(2);
251 double dc = sqrt(dx*dx+dy*dy);
252 if(dc<fabs(0.5/lp1.kappa())+fabs(0.5/lp2.kappa())) {
253 double a1 = std::sqrt(lp1.alpha()) + std::sqrt(lp1.beta());
254 double a2 = std::sqrt(lp2.alpha()) + std::sqrt(lp2.beta());
255 double a3 = lp1.alpha()*lp2.alpha() + lp1.beta()*lp2.beta();
256 double det = lp1.alpha()*lp2.beta() - lp1.beta()*lp2.alpha();
257 if(fabs(det)>1e-12) {
258 double c1 = a2 * std::sqrt(lp1.kappa()) + a1 * std::sqrt(lp2.kappa()) -
259 2.0 * a3 * lp1.kappa() * lp2.kappa();
260 if(c1!=0) {
261 double cinv = 1.0 / c1;
262 double c2 = std::sqrt(a3) - 0.5 * (a1 + a2) - 2.0 * a3 *
263 (lp1.gamma() * lp2.kappa() + lp2.gamma() * lp1.kappa());
264 double c3 = a2 * std::sqrt(lp1.gamma()) + a1 * std::sqrt(lp2.gamma()) -
265 2.0 * a3 * lp1.gamma() * lp2.gamma();
266 double root = std::sqrt(c2) - 4.0 * c1 * c3;
267 if (root>=0) {
268 root = sqrt(root);
269 double rad2[2];
270 rad2[0] = 0.5 * cinv * (-c2 - root);
271 rad2[1] = 0.5 * cinv * (-c2 + root);
272 double ab1 = -(lp2.beta() * lp1.gamma() - lp1.beta() * lp2.gamma());
273 double ab2 = (lp2.alpha() * lp1.gamma() - lp1.alpha() * lp2.gamma());
274 double ac1 = -(lp2.beta() * lp1.kappa() - lp1.beta() * lp2.kappa());
275 double ac2 = (lp2.alpha() * lp1.kappa() - lp1.alpha() * lp2.kappa());
276 double dinv = 1.0 / det;
277 v1(1) = dinv * (ab1 + ac1 * rad2[0]);
278 v1(2) = dinv * (ab2 + ac2 * rad2[0]);
279 v1(3) = 0;
280 v2(1) = dinv * (ab1 + ac1 * rad2[1]);
281 v2(2) = dinv * (ab2 + ac2 * rad2[1]);
282 v2(3) = 0;
283 double d1 = lp1.d(v1(1),v1(2));
284 double d2 = lp2.d(v1(1),v1(2));
285 double d3 = lp1.d(v2(1),v2(2));
286 double d4 = lp2.d(v2(1),v2(2));
287 double r = sqrt(rad2[0]);
288 Lpar::Cpar cp1(lp1);
289 Lpar::Cpar cp2(lp2);
290 for(int j=0;j<2;j++) {
291 double s1,s2;
292 if(j==0) {
293 s1 = lp1.s(v1(1),v1(2));
294 s2 = lp2.s(v1(1),v1(2));
295 } else {
296 s1 = lp1.s(v2(1),v2(2));
297 s2 = lp2.s(v2(1),v2(2));
298 }
299 double phi1 = cp1.fi() + 2 * cp1.cu() * s1;
300 double phi2 = cp2.fi() + 2 * cp2.cu() * s2;
301 double f = (1 + 2 * cp1.cu() * cp1.da()) *
302 (1 + 2 * cp2.cu() * cp2.da()) * cos(cp1.fi()-cp2.fi());
303 f -= 2 * (lp1.gamma() * lp2.kappa() + lp2.gamma() * lp1.kappa());
304 double cosphi12 = f;
305 }
306 return 2;
307 }
308 }
309 }
310 }
311 return 0;
312}
313
314//
315// const member functions
316//
317
318//
319// static member functions
320//
321
322std::ostream& operator<<(std::ostream &o, Lpar &s) {
323 return o << " al=" << s.m_alpha << " be=" << s.m_beta
324 << " ka=" << s.m_kappa << " ga=" << s.m_gamma;
325}
326
327}
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
std::string root
TCanvas * c1
Double_t phi2
Double_t x[10]
Double_t phi1
int dc[18]
Definition EvtPycont.cc:42
XmlRpcServer s
**********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
friend std::ostream & operator<<(std::ostream &o, Lpar &)
friend int intersect(const Lpar &, const Lpar &, HepVector &, HepVector &)
void circle(double x1, double y1, double x2, double y2, double x3, double y3)
double phi(double r, int dir=0) const