101 EGS_DoseScoring::EGS_DoseScoring(
const string &Name,
104 norm_u(1.0), nreg(0), nmedia(0), max_dreg(-1), max_medl(0),
105 m_lastCase(-1),score_medium_dose(false), score_region_dose(false), output_dose_file(false) {
106 otype =
"EGS_DoseScoring";
109 EGS_DoseScoring::~EGS_DoseScoring() {
127 if (d_regionString.length() > 0 && d_region.size() < 1) {
128 getNumberRegions(d_regionString, d_region);
129 getLabelRegions(d_regionString, d_region);
133 nreg =
app->getnRegions();
135 nmedia =
app->getnMedia();
141 for (imed=0; imed < nmedia; imed++) {
142 sprintf(buf,
"%s%n",
app->getMediumName(imed),&count);
143 if (count > max_medl) {
147 if (d_region.size()>nreg)
148 egsWarning(
"\n*********************************************"
150 "\nRequesting %d dose scoring regions, but there"
151 "\nare only %d geometrical regions!"
152 "\nscoring will be done in all regions!"
153 "\n*********************************************",
154 d_region.size(),nreg);
157 if (score_region_dose) {
158 if (d_region.size() && d_region.size() < nreg) {
160 for (vector<int>::iterator it = d_region.begin(); it < d_region.end(); it++) {
161 if (*it > max_dreg) {
165 for (
int j=0; j<nreg; j++) {
166 d_reg_index.push_back(-1);
167 vol.push_back(vol_list[0]);
169 for (
int i=0; i<d_region.size(); i++) {
170 d_reg_index[d_region[i]]=i;
171 if (i < vol_list.size()) {
172 vol[d_region[i]] = vol_list[i];
175 if (score_region_dose) {
181 for (
int j=0; j<nreg; j++) {
182 d_reg_index.push_back(j);
183 if (j < vol_list.size()) {
184 vol.push_back(vol_list[j]);
187 vol.push_back(vol_list[0]);
190 if (score_region_dose) {
196 if (score_medium_dose) {
199 if (!score_region_dose) {
200 if (vol_list.size() == 1) {
201 vol.push_back(vol_list[0]);
204 for (
int j=0; j<nreg; j++) {
205 if (j < vol_list.size()) {
206 vol.push_back(vol_list[j]);
209 vol.push_back(vol_list[0]);
215 if (output_dose_file) {
217 for (
int i=0; i<nreg; i++) {
218 df_reg.push_back(-1);
226 EGS_Float minx,maxx,miny,maxy,minz,maxz;
227 for (
int k=0; k<nz; k++) {
228 for (
int j=0; j<ny; j++) {
229 for (
int i=0; i<nx; i++) {
239 int g_reg =
app->isWhere(tp);
240 df_reg[g_reg]=i+j*nx+k*nx*ny;
248 description =
"\n*******************************************\n";
252 description +=
"*******************************************\n";
259 description +=
" - Medium dose will be calculated\n";
261 description +=
"\n--------------------------------------\n";
262 sprintf(buf,
"%*s %*s rho/(g/cm^3)\n",max_medl/2,
"medium",max_medl/2,
" ");
264 description +=
"--------------------------------------\n";
265 for (imed=0; imed < nmedia; imed++) {
266 sprintf(buf,
"%-*s",max_medl,
app->getMediumName(imed));
269 sprintf(buf,
"%11.8f",
app->getMediumRho(imed));
273 description +=
"--------------------------------------\n";
275 description +=
" Non-unity user-requested normalization = ";
276 sprintf(buf,
"%g\n",norm_u);
279 description +=
"\n*******************************************\n\n";
281 if (d_region.size()) {
301 void EGS_DoseScoring::getNumberRegions(
const string &str, vector<int> ®s) {
305 void EGS_DoseScoring::getLabelRegions(
const string &str, vector<int> ®s) {
309 void EGS_DoseScoring::reportResults() {
310 egsInformation(
"\n======================================================\n");
312 egsInformation(
"======================================================\n");
313 EGS_Float normD = 1., normE=1.;
315 EGS_Float F =
app->getFluence();
319 normD = 1.602e-10*normE;
320 int irmax_digits = getDigits(max_dreg);
321 if (irmax_digits < 2) {
328 egsInformation(
"\n\n==> Summary of region dosimetry (per particle)\n\n");
330 "%*s %*s %12s %12s Edep (MeV) D (Gy) %n\n",
331 irmax_digits,
"ir",max_medl,
"medium",
"rho (g/cm^3)",
"Volume (cm^3)",&count);
334 egsInformation(
"\n==> Summary of region dosimetry (per fluence)\n");
336 "%*s %*s %12s %12s Edep (MeV*cm^2) D (Gy*cm^2) %n\n",
337 irmax_digits,
"ir",max_medl,
"medium",
"rho (g/cm^3)",
"Volume (cm^3)",&count);
339 line.append(count,
'-');
343 for (
int ireg = 0; ireg < nreg; ireg++) {
344 if (d_reg_index[ireg]>=0) {
349 EGS_Float rho =
app->getMediumRho(imed);
350 EGS_Float mass = vol[ireg]*rho;
358 egsInformation(
"%*d %-*s %11.8f %13.6f %12.4e +/- %-7.3f%% %10.4e +/- %-7.3f%%\n",
359 irmax_digits,ireg,max_medl,
app->getMediumName(imed),rho,vol[ireg],r*normE,dr*100.,r*normD/mass,dr*100.);
365 vector<EGS_Float> massM(nmedia,0);
367 for (
int ir=0; ir<nreg; ir++) {
374 EGS_Float volume = vol.size() > 1 ? vol[ir]:vol[0];
375 massM[imed] +=
app->getMediumRho(imed)*volume;
379 egsInformation(
"\n\n==> Summary of media dosimetry (per particle)\n");
381 "%*s %*s Edep/[MeV] D/[Gy] %n\n",
382 max_medl/2,
"medium",max_medl/2,
" ",&count);
385 egsInformation(
"\n\n==> Summary of media dosimetry (per fluence)\n");
387 "%*s %*s Edep/[MeV*cm2] D/[Gy*cm2] %n\n",
388 max_medl/2,
"medium",max_medl/2,
" ",&count);
391 line.append(count,
'-');
394 for (
int im=0; im<nmedia; im++) {
399 "%-*s %10.4e +/- %-7.3f%% %10.4e +/- %-7.3f%%\n",
400 max_medl,
app->getMediumName(im),r*normE,dr*100.,r*normD/massM[im],dr*100.);
407 egsInformation(
"\n EGS_DoseScoring: This is one of a number of parallel jobs. Will only output dose file on combining results.\n");
410 outputDoseFile(normD);
413 egsInformation(
"\n======================================================\n");
416 void EGS_DoseScoring::outputDoseFile(
const EGS_Float &normD) {
419 egsInformation(
"\n EGS_DoseScoring: Writing dose data for EGS_XYZGeometry %s... \n",dose_geom->
getName().c_str());
424 df_out.open(df_name.c_str());
426 egsFatal(
"\n EGS_DoseScoring: Error: Failed to open file %s\n",df_name.c_str());
434 df_out << nx <<
" " << ny <<
" " << nz <<
"\n";
436 float bound,
dose, doseun;
438 for (
int i=0; i<=nx; i++) {
440 df_out << bound <<
" ";
443 for (
int j=0; j<=ny; j++) {
445 df_out << bound <<
" ";
448 for (
int k=0; k<=nz; k++) {
450 df_out << bound <<
" ";
454 for (
int i=0; i<nx*ny*nz; i++) {
456 EGS_Float mass = dose_geom->
getVolume(i)*getRealRho(i);
458 df_out <<
dose <<
" ";
462 for (
int i=0; i<nx*ny*nz; i++) {
471 df_out << doseun <<
" ";
477 egsFatal(
"\n EGS_DoseScoring: Warning: Dose output file type not recognized.\n");
481 bool EGS_DoseScoring::storeState(ostream &data)
const {
499 bool EGS_DoseScoring::setState(istream &data) {
515 bool EGS_DoseScoring::addState(istream &data) {
516 int err = addTheStates(data);
523 int EGS_DoseScoring::addTheStates(istream &data) {
531 if (!tmp.setState(data)) {
538 if (!tmpM.setState(data)) {
548 if (!tmpF.setState(data)) {
556 void EGS_DoseScoring::resetCounter() {
596 const static char *func =
"createAusgabObject(dose_scoring)";
601 vector <EGS_Float> v_in;
605 vector<string> allowed_mode;
606 allowed_mode.push_back(
"no");
607 allowed_mode.push_back(
"yes");
608 int d_in_medium = input->
getInput(
"medium dose",allowed_mode,0);
609 int d_in_region = input->
getInput(
"region dose",allowed_mode,1);
612 string d_regionsString;
613 vector <int> d_regions;
614 bool using_all_regions=
true;
615 vector <int> d_start, d_stop;
616 if (!input->
getInput(
"dose regions",d_regionsString)&& d_regionsString.length()>0) {
617 using_all_regions =
false;
620 int err1 = input->
getInput(
"dose start region",d_start);
621 int err2 = input->
getInput(
"dose stop region",d_stop);
622 if (!err1 && !err2) {
623 if (d_start.size()==d_stop.size()) {
624 for (
int i=0; i<d_start.size(); i++) {
625 int ir = d_start[i], fr = d_stop[i];
626 for (
int ireg=ir; ireg<=fr; ireg++) {
627 d_regions.push_back(ireg);
630 using_all_regions =
false;
633 "%s: Mismatch in start and stop dose region groups !!!\n"
634 " Calculating dose in ALL regions.\n",func);
637 EGS_Float norma = 1.0;
638 int err04 = input->
getInput(
"normalization",norma);
646 vector <EGS_Float> volin;
648 if (! using_all_regions && v_in.size()== d_start.size()) {
649 for (
int i=0; i<d_start.size(); i++) {
650 int ir = d_start[i], fr = d_stop[i];
651 for (
int ireg=ir; ireg<=fr; ireg++) {
652 volin.push_back(v_in[i]);
661 bool outputdosefile=
false;
668 int err05 = fileinp->
getInput(
"geometry name",gname);
670 egsFatal(
"EGS_DoseScoring: Output dose file: missing/incorrect input for name of geometry.\n");
675 egsFatal(
"EGS_DoseScoring: Output dose file: %s does not name an existing geometry\n",gname.c_str());
677 else if (dgeom->
getType()!=
"EGS_XYZGeometry") {
678 egsFatal(
"EGS_DoseScoring: Output dose file: %s is not an EGS_XYZGeometry.\n",gname.c_str());
682 if (fileinp->
getInput(
"file type", str) < 0) {
686 vector<string> allowed_ftype;
687 allowed_ftype.push_back(
"3ddose");
688 ftype = fileinp->
getInput(
"file type", allowed_ftype, -1);
690 egsFatal(
"EGS_DoseScoring: Output dose file: Invalid file type. Currently only 3ddose is supported.\n");
703 if (volin.size()==1) {
704 result->setVol(volin[0]);
706 else if (volin.size()) {
707 result->setVol(volin);
712 if (!using_all_regions) {
713 if (d_regions.size() > 0) {
714 result->setDoseRegions(d_regions);
717 result->setDoseRegions(d_regionsString);
721 result->setMediumScoring(
true);
724 result->setRegionScoring(
true);
726 if (outputdosefile) {
727 result->setOutputFile(
true,dgeom,ftype);
731 result->setUserNorm(norma);
Base class for advanced EGSnrc C++ applications.
void getLabelRegions(const string &str, vector< int > ®s)
Gets the regions for the labels in str and pushes onto regs.
int getMedium(int ireg)
Returns the medium index in region ireg using C-style indexing.
bool isRealRegion(int ireg)
Returns true if ireg is a real region, false otherwise.
const string & getAppDir() const
Returns the absolute path to the user code directory.
void getNumberRegions(const string &str, vector< int > ®s)
Gets numbers out of str and pushes them onto regs.
int getIparallel() const
Returns the job number in a parallel run.
virtual void setApplication(EGS_Application *App)
Set the application this object belongs to.
string description
A short ausgab object description.
EGS_Application * app
The application this object belongs to.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual const string & getType() const =0
Get the geometry type.
virtual EGS_Float getVolume(int ireg)
Calculates the volume of region ireg.
const string & getName() const
Get the name of this geometry.
virtual int getNRegDir(int idir)
virtual EGS_Float getBound(int idir, int ind)
Returns region boundaries in direction determined by idir.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
A dose scoring object: header.
EGS_ScoringArray * doseF
Scoring dose in each voxel in EGS_XYZGeometry.
EGS_ScoringArray * doseM
Scoring dose in each medium.
EGS_I64 m_lastCase
The event set via setCurrentCase()
EGS_ScoringArray * dose
Scoring in each dose scoring region.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
const string & getObjectName() const
Get the object name.
string name
The object name.
A class for scoring an array of quantities (e.g. a dose distribution) in a Monte Carlo simulation.
int regions() const
Returns the number of regions (or elements or bins, the most appropriate term depending on the way th...
bool storeState(ostream &data)
Stores the state of the scoring array object into the data stream data.
void currentResult(int ireg, double &r, double &dr)
Sets r to the result in region ireg and dr to its statistical uncertainty.
void reset()
Reset the scoring array to a pristine state.
bool setState(istream &data)
Sets the state fof the scoring array object from the data in the input stream data.
A class representing 3D vectors.
A dose scoring ausgab object.
Global egspp functions header file.
EGS_RADIATIVE_SPLITTING_EXPORT EGS_AusgabObject * createAusgabObject(EGS_Input *input, EGS_ObjectFactory *f)
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,...
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.
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,...
string egsJoinPath(const string &first, const string &second)
Join two path variables (or a path and a file name) using the platform specific directory separator a...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.