44 baseSource(0), q_allowed(0), decays(0), activity(1), sCount(0) {
48 err = input->
getInput(
"charge", tmp_q);
50 if (std::find(q_allowed.begin(), q_allowed.end(), -1) != q_allowed.end()
51 && std::find(q_allowed.begin(), q_allowed.end(), 0) != q_allowed.end()
52 && std::find(q_allowed.begin(), q_allowed.end(), 1) != q_allowed.end()
53 && std::find(q_allowed.begin(), q_allowed.end(), 2) != q_allowed.end()
64 q_allowed.push_back(-1);
65 q_allowed.push_back(1);
66 q_allowed.push_back(0);
67 q_allowed.push_back(2);
75 EGS_Float spectrumWeightTotal = 0;
76 disintegrationOccurred =
true;
82 egsInformation(
"**********************************************\n");
94 EGS_Float spectrumMaxE = decays[i]->maxEnergy();
95 if (spectrumMaxE > Emax) {
99 spectrumWeightTotal += decays[i]->getSpectrumWeight();
103 if (decays.size() < 1) {
104 egsFatal(
"\nEGS_RadionuclideSource: Error: No spectrum of type EGS_RadionuclideSpectrum was defined.\n");
108 for (i=0; i<decays.size(); ++i) {
109 decays[i]->setSpectrumWeight(
110 decays[i]->getSpectrumWeight() / spectrumWeightTotal);
113 decays[i]->setSpectrumWeight(
114 decays[i]->getSpectrumWeight() +
115 decays[i-1]->getSpectrumWeight());
121 err = input->
getInput(
"activity", tmp_A);
129 egsInformation(
"EGS_RadionuclideSource: Activity [disintegrations/s]: %e\n",
135 err = input->
getInput(
"experiment time", experimentTime);
140 if (experimentTime > 0.) {
141 egsInformation(
"EGS_RadionuclideSource: Experiment time [s]: %e\n",
145 egsInformation(
"EGS_RadionuclideSource: Experiment time will not limit the simulation.\n");
153 err = input->
getInput(
"source type",dummy);
154 int err2 = input->
getInput(
"geometry",dummy);
156 egsWarning(
"\nEGS_RadionuclideSource: Warning: Inputs for defining the radionuclide source as an isotropic or collimated source (e.g. 'source type') are deprecated. Please see the documentation - define the type of source separately and then refer to it using the new 'base source' input.\n");
161 err = input->
getInput(
"base source",sName);
163 egsFatal(
"\nEGS_RadionuclideSource: Error: Base source must be defined\n"
164 "using 'base source = some_name'\n");
168 egsFatal(
"\nEGS_RadionuclideSource: Error: no source named %s"
169 " is defined\n",sName.c_str());
184 if (decays.size() > 1 && disintegrationOccurred) {
189 for (i=0; i<decays.size(); ++i) {
190 if (uRand < decays[i]->getSpectrumWeight()) {
197 if (experimentTime <= 0. || time < experimentTime) {
207 EGS_I64 ishowerOld = decays[i]->getShowerIndex();
209 E = decays[i]->sampleEnergy(rndm);
211 EGS_I64 ishowerNew = decays[i]->getShowerIndex();
212 if (ishowerNew > ishowerOld) {
213 disintegrationOccurred =
true;
214 time = lastDisintTime + -log(1.-rndm->
getUniform()) / activity * (ishowerNew - ishowerOld);
216 lastDisintTime = time;
217 ishower += (ishowerNew - ishowerOld);
220 disintegrationOccurred =
false;
226 time += decays[i]->getTime();
229 q = decays[i]->getCharge();
230 int qTemp(q), latchTemp(latch);
236 if (disintegrationOccurred) {
237 xOfDisintegration = x;
240 x = xOfDisintegration;
246 EGS_Float edep = decays[i]->getEdep();
249 int ireg = app->isWhere(x);
254 if (q_allowAll || std::find(q_allowed.begin(), q_allowed.end(), q) != q_allowed.end()) {
272 void EGS_RadionuclideSource::setUp() {
273 otype =
"EGS_RadionuclideSource";
278 description =
"Radionuclide production in base source ";
282 if (std::find(q_allowed.begin(), q_allowed.end(), -1) !=
286 if (std::find(q_allowed.begin(), q_allowed.end(), 0) != q_allowed.end()) {
289 if (std::find(q_allowed.begin(), q_allowed.end(), 1) != q_allowed.end()) {
292 if (std::find(q_allowed.begin(), q_allowed.end(), 1) != q_allowed.end()) {
302 for (
unsigned int i=0; i<decays.size(); ++i) {
315 for (
unsigned int i=0; i<decays.size(); ++i) {
319 ishower += decays[i]->getShowerIndex();
332 for (
unsigned int i=0; i<decays.size(); ++i) {
333 decays[i]->resetCounter();
342 for (
unsigned int i=0; i<decays.size(); ++i) {
359 createSourceTemplate<EGS_RadionuclideSource>(input,f,
"radionuclide "
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, false on failure.
bool addState(istream &data)
Add the source state from the stream data to the current state.
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, false on failure.
A class representing 3D vectors.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
bool storeState(ostream &data_out) const
Store the source state to the data stream data_out.
virtual void resetCounter()
Reset the source state.
EGS_RadionuclideSource(EGS_Input *, EGS_ObjectFactory *f=0)
Constructor from input file.
const char * getSourceDescription() const
Get a short description of this source.
static EGS_BaseSpectrum * createSpectrum(EGS_Input *inp)
Create and return a pointer to a spectrum object from the information pointed to by inp...
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
Base random number generator class. All random number generators should be derived from this class...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_I64 getNextParticle(EGS_RandomGenerator *rndm, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)
Gets the next particle from the radionuclide spectra.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
bool setState(istream &data)
Set the source state according to the data in the stream data.
static EGS_Application * activeApplication()
Get the active application.
static EGS_BaseSource * getSource(const string &Name)
Get a pointer to the source named Name.
Attempts to fix broken math header files.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
EGS_I64 getShowerIndex() const
Returns the shower index of the most recent particle.
bool isValid() const
Checks the validity of the source.
int userScoring(int iarg, int ir=-1)
User scoring function for accumulation of results and VRT implementation.
void resetCounter()
Reset the source to a state with zero sampled particles.
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.
string otype
The object type.
EGS_Application class header file.
Base source class. All particle sources must be derived from this class.
string description
A short source description.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.