Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
vec.cpp File Reference
#include <stdlib.h>
#include <iomanip>
#include <cmath>
#include "wcpplib/geometry/vec.h"
#include "wcpplib/util/emul_new_stand.h"
#include <CLHEP/Random/RandomEngine.h>
#include "geometry/vec.ic"

Go to the source code of this file.

Functions

 macro_copy_body (absref_transmit) void absref_transmit
 
vfloat cos2vec (const vec &r1, const vec &r2)
 
vfloat ang2vec (const vec &r1, const vec &r2)
 
vfloat sin2vec (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)
 
std::ostream & operator<< (std::ostream &file, const vec &v)
 
std::ostream & operator<< (std::ostream &file, const vecReg &v)
 
std::ostream & operator<< (std::ostream &file, const basis &b)
 
std::ostream & operator<< (std::ostream &file, const basisReg &b)
 
std::ostream & operator<< (std::ostream &file, const point &p)
 
std::ostream & operator<< (std::ostream &file, const pointReg &b)
 
std::ostream & operator<< (std::ostream &file, const abssyscoor &f)
 
std::ostream & operator<< (std::ostream &file, const fixsyscoor &f)
 

Variables

HepRandomEngine & random_engine
 
int vecerror = 0
 
vec dex (1, 0, 0)
 
vec dey (0, 1, 0)
 
vec dez (0, 0, 1)
 
vec dv0 (0, 0, 0)
 

Function Documentation

◆ ang2projvec()

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

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}
Definition: vec.h:248
vfloat ang2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:165
vec dv0(0, 0, 0)
vec project_to_plane(const vec &r, const vec &normal)
Definition: vec.cpp:200
int vecerror
Definition: vec.cpp:31
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15

Referenced by Heed::polygon::check_point_in(), and Heed::splane::range().

◆ ang2vec()

vfloat ang2vec ( const vec r1,
const vec r2 
)

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
vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:142
vfloat sin2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:183

◆ cos2vec()

vfloat cos2vec ( const vec r1,
const vec r2 
)

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}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313

Referenced by Heed::spquadr::apos(), basis::basis(), Heed::splane::check_point_inside(), Heed::splane::check_point_inside1(), Heed::straight::distance(), Heed::mparticle::new_speed(), and Heed::splane::range().

◆ macro_copy_body()

macro_copy_body ( absref_transmit  )

Definition at line 33 of file vec.cpp.

37 {
38 if (l > 0) {
39 Ifile << "absref_transmit::print(l=" << l << ") qaref=" << qaref
40 << " qaref_pointer=" << qaref_pointer
41 << " qaref_other=" << qaref_other << "\n";
42 file.flush();
43 }
44}
45
46absref* absref_transmit::get_other(int /*n*/) { return NULL; }
Definition: vec.h:134
#define Ifile
Definition: prstream.h:207

◆ operator<<() [1/8]

std::ostream & operator<< ( std::ostream &  file,
const abssyscoor f 
)

Definition at line 595 of file vec.cpp.

595 {
596 f.print(file, 2);
597 return file;
598}
virtual void print(std::ostream &file, int l) const
Definition: vec.cpp:572

◆ operator<<() [2/8]

std::ostream & operator<< ( std::ostream &  file,
const basis b 
)

Definition at line 509 of file vec.cpp.

509 {
510 Ifile << "basis: name=" << b.name << '\n';
511 indn.n += 2;
512 int indnsave = indn.n;
513 Ifile << "ex: ";
514 indn.n = 0;
515 file << b.ex;
516 indn.n = indnsave;
517 Ifile << "ey: ";
518 indn.n = 0;
519 file << b.ey;
520 indn.n = indnsave;
521 Ifile << "ez: ";
522 indn.n = 0;
523 file << b.ez;
524 indn.n = indnsave;
525 indn.n -= 2;
526 //file << '\n';
527 return file;
528}
vec ey
Definition: vec.h:399
String name
Definition: vec.h:412
vec ex
Definition: vec.h:399
vec ez
Definition: vec.h:399
indentation indn
Definition: prstream.cpp:13

◆ operator<<() [3/8]

std::ostream & operator<< ( std::ostream &  file,
const basisReg b 
)

Definition at line 530 of file vec.cpp.

530 {
531 Ifile << "basisReg=" << ((basis&)b);
532 return file;
533}
Definition: vec.h:397

◆ operator<<() [4/8]

std::ostream & operator<< ( std::ostream &  file,
const fixsyscoor f 
)

Definition at line 633 of file vec.cpp.

633 {
634 Ifile << "fixsyscoor:\n";
635 f.RegPassivePtr::print(file, 2);
636 f.abssyscoor::print(file, 2);
637 return file;
638}

◆ operator<<() [5/8]

std::ostream & operator<< ( std::ostream &  file,
const point p 
)

Definition at line 557 of file vec.cpp.

557 {
558 Ifile << "point:\n";
559 indn.n += 2;
560 file << p.v;
561 indn.n -= 2;
562 return file;
563}
vec v
Definition: vec.h:479

◆ operator<<() [6/8]

std::ostream & operator<< ( std::ostream &  file,
const pointReg b 
)

Definition at line 565 of file vec.cpp.

565 {
566 Ifile << "pointReg=" << ((point&)b);
567 return file;
568}
Definition: vec.h:477

◆ operator<<() [7/8]

std::ostream & operator<< ( std::ostream &  file,
const vec v 
)

Definition at line 346 of file vec.cpp.

346 {
347 Ifile << "vector=" << std::setw(13) << v.x << std::setw(13) << v.y
348 << std::setw(13) << v.z;
349 file << '\n';
350 file.flush();
351 return file;
352}
vfloat y
Definition: vec.h:250
vfloat x
Definition: vec.h:250
vfloat z
Definition: vec.h:250

◆ operator<<() [8/8]

std::ostream & operator<< ( std::ostream &  file,
const vecReg v 
)

Definition at line 359 of file vec.cpp.

359 {
360 Ifile << "vecReg=" << ((vec&)v);
361 return file;
362}

◆ project_to_plane()

vec project_to_plane ( const vec r,
const vec normal 
)

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}

Referenced by Heed::mparticle::curvature(), and Heed::mparticle::new_speed().

◆ sin2vec()

vfloat sin2vec ( const vec r1,
const vec r2 
)

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}

Referenced by Heed::straight::distance().

Variable Documentation

◆ dex

vec dex(1, 0, 0) ( ,
,
 
)

◆ dey

vec dey(0, 1, 0) ( ,
,
 
)

◆ dez

vec dez(0, 0, 1) ( ,
,
 
)

◆ dv0

◆ random_engine

HepRandomEngine& random_engine
extern

◆ vecerror