CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
StraightLine.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <cmath>
4#include <cfloat>
5
7
8StraightLine::StraightLine(const HepPoint3D & pivot, const HepVector & a)
9 :m_pivot(pivot),m_a(a)
10{
11}
12
13StraightLine::StraightLine(double dr, double phi0, double dz, double tanl)
14 :m_a(HepVector(4,0))
15{
16 m_a[0]=dr;
17 m_a[1]=phi0;
18 m_a[2]=dz;
19 m_a[3]=tanl;
20
21 HepPoint3D pivot(0,0,0);
22 m_pivot=pivot;
23}
24
26 :m_a(HepVector(4,0))
27{
28 // cout << "debug int StraightLine" << endl;
29 // cout << "2points: " << setw(15) << pos1.x() << setw(15) << pos1.y() << setw(15) << pos1.z()
30 // << setw(15) << pos2.x() << setw(15) << pos2.y() << setw(15) << pos2.z() << endl;
31 HepPoint3D pivot(0,0,0);
32 m_pivot=pivot;
33
34 if(pos1.y()<pos2.y()) {
35 HepPoint3D pos_tmp=pos1;
36 pos1=pos2;
37 pos2=pos_tmp;
38 }
39 else if(pos1.y()==pos2.y()&&pos1.x()>pos2.x()) {
40 HepPoint3D pos_tmp = pos1;
41 pos1=pos2;
42 pos2=pos_tmp;
43 }
44 //cout<<__FILE__<<": pos1, pos2 = "<<pos1<<", "<<pos2<<endl;
45 HepPoint3D vec = pos2-pos1;
46 double phi_vec = vec.phi();// (pi,2pi]
47 //cout<<__FILE__<<": phi_vec="<<phi_vec<<endl;
48 double phi0=phi_vec+M_PI/2.;// automatically in (-pi/2,pi/2)
49 //cout<<__FILE__<<": phi0 ="<<phi0 <<endl;
50 double dphi1=pos1.phi()-phi0;
51 double dr = pos1.perp()*cos(dphi1);
52
53 double s1(0.),s2(0.);
54 if(pos1.y()!=pos2.y()) {
55 s1=(pos1.y()-dr*sin(phi0))/sin(phi_vec);
56 s2=(pos2.y()-dr*sin(phi0))/sin(phi_vec);
57 }
58 else {
59 s1=(pos1.x()-dr*cos(phi0))/cos(phi_vec);
60 s2=(pos2.x()-dr*cos(phi0))/cos(phi_vec);
61 }
62
63 double dz(0.),tanl(0.);
64 if(s1>=s2) {
65 cout<<"StraightLine: s1>=s2!!!"<<endl;
66 }
67 else {
68 tanl=(pos2.z()-pos1.z())/(s2-s1);
69 dz=-s1*tanl+pos1.z();
70 }
71 m_a[0]=dr;
72 m_a[1]=phi0;
73 m_a[2]=dz;
74 m_a[3]=tanl;
75 // cout << "line: " << setw(15) << dr << setw(15) << phi0 << setw(15) << dz << setw(15) << tanl << endl;
76}
77
80
82{
83 double x=m_a[0]*cos(m_a[1])+s*cos(m_a[1]-M_PI/2.);
84 double y=m_a[0]*sin(m_a[1])+s*sin(m_a[1]-M_PI/2.);
85 double z=m_a[2]+s*m_a[3];
86 return HepPoint3D(x,y,z);
87}
88
89double StraightLine::sAtR(double R, int direction) const
90{
91 // if pivot at (0,0,0)
92 double ss=999999.;
93 if(fabs(m_a[0])<=R) {
94 ss=sqrt(R*R-m_a[0]*m_a[0]);
95 ss*=direction;
96 }
97 return ss;
98}
99
100HepPoint3D StraightLine::xAtR(double R, int direction) const
101{
102 HepPoint3D pos(999999,999999,999999);
103 double ss=sAtR(R, direction);
104 if(ss!=999999.) pos=x(ss);
105 return pos;
106}
107
108double StraightLine::sAtPhi(double phi) const
109{
110 // if pivot at (0,0,0)
111 double ss=999999.;
112 //double phi0_global = m_a[1];//(-pi/2,pi/2]
113 if(m_a[0]<0) {
114 //phi0_global+ = M_PI; //(pi/2,3/2*pi]
115 phi+=M_PI;
116 }
117 double dphi=phi0()-phi;
118 while(dphi> M_PI) dphi-=2*M_PI;
119 while(dphi<-M_PI) dphi+=2*M_PI;
120 if(fabs(dphi)<M_PI/2)
121 {
122 ss=m_a[0]*tan(dphi);
123 }
124 return ss;
125}
126
128{
129 HepPoint3D pos(999999,999999,999999);
130 double ss=sAtPhi(phi);
131 if(ss!=999999.) pos=x(ss);
132 return pos;
133}
134
135void StraightLine::set(const HepVector & a)
136{
137 m_a=a;
138}
139
140void StraightLine::set(const HepPoint3D & pivot)
141{
142 m_pivot = pivot;
143 // m_a to be updated // FIXME
144}
145
146void StraightLine::set(const HepPoint3D & pivot, const HepVector & a)
147{
148 m_pivot = pivot;
149 m_a=a;
150}
151
153{
154 cout<<"line pivot: "<<m_pivot<<endl;
155 cout<<" par: "<<m_a<<endl;
156}
double tan(const BesAngle a)
Definition BesAngle.h:216
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
Double_t x[10]
XmlRpcServer s
HepGeom::Point3D< double > HepPoint3D
#define M_PI
Definition TConstant.h:4
double dz(void) const
double sAtPhi(double phi) const
HepPoint3D x(double s=0.) const
returns position after moving s in downwoards
virtual ~StraightLine()
Destructor.
const HepPoint3D & pivot(void) const
returns pivot position.
HepPoint3D xAtR(double R, int direction=1) const
double dr(void) const
returns an element of parameters.
void set(const HepVector &a)
returns position and convariance matrix(Ex) after moving s.
HepPoint3D xAtPhi(double phi) const
double tanl(void) const
const HepVector & a(void) const
returns helix parameters.
double phi0(void) const
StraightLine(const HepPoint3D &pivot, const HepVector &a)
double sAtR(double R, int direction=1) const
dble_vec_t vec[12]
Definition ranlxd.c:372