EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
/Users/marc/Developer/EGSnrc/HEN_HOUSE/user_codes/egs_brachy/egs_brachy/phantom.h
Go to the documentation of this file.
1/*
2################################################################################
3#
4# egs_brachy phantom.h
5# Copyright (C) 2016 Rowan Thomson, Dave Rogers, Randle Taylor, and Marc
6# Chamberland
7#
8# This file is part of egs_brachy
9#
10# egs_brachy is free software: you can redistribute it and/or modify it
11# under the terms of the GNU Affero General Public License as published
12# by the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# egs_brachy is distributed in the hope that it will be useful, but
16# WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18# Affero General Public License for more details:
19# <http://www.gnu.org/licenses/>.
20#
21################################################################################
22#
23# When egs_brachy is used for publications, please cite our paper:
24# M. J. P. Chamberland, R. E. P. Taylor, D. W. O. Rogers, and R. M. Thomson,
25# egs brachy: a versatile and fast Monte Carlo code for brachytherapy,
26# Phys. Med. Biol. 61, 8214-8231 (2016).
27#
28################################################################################
29#
30# Author: Randle Taylor, 2016
31#
32# Contributors: Marc Chamberland
33# Dave Rogers
34# Rowan Thomson
35#
36################################################################################
37*/
38
44#ifndef EB_PHANTOM_
45#define EB_PHANTOM_
46
47#include <map>
48#include <set>
49#include "egs_scoring.h"
50#include "egs_application.h"
51#include "egs_interface2.h"
52#include "pubsub.h"
53
56struct RegionResult;
57
71class EB_Phantom : public Subscriber {
72
73private:
74
75 const static string autovol_phantom_geom_types[];
76 const static string threeddose_geom_types[];
77
78 EGS_Application *app;
79 EGS_ScoringArray *tlen_score;
80 EGS_ScoringArray *edep_score;
81 EGS_ScoringArray *prim_score;
82 EGS_ScoringArray *sscat_score;
83
84 EGS_ScoringArray *mscat_score;
85
87 EGS_Float dose_scale;
88
89 EGS_Float total_radiant_e;
90 EGS_I64 cur_history;
92
94
95 std::map<int, double> corrected_volumes;
96 std::map<int, double> volume_uncertainty;
99 void outputDoseStats(EGS_ScoringArray *score, string type);
100
102 void outputTopDoses(int top_n, vector<RegionResult> region_results);
103
105 void output3ddoseResults(string);
106
108 void output3DDoses(ostream &out, EGS_ScoringArray *score, string type);
109
111 void output3DBounds(ostream &out);
112
114 void outputEGSPhant(string);
115
117 void writeEGSPhant(ostream &);
118
120 string medIndex(int medium);
121
124 vector<RegionResult> getRegionResults();
125
127 void getScoringArrays(vector<EGS_ScoringArray *> &scores, vector<string> &types, vector<string> &descriptions);
128
130 void getEGSdatScoringArrays(vector<EGS_ScoringArray *> &scores);
131
132
133public:
134
140
142 EB_Phantom(EGS_Application *, EGS_BaseGeometry *, set<int> global_regions, int nsource, Publisher *publisher);
143
146
147 if (tlen_score) {
148 delete tlen_score;
149 }
150 if (edep_score) {
151 delete edep_score;
152 }
153 if (prim_score) {
154 delete prim_score;
155 }
156 if (sscat_score) {
157 delete sscat_score;
158 }
159 if (mscat_score) {
160 delete mscat_score;
161 }
162
163 };
164
167 static bool needsUserVolumes(const string &geom_type);
168
171 static bool canWrite3ddose(const string &geom_type);
172
174 void scoreTlen(int ir, EGS_Float dose, EGS_Particle *p);
175
177 void scoreEdep(int ir, EGS_Float dose);
178
180 void getCurrentScore(int ireg, double &sum, double &sum2);
181
182 double getTlenNorm(int ireg);
183
185 void setDoseScale(EGS_Float);
186
187 void update(EB_Message message, void *data);
188
189 bool hasVolCor(int ireg);
190
192 EGS_Float getCorrectedVolume(int ireg);
193
195 EGS_Float getVolumeUncertainty(int ireg);
196
198 EGS_Float getUncorrectedVolume(int ireg);
199
200
202 vector<int> getRegionsWithCorrections();
203
205 void setCorrectedVolume(int ir, double fraction, double unc=0);
206
210 void enableTLenScoring();
211
216
221
222
224 void setHistory(EGS_I64 current_case);
225
227 void setEffectiveHistories(EGS_Float current_case);
228
230 EGS_Float avgVoxelVol();
231
233 void outputVoxelInfo(string format);
234
236 void writeVoxelInfo(ostream &);
237
239 void outputVolumeCorrection(string format);
240
242 void writeVolumeCorrection(ostream &);
243
245 void outputResults(int top_n=20, string output_3ddose="text", string output_egsphant="text",
246 string output_voxinfo="text", string output_volcor="text");
247
249 bool globalRegIsInPhant(int global_reg) {
250 return (global_reg_start <= global_reg) && (global_reg <= global_reg_stop);
251 }
252
254 int globalToLocal(int global_reg) {
255 if ((global_reg_start <= global_reg) && (global_reg <= global_reg_stop)) {
256 return global_reg - global_reg_start;
257 }
258
259 return -1;
260 }
261
262
263
264 int outputData(ostream *ofile);
265 int readData(istream *ifile);
266 void resetCounter();
267 int addState(istream &ifile);
268
270 EGS_Float getRealRho(int ireg);
271
273 EGS_Float getRealMass(int ireg);
274
276 EGS_Float getUncorrectedMass(int ireg);
277
280 void getResult(EGS_ScoringArray *, int ireg, string type, EGS_Float &r, EGS_Float &dr);
281
282
284 EGS_BaseGeometry *geometry;
285
292
295
298
299};
300
301#endif
A class to represent a single phantom for scoring dose in egs_brachy.
Definition phantom.h:71
@ YDIR
YDIR=1 y dir for rectilinear, r dir for cylindrical.
Definition phantom.h:137
@ XDIR
XDIR=0 x dir for rectilinear, r dir for spherical, z dir for cylindrical.
Definition phantom.h:136
@ ZDIR
ZDIR=2 z dir for rectilinear.
Definition phantom.h:138
void getResult(EGS_ScoringArray *, int ireg, string type, EGS_Float &r, EGS_Float &dr)
get result for region from scoring array and normalize based on the type requested.
Definition phantom.cpp:349
void outputEGSPhant(string)
initialize and write an egsphant file for this phantom
Definition phantom.cpp:833
void scoreTlen(int ir, EGS_Float dose, EGS_Particle *p)
add tracklength dose to region ir
Definition phantom.cpp:133
bool hasVolCor(int ireg)
Definition phantom.cpp:310
void output3ddoseResults(string)
write the phantom boundaries, doses and uncertainties to 3ddose file
Definition phantom.cpp:688
void outputVoxelInfo(string format)
write voxel volumes, mass, desnity etc
Definition phantom.cpp:897
std::map< int, double > volume_uncertainty
Definition phantom.h:96
int global_reg_stop
ending global region index for this phantom
Definition phantom.h:294
~EB_Phantom()
EB_Phantom destructor.
Definition phantom.h:145
void update(EB_Message message, void *data)
Definition phantom.cpp:124
bool can_write_3ddose
this phantom can output 3ddose files
Definition phantom.h:297
EGS_Float getUncorrectedVolume(int ireg)
get corrected volume for a given region
Definition phantom.cpp:302
EGS_BaseGeometry * geometry
the phantom geometry object
Definition phantom.h:284
void getCurrentScore(int ireg, double &sum, double &sum2)
get current tlen score for region
Definition phantom.cpp:332
void output3DDoses(ostream &out, EGS_ScoringArray *score, string type)
write input scoring array to 3ddose file
Definition phantom.cpp:758
vector< int > getRegionsWithCorrections()
return a vector of all regions which were corrected
Definition phantom.cpp:194
bool globalRegIsInPhant(int global_reg)
check whether a global region falls within this phantom
Definition phantom.h:249
double getTlenNorm(int ireg)
Definition phantom.cpp:344
int global_reg_start
starting global region index for this phantom
Definition phantom.h:293
EGS_Float effective_histories
Definition phantom.h:91
void outputTopDoses(int top_n, vector< RegionResult > region_results)
write the top_n doses to console
Definition phantom.cpp:567
EGS_Float getRealRho(int ireg)
return actual density for region
Definition phantom.cpp:285
void resetCounter()
Definition phantom.cpp:1022
void writeVolumeCorrection(ostream &)
write voxel volumes to file
Definition phantom.cpp:922
void setEffectiveHistories(EGS_Float current_case)
set number of effective histories for normalizing scoring arrays
Definition phantom.cpp:253
void enableScatterScoring()
enableInteractionScoring must be called before simulation begins if you want to score dose with inter...
Definition phantom.cpp:222
void setHistory(EGS_I64 current_case)
set current history on scoring arrays for proper statistics
Definition phantom.cpp:234
bool needs_user_geoms
this phantom requires user specified geometries
Definition phantom.h:296
static const string threeddose_geom_types[]
Definition phantom.h:101
int readData(istream *ifile)
Definition phantom.cpp:977
void scoreEdep(int ir, EGS_Float dose)
add energy deposition dose to region ir
Definition phantom.cpp:155
EGS_Float getRealMass(int ireg)
return (corrected) real mass for region
Definition phantom.cpp:291
static const string autovol_phantom_geom_types[]
Definition phantom.h:97
EGS_Application * app
Parent application instance. Required for constructing filenames.
Definition phantom.h:78
EGS_ScoringArray * sscat_score
Tracklenth scored dose from single scattered particles.
Definition phantom.h:82
vector< RegionResult > getRegionResults()
create a vector of RegionResult structs which can then be sorted by dose value. used for output routi...
Definition phantom.cpp:377
EGS_Float total_radiant_e
Definition phantom.h:89
void setCorrectedVolume(int ir, double fraction, double unc=0)
Allow user to tell phantom what the actual volume of a region is.
Definition phantom.cpp:202
void getScoringArrays(vector< EGS_ScoringArray * > &scores, vector< string > &types, vector< string > &descriptions)
get all active scoring arrays, their types and descriptions
Definition phantom.cpp:636
string medIndex(int medium)
get medium index 1-9A-Z
Definition phantom.cpp:823
int globalToLocal(int global_reg)
convert global region to local phantom region
Definition phantom.h:254
EGS_ScoringArray * mscat_score
Tracklenth scored dose from multiple scattered particles.
Definition phantom.h:84
static bool canWrite3ddose(const string &geom_type)
function for checking whether a given geometry type can output 3ddose files
Definition phantom.cpp:180
void outputResults(int top_n=20, string output_3ddose="text", string output_egsphant="text", string output_voxinfo="text", string output_volcor="text")
tell phantom to output its results.
Definition phantom.cpp:259
int addState(istream &ifile)
Definition phantom.cpp:996
EGS_ScoringArray * prim_score
Tracklenth scored dose from primary particles.
Definition phantom.h:81
void writeEGSPhant(ostream &)
write actual egsphant data to file for this phantom
Definition phantom.cpp:781
void getEGSdatScoringArrays(vector< EGS_ScoringArray * > &scores)
get all active scoring arrays for writing to egsdat file
Definition phantom.cpp:668
void enableTLenScoring()
enableTLenScoring must be called before simulation begins if you want to score dose with tracklength ...
Definition phantom.cpp:208
void outputDoseStats(EGS_ScoringArray *score, string type)
write some stats about dose arrays
Definition phantom.cpp:408
Publisher * publisher
Definition phantom.h:93
EGS_I64 cur_history
Definition phantom.h:90
EGS_ScoringArray * tlen_score
Tracklength dose scoring array.
Definition phantom.h:79
std::map< int, double > corrected_volumes
Corrected volume in a given region.
Definition phantom.h:95
void outputVolumeCorrection(string format)
intialize and output write voxel volumes to file
Definition phantom.cpp:934
EGS_Float dose_scale
Definition phantom.h:87
void output3DBounds(ostream &out)
write the phantom bounds to 3ddose file
Definition phantom.cpp:735
EGS_Float getCorrectedVolume(int ireg)
get uncorrected volume for a given region
Definition phantom.cpp:314
void setDoseScale(EGS_Float)
set dose scaling factor for output
Definition phantom.cpp:162
static bool needsUserVolumes(const string &geom_type)
function for checking whether a given geometry type requires user specified volumes
Definition phantom.cpp:166
void writeVoxelInfo(ostream &)
write voxel info file
Definition phantom.cpp:865
int outputData(ostream *ofile)
Definition phantom.cpp:958
set< int > global_regions
the set of all global regions contained in this phantom
Definition phantom.h:291
EGS_Float getUncorrectedMass(int ireg)
return uncorrected for region
Definition phantom.cpp:298
int nsources
Definition phantom.h:86
EGS_Float getVolumeUncertainty(int ireg)
get volume unc
Definition phantom.cpp:323
void enableInteractionScoring()
enableInteractionScoring must be called before simulation begins if you want to score dose with inter...
Definition phantom.cpp:215
EGS_Float avgVoxelVol()
return average voxel volume
Definition phantom.cpp:855
EGS_ScoringArray * edep_score
Interaction scored dose scoring array.
Definition phantom.h:80
A simple pub/sub module to allow various egs_brachy classes to subscribe to particle events.
EB_Message
Definition pubsub.h:54