43 #ifndef EGS_BASE_SOURCE_
44 #define EGS_BASE_SOURCE_
112 return description.c_str();
137 EGS_Float &E, EGS_Float &wt,
205 return vector<EGS_Ensdf *>();
321 static void addKnownTypeId(
const char *name);
340 EGS_Float getTimeIndex() {
345 void setTimeIndex(EGS_Float temp_time) {
346 time_index=temp_time;
359 virtual void containsDynamic(
bool &hasdynamic) { };
404 type(
"Unknown spectrum") {};
426 EGS_Float e = sample(rndm);
463 data_out <<
" " << sum_E <<
" " << sum_E2 << endl;
464 if (!data_out.good() || data_out.fail()) {
487 data_in >> sum_E >> sum_E2;
488 if (data_in.eof() || !data_in.good() || data_in.fail()) {
507 EGS_I64 count_save = count;
508 double sum_E_save = sum_E, sum_E2_save = sum_E2;
509 if (!setState(data_in)) {
514 sum_E2 += sum_E2_save;
561 de = sqrt(de/(count-1));
572 egsInformation(
"expected average energy: %g\n",expectedAverage());
574 getSampledAverage(e,de);
685 int &Q,
int &latch, EGS_Float &E, EGS_Float &wt,
688 E = s->sampleEnergy(rndm);
689 getPositionDirection(rndm,x,u,wt);
711 return s->maxEnergy();
745 if (!s->storeState(data_out)) {
748 if (!storeFluenceState(data_out)) {
761 EGS_I64 count_save = count;
765 if (!s->addState(data)) {
768 if (!addFluenceData(data)) {
784 resetFluenceCounter();
836 if (!s->setState(data)) {
839 if (!setFluenceState(data)) {
885 egsWarning(
"createSource(%s): null input?\n",name);
888 T *res =
new T(input,f);
889 if (!res->isValid()) {
890 egsWarning(
"createSource(%s): the input is not "
891 "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.