Garfield++ 5.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
4/*
5Copyright (c) 2000 Igor B. Smirnov
6
7The file can be used, copied, modified, and distributed
8according to the terms of GNU Lesser General Public License version 2.1
9as published by the Free Software Foundation,
10and provided that the above copyright notice, this permission notice,
11and notices about any modifications of the original text
12appear in all copies and in supporting documentation.
13The file is provided "as is" without express or implied warranty.
14*/
15
16namespace Heed {
17
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 return absref_transmit();
25}
26
28 : m_dx(0), m_dy(0), m_dz(0), m_dxh(0), m_dyh(0), m_dzh(0), m_name("none") {
29 mfunname("box::box()");
30 init_prec();
32}
33
34box::box(vfloat fdx, vfloat fdy, vfloat fdz, const std::string& fname) {
35 pvecerror("box(vfloat fdx, vfloat fdy, vfloat fdz, const string &fname)");
36 m_dx = fabs(fdx);
37 m_dy = fabs(fdy);
38 m_dz = fabs(fdz);
39 m_dxh = 0.5 * m_dx;
40 m_dyh = 0.5 * m_dy;
41 m_dzh = 0.5 * m_dz;
42 m_name = fname;
43 init_prec();
45}
46
47box::box(vfloat fdx, vfloat fdy, vfloat fdz, vfloat fprec,
48 const std::string& fname) {
49 pvecerror("box(vfloat fdx, vfloat fdy, vfloat fdz, vfloat fprec, const string &fname)");
50 m_dx = fabs(fdx);
51 m_dy = fabs(fdy);
52 m_dz = fabs(fdz);
53 m_dxh = 0.5 * m_dx;
54 m_dyh = 0.5 * m_dy;
55 m_dzh = 0.5 * m_dz;
56 m_name = fname;
57 prec = fprec;
59}
60
61box::box(box& fb) : absref(fb), absvol(fb) {
62 pvecerror("box(box& fb)");
63 m_dx = fb.m_dx;
64 m_dy = fb.m_dy;
65 m_dz = fb.m_dz;
66 m_dxh = 0.5 * m_dx;
67 m_dyh = 0.5 * m_dy;
68 m_dzh = 0.5 * m_dz;
69 prec = fb.prec;
70 m_name = fb.m_name;
72}
73
74box::box(const box& fb) : absref(fb), absvol(fb) {
75 pvecerror("box(const box& fb)");
76 m_dx = fb.m_dx;
77 m_dy = fb.m_dy;
78 m_dz = fb.m_dz;
79 m_dxh = 0.5 * m_dx;
80 m_dyh = 0.5 * m_dy;
81 m_dzh = 0.5 * m_dz;
82 m_name = fb.m_name;
83 prec = fb.prec;
85}
86
88 prec = (m_dxh + m_dyh + m_dzh) / 3.0;
90}
91
93 mfunname("void box::init_planes()");
94 std::vector<std::shared_ptr<surface> > fsurf(6);
95 fsurf[0] = std::make_shared<splane>(
96 plane(point(m_dxh, 0, 0), vec(-1, 0, 0)), vec(-1, 0, 0));
97 fsurf[1] = std::make_shared<splane>(
98 plane(point(-m_dxh, 0, 0), vec(+1, 0, 0)), vec(+1, 0, 0));
99 fsurf[2] = std::make_shared<splane>(
100 plane(point(0, m_dyh, 0), vec(0, -1, 0)), vec(0, -1, 0));
101 fsurf[3] = std::make_shared<splane>(
102 plane(point(0, -m_dyh, 0), vec(0, +1, 0)), vec(0, +1, 0));
103 fsurf[4] = std::make_shared<splane>(
104 plane(point(0, 0, m_dzh), vec(0, 0, -1)), vec(0, 0, -1));
105 fsurf[5] = std::make_shared<splane>(
106 plane(point(0, 0, -m_dzh), vec(0, 0, +1)), vec(0, 0, +1));
107 m_ulsv.ulsvolume_init(fsurf, "ulsv of box", prec);
108}
109
110int box::check_point_inside(const point& fpt, const vec& dir) const {
111 mfunname("int check_point_inside(const point& fpt, const vec& dir)");
112#ifdef TRACE_find_embed_vol
113 mcout << "box::check_point_inside: \n";
114 print(mcout, 1);
115 mcout << "fpt=" << fpt << "dir=" << dir;
116#endif
117 if (dir == dv0) {
118 if (fabs(fpt.v.x) <= m_dxh && fabs(fpt.v.y) <= m_dyh &&
119 fabs(fpt.v.z) <= m_dzh) {
120 return 1;
121 }
122 return 0;
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 mcout << "cond 1, returning 1\n";
128#endif
129 return 1;
130 }
131 if (fabs(fpt.v.x) > m_dxh + prec || fabs(fpt.v.y) > m_dyh + prec ||
132 fabs(fpt.v.z) > m_dzh + prec) {
133#ifdef TRACE_find_embed_vol
134 if (fabs(fpt.v.x) > m_dxh + prec) mcout << "cond 2.1 satisfied\n";
135 if (fabs(fpt.v.y) > m_dyh + prec) mcout << "cond 2.2 satisfied\n";
136 if (fabs(fpt.v.z) > m_dzh + prec) mcout << "cond 2.3 satisfied\n";
137 mcout << "cond 2, returning 0\n";
138#endif
139 return 0;
140 }
141 // What remains is point belonging to border.
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#ifdef IMPROVED_BOUNDARY
146 if (dir.x == 0.0) return 0;
147#endif
148 if ((fpt.v.x > 0 && dir.x > 0) || (fpt.v.x < 0 && dir.x < 0)) {
149#ifdef TRACE_find_embed_vol
150 mcout << "cond 3, returning 0\n";
151#endif
152 return 0;
153 }
154 }
155 if (fabs(fpt.v.y) > m_dyh - prec) {
156#ifdef IMPROVED_BOUNDARY
157 if (dir.y == 0.0) return 0;
158#endif
159 if ((fpt.v.y > 0 && dir.y > 0) || (fpt.v.y < 0 && dir.y < 0)) {
160#ifdef TRACE_find_embed_vol
161 mcout << "cond 4, returning 0\n";
162#endif
163 return 0;
164 }
165 }
166 if (fabs(fpt.v.z) > m_dzh - prec) {
167#ifdef IMPROVED_BOUNDARY
168 if (dir.z == 0.0) return 0;
169#endif
170 if ((fpt.v.z > 0 && dir.z > 0) || (fpt.v.z < 0 && dir.z < 0)) {
171#ifdef TRACE_find_embed_vol
172 mcout << "cond 5, returning 0\n";
173#endif
174 return 0;
175 }
176 }
177#ifdef TRACE_find_embed_vol
178 mcout << "finish, returning 1\n";
179#endif
180 return 1;
181}
182
183void box::print(std::ostream& file, int l) const {
184 if (l <= 0) return;
185 char s[1000];
186 chname(s);
187 Ifile << "box::print(l=" << l << "): " << s << '\n';
188 indn.n += 2;
189 Ifile << " dx=" << m_dx << " dy=" << m_dy << " dz=" << m_dz
190 << " prec=" << prec << '\n';
191 Ifile << " dxh=" << m_dxh << " dyh=" << m_dyh << " dzh=" << m_dzh << '\n';
192 if (l >= 10) {
193 l--;
194 indn.n += 2;
195 m_ulsv.print(file, l);
196 indn.n -= 2;
197 }
198 absvol::print(file, l);
199 indn.n -= 2;
200}
201
202int box::range_ext(trajestep& fts, int s_ext) const {
203 mfunname("virtual int box::range_ext(trajestep& fts, int s_ext) const");
204 if (s_ext == 0) {
205 if (fabs(fts.currpos.v.x) > m_dxh + fts.mrange) return 0;
206 if (fabs(fts.currpos.v.y) > m_dyh + fts.mrange) return 0;
207 if (fabs(fts.currpos.v.z) > m_dzh + fts.mrange) return 0;
208 } else {
209 if (fabs(fts.currpos.v.x) < m_dxh - fts.mrange &&
210 fabs(fts.currpos.v.y) < m_dyh - fts.mrange &&
211 fabs(fts.currpos.v.z) < m_dzh - fts.mrange) {
212 return 0;
213 }
214 }
215 return m_ulsv.range_ext(fts, s_ext);
216}
217
218box* box::copy() const { return new box(*this); }
219
220void box::income(gparticle* /*gp*/) {}
221void box::chname(char* nm) const {
222 strcpy(nm, "box: ");
223 strcat(nm, m_name.c_str());
224}
225
226// ***** manip_box ********
227
228absvol* manip_box::Gavol() const { return (box*)this; }
229manip_box* manip_box::copy() const { return new manip_box(*this); }
230void manip_box::chname(char* nm) const {
231 strcpy(nm, "manip_box: ");
232 strcat(nm, m_name.c_str());
233}
234
235void manip_box::print(std::ostream& file, int l) const {
236 if (l <= 0) return;
237 char s[1000];
238 chname(s);
239 Ifile << "manip_box::print(l=" << l << "): " << s << '\n';
240 l = l - 1;
241 if (l > 0) {
242 indn.n += 2;
243 box::print(file, l);
244 indn.n -= 2;
245 }
246 file.flush();
247}
248
249// ***** sh_manip_box ********
250
251// absvol* sh_manip_box::Gavol() const { return (box*)this; }
253 return dynamic_cast<box*>(const_cast<sh_manip_box*>(this));
254}
255
259
260sh_manip_box* sh_manip_box::copy() const { return new sh_manip_box(*this); }
261void sh_manip_box::chname(char* nm) const {
262 strcpy(nm, "sh_manip_box: ");
263 strcat(nm, m_name.c_str());
264}
265
266void sh_manip_box::print(std::ostream& file, int l) const {
267 if (l <= 0) return;
268 char s[1000];
269 chname(s);
270 Ifile << "sh_manip_box::print(l=" << l << "): " << s << '\n';
271 l = l - 1;
272 if (l > 0) {
273 indn.n += 2;
274 csys.print(file, l);
275 box::print(file, l);
276 indn.n -= 2;
277 }
278 file.flush();
279}
280}
#define mfunnamep(string)
#define spexit(stream)
#define mfunname(string)
virtual void print(std::ostream &file, int l) const
Definition volume.cpp:120
vfloat prec
Definition volume.h:72
int range_ext(trajestep &fts, int s_ext) const override
Range till exit from given volume or to entry only.
Definition box.cpp:202
box * copy() const override
Definition box.cpp:218
absref_transmit get_components() override
Definition box.cpp:18
void income(gparticle *gp) override
Definition box.cpp:220
void init_planes()
Definition box.cpp:92
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:183
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:87
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:110
void chname(char *nm) const override
Definition box.cpp:221
box()
Default constructor.
Definition box.cpp:27
manip_box()
Constructor.
Definition box.h:66
manip_box * copy() const override
Definition box.cpp:229
void chname(char *nm) const override
Definition box.cpp:230
absvol * Gavol() const override
Get the volume.
Definition box.cpp:228
void print(std::ostream &file, int l) const override
Definition box.cpp:235
Plane, defined by defined by a point and a vector normal to the plane.
Definition plane.h:24
Point.
Definition vec.h:368
vec v
Definition vec.h:370
fixsyscoor csys
Definition volume.h:168
virtual absref_transmit get_components() override
Definition volume.cpp:257
absref_transmit get_components() override
Definition box.cpp:256
sh_manip_box()
Constructor.
Definition box.h:82
void print(std::ostream &file, int l) const override
Definition box.cpp:266
void chname(char *nm) const override
Definition box.cpp:261
absvol * Gavol() const override
Get the volume.
Definition box.cpp:252
sh_manip_box * copy() const override
Definition box.cpp:260
point currpos
Current position.
Definition trajestep.h:74
vfloat mrange
Maximal possible range.
Definition trajestep.h:93
vfloat x
Definition vec.h:192
vfloat z
Definition vec.h:194
vfloat y
Definition vec.h:193
Definition BGMesh.cpp:6
vec dv0(0, 0, 0)
Definition vec.h:308
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:195
#define mcerr
Definition prstream.h:128
#define pvecerror(string)
Definition vec.h:28