Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
box.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
16// ******** box (3-dimensional rectangle (rectangular parallelogram) *******
17
18void box::get_components(ActivePtr<absref_transmit>& /*aref_tran*/) {
19 mfunnamep("box::get_components(...)");
20 funnw.ehdr(mcerr);
21 mcerr << "one should not call this function, since this object cannot be "
22 "modified\n";
24}
25
26box::box(void) : dx(0), dy(0), dz(0), dxh(0), dyh(0), dzh(0), name("none") {
27 mfunname("box::box(void)");
28 init_prec();
30}
31
32box::box(vfloat fdx, vfloat fdy, vfloat fdz, const String& fname) {
33 pvecerror("box(vfloat fdx, vfloat fdy, vfloat fdz, const String &fname)");
34 dx = abslt(fdx);
35 dy = abslt(fdy);
36 dz = abslt(fdz);
37 dxh = 0.5 * dx;
38 dyh = 0.5 * dy;
39 dzh = 0.5 * dz;
40 name = fname;
41 init_prec();
43}
44
45box::box(vfloat fdx, vfloat fdy, vfloat fdz, vfloat fprec,
46 const String& fname) {
47 pvecerror("box(vfloat fdx, vfloat fdy, vfloat fdz, const String &fname)");
48 dx = abslt(fdx);
49 dy = abslt(fdy);
50 dz = abslt(fdz);
51 dxh = 0.5 * dx;
52 dyh = 0.5 * dy;
53 dzh = 0.5 * dz;
54 name = fname;
55 prec = fprec;
57}
58
59box::box(box& fb) : absref(fb), absvol(fb) {
60 pvecerror("box(const box& fb)");
61 dx = fb.dx;
62 dy = fb.dy;
63 dz = fb.dz;
64 dxh = 0.5 * dx;
65 dyh = 0.5 * dy;
66 dzh = 0.5 * dz;
67 prec = fb.prec;
68 name = fb.name;
70}
71
72box::box(const box& fb) : absref(fb), absvol(fb) {
73 pvecerror("box(const box& fb)");
74 dx = fb.dx;
75 dy = fb.dy;
76 dz = fb.dz;
77 dxh = 0.5 * dx;
78 dyh = 0.5 * dy;
79 dzh = 0.5 * dz;
80 name = fb.name;
81 prec = fb.prec;
83}
84
85void box::init_prec(void) {
86 prec = (dxh + dyh + dzh) / 3.0;
88}
89
90void box::init_planes(void) {
91 mfunname("void box::init_planes(void)");
92 splane spl[6];
93 spl[0] = splane(plane(point(dxh, 0, 0), vec(-1, 0, 0)), vec(-1, 0, 0));
94 spl[1] = splane(plane(point(-dxh, 0, 0), vec(1, 0, 0)), vec(1, 0, 0));
95 spl[2] = splane(plane(point(0, dyh, 0), vec(0, -1, 0)), vec(0, -1, 0));
96 spl[3] = splane(plane(point(0, -dyh, 0), vec(0, 1, 0)), vec(0, 1, 0));
97 spl[4] = splane(plane(point(0, 0, dzh), vec(0, 0, -1)), vec(0, 0, -1));
98 spl[5] = splane(plane(point(0, 0, -dzh), vec(0, 0, 1)), vec(0, 0, 1));
99 surface* fsurf[6];
100 for (int n = 0; n < 6; ++n)
101 fsurf[n] = &spl[n];
102 ulsv.ulsvolume_init(fsurf, 6, "ulsv of box", prec);
103}
104
105int box::check_point_inside(const point& fpt, const vec& dir) const {
106 mfunname("virtual int check_point_inside(const point& fpt, const vec& dir)");
107#ifdef TRACE_find_embed_vol
108 mcout << "box::check_point_inside: \n";
109 print(mcout, 1);
110 mcout << "fpt=" << fpt << "dir=" << dir;
111#endif
112 if (dir == dv0) {
113 if (abslt(fpt.v.x) <= dxh && abslt(fpt.v.y) <= dyh &&
114 abslt(fpt.v.z) <= dzh) {
115 return 1;
116 }
117 return 0;
118 } else {
119 if (abslt(fpt.v.x) <= dxh - prec && abslt(fpt.v.y) <= dyh - prec &&
120 abslt(fpt.v.z) <= dzh - prec) {
121#ifdef TRACE_find_embed_vol
122 mcout << "cond 1, returning 1\n";
123#endif
124 return 1;
125 }
126 if (abslt(fpt.v.x) > dxh + prec || abslt(fpt.v.y) > dyh + prec ||
127 abslt(fpt.v.z) > dzh + prec) {
128#ifdef TRACE_find_embed_vol
129 if (abslt(fpt.v.x) > dxh + prec) mcout << "cond 2.1 satisfied\n";
130 if (abslt(fpt.v.y) > dyh + prec) mcout << "cond 2.2 satisfied\n";
131 if (abslt(fpt.v.z) > dzh + prec) mcout << "cond 2.3 satisfied\n";
132 mcout << "cond 2, returning 0\n";
133#endif
134 return 0;
135 }
136 // What remains is point belonging to border
137#ifdef IMPROVED_BOUNDARY
138 // Below we detect cases when particle is exiting, leaving the
139 // case when it is entering
140 if (abslt(fpt.v.x) > dxh - prec) {
141 if (dir.x == 0.0) return 0;
142 if ((fpt.v.x > 0 && dir.x > 0) || (fpt.v.x < 0 && dir.x < 0)) {
143#ifdef TRACE_find_embed_vol
144 mcout << "cond 3, returning 0\n";
145#endif
146 return 0;
147 }
148 }
149 if (abslt(fpt.v.y) > dyh - prec) {
150 if (dir.y == 0.0) return 0;
151 if ((fpt.v.y > 0 && dir.y > 0) || (fpt.v.y < 0 && dir.y < 0)) {
152#ifdef TRACE_find_embed_vol
153 mcout << "cond 4, returning 0\n";
154#endif
155 return 0;
156 }
157 }
158 if (abslt(fpt.v.z) > dzh - prec) {
159 if (dir.z == 0.0) return 0;
160 if ((fpt.v.z > 0 && dir.z > 0) || (fpt.v.z < 0 && dir.z < 0)) {
161#ifdef TRACE_find_embed_vol
162 mcout << "cond 5, returning 0\n";
163#endif
164 return 0;
165 }
166 }
167#ifdef TRACE_find_embed_vol
168 mcout << "finish, returning 1\n";
169#endif
170 return 1;
171
172#else
173 // for IMPROVED_BOUNDARY
174 // In the old version, which is below,
175 // if the track is parallel to a boundary, it was interpreted as
176 // signature of being inside volume.
177 // The general principal, saying that
178 // if particle is located at the boundary and headed
179 // outside the volume,
180 // it is considered in the volume to which it is headed,
181 // cannot help to choose between two versions.
182 // Of course, the box is convex and the particle flying along the border
183 // enters the external space sooner or later and it can be regarded as
184 // already outside. But the same can be said about the particle,
185 // which is completely indise the volume.
186 // So this principle does not work here.
187 // The other principle should be applied.
188 // If we allow the absolutely thing volumes (control surfaces)
189 // we should use the algorithm, which, in particular stops the particle
190 // crossing exactly the corner of volume without entering its inside.
191 // But this does not allow to choose. So now the old (this) variant
192 // is used, untill other arguments appear.
193
194 if (abslt(fpt.v.x) > dxh - prec &&
195 ((fpt.v.x > 0 && dir.x > 0) || (fpt.v.x < 0 && dir.x < 0))) {
196#ifdef TRACE_find_embed_vol
197 mcout << "cond 3, returning 0\n";
198#endif
199 return 0; // exiting
200 }
201 if (abslt(fpt.v.y) > dyh - prec &&
202 ((fpt.v.y > 0 && dir.y > 0) || (fpt.v.y < 0 && dir.y < 0))) {
203#ifdef TRACE_find_embed_vol
204 mcout << "cond 4, returning 0\n";
205#endif
206 return 0;
207 }
208 if (abslt(fpt.v.z) > dzh - prec &&
209 ((fpt.v.z > 0 && dir.z > 0) || (fpt.v.z < 0 && dir.z < 0))) {
210#ifdef TRACE_find_embed_vol
211 mcout << "cond 5, returning 0\n";
212#endif
213 return 0;
214 }
215#ifdef TRACE_find_embed_vol
216 mcout << "finish, returning 1\n";
217#endif
218 return 1;
219#endif
220 }
221}
222
223void box::print(std::ostream& file, int l) const {
224 if (l <= 0) return;
225 char s[1000];
226 chname(s);
227 Ifile << "box::print(l=" << l << "): " << s << '\n';
228 indn.n += 2;
229 Ifile << " dx=" << dx << " dy=" << dy << " dz=" << dz << " prec=" << prec
230 << '\n';
231 Ifile << " dxh=" << dxh << " dyh=" << dyh << " dzh=" << dzh << '\n';
232 if (l >= 10) {
233 l--;
234 indn.n += 2;
235 ulsv.print(file, l);
236 indn.n -= 2;
237 }
238 absvol::print(file, l);
239 indn.n -= 2;
240}
241
242int box::range_ext(trajestep& fts, int s_ext) const {
243 mfunname("virtual int box::range_ext(trajestep& fts, int s_ext) const");
244 if (s_ext == 0) {
245 if (abslt(fts.currpos.v.x) > dxh + fts.mrange) return 0;
246 if (abslt(fts.currpos.v.y) > dyh + fts.mrange) return 0;
247 if (abslt(fts.currpos.v.z) > dzh + fts.mrange) return 0;
248 } else {
249 if (abslt(fts.currpos.v.x) < dxh - fts.mrange &&
250 abslt(fts.currpos.v.y) < dyh - fts.mrange &&
251 abslt(fts.currpos.v.z) < dzh - fts.mrange) {
252 return 0;
253 }
254 }
255 return ulsv.range_ext(fts, s_ext);
256}
258
259void box::income(gparticle* /*gp*/) {}
260void box::chname(char* nm) const {
261#ifdef USE_STLSTRING
262 strcpy(nm, "box: ");
263 strcat(nm, name.c_str());
264#else
265 strcpy(nm, "box: ");
266 strcat(nm, name);
267#endif
268}
269
270// ***** manip_box ********
271
272absvol* manip_box::Gavol(void) const { return (box*)this; }
274void manip_box::chname(char* nm) const {
275#ifdef USE_STLSTRING
276 strcpy(nm, "manip_box: ");
277 strcat(nm, name.c_str());
278#else
279 strcpy(nm, "manip_box: ");
280 strcat(nm, name);
281#endif
282}
283
284void manip_box::print(std::ostream& file, int l) const {
285 if (l > 0) {
286 char s[1000];
287 chname(s);
288 Ifile << "manip_box::print(l=" << l << "): " << s << '\n';
289 l = l - 1;
290 if (l > 0) {
291 indn.n += 2;
292 box::print(file, l);
293 indn.n -= 2;
294 }
295 file.flush();
296 }
297}
298
299// ***** sh_manip_box ********
300
301absvol* sh_manip_box::Gavol(void) const { return (box*)this; }
302
303void sh_manip_box::get_components(ActivePtr<absref_transmit>& aref_tran) {
305}
306
307macro_copy_body(sh_manip_box)
308void sh_manip_box::chname(char* nm) const {
309#ifdef USE_STLSTRING
310 strcpy(nm, "sh_manip_box: ");
311 strcat(nm, name.c_str());
312#else
313 strcpy(nm, "sh_manip_box: ");
314 strcat(nm, name);
315#endif
316}
317
318void sh_manip_box::print(std::ostream& file, int l) const {
319 if (l > 0) {
320 char s[1000];
321 chname(s);
322 Ifile << "sh_manip_box::print(l=" << l << "): " << s << '\n';
323 l = l - 1;
324 if (l > 0) {
325 indn.n += 2;
326 csys.print(file, l);
327 box::print(file, l);
328 indn.n -= 2;
329 }
330 file.flush();
331 }
332}
333
334}
#define macro_copy_body(type)
Definition: AbsPtr.h:297
#define mfunnamep(string)
Definition: FunNameStack.h:77
#define spexit(stream)
Definition: FunNameStack.h:536
#define mfunname(string)
Definition: FunNameStack.h:67
std::string String
Definition: String.h:75
Definition: box.h:24
String name
Definition: box.h:29
vfloat dx
Definition: box.h:26
vfloat dzh
Definition: box.h:27
virtual int range_ext(trajestep &fts, int s_ext) const
Definition: box.cpp:242
vfloat dz
Definition: box.h:26
virtual void income(gparticle *gp)
virtual void print(std::ostream &file, int l) const
Definition: box.cpp:223
vfloat dy
Definition: box.h:26
void init_planes(void)
Definition: box.cpp:90
vfloat dyh
Definition: box.h:27
vfloat dxh
Definition: box.h:27
ulsvolume ulsv
Definition: box.h:28
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: box.cpp:18
void init_prec(void)
Definition: box.cpp:85
box(void)
Constructors.
Definition: box.cpp:26
virtual void chname(char *nm) const
Definition: box.cpp:260
virtual int check_point_inside(const point &fpt, const vec &dir) const
Definition: box.cpp:105
virtual void chname(char *nm) const
virtual absvol * Gavol(void) const
Definition: box.cpp:272
virtual void print(std::ostream &file, int l) const
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
virtual void print(std::ostream &file, int l) const
virtual absvol * Gavol(void) const
virtual void chname(char *nm) const
void ulsvolume_init(surface *fsurf[pqqsurf], int fqsurf, const String &fname, vfloat fprec)
Definition: surface.cpp:339
virtual void print(std::ostream &file, int l) const
int range_ext(trajestep &fts, int s_ext) const
Definition: surface.cpp:214
Definition: vec.h:134
Definition: volume.h:91
vfloat prec
Definition: volume.h:95
virtual void print(std::ostream &file, int l) const
Definition: volume.cpp:144
virtual void print(std::ostream &file, int l) const
Definition: vec.cpp:622
Definition: vec.h:477
vec v
Definition: vec.h:479
fixsyscoor csys
Definition: volume.h:233
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
point currpos
Definition: trajestep.h:74
vfloat mrange
Definition: trajestep.h:91
Definition: vec.h:248
vfloat y
Definition: vec.h:250
vfloat x
Definition: vec.h:250
vfloat z
Definition: vec.h:250
Definition: BGMesh.cpp:3
indentation indn
Definition: prstream.cpp:13
#define mcout
Definition: prstream.h:133
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
vec dv0(0, 0, 0)
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15
vfloat abslt(vfloat f)
Definition: vfloat.h:19
const vfloat vprecision
Definition: vfloat.h:17