BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
TrackUtil/TrackUtil-00-00-08/TrackUtil/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// $Id: Lpar.h,v 1.3 2009/11/30 02:22:44 zhangy Exp $
14//
15
16#if !defined(PACKAGE_LPAR_H_INCLUDED)
17#define PACKAGE_LPAR_H_INCLUDED
18
19// system include files
20#include <iosfwd>
21#include <cmath>
22#include <iostream>
23#include "TrackUtil/Helix.h"
24#include "GaudiKernel/StatusCode.h"
25#include "GaudiKernel/IInterface.h"
26#include "GaudiKernel/Kernel.h"
27#include "GaudiKernel/Service.h"
28#include "GaudiKernel/ISvcLocator.h"
29#include "GaudiKernel/SvcFactory.h"
30#include "GaudiKernel/IDataProviderSvc.h"
31#include "GaudiKernel/Bootstrap.h"
32
35
36// user include files
37#include "CLHEP/Matrix/Vector.h"
38#include "CLHEP/Matrix/Matrix.h"
39#ifndef CLHEP_POINT3D_H
40#include "CLHEP/Geometry/Point3D.h"
41#endif
42#ifndef ENABLE_BACKWARDS_COMPATIBILITY
44#endif
45using namespace CLHEP;
46
47// forward declarations
48
49class Lpar
50{
51 // friend classes and functions
52
53 public:
54 // constants, enums and typedefs
55
56 // Constructors and destructor
58
59 virtual ~Lpar();
60 private:
61 IMagneticFieldSvc* m_pmgnIMF;
62
63 public:
64 // assignment operator(s)
65 inline const Lpar& operator=( const Lpar& );
66
67 // member functions
68 inline void neg();
69 void circle(double x1, double y1, double x2, double y2,
70 double x3, double y3);
71
72 // const member functions
73 double kappa() const { return m_kappa; }
74 double radius() const { return 0.5/std::fabs(m_kappa);}
75 HepVector center() const;
76 double s(double x, double y) const;
77 inline double d(double x, double y) const;
78 inline double dr(double x, double y) const;
79 double s(double r, int dir=0) const;
80 double phi(double r, int dir=0) const;
81 inline int sd(double r, double x, double y,
82 double limit, double & s, double & d) const;
83 inline HepVector Hpar(const HepPoint3D & pivot) const;
84 // static member functions
85
86 // friend functions and classes
87 friend class Lpav;
88 friend std::ostream & operator<<(std::ostream &o, Lpar &);
89 friend int intersect(const Lpar&, const Lpar&, HepVector&, HepVector&);
90
91 protected:
92 // protected member functions
93
94 // protected const member functions
95 private:
96 // Private class cpar
97 class Cpar {
98 public:
99 Cpar(const Lpar&);
100 double xi() const{ return 1 + 2 * m_cu * m_da; }
101 double sfi() const { return m_sfi; }
102 double cfi() const { return m_cfi; }
103 double da() const { return m_da; }
104 double cu() const { return m_cu; }
105 double fi() const { return m_fi; }
106 private:
107 double m_cu;
108 double m_fi;
109 double m_da;
110 double m_sfi;
111 double m_cfi;
112 };
113 friend class Lpar::Cpar;
114 // Constructors and destructor
115 inline Lpar( const Lpar& );
116
117 // comparison operators
118 bool operator==( const Lpar& ) const;
119 bool operator!=( const Lpar& ) const;
120
121 // private member functions
122 void scale(double s) { m_kappa /= s; m_gamma *= s; }
123 inline void rotate(double c, double s);
124 inline void move (double x, double y);
125
126 // private const member functions
127 double alpha() const { return m_alpha; }
128 double beta() const { return m_beta; }
129 double gamma() const { return m_gamma; }
130 inline double check() const;
131 HepMatrix dldc() const;
132 inline double d0(double x, double y) const;
133 double kr2g(double r) const { return m_kappa * r * r + m_gamma; }
134 double x(double r) const;
135 double y(double r) const;
136 void xhyh(double x, double y, double&xh, double&yh) const;
137 double xi2() const { return 1 + 4 * m_kappa * m_gamma; }
138 bool xy(double, double&, double&, int dir=0) const;
139 inline double r_max() const;
140 double xc() const { return - m_alpha/2/m_kappa; }
141 double yc() const { return - m_beta/2/m_kappa; }
142 double da() const { return 2 * gamma() / (std::sqrt(xi2()) + 1); }
143 inline double arcfun(double xh, double yh) const;
144
145 // data members
146 double m_alpha;
147 double m_beta;
148 double m_gamma;
149 double m_kappa;
150
151
152 // static const double BELLE_ALPHA;
153
154 // static data members
155
156};
157
158// inline function definitions
159
160// inline Lpar::Lpar(double a, double b, double k, double g) {
161// m_alpha = a; m_beta = b; m_kappa = k; m_gamma = g;
162// }
163
164inline Lpar::Lpar() {
165 m_alpha = 0;
166 m_beta = 1;
167 m_gamma = 0;
168 m_kappa = 0;
169 StatusCode scmgn = Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF);
170 if(scmgn!=StatusCode::SUCCESS) {
171 std::cout<< "Unable to open Magnetic field service"<<std::endl;
172 }
173}
174
175inline Lpar::Lpar(const Lpar&l) {
176 m_alpha = l.m_alpha;
177 m_beta = l.m_beta;
178 m_gamma = l.m_gamma;
179 m_kappa = l.m_kappa;
180}
181
182inline const Lpar&Lpar::operator=(const Lpar&l) {
183 if (this != &l) {
184 m_alpha = l.m_alpha;
185 m_beta = l.m_beta;
186 m_gamma = l.m_gamma;
187 m_kappa = l.m_kappa;
188 }
189 return *this;
190}
191
192inline void Lpar::rotate(double c, double s) {
193 double aLpar = c * m_alpha + s * m_beta;
194 double betar = -s * m_alpha + c * m_beta;
195 m_alpha = aLpar;
196 m_beta = betar;
197}
198
199inline void Lpar::move (double x, double y) {
200 m_gamma += m_kappa * ( x * x + y * y ) + m_alpha * x + m_beta * y;
201 m_alpha += 2 * m_kappa * x;
202 m_beta += 2 * m_kappa * y;
203}
204
205inline double Lpar::check() const {
206 return m_alpha * m_alpha + m_beta * m_beta - 4 * m_kappa * m_gamma - 1;
207}
208
209inline void Lpar::neg() {
210 m_alpha = -m_alpha;
211 m_beta = -m_beta;
212 m_gamma = -m_gamma;
213 m_kappa = -m_kappa;
214}
215
216inline double Lpar::d0(double x, double y) const {
217 return m_alpha * x + m_beta * y + m_gamma + m_kappa * ( x * x + y * y);
218}
219
220inline double Lpar::d(double x, double y) const {
221 double dd = d0(x,y);
222 const double approx_limit = 0.2;
223 if(std::fabs(m_kappa*dd)>approx_limit) return -1;
224 return dd * ( 1 - m_kappa * dd );
225}
226
227inline double Lpar::dr(double x, double y) const {
228 double dx = xc() - x;
229 double dy = yc() - y;
230 double r = 0.5/std::fabs(m_kappa);
231 return std::fabs(std::sqrt(dx * dx + dy * dy) - r);
232}
233
234inline double Lpar::r_max() const {
235 if (m_kappa==0) return 100000000.0;
236 if (m_gamma==0) return 1/std::fabs(m_kappa);
237 return std::fabs(2*m_gamma/(std::sqrt(1+4*m_gamma*m_kappa)-1));
238}
239
240inline double Lpar::arcfun(double xh, double yh) const {
241 //
242 // Duet way of calculating Sperp.
243 //
244 double r2kap = 2.0 * m_kappa;
245 double xi = std::sqrt(xi2());
246 double xinv = 1.0 / xi;
247 double ar2kap = std::fabs(r2kap);
248 double cross = m_alpha * yh - m_beta * xh;
249 double a1 = ar2kap * cross * xinv;
250 double a2 = r2kap * (m_alpha * xh + m_beta * yh) * xinv + xi;
251 if (a1>=0 && a2>0 && a1<0.3) {
252 double arg2 = a1*a1;
253 return cross * ( 1.0 + arg2 * (1./6. + arg2 * (3./40.))) * xinv;
254 } else {
255 double at2 = std::atan2(a1,a2);
256 if (at2<0) at2 += (2*M_PI);
257 return at2/ar2kap;
258 }
259}
260
261inline int Lpar::sd(double r, double x, double y,
262 double limit, double & s, double & d) const{
263 if ((x*yc()-y*xc())*m_kappa<0) return 0;
264 double dd = d0(x,y);
265 d = dd * ( 1 - m_kappa * dd );
266 double d_cross_limit = d*limit;
267 if (d_cross_limit < 0 || d_cross_limit > limit*limit) return 0;
268 double rc = std::sqrt(m_alpha*m_alpha+m_beta*m_beta)/(2*m_kappa);
269 double rho = 1./(-2*m_kappa);
270 double cosPhi = (rc*rc + rho*rho - r*r)/(-2*rc*rho);
271 double phi = std::acos(cosPhi);
272 s = std::fabs(rho)*phi;
273 d *= r/(std::fabs(rc)*std::sin(phi));
274 if (abs(d) > abs(limit)) return 0;
275 d_cross_limit = d*limit;
276 if (d_cross_limit > limit*limit) return 0;
277 return 1;
278}
279
280inline HepVector Lpar::Hpar(const HepPoint3D & pivot) const{
281 HepVector a(5);
282 double m_bField = -10000*(m_pmgnIMF->getReferField());
283 double m_alpha = 10000. / 2.99792458 / m_bField;
284 double dd = d0(pivot.x(),pivot.y());
285 a(1) = dd * ( m_kappa * dd - 1 );
286 a(2) = (m_kappa>0) ? std::atan2(yc() - pivot.y(), xc() - pivot.x()) + M_PI
287 : std::atan2(pivot.y() - yc(), pivot.x() - xc()) - M_PI + 2*M_PI;
288 //a(3) = -2.0*BELLE_ALPHA*m_kappa;
289 a(3) = -2.0*m_alpha*m_kappa;
290 a(4) = 0;
291 a(5) = 0;
292 return a;
293}
294
295#endif /* PACKAGE_LPAR_H_INCLUDED */
296
bool operator==(const EventID &lhs, const EventID &rhs)
Definition: EventID.h:79
bool operator!=(const EventID &lhs, const EventID &rhs)
Definition: EventID.h:86
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
Definition: EvtVector3R.cc:84
const double alpha
XmlRpcServer s
Definition: HelloServer.cpp:11
#define M_PI
Definition: TConstant.h:4
HepGeom::Point3D< double > HepPoint3D
virtual double getReferField()=0
double dr(double x, double y) const
double d(double x, double y) const
friend int intersect(const Lpar &, const Lpar &, HepVector &, HepVector &)
double s(double r, int dir=0) const
void neg()
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)
double s(double x, double y) const
const Lpar & operator=(const Lpar &)
double phi(double r, int dir=0) const
virtual ~Lpar()
HepVector center() const
double y[1000]
double x[1000]