Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
trajestep.cpp
Go to the documentation of this file.
2/*
3Copyright (c) 2000 Igor B. Smirnov
4
5The file can be used, copied, modified, and distributed
6according to the terms of GNU Lesser General Public License version 2.1
7as published by the Free Software Foundation,
8and provided that the above copyright notice, this permission notice,
9and notices about any modifications of the original text
10appear in all copies and in supporting documentation.
11The file is provided "as is" without express or implied warranty.
12*/
13
14namespace Heed {
15
16absref absref::* trajestep::aref[4] = {(absref absref::*)&trajestep::currpos,
17 (absref absref::*)&trajestep::dir,
18 (absref absref::*)&trajestep::relcen,
19 (absref absref::*)&trajestep::mpoint};
20
22 return absref_transmit(4, aref);
23}
24
25trajestep::trajestep(const vfloat fmax_range, const vfloat frad_for_straight,
26 const vfloat fmax_straight_arange,
27 const vfloat fmax_circ_arange, const point& fcurrpos,
28 const vec& fdir, const bool fcurved, const vec& frelcen,
29 vfloat fmrange, vfloat prec)
30 : max_range(fmax_range),
31 rad_for_straight(frad_for_straight),
32 max_straight_arange(fmax_straight_arange),
33 max_circ_arange(fmax_circ_arange),
34 currpos(fcurrpos),
35 dir(),
36 curved(fcurved),
37 relcen(frelcen),
38 s_prec(1),
39 mrange(fmrange) {
40 pvecerror("trajestep::trajestep(...)");
41 if (fdir == dv0) {
42 dir = dv0;
43 mrange = 0;
44 } else {
45 dir = unit_vec(fdir);
46 if (curved) {
47 check_econd11a(check_perp(dir, relcen, prec), != 1,
48 "dir=" << dir << "relcen=" << relcen
49 << "fcurrpos=" << fcurrpos << "fdir=" << fdir,
50 mcerr);
51 }
52 if (mrange < 0 || mrange > max_range) mrange = max_range;
54 if (s_range_cf == 1) {
55 const vfloat r = relcen.length();
56 if (r >= rad_for_straight) {
57 s_range_cf = 0;
58 mrange = std::min(mrange, r * max_straight_arange);
59 } else {
60 mrange = std::min(mrange, r * max_circ_arange);
61 }
62 }
63 }
64}
65
67 mfunname("trajestep::trajestep(const trajestep& fts, vfloat fmrange)");
68 // Continue propagation from the end point of the old step.
69 point fpos;
70 vec fdir;
71 vec frelcen;
72 fts.Gnextpoint1(fts.mrange, fpos, fdir, frelcen);
73 vfloat prec = 0.1; // not important here
74 *this =
77 fpos, fdir, fts.curved, frelcen, fmrange, prec);
78}
79
80void trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir) const {
81 pvecerror("int trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir)");
82 check_econd12(frange, >, mrange, mcerr);
83 if (s_range_cf == 0) {
84 // interpolation by straight line
85 fpos = currpos + frange * dir;
86 if (!curved) {
87 // no curvature
88 fdir = dir;
89 } else {
90 vfloat ang = frange / relcen.length();
91 fdir = dir;
92 fdir.turn(dir || relcen, ang);
93 }
94 } else {
95 vfloat ang = frange / relcen.length(); // angle to turn
96 fdir = dir;
97 fdir.turn(dir || relcen, ang); // direction at the end
98 vec frelcen = relcen;
99 frelcen.turn(dir || relcen, ang);
100 fpos = currpos + relcen - frelcen;
101 }
102}
103
104void trajestep::Gnextpoint1(vfloat frange, point& fpos, vec& fdir,
105 vec& frelcen) const {
106 pvecerror(
107 "int trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir, "
108 "vec& frelcen)");
109 check_econd12(frange, >, mrange, mcerr);
110 if (s_range_cf == 0) {
111 // interpolation by straight line
112 fpos = currpos + frange * dir;
113 if (!curved) {
114 // no curvature
115 fdir = dir;
116 frelcen = relcen; // whatever it is
117 } else {
118 vfloat ang = frange / relcen.length();
119 fdir = dir;
120 fdir.turn(dir || relcen, ang);
121 frelcen = relcen;
122 frelcen.turn(dir || relcen, ang);
123 }
124 } else {
125 vfloat ang = frange / relcen.length(); // angle to turn
126 fdir = dir;
127 fdir.turn(dir || relcen, ang); // direction at the end
128 frelcen = relcen;
129 frelcen.turn(dir || relcen, ang);
130 fpos = currpos + relcen - frelcen;
131 }
132}
133
134std::ostream& operator<<(std::ostream& file, const trajestep& f) {
135 Ifile << "trajestep: curved=" << f.curved << "\n";
136 indn.n += 2;
137 Ifile << "currpos:" << f.currpos << indn << "dir=" << f.dir << indn
138 << "relcen=" << f.relcen << indn << "s_range_cf=" << f.s_range_cf
139 << " s_prec=" << f.s_prec << " mrange=" << f.mrange << '\n' << indn
140 << "mpoint=" << f.mpoint;
141 indn.n -= 2;
142 return file;
143}
144}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:172
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:163
#define mfunname(string)
Definition: FunNameStack.h:45
Point.
Definition: vec.h:368
point currpos
Current position.
Definition: trajestep.h:74
vfloat rad_for_straight
Radius beyond which to prefer straight lines to reduce calculation time.
Definition: trajestep.h:67
vfloat mrange
Maximal possible range.
Definition: trajestep.h:93
static absref absref::* aref[4]
Definition: trajestep.h:102
trajestep()=default
Default constructor.
vfloat max_straight_arange
Angular step for curved lines when using straight-line approximation.
Definition: trajestep.h:69
bool curved
Type of trajectory (curved or straight).
Definition: trajestep.h:78
void Gnextpoint(vfloat frange, point &fpos, vec &fdir) const
Move to the next point.
Definition: trajestep.cpp:80
virtual absref_transmit get_components() override
Definition: trajestep.cpp:21
vfloat max_circ_arange
Angular step for curved lines.
Definition: trajestep.h:71
vfloat max_range
Max. step length.
Definition: trajestep.h:64
vec dir
Unit vector.
Definition: trajestep.h:76
Definition: vec.h:179
void turn(const vec &dir, vfloat angle) override
Turn this vector.
Definition: vec.cpp:216
vfloat length() const
Definition: vec.h:196
Definition: BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37
vec dv0(0, 0, 0)
Definition: vec.h:308
indentation indn
Definition: prstream.cpp:15
double vfloat
Definition: vfloat.h:16
#define Ifile
Definition: prstream.h:195
#define mcerr
Definition: prstream.h:128
#define pvecerror(string)
Definition: vec.h:28