CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitAlg/KalFitAlg-00-15-20/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(KALFIT_LPAR_H_INCLUDED)
16#define KALFIT_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
41namespace KalmanFit {
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// inline function definitions
150
151// inline Lpar::Lpar(double a, double b, double k, double g) {
152// m_alpha = a; m_beta = b; m_kappa = k; m_gamma = g;
153// }
154
155inline Lpar::Lpar() {
156 m_alpha = 0;
157 m_beta = 1;
158 m_gamma = 0;
159 m_kappa = 0;
160}
161
162inline Lpar::Lpar(const Lpar&l) {
163 m_alpha = l.m_alpha;
164 m_beta = l.m_beta;
165 m_gamma = l.m_gamma;
166 m_kappa = l.m_kappa;
167}
168
169inline const Lpar&Lpar::operator=(const Lpar&l) {
170 if (this != &l) {
171 m_alpha = l.m_alpha;
172 m_beta = l.m_beta;
173 m_gamma = l.m_gamma;
174 m_kappa = l.m_kappa;
175 }
176 return *this;
177}
178
179inline void Lpar::rotate(double c, double s) {
180 double aLpar = c * m_alpha + s * m_beta;
181 double betar = -s * m_alpha + c * m_beta;
182 m_alpha = aLpar;
183 m_beta = betar;
184}
185
186inline void Lpar::move (double x, double y) {
187 m_gamma += m_kappa * ( x * x + y * y ) + m_alpha * x + m_beta * y;
188 m_alpha += 2 * m_kappa * x;
189 m_beta += 2 * m_kappa * y;
190}
191
192inline double Lpar::check() const {
193 return m_alpha * m_alpha + m_beta * m_beta - 4 * m_kappa * m_gamma - 1;
194}
195
196inline void Lpar::neg() {
197 m_alpha = -m_alpha;
198 m_beta = -m_beta;
199 m_gamma = -m_gamma;
200 m_kappa = -m_kappa;
201}
202
203inline double Lpar::d0(double x, double y) const {
204 return m_alpha * x + m_beta * y + m_gamma + m_kappa * ( x * x + y * y);
205}
206
207inline double Lpar::d(double x, double y) const {
208 double dd = d0(x,y);
209 const double approx_limit = 0.2;
210 if(std::fabs(m_kappa*dd)>approx_limit) return -1;
211 return dd * ( 1 - m_kappa * dd );
212}
213
214inline double Lpar::dr(double x, double y) const {
215 double dx = xc() - x;
216 double dy = yc() - y;
217 double r = 0.5/std::fabs(m_kappa);
218 return std::fabs(std::sqrt(dx * dx + dy * dy) - r);
219}
220
221inline double Lpar::r_max() const {
222 if (m_kappa==0) return 100000000.0;
223 if (m_gamma==0) return 1/std::fabs(m_kappa);
224 return std::fabs(2*m_gamma/(std::sqrt(1+4*m_gamma*m_kappa)-1));
225}
226
227inline double Lpar::arcfun(double xh, double yh) const {
228 //
229 // Duet way of calculating Sperp.
230 //
231 double r2kap = 2.0 * m_kappa;
232 double xi = std::sqrt(xi2());
233 double xinv = 1.0 / xi;
234 double ar2kap = std::fabs(r2kap);
235 double cross = m_alpha * yh - m_beta * xh;
236 double a1 = ar2kap * cross * xinv;
237 double a2 = r2kap * (m_alpha * xh + m_beta * yh) * xinv + xi;
238 if (a1>=0 && a2>0 && a1<0.3) {
239 double arg2 = a1*a1;
240 return cross * ( 1.0 + arg2 * (1./6. + arg2 * (3./40.))) * xinv;
241 } else {
242 double at2 = std::atan2(a1,a2);
243 if (at2<0) at2 += (2*M_PI);
244 return at2/ar2kap;
245 }
246}
247
248inline int Lpar::sd(double r, double x, double y,
249 double limit, double & s, double & d) const{
250 if ((x*yc()-y*xc())*m_kappa<0) return 0;
251 double dd = d0(x,y);
252 d = dd * ( 1 - m_kappa * dd );
253 double d_cross_limit = d*limit;
254 if (d_cross_limit < 0 || d_cross_limit > limit*limit) return 0;
255
256 double rc = std::sqrt(m_alpha*m_alpha+m_beta*m_beta)/(2*m_kappa);
257 double rho = 1./(-2*m_kappa);
258 double cosPhi = (rc*rc + rho*rho - r*r)/(-2*rc*rho);
259 double phi = std::acos(cosPhi);
260 s = std::fabs(rho)*phi;
261 d *= r/(std::fabs(rc)*std::sin(phi));
262 if (abs(d) > abs(limit)) return 0;
263 d_cross_limit = d*limit;
264 if (d_cross_limit > limit*limit) return 0;
265 return 1;
266}
267
268inline HepVector Lpar::Hpar(const HepPoint3D & pivot) const{
269 HepVector a(5);
270 double dd = d0(pivot.x(),pivot.y());
271 a(1) = dd * ( m_kappa * dd - 1 );
272 a(2) = (m_kappa>0) ? std::atan2(yc() - pivot.y(), xc() - pivot.x()) + M_PI
273 : std::atan2(pivot.y() - yc(), pivot.x() - xc()) - M_PI;
274 a(3) = -2.0*BELLE_ALPHA*m_kappa;
275 a(4) = 0;
276 a(5) = 0;
277 return a;
278}
279
280}
281#endif /* KALFIT_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)
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
const double alpha
XmlRpcServer s
HepGeom::Point3D< double > HepPoint3D
#define M_PI
Definition TConstant.h:4
friend std::ostream & operator<<(std::ostream &o, Lpar &)
friend int intersect(const Lpar &, const Lpar &, HepVector &, HepVector &)
HepVector Hpar(const HepPoint3D &pivot) const
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)
double phi(double r, int dir=0) const