EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EGS_PhspSource Class Reference

A phase-space file source. More...

#include <egs_phsp_source.h>

Inheritance diagram for EGS_PhspSource:
EGS_BaseSource EGS_Object

Public Member Functions

 EGS_PhspSource (const string &phsp_file, const string &Name="", EGS_ObjectFactory *f=0)
 Constructor. More...
 
 EGS_PhspSource (EGS_Input *, EGS_ObjectFactory *f=0)
 Constructor. More...
 
EGS_I64 getNextParticle (EGS_RandomGenerator *rndm, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)
 
void setSimulationChunk (EGS_I64 nstart, EGS_I64 nrun)
 
EGS_Float getEmax () const
 
EGS_Float getFluence () const
 
bool storeState (ostream &data) const
 
bool setState (istream &data)
 
bool addState (istream &data)
 
void resetCounter ()
 
bool isValid () const
 
void setCutout (EGS_Float xmin, EGS_Float xmax, EGS_Float ymin, EGS_Float ymax)
 
void setFilter (int, int, int, const int *)
 
- Public Member Functions inherited from EGS_BaseSource
 EGS_BaseSource (const string &Name="", EGS_ObjectFactory *f=0)
 Construct a source named Name. More...
 
 EGS_BaseSource (EGS_Input *input, EGS_ObjectFactory *f=0)
 Construct a source from the input pointed to by inp. More...
 
const char * getSourceDescription () const
 Get a short description of this source. More...
 
virtual int getCharge () const
 Get the charge of the source. More...
 
virtual EGS_Float getMu ()
 
- Public Member Functions inherited from EGS_Object
 EGS_Object (const string &Name="", EGS_ObjectFactory *f=0)
 Create an EGS_Object named Name belonging to the object factory f. More...
 
 EGS_Object (EGS_Input *inp, EGS_ObjectFactory *f=0)
 Create an EGS_Object from the information pointed to by inp that belongs to object factory f. More...
 
const string & getObjectName () const
 Get the object name.
 
void setObjectName (const string &Name)
 Set the object name to Name.
 
const string & getObjectType () const
 Get the object type.
 
virtual EGS_ObjectcreateObject (EGS_Input *inp)
 Create an object from the infromation pointed to by inp. More...
 
void setName (EGS_Input *inp)
 Set the name of the object from the information provided by inp. More...
 
int ref ()
 Increase the reference count to this object.
 
int deref ()
 Decrease the reference count to this object.
 
void setFactory (EGS_ObjectFactory *f)
 Set the factory to which the object belongs. More...
 

Protected Member Functions

void openFile (const string &)
 
void init ()
 
void readParticle ()
 
bool rejectParticle () const
 

Protected Attributes

bool is_valid
 
string the_file_name
 The phase-space file name.
 
ifstream the_file
 Phase space data stream.
 
int recl
 The particle record length.
 
bool mode2
 true, if a MODE2 file
 
bool swap_bytes
 
char * record
 Memory to read a particle into.
 
EGS_Float Emax
 Maximum energy (obtained from the phsp file)
 
EGS_Float Emin
 Minimum energy (obtained from the phsp file)
 
EGS_Float Pinc
 Number of incident particles that created the file.
 
EGS_I64 Nparticle
 Number of particles in the file.
 
EGS_I64 Nphoton
 Number of photons in the file.
 
EGS_I64 Nread
 Number of particles read so far.
 
EGS_I64 Npos
 Next record to be read.
 
EGS_I64 Nfirst
 first record this source can use
 
EGS_I64 Nlast
 Last record this source can use.
 
EGS_I64 count
 
int Nrestart
 Number of times the file was restarted.
 
int Nrecycle_g
 Number of times to recycle a photon.
 
int Nrecycle_e
 Number of times to recycle a charged particle.
 
int Nrecycle
 Number of times to recycle current particle.
 
int Nuse
 Number of times current particle was used so far.
 
bool first
 
int particle_type
 
int filter_type
 
unsigned long filter1
 
unsigned long filter2
 
EGS_Float Xmin
 
EGS_Float Xmax
 
EGS_Float Ymin
 
EGS_Float Ymax
 
EGS_Float wmin
 
EGS_Float wmax
 
- Protected Attributes inherited from EGS_BaseSource
string description
 A short source description. More...
 
- Protected Attributes inherited from EGS_Object
string name
 The object name.
 
string otype
 The object type.
 
int nref
 Number of references to the object.
 
EGS_ObjectFactoryfactory
 The factory this object belongs to.
 

Additional Inherited Members

- Static Public Member Functions inherited from EGS_BaseSource
static EGS_BaseSourcecreateSource (EGS_Input *)
 Create sources from the information pointed to by input. More...
 
static EGS_BaseSourcegetSource (const string &Name)
 Get a pointer to the source named Name. More...
 
static void addKnownSource (EGS_BaseSource *o)
 Add a known source object to the source factory. More...
 
static void addKnownTypeId (const char *name)
 Add a known source object typeid to the source factory. More...
 
- Static Public Member Functions inherited from EGS_Object
static string getUniqueName (const EGS_Object *o=0)
 Create and return a unique object name. More...
 
static void deleteObject (EGS_Object *o)
 Delete an object. More...
 

Detailed Description

A phase-space file source.

A phase-space file source reads and delivers particles from a BEAMnrc phase-space file. Because the phase-space file only contains the x- and y- positions, the z-position is set to 0. A phase-space file source is defined as follows:

:start source:
    library = egs_phsp_source
    name = some_name
    phase space file = name of the phase space file
    particle type = one of photons, electrons, positrons, all, or charged
    cutout = x1 x2 y1 y2  (optional)
    weight window = wmin wmax, the min and max particle weights to use. If the particle weight is not in this range, it is rejected. (optional)
    recycle photons = number of times to recycle each photon (optional)
    recycle electrons = number of times to recycle each electron (optional)
:stop source:

The optional cutout key permits to set a rectangular cutout defined by its upper-left and lower-right corners x1,y1 and x2,y2 (all particles not within this rectangle will be thrown away). The particle type key permits to select a subset of particles based on the particle charge. No filters based on the value of the latch variable are implemented yet but such filters will be added in future versions of the library. Note that a phase-space source can be used as the source in a transformed source permitting in this way arbitrary transformations to be applied to the particle positions and directions. It is worth noting that, together with a transformation, the phase-space source can reproduce the functionality of any phase-space file based source in the RZ series of user codes and in DOSXYZnrc.

A simple example:

:start source definition:
    :start source:
        name        = my_source
        library     = egs_phsp_source
        phase space file = ../BEAM_EX16MVp/EX16MVp.egsphsp1
        particle type = all
        cutout      = -1 1 -2 2
        recycle photons = 10
        recycle electrons = 10
    :stop source:

    simulation source = my_source

:stop source definition:
egs_phsp_source.png
A simple example
Todo:
Fully implement latch filters

Definition at line 127 of file egs_phsp_source.h.

Constructor & Destructor Documentation

EGS_PhspSource::EGS_PhspSource ( const string &  phsp_file,
const string &  Name = "",
EGS_ObjectFactory f = 0 
)

Constructor.

Construct a phase-space file source delivering particles from the BEAMnrc phase-space file phsp_file.

Definition at line 44 of file egs_phsp_source.cpp.

EGS_PhspSource::EGS_PhspSource ( EGS_Input input,
EGS_ObjectFactory f = 0 
)

Constructor.

Construct a phase-space file source from the information pointed to by inp.

Definition at line 201 of file egs_phsp_source.cpp.

References EGS_BaseSource::description, egsWarning, EGS_Input::getInput(), Nrecycle_e, Nrecycle_g, and the_file_name.

Member Data Documentation

bool EGS_PhspSource::swap_bytes
protected
\c true, if phase-space file was generated

on a CPU with different endianness

Definition at line 240 of file egs_phsp_source.h.

EGS_I64 EGS_PhspSource::count
protected
 Particles delivered so far (may be less than

Nread because some particles were rejected

Definition at line 246 of file egs_phsp_source.h.


The documentation for this class was generated from the following files: