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_ScoringArray Class Reference

A class for scoring an array of quantities (e.g. a dose distribution) in a Monte Carlo simulation. More...

#include <egs_scoring.h>

Public Member Functions

 EGS_ScoringArray (int N)
 Construct a scoring array with N elements. More...
 
 ~EGS_ScoringArray ()
 Destructor. Deallocates all allocated memory.
 
void setHistory (EGS_I64 ncase)
 Set the current statistically independent event to ncase. More...
 
void score (int ireg, EGS_Float f)
 Add f to the score in the element ireg. More...
 
EGS_Float currentScore (int ireg) const
 Returns the score in element ireg from the last statistically indepent event that contributed to ireg (which may be the current event) More...
 
EGS_Float thisHistoryScore (int ireg) const
 Returns the score in ireg in the current event.
 
void currentScore (int ireg, double &s, double &s2)
 Sets s and s2 to the sum of scores and sum of scores squared in element ireg. More...
 
void currentResult (int ireg, double &r, double &dr)
 Sets r to the result in region ireg and dr to its statistical uncertainty. More...
 
void reportResults (double norm, const char *title, bool relative_error, const char *format=0)
 
bool storeState (ostream &data)
 Stores the state of the scoring array object into the data stream data. More...
 
bool setState (istream &data)
 Sets the state fof the scoring array object from the data in the input stream data. More...
 
void reset ()
 Reset the scoring array to a pristine state.
 
EGS_ScoringArrayoperator+= (const EGS_ScoringArray &x)
 Add the results of x to the rtesults of the invoking object. More...
 
int bins () const
 Returns the number of bins (or elements or regions, the most appropriate term depending on the way the scorring array is being used).
 
int regions () const
 Returns the number of regions (or elements or bins, the most appropriate term depending on the way the scorring array is being used).
 

Protected Attributes

EGS_I64 current_ncase
 
EGS_I64 current_ncase_65536
 
int nreg
 
EGS_ScoringSingleresult
 
unsigned short current_ncase_short
 

Detailed Description

A class for scoring an array of quantities (e.g. a dose distribution) in a Monte Carlo simulation.

The EGS_ScoringArray class implements all functionality needed for scoring a single quantity of interest or an array of quantities of interest in a Monte Carlo simulation, including history-by-history statistical analysis. Internally it makes use of the EGS_ScoringSingle class for accumulating the result in each element of the array but it also maintains a 64 bit integer indicating the last statistically independent event that contributed to any of the elements of the scoring array.

Examples:
tutor2pp.cpp, and tutor7pp.cpp.

Definition at line 219 of file egs_scoring.h.

Constructor & Destructor Documentation

EGS_ScoringArray::EGS_ScoringArray ( int  N)

Construct a scoring array with N elements.

All elements are initialized to zero. N must be greater than zero.

Definition at line 43 of file egs_scoring.cpp.

References egsFatal, nreg, and result.

Member Function Documentation

void EGS_ScoringArray::setHistory ( EGS_I64  ncase)

Set the current statistically independent event to ncase.

This function must be called before starting the simulation of the next statistically independent event (history).

Examples:
tutor2pp.cpp.

Definition at line 55 of file egs_scoring.cpp.

References current_ncase, current_ncase_65536, current_ncase_short, EGS_ScoringSingle::finishCase(), nreg, and result.

void EGS_ScoringArray::score ( int  ireg,
EGS_Float  f 
)

Add f to the score in the element ireg.

Uses EGS_ScoringSingle::score() of the scoring object in the region ireg

Examples:
tutor2pp.cpp, and tutor7pp.cpp.

Definition at line 244 of file egs_scoring.h.

EGS_Float EGS_ScoringArray::currentScore ( int  ireg) const

Returns the score in element ireg from the last statistically indepent event that contributed to ireg (which may be the current event)

See Also
thisHistoryScore()

Definition at line 254 of file egs_scoring.h.

void EGS_ScoringArray::currentScore ( int  ireg,
double &  s,
double &  s2 
)

Sets s and s2 to the sum of scores and sum of scores squared in element ireg.

See Also
EGS_ScoringSingle::currentScore(double,double).

Definition at line 271 of file egs_scoring.h.

void EGS_ScoringArray::currentResult ( int  ireg,
double &  r,
double &  dr 
)

Sets r to the result in region ireg and dr to its statistical uncertainty.

See Also
EGS_ScoringSingle::currentResult(double,double)

Definition at line 280 of file egs_scoring.h.

void EGS_ScoringArray::reportResults ( double  norm,
const char *  title,
bool  relative_error,
const char *  format = 0 
)
Reports the results collected so far using egsInformation().

This function outputs the results collected so far using egsInformation() after printing the character string pointed to by title. The results are normalized using norm, i.e. the result output is sum of scores collected so far divided by the number of statistically independent events and multiplied with norm. The default output is of the form
element index result +/- uncertainty
for each element in the array, one element per line. If relative_error is true, the uncertainty output will be as percent of the result, otherwise the absolute value of the uncertainties will be output. The default format string used is d g +/- g, this can be modified by passing a non-null pointer to a format string with format.

Examples:
tutor2pp.cpp.

Definition at line 71 of file egs_scoring.cpp.

References current_ncase, EGS_ScoringSingle::currentResult(), egsInformation, egsWarning, nreg, and result.

bool EGS_ScoringArray::storeState ( ostream &  data)

Stores the state of the scoring array object into the data stream data.

This function can be used for storing intermediate results into a data file for later recovery in e.g. restarted calculations. The information stored in the number of element in the array nreg, the current short integer history counter, the current history counter, the current history counter divided by 65536 and the data from each of the nreg elements using their EGS_ScoringSingle::storeData function.

Definition at line 316 of file egs_scoring.h.

References egsStoreI64().

bool EGS_ScoringArray::setState ( istream &  data)

Sets the state fof the scoring array object from the data in the input stream data.

This function is useful for seting the state of the scoring object to a state previously stored using storeState() in e.g. restarted simulations.

Examples:
tutor7pp.cpp.

Definition at line 340 of file egs_scoring.h.

References egsGetI64().

EGS_ScoringArray& EGS_ScoringArray::operator+= ( const EGS_ScoringArray x)

Add the results of x to the rtesults of the invoking object.

This operator is useful for e.g. combining the results of parallel runs.

Definition at line 383 of file egs_scoring.h.

References current_ncase, and result.

Member Data Documentation

EGS_I64 EGS_ScoringArray::current_ncase
protected

Current statistically indepent event set with setHistory().

Definition at line 408 of file egs_scoring.h.

Referenced by operator+=(), reportResults(), and setHistory().

EGS_I64 EGS_ScoringArray::current_ncase_65536
protected

current_ncase divided by 65536

Definition at line 415 of file egs_scoring.h.

Referenced by setHistory().

int EGS_ScoringArray::nreg
protected

Number of elements (bins, regions) the scorring array has. Set in the object constructor.

Definition at line 418 of file egs_scoring.h.

Referenced by EGS_ScoringArray(), reportResults(), and setHistory().

EGS_ScoringSingle* EGS_ScoringArray::result
protected

The nreg scoring elements

Definition at line 420 of file egs_scoring.h.

Referenced by EGS_ScoringArray(), operator+=(), reportResults(), setHistory(), and ~EGS_ScoringArray().

unsigned short EGS_ScoringArray::current_ncase_short
protected

current_ncase%65536. This is needed because the individual elements of the array only use an unsigned 16 bit integer for their history number.

Definition at line 425 of file egs_scoring.h.

Referenced by setHistory().


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