Garfield++ v1r0
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
14void stvpoint::print(std::ostream& file, int l) const {
15 if (l >= 0) {
16 Ifile << "stvpoint: sb=" << sb << " s_ent=" << s_ent << " prange=" << prange
17 << " time=" << time << '\n';
18 indn.n += 2;
19 Ifile << "position:\n";
20 file << pt << ptloc;
21 Ifile << "direction of moving:\n";
22 file << dir << dirloc;
23 Ifile << "speed=" << speed << '\n';
24 if (tid.qeid <= 0) {
25 Ifile << "point is outside universe, tid.qeid=" << tid.qeid << '\n';
26 file.flush();
27 indn.n -= 2;
28 return;
29 }
30 tid.print(file, 1);
31 char s[100];
32 //amvol[namvol-1]->chname(s);
33 //Ifile<<"current volume name "<<s<<'\n';
34 if (sb == 2) {
35 next_eid.amvol->m_chname(s);
36 Ifile << "next volume name " << s << '\n';
37 }
38 //if(l>1)
39 //{
40 // Ifile<<"current volume:\n";
41 // amvol[namvol-1]->print(file,l-1);
42 //}
43 indn.n -= 2;
44 file.flush();
45 }
46}
47
49
50gparticle::gparticle(manip_absvol* primvol, const point& pt, const vec& vel,
51 vfloat time)
52 : s_life(0),
53 nstep(0),
54 total_range_from_origin(0.0),
55 n_zero_step(0),
56 prevpos(),
57 nextpos() {
58 mfunname("gparticle::gparticle(...)");
59 //mcout<<"origin.namvol="<<origin.namvol<<'\n';
60 origin.tid.eid[0].nembed = 0; // just to clear
61 primvol->m_find_embed_vol(pt, vel, &origin.tid);
62 origin.pt = pt;
63 if (vel == dv0) {
64 origin.dir = dv0;
65 origin.speed = 0.0;
66 } else {
67 origin.dir = unit_vec(vel);
68 origin.speed = length(vel);
69 }
74 origin.time = time;
75 origin.sb = 0;
76 origin.s_ent = 1; //origin.next_eid=NULL;
77 if (origin.tid.qeid == 0) return;
78 s_life = 1;
81 nextpos.s_ent = 0;
82 //mcout<<"origin.namvol="<<origin.namvol<<'\n';
83 //mcout<<"origin=\n"; origin.print(mcout,1);
84 //mcout<<"currpos=\n"; currpos.print(mcout,1);
85 //nextpos=calc_step_to_bord();
86}
87
89 void) { // make step to nextpos and calculate new step to border
90 mfunname("void gparticle::step(void)");
95 nstep++;
96 if (currpos.prange == 0) {
99 "too much zero steps, possible infinite loop\n", mcerr);
100 } else
101 n_zero_step = 0;
103 if (s_life == 1) {
104 if (prevpos.tid != currpos.tid)
105 //prevpos.namvol != currpos.namvol ||
106 //prevpos.amvol[prevpos.namvol-1] != currpos.amvol[currpos.namvol-1])
107 change_vol(); // possible correction ( reflection..)
109 }
110}
111
112void gparticle::curvature(int& fs_cf, vec& frelcen, vfloat& fmrange,
113 vfloat /*prec*/) {
114 fs_cf = 0;
115 frelcen = vec(0, 0, 0);
116 fmrange = max_vfloat;
117 /* The following is for debug
118 vec field(0,1,0);
119 vfloat rad = 10;
120 if (length(currpos.dir) > 0 && check_par(currpos.dir, field) == 0) {
121 fs_cf = 1;
122 vfloat coef = sin2vec(currpos.dir, field);
123 rad = rad / coef;
124 frelcen = unit_vec(currpos.dir || field) * rad;
125 }
126 */
127}
128
129void gparticle::physics_mrange(double& /*fmrange*/) {}
130
131// calculate next point as step to border
133 pvecerror("stvpoint gparticle::calc_step_to_bord()");
135 if (currpos.sb > 0) {
136 // it does not do step, but switch to new volume
137 //return switch_new_vol(currpos.amvol, currpos.namvol);
138 return switch_new_vol();
139 } else {
140 manip_absvol_eid faeid; //manip_absvol* famvol;
141 /*
142 if(currpos.s_ent > 0 && currpos.tid.G_lavol()->mandatory()==1) {
143 // to find volume again, borders can be common for many volumes,
144 // or mandatory volume can be thin.
145 // manip_absvol* ffamvol[pqamvol];
146 manip_absvol_treeid tidl;
147 //int ffnamvol=0;
148 currpos.tid.eid[0].amvol->find_embed_vol(currpos.pt, currpos.dir, &tidl);
149 if(currpos.tid != tidl)
150 //currpos.namvol != ffnamvol ||
151 //currpos.amvol[currpos.namvol-1] != ffamvol[ffnamvol-1])
152 {
153 //Imcout<<"calc_step_to_bord: volume is changed again\n";
154 return stvpoint(currpos.pt, currpos.dir, currpos.speed,
155 currpos.tid,
156 //currpos.amvol, currpos.namvol, // till end of this
157 0.0,
158 currpos.time ,
159 1, 0, *(tidl.G_laeid()) );
160 }
161 }
162 */
163 int s_cf;
164 vec relcen;
165 vfloat mrange;
166 //mcout<<"gparticle::calc_step_to_bord(): now running the curvature()\n";
167 curvature(s_cf, relcen, mrange, gtrajlim.max_straight_arange);
168 curr_relcen = relcen;
169 if (mrange <= 0) {
170 // preserves currpos for modification by physics
171 stvpoint temp(currpos);
172 temp.s_ent = 0;
173 return temp;
174 }
175 //mcout<<"s_cf="<<s_cf<<" relcen="<<relcen
176 // <<"mrange="<<mrange<<'\n';
177
178 //mcout<<"gparticle::calc_step_to_bord(): now running the trajestep\n";
179 currpos.tid.up_absref(&relcen); // changing to local system
180 physics_mrange(mrange);
181 trajestep ts(&gtrajlim, currpos.ptloc, currpos.dirloc, s_cf, relcen, mrange,
182 currpos.tid.G_laeid()->amvol->Gavol()->prec);
183 //s_cf, relcen, mrange, currpos.next_eid.amvol->Gavol()->prec );
184 if (ts.mrange <= 0) {
185 stvpoint temp(currpos);
186 temp.s_ent = 0;
187 return temp;
188 /*
189 return stvpoint(currpos.pt, currpos.dir, currpos.speed,
190 currpos.tid,
191 //currpos.amvol, currpos.namvol, // till end of this
192 ts.mrange,
193 currpos.time,
194 0, 0, currpos.next_eid );
195 */
196 }
197 //mcout<<"calc_step_to_bord: ts="<<ts;
198 //currpos.tid.G_lavol()->print(mcout, 1);
199
200 // Here the range is calculated:
201 int sb;
202 currpos.tid.G_lavol()->range(ts, 1, sb, &faeid);
203 // 1 means inside the volume and makes
204 // the program checking embraced volumes
205 // point pte;
206 // range(currpos.pt, currpos.dir,
207 // 1, sb, rng, pte, &faeid);
208 //mcout<<"calc_step_to_bord: sb="<<sb<<" ts="<<ts;
209 if (ts.s_prec == 0) {
210 // point is crossed
211 return stvpoint(currpos, ts, sb, 0, faeid);
212 } else {
213 return stvpoint(currpos, ts, ts.mrange, sb, 0, faeid);
214 }
215 /*
216 vec dir;
217 ts.Gnextpoint(ts.mrange, pte, dir);
218 return stvpoint(pte, dir, currpos.speed,
219 currpos.tid,
220 //currpos.amvol, currpos.namvol, // till end of this
221 ts.mrange,
222 currpos.time + ts.mrange / currpos.speed,
223 sb, 0, faeid );
224 */
225 }
226}
227
228//vfloat gparticle::precision_of_switch=PRECISION_OF_SWITCH;
229
230//stvpoint gparticle::switch_new_vol(manip_absvol* famvol[pqamvol], int fnamvol)
232 // generates next position in new volume
233 mfunname("stvpoint gparticle::switch_new_vol(void)");
234 /*
235 mcout<<"gparticle::switch_new_vol:\n";
236 if(currpos.next_eid.amvol==NULL)
237 {
238 mcout<<"currpos.next_eid.amvol="<<currpos.next_eid.amvol<<'\n';
239 }
240 else
241 {
242 currpos.next_eid.amvol->print(mcout,3);
243 int i=currpos.next_eid.amvol->check_point_inside(currpos.ptloc,
244 currpos.dirloc);
245 mcout<<"i="<<i<<'\n';
246 }
247 */
249 manip_absvol_eid eidl;
250 //int namvoll=0;
251 //manip_absvol* amvoll[pqamvol];
252 stvpoint nextp = currpos;
253 //vec additional_dist=currpos.dir * nextp.next_eid.amvol->Gavol()->prec;
254 //vec additional_dist=currpos.dir * precision_of_switch;
255 //nextp.pt.shift(additional_dist);
256 //nextp.time=nextp.time+length(additional_dist)/nextp.speed;
257 point pth = nextp.pt;
258//if(famvol[fnamvol]->Gavol()->mandatory()==1)
259/*
260if(nextp.sb==2 && nextp.next_eid.amvol->Gavol()->mandatory()==1)
261{
262 // Going to embraced volume even if it is too thin
263 //for( namvoll=0; namvoll<nextp.namvol; namvoll++)
264 // amvoll[namvoll]=nextp.amvol[namvoll];
265 //amvoll[namvoll++]=nextp.next_mvol;
266 tidl = nextp.tid;
267 tidl.eid[tidl.qeid++] = nextp.next_eid;
268 return stvpoint(pth, nextp.dir, nextp.speed, tidl,
269 0.0, nextp.time, 0 , 1, eidl);
270}
271else
272{
273*/
274// search from primary
275// In this case it does not necessary switch to encountered volume
276// namely nextp.next_eid
277// Borders of two volumes may coincide. Thus it should look for
278// the deepest volume at this point.
279mark1:
280 nextp.tid.eid[0].amvol->m_find_embed_vol(pth, nextp.dir, &tidl);
281 //tidl.print(mcout, 2);
282 //mcout<<"namvoll="<<namvoll<<'\n';
283 if (tidl.qeid > 0) {
284 int s_e;
285 if (tidl == nextp.tid) {
286 //namvoll==nextp.namvol && amvoll[namvoll-1]==nextp.amvol[namvoll-1] )
287 s_e = 0; // remains in the same old volume, may be numerical error
288 // Will probably repeat attempt to switch at the same steps
289 // untill success.
290 //mcout<<"stvpoint gparticle::switch_new_vol(void): remains in the same
291 //volume\n";
292 double curprec = nextp.tid.G_lavol()->prec;
293 if (currpos.prange <= curprec) { // very bad case, to repeat the trial.
294 //mcout<<"trial is repeated\n";
295 vec additional_dist = nextp.dir * curprec;
296 //Iprint(mcout, additional_dist);
297 pth = pth + additional_dist;
298 //Iprint(mcout, pth);
299 tidl = manip_absvol_treeid();
300 goto mark1;
301 }
302 } else
303 s_e = 1; // switch to new volume
304 return stvpoint(pth, nextp.dir, nextp.speed, tidl, 0.0, nextp.time, 0, s_e,
305 eidl);
306 } else {
307 s_life = 0;
308 return stvpoint();
309 }
310 //}
311}
312void gparticle::print(std::ostream& file, int l) const {
313 if (l >= 0) {
314 Ifile << "gparticle(l=" << l << "): s_life=" << s_life << " nstep=" << nstep
315 << " total_range_from_origin=" << total_range_from_origin
316 << " n_zero_step=" << n_zero_step << '\n';
317 if (l == 1) {
318 file.flush();
319 return;
320 }
321 indn.n += 2;
322 if (l - 5 >= 0) {
323 Ifile << "origin point:\n";
324 indn.n += 2;
325 origin.print(file, l - 2);
326 indn.n -= 2;
327 }
328 if (l - 4 >= 0) {
329 Ifile << "previous point:\n";
330 indn.n += 2;
331 prevpos.print(file, l - 1);
332 indn.n -= 2;
333 }
334 if (l - 2 >= 0) {
335 Ifile << "current point:\n";
336 indn.n += 2;
337 currpos.print(file, l);
338 Iprint(file, curr_relcen);
339 Ifile << " length(curr_relcen)=" << length(curr_relcen) << '\n';
340 indn.n -= 2;
341 }
342 if (l - 3 >= 0) {
343 Ifile << "next point:\n";
344 indn.n += 2;
345 nextpos.print(file, l - 1);
346 indn.n -= 2;
347 }
348 indn.n -= 2;
349 file.flush();
350 }
351}
#define check_econd12a(a, sign, b, add, stream)
Definition: FunNameStack.h:411
#define mfunname(string)
Definition: FunNameStack.h:67
vfloat prec
Definition: volume.h:95
virtual int range(trajestep &fts, int s_ext, int &sb, manip_absvol_eid *faeid) const
Definition: volume.cpp:118
stvpoint currpos
Definition: gparticle.h:188
vec curr_relcen
Definition: gparticle.h:190
long n_zero_step
Definition: gparticle.h:183
virtual void physics_mrange(double &fmrange)
Definition: gparticle.cpp:129
virtual void curvature(int &fs_cf, vec &frelcen, vfloat &fmrange, vfloat prec)
Definition: gparticle.cpp:112
stvpoint switch_new_vol(void)
Definition: gparticle.cpp:231
virtual void print(std::ostream &file, int l) const
Definition: gparticle.cpp:312
virtual stvpoint calc_step_to_bord()
Definition: gparticle.cpp:132
virtual void physics_after_new_speed(void)
Definition: gparticle.h:231
virtual void step(void)
Definition: gparticle.cpp:88
double total_range_from_origin
Definition: gparticle.h:182
stvpoint origin
Definition: gparticle.h:186
stvpoint prevpos
Definition: gparticle.h:187
long nstep
Definition: gparticle.h:181
int s_life
Definition: gparticle.h:180
virtual void change_vol(void)
Definition: gparticle.h:218
gparticle(void)
Definition: gparticle.h:194
static long max_q_zero_step
Definition: gparticle.h:185
stvpoint nextpos
Definition: gparticle.h:189
PassivePtr< manip_absvol > amvol
Definition: volume.h:39
const manip_absvol_eid * G_laeid() const
Definition: volume.h:54
manip_absvol_eid eid[pqamvol]
Definition: volume.h:52
void print(std::ostream &file, int l) const
Definition: volume.cpp:70
void up_absref(absref *f)
Definition: volume.cpp:37
absvol * G_lavol() const
Definition: volume.cpp:28
virtual int m_find_embed_vol(const point &fpt, const vec &fdir, manip_absvol_treeid *atid) const
Definition: vec.h:477
int sb
Definition: gparticle.h:46
point pt
Definition: gparticle.h:33
point ptloc
Definition: gparticle.h:37
virtual void print(std::ostream &file, int l) const
Definition: gparticle.cpp:14
manip_absvol_eid next_eid
Definition: gparticle.h:52
vec dirloc
Definition: gparticle.h:39
int s_ent
Definition: gparticle.h:49
vfloat prange
Definition: gparticle.h:54
manip_absvol_treeid tid
Definition: gparticle.h:43
vfloat time
Definition: gparticle.h:55
vec dir
Definition: gparticle.h:35
vfloat speed
Definition: gparticle.h:41
vfloat max_straight_arange
Definition: trajestep.h:48
vfloat mrange
Definition: trajestep.h:91
int s_prec
Definition: trajestep.h:90
Definition: vec.h:248
trajestep_limit gtrajlim
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
#define Iprint(file, name)
Definition: prstream.h:209
#define mcerr
Definition: prstream.h:135
vec dv0(0, 0, 0)
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15
#define max_vfloat
Definition: vfloat.h:14