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 
138 class EGS_BEAM_SOURCE_EXPORT EGS_BeamSource : public EGS_BaseSource {
139 
140 public:
141 
144  ~EGS_BeamSource();
145 
146  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
147  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
148  EGS_Vector &x, EGS_Vector &u);
149  EGS_Float getEmax() const {
150  return Emax;
151  };
152  EGS_Float getFluence() const {
153  return count;
154  };
155  bool storeState(ostream &data) const {
156  return egsStoreI64(data,count);
157  };
158  bool setState(istream &data) {
159  return egsGetI64(data,count);
160  };
161  bool addState(istream &data) {
162  EGS_I64 tmp;
163  bool res = egsGetI64(data,tmp);
164  count += tmp;
165  return res;
166  };
167  void resetCounter() {
168  count = 0;
169  };
170 
171  bool isValid() const {
172  return is_valid;
173  };
174 
175  void setCutout(EGS_Float xmin, EGS_Float xmax, EGS_Float ymin,
176  EGS_Float ymax) {
177  Xmin = xmin;
178  Xmax = xmax;
179  Ymin = ymin;
180  Ymax = ymax;
181  };
182 
183  void containsDynamic(bool &hasdynamic);
184 
185 protected:
186 
188  FinishFunction finish;
190  SampleFunction sample;
191  MotionSampleFunction motionsample; //< Use this instead because we may want
192  //< to synchronize dynamic source with this
193 
194  bool is_valid;
195  bool time_stored;
196  string the_file_name;
197  ifstream the_file;
198  EGS_Float Emax;
199  EGS_Float time;
200  EGS_I64 count;
201 
202  // filters
203  int particle_type;
204  EGS_Float Xmin, Xmax, Ymin, Ymax;
205  EGS_Float wmin, wmax;
206 
207  // temporary particle storage
208  int q_save, latch_save;
209  EGS_Float E_save, wt_save, time_save;
210  EGS_Vector x_save, u_save;
211 
212  // reusing particles
213  int n_reuse_photon, n_reuse_electron;
214  int i_reuse_photon, i_reuse_electron;
215 
216  // stored info for first particle read in
217  // need this because we now query the data to see
218  // if time index is passed by the source
219  EGS_Float tei,txi,tyi,tzi,tui,tvi,twi,twti,ttimei;
220  int tqi,tlatchi,tiphati;
221  EGS_I64 counti;
222  bool use_iparticle; // true if we want to use the above data instead
223  // of calling motionsample
224 
225 };
226 
227 #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:67
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,...