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:
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_scoring.h"
38 #include "egs_functions.h"
39 
40 #include <string>
41 using std::string;
42 
44  current_ncase(0), current_ncase_65536(0), current_ncase_short(0) {
45  if (N <= 0) egsFatal("EGS_ScoringArray::EGS_ScoringArray:\n"
46  " attempt to construct a scoring array with non-positive size\n");
47  result = new EGS_ScoringSingle [N];
48  nreg = N;
49 }
50 
52  delete [] result;
53 }
54 
55 void EGS_ScoringArray::setHistory(EGS_I64 ncase) {
56  if (ncase != current_ncase) {
57  current_ncase = ncase;
58  EGS_I64 aux = ncase >> 16;
59  if (aux != current_ncase_65536) {
60  current_ncase_65536 = aux;
61  for (int j=0; j<nreg; j++) {
62  result[j].finishCase(0,0);
63  }
64  }
65  aux = ncase - (aux << 16);
66  unsigned short aux1 = (unsigned short) aux;
67  current_ncase_short = aux1;
68  }
69 }
70 
71 void EGS_ScoringArray::reportResults(double norm, const char *title,
72  bool relative_error, const char *format) {
73  if (title) egsInformation("\n\n%s for %lli particles:\n\n",title,
75  if (current_ncase < 2) {
76  egsWarning("EGS_ScoringArray::reportResults: you must run more than 2 "
77  "histories\n\n");
78  return;
79  }
80  char c = (relative_error) ? '%' : ' ';
81  string myformat = " %d %g +/- %g %c\n";
82  const char *oformat = format ? format : myformat.c_str();
83  for (int j=0; j<nreg; j++) {
84  double r,dr;
86  if (relative_error) {
87  dr = (r > 0) ? 100*dr/r : 100;
88  }
89  else {
90  dr *= norm;
91  }
92  egsInformation(oformat,j,r*norm,dr,c);
93  }
94 }
EGS_ScoringArray(int N)
Construct a scoring array with N elements.
Definition: egs_scoring.cpp:43
unsigned short current_ncase_short
Definition: egs_scoring.h:425
EGS_I64 current_ncase
Definition: egs_scoring.h:408
void setHistory(EGS_I64 ncase)
Set the current statistically independent event to ncase.
Definition: egs_scoring.cpp:55
Global egspp functions header file.
EGS_ScoringSingle * result
Definition: egs_scoring.h:420
void finishCase(unsigned short new_case, EGS_Float new_result)
Finish the current &#39;case&#39; (event) and start a new event with index new_case and a score of new_result...
Definition: egs_scoring.h:90
EGS_I64 current_ncase_65536
Definition: egs_scoring.h:415
A class for scoring a single quantity of interest in a Monte Carlo simulation.
Definition: egs_scoring.h:63
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
void reportResults(double norm, const char *title, bool relative_error, const char *format=0)
Definition: egs_scoring.cpp:71
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_ScoringSingle and EGS_ScoringArray class header file.
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
~EGS_ScoringArray()
Destructor. Deallocates all allocated memory.
Definition: egs_scoring.cpp:51
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.