MCBooster  1.0.1
Tool to generate MC phase space samples in parallel.
Vector3R.h
Go to the documentation of this file.
1 /*
2  * Vector3R.h
3  *
4  * obs.: inspired on the corresponding EvtGen class.
5  *
6  * Created on : Feb 25, 2016
7  * Author: Antonio Augusto Alves Junior
8  */
9 
10 /*
11  * This file is part of MCBooster.
12  *
13  * MCBooster is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * MCBooster is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with MCBooster. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #ifndef VECTOR3R_H_
28 #define VECTOR3R_H_
29 
30 
31 
32 #include <mcbooster/Config.h>
33 #include <mcbooster/GTypes.h>
34 #include <iosfwd>
35 #include <iostream>
36 #include <math.h>
37 
38 using std::ostream;
39 namespace MCBooster
40 {
41 class Vector3R
42 {
43 
44  __host__ __device__ friend Vector3R rotateEuler(const Vector3R& v,
45  GReal_t phi, GReal_t theta, GReal_t ksi);
46 
47  __host__ __device__ inline friend Vector3R operator*(GReal_t c,
48  const Vector3R& v2);
49  __host__ __device__ inline friend GReal_t operator*(const Vector3R& v1,
50  const Vector3R& v2);
51  __host__ __device__ inline friend Vector3R operator+(const Vector3R& v1,
52  const Vector3R& v2);
53  __host__ __device__ inline friend Vector3R operator-(const Vector3R& v1,
54  const Vector3R& v2);
55  __host__ __device__ inline friend Vector3R operator*(const Vector3R& v1,
56  GReal_t c);
57  __host__ __device__ inline friend Vector3R operator/(const Vector3R& v1,
58  GReal_t c);
59  __host__ __device__ friend Vector3R cross(const Vector3R& v1,
60  const Vector3R& v2);
61 
62 public:
63  __host__ __device__ inline Vector3R();
64  __host__ __device__ inline Vector3R(GReal_t x, GReal_t y, GReal_t z);
65  __host__ __device__ inline Vector3R(const Vector3R& other);
66  __host__ __device__ inline Vector3R& operator*=(const GReal_t c);
67  __host__ __device__ inline Vector3R& operator/=(const GReal_t c);
68  __host__ __device__ inline Vector3R& operator+=(const Vector3R& v2);
69  __host__ __device__ inline Vector3R& operator-=(const Vector3R& v2);
70  __host__ __device__ inline void set(GInt_t i, GReal_t d);
71  __host__ __device__ inline void set(GReal_t x, GReal_t y, GReal_t z);
72  __host__ __device__ inline void applyRotateEuler(GReal_t phi, GReal_t theta,
73  GReal_t ksi);
74  __host__ __device__ inline GReal_t get(GInt_t i) const;
75  __host__ inline friend std::ostream& operator<<(std::ostream& s,
76  const Vector3R& v);
77  __host__ __device__ inline GReal_t dot(const Vector3R& v2);
78  __host__ __device__ inline GReal_t d3mag() const;
79 
80 private:
81 
82  GReal_t v[3];
83 
84 };
85 
87 {
88 
89  v[0] *= c;
90  v[1] *= c;
91  v[2] *= c;
92  return *this;
93 }
94 
96 {
97 
98  v[0] /= c;
99  v[1] /= c;
100  v[2] /= c;
101  return *this;
102 }
103 
105 {
106 
107  v[0] += v2.v[0];
108  v[1] += v2.v[1];
109  v[2] += v2.v[2];
110  return *this;
111 }
112 
114 {
115 
116  v[0] -= v2.v[0];
117  v[1] -= v2.v[1];
118  v[2] -= v2.v[2];
119  return *this;
120 }
121 
122 inline Vector3R operator*(GReal_t c, const Vector3R& v2)
123 {
124 
125  return Vector3R(v2) *= c;
126 }
127 
128 inline Vector3R operator*(const Vector3R& v1, GReal_t c)
129 {
130 
131  return Vector3R(v1) *= c;
132 }
133 
134 inline Vector3R operator/(const Vector3R& v1, GReal_t c)
135 {
136 
137  return Vector3R(v1) /= c;
138 }
139 
140 inline GReal_t operator*(const Vector3R& v1, const Vector3R& v2)
141 {
142 
143  return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2];
144 }
145 
146 inline Vector3R operator+(const Vector3R& v1, const Vector3R& v2)
147 {
148 
149  return Vector3R(v1) += v2;
150 }
151 
152 inline Vector3R operator-(const Vector3R& v1, const Vector3R& v2)
153 {
154 
155  return Vector3R(v1) -= v2;
156 
157 }
158 
159 inline GReal_t Vector3R::get(GInt_t i) const
160 {
161  return v[i];
162 }
163 
164 inline void Vector3R::set(GInt_t i, GReal_t d)
165 {
166 
167  v[i] = d;
168 }
169 
170 inline void Vector3R::set(GReal_t x, GReal_t y, GReal_t z)
171 {
172 
173  v[0] = x;
174  v[1] = y;
175  v[2] = z;
176 }
177 
179 {
180 
181  v[0] = v[1] = v[2] = 0.0;
182 }
183 
185 {
186 
187  v[0] = x;
188  v[1] = y;
189  v[2] = z;
190 }
191 
192 inline Vector3R::Vector3R(const Vector3R& other)
193 {
194 
195  v[0] = other.get(0);
196  v[1] = other.get(1);
197  v[2] = other.get(2);
198 }
199 
200 inline Vector3R rotateEuler(const Vector3R& v, GReal_t alpha, GReal_t beta,
201  GReal_t gamma)
202 {
203 
204  Vector3R tmp(v);
205  tmp.applyRotateEuler(alpha, beta, gamma);
206  return tmp;
207 
208 }
209 
210 inline void Vector3R::applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi)
211 {
212 
213  GReal_t temp[3];
214  GReal_t sp, st, sk, cp, ct, ck;
215 
216  sp = sin(phi);
217  st = sin(theta);
218  sk = sin(ksi);
219  cp = cos(phi);
220  ct = cos(theta);
221  ck = cos(ksi);
222 
223  temp[0] = (ck * ct * cp - sk * sp) * v[0] + (-sk * ct * cp - ck * sp) * v[1]
224  + st * cp * v[2];
225  temp[1] = (ck * ct * sp + sk * cp) * v[0] + (-sk * ct * sp + ck * cp) * v[1]
226  + st * sp * v[2];
227  temp[2] = -ck * st * v[0] + sk * st * v[1] + ct * v[2];
228 
229  v[0] = temp[0];
230  v[1] = temp[1];
231  v[2] = temp[2];
232 }
233 
234 inline ostream& operator<<(ostream& s, const Vector3R& v)
235 {
236 
237  s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << ")";
238 
239  return s;
240 
241 }
242 
243 inline Vector3R cross(const Vector3R& p1, const Vector3R& p2)
244 {
245 
246  //Calcs the cross product. Added by djl on July 27, 1995.
247  //Modified for real vectros by ryd Aug 28-96
248 
249  return Vector3R(p1.v[1] * p2.v[2] - p1.v[2] * p2.v[1],
250  p1.v[2] * p2.v[0] - p1.v[0] * p2.v[2],
251  p1.v[0] * p2.v[1] - p1.v[1] * p2.v[0]);
252 
253 }
254 
255 inline GReal_t Vector3R::d3mag() const
256 
257 // returns the 3 momentum mag.
258 {
259  GReal_t temp;
260 
261  temp = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
262  temp = sqrt(temp);
263 
264  return temp;
265 } // r3mag
266 
267 inline GReal_t Vector3R::dot(const Vector3R& p2)
268 {
269 
270  GReal_t temp;
271 
272  temp = v[0] * p2.v[0];
273  temp += v[0] * p2.v[0];
274  temp += v[0] * p2.v[0];
275 
276  return temp;
277 } //dot
278 }
279 #endif /* VECTOR3R_H_ */
__host__ __device__ friend Vector3R operator/(const Vector3R &v1, GReal_t c)
Definition: Vector3R.h:134
__host__ __device__ friend Vector3R operator+(const Vector3R &v1, const Vector3R &v2)
Definition: Vector3R.h:146
__host__ __device__ Vector3R & operator+=(const Vector3R &v2)
Definition: Vector3R.h:104
__host__ __device__ friend Vector3R rotateEuler(const Vector3R &v, GReal_t phi, GReal_t theta, GReal_t ksi)
Definition: Vector3R.h:200
__host__ __device__ void applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi)
Definition: Vector3R.h:210
Vector3R operator+(const Vector3R &v1, const Vector3R &v2)
Definition: Vector3R.h:146
Vector3R rotateEuler(const Vector3R &v, GReal_t alpha, GReal_t beta, GReal_t gamma)
Definition: Vector3R.h:200
__host__ __device__ void set(GInt_t i, GReal_t d)
Definition: Vector3R.h:164
__host__ __device__ GReal_t get(GInt_t i) const
Definition: Vector3R.h:159
__host__ __device__ Vector3R & operator-=(const Vector3R &v2)
Definition: Vector3R.h:113
__host__ __device__ friend Vector3R operator-(const Vector3R &v1, const Vector3R &v2)
Definition: Vector3R.h:152
__host__ __device__ Vector3R()
Definition: Vector3R.h:178
__host__ __device__ GReal_t dot(const Vector3R &v2)
Definition: Vector3R.h:267
__host__ __device__ GReal_t d3mag() const
Definition: Vector3R.h:255
Vector3R operator/(const Vector3R &v1, GReal_t c)
Definition: Vector3R.h:134
__host__ __device__ friend Vector3R cross(const Vector3R &v1, const Vector3R &v2)
Definition: Vector3R.h:243
Vector3R cross(const Vector3R &p1, const Vector3R &p2)
Definition: Vector3R.h:243
ostream & operator<<(ostream &s, const Vector3R &v)
Definition: Vector3R.h:234
double GReal_t
Double 8 bytes or float 4 bytes.
Definition: GTypes.h:52
__host__ __device__ friend Vector3R operator*(GReal_t c, const Vector3R &v2)
Definition: Vector3R.h:122
Vector3R operator-(const Vector3R &v1, const Vector3R &v2)
Definition: Vector3R.h:152
__host__ friend std::ostream & operator<<(std::ostream &s, const Vector3R &v)
Definition: Vector3R.h:234
Vector3R operator*(GReal_t c, const Vector3R &v2)
Definition: Vector3R.h:122
int GInt_t
Signed integer 4 bytes (int)
Definition: GTypes.h:37
__host__ __device__ Vector3R & operator*=(const GReal_t c)
Definition: Vector3R.h:86
__host__ __device__ Vector3R & operator/=(const GReal_t c)
Definition: Vector3R.h:95