Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
gparticle.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
16void stvpoint::print(std::ostream& file, int l) const {
17 if (l < 0) return;
18 Ifile << "stvpoint: sb=" << sb << " s_ent=" << s_ent << " prange=" << prange
19 << " time=" << time << '\n';
20 indn.n += 2;
21 Ifile << "position:\n" << pt << ptloc;
22 Ifile << "direction of moving:\n" << dir << dirloc;
23 Ifile << "speed=" << speed << '\n';
24 if (tid.eid.empty()) {
25 Ifile << "point is outside universe\n";
26 file.flush();
27 indn.n -= 2;
28 return;
29 }
30 tid.print(file, 1);
31 char s[100];
32 if (sb == 2) {
33 // next_eid.amvol->m_chname(s);
34 next_eid->m_chname(s);
35 Ifile << "next volume name " << s << '\n';
36 }
37 indn.n -= 2;
38 file.flush();
39}
40
42
43gparticle::gparticle(manip_absvol* primvol, const point& pt, const vec& vel,
44 vfloat time)
45 : s_life(false),
46 nstep(0),
47 total_range_from_origin(0.0),
48 n_zero_step(0),
49 prevpos(),
50 nextpos() {
51 // As far as I can now understand, PassivePtr<primvol> will be at
52 // origin.tid.eid[0]
53 mfunname("gparticle::gparticle(...)");
54 primvol->m_find_embed_vol(pt, vel, &origin.tid);
55 origin.pt = pt;
56 if (vel == dv0) {
57 origin.dir = dv0;
58 origin.speed = 0.0;
59 } else {
60 origin.dir = unit_vec(vel);
61 origin.speed = vel.length();
62 }
67 origin.time = time;
68 origin.sb = 0;
69 origin.s_ent = 1;
70 if (origin.tid.eid.empty()) return;
71 s_life = true;
74 nextpos.s_ent = 0;
75}
76
77void gparticle::step(std::vector<gparticle*>& secondaries) {
78 // Make step to nextpos and calculate new step to border
79 mfunname("void gparticle::step()");
84 nstep++;
85 if (currpos.prange == 0) {
88 "too much zero steps, possible infinite loop\n", mcerr);
89 } else {
90 n_zero_step = 0;
91 }
92 physics_after_new_speed(secondaries);
93 if (s_life) {
96 }
97}
98
99void gparticle::curvature(int& fs_cf, vec& frelcen, vfloat& fmrange,
100 vfloat /*prec*/) {
101 fs_cf = 0;
102 frelcen = vec(0, 0, 0);
103 fmrange = max_vfloat;
104 /* The following is for debug
105 vec field(0,1,0);
106 vfloat rad = 10;
107 if (length(currpos.dir) > 0 && check_par(currpos.dir, field) == 0) {
108 fs_cf = 1;
109 vfloat coef = sin2vec(currpos.dir, field);
110 rad = rad / coef;
111 frelcen = unit_vec(currpos.dir || field) * rad;
112 }
113 */
114}
115
116void gparticle::physics_mrange(double& /*fmrange*/) {}
117
118// calculate next point as step to border
120 pvecerror("stvpoint gparticle::calc_step_to_bord()");
122 if (currpos.sb > 0) {
123 // it does not do step, but switch to new volume
124 return switch_new_vol();
125 }
126 int s_cf;
127 vec relcen;
128 vfloat mrange;
129 curvature(s_cf, relcen, mrange, gtrajlim.max_straight_arange);
130 curr_relcen = relcen;
131 if (mrange <= 0) {
132 // preserves currpos for modification by physics
133 stvpoint temp(currpos);
134 temp.s_ent = 0;
135 return temp;
136 }
137 currpos.tid.up_absref(&relcen); // changing to local system
138 physics_mrange(mrange);
139 trajestep ts(&gtrajlim, currpos.ptloc, currpos.dirloc, s_cf, relcen, mrange,
140 currpos.tid.eid.back()->Gavol()->prec);
141 if (ts.mrange <= 0) {
142 stvpoint temp(currpos);
143 temp.s_ent = 0;
144 return temp;
145 }
146 // Here the range is calculated:
147 int sb;
148 // manip_absvol_eid faeid;
150 currpos.tid.G_lavol()->range(ts, 1, sb, faeid);
151 // 1 means inside the volume and makes
152 // the program checking embraced volumes
153 if (ts.s_prec == 0) {
154 // point is crossed
155 return stvpoint(currpos, ts, sb, 0, faeid);
156 }
157 return stvpoint(currpos, ts, ts.mrange, sb, 0, faeid);
158}
159
161 // generates next position in new volume
162 mfunname("stvpoint gparticle::switch_new_vol(void)");
165 stvpoint nextp = currpos;
166 point pth = nextp.pt;
167 // search from primary
168 // In this case it does not necessary switch to encountered volume
169 // namely nextp.next_eid
170 // Borders of two volumes may coincide. Thus it should look for
171 // the deepest volume at this point.
172 bool ok = false;
173 while (!ok) {
174 nextp.tid.eid[0]->m_find_embed_vol(pth, nextp.dir, &tidl);
175 if (tidl.eid.empty()) {
176 s_life = false;
177 break;
178 }
179 // By default, assume switching to new volume.
180 int s_e = 1;
181 if (tidl == nextp.tid) {
182 // Remains in the same old volume, may be numerical error
183 // Will probably repeat attempt to switch at the same steps until ok.
184 s_e = 0;
185 double curprec = nextp.tid.G_lavol()->prec;
186 if (currpos.prange <= curprec) {
187 // very bad case, to repeat the trial.
188 vec additional_dist = nextp.dir * curprec;
189 pth = pth + additional_dist;
190 tidl = manip_absvol_treeid();
191 continue;
192 }
193 }
194 return stvpoint(pth, nextp.dir, nextp.speed, tidl, 0.0, nextp.time, 0, s_e,
195 eidl);
196 }
197 return stvpoint();
198}
199
200void gparticle::print(std::ostream& file, int l) const {
201 if (l < 0) return;
202 Ifile << "gparticle(l=" << l << "): s_life=" << s_life << " nstep=" << nstep
203 << " total_range_from_origin=" << total_range_from_origin
204 << " n_zero_step=" << n_zero_step << '\n';
205 if (l == 1) {
206 file.flush();
207 return;
208 }
209 indn.n += 2;
210 if (l - 5 >= 0) {
211 Ifile << "origin point:\n";
212 indn.n += 2;
213 origin.print(file, l - 2);
214 indn.n -= 2;
215 }
216 if (l - 4 >= 0) {
217 Ifile << "previous point:\n";
218 indn.n += 2;
219 prevpos.print(file, l - 1);
220 indn.n -= 2;
221 }
222 if (l - 2 >= 0) {
223 Ifile << "current point:\n";
224 indn.n += 2;
225 currpos.print(file, l);
226 Iprint(file, curr_relcen);
227 Ifile << " length(curr_relcen)=" << curr_relcen.length() << '\n';
228 indn.n -= 2;
229 }
230 if (l - 3 >= 0) {
231 Ifile << "next point:\n";
232 indn.n += 2;
233 nextpos.print(file, l - 1);
234 indn.n -= 2;
235 }
236 indn.n -= 2;
237 file.flush();
238}
239}
#define check_econd12a(a, sign, b, add, stream)
Definition: FunNameStack.h:181
#define mfunname(string)
Definition: FunNameStack.h:45
virtual int range(trajestep &fts, int s_ext, int &sb, PassivePtr< manip_absvol > &faeid) const
Definition: volume.cpp:98
vfloat prec
Definition: volume.h:74
virtual void print(std::ostream &file, int l) const
Definition: gparticle.cpp:200
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:116
static long max_q_zero_step
Definition: gparticle.h:174
stvpoint prevpos
Definition: gparticle.h:176
virtual void change_vol(void)
Definition: gparticle.h:194
virtual void physics_after_new_speed(std::vector< gparticle * > &)
Definition: gparticle.h:207
virtual void curvature(int &fs_cf, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:99
stvpoint origin
Definition: gparticle.h:175
double total_range_from_origin
Range from origin to currpos.
Definition: gparticle.h:170
virtual stvpoint calc_step_to_bord()
Produces nextpos.
Definition: gparticle.cpp:119
long nstep
Step number.
Definition: gparticle.h:168
virtual void step(std::vector< gparticle * > &secondaries)
Definition: gparticle.cpp:77
stvpoint currpos
Definition: gparticle.h:177
gparticle()
Default constructor.
Definition: gparticle.h:159
stvpoint nextpos
Definition: gparticle.h:178
stvpoint switch_new_vol()
Definition: gparticle.cpp:160
long n_zero_step
Number of previous steps with zero range (including this step).
Definition: gparticle.h:172
Service class (array of manip_absvol).
Definition: volume.h:32
void print(std::ostream &file, int l) const
Definition: volume.cpp:56
void up_absref(absref *f)
Definition: volume.cpp:26
std::vector< PassivePtr< manip_absvol > > eid
List of volumes.
Definition: volume.h:37
absvol * G_lavol() const
Get last address of volume.
Definition: volume.cpp:17
Abstract base classs for volume "manipulators".
Definition: volume.h:178
virtual int m_find_embed_vol(const point &fpt, const vec &fdir, manip_absvol_treeid *atid) const
Definition: volume.cpp:167
Point.
Definition: vec.h:374
Point in space, time and velocity.
Definition: gparticle.h:20
vfloat time
Definition: gparticle.h:47
void print(std::ostream &file, int l) const
Definition: gparticle.cpp:16
vec dirloc
Unit vector, in the local system (last system in the tree).
Definition: gparticle.h:29
vec dir
Unit vector, in the first system in the tree.
Definition: gparticle.h:25
PassivePtr< manip_absvol > next_eid
Definition: gparticle.h:44
vfloat prange
Range from previous point.
Definition: gparticle.h:46
vfloat speed
Longitudinal velocity.
Definition: gparticle.h:31
point pt
Coordinates in the first system in the tree.
Definition: gparticle.h:23
manip_absvol_treeid tid
Definition: gparticle.h:32
point ptloc
Coordinates in the local system (last system in the tree).
Definition: gparticle.h:27
vfloat max_straight_arange
Angle of range if it goes along straight line, but s_cf == 1.
Definition: trajestep.h:38
vfloat mrange
Maximal possible range.
Definition: trajestep.h:90
Definition: vec.h:186
vfloat length() const
Definition: vec.h:205
Definition: BGMesh.cpp:5
vec dv0(0, 0, 0)
Definition: vec.h:314
indentation indn
Definition: prstream.cpp:15
double vfloat
Definition: vfloat.h:16
trajestep_limit gtrajlim
Definition: TrackHeed.cc:50
#define Ifile
Definition: prstream.h:196
#define Iprint(file, name)
Definition: prstream.h:198
#define mcerr
Definition: prstream.h:128
#define pvecerror(string)
Definition: vec.h:29