EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EGS_BaseSpectrum Class Referenceabstract

Base class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from this class. More...

#include <egs_base_source.h>

Inheritance diagram for EGS_BaseSpectrum:
EGS_DoubleGaussianSpectrum EGS_GaussianSpectrum EGS_MonoEnergy EGS_RadionuclideSpectrum EGS_TabulatedSpectrum EGS_UniformSpectrum

Public Member Functions

 EGS_BaseSpectrum ()
 Constructor. More...
 
virtual ~EGS_BaseSpectrum ()
 Destructor. Does nothing.
 
const string & getType () const
 Get the spectrum type. More...
 
EGS_Float sampleEnergy (EGS_RandomGenerator *rndm)
 Sample a particle energy. More...
 
virtual EGS_Float maxEnergy () const =0
 Get the maximum energy of this spectrum. More...
 
virtual EGS_Float expectedAverage () const =0
 Get the average energy of the spectrum. More...
 
virtual bool storeState (ostream &data_out) const
 Store the state of the spectrum object into the stream data_out. More...
 
virtual bool setState (istream &data_in)
 Set the state of the spectrum object from the data in the stream data_in. More...
 
virtual bool addState (istream &data_in)
 Add to the state of this object the data from the stream data_in. More...
 
virtual void resetCounter ()
 Reset the state of this spectrum object. More...
 
void getSampledAverage (EGS_Float &e, EGS_Float &de) const
 Get the average sampled energy and its statistical uncertainty. More...
 
void reportAverageEnergy () const
 Report the average energy (expected and actually sampled). More...
 

Static Public Member Functions

static EGS_BaseSpectrumcreateSpectrum (EGS_Input *inp)
 Create and return a pointer to a spectrum object from the information pointed to by inp. More...
 

Protected Member Functions

virtual EGS_Float sample (EGS_RandomGenerator *rndm)=0
 Sample an energy from the spectrum energy distribution. More...
 

Protected Attributes

EGS_I64 count
 Number of times the sampleEnergy() method was called.
 
double sum_E
 Sum of energies sampled so far.
 
double sum_E2
 Sum of energies squared sampled so far.
 
string type
 A short string describing the spectrum that must be set by derived classes.
 

Detailed Description

Base class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from this class.

Objects derived from this class are used as the particle spectrum in sources derived from EGS_BaseSimpleSource. The following spectra are available: a monoenergetic spectrum, a Gaussian spectrum, a double-Gaussian spectrum, a uniform spectrum and a tabulated spectrum. a radionuclide spectrum.

Examples:
sources/egs_point_source/egs_point_source.cpp.

Definition at line 334 of file egs_base_source.h.

Constructor & Destructor Documentation

EGS_BaseSpectrum::EGS_BaseSpectrum ( )

Constructor.

Initializes the counters counters count, sum_E and sum_E2 to zero and sets the spectrum description string type to 'Unknown spectrum'.

Definition at line 343 of file egs_base_source.h.

Member Function Documentation

const string& EGS_BaseSpectrum::getType ( ) const

Get the spectrum type.

Returns a reference to the protected data member type, which should be set to a short string describing the type of the spectrum by derived classes.

Examples:
sources/egs_point_source/egs_point_source.cpp.

Definition at line 355 of file egs_base_source.h.

Referenced by EGS_PointSource::setUp().

EGS_Float EGS_BaseSpectrum::sampleEnergy ( EGS_RandomGenerator rndm)

Sample a particle energy.

This method uses the random number generator rndm and the protected virtual method sample() to sample and return a particle energy. It also updates the counters count, sum_E and sum_E2.

Definition at line 365 of file egs_base_source.h.

virtual EGS_Float EGS_BaseSpectrum::maxEnergy ( ) const
pure virtual

Get the maximum energy of this spectrum.

This pure virtual method must be reimplemented by derived classes to return the maximum spectrum energy.

Implemented in EGS_RadionuclideSpectrum.

virtual EGS_Float EGS_BaseSpectrum::expectedAverage ( ) const
pure virtual

Get the average energy of the spectrum.

This pure virtual method must be reimplemented by derived classes to return the expected average energy of the spectrum.

Implemented in EGS_RadionuclideSpectrum.

virtual bool EGS_BaseSpectrum::storeState ( ostream &  data_out) const
virtual

Store the state of the spectrum object into the stream data_out.

The default implementation of this method stores the counters count, sum_E and sum_E2 and returns true, if the operation succeeded, false otherwise. Derived spectrum classes may add additional information to the stream, if needed.

storeState(), setState(), addState() and resetCounter() are needed for restarted calculations and for combining the results of parallel runs.

Definition at line 399 of file egs_base_source.h.

References egsStoreI64().

virtual bool EGS_BaseSpectrum::setState ( istream &  data_in)
virtual

Set the state of the spectrum object from the data in the stream data_in.

The default implementation of this method is to read the data stored using storeState() (i.e. count, sum_E and sum_E2) and to return true, if the operation succeeded, false otherwise. Derived spectrum classes should re-implement this method if they are storing additional data in the storeState() method.

storeState(), setState(), addState() and resetCounter() are needed for restarted calculations and for combining the results of parallel runs.

Definition at line 423 of file egs_base_source.h.

References egsGetI64().

virtual bool EGS_BaseSpectrum::addState ( istream &  data_in)
virtual

Add to the state of this object the data from the stream data_in.

The default implementation of this method adds to count, sum_E and sum_E2 the corresponding data read from the data_in. Derived spectrum classes should re-implement this method if they are storing extra information using storeState().

storeState(), setState(), addState() and resetCounter() are needed for restarted calculations and for combining the results of parallel runs.

Definition at line 446 of file egs_base_source.h.

virtual void EGS_BaseSpectrum::resetCounter ( )
virtual

Reset the state of this spectrum object.

The default implementation of this method sets count, sum_E and sum_E2 to zero. It should be re-implemented by derived classes if additional data is needed to describe the state of the spectrum object to reset this data as well.

storeState(), setState(), addState() and resetCounter() are needed for restarted calculations and for combining the results of parallel runs.

Definition at line 469 of file egs_base_source.h.

EGS_BaseSpectrum * EGS_BaseSpectrum::createSpectrum ( EGS_Input inp)
static

Create and return a pointer to a spectrum object from the information pointed to by inp.

This static method looks for a property named spectrum in the input tree pointed to by inp and if such property exists, creates a spectrum object according to the information it contains. Otherwise null is returned. The spectrum property must define the spectrum type using a
type = type of the spectrum
key-value pair and has enough information needed by the spectrum type being constructed.

Definition at line 1740 of file egs_spectra.cpp.

References EGS_Application::activeApplication(), EGS_Input::compare(), egsExpandPath(), egsFatal, egsInformation, egsJoinPath(), egsWarning, EGS_Application::getHenHouse(), EGS_Input::getInput(), EGS_Input::isA(), and EGS_Input::takeInputItem().

Referenced by EGS_BaseSimpleSource::EGS_BaseSimpleSource(), and EGS_RadionuclideSource::EGS_RadionuclideSource().

void EGS_BaseSpectrum::getSampledAverage ( EGS_Float &  e,
EGS_Float &  de 
) const

Get the average sampled energy and its statistical uncertainty.

This function assigns the average energy sampled so far to e and its statistical uncertainty to de.

Definition at line 495 of file egs_base_source.h.

void EGS_BaseSpectrum::reportAverageEnergy ( ) const

Report the average energy (expected and actually sampled).

This function prints information about the expected and actually sampled average energy of the spectrum using egsInformation().

Definition at line 64 of file egs_spectra.cpp.

References egsInformation.

virtual EGS_Float EGS_BaseSpectrum::sample ( EGS_RandomGenerator rndm)
protectedpure virtual

Sample an energy from the spectrum energy distribution.

This pure virtual method must be implemented by derived classes to sample and return a particle energy using the random number generator rndm.

Implemented in EGS_RadionuclideSpectrum.


The documentation for this class was generated from the following files: