Garfield++ v1r0
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
14void trajestep_limit::range(int fs_cf0, vfloat rad, int& fs_cf1,
15 vfloat& mrange) {
16 if (mrange < 0 || mrange > max_range) mrange = max_range;
17 fs_cf1 = fs_cf0;
18 if (fs_cf1 == 1) {
19 if (rad >= rad_for_straight) {
20 fs_cf1 = 0;
21 if (mrange / rad > max_straight_arange)
22 mrange = rad * max_straight_arange;
23 } else {
24 if (mrange / rad > max_circumf_arange) mrange = rad * max_circumf_arange;
25 }
26 }
27}
28
33
34void trajestep::get_components(ActivePtr<absref_transmit>& aref_tran) {
35 aref_tran.pass(new absref_transmit(4, aref));
36}
37
39 const vec& fdir, int fs_cf, const vec& frelcen,
40 vfloat fmrange, vfloat prec)
41 : tl(ftl),
42 currpos(fcurrpos),
43 dir(),
44 s_cf(fs_cf),
45 relcen(frelcen),
46 s_prec(1),
47 mrange(fmrange) {
48 pvecerror("trajestep::trajestep(...)");
49 if (fdir == dv0) {
50 dir = dv0;
51 mrange = 0;
52 } else {
53 dir = unit_vec(fdir);
54 if (s_cf == 1) {
55 check_econd11a(check_perp(dir, relcen, prec), != 1,
56 "dir=" << dir << "relcen=" << relcen
57 << "fcurrpos=" << fcurrpos << "fdir=" << fdir,
58 mcerr);
59 }
60 tl->range(s_cf, length(relcen), s_range_cf, mrange);
61 }
62}
63
64trajestep::trajestep(const trajestep& fts, // the new object will continue
65 // propagation from the end point of the old one
66 vfloat mrange) // new range to travel
67 {
68 mfunname("trajestep::trajestep(const trajestep& fts, vfloat mrange)");
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 =
75 trajestep(fts.tl.getver(), fpos, fdir, fts.s_cf, frelcen, mrange, prec);
76}
77
78void trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir) const {
79 pvecerror("int trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir)");
80 check_econd12(frange, >, mrange, mcerr);
81 if (s_range_cf == 0) // interpolation by straight line
82 {
83 fpos = currpos + frange * dir;
84 if (s_cf == 0) // no curvature
85 {
86 fdir = dir;
87 return;
88 } else {
89 vfloat ang = frange / length(relcen);
90 fdir = dir;
91 fdir.turn(dir || relcen, ang);
92 return;
93 }
94 } else {
95 vfloat ang = frange / length(relcen); // 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 return;
102 }
103}
104
105void trajestep::Gnextpoint1(vfloat frange, point& fpos, vec& fdir,
106 vec& frelcen) const {
107 pvecerror("int trajestep::Gnextpoint(vfloat frange, point& fpos, vec& fdir, "
108 "vec& frelcen)");
109 check_econd12(frange, >, mrange, mcerr);
110 if (s_range_cf == 0) // interpolation by straight line
111 {
112 fpos = currpos + frange * dir;
113 if (s_cf == 0) // no curvature
114 {
115 fdir = dir;
116 frelcen = relcen; // whatever it is
117 return;
118 } else {
119 vfloat ang = frange / length(relcen);
120 fdir = dir;
121 fdir.turn(dir || relcen, ang);
122 frelcen = relcen;
123 frelcen.turn(dir || relcen, ang);
124 return;
125 }
126 } else {
127 vfloat ang = frange / length(relcen); // angle to turn
128 fdir = dir;
129 fdir.turn(dir || relcen, ang); // direction at the end
130 frelcen = relcen;
131 frelcen.turn(dir || relcen, ang);
132 fpos = currpos + relcen - frelcen;
133 return;
134 }
135}
136
137std::ostream& operator<<(std::ostream& file, const trajestep& f) {
138 Ifile << "trajestep: s_cf=" << f.s_cf << "\n";
139 indn.n += 2;
140 Ifile << "currpos:" << f.currpos << indn << "dir=" << f.dir << indn
141 << "relcen=" << f.relcen << indn << "s_range_cf=" << f.s_range_cf
142 << " s_prec=" << f.s_prec << " mrange=" << f.mrange << '\n' << indn
143 << "mpoint=" << f.mpoint;
144 indn.n -= 2;
145 return file;
146}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
#define mfunname(string)
Definition: FunNameStack.h:67
Definition: vec.h:134
Definition: vec.h:477
vfloat max_straight_arange
Definition: trajestep.h:48
void range(int fs_cf0, vfloat rad, int &fs_cf1, vfloat &mrange)
Definition: trajestep.cpp:14
vfloat max_circumf_arange
Definition: trajestep.h:50
vfloat rad_for_straight
Definition: trajestep.h:45
vfloat max_range
Definition: trajestep.h:34
void Gnextpoint(vfloat frange, point &fpos, vec &fdir) const
Definition: trajestep.cpp:78
int s_range_cf
Definition: trajestep.h:88
vec dir
Definition: trajestep.h:75
point currpos
Definition: trajestep.h:74
static absrefabsref::*[4] aref
Definition: trajestep.h:130
PassivePtr< trajestep_limit > tl
Definition: trajestep.h:73
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: trajestep.cpp:34
vfloat mrange
Definition: trajestep.h:91
trajestep(void)
Definition: trajestep.h:109
int s_cf
Definition: trajestep.h:76
void Gnextpoint1(vfloat frange, point &fpos, vec &fdir, vec &frelcen) const
Definition: trajestep.cpp:105
vec relcen
Definition: trajestep.h:80
point mpoint
Definition: trajestep.h:92
int s_prec
Definition: trajestep.h:90
Definition: vec.h:248
void turn(const vec &dir, vfloat angle)
Definition: vec.cpp:298
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
std::ostream & operator<<(std::ostream &file, const trajestep &f)
Definition: trajestep.cpp:137
vec dv0(0, 0, 0)
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15