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 
121 class EGS_ANGULAR_SPREAD_SOURCE_EXPORT EGS_AngularSpreadSource :
122  public EGS_BaseSource {
123 
124 public:
125 
128  EGS_Object::deleteObject(source);
129  };
130 
131  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
132  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
133  EGS_Vector &x, EGS_Vector &u) {
134  EGS_I64 c = source->getNextParticle(rndm,q,latch,E,wt,x,u);
135  //egsInformation("\nGot u=(%g,%g,%g)\n",u.x,u.y,u.z);
136  if (sigma > 0) {
137  EGS_Float cost;
138  do {
139  cost = 1 + sigma*log(1 - rndm->getUniform());
140  }
141  while (cost <= -1);
142  EGS_Float cphi, sphi;
143  rndm->getAzimuth(cphi,sphi);
144  EGS_Float sint = sqrt(1-cost*cost);
145  u.rotate(cost,sint,cphi,sphi);
146  //egsInformation("sampled cost=%g -> unew=(%g,%g,%g)\n",cost,u.x,u.y,u.z);
147  }
148  return c;
149  };
150  EGS_Float getEmax() const {
151  return source->getEmax();
152  };
153  EGS_Float getFluence() const {
154  return source->getFluence();
155  };
156  bool storeState(ostream &data) const {
157  return source->storeState(data);
158  };
159  bool setState(istream &data) {
160  return source->setState(data);
161  };
162  bool addState(istream &data_in) {
163  return source->addState(data_in);
164  };
165  void resetCounter() {
166  source->resetCounter();
167  };
168 
169  bool isValid() const {
170  return (source != 0);
171  };
172 
173 protected:
174 
176  EGS_Float sigma;
177 
178  void setUp();
179 
180 };
181 
182 #endif
A source that adds additional Gaussian angular spread to another source.
EGS_BaseSource * source
The source being transformed.
Base source class. All particle sources must be derived from this class.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
virtual void resetCounter()
Reset the source state.
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 bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
An object factory.
static void deleteObject(EGS_Object *o)
Delete an object.
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:90
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:161
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Definition: egs_rndm.h:126
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.