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