EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
beam_dose_scoring.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ beampp dose scoring object headers
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: Blake Walters, 2014
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 #
30 # A dose scoring ausgab object for beampp: Allows the user to score dose in
31 # specified CMs on a region-by-region and/or medium-by-medium basis. Volumes
32 # of all regions are assumed to be 1 cm^3 unless explicitly specified by the
33 # user.
34 #
35 ###############################################################################
36 */
37 
38 
44 #ifndef BEAM_DOSE_SCORING_
45 #define BEAM_DOSE_SCORING_
46 
47 #include "egs_ausgab_object.h"
48 #include "egs_application.h"
49 #include "beampp_class.h"
50 #include "egs_scoring.h"
51 #include "egs_interface2.h"
52 
53 #ifdef WIN32
54 
55  #ifdef BUILD_DOSE_SCORING_DLL
56  #define BEAM_DOSE_SCORING_EXPORT __declspec(dllexport)
57  #else
58  #define BEAM_DOSE_SCORING_EXPORT __declspec(dllimport)
59  #endif
60  #define BEAM_DOSE_SCORING_LOCAL
61 
62 #else
63 
64  #ifdef HAVE_VISIBILITY
65  #define BEAM_DOSE_SCORING_EXPORT __attribute__ ((visibility ("default")))
66  #define BEAM_DOSE_SCORING_LOCAL __attribute__ ((visibility ("hidden")))
67  #else
68  #define BEAM_DOSE_SCORING_EXPORT
69  #define BEAM_DOSE_SCORING_LOCAL
70  #endif
71 
72 #endif
73 
74 
85 class BEAM_DOSE_SCORING_EXPORT BEAM_DoseScoring : public EGS_AusgabObject {
86 
87 public:
88 
89  BEAM_DoseScoring(const string &Name="", EGS_ObjectFactory *f = 0);
90 
92 
94 
95  int ir = app->top_p.ir, imed = ir>=0 ? app->getMedium(ir):-1;
96  EGS_Float edep = app->getEdep();
97 
98  if (d_reg_index[ir]<0) {
99  return 0;
100  }
101 
102  /**** energy deposition in current region ***/
103  if (iarg <= 4 && ir >= 0 && edep > 0 && dose) {
104  dose->score(d_reg_index[ir], edep*app->top_p.wt);
105  }
106 
107  /**** energy deposition in a medium ***/
108  //put it here so it doesn't get scored if this is not a scoring region
109  if (iarg <= 4 && imed >= 0 && edep > 0 && doseM) {
110  doseM->score(imed+nmedia*d_reg_cm_ind[ir], edep*app->top_p.wt);
111  }
112  return 0;
113  };
114 
115  bool needsCall(EGS_Application::AusgabCall iarg) const {
116  return true;
117  };
118 
119  void setApplication(EGS_Application *App);
120 
121  void reportResults();
122 
123  void setCurrentCase(EGS_I64 ncase) {
124  if (ncase != m_lastCase) {
125  m_lastCase = ncase;
126  if (dose) {
127  dose->setHistory(ncase);
128  }
129  if (doseM) {
130  doseM->setHistory(ncase);
131  }
132  }
133  };
134  int getDigits(int i) {
135  int imax = 10;
136  while (i>=imax) {
137  imax*=10;
138  }
139  return (int)log10((float)imax);
140  };
141 
142  void setVol(const vector<EGS_Float> volin) {
143  vol_list=volin;
144  };
145  void setVol(const EGS_Float volin) {
146  vol_list.push_back(volin);
147  };
148  void setDoseCMs(const vector <int> dcm) {
149  d_cms=dcm;
150  };
151  void setMediumScoring(bool flag) {
152  score_medium_dose=flag;
153  };
154  void setRegionScoring(bool flag) {
155  score_region_dose=flag;
156  };
157 
158  bool storeState(ostream &data) const;
159  bool setState(istream &data);
160  void resetCounter();
161  bool addState(istream &data);
162  int addTheStates(istream &data);
163 
164 protected:
165  BEAMpp_Application *bapp;
168  vector <EGS_Float> vol_list; // Input list of region volumes
169  vector <int> d_cms; // List of CMs for which dose is to be output
170  vector <int> d_region; // Input list of dose scoring regions d_reg[i] = ir
171  vector <int> d_reg_index; // list index for dose scoring regions d_reg_index[ir]= 0..d_reg.size()-1
172  vector <int> d_reg_cm_ind; // dose CM index for each dose region. Allows quick scoring of medium dose.
173  vector < vector <int> > cm_med; // list of media present in CMs in which dose is scored
174  vector <EGS_Float> vol; // geometrical region volumes
175  int nreg, // number of regions in the geometry
176  nmedia; // number of media in the input file
177  int max_dreg, // maximum dose region number
178  max_medl; // maximum medium name length
179  EGS_I64 m_lastCase;
180  bool score_medium_dose,
181  score_region_dose;
182 };
183 
184 #endif
EGS_ScoringArray * dose
Scoring in each dose scoring region.
A class for scoring an array of quantities (e.g. a dose distribution) in a Monte Carlo simulation...
Definition: egs_scoring.h:219
EGS_AusgabObject interface class header file.
virtual int processEvent(EGS_Application::AusgabCall iarg)=0
Process an ausgab call for event iarg.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
This file defines the C/C++ interface to the EGSnrc mortran back-end.
AusgabCall
Possible calls to the user scoring function ausgab().
virtual void resetCounter()
Reset the ausgab object state.
EGS_ScoringArray * doseM
Scoring dose in each medium.
virtual bool needsCall(EGS_Application::AusgabCall iarg) const
Is the ausgab call iarg relevant for this object?
A dose scoring object: header.
virtual bool setState(istream &data_in)
Set the ausgab object state based on data from the stream data_in.
virtual void reportResults()
Report results.
An object factory.
EGS_I64 m_lastCase
The event set via setCurrentCase()
virtual bool addState(istream &data_in)
Add data from the stream data_in to the ausgab object state.
EGS_ScoringSingle and EGS_ScoringArray class header file.
virtual void setCurrentCase(EGS_I64 ncase)
Set the current event.
virtual void setApplication(EGS_Application *App)
Set the application this object belongs to.
EGS_Application class header file.
Base class for advanced EGSnrc C++ applications.