Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
vec Class Reference

#include <vec.h>

+ Inheritance diagram for vec:

Public Member Functions

vec operator/ (vfloat p) const
 
 vec (vfloat xx, vfloat yy, vfloat zz)
 
 vec ()
 
virtual ~vec ()
 
vec down_new (const basis *fabas)
 
void down (const basis *fabas)
 
vec up_new (const basis *fabas_new)
 
void up (const basis *fabas_new)
 
vec down_new (const abssyscoor *fasc)
 
void down (const abssyscoor *fasc)
 
vec up_new (const abssyscoor *fasc)
 
void up (const abssyscoor *fasc)
 
vec turn_new (const vec &dir, vfloat angle)
 
void turn (const vec &dir, vfloat angle)
 
void shift (const vec &dir)
 
void random_round_vec (void)
 
void random_conic_vec (double theta)
 
void random_sfer_vec (void)
 
- Public Member Functions inherited from absref
virtual ~absref ()
 
virtual void down (const abssyscoor *fasc)
 
virtual void up (const abssyscoor *fasc)
 
virtual void turn (const vec &dir, vfloat angle)
 
virtual void shift (const vec &dir)
 

Public Attributes

vfloat x
 
vfloat y
 
vfloat z
 

Friends

vec operator* (const vec &v, vfloat p)
 
vec operator*= (vec &v, vfloat p)
 
vec operator* (vfloat p, const vec &v)
 
vec operator/= (vec &v, vfloat p)
 
vec operator+ (const vec &r1, const vec &r2)
 
vecoperator+= (vec &r1, const vec &r2)
 
vec operator- (const vec &r1, const vec &r2)
 
vec operator-= (vec &r1, const vec &r2)
 
vec operator- (const vec &r)
 
vfloat operator* (const vec &r1, const vec &r2)
 
vec operator|| (const vec &r1, const vec &r2)
 
wl_inline int operator== (const vec &r1, const vec &r2)
 
wl_inline int operator!= (const vec &r1, const vec &r2)
 
wl_inline int apeq (const vec &r1, const vec &r2, vfloat prec)
 
wl_inline int not_apeq (const vec &r1, const vec &r2, vfloat prec)
 
vfloat length (const vec &v)
 
vfloat length2 (const vec &v)
 
wl_inline vec unit_vec (const vec &v)
 
vfloat cos2vec (const vec &r1, const vec &r2)
 
vfloat ang2vec (const vec &r1, const vec &r2)
 
vec project_to_plane (const vec &r, const vec &normal)
 
vfloat ang2projvec (const vec &r1, const vec &r2, const vec &normal)
 
vfloat sin2vec (const vec &r1, const vec &r2)
 
wl_inline int check_par (const vec &r1, const vec &r2, vfloat prec)
 
wl_inline int check_perp (const vec &r1, const vec &r2, vfloat prec)
 
wl_inline vec switch_xyz (const vec &)
 

Detailed Description

Definition at line 248 of file vec.h.

Constructor & Destructor Documentation

◆ vec() [1/2]

vec::vec ( vfloat  xx,
vfloat  yy,
vfloat  zz 
)
inline

Definition at line 334 of file vec.h.

334 {
335 x = xx;
336 y = yy;
337 z = zz;
338 }
vfloat y
Definition: vec.h:250
vfloat x
Definition: vec.h:250
vfloat z
Definition: vec.h:250

◆ vec() [2/2]

vec::vec ( )
inline

Definition at line 339 of file vec.h.

339 {
340 x = 0;
341 y = 0;
342 z = 0;
343 }

Referenced by operator/(), and turn_new().

◆ ~vec()

virtual vec::~vec ( )
inlinevirtual

Definition at line 349 of file vec.h.

349{}

Member Function Documentation

◆ down() [1/2]

void vec::down ( const abssyscoor fasc)
virtual

Reimplemented from absref.

Definition at line 307 of file vec.cpp.

307{ down(fasc->Gabas()); }
virtual const basis * Gabas(void) const =0
void down(const basis *fabas)
Definition: vec.cpp:247

◆ down() [2/2]

void vec::down ( const basis fabas)

◆ down_new() [1/2]

vec vec::down_new ( const abssyscoor fasc)

Definition at line 306 of file vec.cpp.

306{ return down_new(fasc->Gabas()); }

◆ down_new() [2/2]

vec vec::down_new ( const basis fabas)

Definition at line 232 of file vec.cpp.

232 {
233 //pvecerror("vec vec::down_new(void)");
234 vec r;
235 vec ex = fabas->Gex();
236 vec ey = fabas->Gey();
237 vec ez = fabas->Gez();
238 r.x = x * ex.x + y * ey.x + z * ez.x;
239 r.y = x * ex.y + y * ey.y + z * ez.y;
240 r.z = x * ex.z + y * ey.z + z * ez.z;
241 //mcout<<scout(*this);
242 //mcout<<scout(ex)<<scout(ey)<<scout(ez);
243 //mcout<<scout(r);
244 return r;
245}
vec Gez() const
Definition: vec.h:417
vec Gex() const
Definition: vec.h:415
vec Gey() const
Definition: vec.h:416
Definition: vec.h:248

Referenced by down(), and down_new().

◆ operator/()

vec vec::operator/ ( vfloat  p) const
inline

Definition at line 262 of file vec.h.

262{ return vec(x / p, y / p, z / p); }
vec()
Definition: vec.h:339

◆ random_conic_vec()

void vec::random_conic_vec ( double  theta)

Definition at line 322 of file vec.cpp.

322 {
323#ifdef USE_SRANLUX
324 vfloat phi = M_PI * 2.0 * SRANLUX();
325#else
326 vfloat phi = M_PI * 2.0 * random_engine.flat();
327#endif
328 double stheta = sin(theta);
329 x = sin(phi) * stheta;
330 y = cos(phi) * stheta;
331 z = cos(theta);
332}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:431
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:383
ffloat SRANLUX(void)
Definition: ranluxint.h:262
HepRandomEngine & random_engine
double vfloat
Definition: vfloat.h:15

Referenced by Heed::HeedParticle::physics(), and Heed::HeedParticle_BGM::physics().

◆ random_round_vec()

void vec::random_round_vec ( void  )

Definition at line 311 of file vec.cpp.

311 {
312#ifdef USE_SRANLUX
313 vfloat phi = M_PI * 2.0 * SRANLUX();
314#else
315 vfloat phi = M_PI * 2.0 * random_engine.flat();
316#endif
317 x = sin(phi);
318 y = cos(phi);
319 z = 0;
320}

Referenced by Heed::ElElasticScat::fill_hist_low_scat(), Heed::HeedDeltaElectron::physics_after_new_speed(), and random_sfer_vec().

◆ random_sfer_vec()

void vec::random_sfer_vec ( void  )

Definition at line 334 of file vec.cpp.

334 {
335#ifdef USE_SRANLUX
336 vfloat cteta = 2.0 * SRANLUX() - 1.0;
337#else
338 vfloat cteta = 2.0 * random_engine.flat() - 1.0;
339#endif
341 vfloat steta = sqrt(1.0 - cteta * cteta);
342 *this = (*this) * steta;
343 z = cteta;
344}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
void random_round_vec(void)
Definition: vec.cpp:311

Referenced by Heed::HeedPhoton::physics_after_new_speed().

◆ shift()

void vec::shift ( const vec dir)
virtual

Reimplemented from absref.

Definition at line 302 of file vec.cpp.

302 {
303 // Not defined for vectors
304}

◆ turn()

void vec::turn ( const vec dir,
vfloat  angle 
)
virtual

Reimplemented from absref.

Definition at line 298 of file vec.cpp.

298 {
299 *this = this->turn_new(dir, angle);
300}
vec turn_new(const vec &dir, vfloat angle)
Definition: vec.cpp:271

Referenced by trajestep::Gnextpoint(), trajestep::Gnextpoint1(), Heed::mparticle::new_speed(), Heed::spquadr::pt_angle_rad(), and Heed::splane::range().

◆ turn_new()

vec vec::turn_new ( const vec dir,
vfloat  angle 
)

Definition at line 271 of file vec.cpp.

271 {
272 pvecerror("vec turn(vec& dir, vfloat& angle)");
273 if (length(*this) == 0) return vec(0, 0, 0);
274 if (check_par(*this, dir, 0.0) != 0) {
275 // parallel vectors are not changed
276 return *this;
277 }
278 vfloat dirlen = length(dir);
279 check_econd11a(dirlen, == 0, "cannot turn around zero vector", mcerr);
280 vec u = dir / dirlen; // unit vector
281 vec constcomp = u * (*this) * u;
282 //vec perpcomp = (*this) - constcomp;
283 //vfloat len=length(perpcomp);
284 vec ort1 = unit_vec(u || (*this));
285 vec ort2 = ort1 || u;
286 vec perpcomp = ort2 * (*this) * ort2;
287 vfloat len = length(perpcomp);
288 //mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2;
289 ort1 = sin(angle) * len * ort1;
290 ort2 = cos(angle) * len * ort2;
291 //mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2
292 // <<" len="<<len<<" sin(angle)="<<sin(angle)<<" cos(angle)="<<cos(angle)
293 // <<" angle="<<angle<<'\n';
294 return constcomp + ort1 + ort2;
295
296}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
friend vfloat length(const vec &v)
Definition: vec.h:299
friend wl_inline int check_par(const vec &r1, const vec &r2, vfloat prec)
friend wl_inline vec unit_vec(const vec &v)
#define mcerr
Definition: prstream.h:135
#define pvecerror(string)
Definition: vec.h:52

Referenced by turn().

◆ up() [1/2]

void vec::up ( const abssyscoor fasc)
virtual

Reimplemented from absref.

Definition at line 309 of file vec.cpp.

309{ up(fasc->Gabas()); }
void up(const basis *fabas_new)
Definition: vec.cpp:269

◆ up() [2/2]

void vec::up ( const basis fabas_new)

Definition at line 269 of file vec.cpp.

269{ *this = this->up_new(fabas_new); }
vec up_new(const basis *fabas_new)
Definition: vec.cpp:249

Referenced by macro_copy_body_not_defined(), up(), and point::up().

◆ up_new() [1/2]

vec vec::up_new ( const abssyscoor fasc)

Definition at line 308 of file vec.cpp.

308{ return up_new(fasc->Gabas()); }

◆ up_new() [2/2]

vec vec::up_new ( const basis fabas_new)

Definition at line 249 of file vec.cpp.

249 {
250 // it is assumed that fabas_new is derivative from old
251 pvecerrorp("vec vec::up_new((const basis *pbas)");
252 vec r;
253 //check_econd11(fabas_new , ==NULL, mcerr);
254 // not compiled in IRIX, reason is unkown
255 if (fabas_new == NULL) {
256 funnw.ehdr(mcerr);
257 mcerr << "fabas_new==NULL\n";
258 spexit(mcerr);
259 }
260 vec ex = fabas_new->Gex();
261 vec ey = fabas_new->Gey();
262 vec ez = fabas_new->Gez();
263 r.x = x * ex.x + y * ex.y + z * ex.z;
264 r.y = x * ey.x + y * ey.y + z * ey.z;
265 r.z = x * ez.x + y * ez.y + z * ez.z;
266 return r;
267}
#define spexit(stream)
Definition: FunNameStack.h:536
#define pvecerrorp(string)
Definition: vec.h:59

Referenced by up(), and up_new().

Friends And Related Function Documentation

◆ ang2projvec

vfloat ang2projvec ( const vec r1,
const vec r2,
const vec normal 
)
friend

Definition at line 212 of file vec.cpp.

212 {
213 pvecerror(
214 "vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal)");
215 vec rt1 = project_to_plane(r1, normal);
216 vec rt2 = project_to_plane(r2, normal);
217 if (rt1 == dv0 || rt2 == dv0) {
218 vecerror = 1;
219 return 0;
220 }
221 vfloat tang = ang2vec(rt1, rt2);
222 if (tang == 0) return tang; // projections are parallel
223 vec at = rt1 || rt2;
224 int i = check_par(at, normal, 0.0001);
225 //mcout<<"r1="<<r1<<"r2="<<r2<<"normal="<<normal
226 // <<"rt1="<<rt1<<"rt2="<<rt2<<"\ntang="<<tang
227 // <<"\nat="<<at<<" i="<<i<<'\n';
228 if (i == -1) return 2.0 * M_PI - tang;
229 return tang; // it works if angle <= PI
230}
friend vfloat ang2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:165
friend vec project_to_plane(const vec &r, const vec &normal)
Definition: vec.cpp:200
vec dv0
int vecerror
Definition: vec.cpp:31

◆ ang2vec

vfloat ang2vec ( const vec r1,
const vec r2 
)
friend

Definition at line 165 of file vec.cpp.

165 {
166 // angle between vectors
167 // instead of return acos(cos2vec(r1,r2)); which produces NaN on linux at
168 // parallel vectors
169 vfloat cs = cos2vec(r1, r2);
170 if (vecerror != 0) return 0;
171 if (cs > 0.707106781187 || cs < -0.707106781187) { // 1.0/sqrt(2)
172 // pass to sin, it will be more exactly
173 vfloat sn = sin2vec(r1, r2);
174 if (vecerror != 0) return 0;
175 if (cs > 0.0)
176 return asin(sn);
177 else
178 return M_PI - asin(sn);
179 }
180 return acos(cs);
181}
DoubleAc asin(const DoubleAc &f)
Definition: DoubleAc.cpp:468
DoubleAc acos(const DoubleAc &f)
Definition: DoubleAc.cpp:488
friend vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:142
friend vfloat sin2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:183

◆ apeq

wl_inline int apeq ( const vec r1,
const vec r2,
vfloat  prec 
)
friend

◆ check_par

wl_inline int check_par ( const vec r1,
const vec r2,
vfloat  prec 
)
friend

Referenced by turn_new().

◆ check_perp

wl_inline int check_perp ( const vec r1,
const vec r2,
vfloat  prec 
)
friend

◆ cos2vec

vfloat cos2vec ( const vec r1,
const vec r2 
)
friend

Definition at line 142 of file vec.cpp.

142 {
143 // cosinus of angle between vectors
144 // If one of vectors has zero length, it returns 2.
145 pvecerror("vfloat cos2vec(const vec& r1, const vec& r2)");
146 vfloat lr1 = length2(r1);
147 vfloat lr2 = length2(r2);
148 //mcout<<"cos2vec:\n";
149 //Iprintn(mcout, lr1);
150 //Iprintn(mcout, lr2);
151 if (lr1 == 0 || lr2 == 0) {
152 vecerror = 1;
153 return 0;
154 }
155 vfloat cs = r1 * r2;
156 int sign = 1;
157 if (cs < 0) sign = -1;
158 cs = cs * cs;
159 cs = sign * sqrt(cs / (lr1 * lr2));
160 //mcout<<"r1="<<r1<<"r2="<<r2<<"cos="<<cs<<'\n';
161 return cs;
162 //return r1*r2/(lr1*lr2);
163}
friend vfloat length2(const vec &v)
Definition: vec.h:302

◆ length

vfloat length ( const vec v)
friend

Definition at line 299 of file vec.h.

299 {
300 return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
301 }

Referenced by turn_new().

◆ length2

vfloat length2 ( const vec v)
friend

Definition at line 302 of file vec.h.

302 {
303 return (v.x * v.x + v.y * v.y + v.z * v.z);
304 }

◆ not_apeq

wl_inline int not_apeq ( const vec r1,
const vec r2,
vfloat  prec 
)
friend

◆ operator!=

wl_inline int operator!= ( const vec r1,
const vec r2 
)
friend

◆ operator* [1/3]

vfloat operator* ( const vec r1,
const vec r2 
)
friend

Definition at line 282 of file vec.h.

282 {
283 return r1.x * r2.x + r1.y * r2.y + r1.z * r2.z;
284 }

◆ operator* [2/3]

vec operator* ( const vec v,
vfloat  p 
)
friend

Definition at line 252 of file vec.h.

252 {
253 return vec(v.x * p, v.y * p, v.z * p);
254 }

◆ operator* [3/3]

vec operator* ( vfloat  p,
const vec v 
)
friend

Definition at line 259 of file vec.h.

259 {
260 return vec(v.x * p, v.y * p, v.z * p);
261 }

◆ operator*=

vec operator*= ( vec v,
vfloat  p 
)
friend

Definition at line 255 of file vec.h.

255 {
256 v = v * p;
257 return v;
258 }

◆ operator+

vec operator+ ( const vec r1,
const vec r2 
)
friend

Definition at line 267 of file vec.h.

267 {
268 return vec(r1.x + r2.x, r1.y + r2.y, r1.z + r2.z);
269 }

◆ operator+=

vec & operator+= ( vec r1,
const vec r2 
)
friend

Definition at line 270 of file vec.h.

270 {
271 r1 = r1 + r2;
272 return r1;
273 }

◆ operator- [1/2]

vec operator- ( const vec r)
friend

Definition at line 281 of file vec.h.

281{ return vec(-r.x, -r.y, -r.z); }

◆ operator- [2/2]

vec operator- ( const vec r1,
const vec r2 
)
friend

Definition at line 274 of file vec.h.

274 {
275 return vec(r1.x - r2.x, r1.y - r2.y, r1.z - r2.z);
276 }

◆ operator-=

vec operator-= ( vec r1,
const vec r2 
)
friend

Definition at line 277 of file vec.h.

277 {
278 r1 = r1 - r2;
279 return r1;
280 }

◆ operator/=

vec operator/= ( vec v,
vfloat  p 
)
friend

Definition at line 263 of file vec.h.

263 {
264 v = v / p;
265 return v;
266 }

◆ operator==

wl_inline int operator== ( const vec r1,
const vec r2 
)
friend

◆ operator||

vec operator|| ( const vec r1,
const vec r2 
)
friend

Definition at line 286 of file vec.h.

286 {
287 return vec(r1.y * r2.z - r1.z * r2.y, r1.z * r2.x - r1.x * r2.z,
288 r1.x * r2.y - r1.y * r2.x);
289 }

◆ project_to_plane

vec project_to_plane ( const vec r,
const vec normal 
)
friend

Definition at line 200 of file vec.cpp.

200 {
201 pvecerror("vec project_to_plane(const vec& r, const vec& normal)");
202 vec per(normal || r);
203 if (per == dv0) {
204 // either one of vectors is 0 or they are parallel
205 return dv0;
206 }
207 vec ax = unit_vec(per || normal);
208 vfloat v = ax * r;
209 return v * ax;
210}

◆ sin2vec

vfloat sin2vec ( const vec r1,
const vec r2 
)
friend

Definition at line 183 of file vec.cpp.

183 {
184 // sinus of angle between vectors
185 pvecerror("vfloat sin2vec(const vec& r1, const vec& r2)");
186 vfloat lr1 = length2(r1);
187 vfloat lr2 = length2(r2);
188 if (lr1 == 0 || lr2 == 0) {
189 vecerror = 1;
190 return 0;
191 }
192 vfloat sn = length(r1 || r2);
193 sn = sn * sn;
194 sn = sqrt(sn / (lr1 * lr2));
195 //mcout<<"r1="<<r1<<"r2="<<r2<<"sin="<<sn<<'\n';
196 return sn;
197 //return sin(ang2vec(r1,r2));
198}

◆ switch_xyz

wl_inline vec switch_xyz ( const vec )
friend

◆ unit_vec

wl_inline vec unit_vec ( const vec v)
friend

Referenced by turn_new().

Member Data Documentation

◆ x

◆ y

◆ z


The documentation for this class was generated from the following files: