EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_point_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ point 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: Frederic Tessier
27 # Reid Townson
28 #
29 ###############################################################################
30 */
31 
32 
38 #ifndef EGS_POINT_SOURCE_
39 #define EGS_POINT_SOURCE_
40 
41 #include "egs_base_source.h"
42 #include "egs_vector.h"
43 #include "egs_rndm.h"
44 
45 
46 #ifdef WIN32
47 
48  #ifdef BUILD_POINT_SOURCE_DLL
49  #define EGS_POINT_SOURCE_EXPORT __declspec(dllexport)
50  #else
51  #define EGS_POINT_SOURCE_EXPORT __declspec(dllimport)
52  #endif
53  #define EGS_POINT_SOURCE_LOCAL
54 
55 #else
56 
57  #ifdef HAVE_VISIBILITY
58  #define EGS_POINT_SOURCE_EXPORT __attribute__ ((visibility ("default")))
59  #define EGS_POINT_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
60  #else
61  #define EGS_POINT_SOURCE_EXPORT
62  #define EGS_POINT_SOURCE_LOCAL
63  #endif
64 
65 #endif
66 
110 class EGS_POINT_SOURCE_EXPORT EGS_PointSource : public EGS_BaseSimpleSource {
111 
112  EGS_Vector xo;
113  bool valid;
114 
115 public:
116 
122  EGS_PointSource(int Q, EGS_BaseSpectrum *Spec, const EGS_Vector &Xo,
123  const string &Name="", EGS_ObjectFactory *f=0) :
124  EGS_BaseSimpleSource(Q,Spec,Name,f), xo(Xo), valid(true) {
125  setUp();
126  };
127 
133  ~EGS_PointSource() {};
134 
136  EGS_Vector &x, EGS_Vector &u, EGS_Float &wt) {
137  x = xo;
138  u.z = 2*rndm->getUniform()-1;
139  EGS_Float sinz = 1-u.z*u.z;
140  if (sinz > epsilon) {
141  sinz = sqrt(sinz);
142  EGS_Float cphi, sphi;
143  rndm->getAzimuth(cphi,sphi);
144  u.x = sinz*cphi;
145  u.y = sinz*sphi;
146  }
147  else {
148  u.x = 0;
149  u.y = 0;
150  }
151  wt = 1;
152  };
153 
154  EGS_Float getFluence() const {
155  return count;
156  };
157 
158  bool storeFluenceState(ostream &) const {
159  return true;
160  };
161 
162  bool setFluenceState(istream &) {
163  return true;
164  };
165 
166  bool isValid() const {
167  return (valid && s != 0);
168  };
169 
170 protected:
171 
173  void setUp();
174 
175 };
176 
177 #endif
virtual void getPositionDirection(EGS_RandomGenerator *rndm, EGS_Vector &x, EGS_Vector &u, EGS_Float &wt)=0
Sample a particle position and direction.
EGS_PointSource(int Q, EGS_BaseSpectrum *Spec, const EGS_Vector &Xo, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseSource class header file.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
EGS_Float y
y-component
Definition: egs_vector.h:61
A class representing 3D vectors.
Definition: egs_vector.h:56
void getAzimuth(EGS_Float &cphi, EGS_Float &sphi)
Sets cphi and sphi to the cosine and sine of a random angle uniformely distributed between 0 and ...
Definition: egs_rndm.h:138
EGS_I64 count
Number of statistically independent particles delivered so far.
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
EGS_Float z
z-component
Definition: egs_vector.h:62
EGS_RandomGenerator class header file.
A point source.
An object factory.
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Definition: egs_rndm.h:103
EGS_Float x
x-component
Definition: egs_vector.h:60
virtual bool storeFluenceState(ostream &data_out) const
Store the fluence state of this source to the data stream data_out.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:61
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 class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from th...
Base class for &#39;simple&#39; particle sources.
virtual bool isValid() const
Is this a valid source?
virtual bool setFluenceState(istream &data)
Set the data related to the sampling of positions and directions to a state contained in the stream d...