EGSnrc C++ class library
Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
|
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_BaseGeometry * | g |
The simulation geometry. | |
EGS_BaseSource * | source |
The particle source. | |
EGS_RandomGenerator * | rndm |
The random number generator. | |
EGS_Input * | input |
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 | |
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.
Definition at line 61 of file egs_simple_application.h.
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.
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.
|
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.
|
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).
Definition at line 121 of file egs_simple_application.h.
Referenced by egsAusgab().
|
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().
|
virtual |
Run the simulation.
The default implementation of this function simulates ncase showers, calling startHistory() and endHistory() before/after the shower is simulated. The progress of the simulation is reported nreport times during the simulation. This number can bechanged using setNProgress().
Definition at line 275 of file egs_simple_application.cpp.
References EGS_Stack::dnear, EGS_Stack::E, egsInformation, egsShower(), endHistory(), Etot, g, EGS_BaseSource::getNextParticle(), EGS_BaseGeometry::howfar(), EGS_Stack::iq, EGS_Stack::ir, EGS_BaseGeometry::isWhere(), last_case, EGS_Stack::latch, ncase, EGS_Stack::np, nreport, EGS_Useful::rm, rndm, source, EGS_Timer::start(), startHistory(), sum_E, sum_E2, sum_w, sum_w2, the_stack, the_useful, EGS_Timer::time(), EGS_Stack::u, EGS_Stack::v, veryFar, EGS_Stack::w, EGS_Stack::wt, EGS_Vector::x, EGS_Stack::x, EGS_Vector::y, EGS_Stack::y, EGS_Vector::z, and EGS_Stack::z.
|
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.
Definition at line 169 of file egs_simple_application.h.
Referenced by run().
|
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.
|
protected |
same as sum_E but only for particles entering the geometry
Definition at line 221 of file egs_simple_application.h.
Referenced by run().