43 #ifndef EGS_BASE_SOURCE_
44 #define EGS_BASE_SOURCE_
61 static shared_ptr<EGS_BlockInput> srcBlockInput = make_shared<EGS_BlockInput>(
"source");
62 inline void setBaseSourceInputs(
bool isSimpleSource =
true,
bool includeSpectrumBlock =
true) {
63 srcBlockInput->addSingleInput(
"library",
true,
"The type of source, loaded by shared library in egs++/dso.");
64 srcBlockInput->addSingleInput(
"name",
true,
"The user-declared unique name of this source. This is the name you may refer to elsewhere in the input file");
67 includeSpectrumBlock =
true;
68 srcBlockInput->addSingleInput(
"charge",
true,
"The type of particle to emit from the source, as defined by the charge. Use 0 for photons, -1 for electrons and 1 for positrons.", {
"0",
"1",
"-1"});
70 if (includeSpectrumBlock) {
71 shared_ptr<EGS_BlockInput> specBlock = srcBlockInput->addBlockInput(
"spectrum");
72 auto typePtr = specBlock->addSingleInput(
"type",
true,
"The type of energy distribution for the spectrum.", {
"monoenergetic",
"Gaussian",
"Double Gaussian",
"uniform",
"tabulated spectrum",
"radionuclide"});
75 specBlock->addSingleInput(
"energy",
false,
"The kinetic energy of the source particles in MeV.")->addDependency(typePtr,
"monoenergetic");
78 specBlock->addSingleInput(
"mean energy",
false,
"The mean kinetic energy of the source particles in MeV.")->addDependency(typePtr,
"Gaussian");
79 auto sigmaPtr = specBlock->addSingleInput(
"sigma",
false,
"The sigma of the spectrum. For a double Gaussian, input two values.");
80 sigmaPtr->addDependency(typePtr,
"Gaussian");
81 sigmaPtr->addDependency(typePtr,
"Double Gaussian");
82 auto fwhmPtr = specBlock->addSingleInput(
"fwhm",
false,
"The full-width-at-half-maximum of the spectrum. For a double Gaussian, input two values.");
83 fwhmPtr->addDependency(typePtr,
"Gaussian");
84 fwhmPtr->addDependency(typePtr,
"Double Gaussian");
85 fwhmPtr->addDependency(sigmaPtr,
"",
true);
86 sigmaPtr->addDependency(fwhmPtr,
"",
true);
89 auto rangePtr = specBlock->addSingleInput(
"range",
false,
"The minimum and maximum energy for the spectrum, in MeV.");
90 rangePtr->addDependency(typePtr,
"uniform");
91 auto minEPtr = specBlock->addSingleInput(
"minimum energy",
false,
"The minimum energy for the spectrum, in MeV.");
92 minEPtr->addDependency(typePtr,
"uniform");
93 auto maxEPtr = specBlock->addSingleInput(
"maximum energy",
false,
"The maximum energy for the spectrum, in MeV.");
94 maxEPtr->addDependency(typePtr,
"uniform");
95 minEPtr->addDependency(rangePtr,
"",
true);
96 maxEPtr->addDependency(rangePtr,
"",
true);
97 rangePtr->addDependency(minEPtr,
"",
true);
98 rangePtr->addDependency(maxEPtr,
"",
true);
101 auto specFilePtr = specBlock->addSingleInput(
"spectrum file",
false,
"The full file path to the spectrum file. See documentation for the format of the file.");
102 specFilePtr->addDependency(typePtr,
"tabulated spectrum");
103 auto modePtr = specBlock->addSingleInput(
"spectrum mode",
false,
"The mode number that denotes how to create the spectrum. Use 0 for histogram counts/bin, 1 for counts/MeV, 2 for a line spectrum and 3 for an interpolated spectrum.");
104 modePtr->addDependency(typePtr,
"tabulated spectrum");
105 auto energiesPtr = specBlock->addSingleInput(
"energies",
false,
"A list of energies for the spectrum, in MeV. When applicable, this is the upper edge of the bin.");
106 energiesPtr->addDependency(typePtr,
"tabulated spectrum");
107 auto probsPtr = specBlock->addSingleInput(
"probabilities",
false,
"A list of probabilities for the spectrum. Does not need to be normalized.");
108 probsPtr->addDependency(typePtr,
"tabulated spectrum");
109 modePtr->addDependency(specFilePtr,
"",
true);
110 energiesPtr->addDependency(specFilePtr,
"",
true);
111 probsPtr->addDependency(specFilePtr,
"",
true);
114 specBlock->addSingleInput(
"nuclide",
true,
"The name of the nuclide to model, e.g. Co-60 or Tc-99m. If the 'ensdf file' input is not specified, then the ENSDF file will be searched for as $HEN_HOUSE/spectra/lnhb/ensdf/nuclide.txt, where nuclide is the text you input. Note that a radionuclide spectrum is ONLY compatible with a radionuclide source.")->addDependency(typePtr,
"radionuclide");
115 specBlock->addSingleInput(
"ensdf file",
false,
"The full path to the ENSDF file to use.")->addDependency(typePtr,
"radionuclide");
116 specBlock->addSingleInput(
"relative activity",
false,
"If multiple radionuclide spectra are specified for a single radionuclide source, this is the relative weight of this spectrum. Defaults to 1.")->addDependency(typePtr,
"radionuclide");
117 specBlock->addSingleInput(
"atomic relaxations",
false,
"The model to use for atomic relaxations resulting from radionuclide decay. Defaults to EADL.", {
"eadl",
"ensdf",
"off"})->addDependency(typePtr,
"radionuclide");
118 specBlock->addSingleInput(
"output beta spectra",
false,
"Whether or not to output as files the beta spectra that are used for sampling beta decay energies. Defaults to No.", {
"yes",
"no"})->addDependency(typePtr,
"radionuclide");
119 specBlock->addSingleInput(
"alpha scoring",
false,
"The model to use for scoring alpha particles during radionuclide decay. Defaults to Discard.", {
"local",
"discard"})->addDependency(typePtr,
"radionuclide");
120 specBlock->addSingleInput(
"extra transition approximation",
false,
"Whether or not to use the option that automatically balances transition intensities. Defaults to Off.", {
"on",
"off"})->addDependency(typePtr,
"radionuclide");
176 return description.c_str();
201 EGS_Float &E, EGS_Float &wt,
274 return vector<EGS_Ensdf *>();
393 static void addKnownTypeId(
const char *name);
412 EGS_Float getTimeIndex() {
417 void setTimeIndex(EGS_Float temp_time) {
418 time_index=temp_time;
431 virtual void containsDynamic(
bool &hasdynamic) {
478 type(
"Unknown spectrum") {};
500 EGS_Float e = sample(rndm);
537 data_out <<
" " << sum_E <<
" " << sum_E2 << endl;
538 if (!data_out.good() || data_out.fail()) {
561 data_in >> sum_E >> sum_E2;
562 if (data_in.eof() || !data_in.good() || data_in.fail()) {
581 EGS_I64 count_save = count;
582 double sum_E_save = sum_E, sum_E2_save = sum_E2;
583 if (!setState(data_in)) {
588 sum_E2 += sum_E2_save;
635 de = sqrt(de/(count-1));
646 egsInformation(
"expected average energy: %g\n",expectedAverage());
648 getSampledAverage(e,de);
759 int &Q,
int &latch, EGS_Float &E, EGS_Float &wt,
762 E = s->sampleEnergy(rndm);
763 getPositionDirection(rndm,x,u,wt);
785 return s->maxEnergy();
820 if (!s->storeState(data_out)) {
823 if (!storeFluenceState(data_out)) {
836 EGS_I64 count_save = count;
840 if (!s->addState(data)) {
843 if (!addFluenceData(data)) {
859 resetFluenceCounter();
913 if (!s->setState(data)) {
916 if (!setFluenceState(data)) {
962 egsWarning(
"createSource(%s): null input?\n",name);
965 T *res =
new T(input,f);
966 if (!res->isValid()) {
967 egsWarning(
"createSource(%s): the input is not "
968 "sufficient to create a valid source\n",name);
Base class for 'simple' particle sources.
string type
A short description of the source type.
EGS_BaseSimpleSource(int Q, EGS_BaseSpectrum *Spec, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
~EGS_BaseSimpleSource()
Destructor.
int q
The charge of this simple source.
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.
EGS_BaseSpectrum * s
The energy spectrum of this source.
virtual bool isValid() const
Is this a valid source?
virtual bool setState(istream &data)
Set the source state according to the data in the stream data.
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 addState(istream &data)
Add the source state from the stream data to the current state.
int getCharge() const
Get the charge of the source.
virtual bool storeState(ostream &data_out) const
Store the source state to the data stream data_out.
virtual EGS_Float getEmax() const
Get the maximum energy of the source.
virtual void resetCounter()
Reset the source to a state with zero sampled particles.
virtual void setLatch(int &latch)
virtual bool setFluenceState(istream &data)
Set the data related to the sampling of positions and directions to a state contained in the stream d...
EGS_I64 count
Number of statistically independent particles delivered so far.
virtual EGS_I64 getNextParticle(EGS_RandomGenerator *rndm, int &Q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)
Sample the next source particle from the source probability distribution.
Base source class. All particle sources must be derived from this class.
virtual int getCharge() const
Get the charge of the source.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
EGS_BaseSource(EGS_Input *input, EGS_ObjectFactory *f=0)
Construct a source from the input pointed to by inp.
const char * getSourceDescription() const
Get a short description of this source.
EGS_BaseSource(const string &Name="", EGS_ObjectFactory *f=0)
Construct a source named Name.
virtual void printSampledEmissions()
Print statistics on what was sampled from the source.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
EGS_Float time_index
time index corresponding to a particle. This stores the current time index for all objects in the sim...
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
virtual void resetCounter()
Reset the source state.
string description
A short source description.
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.
static void addKnownTypeId(const char *name)
Add a known source object typeid to the source factory.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk)
Set the next simulation chunk to start at nstart and to consist of nrun particles.
virtual vector< EGS_Ensdf * > getRadionuclideEnsdf()
Get the radionuclide ENSDF object from the source.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
Base class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from th...
EGS_Float sampleEnergy(EGS_RandomGenerator *rndm)
Sample a particle energy.
virtual bool setState(istream &data_in)
Set the state of the spectrum object from the data in the stream data_in.
virtual ~EGS_BaseSpectrum()
Destructor. Does nothing.
double sum_E2
Sum of energies squared sampled so far.
void reportAverageEnergy() const
Report the average energy (expected and actually sampled).
virtual EGS_Float maxEnergy() const =0
Get the maximum energy of this spectrum.
string type
A short string describing the spectrum that must be set by derived classes.
virtual bool addState(istream &data_in)
Add to the state of this object the data from the stream data_in.
virtual EGS_Float sample(EGS_RandomGenerator *rndm)=0
Sample an energy from the spectrum energy distribution.
virtual EGS_Float expectedAverage() const =0
Get the average energy of the spectrum.
EGS_BaseSpectrum()
Constructor.
void getSampledAverage(EGS_Float &e, EGS_Float &de) const
Get the average sampled energy and its statistical uncertainty.
EGS_I64 count
Number of times the sampleEnergy() method was called.
virtual bool storeState(ostream &data_out) const
Store the state of the spectrum object into the stream data_out.
double sum_E
Sum of energies sampled so far.
const string & getType() const
Get the spectrum type.
virtual void resetCounter()
Reset the state of this spectrum object.
Base random number generator class. All random number generators should be derived from this class.
A class representing 3D vectors.
EGS_BaseSource * createSourceTemplate(EGS_Input *input, EGS_ObjectFactory *f, const char *name)
A template source creation function.
The ensdf library header file.
Global egspp functions header file.
#define EGS_EXPORT
Export symbols from the egspp library.
Attempts to fix broken math header files.
EGS_Object and EGS_ObjectFactory class 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 egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
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,...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.