EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_track_scoring.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ particle track scoring object
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: Iwan Kawrakow, 2009
25 #
26 # Contributors: Georgi Gerganov
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_track_scoring.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 EGS_TrackScoring::EGS_TrackScoring(const string &Name, EGS_ObjectFactory *f) :
42  EGS_AusgabObject(Name,f), m_pts(0), m_start(0), m_stop(1024), m_lastCase(-1),
43  m_nScore(0), m_bufSize(16), m_score(false), m_didScore(false),
44  m_score_photons(true), m_score_electrons(true), m_score_positrons(true), m_fnExtra("") {
45  otype = "EGS_TrackScoring";
46 }
47 
48 EGS_TrackScoring::~EGS_TrackScoring() {
49  if (m_pts) {
50  delete m_pts;
51  }
52 }
53 
54 void EGS_TrackScoring::setApplication(EGS_Application *App) {
56  if (!app) {
57  return;
58  }
59  if (m_pts) {
60  delete m_pts;
61  m_pts = 0;
62  }
63  if (m_bufSize < 1) {
64  m_bufSize = 1024;
65  }
66  string fname(app->getOutputFile());
67  fname += m_fnExtra;
68  if (!egsIsAbsolutePath(fname)) {
69  fname = egsJoinPath(app->getAppDir(),fname);
70  }
71  int i_parallel = -1;
72  if (app->getNparallel() > 1) {
73  i_parallel = app->getIparallel();
74  }
75  if (i_parallel >= 0) {
76  char buf[16];
77  sprintf(buf,"_w%d",i_parallel);
78  fname += buf;
79  }
80  fname += ".ptracks";
81  m_pts = new EGS_ParticleTrackContainer(fname.c_str(),m_bufSize);
82 
83  description = "\nParticle Track Scoring (";
84  description += name;
85  description += ")\n";
86  description += "======================================================\n";
87  description += " - Scoring photon tracks = ";
88  description += m_score_photons ? "YES\n" : "NO\n";
89  description += " - Scoring electron tracks = ";
90  description += m_score_electrons ? "YES\n" : "NO\n";
91  description += " - Scoring positron tracks = ";
92  description += m_score_positrons ? "YES\n" : "NO\n";
93  description += " - First event to score = ";
94  char buf[32];
95  sprintf(buf,"%lld\n",m_start);
96  description += buf;
97  description += " - Last event to score = ";
98  sprintf(buf,"%lld\n",m_stop);
99  description += buf;
100  description += " - Track buffer size = ";
101  sprintf(buf,"%d\n",m_bufSize);
102  description += buf;
103  description += " - Output file name = ";
104  description += fname;
105  description += "\n\n";
106 }
107 
108 void EGS_TrackScoring::reportResults() {
109  egsInformation("\nParticle Track Scoring (%s)\n",name.c_str());
110  egsInformation("======================================================\n");
111  egsInformation(" Total events scored: %lld\n",m_nScore);
112  if (m_pts) {
113  m_pts->reportResults(false);
114  }
115 }
116 
117 
118 extern "C" {
119 
120  EGS_TRACK_SCORING_EXPORT EGS_AusgabObject *createAusgabObject(EGS_Input *input,
121  EGS_ObjectFactory *f) {
122  const static char *func = "createAusgabObject(track_scoring)";
123  if (!input) {
124  egsWarning("%s: null input?\n",func);
125  return 0;
126  }
127  vector<string> sc_options;
128  sc_options.push_back("no");
129  sc_options.push_back("yes");
130  bool scph = input->getInput("score photons",sc_options,true);
131  bool scel = input->getInput("score electrons",sc_options,true);
132  bool scpo = input->getInput("score positrons",sc_options,true);
133  if (!scph && !scel && !scpo) {
134  return 0;
135  }
136  EGS_I64 first = 0, last = 1024;
137  input->getInput("start scoring",first);
138  input->getInput("stop scoring",last);
139  int bufSize = 1024;
140  input->getInput("buffer size",bufSize);
141  string fnExtra;
142  input->getInput("file name addition",fnExtra);
143  EGS_TrackScoring *result = new EGS_TrackScoring("",f);
144  result->setScorePhotons(scph);
145  result->setScoreElectrons(scel);
146  result->setScorePositrons(scpo);
147  result->setFirstEvent(first);
148  result->setLastEvent(last);
149  result->setBufferSize(bufSize);
150  result->setFileNameExtra(fnExtra);
151  result->setName(input);
152  return result;
153  }
154 
155 }
bool m_score_positrons
Score positron tracks?
bool m_score_photons
Score photon tracks?
string description
A short ausgab object description.
bool egsIsAbsolutePath(const string &path)
Does the string path represent an absolute path name?
EGS_ParticleTrackContainer * m_pts
The particle track container.
EGS_Input class header file.
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_I64 m_start
Minimum event index for which to score tracks.
int getIparallel() const
Returns the job number in a parallel run.
Global egspp functions header file.
int getNparallel() const
Returns the number of parallel jobs executing.
string m_fnExtra
String to append to output file name.
EGS_I64 m_nScore
Number of events for which tracks were scored.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
An object factory.
A class that stores all the tracks in a simulation.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
void reportResults(bool with_header=true)
Report results from the track scoring process so far.
string name
The object name.
EGS_I64 m_stop
Maximum event index for which to score tracks.
A track scoring ausgab object.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
A track scoring object: header.
const string & getAppDir() const
Returns the absolute path to the user code directory.
string otype
The object type.
int m_bufSize
The track container size.
virtual void setApplication(EGS_Application *App)
Set the application this object belongs to.
int getInput(const string &key, vector< string > &values) const
Assign values to an array of strings from an input identified by key.
Definition: egs_input.cpp:338
Base class for advanced EGSnrc C++ applications.
const string & getOutputFile() const
Returns the base name of the output file(s)
EGS_Application * app
The application this object belongs to.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
bool m_score_electrons
Score electron tracks?