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