15#if !defined(PACKAGE_LPAR_H_INCLUDED)
16#define PACKAGE_LPAR_H_INCLUDED
24#include "CLHEP/Matrix/Vector.h"
25#include "CLHEP/Matrix/Matrix.h"
27#include "CLHEP/Geometry/Point3D.h"
28#ifndef ENABLE_BACKWARDS_COMPATIBILITY
33 using CLHEP::HepVector;
34 using CLHEP::Hep3Vector;
35 using CLHEP::HepMatrix;
36 using CLHEP::HepSymMatrix;
59 void circle(
double x1,
double y1,
double x2,
double y2,
60 double x3,
double y3);
63 double kappa()
const {
return m_kappa; }
64 double radius()
const {
return 0.5/std::fabs(m_kappa);}
66 double s(
double x,
double y)
const;
67 inline double d(
double x,
double y)
const;
68 inline double dr(
double x,
double y)
const;
69 double s(
double r,
int dir=0)
const;
70 double phi(
double r,
int dir=0)
const;
71 inline int sd(
double r,
double x,
double y,
72 double limit,
double &
s,
double &
d)
const;
92 double xi()
const{
return 1 + 2 * m_cu * m_da; }
93 double sfi()
const {
return m_sfi; }
94 double cfi()
const {
return m_cfi; }
95 double da()
const {
return m_da; }
96 double cu()
const {
return m_cu; }
97 double fi()
const {
return m_fi; }
114 void scale(
double s) { m_kappa /=
s; m_gamma *=
s; }
115 inline void rotate(
double c,
double s);
116 inline void move (
double x,
double y);
119 double alpha()
const {
return m_alpha; }
120 double beta()
const {
return m_beta; }
121 double gamma()
const {
return m_gamma; }
122 inline double check()
const;
123 HepMatrix dldc()
const;
124 inline double d0(
double x,
double y)
const;
125 double kr2g(
double r)
const {
return m_kappa * r * r + m_gamma; }
126 double x(
double r)
const;
127 double y(
double r)
const;
128 void xhyh(
double x,
double y,
double&xh,
double&yh)
const;
129 double xi2()
const {
return 1 + 4 * m_kappa * m_gamma; }
130 bool xy(
double,
double&,
double&,
int dir=0)
const;
131 inline double r_max()
const;
132 double xc()
const {
return - m_alpha/2/m_kappa; }
133 double yc()
const {
return - m_beta/2/m_kappa; }
134 double da()
const {
return 2 * gamma() / (std::sqrt(xi2()) + 1); }
135 inline double arcfun(
double xh,
double yh)
const;
144 static const double BELLE_ALPHA;
180inline void Lpar::rotate(
double c,
double s) {
181 double aLpar = c * m_alpha +
s * m_beta;
182 double betar = -
s * m_alpha + c * m_beta;
187inline void Lpar::move (
double x,
double y) {
188 m_gamma += m_kappa * (
x *
x +
y *
y ) + m_alpha * x + m_beta *
y;
189 m_alpha += 2 * m_kappa *
x;
190 m_beta += 2 * m_kappa *
y;
193inline double Lpar::check()
const {
194 return m_alpha * m_alpha + m_beta * m_beta - 4 * m_kappa * m_gamma - 1;
204inline double Lpar::d0(
double x,
double y)
const {
205 return m_alpha *
x + m_beta *
y + m_gamma + m_kappa * (
x *
x +
y *
y);
210 const double approx_limit = 0.2;
211 if(std::fabs(m_kappa*dd)>approx_limit)
return -1;
212 return dd * ( 1 - m_kappa * dd );
216 double dx = xc() -
x;
217 double dy = yc() -
y;
218 double r = 0.5/std::fabs(m_kappa);
219 return std::fabs(std::sqrt(dx * dx + dy * dy) - r);
222inline double Lpar::r_max()
const {
223 if (m_kappa==0)
return 100000000.0;
224 if (m_gamma==0)
return 1/std::fabs(m_kappa);
225 return std::fabs(2*m_gamma/(std::sqrt(1+4*m_gamma*m_kappa)-1));
228inline double Lpar::arcfun(
double xh,
double yh)
const {
232 double r2kap = 2.0 * m_kappa;
233 double xi = std::sqrt(xi2());
234 double xinv = 1.0 / xi;
235 double ar2kap = std::fabs(r2kap);
236 double cross = m_alpha * yh - m_beta * xh;
237 double a1 = ar2kap *
cross * xinv;
238 double a2 = r2kap * (m_alpha * xh + m_beta * yh) * xinv + xi;
239 if (a1>=0 && a2>0 && a1<0.3) {
241 return cross * ( 1.0 + arg2 * (1./6. + arg2 * (3./40.))) * xinv;
243 double at2 = std::atan2(a1,a2);
244 if (at2<0) at2 += (2*
M_PI);
250 double limit,
double &
s,
double &
d)
const{
251 if ((
x*yc()-
y*xc())*m_kappa<0)
return 0;
253 d = dd * ( 1 - m_kappa * dd );
254 double d_cross_limit =
d*limit;
255 if (d_cross_limit < 0 || d_cross_limit > limit*limit)
return 0;
257 double rc = std::sqrt(m_alpha*m_alpha+m_beta*m_beta)/(2*m_kappa);
258 double rho = 1./(-2*m_kappa);
259 double cosPhi = (rc*rc + rho*rho - r*r)/(-2*rc*rho);
260 double phi = std::acos(cosPhi);
261 s = std::fabs(rho)*
phi;
262 d *= r/(std::fabs(rc)*std::sin(
phi));
263 if (
abs(
d) >
abs(limit))
return 0;
264 d_cross_limit =
d*limit;
265 if (d_cross_limit > limit*limit)
return 0;
271 double dd = d0(pivot.x(),pivot.y());
272 a(1) = dd * ( m_kappa * dd - 1 );
273 a(2) = (m_kappa>0) ? std::atan2(yc() - pivot.y(), xc() - pivot.x()) +
M_PI
274 : std::atan2(pivot.y() - yc(), pivot.x() - xc()) -
M_PI;
275 a(3) = -2.0*BELLE_ALPHA*m_kappa;
bool operator==(const EventID &lhs, const EventID &rhs)
bool operator!=(const EventID &lhs, const EventID &rhs)
HepGeom::Point3D< double > HepPoint3D
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
double dr(double x, double y) const
double d(double x, double y) const
friend int intersect(const Lpar &, const Lpar &, HepVector &, HepVector &)
HepVector Hpar(const HepPoint3D &pivot) const
friend std::ostream & operator<<(std::ostream &o, Lpar &)
int sd(double r, double x, double y, double limit, double &s, double &d) const
void circle(double x1, double y1, double x2, double y2, double x3, double y3)
const Lpar & operator=(const Lpar &)
double phi(double r, int dir=0) const