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