EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
iaea_phsp_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ IAEA format phase-space source headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Blake Walters, 2013
25 #
26 # Contributors: Reid Townson
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef IAEA_PHSP_SOURCE_
38 #define IAEA_PHSP_SOURCE_
39 
40 #define MAXEXTRAS 10
41 
42 #include "egs_vector.h"
43 #include "egs_base_source.h"
44 #include "egs_rndm.h"
45 #include "egs_alias_table.h"
46 
47 #include <fstream>
48 using namespace std;
49 
50 #ifdef WIN32
51 
52  #ifdef BUILD_IAEA_PHSP_SOURCE_DLL
53  #define IAEA_PHSP_SOURCE_EXPORT __declspec(dllexport)
54  #else
55  #define IAEA_PHSP_SOURCE_EXPORT __declspec(dllimport)
56  #endif
57  #define IAEA_PHSP_SOURCE_LOCAL
58 
59 #else
60 
61  #ifdef HAVE_VISIBILITY
62  #define IAEA_PHSP_SOURCE_EXPORT __attribute__ ((visibility ("default")))
63  #define IAEA_PHSP_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
64  #else
65  #define IAEA_PHSP_SOURCE_EXPORT
66  #define IAEA_PHSP_SOURCE_LOCAL
67  #endif
68 
69 #endif
70 
133 class IAEA_PHSP_SOURCE_EXPORT IAEA_PhspSource : public EGS_BaseSource {
134 
135 public:
136 
142  IAEA_PhspSource(const string &phsp_file,
143  const string &Name="", EGS_ObjectFactory *f=0);
144 
150  ~IAEA_PhspSource() { };
151 
152  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
153  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
154  EGS_Vector &x, EGS_Vector &u);
155  void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun);
156  EGS_Float getEmax() const {
157  return Emax;
158  };
159  EGS_Float getFluence() const {
160  double aux = ((double) Nread)/((double) Nparticle);
161  return Pinc*aux;
162  };
163  EGS_Float getMu() {
164  if (mu_stored) {
165  return p.mu;
166  }
167  else {
168  return -1.0;
169  }
170  };
171  bool storeState(ostream &data) const {
172  data << endl;
173  bool res = egsStoreI64(data,Nread);
174  if (!res) {
175  return res;
176  }
177  data << " ";
178  res = egsStoreI64(data,Nfirst);
179  if (!res) {
180  return res;
181  }
182  data << " ";
183  res = egsStoreI64(data,Nlast);
184  if (!res) {
185  return res;
186  }
187  data << " ";
188  res = egsStoreI64(data,Npos);
189  if (!res) {
190  return res;
191  }
192  data << " ";
193  res = egsStoreI64(data,count);
194  if (!res) {
195  return res;
196  }
197  data << " ";
198  return res;
199  };
200  bool setState(istream &data) {
201  first = false;
202  bool res = egsGetI64(data,Nread);
203  if (!res) {
204  return res;
205  }
206  res = egsGetI64(data,Nfirst);
207  if (!res) {
208  return res;
209  }
210  res = egsGetI64(data,Nlast);
211  if (!res) {
212  return res;
213  }
214  res = egsGetI64(data,Npos);
215  if (!res) {
216  return res;
217  }
218  Npos++;
219  iaea_set_record(&iaea_fileid,&Npos,&iaea_iostat);
220  res = egsGetI64(data,count);
221  return res;
222  };
223  bool addState(istream &data) {
224  EGS_I64 tmp_Nread = Nread, tmp_count = count;
225  bool res = setState(data);
226  Nread += tmp_Nread;
227  count += tmp_count;
228  return res;
229  };
230  void resetCounter() {
231  Nread = 0;
232  count = 0;
233  };
234 
235  bool isValid() const {
236  return is_valid;
237  };
238 
239  void setCutout(EGS_Float xmin, EGS_Float xmax, EGS_Float ymin,
240  EGS_Float ymax) {
241  Xmin = xmin;
242  Xmax = xmax;
243  Ymin = ymin;
244  Ymax = ymax;
245  };
246  void setFilter(int, int, int, const int *);
247 
248 protected:
249 
250  bool is_valid;
251  string the_file_name;
252  bool mode2;
254  bool mu_stored;
255  bool swap_bytes;
257  EGS_Float Emax,
258  Pinc;
259  EGS_I64 Nparticle,
260  Nphoton,
261  Nread,
262  Npos,
263  Nfirst,
264  Nlast,
265  count;
267  int Nrestart;
270  int Nrecycle;
271  int Nuse;
276  int i_zlast;
277  int i_mu;
278  int i_latch;
279 
280  bool first;
281 
282  // filters
283  int particle_type;
284  int filter_type;
285  unsigned long filter1, filter2;
286  EGS_Float Xmin, Xmax, Ymin, Ymax;
287  EGS_Float wmin, wmax; // weight window
288 
289  void openFile(const string &);
290  void init();
291 
292 #ifndef SKIP_DOXYGEN
293  struct EGS_LOCAL BeamParticle {
294  int latch, q;
295  float E, u, v, w, x, y, z, wt, zlast, mu;
296  };
297  BeamParticle p;
298 #endif
299 
300  inline bool rejectParticle() const;
301 
302 };
303 
304 #endif
EGS_I64 Nread
Number of particles read so far.
int n_extra_floats
no. of extra floats stored in phsp file
bool EGS_EXPORT egsGetI64(istream &data, EGS_I64 &n)
Reads a 64 bit integer from the stream data and assigns it to n. Returns true on success, false on failure.
int i_zlast
index of zlast in extra_floats array
int i_mu
index of mu index in extra_floats array
bool mode2
true, if a MODE2 file (i.e. storing Zlast)
EGS_AliasTable class header file.
EGS_BaseSource class header file.
int Nrecycle_e
Number of times to recycle a charged particle.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
bool EGS_EXPORT egsStoreI64(ostream &data, EGS_I64 n)
Writes the 64 bit integer n to the output stream data and returns true on success, false on failure.
A class representing 3D vectors.
Definition: egs_vector.h:56
int Nrestart
Number of times the file was restarted.
int iaea_iostat
iostat on read/write of iaea phsp file
int Nuse
Number of times current particle was used so far.
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
EGS_RandomGenerator class header file.
An object factory.
EGS_Float Pinc
Number of incident particles that created the file.
An IAEA phase-space file source.
int iaea_fileid
phsp file unit no.
int i_latch
index of latch in extra_floats array
bool mu_stored
true if mu index stored
string the_file_name
The phase-space file name.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
int Nrecycle_g
Number of times to recycle a photon.
bool latch_stored
true if LATCH is stored in data
int Nrecycle
Number of times to recycle current particle.
Base source class. All particle sources must be derived from this class.
int n_extra_longs
no. of extra longs stored in phsp file