EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_scoring.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ scoring
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors: Berit Behnke
27 # Reid Townson
28 #
29 ###############################################################################
30 */
31 
32 
38 #include "egs_scoring.h"
39 #include "egs_functions.h"
40 
41 #include <string>
42 using std::string;
43 
45  current_ncase(0), current_ncase_65536(0), current_ncase_short(0) {
46  if (N <= 0) egsFatal("EGS_ScoringArray::EGS_ScoringArray:\n"
47  " attempt to construct a scoring array with non-positive size\n");
48  result = new EGS_ScoringSingle [N];
49  nreg = N;
50 }
51 
53  delete [] result;
54 }
55 
56 void EGS_ScoringArray::setHistory(EGS_I64 ncase) {
57  if (ncase != current_ncase) {
58  current_ncase = ncase;
59  EGS_I64 aux = ncase >> 16;
60  if (aux != current_ncase_65536) {
61  current_ncase_65536 = aux;
62  for (int j=0; j<nreg; j++) {
63  result[j].finishCase(0,0);
64  }
65  }
66  aux = ncase - (aux << 16);
67  unsigned short aux1 = (unsigned short) aux;
68  current_ncase_short = aux1;
69  }
70 }
71 
72 void EGS_ScoringArray::reportResults(double norm, const char *title,
73  bool relative_error, const char *format) {
74  if (title) egsInformation("\n\n%s for %lli particles:\n\n",title,
76  if (current_ncase < 2) {
77  egsWarning("EGS_ScoringArray::reportResults: you must run more than 2 "
78  "histories\n\n");
79  return;
80  }
81  char c = (relative_error) ? '%' : ' ';
82  string myformat = " %d %g +/- %g %c\n";
83  const char *oformat = format ? format : myformat.c_str();
84  for (int j=0; j<nreg; j++) {
85  double r,dr;
87  if (relative_error) {
88  dr = (r > 0) ? 100*dr/r : 100;
89  }
90  else {
91  dr *= norm;
92  }
93  egsInformation(oformat,j,r*norm,dr,c);
94  }
95 }
~EGS_ScoringArray()
Destructor. Deallocates all allocated memory.
Definition: egs_scoring.cpp:52
EGS_I64 current_ncase_65536
Definition: egs_scoring.h:415
EGS_I64 current_ncase
Definition: egs_scoring.h:408
EGS_ScoringArray(int N)
Construct a scoring array with N elements.
Definition: egs_scoring.cpp:44
void setHistory(EGS_I64 ncase)
Set the current statistically independent event to ncase.
Definition: egs_scoring.cpp:56
EGS_ScoringSingle * result
Definition: egs_scoring.h:420
void reportResults(double norm, const char *title, bool relative_error, const char *format=0)
Definition: egs_scoring.cpp:72
unsigned short current_ncase_short
Definition: egs_scoring.h:425
A class for scoring a single quantity of interest in a Monte Carlo simulation.
Definition: egs_scoring.h:63
void finishCase(unsigned short new_case, EGS_Float new_result)
Finish the current 'case' (event) and start a new event with index new_case and a score of new_result...
Definition: egs_scoring.h:90
void currentResult(EGS_I64 ncase, double &r, double &dr)
Sets r to the current result and dr to its statistical uncertainty assuming ncase statistically indep...
Definition: egs_scoring.h:122
Global egspp functions header file.
EGS_ScoringSingle and EGS_ScoringArray class header file.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.