EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_radiative_splitting.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ radiative splitting object headers
5 # Copyright (C) 2018 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: Ernesto Mainegra-Hing, 2018
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 #
30 # A general radiative splitting tool.
31 #
32 # TODO:
33 #
34 # - Add directional radiative splitting (DRS)
35 #
36 ###############################################################################
37 */
38 
39 
45 #ifndef EGS_RADIATIVE_SPLITTING_
46 #define EGS_RADIATIVE_SPLITTING_
47 
48 #include "egs_ausgab_object.h"
49 #include "egs_application.h"
50 #include "egs_scoring.h"
51 #include "egs_base_geometry.h"
52 
53 #ifdef WIN32
54 
55  #ifdef BUILD_RADIATIVE_SPLITTING_DLL
56  #define EGS_RADIATIVE_SPLITTING_EXPORT __declspec(dllexport)
57  #else
58  #define EGS_RADIATIVE_SPLITTING_EXPORT __declspec(dllimport)
59  #endif
60  #define EGS_RADIATIVE_SPLITTING_LOCAL
61 
62 #else
63 
64  #ifdef HAVE_VISIBILITY
65  #define EGS_RADIATIVE_SPLITTING_EXPORT __attribute__ ((visibility ("default")))
66  #define EGS_RADIATIVE_SPLITTING_LOCAL __attribute__ ((visibility ("hidden")))
67  #else
68  #define EGS_RADIATIVE_SPLITTING_EXPORT
69  #define EGS_RADIATIVE_SPLITTING_LOCAL
70  #endif
71 
72 #endif
73 
93 class EGS_RADIATIVE_SPLITTING_EXPORT EGS_RadiativeSplitting : public EGS_AusgabObject {
94 
95 public:
96 
98  enum Type {
99  URS, // EGSnrc Uniform Radiative Splitting
100  DRS, // Directional Radiative Splitting
101  DRSf // Directional Radiative Splitting (BEAMnrc)
102  };
103 
104  EGS_RadiativeSplitting(const string &Name="", EGS_ObjectFactory *f = 0);
105 
107 
108  void setApplication(EGS_Application *App);
110  void setSplitting(const int &n_s) {
111  nsplit = n_s;
112  if (nsplit < 0) {
113  nsplit *= -1;
114  i_play_RR = false;
115  }
116  else if (nsplit > 1) {
117  i_play_RR = true;
118  }
119  /* Avoid zero division. A zero value turns off brems */
120  wthin = nsplit ? 1./nsplit : 1.0;
121  };
122 
123  bool needsCall(EGS_Application::AusgabCall iarg) const {
124  if (
128  iarg == EGS_Application::AfterBrems ||
132  return true;
133  }
134  else {
135  return false;
136  }
137  };
138 
140 
141  /* A fat particle's weight is larger than a thin particle's max weight */
142  bool is_phat = (app->top_p.wt - wthin) > epsilon;
143  bool is_primary = app->top_p.latch == 0 ? true : false;
144 
145  /* Split radiative events ONLY for primary and fat electrons */
146  if (iarg == EGS_Application::BeforeBrems ||
149  (is_primary || is_phat)) {
150  app->setRadiativeSplitting(nsplit);
151  }
152  /* Avoids higher order splitting of radiative events */
153  else if (iarg == EGS_Application::AfterBrems ||
156  app->setRadiativeSplitting(1);
157  app->setLatch(app->getNpOld()+1,1);
158  }
159  /* Fluorescent photons created by charged particles surviving RR
160  when radiative splitting ON should be split to avoid having heavy photons.
161  This should happen in EGSnrc, but it is not implemented yet, so do it here!
162  Note that when this is implemented in EGSnrc, the weight check will make sure
163  photons aren't split again!
164  */
165  if (iarg == EGS_Application::FluorescentEvent && is_phat && nsplit > 1) {
166  app->splitTopParticleIsotropically(nsplit);
167  }
168 
169 
170  return 0;
171  };
172 
173 protected:
174  /* Max weight of thin particles */
175  EGS_Float wthin;
176  /* Maximum splitting limited to 2,147,483,647. Negative value switches OFF RR. */
177  int nsplit;
178  /* Switch for Russian Roulette */
179  bool i_play_RR;
180 
181 };
182 
183 #endif
Base class for advanced EGSnrc C++ applications.
AusgabCall
Possible calls to the user scoring function ausgab().
@ BeforeBrems
before a bremsstrahlung interaction
@ AfterBrems
after a bremsstrahlung interaction
@ AfterAnnihRest
after annihilation at rest
@ AfterAnnihFlight
after annihilation in flight
@ FluorescentEvent
a fluorescent transition just occured
@ BeforeAnnihRest
before annihilation at rest
@ BeforeAnnihFlight
before annihilation in flight
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 bool needsCall(EGS_Application::AusgabCall iarg) const
Is the ausgab call iarg relevant for this object?
An object factory.
A radiative splitting object: header.
void setSplitting(const int &n_s)
EGS_Application class header file.
EGS_AusgabObject interface class header file.
EGS_BaseGeometry class header file.
EGS_ScoringSingle and EGS_ScoringArray class header file.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:62