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, int npar, int nchunk);
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  bool storeState(ostream &data) const {
164  data << endl;
165  bool res = egsStoreI64(data,Nread);
166  if (!res) {
167  return res;
168  }
169  data << " ";
170  res = egsStoreI64(data,Nfirst);
171  if (!res) {
172  return res;
173  }
174  data << " ";
175  res = egsStoreI64(data,Nlast);
176  if (!res) {
177  return res;
178  }
179  data << " ";
180  res = egsStoreI64(data,Npos);
181  if (!res) {
182  return res;
183  }
184  data << " ";
185  res = egsStoreI64(data,count);
186  if (!res) {
187  return res;
188  }
189  data << " ";
190  return res;
191  };
192  bool setState(istream &data) {
193  first = false;
194  bool res = egsGetI64(data,Nread);
195  if (!res) {
196  return res;
197  }
198  res = egsGetI64(data,Nfirst);
199  if (!res) {
200  return res;
201  }
202  res = egsGetI64(data,Nlast);
203  if (!res) {
204  return res;
205  }
206  res = egsGetI64(data,Npos);
207  if (!res) {
208  return res;
209  }
210  Npos++;
211  iaea_set_record(&iaea_fileid,&Npos,&iaea_iostat);
212  res = egsGetI64(data,count);
213  return res;
214  };
215  bool addState(istream &data) {
216  EGS_I64 tmp_Nread = Nread, tmp_count = count;
217  bool res = setState(data);
218  Nread += tmp_Nread;
219  count += tmp_count;
220  return res;
221  };
222  void resetCounter() {
223  Nread = 0;
224  count = 0;
225  };
226 
227  bool isValid() const {
228  return is_valid;
229  };
230 
231  void setCutout(EGS_Float xmin, EGS_Float xmax, EGS_Float ymin,
232  EGS_Float ymax) {
233  Xmin = xmin;
234  Xmax = xmax;
235  Ymin = ymin;
236  Ymax = ymax;
237  };
238  void setFilter(int, int, int, const int *);
239 
240  void containsDynamic(bool &hasdynamic);
241 
242 protected:
243 
244  bool is_valid;
245  string the_file_name;
246  bool mode2;
248  bool time_stored;
249  bool swap_bytes;
251  EGS_Float Emax,
253  EGS_I64 Nparticle,
261  int Nrestart;
264  int Nrecycle;
265  int Nuse;
270  int i_zlast;
271  int i_time;
272  int i_latch;
273 
274  bool first;
275 
276  // filters
277  int particle_type;
278  int filter_type;
279  unsigned long filter1, filter2;
280  EGS_Float Xmin, Xmax, Ymin, Ymax;
281  EGS_Float wmin, wmax; // weight window
282 
283  void openFile(const string &);
284  void init();
285 
286 #ifndef SKIP_DOXYGEN
287  struct EGS_LOCAL BeamParticle {
288  int latch, q;
289  float E, u, v, w, x, y, z, wt, zlast, time;
290  };
291  BeamParticle p;
292 #endif
293 
294  inline bool rejectParticle() const;
295 
296 };
297 
298 #endif
Base source class. All particle sources must be derived from this class.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
An object factory.
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:67
A class representing 3D vectors.
Definition: egs_vector.h:57
An IAEA phase-space file source.
EGS_I64 Npos
Next record to be read.
int Nrecycle_g
Number of times to recycle a photon.
string the_file_name
The phase-space file name.
EGS_I64 Nlast
Last record this source can use.
EGS_I64 Nphoton
Number of photons in the file.
int Nrestart
Number of times the file was restarted.
int i_latch
index of latch in extra_floats array
int Nuse
Number of times current particle was used so far.
EGS_I64 Nread
Number of particles read so far.
EGS_I64 Nfirst
first record this source can use
int Nrecycle
Number of times to recycle current particle.
bool time_stored
true if time index stored
int iaea_fileid
phsp file unit no.
int n_extra_floats
no. of extra floats stored in phsp file
int i_zlast
index of zlast in extra_floats array
int i_time
index of time index in extra_floats array
EGS_Float Pinc
Number of incident particles that created the file.
EGS_I64 Nparticle
Number of particles in the file.
bool mode2
true, if a MODE2 file (i.e. storing Zlast)
int n_extra_longs
no. of extra longs stored in phsp file
int Nrecycle_e
Number of times to recycle a charged particle.
bool latch_stored
true if LATCH is stored in data
EGS_Float Emax
Maximum k.e. (obtained from the phsp file)
int iaea_iostat
iostat on read/write of iaea phsp file
EGS_AliasTable class header file.
EGS_BaseSource class header file.
EGS_RandomGenerator class header file.
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,...
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,...