CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitAlg/KalFitAlg-00-15-14/KalFitAlg/lpav/Lpar.h
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// Usage:
9// <usage>
10//
11// Author: KATAYAMA Nobuhiko
12// Created: Fri Feb 6 10:21:31 JST 1998
13//
14
15#if !defined(PACKAGE_LPAR_H_INCLUDED)
16#define PACKAGE_LPAR_H_INCLUDED
17
18// system include files
19#include <iosfwd>
20#include <cmath>
21#include <iostream>
22
23// user include files
24#include "CLHEP/Matrix/Vector.h"
25#include "CLHEP/Matrix/Matrix.h"
26//#ifndef CLHEP_POINT3D_H
27#include "CLHEP/Geometry/Point3D.h"
28#ifndef ENABLE_BACKWARDS_COMPATIBILITY
30#endif
31//#endif
32
33 using CLHEP::HepVector;
34 using CLHEP::Hep3Vector;
35 using CLHEP::HepMatrix;
36 using CLHEP::HepSymMatrix;
37
38using namespace CLHEP;
39
40// forward declarations
41
42class Lpar
43{
44 // friend classes and functions
45
46 public:
47 // constants, enums and typedefs
48
49 // Constructors and destructor
50 Lpar();
51
52 virtual ~Lpar();
53
54 // assignment operator(s)
55 inline const Lpar& operator=( const Lpar& );
56
57 // member functions
58 inline void neg();
59 void circle(double x1, double y1, double x2, double y2,
60 double x3, double y3);
61
62 // const member functions
63 double kappa() const { return m_kappa; }
64 double radius() const { return 0.5/std::fabs(m_kappa);}
65 HepVector center() const;
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;
73 inline HepVector Hpar(const HepPoint3D & pivot) const;
74
75 // static member functions
76
77 // friend functions and classes
78 friend class Lpav;
79 friend std::ostream & operator<<(std::ostream &o, Lpar &);
80 friend int intersect(const Lpar&, const Lpar&, HepVector&, HepVector&);
81
82 protected:
83 // protected member functions
84
85 // protected const member functions
86
87 private:
88 // Private class cpar
89 class Cpar {
90 public:
91 Cpar(const Lpar&);
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; }
98 private:
99 double m_cu;
100 double m_fi;
101 double m_da;
102 double m_sfi;
103 double m_cfi;
104 };
105 friend class Lpar::Cpar;
106 // Constructors and destructor
107 inline Lpar( const Lpar& );
108
109 // comparison operators
110 bool operator==( const Lpar& ) const;
111 bool operator!=( const Lpar& ) const;
112
113 // private member functions
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);
117
118 // private const member functions
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;
136
137 // data members
138 double m_alpha;
139 double m_beta;
140 double m_gamma;
141 double m_kappa;
142
143
144 static const double BELLE_ALPHA;
145
146 // static data members
147
148};
149
150// inline function definitions
151
152// inline Lpar::Lpar(double a, double b, double k, double g) {
153// m_alpha = a; m_beta = b; m_kappa = k; m_gamma = g;
154// }
155
156inline Lpar::Lpar() {
157 m_alpha = 0;
158 m_beta = 1;
159 m_gamma = 0;
160 m_kappa = 0;
161}
162
163inline Lpar::Lpar(const Lpar&l) {
164 m_alpha = l.m_alpha;
165 m_beta = l.m_beta;
166 m_gamma = l.m_gamma;
167 m_kappa = l.m_kappa;
168}
169
170inline const Lpar&Lpar::operator=(const Lpar&l) {
171 if (this != &l) {
172 m_alpha = l.m_alpha;
173 m_beta = l.m_beta;
174 m_gamma = l.m_gamma;
175 m_kappa = l.m_kappa;
176 }
177 return *this;
178}
179
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;
183 m_alpha = aLpar;
184 m_beta = betar;
185}
186
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;
191}
192
193inline double Lpar::check() const {
194 return m_alpha * m_alpha + m_beta * m_beta - 4 * m_kappa * m_gamma - 1;
195}
196
197inline void Lpar::neg() {
198 m_alpha = -m_alpha;
199 m_beta = -m_beta;
200 m_gamma = -m_gamma;
201 m_kappa = -m_kappa;
202}
203
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);
206}
207
208inline double Lpar::d(double x, double y) const {
209 double dd = d0(x,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 );
213}
214
215inline double Lpar::dr(double x, double y) const {
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);
220}
221
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));
226}
227
228inline double Lpar::arcfun(double xh, double yh) const {
229 //
230 // Duet way of calculating Sperp.
231 //
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) {
240 double arg2 = a1*a1;
241 return cross * ( 1.0 + arg2 * (1./6. + arg2 * (3./40.))) * xinv;
242 } else {
243 double at2 = std::atan2(a1,a2);
244 if (at2<0) at2 += (2*M_PI);
245 return at2/ar2kap;
246 }
247}
248
249inline int Lpar::sd(double r, double x, double y,
250 double limit, double & s, double & d) const{
251 if ((x*yc()-y*xc())*m_kappa<0) return 0;
252 double dd = d0(x,y);
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;
256
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;
266 return 1;
267}
268
269inline HepVector Lpar::Hpar(const HepPoint3D & pivot) const{
270 HepVector a(5);
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;
276 a(4) = 0;
277 a(5) = 0;
278 return a;
279}
280
281#endif /* PACKAGE_LPAR_H_INCLUDED */
282
Double_t x[10]
bool operator==(const EventID &lhs, const EventID &rhs)
Definition: EventID.h:79
bool operator!=(const EventID &lhs, const EventID &rhs)
Definition: EventID.h:86
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
Definition: EvtVector3R.cc:84
const double alpha
XmlRpcServer s
Definition: HelloServer.cpp:11
HepGeom::Point3D< double > HepPoint3D
#define M_PI
Definition: TConstant.h:4
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