EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_track_scoring.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ particle track scoring object headers
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 # Alexandre Demelo
28 #
29 ###############################################################################
30 */
31 
32 
38 #ifndef EGS_TRACK_SCORING_
39 #define EGS_TRACK_SCORING_
40 
41 #include "egs_ausgab_object.h"
42 #include "egs_application.h"
43 #include "egs_particle_track.h"
44 
45 #ifdef WIN32
46 
47  #ifdef BUILD_TRACK_SCORING_DLL
48  #define EGS_TRACK_SCORING_EXPORT __declspec(dllexport)
49  #else
50  #define EGS_TRACK_SCORING_EXPORT __declspec(dllimport)
51  #endif
52  #define EGS_TRACK_SCORING_LOCAL
53 
54 #else
55 
56  #ifdef HAVE_VISIBILITY
57  #define EGS_TRACK_SCORING_EXPORT __attribute__ ((visibility ("default")))
58  #define EGS_TRACK_SCORING_LOCAL __attribute__ ((visibility ("hidden")))
59  #else
60  #define EGS_TRACK_SCORING_EXPORT
61  #define EGS_TRACK_SCORING_LOCAL
62  #endif
63 
64 #endif
65 
96 class EGS_TRACK_SCORING_EXPORT EGS_TrackScoring : public EGS_AusgabObject {
97 
98 public:
99 
100  EGS_TrackScoring(const string &Name="", EGS_ObjectFactory *f = 0);
101 
102  ~EGS_TrackScoring();
103 
105  if (m_score) {
106  if (!m_didScore) {
107  m_didScore = true;
108  ++m_nScore;
109  }
110  int np = app->Np;
111  if (m_pts->isScoringParticle(np)) {
112  if (iarg == EGS_Application::AfterTransport) {
113  m_pts->addVertex(np,new EGS_ParticleTrack::Vertex(app->top_p.x,app->top_p.E));
114  }
115  else if (iarg != EGS_Application::BeforeTransport) {
116  m_pts->stopScoringParticle(np);
117  }
118  }
119  else if (iarg == EGS_Application::BeforeTransport) {
120  int q = app->top_p.q;
121  EGS_Float timeindex = app->getTimeIndex(); // get current time index from the source (through the application.cpp)
122  if ((q == 0 && m_score_photons) ||
123  (q == -1 && m_score_electrons) ||
124  (q == 1 && m_score_positrons)) {
125  m_pts->startNewTrack(np);
126  m_pts->setCurrentParticleInfo(new EGS_ParticleTrack::ParticleInfo(q));
127  m_pts->setCurrentTimeIndex(timeindex); // set current time index for the particle track container object
128  m_pts->addVertex(np,new EGS_ParticleTrack::Vertex(app->top_p.x,app->top_p.E));
129  }
130  }
131  }
132  return 0;
133  };
134 
135  bool needsCall(EGS_Application::AusgabCall iarg) const {
136  return true;
137  };
138 
139  void setApplication(EGS_Application *App);
140 
141  void reportResults();
142 
143  void setCurrentCase(EGS_I64 ncase) {
144  if (ncase != m_lastCase) {
145  m_lastCase = ncase;
146  m_didScore = false;
147  }
148  if (ncase < m_start || ncase > m_stop) {
149  m_score = false;
150  }
151  else {
152  m_score = true;
153  }
154  };
155 
156  void setScorePhotons(bool score) {
157  m_score_photons = score;
158  };
159  void setScoreElectrons(bool score) {
160  m_score_electrons = score;
161  };
162  void setScorePositrons(bool score) {
163  m_score_positrons = score;
164  };
165  void setIncludeTime(bool incltime) {
166  m_include_time = incltime;
167  };
168  void setAutoDetectDynamic(bool autoDetectDynamic) {
169  m_autoDetectDynamic = autoDetectDynamic;
170  };
171  void setFirstEvent(EGS_I64 first) {
172  m_start = first;
173  };
174  void setLastEvent(EGS_I64 last) {
175  m_stop = last;
176  };
177  void setBufferSize(int size) {
178  m_bufSize = size;
179  };
180  void setFileNameExtra(const string &extra) {
181  m_fnExtra = extra;
182  };
183 
184 protected:
185 
187 
188  EGS_I64 m_start;
189  EGS_I64 m_stop;
190  EGS_I64 m_lastCase;
191  EGS_I64 m_nScore;
192 
193  int m_bufSize;
194 
195  bool m_score;
196  bool m_didScore;
197 
203 
204  string m_fnExtra;
205 
206 };
207 
208 #endif
Base class for advanced EGSnrc C++ applications.
AusgabCall
Possible calls to the user scoring function ausgab().
@ BeforeTransport
before the step
@ AfterTransport
after the step
virtual void setApplication(EGS_Application *App)
Set the application this object belongs to.
virtual int processEvent(EGS_Application::AusgabCall iarg)=0
Process an ausgab call for event iarg.
virtual void reportResults()
Report results.
virtual void setCurrentCase(EGS_I64 ncase)
Set the current event.
virtual bool needsCall(EGS_Application::AusgabCall iarg) const
Is the ausgab call iarg relevant for this object?
An object factory.
A class that stores all the tracks in a simulation.
A track scoring object: header.
EGS_I64 m_lastCase
The event set via setCurrentCase()
EGS_I64 m_start
Minimum event index for which to score tracks.
bool m_score
Should tracks be scored?
bool m_score_electrons
Score electron tracks?
bool m_include_time
include time index in tracks file?
string m_fnExtra
String to append to output file name.
bool m_autoDetectDynamic
Option for autodetecting whether to include time indices.
EGS_I64 m_stop
Maximum event index for which to score tracks.
int m_bufSize
The track container size.
EGS_ParticleTrackContainer * m_pts
The particle track container.
bool m_score_photons
Score photon tracks?
EGS_I64 m_nScore
Number of events for which tracks were scored.
bool m_score_positrons
Score positron tracks?
bool m_didScore
Did the last event score tracks?
EGS_Application class header file.
EGS_AusgabObject interface class header file.
EGS_ParticleTrack class header file.
Structure describing the particle being tracked.
Structure to store the data for each interaction along the track.