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