Skip to content

Commit

Permalink
Modified the store/add/set/reset state functions
Browse files Browse the repository at this point in the history
Included proper sCount and baseSource() state setting, storing, and resetting.  Modified addState so that sCount and count are added to, rather than set to the read in values.
  • Loading branch information
MartinMartinov authored and ftessier committed Jul 11, 2022
1 parent b3b95e7 commit e715e5b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# Author: Reid Townson, 2016
#
# Contributors: Martin Martinov, 2021
# Contributors:
#
###############################################################################
*/
Expand All @@ -41,16 +41,16 @@

EGS_RadionuclideSource::EGS_RadionuclideSource(EGS_Input *input,
EGS_ObjectFactory *f) : EGS_BaseSource(input,f),
baseSource(0), q_allowed(0), decays(0), activity(1), sCount (0) {
baseSource(0), q_allowed(0), decays(0), activity(1) {

int err;
vector<int> tmp_q;
err = input->getInput("charge", tmp_q);
if (!err) {
if (std::find(q_allowed.begin(), q_allowed.end(), -1) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 0) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 1) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 2) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 0) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 1) != q_allowed.end()
&& std::find(q_allowed.begin(), q_allowed.end(), 2) != q_allowed.end()
) {
q_allowAll = true;
}
Expand All @@ -69,6 +69,7 @@ EGS_RadionuclideSource::EGS_RadionuclideSource(EGS_Input *input,

// Create the decay spectra
count = 0;
sCount = 0;
Emax = 0;
unsigned int i = 0;
EGS_Float spectrumWeightTotal = 0;
Expand Down Expand Up @@ -159,7 +160,7 @@ EGS_RadionuclideSource::EGS_RadionuclideSource(EGS_Input *input,
egsWarning("EGS_RadionuclideSource: no source named %s"
" is defined\n",sName.c_str());
}

// Initialize emission type to signify nothing has happened yet
emissionType = 99;

Expand Down Expand Up @@ -218,7 +219,6 @@ EGS_I64 EGS_RadionuclideSource::getNextParticle(EGS_RandomGenerator *rndm, int
}

q = decays[i]->getCharge();

int qTemp (q), latchTemp (latch);
EGS_Float ETemp (E);
baseSource->getNextParticle(rndm, qTemp, latchTemp, ETemp, wt, x, u);
Expand Down Expand Up @@ -297,6 +297,7 @@ bool EGS_RadionuclideSource::storeState(ostream &data_out) const {
}
}
egsStoreI64(data_out,count);
egsStoreI64(data_out,sCount);
baseSource->storeState(data_out);

return true;
Expand All @@ -311,7 +312,9 @@ bool EGS_RadionuclideSource::addState(istream &data) {
}
EGS_I64 tmp_val;
egsGetI64(data,tmp_val);
count = tmp_val;
count += tmp_val;
egsGetI64(data,tmp_val);
sCount += tmp_val;
baseSource->addState(data);

return true;
Expand All @@ -324,6 +327,7 @@ void EGS_RadionuclideSource::resetCounter() {
ishower = 0;
count = 0;
sCount = 0;
baseSource->resetCounter();
}

bool EGS_RadionuclideSource::setState(istream &data) {
Expand All @@ -333,6 +337,7 @@ bool EGS_RadionuclideSource::setState(istream &data) {
}
}
egsGetI64(data,count);
egsGetI64(data,sCount);
baseSource->setState(data);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# Author: Reid Townson, 2016
#
# Contributors: Martin Martinov, 2021
# Contributors:
#
###############################################################################
*/
Expand Down Expand Up @@ -137,19 +137,20 @@ on the number of disintegration events (tracked by <b> \c ishower </b>). This
is distinct from the <b> \c ncase </b> input parameter, which is the
number of particles returned by the source (includes relaxations etc.).
A radionuclide source is defined using the following input. It imports a base
source and uses the base source getNextParticle() invocation to determine decay
location. This implementation leads to increased random number sampling than
that strictly required in the simulation, due to the information generated in
the base source beyond particle position that is not used in
egs_radionuclide_source. Thus, its probably best, though not required, that
the base source use a monoenergetic spectrum to avoid oversampling.
A radionuclide source is defined using the following input. Notice that the
format is similar to \ref EGS_IsotropicSource or \ref EGS_CollimatedSource.
Be <b>careful using a collimated source</b> - it may neglect effects from the physical
source on the spectrum, and neglect potential contributions from surrounding
structures. Restricting the emission angles by collimation generally constitutes
a physical approximation of your geometry and is an approximate efficiency
enhancement technique. It is also important to note that the collimated source
determines the fluence with \f$N/d^2\f$, where \c N is the number of
disintegrations sampled and \c d is the user-defined minimum distance between the
source and target shapes.
\verbatim
:start source:
name = my_mixture
library = egs_radionuclide_source
base source = name of the source used to generate decay locations
activity = [optional, default=1] total activity of mixture,
assumed constant. The activity only affects the
emission times assigned to particles.
Expand All @@ -164,6 +165,26 @@ the base source use a monoenergetic spectrum to avoid oversampling.
set to 0 for no time limit. Source particles generated
after the experiment time are not transported.
# If source type = isotropic
geometry = [optional] my_geometry # see egs_isotropic_source
region selection = [optional] geometry confinement option
one of IncludeAll, ExcludeAll,
IncludeSelected, ExcludeSelected
selected regions = [required for IncludeSelected, ExcludeSelected]
regions to apply geometry confinement
:start shape:
definition of the isotropic source shape
:stop shape:
# If source type = collimated (beware of its limitations)
:start source shape:
definition of the source shape
:stop source shape:
:start target shape:
definition of the target shape
:stop target shape:
distance = source-target shape min. distance
:start spectrum:
definition of an EGS_RadionuclideSpectrum (see link below)
:stop spectrum:
Expand Down Expand Up @@ -234,8 +255,9 @@ results for non-disintegration emissions.
:stop geometry definition:
:start source definition:
:start source:
name = source_location
library = egs_isotropic_source
name = my_source
library = egs_radionuclide_source
activity = 28e6
geometry = my_envelope
region selection = IncludeSelected
selected regions = 1 2
Expand All @@ -246,17 +268,6 @@ results for non-disintegration emissions.
media = H2O521ICRU
:stop media input:
:stop shape:
:start spectrum:
type = monoenergetic # Input is ignored
energy = 1.0 # Input is ignored
:stop spectrum:
:stop source:
:start source:
name = my_source
library = egs_radionuclide_source
base source = source_location
activity = 28e6
:start spectrum:
type = radionuclide
nuclide = Ir-192
Expand All @@ -272,30 +283,28 @@ class EGS_RADIONUCLIDE_SOURCE_EXPORT EGS_RadionuclideSource :
public EGS_BaseSource {

public:

/*! \brief Constructor from input file */
EGS_RadionuclideSource(EGS_Input *, EGS_ObjectFactory *f=0);

/*! \brief Destructor */
~EGS_RadionuclideSource() {
if (baseSource)
if (baseSource)
if (!baseSource->deref()) {
delete baseSource;
}

for (vector<EGS_RadionuclideSpectrum * >::iterator it =
decays.begin();
it!=decays.end(); it++) {
delete *it;
*it=0;
}
decays.clear();
for (vector<EGS_RadionuclideSpectrum * >::iterator it =
decays.begin(); it!=decays.end(); it++) {
delete *it;
*it=0;
}
decays.clear();
};

/*! \brief Gets the next particle from the radionuclide spectra */
EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
int &q, int &latch, EGS_Float &E, EGS_Float &wt,
EGS_Vector &x, EGS_Vector &u);
EGS_Vector &x, EGS_Vector &u);

/*! \brief Returns the maximum energy out of all the spectra */
EGS_Float getEmax() const {
Expand All @@ -304,7 +313,8 @@ class EGS_RADIONUCLIDE_SOURCE_EXPORT EGS_RadionuclideSource :

/*! \brief Returns the current fluence (number of disintegrations) */
EGS_Float getFluence() const {
return (ishower+1)*(baseSource->getFluence()/sCount); //!< Scale ishower+1 return by fluence ratio returned by file
return (ishower+1)*(baseSource->getFluence()/sCount);
//!< Scale ishower+1 return by fluence ratio returned by file
};

/*! \brief Returns the emission time of the most recent particle */
Expand Down

0 comments on commit e715e5b

Please sign in to comment.