BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
vector3.h
Go to the documentation of this file.
1typedef struct{
2 float x;
3 float y;
4 float z;
5} vector3;
6
7
8// initialize the vector to (x,y,z)
9vector3 InitV(float x, float y, float z)
10{
11 vector3 v;
12 v.x = x;
13 v.y = y;
14 v.z = z;
15 return v;
16}
17
18// initialize the vector to (x,y,z)
19vector3 InitV1(float phi, float cosTheta, float magnitude)
20{
21 vector3 v;
22 float sinTheta = sqrt(1.0-cosTheta*cosTheta);
23 v.z = magnitude*cosTheta;
24 v.y = magnitude*sinTheta*sin(phi);
25 v.x = magnitude*sinTheta*cos(phi);
26 return v;
27}
28
29// the magnitude of vector v
31{
32 return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
33}
34
35// the squared magnitude of vector v
37{
38 return v.x*v.x+v.y*v.y+v.z*v.z;
39}
40
41// Scalar product of vector v1 and v2
42float Dot(vector3 v1, vector3 v2)
43{
44 return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;
45}
46
47
48// Cross product of vector v1 and v2
50{
51 vector3 v;
52 v.x = v1.y*v2.z - v1.z*v2.y;
53 v.y = v1.z*v2.x - v1.x*v2.z;
54 v.z = v1.x*v2.y - v1.y*v2.x;
55 return v;
56}
57
58// Unit vector parallel to vector v
60{
61 vector3 vv;
62 float p = Mag(v);
63 vv.x = v.x/p;
64 vv.y = v.y/p;
65 vv.z = v.z/p;
66 return vv;
67}
68
69
70// Calculate the intersection piont with z0 = c plane
71// for vector vec which pass point pos
73{
74 vector3 vz0;
75 vz0.z = z0;
76 vz0.x = (vz0.z - pos.z)*vec.x/vec.z + pos.x;
77 vz0.y = (vz0.z - pos.z)*vec.y/vec.z + pos.y;
78 return vz0;
79}
80
81
82// vector v times with a constant a
84{
85 vector3 vv;
86 vv.x = a*v.x;
87 vv.y = a*v.y;
88 vv.z = a*v.z;
89 return vv;
90}
91
92// vector v1 + vector v2
94{
95 vector3 v;
96 v.x = v1.x + v2.x;
97 v.y = v1.y + v2.y;
98 v.z = v1.z + v2.z;
99 return v;
100}
101
102// vector v1 - vector v2
104{
105 vector3 v;
106 v.x = v1.x - v2.x;
107 v.y = v1.y - v2.y;
108 v.z = v1.z - v2.z;
109 return v;
110}
111
112// Transform v from ux, uy, uz frame to (1,0,0),(0,1,0),(0,0,1) frame
114{
115 ux = TimesA(v.x,ux);
116 uy = TimesA(v.y,uy);
117 uz = TimesA(v.z,uz);
118 v = AddV(AddV(ux, uy), uz);
119 return v;
120}
121
122
123// Transform v to ux, uy, uz frame from (1,0,0),(0,1,0),(0,0,1) frame
125{
126 vector3 vv;
127 vv.x = Dot(v,ux);
128 vv.y = Dot(v,uy);
129 vv.z = Dot(v,uz);
130 return vv;
131}
132
133const float pi = 3.1415926536;
134const float rad = 57.29578;
135
136typedef struct{
137 float r;
138 float theta;
139 float phi;
140} polar;
141
143{
144 polar s;
145 float rxy;
146
147 s.r = sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
148 if(s.r==0.0){
149 s.theta = 0.0;
150 }
151 else{
152 s.theta = acos(v.z/s.r);
153 }
154
155 rxy = sqrt(v.x*v.x+v.y*v.y);
156 if(rxy==0.0){
157 s.phi = 0.0;
158 }
159 else{
160 if(v.y>=0.0) s.phi = acos(v.x/rxy);
161 else{
162 s.phi = 2.0*pi-acos(v.x/rxy);
163 }
164 }
165
166 return s;
167}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
Double_t x[10]
XmlRpcServer s
Definition: HelloServer.cpp:11
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
dble_vec_t vec[12]
Definition: ranlxd.c:372
Definition: vector3.h:136
float phi
Definition: vector3.h:139
float theta
Definition: vector3.h:138
float r
Definition: vector3.h:137
Definition: vector3.h:1
float y
Definition: vector3.h:3
float z
Definition: vector3.h:4
float x
Definition: vector3.h:2
float Mag(vector3 v)
Definition: vector3.h:30
float Dot(vector3 v1, vector3 v2)
Definition: vector3.h:42
vector3 Unit(vector3 v)
Definition: vector3.h:59
vector3 TransformTo(vector3 v, vector3 ux, vector3 uy, vector3 uz)
Definition: vector3.h:124
vector3 TransformFrom(vector3 v, vector3 ux, vector3 uy, vector3 uz)
Definition: vector3.h:113
vector3 InitV1(float phi, float cosTheta, float magnitude)
Definition: vector3.h:19
vector3 AddV(vector3 v1, vector3 v2)
Definition: vector3.h:93
vector3 Intersection(float z0, vector3 vec, vector3 pos)
Definition: vector3.h:72
polar XYZ2Polar(vector3 v)
Definition: vector3.h:142
vector3 TimesA(float a, vector3 v)
Definition: vector3.h:83
float Mag2(vector3 v)
Definition: vector3.h:36
vector3 SubV(vector3 v1, vector3 v2)
Definition: vector3.h:103
const float rad
Definition: vector3.h:134
const float pi
Definition: vector3.h:133
vector3 Cross(vector3 v1, vector3 v2)
Definition: vector3.h:49
vector3 InitV(float x, float y, float z)
Definition: vector3.h:9