EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_beam_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ beam 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: Iwan Kawrakow, 2005
25 #
26 # Contributors: Ernesto Mainegra-Hing
27 # Frederic Tessier
28 # Reid Townson
29 # Blake Walters
30 #
31 ###############################################################################
32 */
33 
34 
40 #ifndef EGS_BEAM_SOURCE_
41 #define EGS_BEAM_SOURCE_
42 
43 #include "egs_vector.h"
44 #include "egs_base_source.h"
45 #include "egs_rndm.h"
46 #include "egs_functions.h"
47 
48 #include <fstream>
49 using namespace std;
50 
51 #ifdef WIN32
52 
53  #ifdef BUILD_BEAM_SOURCE_DLL
54  #define EGS_BEAM_SOURCE_EXPORT __declspec(dllexport)
55  #else
56  #define EGS_BEAM_SOURCE_EXPORT __declspec(dllimport)
57  #endif
58  #define EGS_BEAM_SOURCE_LOCAL
59 
60 #else
61 
62  #ifdef HAVE_VISIBILITY
63  #define EGS_BEAM_SOURCE_EXPORT __attribute__ ((visibility ("default")))
64  #define EGS_BEAM_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
65  #else
66  #define EGS_BEAM_SOURCE_EXPORT
67  #define EGS_BEAM_SOURCE_LOCAL
68  #endif
69 
70 #endif
71 
72 class EGS_Library;
73 typedef void (*InitFunction)(const int *, const int *, const int *,
74  const char *, const char *, const char *,
75  const char *, const char *, int,int,int,int,int);
76 typedef void (*FinishFunction)();
77 typedef void (*SampleFunction)(EGS_Float *, EGS_Float *, EGS_Float *,
78  EGS_Float *, EGS_Float *, EGS_Float *, EGS_Float *, EGS_Float *,
79  EGS_I32 *, EGS_I32 *, EGS_I64 *, EGS_I32 *);
80 typedef void (*MotionSampleFunction)(EGS_Float *, EGS_Float *, EGS_Float *,
81  EGS_Float *, EGS_Float *, EGS_Float *, EGS_Float *, EGS_Float *,
82  EGS_I32 *, EGS_I32 *, EGS_I64 *, EGS_I32 *, EGS_Float *);
83 typedef void (*MaxEnergyFunction)(EGS_Float *);
84 
140 class EGS_BEAM_SOURCE_EXPORT EGS_BeamSource : public EGS_BaseSource {
141 
142 public:
143 
146  ~EGS_BeamSource();
147 
148  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
149  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
150  EGS_Vector &x, EGS_Vector &u);
151  EGS_Float getEmax() const {
152  return Emax;
153  };
154  EGS_Float getFluence() const {
155  return count;
156  };
157  bool storeState(ostream &data) const {
158  return egsStoreI64(data,count);
159  };
160  bool setState(istream &data) {
161  return egsGetI64(data,count);
162  };
163  bool addState(istream &data) {
164  EGS_I64 tmp;
165  bool res = egsGetI64(data,tmp);
166  count += tmp;
167  return res;
168  };
169  void resetCounter() {
170  count = 0;
171  };
172 
173  bool isValid() const {
174  return is_valid;
175  };
176 
177  void setCutout(EGS_Float xmin, EGS_Float xmax, EGS_Float ymin,
178  EGS_Float ymax) {
179  Xmin = xmin;
180  Xmax = xmax;
181  Ymin = ymin;
182  Ymax = ymax;
183  };
184 
185  void containsDynamic(bool &hasdynamic);
186 
187 protected:
188 
190  FinishFunction finish;
192  SampleFunction sample;
193  MotionSampleFunction motionsample; //< Use this instead because we may want
194  //< to synchronize dynamic source with this
195 
196  bool is_valid;
197  bool time_stored;
198  string the_file_name;
199  ifstream the_file;
200  EGS_Float Emax;
201  EGS_Float time;
202  EGS_I64 count;
203 
204  // filters
205  int particle_type;
206  EGS_Float Xmin, Xmax, Ymin, Ymax;
207  EGS_Float wmin, wmax;
208 
209  // temporary particle storage
210  int q_save, latch_save;
211  EGS_Float E_save, wt_save, time_save;
212  EGS_Vector x_save, u_save;
213 
214  // reusing particles
215  int n_reuse_photon, n_reuse_electron;
216  int i_reuse_photon, i_reuse_electron;
217 
218  // stored info for first particle read in
219  // need this because we now query the data to see
220  // if time index is passed by the source
221  EGS_Float tei,txi,tyi,tzi,tui,tvi,twi,twti,ttimei;
222  int tqi,tlatchi,tiphati;
223  EGS_I64 counti;
224  bool use_iparticle; // true if we want to use the above data instead
225  // of calling motionsample
226 
227 };
228 
229 #endif
Base source class. All particle sources must be derived from this class.
A BEAM simulation source.
bool time_stored
true if time index stored
EGS_Library * lib
The BEAMnrc user code library.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
A class for dynamically loading shared libraries.
Definition: egs_library.h:52
An object factory.
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:90
A class representing 3D vectors.
Definition: egs_vector.h:57
EGS_BaseSource class header file.
Global egspp functions 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,...