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

A base class for developing simple EGSnrc applications. More...

#include <egs_simple_application.h>

Public Member Functions

 EGS_SimpleApplication (int argc, char **argv)
 Construct a simple application object. More...
 
virtual ~EGS_SimpleApplication ()
 
int howfar (int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed)
 See the EGSnrc howfar geometry specification .
 
EGS_Float hownear (int ireg, const EGS_Vector &x)
 See the EGSnrc hownear geometry specification .
 
int getMedium (int ireg)
 Get the medium index in region ireg.
 
virtual int ausgab (int)
 
virtual void finish ()
 Finish the simulation. More...
 
virtual int run ()
 Run the simulation. More...
 
void setNProgress (int nprog)
 Set the number of times the shower loop in run() reports the progress of the simulation to nprog.
 
virtual void startHistory (EGS_I64)
 Start a new shower. More...
 
virtual void endHistory ()
 
void fillRandomArray (int n, EGS_Float *r)
 Fill the array pointed to by r with n random numbers.
 
const char * egsHome () const
 
const char * henHouse () const
 
const char * pegsFile () const
 
const char * inputFile () const
 
const char * outputFile () const
 
const char * userCode () const
 
const char * workDir () const
 
int iParallel () const
 
int nParallel () const
 

Protected Attributes

EGS_I64 ncase
 Number of showers to simulate.
 
int nreport
 How often to report the progress.
 
EGS_BaseGeometryg
 The simulation geometry.
 
EGS_BaseSourcesource
 The particle source.
 
EGS_RandomGeneratorrndm
 The random number generator.
 
EGS_Inputinput
 The input found in the input file.
 
double sum_E
 sum of E*wt of particles from the source
 
double sum_E2
 sum of E*E*wt of particles from the source
 
double sum_w
 sum of weights
 
double sum_w2
 sum of weights squared
 
double Etot
 
EGS_I64 last_case
 last statistically independent event
 

Detailed Description

A base class for developing simple EGSnrc applications.

The easiest way to develop a C++ user code for EGSnrc is to derive from the EGS_SimpleApplication class and implement the ausgab() function to perform the scoring of the quantites of interest, possibly reimplement the startHistory() and endHistory() functions (called before/after the simulation of a single shower within the shower loop performed in run()), and implement initializitions and output of the results. An example of a simple C++ application for EGSnrc that uses a class derived from EGS_SimpleApplication is tutor2pp.

A better way of developing C++ user codes for EGSnrc is to derive from the EGS_AdvancedApplication class.

Examples:
tutor2pp.cpp.

Definition at line 61 of file egs_simple_application.h.

Constructor & Destructor Documentation

EGS_SimpleApplication::EGS_SimpleApplication ( int  argc,
char **  argv 
)

Construct a simple application object.

The command line arguments must be passed to the EGS_SimpleApplication constructor so that the name of the application, the input file, the output file and the pegs file can be determined. The input file is then read in, geometry, source and random number generator are initialized and the egs_init function is called. The egs_init function, which is part of the mortran back-end, sets default values for all variables needed in the simulation, creates a temporary working directory for the run and opens various Fortran I/O units needed by the mortran back-end. The media present in the geometry are then added to the mortran back-end and the HATCH subroutine is called to initialize the cross section data. Finally, a check is made that the cross section data files cover the energy range needed based on the maximum energy of the source.

Examples:
tutor2pp.cpp.

Definition at line 110 of file egs_simple_application.cpp.

References EGS_BaseGeometry::createGeometry(), EGS_RandomGenerator::createRNG(), EGS_BaseSource::createSource(), EGS_RandomGenerator::defaultRNG(), EGS_BaseGeometry::describeGeometries(), EGS_Bounds::ecut, EGS_Bounds::ecut_new, egsAddMedium(), egsFatal, egsGetTransportParameter(), egsHatch(), egsInformation, egsInit(), egsWarning, g, EGS_BaseSource::getEmax(), EGS_BaseGeometry::getMediumName(), EGS_BaseGeometry::getName(), EGS_BaseGeometry::getType(), input, ncase, EGS_BaseGeometry::nMedia(), nreport, EGS_Bounds::pcut, EGS_Bounds::pcut_new, EGS_Useful::rm, rndm, EGS_Input::setContentFromFile(), source, EGS_Input::takeInputItem(), the_bounds, the_egsio, the_thresh, the_useful, EGS_Thresh::ue, and EGS_Thresh::up.

EGS_SimpleApplication::~EGS_SimpleApplication ( )
virtual
Destructor.

Deletes the geometry, the source, the random number generator and the input object.

Definition at line 254 of file egs_simple_application.cpp.

References EGS_BaseGeometry::deref(), g, input, rndm, and source.

Member Function Documentation

virtual int EGS_SimpleApplication::ausgab ( int  )
virtual
Scoring of results.

This function must be reimplemented by the derived class to perform the scoring of the quantities of interest during the simulation. ausgab() is called with a corresponding integer argument on various events during the simulation (see PIRS-701).

Examples:
tutor2pp.cpp.

Definition at line 121 of file egs_simple_application.h.

Referenced by egsAusgab().

void EGS_SimpleApplication::finish ( )
virtual

Finish the simulation.

The default implemenmtation simply calls the egsFinish() function, which moves all output from the temporary working directory to the user code directory and deletes the temporary working directory.

Definition at line 271 of file egs_simple_application.cpp.

References egsFinish().

int EGS_SimpleApplication::run ( )
virtual
virtual void EGS_SimpleApplication::startHistory ( EGS_I64  )
virtual

Start a new shower.

This function is called from within the shower loop in run() before the simulation of the next particle starts. Could be reimplemented in derived classes to e.g. inform scoring objects that a new statistically independent event begins.

Examples:
tutor2pp.cpp.

Definition at line 169 of file egs_simple_application.h.

Referenced by run().

virtual void EGS_SimpleApplication::endHistory ( )
virtual
Finish a shower.

This function is called from within the shower loop in run() after the simulation of a particle has finished. Could be reimplemented in derived classes to e.g. score a pulse-height distribution.

Definition at line 177 of file egs_simple_application.h.

Referenced by run().

const char * EGS_SimpleApplication::egsHome ( ) const

Get the EGS_HOME directory

Definition at line 74 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::henHouse ( ) const

Get the HEN_HOUSE directory

Definition at line 78 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::pegsFile ( ) const

Get the name of the PEGS file

Definition at line 82 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::inputFile ( ) const

Get the name of the input file

Definition at line 86 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::outputFile ( ) const

Get the name of the output file

Definition at line 90 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::userCode ( ) const

Get the name of the user code

Definition at line 94 of file egs_simple_application.cpp.

References the_egsio.

const char * EGS_SimpleApplication::workDir ( ) const

Get the working directory

Definition at line 98 of file egs_simple_application.cpp.

References the_egsio.

int EGS_SimpleApplication::iParallel ( ) const

The index of this job in a parallel run

Definition at line 102 of file egs_simple_application.cpp.

References the_egsio.

int EGS_SimpleApplication::nParallel ( ) const

Number of parallel jobs

Definition at line 106 of file egs_simple_application.cpp.

References the_egsio.

Member Data Documentation

double EGS_SimpleApplication::Etot
protected

same as sum_E but only for particles entering the geometry

Examples:
tutor2pp.cpp.

Definition at line 221 of file egs_simple_application.h.

Referenced by run().


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