51 BEAM_DoseScoring::BEAM_DoseScoring(
const string &Name,
54 dose(0), doseM(0), max_dreg(-1), max_medl(0),
55 score_medium_dose(false), score_region_dose(false) {
56 otype =
"BEAM_DoseScoring";
59 BEAM_DoseScoring::~BEAM_DoseScoring() {
71 bapp =
dynamic_cast<BEAMpp_Application *
>(
app);
76 nreg =
app->getnRegions();
78 nmedia =
app->getnMedia();
82 for (
int i=0; i<d_cms.size(); i++) {
84 for (
int j=0; j<nmedia; j++) {
85 med_ind.push_back(-1);
87 cm_med.push_back(med_ind);
89 for (
int i=0; i<d_cms.size(); i++) {
94 d_start = bapp->CM_reg_end(d_cms[i]-1)+1;
96 d_end = bapp->CM_reg_end(d_cms[i]);
97 for (
int j=d_start; j<=d_end; j++) {
100 if (bapp->IsRegionReal(j)) {
101 d_region.push_back(j);
110 for (imed=0; imed < nmedia; imed++) {
111 sprintf(buf,
"%s%n",
app->getMediumName(imed),&count);
112 if (count > max_medl) {
118 if (d_region.size()) {
120 for (vector<int>::iterator it = d_region.begin(); it < d_region.end(); it++) {
121 if (*it > max_dreg) {
125 for (
int j=0; j<nreg; j++) {
126 d_reg_index.push_back(-1);
127 d_reg_cm_ind.push_back(-1);
130 for (
int i=0; i<d_region.size(); i++) {
131 d_reg_index[d_region[i]]=i;
132 if (d_region[i] < vol_list.size()) {
133 vol[d_region[i]] = vol_list[d_region[i]];
135 for (
int j=0; j<d_cms.size(); j++) {
136 if (d_region[i]<=bapp->CM_reg_end(d_cms[j])) {
137 d_reg_cm_ind[d_region[i]]=j;
142 if (score_region_dose) {
147 if (score_medium_dose) {
151 description =
"\n*******************************************\n";
155 description +=
"*******************************************\n";
156 description +=
"\n Dose will be calculated in CM no.'s (start region - end region):\n";
157 for (
int i=0; i<d_cms.size(); i++) {
159 sprintf(buf,
"%d (0 - %d)\n",d_cms[i],bapp->CM_reg_end(d_cms[i]));
162 sprintf(buf,
"%d (%d - %d)\n",d_cms[i],bapp->CM_reg_end(d_cms[i]-1)+1,bapp->CM_reg_end(d_cms[i]));
168 description +=
" - Region dose will be calculated\n";
171 description +=
" - Medium dose will be calculated\n";
173 description +=
"\n--------------------------------------\n";
174 sprintf(buf,
"%*s %*s rho/[g/cm**3]\n",max_medl/2,
"medium",max_medl/2,
" ");
176 description +=
"--------------------------------------\n";
177 for (imed=0; imed < nmedia; imed++) {
178 sprintf(buf,
"%-*s",max_medl,
app->getMediumName(imed));
181 sprintf(buf,
"%5.2f",
app->getMediumRho(imed));
185 description +=
"\n*******************************************\n\n";
186 if (d_region.size()) {
191 void BEAM_DoseScoring::reportResults() {
192 egsInformation(
"\n======================================================\n");
194 egsInformation(
"======================================================\n");
195 EGS_Float normD = 1., normE=1.;
197 EGS_Float F =
app->getFluence();
201 for (
int i=0; i<d_cms.size(); i++) {
205 normD = 1.602e-10*normE;
206 int irmax_digits = getDigits(max_dreg);
211 egsInformation(
"\n\n==> Summary of region dosimetry (per particle)\n");
213 "CM %-*s %-*s %-*s rho/[g/cm3] V/cm3 Edep/[MeV] D/[Gy] %n\n",
214 irmax_digits,
"ir",irmax_digits,
"CM reg.",max_medl,
"medium",&count);
217 egsInformation(
"\n==> Summary of region dosimetry (per fluence)\n");
219 "CM %-*s %-*s %-*s rho/[g/cm3] V/cm3 Edep/[MeV*cm2] D/[Gy*cm2] %n\n",
220 irmax_digits,
"ir",irmax_digits,
"CM reg.",max_medl,
"medium",&count);
222 line.append(count,
'-');
226 for (
int i=0; i<d_cms.size(); i++) {
231 ir_cm = bapp->CM_reg_end(d_cms[i]-1)+1;
233 fr_cm = bapp->CM_reg_end(d_cms[i]);
234 for (
int ireg = ir_cm; ireg <= fr_cm; ireg++) {
235 if (d_reg_index[ireg]>=0) {
240 EGS_Float rho =
app->getMediumRho(imed);
241 EGS_Float mass = vol[ireg]*rho;
249 egsInformation(
"%-2d %-*d %-*d %-*s %7.3f %7.3f %10.4e +/- %-7.3f%% %10.4e +/- %-7.3f%%\n",
250 d_cms[i],max(irmax_digits,2),ireg,max(irmax_digits,7),ireg-ir_cm,max_medl,
app->getMediumName(imed),rho,vol[ireg],r*normE,dr*100.,r*normD/mass,dr*100.);
257 vector<EGS_Float> massM(d_cms.size()*nmedia,0);
259 for (
int ir=0; ir<nreg; ir++) {
260 if (d_reg_index[ir]>=0) {
262 massM[imed+d_reg_cm_ind[ir]*nmedia] +=
app->getMediumRho(imed)*vol[ir];
266 egsInformation(
"\n\n==> Summary of media dosimetry (per particle)\n");
268 "CM %*s %*s Edep/[MeV] D/[Gy] %n\n",
269 max_medl/2,
"medium",max_medl/2,
" ",&count);
272 egsInformation(
"\n\n==> Summary of media dosimetry (per fluence)\n");
274 "CM %*s %*s Edep/[MeV*cm2] D/[Gy*cm2] %n\n",
275 max_medl/2,
"medium",max_medl/2,
" ",&count);
278 line.append(count,
'-');
281 for (
int i=0; i<d_cms.size(); i++) {
282 for (
int im=0; im<nmedia; im++) {
284 if (cm_med[i][im] >= 0) {
292 "%-2d %-*s %10.4e +/- %-7.3f%% %10.4e +/- %-7.3f%%\n",
293 d_cms[i],max_medl,
app->getMediumName(im),r*normE,dr*100.,r*normD/massM[im+i*nmedia],dr*100.);
299 egsInformation(
"\n======================================================\n");
302 bool BEAM_DoseScoring::storeState(ostream &data)
const {
317 bool BEAM_DoseScoring::setState(istream &data) {
330 bool BEAM_DoseScoring::addState(istream &data) {
331 int err = addTheStates(data);
339 int BEAM_DoseScoring::addTheStates(istream &data) {
347 if (!tmp.setState(data)) {
354 if (!tmpM.setState(data)) {
362 void BEAM_DoseScoring::resetCounter() {
377 const static char *func =
"createAusgabObject(beam_dose_scoring)";
384 int err1=input->
getInput(
"dose CMs",d_cms);
386 egsWarning(
"%s: No CMs input. Dose will not be scored.\n",func);
390 vector<string> allowed_mode;
391 allowed_mode.push_back(
"no");
392 allowed_mode.push_back(
"yes");
393 int d_in_medium = input->
getInput(
"medium dose",allowed_mode,0);
394 int d_in_region = input->
getInput(
"region dose",allowed_mode,1);
395 if (d_in_medium == 0 && d_in_region == 0) {
396 egsWarning(
"%s: Neither dose in regions nor dose in medium specified. Dose will not be scored.\n",func);
399 vector <int> vreg_start,vreg_stop;
400 vector <EGS_Float> v_in,volin;
402 int err2 = input->
getInput(
"start volume region",vreg_start);
403 int err3 = input->
getInput(
"stop volume region",vreg_stop);
404 int err4 = input->
getInput(
"volume",v_in);
406 egsWarning(
"%s: No dose zone volumes input. Will assume 1 cm^3 for all regions.\n",func);
409 if (!err2 && !err3) {
410 if (vreg_start.size()==vreg_stop.size()) {
411 if (v_in.size()<vreg_start.size()) {
412 egsWarning(
"%s: No volumes input for region groups %d to %d.\n Will use last input volume for remaining groups.\n",func,v_in.size()+1,vreg_start.size());
413 for (
int i=v_in.size()+1; i<vreg_start.size(); i++) {
414 v_in.push_back(v_in[v_in.size()-1]);
417 for (
int i=0; i<vreg_start.size(); i++) {
418 if (volin.size()<=vreg_stop[i]) {
420 for (
int j=volin.size(); j<=vreg_stop[i]; j++) {
421 volin.push_back(1.0);
424 for (
int j=vreg_start[i]; j<=vreg_stop[i]; j++) {
430 egsWarning(
"%s: Unequal number of start and stop regions. Will assume 1 cm^3 for all regions.\n",func);
439 result->setVol(volin);
444 result->setDoseCMs(d_cms);
446 result->setMediumScoring(
true);
449 result->setRegionScoring(
true);
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...
bool EGS_EXPORT egsGetI64(istream &data, EGS_I64 &n)
Reads a 64 bit integer from the stream data and assigns it to n. Returns true on success, false on failure.
string description
A short ausgab object description.
bool EGS_EXPORT egsStoreI64(ostream &data, EGS_I64 n)
Writes the 64 bit integer n to the output stream data and returns true on success, false on failure.
Global egspp functions header file.
EGS_ScoringArray * doseM
Scoring dose in each medium.
bool setState(istream &data)
Sets the state fof the scoring array object from the data in the input stream data.
bool storeState(ostream &data)
Stores the state of the scoring array object into the data stream data.
bool isRealRegion(int ireg)
Returns true if ireg is a real region, false otherwise.
A dose scoring object: header.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
void reset()
Reset the scoring array to a pristine state.
void currentResult(int ireg, double &r, double &dr)
Sets r to the result in region ireg and dr to its statistical uncertainty.
A dose scoring ausgab object for beampp.
int getMedium(int ireg)
Returns the medium index in region ireg using C-style indexing.
EGS_I64 m_lastCase
The event set via setCurrentCase()
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
string name
The object name.
Base class for advanced EGSnrc C++ applications.
EGS_Application * app
The application this object belongs to.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.