48 int size = ((int)fmt.size()) * 2 + 50;
54 int n = vsnprintf((
char *)str.data(), size, fmt.c_str(), ap);
56 if (n > -1 && n < size) {
77 size_t i = s.rfind(sep, s.length());
78 if (i != string::npos) {
79 return (s.substr(i+1, s.length() - i));
89 types.push_back(
"surface count");
90 types.push_back(
"energy weighted surface");
91 types.push_back(
"fluence in region");
92 types.push_back(
"energy fluence in region");
94 string type = types[inp->getInput(
"type", types, 0)];
97 if (type ==
"surface count") {
99 }
else if (type ==
"energy weighted surface") {
101 }
else if (type ==
"fluence in region") {
103 }
else if (type ==
"energy fluence in region") {
107 if (!scorer || !scorer->
isValid()) {
126 int err = input->getInput(
"minimum energy",
e_min);
131 err = input->getInput(
"maximum energy",
e_max);
136 err = input->getInput(
"number of bins",
nbins);
137 if (err ||
nbins < 1) {
141 vector<string> particle_choices;
142 particle_choices.push_back(
"photon");
143 particle_choices.push_back(
"electron");
144 particle_choices.push_back(
"positron");
145 particle_type = input->getInput(
"particle type", particle_choices, 0);
155 err = input->getInput(
"file extension",
fextension);
160 vector<string> choices;
161 choices.push_back(
"xmgr");
162 choices.push_back(
"csv");
163 choices.push_back(
"egsnrc");
164 int choice = input->getInput(
"output format", choices, 0);
168 err = input->getInput(
"egsnrc format mode",
egsnrc_mode);
172 if (egsnrc_mode < 0 || egsnrc_mode > 2) {
173 egsWarning(
"Unsupported egsnrc spectrum output format mode. Defaulting to mode 0\n");
208 double rest_mass = p->q == 0 ? 0 : the_useful->prm;
209 return (p->E - rest_mass);
217 }
else if (
format ==
"egsnrc") {
219 }
else if (
format ==
"xmgr") {
226 egsInformation(
"\n%s\n",sep.c_str());
227 egsInformation(
"%s\n",
getTitle().c_str());
231 "Energy range : %.3FMeV <= E <= %.3FMeV (%d bins of width %.3GMeV)\n",
235 egsInformation(
"%s\n",sep.c_str());
243 out.open(fname.c_str());
246 for (
int i=0; i <
nbins; i++) {
260 out.open(fname.c_str());
261 out <<
"egs_brachy scored spectrum"<<
"\n";
268 double top, prob, r, dr;
269 for (
int i=0; i <
nbins; i++) {
282 double r, dr, norm=0;
284 vector<double> probabilities;
287 for (
int i=0; i <
nbins; i++) {
292 probabilities.push_back(r);
297 for (
size_t i = 0; i < mids.size(); i++) {
301 out <<
string_format(
"%.5E,%.5E\n", mids[i], probabilities[i]/norm);
313 out.open(fname.c_str());
314 out <<
"# EGS_Brachy spectrum\n";
316 out <<
"@ legend 0.2, 0.8\n";
317 out <<
"@ legend box linestyle 0\n";
318 out <<
"@ legend font 4\n";
320 out <<
"@ xaxis label char size 1.3\n";
321 out <<
"@ xaxis label font 4\n";
322 out <<
"@ xaxis ticklabel font 4\n";
324 out <<
"@ yaxis label char size 1.3\n";
325 out <<
"@ yaxis label font 4\n";
326 out <<
"@ yaxis ticklabel font 4\n";
327 out <<
"@ title \"" <<
getTitle() <<
"\"\n";
328 out <<
"@ title font 4\n";
329 out <<
"@ title size 1.500000\n";
331 out <<
"@ subtitle font 4\n";
332 out <<
"@ subtitle size 1.000000\n";
334 out<<
"@ s0 errorbar linestyle 0\n";
335 out<<
"@ s0 legend \"Spectrum\"\n";
336 out<<
"@target G0.S0\n";
339 double mid, bot, top, r, dr;
340 for (
int i=0; i <
nbins; i++) {
372 score(message, data);
378 bins->currentResult(i, r, dr);
385 bool ok =
bins->storeState(*ofile);
398 bool ok =
bins->setState(*ifile);
418 EGS_I64 cur_history_tmp, eff_history_tmp;
419 EGS_Float total_scored_tmp;
420 EGS_ScoringArray tmp_bins(
bins->regions());
422 data >> cur_history_tmp >> eff_history_tmp;
423 data >> total_scored_tmp;
424 bool ok = tmp_bins.setState(data);
444 EGS_Particle *p=
static_cast<EGS_Particle *
>(data);
458 bins->currentResult(i, r, dr);
468 egsInformation(
"Scoring metric : absolute photon counts on surface of source\n") ;
479 EGS_Particle *p=
static_cast<EGS_Particle *
>(data);
493 bins->currentResult(i, r, dr);
502 egsInformation(
"Scoring metric : Energy weighted spectrum on surface of source\n") ;
503 egsInformation(
"Total Radiant E : %.5G MeV\n",
total_scored);
515 EGS_Particle *p=
static_cast<EGS_Particle *
>(data);
518 bool in_energy_scoring_range = (
e_min <= p->E) && (p->E <=
e_max);
521 if (in_scoring_region && in_energy_scoring_range && correct_particle) {
522 EGS_Float
score = the_epcont->tvstep*p->wt;
533 bins->currentResult(i, r, dr);
542 egsInformation(
"Scoring metric : Fluence in region\n") ;
543 egsInformation(
"Scoring region (global) : %d \n",
scoring_region) ;
545 egsInformation(
"Region Volume : %.3G cm^3\n",
region_volume) ;
546 egsInformation(
"Total E fluence : %.5G MeV/cm^2\n",
total_scored);
558 EGS_Particle *p=
static_cast<EGS_Particle *
>(data);
561 bool in_energy_scoring_range = (
e_min <= p->E) && (p->E <=
e_max);
564 if (in_scoring_region && in_energy_scoring_range && correct_particle) {
565 EGS_Float
score = p->E*the_epcont->tvstep*p->wt;
576 bins->currentResult(i, r, dr);
585 egsInformation(
"Scoring metric : Energy fluence in region\n") ;
586 egsInformation(
"Scoring region (global) : %d \n",
scoring_region) ;
588 egsInformation(
"Region Volume : %.3G cm^3\n",
region_volume) ;
589 egsInformation(
"Total E fluence : %.5G MeV/cm^2\n",
total_scored);
abstract base class for scoring spectrum information
virtual string getSubTitle() const
EGS_ScoringArray * bins
spectrum scoring array
int readData(istream *ifile)
string getParticleName() const
Return name of particle we are scoring.
EGS_Float getBinWidth() const
void setEffectiveHistories(EGS_Float effective_histories)
string outputCSV(string filename)
output results to csv file
int addState(istream &data)
int nbins
number of bins to score spectrum in
virtual void getResult(int bin, EGS_Float &r, EGS_Float &dr)
set r & dr to result/uncertainty for given bin. Normalization can be done in this routine
string outputXMGR(string filename)
output results to xmgrace file
static BaseSpectrumScorer * getSpectrumScorer(EGS_Input *inp, EGS_BaseSource *source, GeomInfo *ginfo, Publisher *publisher)
factory method for creating one of the derived spectrum scoring classes
virtual void score(EB_Message message, void *data=0)=0
virtual string getTitle() const
int getBin(EGS_Float E) const
get index of bin that that E falls in
virtual void update(EB_Message message, void *data=0)
Receives messages from application. This method handles NEW_HISTORY messages but delegates all other ...
virtual void outputTotal()
BaseSpectrumScorer(EGS_Input *input, EGS_BaseSource *src, GeomInfo *ginfo, Publisher *publisher)
int outputData(ostream *ofile)
string getFileName(string root) const
virtual ~BaseSpectrumScorer()
static const int DEFAULT_NBINS
virtual string getXAxisLabel() const
EGS_Float e_max
maximum spectrum energy to score
virtual string getYAxisLabel() const
double getParticleEnergy(const EGS_Particle *p) const
string outputEGSnrc(string filename)
output results to EGSnrc tabulated spectrum format
EGS_Float e_min
minimum spectrum energy to score
int outputResults(string root_name)
, write the scored spectrum to file with filename. Returns 0 on success, all other values indicate a ...
A class for scoring the energy fluence of particles enter a voxel of the scoring phantom geometry.
EGS_BaseGeometry * geometry
virtual void score(EB_Message message, void *data=0)
void getResult(int bin, EGS_Float &r, EGS_Float &dr)
set r & dr to result/uncertainty for given bin. Normalization can be done in this routine
A class for scoring the energy weighted spectrum (normalized to total radiant energy) of particles on...
void getResult(int bin, EGS_Float &r, EGS_Float &dr)
set r & dr to result/uncertainty for given bin. Normalization can be done in this routine
virtual void score(EB_Message message, void *data=0)
A class for scoring the fluence of particles enter a voxel of the scoring phantom geometry.
virtual void score(EB_Message message, void *data=0)
void getResult(int bin, EGS_Float &r, EGS_Float &dr)
set r & dr to result/uncertainty for given bin. Normalization can be done in this routine
EGS_BaseGeometry * geometry
a container for organizing meta data about the geometries
void subscribe(Subscriber *s, EB_Message message)
A class for scoring a histogram of the number of particles escaping a source geometry.
void getResult(int bin, EGS_Float &r, EGS_Float &dr)
set r & dr to result/uncertainty for given bin. Normalization can be done in this routine
virtual void score(EB_Message message, void *data=0)
@ PARTICLE_ESCAPING_SOURCE
std::string string_format(const std::string fmt,...)
string getFileNameFromPath(const string &s)
Definition of spectrum scoring classes.