EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_collimated_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ collimated 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 # Reid Townson
28 # Hubert Ho
29 # Reid Townson
30 #
31 ###############################################################################
32 */
33 
34 
40 #ifndef EGS_COLLIMATED_SOURCE_
41 #define EGS_COLLIMATED_SOURCE_
42 
43 #include "egs_vector.h"
44 #include "egs_base_source.h"
45 #include "egs_rndm.h"
46 #include "egs_shapes.h"
47 #include "egs_functions.h"
48 
49 
50 #ifdef WIN32
51 
52  #ifdef BUILD_COLLIMATED_SOURCE_DLL
53  #define EGS_COLLIMATED_SOURCE_EXPORT __declspec(dllexport)
54  #else
55  #define EGS_COLLIMATED_SOURCE_EXPORT __declspec(dllimport)
56  #endif
57  #define EGS_COLLIMATED_SOURCE_LOCAL
58 
59 #else
60 
61  #ifdef HAVE_VISIBILITY
62  #define EGS_COLLIMATED_SOURCE_EXPORT __attribute__ ((visibility ("default")))
63  #define EGS_COLLIMATED_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
64  #else
65  #define EGS_COLLIMATED_SOURCE_EXPORT
66  #define EGS_COLLIMATED_SOURCE_LOCAL
67  #endif
68 
69 #endif
70 
160 class EGS_COLLIMATED_SOURCE_EXPORT EGS_CollimatedSource :
161  public EGS_BaseSimpleSource {
162 
163 public:
164 
171  EGS_BaseShape *sshape, EGS_BaseShape *tshape,
172  const string &Name="", EGS_ObjectFactory *f=0) :
173  EGS_BaseSimpleSource(Q,Spec,Name,f), source_shape(sshape),
174  target_shape(tshape), ctry(0), dist(1) {
175  setUp();
176  };
177 
184  EGS_Object::deleteObject(source_shape);
185  EGS_Object::deleteObject(target_shape);
186  };
187 
189  EGS_Vector &x, EGS_Vector &u, EGS_Float &wt) {
190  //x = source_shape->getPoint(rndm);
191  x = source_shape->getRandomPoint(rndm);
192  int ntry = 0;
193  do {
194  target_shape->getPointSourceDirection(x,rndm,u,wt);
195  ntry++;
196  if (ntry > 10000)
197  egsFatal("EGS_CollimatedSource::getPositionDirection:\n"
198  " my target shape %s, which is of type %s, failed to\n"
199  " return a positive weight after 10000 attempts\n",
200  target_shape->getObjectName().c_str(),
201  target_shape->getObjectType().c_str());
202  }
203  while (wt <= 0);
204  //egsInformation("got x=(%g,%g,%g) u=(%g,%g,%g) wt = %g ntry = %d\n",
205  // x.x,x.y,x.z,u.x,u.y,u.z,wt,ntry);
206  ctry += ntry;
207  };
208 
209  EGS_Float getFluence() const {
210  double res = ctry;
211  return res/(dist*dist);
212  };
213 
214  bool storeFluenceState(ostream &data) const {
215  return egsStoreI64(data,ctry);
216  };
217 
218  bool setFluenceState(istream &data) {
219  return egsGetI64(data,ctry);
220  };
221 
222  bool addFluenceData(istream &data) {
223  EGS_I64 tmp;
224  bool ok = egsGetI64(data,tmp);
225  if (!ok) {
226  return false;
227  }
228  ctry += tmp;
229  return true;
230  };
231 
232  bool isValid() const {
233  return (s != 0 && source_shape != 0 && target_shape != 0 &&
234  target_shape->supportsDirectionMethod());
235  };
236 
237  void resetFluenceCounter() {
238  ctry = 0;
239  };
240 
241 protected:
242 
245  EGS_I64 ctry;
246  EGS_Float dist;
247 
248  void setUp();
249 
250 };
251 
252 #endif
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:114
Base class for 'simple' particle sources.
virtual bool addFluenceData(istream &data)
Add fluence data from the stream data to the current state.
virtual void getPositionDirection(EGS_RandomGenerator *rndm, EGS_Vector &x, EGS_Vector &u, EGS_Float &wt)=0
Sample a particle position and direction.
virtual bool isValid() const
Is this a valid source?
virtual void resetFluenceCounter()
Reset the data related to the sampling of positions and directions to a state with zero sampled parti...
virtual bool storeFluenceState(ostream &data_out) const
Store the fluence state of this source to the data stream data_out.
virtual bool setFluenceState(istream &data)
Set the data related to the sampling of positions and directions to a state contained in the stream d...
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
Base class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from th...
A collimated particle source.
EGS_I64 ctry
number of attempts to sample a particle
EGS_Float dist
source-target shape min. distance
EGS_CollimatedSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *sshape, EGS_BaseShape *tshape, const string &Name="", EGS_ObjectFactory *f=0)
EGS_BaseShape * source_shape
the source shape
EGS_BaseShape * target_shape
the target shape
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: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_BaseShape and shape classes 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,...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
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,...