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

#include <vec.h>

+ Inheritance diagram for Heed::vec:

Public Member Functions

 vec (vfloat xx, vfloat yy, vfloat zz)
 Constructor.
 
 vec ()=default
 Default constructor.
 
virtual ~vec ()
 Destructor.
 
vfloat length () const
 
vfloat length2 () const
 
vec down_new (const basis *fabas)
 
vec up_new (const basis *fabas_new)
 
void down (const basis *fabas)
 
void up (const basis *fabas_new)
 
vec down_new (const abssyscoor *fasc)
 
vec up_new (const abssyscoor *fasc)
 
void down (const abssyscoor *fasc) override
 Convert numbering representation of object to basical system of fasc.
 
void up (const abssyscoor *fasc) override
 Convert numbering representation of objects to new system.
 
vec turn_new (const vec &dir, vfloat angle)
 Make new turned vector and leave this one unchanged.
 
void turn (const vec &dir, vfloat angle) override
 Turn this vector.
 
void shift (const vec &dir) override
 
void random_round_vec ()
 Generate random unit vector in plane perpendicular to z-axis.
 
void random_conic_vec (double theta)
 
void random_sfer_vec ()
 
vec operator/ (vfloat p) const
 
- Public Member Functions inherited from Heed::absref
virtual ~absref ()
 Destructor.
 
virtual void down (const abssyscoor *fasc)
 Convert numbering representation of object to basical system of fasc.
 
virtual void up (const abssyscoor *fasc)
 Convert numbering representation of objects to new system.
 
virtual void turn (const vec &dir, vfloat angle)
 Turn around axis doing via center of coordinate system along dir.
 
virtual void shift (const vec &dir)
 

Public Attributes

vfloat x = 0.
 
vfloat y = 0.
 
vfloat z = 0.
 

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)
 Vector product.
 
int operator== (const vec &r1, const vec &r2)
 Return 1 if precisely the same vectors and 0 otherwise.
 
int operator!= (const vec &r1, const vec &r2)
 Return 0 if precisely the same vectors and 1 otherwise.
 
bool apeq (const vec &r1, const vec &r2, vfloat prec)
 Return true if two vectors are approximately the same.
 
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)
 
int check_par (const vec &r1, const vec &r2, vfloat prec)
 
int check_perp (const vec &r1, const vec &r2, vfloat prec)
 
vec switch_xyz (const vec &)
 

Detailed Description

Vector. Each vector is presented by three components and corresponds to some basis. // The components are a projection of the vector to unit basis vectors. If bas==NULL then it is the primary basis. So the concept of vector is more primary concept with comparison of basis, since one can not postulate basis while vectors do not exist.

Definition at line 177 of file vec.h.

Constructor & Destructor Documentation

◆ vec() [1/2]

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

Constructor.

Definition at line 180 of file vec.h.

180 {
181 x = xx;
182 y = yy;
183 z = zz;
184 }
vfloat x
Definition: vec.h:190
vfloat z
Definition: vec.h:192
vfloat y
Definition: vec.h:191

◆ vec() [2/2]

Heed::vec::vec ( )
default

Default constructor.

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

◆ ~vec()

virtual Heed::vec::~vec ( )
inlinevirtual

Destructor.

Definition at line 188 of file vec.h.

188{}

Member Function Documentation

◆ down() [1/2]

void Heed::vec::down ( const abssyscoor fasc)
overridevirtual

Convert numbering representation of object to basical system of fasc.

Reimplemented from Heed::absref.

Definition at line 225 of file vec.cpp.

225{ down(fasc->Gabas()); }
void down(const basis *fabas)
Definition: vec.cpp:168

◆ down() [2/2]

void Heed::vec::down ( const basis fabas)

Definition at line 168 of file vec.cpp.

168{ *this = this->down_new(fabas); }
vec down_new(const basis *fabas)
Definition: vec.cpp:156

Referenced by down(), Heed::point::down(), Heed::HeedParticle::physics(), Heed::HeedParticle_BGM::physics(), and Heed::HeedDeltaElectron::physics_after_new_speed().

◆ down_new() [1/2]

vec Heed::vec::down_new ( const abssyscoor fasc)

Definition at line 224 of file vec.cpp.

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

◆ down_new() [2/2]

vec Heed::vec::down_new ( const basis fabas)

Definition at line 156 of file vec.cpp.

156 {
157 // pvecerror("vec vec::down_new(void)");
158 vec r;
159 vec ex = fabas->Gex();
160 vec ey = fabas->Gey();
161 vec ez = fabas->Gez();
162 r.x = x * ex.x + y * ey.x + z * ez.x;
163 r.y = x * ex.y + y * ey.y + z * ez.y;
164 r.z = x * ex.z + y * ey.z + z * ez.z;
165 return r;
166}
vec()=default
Default constructor.

Referenced by down(), and down_new().

◆ length()

◆ length2()

vfloat Heed::vec::length2 ( ) const
inline

Definition at line 195 of file vec.h.

195{ return x * x + y * y + z * z; }

◆ operator/()

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

Definition at line 233 of file vec.h.

233{ return vec(x / p, y / p, z / p); }

◆ random_conic_vec()

void Heed::vec::random_conic_vec ( double  theta)

Generate random unit vector in any direction in conus with symmetry axis along z-axis and with angle theta (radian).

Definition at line 236 of file vec.cpp.

236 {
237 vfloat phi = M_PI * 2.0 * SRANLUX();
238 double stheta = sin(theta);
239 x = sin(phi) * stheta;
240 y = cos(phi) * stheta;
241 z = cos(theta);
242}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:432
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:384
double vfloat
Definition: vfloat.h:16

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

◆ random_round_vec()

void Heed::vec::random_round_vec ( )

Generate random unit vector in plane perpendicular to z-axis.

Definition at line 229 of file vec.cpp.

229 {
230 const vfloat phi = M_PI * 2.0 * SRANLUX();
231 x = sin(phi);
232 y = cos(phi);
233 z = 0;
234}

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

◆ random_sfer_vec()

void Heed::vec::random_sfer_vec ( )

Definition at line 244 of file vec.cpp.

244 {
245 vfloat cteta = 2.0 * SRANLUX() - 1.0;
247 vfloat steta = sqrt(1.0 - cteta * cteta);
248 *this = (*this) * steta;
249 z = cteta;
250}
void random_round_vec()
Generate random unit vector in plane perpendicular to z-axis.
Definition: vec.cpp:229

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

◆ shift()

void Heed::vec::shift ( const vec dir)
overridevirtual

Reimplemented from Heed::absref.

Definition at line 220 of file vec.cpp.

220 {
221 // Not defined for vectors
222}

◆ turn()

void Heed::vec::turn ( const vec dir,
vfloat  angle 
)
overridevirtual

Turn this vector.

Reimplemented from Heed::absref.

Definition at line 216 of file vec.cpp.

216 {
217 *this = this->turn_new(dir, angle);
218}
vec turn_new(const vec &dir, vfloat angle)
Make new turned vector and leave this one unchanged.
Definition: vec.cpp:192

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

◆ turn_new()

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

Make new turned vector and leave this one unchanged.

Definition at line 192 of file vec.cpp.

192 {
193 pvecerror("vec turn(vec& dir, vfloat& angle)");
194 if ((*this).length() == 0) return vec(0, 0, 0);
195 if (check_par(*this, dir, 0.0) != 0) {
196 // parallel vectors are not changed
197 return *this;
198 }
199 vfloat dirlen = dir.length();
200 check_econd11a(dirlen, == 0, "cannot turn around zero vector", mcerr);
201 vec u = dir / dirlen; // unit vector
202 vec constcomp = u * (*this) * u;
203 vec ort1 = unit_vec(u || (*this));
204 vec ort2 = ort1 || u;
205 vec perpcomp = ort2 * (*this) * ort2;
206 vfloat len = perpcomp.length();
207 // mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2;
208 ort1 = sin(angle) * len * ort1;
209 ort2 = cos(angle) * len * ort2;
210 // mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2
211 // <<" len="<<len<<" sin(angle)="<<sin(angle)<<" cos(angle)="<<cos(angle)
212 // <<" angle="<<angle<<'\n';
213 return constcomp + ort1 + ort2;
214}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:172
friend int check_par(const vec &r1, const vec &r2, vfloat prec)
friend vec unit_vec(const vec &v)
#define mcerr
Definition: prstream.h:128
#define pvecerror(string)
Definition: vec.h:28

Referenced by turn().

◆ up() [1/2]

void Heed::vec::up ( const abssyscoor fasc)
overridevirtual

Convert numbering representation of objects to new system.

Reimplemented from Heed::absref.

Definition at line 227 of file vec.cpp.

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

◆ up() [2/2]

void Heed::vec::up ( const basis fabas_new)

Definition at line 190 of file vec.cpp.

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

Referenced by Heed::manip_absvol::m_check_point_inside(), up(), and Heed::point::up().

◆ up_new() [1/2]

vec Heed::vec::up_new ( const abssyscoor fasc)

Definition at line 226 of file vec.cpp.

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

◆ up_new() [2/2]

vec Heed::vec::up_new ( const basis fabas_new)

Definition at line 170 of file vec.cpp.

170 {
171 // it is assumed that fabas_new is derivative from old
172 pvecerrorp("vec vec::up_new((const basis *pbas)");
173 vec r;
174 // check_econd11(fabas_new , ==NULL, mcerr);
175 // not compiled in IRIX, reason is unkown
176 if (fabas_new == NULL) {
177 funnw.ehdr(mcerr);
178 mcerr << "fabas_new==NULL\n";
179 spexit(mcerr);
180 }
181 vec ex = fabas_new->Gex();
182 vec ey = fabas_new->Gey();
183 vec ez = fabas_new->Gez();
184 r.x = x * ex.x + y * ex.y + z * ex.z;
185 r.y = x * ey.x + y * ey.y + z * ey.z;
186 r.z = x * ez.x + y * ez.y + z * ez.z;
187 return r;
188}
#define spexit(stream)
Definition: FunNameStack.h:256
#define pvecerrorp(string)
Definition: vec.h:35

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 136 of file vec.cpp.

136 {
137 pvecerror(
138 "vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal)");
139 vec rt1 = project_to_plane(r1, normal);
140 vec rt2 = project_to_plane(r2, normal);
141 if (rt1 == dv0 || rt2 == dv0) {
142 vecerror = 1;
143 return 0;
144 }
145 vfloat tang = ang2vec(rt1, rt2);
146 if (tang == 0) return tang; // projections are parallel
147 vec at = rt1 || rt2;
148 int i = check_par(at, normal, 0.0001);
149 // mcout<<"r1="<<r1<<"r2="<<r2<<"normal="<<normal
150 // <<"rt1="<<rt1<<"rt2="<<rt2<<"\ntang="<<tang
151 // <<"\nat="<<at<<" i="<<i<<'\n';
152 if (i == -1) return 2.0 * M_PI - tang;
153 return tang; // it works if angle <= PI
154}
friend vfloat ang2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:89
friend vec project_to_plane(const vec &r, const vec &normal)
Definition: vec.cpp:124
vec dv0(0, 0, 0)
Definition: vec.h:306
int vecerror
Definition: vec.cpp:29

◆ ang2vec

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

Definition at line 89 of file vec.cpp.

89 {
90 // angle between vectors
91 // instead of return acos(cos2vec(r1,r2)); which produces NaN on linux at
92 // parallel vectors
93 vfloat cs = cos2vec(r1, r2);
94 if (vecerror != 0) return 0;
95 if (cs > 0.707106781187 || cs < -0.707106781187) { // 1.0/sqrt(2)
96 // pass to sin, it will be more exactly
97 vfloat sn = sin2vec(r1, r2);
98 if (vecerror != 0) return 0;
99 if (cs > 0.0)
100 return asin(sn);
101 else
102 return M_PI - asin(sn);
103 }
104 return acos(cs);
105}
friend vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:66
friend vfloat sin2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:107
DoubleAc acos(const DoubleAc &f)
Definition: DoubleAc.cpp:490
DoubleAc asin(const DoubleAc &f)
Definition: DoubleAc.cpp:470

◆ apeq

bool apeq ( const vec r1,
const vec r2,
vfloat  prec 
)
friend

Return true if two vectors are approximately the same.

◆ check_par

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

Check whether two vectors are parallel, or anti-parallel. Returns: 1 - parallel, -1 - antiparallel, 0 not parallel. Also returns 0 if one or both vectors have zero length. Thus, if angle between vectors < prec, they are parallel.

Referenced by turn_new().

◆ check_perp

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

Check whether two vectors are perpendicular. Returns: 1 perpendicular, 0 not perpendicular. Also returns 0 if one or both vectors have zero length. Thus, if angle between vectors a > 0.5 * M_PI - max(prec, vprecision) and a < 0.5 * M_PI + max(prec, vprecision), they are perpendicular.

◆ cos2vec

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

Definition at line 66 of file vec.cpp.

66 {
67 // cosinus of angle between vectors
68 // If one of vectors has zero length, it returns 2.
69 pvecerror("vfloat cos2vec(const vec& r1, const vec& r2)");
70 vfloat lr1 = r1.length2();
71 vfloat lr2 = r2.length2();
72 // mcout<<"cos2vec:\n";
73 // Iprintn(mcout, lr1);
74 // Iprintn(mcout, lr2);
75 if (lr1 == 0 || lr2 == 0) {
76 vecerror = 1;
77 return 0;
78 }
79 vfloat cs = r1 * r2;
80 int sign = 1;
81 if (cs < 0) sign = -1;
82 cs = cs * cs;
83 cs = sign * sqrt(cs / (lr1 * lr2));
84 // mcout<<"r1="<<r1<<"r2="<<r2<<"cos="<<cs<<'\n';
85 return cs;
86 // return r1*r2/(lr1*lr2);
87}

◆ operator!=

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

Return 0 if precisely the same vectors and 1 otherwise.

◆ operator* [1/3]

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

Definition at line 253 of file vec.h.

253 {
254 return r1.x * r2.x + r1.y * r2.y + r1.z * r2.z;
255 }

◆ operator* [2/3]

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

Definition at line 223 of file vec.h.

223 {
224 return vec(v.x * p, v.y * p, v.z * p);
225 }

◆ operator* [3/3]

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

Definition at line 230 of file vec.h.

230 {
231 return vec(v.x * p, v.y * p, v.z * p);
232 }

◆ operator*=

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

Definition at line 226 of file vec.h.

226 {
227 v = v * p;
228 return v;
229 }

◆ operator+

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

Definition at line 238 of file vec.h.

238 {
239 return vec(r1.x + r2.x, r1.y + r2.y, r1.z + r2.z);
240 }

◆ operator+=

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

Definition at line 241 of file vec.h.

241 {
242 r1 = r1 + r2;
243 return r1;
244 }

◆ operator- [1/2]

vec operator- ( const vec r)
friend

Definition at line 252 of file vec.h.

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

◆ operator- [2/2]

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

Definition at line 245 of file vec.h.

245 {
246 return vec(r1.x - r2.x, r1.y - r2.y, r1.z - r2.z);
247 }

◆ operator-=

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

Definition at line 248 of file vec.h.

248 {
249 r1 = r1 - r2;
250 return r1;
251 }

◆ operator/=

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

Definition at line 234 of file vec.h.

234 {
235 v = v / p;
236 return v;
237 }

◆ operator==

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

Return 1 if precisely the same vectors and 0 otherwise.

◆ operator||

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

Vector product.

Definition at line 257 of file vec.h.

257 {
258 return vec(r1.y * r2.z - r1.z * r2.y, r1.z * r2.x - r1.x * r2.z,
259 r1.x * r2.y - r1.y * r2.x);
260 }

◆ project_to_plane

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

Definition at line 124 of file vec.cpp.

124 {
125 pvecerror("vec project_to_plane(const vec& r, const vec& normal)");
126 vec per(normal || r);
127 if (per == dv0) {
128 // either one of vectors is 0 or they are parallel
129 return dv0;
130 }
131 vec ax = unit_vec(per || normal);
132 vfloat v = ax * r;
133 return v * ax;
134}

◆ sin2vec

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

Definition at line 107 of file vec.cpp.

107 {
108 // sinus of angle between vectors
109 pvecerror("vfloat sin2vec(const vec& r1, const vec& r2)");
110 vfloat lr1 = r1.length2();
111 vfloat lr2 = r2.length2();
112 if (lr1 == 0 || lr2 == 0) {
113 vecerror = 1;
114 return 0;
115 }
116 vfloat sn = (r1 || r2).length();
117 sn = sn * sn;
118 sn = sqrt(sn / (lr1 * lr2));
119 // mcout<<"r1="<<r1<<"r2="<<r2<<"sin="<<sn<<'\n';
120 return sn;
121 // return sin(ang2vec(r1,r2));
122}
vfloat length() const
Definition: vec.h:194

◆ switch_xyz

vec switch_xyz ( const vec )
friend

◆ unit_vec

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: