EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_angular_spread_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ angular spread 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, 2009
25 #
26 # Contributors: Reid Townson
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_ANGULAR_SPREAD_SOURCE_
38 #define EGS_ANGULAR_SPREAD_SOURCE_
39 
40 #include "egs_vector.h"
41 #include "egs_base_source.h"
42 #include "egs_rndm.h"
43 #include "egs_functions.h"
44 
45 
46 #ifdef WIN32
47 
48  #ifdef BUILD_ANGULAR_SPREAD_SOURCE_DLL
49  #define EGS_ANGULAR_SPREAD_SOURCE_EXPORT __declspec(dllexport)
50  #else
51  #define EGS_ANGULAR_SPREAD_SOURCE_EXPORT __declspec(dllimport)
52  #endif
53  #define EGS_ANGULAR_SPREAD_SOURCE_LOCAL
54 
55 #else
56 
57  #ifdef HAVE_VISIBILITY
58  #define EGS_ANGULAR_SPREAD_SOURCE_EXPORT __attribute__ ((visibility ("default")))
59  #define EGS_ANGULAR_SPREAD_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
60  #else
61  #define EGS_ANGULAR_SPREAD_SOURCE_EXPORT
62  #define EGS_ANGULAR_SPREAD_SOURCE_LOCAL
63  #endif
64 
65 #endif
66 
119 class EGS_ANGULAR_SPREAD_SOURCE_EXPORT EGS_AngularSpreadSource :
120  public EGS_BaseSource {
121 
122 public:
123 
126  EGS_Object::deleteObject(source);
127  };
128 
129  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
130  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
131  EGS_Vector &x, EGS_Vector &u) {
132  EGS_I64 c = source->getNextParticle(rndm,q,latch,E,wt,x,u);
133  //egsInformation("\nGot u=(%g,%g,%g)\n",u.x,u.y,u.z);
134  if (sigma > 0) {
135  EGS_Float cost;
136  do {
137  cost = 1 + sigma*log(1 - rndm->getUniform());
138  }
139  while (cost <= -1);
140  EGS_Float cphi, sphi;
141  rndm->getAzimuth(cphi,sphi);
142  EGS_Float sint = sqrt(1-cost*cost);
143  u.rotate(cost,sint,cphi,sphi);
144  //egsInformation("sampled cost=%g -> unew=(%g,%g,%g)\n",cost,u.x,u.y,u.z);
145  }
146  return c;
147  };
148  EGS_Float getEmax() const {
149  return source->getEmax();
150  };
151  EGS_Float getFluence() const {
152  return source->getFluence();
153  };
154  bool storeState(ostream &data) const {
155  return source->storeState(data);
156  };
157  bool setState(istream &data) {
158  return source->setState(data);
159  };
160  bool addState(istream &data_in) {
161  return source->addState(data_in);
162  };
163  void resetCounter() {
164  source->resetCounter();
165  };
166 
167  bool isValid() const {
168  return (source != 0);
169  };
170 
171 protected:
172 
173  EGS_BaseSource *source;
174  EGS_Float sigma;
175 
176  void setUp();
177 
178 };
179 
180 #endif
EGS_BaseSource class header file.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
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
Global egspp functions header file.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
static void deleteObject(EGS_Object *o)
Delete an object.
virtual void resetCounter()
Reset the source state.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
A source that adds additional Gaussian angular spread to another source.
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
EGS_RandomGenerator class header file.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
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
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
virtual EGS_I64 getNextParticle(EGS_RandomGenerator *rndm, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)=0
Sample the next source particle from the source probability distribution.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
Base source class. All particle sources must be derived from this class.