40 #ifndef EGS_BASE_SOURCE_
41 #define EGS_BASE_SOURCE_
108 return description.c_str();
133 EGS_Float &E, EGS_Float &wt,
165 virtual EGS_Float getEmax()
const = 0;
180 virtual EGS_Float getFluence()
const = 0;
187 virtual EGS_Float getMu() {
304 static void addKnownTypeId(
const char *name);
344 type(
"Unknown spectrum") {};
366 EGS_Float e = sample(rndm);
378 virtual EGS_Float maxEnergy()
const = 0;
385 virtual EGS_Float expectedAverage()
const = 0;
403 data_out <<
" " << sum_E <<
" " << sum_E2 << endl;
404 if (!data_out.good() || data_out.fail()) {
427 data_in >> sum_E >> sum_E2;
428 if (data_in.eof() || !data_in.good() || data_in.fail()) {
447 EGS_I64 count_save = count;
448 double sum_E_save = sum_E, sum_E2_save = sum_E2;
449 if (!setState(data_in)) {
454 sum_E2 += sum_E2_save;
501 de = sqrt(de/(count-1));
511 void reportAverageEnergy()
const;
620 int &Q,
int &latch, EGS_Float &E, EGS_Float &wt,
623 E = s->sampleEnergy(rndm);
624 getPositionDirection(rndm,x,u,wt);
646 return s->maxEnergy();
680 if (!s->storeState(data_out)) {
683 if (!storeFluenceState(data_out)) {
696 EGS_I64 count_save = count;
700 if (!s->addState(data)) {
703 if (!addFluenceData(data)) {
719 resetFluenceCounter();
771 if (!s->setState(data)) {
774 if (!setFluenceState(data)) {
820 egsWarning(
"createSource(%s): null input?\n",name);
823 T *res =
new T(input,f);
824 if (!res->isValid()) {
825 egsWarning(
"createSource(%s): the input is not "
826 "sufficient to create a valid source\n",name);
#define EGS_EXPORT
Export symbols from the egspp library.
virtual void setLatch(int &latch)
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.
void getSampledAverage(EGS_Float &e, EGS_Float &de) const
Get the average sampled energy and its statistical uncertainty.
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun)
Set the next simulation chunk to start at nstart and to consist of nrun particles.
EGS_BaseSimpleSource(int Q, EGS_BaseSpectrum *Spec, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
string type
A short string describing the spectrum that must be set by derived classes.
double sum_E
Sum of energies sampled so far.
virtual EGS_Float getEmax() const
Get the maximum energy of the source.
EGS_BaseSource(EGS_Input *input, EGS_ObjectFactory *f=0)
Construct a source from the input pointed to by inp.
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, false on failure.
EGS_BaseSource * createSourceTemplate(EGS_Input *input, EGS_ObjectFactory *f, const char *name)
A template source creation function.
virtual void resetCounter()
Reset the source to a state with zero sampled particles.
A class representing 3D vectors.
EGS_BaseSource(const string &Name="", EGS_ObjectFactory *f=0)
Construct a source named Name.
virtual bool addState(istream &data_in)
Add to the state of this object the data from the stream data_in.
Global egspp functions header file.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
virtual void resetCounter()
Reset the source state.
virtual bool addState(istream &data)
Add the source state from the stream data to the current state.
EGS_I64 count
Number of statistically independent particles delivered so far.
EGS_Float sampleEnergy(EGS_RandomGenerator *rndm)
Sample a particle energy.
const char * getSourceDescription() const
Get a short description of this source.
virtual void resetCounter()
Reset the state of this spectrum object.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
EGS_BaseSpectrum * s
The energy spectrum of this source.
Base random number generator class. All random number generators should be derived from this class...
virtual bool setState(istream &data_in)
Set the state of the spectrum object from the data in the stream data_in.
EGS_BaseSpectrum()
Constructor.
EGS_I64 count
Number of times the sampleEnergy() method was called.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
virtual bool setState(istream &data)
Set the source state according to the data in the stream data.
~EGS_BaseSimpleSource()
Destructor.
Attempts to fix broken math header files.
virtual bool storeState(ostream &data_out) const
Store the state of the spectrum object into the stream data_out.
virtual bool storeFluenceState(ostream &data_out) const
Store the fluence state of this source to the data stream data_out.
string type
A short description of the source type.
virtual int getCharge() const
Get the charge of the source.
EGS_Object and EGS_ObjectFactory class header file.
const string & getType() const
Get the spectrum type.
virtual ~EGS_BaseSpectrum()
Destructor. Does nothing.
static void addKnownTypeId(const char *name)
Add a known source object typeid to the source factory.
int getCharge() const
Get the charge of the source.
virtual bool addFluenceData(istream &data)
Add fluence data from the stream data to the current state.
virtual void resetFluenceCounter()
Reset the data related to the sampling of positions and directions to a state with zero sampled parti...
Base class for energy spectra. All energy spectra in the EGSnrc C++ class library are derived from th...
Base class for 'simple' particle sources.
virtual bool storeState(ostream &data_out) const
Store the source state to the data stream data_out.
virtual bool isValid() const
Is this a valid source?
virtual bool setFluenceState(istream &data)
Set the data related to the sampling of positions and directions to a state contained in the stream d...
double sum_E2
Sum of energies squared sampled so far.
Base source class. All particle sources must be derived from this class.
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)
Sample the next source particle from the source probability distribution.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.