Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
volume.cpp
Go to the documentation of this file.
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
16 amvol.put(NULL);
17 nembed = -1;
18}
19
20void manip_absvol_eid::print(std::ostream& file, int l) const {
21 if (l < 0) return;
22 char s[1000];
23 amvol->m_chname(s);
24 Ifile << s << ", nembed=" << nembed << '\n';
25 file.flush();
26}
27
29 return qeid > 0 ? eid[qeid - 1].amvol->Gavol() : 0;
30}
31
33 for (int n = qeid - 1; n >= 1; n--)
34 eid[n].amvol->down_absref(f);
35}
36
38 for (int n = 1; n < qeid; ++n)
39 eid[n].amvol->up_absref(f);
40}
41
43 for (int n = 0; n < qeid; ++n) {
44 if (eid[n].amvol.get() == amvol) return 1;
45 }
46 return 0;
47}
48
50 for (int n = 0; n < qeid; ++n) {
51 if (eid[n].amvol->Gavol() == avol) return 1;
52 }
53 return 0;
54}
55
57 // checks total route
58 // first to make fast rejection
59 if (tid1.qeid != tid2.qeid) return 0;
60 if (tid1.G_laeid()->nembed != tid2.G_laeid()->nembed) return 0;
61 if (tid1.G_lamvol() != tid2.G_lamvol()) return 0;
62 // more thoroughly
63 for (int n = 0; n < tid1.qeid - 1; ++n) {
64 // the last is checked
65 if (tid1.eid[n].amvol.get() != tid2.eid[n].amvol.get()) return 0;
66 }
67 return 1;
68}
69
70void manip_absvol_treeid::print(std::ostream& file, int l) const {
71 if (l >= 0) {
72 if (qeid <= 0) {
73 Ifile << "no volume defined, qeid=" << qeid << '\n';
74 } else {
75 if (l > 0) {
76 for (int n = 0; n < qeid - 1; ++n) {
77 Ifile << "n=" << n;
78 eid[n].print(file, 0);
79 }
80 }
81 Ifile << "n=" << qeid - 1;
82 eid[qeid - 1].print(file, 0);
83 }
84 file.flush();
85 }
86}
87// ******** absvol *******
90}
91
92int absvol::find_embed_vol(const point& fpt, const vec& dir,
93 manip_absvol_treeid* atid) const {
94 if (check_point_inside(fpt, dir) == 0) return 0;
95 const int s = atid->qeid;
97 if (aman.get_qel() > 0 && atid->qeid >= pqamvol) {
98 mcerr << "absvol::find_embed_vol:\n"
99 << " aman->get_qel() > 0 && atid->qeid == pqamvol\n"
100 << " atid->qeid=" << atid->qeid << '\n';
101 mcerr << " Increase pqamvol\n";
102 exit(1);
103 }
104
105 for (int n = 0; n < aman.get_qel(); ++n) {
106 atid->eid[atid->qeid].nembed = n; // for next
107 const int i = aman[n]->m_find_embed_vol(fpt, dir, atid);
108 if (i == 1) {
109 if (s < atid->qeid) break;
110 Imcout << "absvol::find_embed_vol:\n";
111 Imcout << " Warning: contradiction between "
112 << " i==1 and s == fnamvol\n";
113 }
114 }
115 return 1;
116}
117
118int absvol::range(trajestep& fts, int s_ext, int& sb,
119 manip_absvol_eid* faeid) const {
120 faeid->amvol.put(NULL);
121 faeid->nembed = -1;
122 if (s_ext == 0) {
123 sb = 1;
124 return range_ext(fts, 0);
125 }
126 int s = range_ext(fts, 1);
127 if (s == 1) {
128 sb = 1;
129 } else {
130 sb = 0;
131 }
133 for (int n = 0; n < aman.get_qel(); ++n) {
134 if (aman[n]->m_range_ext(fts, 0) == 1) {
135 sb = 2;
136 faeid->amvol.put(aman[n]);
137 faeid->nembed = n;
138 }
139 }
140 if (sb == 1 || sb == 2) return 1;
141 return 0;
142}
143
144void absvol::print(std::ostream& file, int l) const {
145 if (l <= 0) return;
146 char s[1000];
147 chname(s);
148 Ifile << "absvol::print(l=" << l << "): name=" << s << '\n';
149 --l;
150 if (l > 0) {
152 indn.n += 2;
153 if (embed.get_qel() > 0) {
154 Ifile << "The following volumes are embraced, q=" << embed.get_qel()
155 << '\n';
156 indn.n += 2;
157 for (int n = 0; n < embed.get_qel(); ++n) {
158 Ifile << "n=" << n << '\n';
159 indn.n += 2;
160 embed[n]->m_print(file, l);
161 indn.n -= 2;
162 }
163 indn.n -= 2;
164 } else {
165 Ifile << "None of embraced volumes\n";
166 }
167 indn.n -= 2;
168 }
169 file.flush();
170}
171
173
174// ********* manip_absvol *********
176 const vec& fdir) const {
177 const abssyscoor* asc = Gasc();
178 const absvol* avol = Gavol();
179 if (asc != NULL) {
180 point pt = fpt;
181 vec dir = fdir;
182 pt.up(asc);
183 dir.up(asc);
184 return avol->check_point_inside(pt, dir);
185 }
186 return avol->check_point_inside(fpt, fdir);
187}
188
189int manip_absvol::m_find_embed_vol(const point& fpt, const vec& fdir,
190 manip_absvol_treeid* atid) const {
191 mfunname("int manip_absvol::m_find_embed_vol(...)");
192 absvol* avol = Gavol();
193 point pt = fpt;
194 up_absref(&pt);
195 vec dir = fdir;
196 up_absref(&dir);
197 atid->eid[atid->qeid++].amvol.put((manip_absvol*)this); // to kill const
198 int s = atid->qeid;
199 int iret = avol->find_embed_vol(pt, dir, atid);
200 if (iret == 0) {
201 if (atid->qeid < s) {
202 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
203 exit(1);
204 }
205 atid->qeid--;
206 return 0;
207 } else {
208 if (atid->qeid < s) {
209 mcerr << "manip_absvol::m_find_embed_vol: should never happen\n";
210 exit(1);
211 }
212 return 1;
213 }
214}
215
216int manip_absvol::m_range(trajestep& fts, int s_ext, int& sb,
217 manip_absvol_eid* faeid) const {
218 trajestep ts(fts);
219 up_absref(&ts);
220 absvol* avol = Gavol();
221
222 int s = avol->range(ts, s_ext, sb, faeid);
223 if (s == 1) {
224 down_absref(&ts);
225 fts = ts;
226 }
227 return s;
228}
229
230int manip_absvol::m_range_ext(trajestep& fts, int s_ext) const {
231 trajestep ts(fts);
232 up_absref(&ts);
233 absvol* avol = Gavol();
234 int s = avol->range_ext(ts, s_ext);
235 if (s == 1) {
236 down_absref(&ts);
237 fts = ts;
238 }
239 return s;
240}
241
242void manip_absvol::m_chname(char* nm) const {
243 strcpy(nm, "mvol->");
244 Gavol()->chname(&nm[6]);
245}
246
247void manip_absvol::m_print(std::ostream& file, int l) const {
248 if (l <= 0) return;
249 char s[1000];
250 m_chname(s);
251 Ifile << "manip_absvol::m_print(l=" << l << "): " << s << '\n';
252 --l;
253 if (l > 0) {
254 indn.n += 2;
255 const abssyscoor* asys = Gasc();
256 if (asys != NULL)
257 asys->print(file, l - 1);
258 else
259 mcout << "manip_absvol::m_print: system==NULL\n";
260 absvol* avol = Gavol();
261 if (avol != NULL)
262 avol->print(file, l - 1);
263 else
264 mcout << "manip_absvol::m_print: avol==NULL\n";
265 indn.n -= 2;
266 }
267 file.flush();
268
269}
270
272
273// ********* sh_manip_absvol *********
274void sh_manip_absvol::get_components(ActivePtr<absref_transmit>& aref_tran) {
275 aref_ptr[0] = &csys;
276 aref_tran.pass(new absref_transmit(1, aref_ptr));
277}
278
279const abssyscoor* sh_manip_absvol::Gasc(void) const { return &csys; }
280
283 : absref(f), manip_absvol(f), csys(f.csys) {}
285 : absref(f), manip_absvol(f), csys(f.csys) {}
287
289 const String& fname)
290 : csys(fc, fbas, fname) {}
291
292void sh_manip_absvol::m_chname(char* nm) const {
293 strcpy(nm, "mvol->");
294 Gavol()->chname(&nm[6]);
295}
296
298
299void sh_manip_absvol::m_print(std::ostream& file, int l) const {
300 if (l <= 0) return;
301 char s[1000];
302 m_chname(s);
303 Ifile << "sh_manip_absvol::m_print(l=" << l << "): " << s << '\n';
304 if (l > 1) {
305 indn.n += 2;
306 Ifile << "csys=" << noindent << csys;
307 absvol* avol = Gavol();
308 if (avol != NULL)
309 avol->print(file, l - 1);
310 else
311 mcout << "manip_absvol::m_print: avol==NULL\n";
312 indn.n -= 2;
313 }
314 file.flush();
315}
#define macro_copy_body_not_defined(type)
Definition: AbsPtr.h:299
#define mfunname(string)
Definition: FunNameStack.h:67
std::string String
Definition: String.h:75
long get_qel(void) const
Definition: AbsArr.h:420
Definition: vec.h:134
virtual void print(std::ostream &file, int l) const
Definition: vec.cpp:572
Definition: volume.h:91
virtual int find_embed_vol(const point &fpt, const vec &dir, manip_absvol_treeid *atid) const
Definition: volume.cpp:92
virtual int range_ext(trajestep &fts, int s_ext) const =0
virtual int check_point_inside(const point &fpt, const vec &dir) const =0
virtual DynLinArr< manip_absvol * > Gamanip_embed(void) const
Definition: volume.cpp:88
virtual int range(trajestep &fts, int s_ext, int &sb, manip_absvol_eid *faeid) const
Definition: volume.cpp:118
virtual void chname(char *nm) const
Definition: volume.h:143
virtual void print(std::ostream &file, int l) const
Definition: volume.cpp:144
Definition: vec.h:397
PassivePtr< manip_absvol > amvol
Definition: volume.h:39
void print(std::ostream &file, int l) const
Definition: volume.cpp:20
manip_absvol_eid(void)
Definition: volume.cpp:15
int check_manip_absvol_registered(manip_absvol *amvol)
Definition: volume.cpp:42
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 down_absref(absref *f)
Definition: volume.cpp:32
manip_absvol * G_lamvol() const
Definition: volume.h:58
void up_absref(absref *f)
Definition: volume.cpp:37
absvol * G_lavol() const
Definition: volume.cpp:28
int check_absvol_registered(absvol *avol)
Definition: volume.cpp:49
void down_absref(absref *f) const
Definition: volume.h:216
virtual const abssyscoor * Gasc(void) const
Definition: volume.h:198
void up_absref(absref *f) const
Definition: volume.h:220
virtual int m_range_ext(trajestep &fts, int s_ext) const
void m_chname(char *nm) const
virtual int m_check_point_inside(const point &fpt, const vec &dir) const
virtual absvol * Gavol(void) const =0
virtual int m_range(trajestep &fts, int s_ext, int &sb, manip_absvol_eid *faeid) const
virtual void m_print(std::ostream &file, int l) const
virtual int m_find_embed_vol(const point &fpt, const vec &fdir, manip_absvol_treeid *atid) const
Definition: vec.h:477
virtual void up(const abssyscoor *fasc)
Definition: vec.cpp:550
virtual const abssyscoor * Gasc(void) const
Definition: volume.cpp:279
absref * aref_ptr[1]
Definition: volume.h:241
virtual void m_chname(char *nm) const
Definition: volume.cpp:292
fixsyscoor csys
Definition: volume.h:233
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
sh_manip_absvol(void)
Definition: volume.cpp:281
virtual void m_print(std::ostream &file, int l) const
Definition: vec.h:248
void up(const basis *fabas_new)
Definition: vec.cpp:269
indentation indn
Definition: prstream.cpp:13
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:15
#define mcout
Definition: prstream.h:133
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
#define Imcout
Definition: prstream.h:208
int operator==(manip_absvol_treeid &tid1, manip_absvol_treeid &tid2)
Definition: volume.cpp:56
#define pqamvol
Definition: volume.h:27