42 #ifndef EGS_APPLICATION_
43 #define EGS_APPLICATION_
69 inline void addmcBlock(shared_ptr<EGS_InputStruct> blockPtr) {
70 shared_ptr<EGS_BlockInput> mcBlock = blockPtr->addBlockInput(
"MC transport parameter");
71 mcBlock->addSingleInput(
"Global ECUT",
false,
"Global electron transport cutoff");
72 mcBlock->addSingleInput(
"Global PCUT",
false,
"Global photon transport cutoff");
73 mcBlock->addSingleInput(
"Global SMAX",
false,
"Global maximum step-size restriction for e-transport");
74 mcBlock->addSingleInput(
"ESTEPE",
false,
"The maximum fractional energy loss in an electron step due to continuous energy loss. Defaults to 0.25");
75 mcBlock->addSingleInput(
"XIMAX",
false,
"Maximum first GS moment per step. Defaults to 0.5, maximum value is 1.");
76 mcBlock->addSingleInput(
"Boundary crossing algorithm",
false,
"Defaults to exact", {
"exact",
"PRESTA-I"});
77 mcBlock->addSingleInput(
"Skin depth for BCA",
false,
"The distance from a boundary to turn on electron single scattering, in mean free paths of the current medium. Set to a very large value to do a single scattering simulation. Defaults to 3 for exact boundary crossing");
78 mcBlock->addSingleInput(
"Electron-step algorithm",
false,
"Defaults to PRESTA-II", {
"PRESTA_II",
"PRESTA_I"});
79 mcBlock->addSingleInput(
"Spin effects",
false,
"Includes relativistic spin effects in electron scattering (On is highly recommended). Defaults to On", {
"On",
"Off"});
80 mcBlock->addSingleInput(
"Brems angular sampling",
false,
"Defaults to KM", {
"KM",
"Simple"});
81 mcBlock->addSingleInput(
"Brems cross sections",
false,
"Defaults to BH", {
"BH",
"NIST"});
82 mcBlock->addSingleInput(
"Pair angular sampling",
false,
"Defaults to Simple", {
"Simple",
"Off",
"KM"});
83 mcBlock->addSingleInput(
"Pair cross sections",
false,
"Defaults to BH. Use NRC at low energies to consider asymmetry in positron-electron energy distribution.", {
"BH",
"NRC"});
84 mcBlock->addSingleInput(
"Triplet production",
false,
"Defaults to On", {
"On",
"Off"});
85 mcBlock->addSingleInput(
"Electron Impact Ionization",
false,
"For more accurate kV x-ray simulations, turn this on. Defaults to Off", {
"On",
"Off",
"casnati",
"kolbenstvedt",
"gryzinski"});
86 mcBlock->addSingleInput(
"Bound Compton scattering",
false,
"Defaults to norej", {
"On",
"Off",
"Simple",
"norej"});
87 mcBlock->addSingleInput(
"Radiative Compton corrections",
false,
"Defaults to Off", {
"On",
"Off"});
88 mcBlock->addSingleInput(
"Rayleigh scattering",
false,
"Defaults to Off", {
"On",
"Off",
"custom"});
89 mcBlock->addSingleInput(
"Photoelectron angular sampling",
false,
"Defaults to On", {
"On",
"Off"});
90 mcBlock->addSingleInput(
"Atomic relaxations",
false,
"Defaults to on", {
"On",
"Off"});
91 mcBlock->addSingleInput(
"Photon cross sections",
false,
"Defaults to xcom, can also be user-supplied", {
"si",
"epdl",
"xcom"});
92 mcBlock->addSingleInput(
"Photon cross-sections output",
false,
"Defaults to Off", {
"On",
"Off"});
93 mcBlock->addSingleInput(
"Compton cross sections",
false,
"User-supplied, Defaults to comp-xsections");
94 mcBlock->addSingleInput(
"Photonuclear attenuation",
false,
"Defaults to Off", {
"On",
"Off"});
95 mcBlock->addSingleInput(
"Photonuclear cross sections",
false,
"Defaults to default, or is user-supplied", {
"default"});
98 inline void addMediaDefBlock(shared_ptr<EGS_InputStruct> blockPtr) {
99 shared_ptr<EGS_BlockInput> mediaBlockInput = blockPtr->addBlockInput(
"media definition");
100 mediaBlockInput->addSingleInput(
"ae",
false,
"Lowest energy for electron production (kinetic+0.511) in MeV. Minimum and most accurate value is 0.521.");
101 mediaBlockInput->addSingleInput(
"ap",
false,
"Lowest energy for photon production (kinetic) in MeV. Minimum and most accurate value is 0.001.");
102 mediaBlockInput->addSingleInput(
"ue",
false,
"Maximum energy for electrons (kinetic+0.511) in MeV. Set to just above the maximum source energy.");
103 mediaBlockInput->addSingleInput(
"up",
false,
"Maximum energy for photons (kinetic) in MeV. Set to just above the maximum source energy.");
105 mediaBlockInput->addSingleInput(
"material data file",
false,
"The full file path to a file containing material data. See HEN_HOUSE/pegs4/data/material.dat for an example containing all the materials from 521ICRU.pegs4dat and 700ICRU.pegs4dat.");
107 shared_ptr<EGS_BlockInput> mediumBlock = mediaBlockInput->addBlockInput(
"myMediumName");
108 mediumBlock->addSingleInput(
"elements",
false,
"A list of elements, separated by commas");
109 auto atomsPtr = mediumBlock->addSingleInput(
"number of atoms",
false,
"For each of the elements, the number of atoms in a molecule of the medium, separated by commas. If the medium is a mixture, use mass fractions instead.");
110 auto fractionsPtr = mediumBlock->addSingleInput(
"mass fractions",
false,
"For each of the elements, the mass fraction of that element in the mixture, comma separated.");
111 mediumBlock->addSingleInput(
"rho",
false,
"The bulk density of the medium in g/cm^3");
112 mediumBlock->addSingleInput(
"sterncid",
false,
"Material ID for the STERNHEIMER-SELTZER-BERGER (SSB) lookup table");
113 mediumBlock->addSingleInput(
"stopping powers",
false,
"This parameter allows various stopping powers to be calculated, rather than just the restricted total stopping powers. This allows for simulations that model various types of CSDA calculations. Defaults to restricted total.", {
"restricted total",
"unrestricted collision",
"unrestricted collision and radiative",
"unrestricted collision and restricted radiative",
"restricted collision and unrestricted radiative",
"unrestricted radiative"});
114 mediumBlock->addSingleInput(
"bremsstrahlung correction",
false,
"Corrections to apply to calculated bremsstrahlung cross-sections. Defaults to KM", {
"KM",
"NRC",
"None"});
115 mediumBlock->addSingleInput(
"gas pressure",
false,
"The pressure in atm of this medium, assuming it is a gas. This is only applied if a density correction file is not used. To apply a gas pressure in that case, generate a new density correction file with the appropriately scaled density.");
116 mediumBlock->addSingleInput(
"e- stopping power output file",
false,
"An output filename to write electron stopping powers to.");
118 atomsPtr->addDependency(fractionsPtr,
"",
true);
119 fractionsPtr->addDependency(atomsPtr,
"",
true);
122 inline string addmcExample() {
125 :start MC transport parameter:
126 Global ECUT = 0.521 # Global electron transport cutoff
127 Global PCUT = 0.001 # Global photon transport cutoff
128 Global SMAX = 1e10 # Global maximum step-size restriction for e- transport
129 ESTEPE = 0.25 # Defaults to 0.25
130 XIMAX = 0.5 # Defaults to 0.5, max. value is 1.
131 Boundary crossing algorithm = exact # exact (default), PRESTA-I
132 Skin depth for BCA = 3 # Default value is 3 for exact boundary crossing
133 Electron-step algorithm = PRESTA-II # PRESTA-II (default),PRESTA-I
134 Spin effects = On # On (default), Off
135 Brems angular sampling = KM # Simple, KM (default)
136 Brems cross sections = BH # BH (default), NIST, NRC
137 Pair angular sampling = Simple # Off, Simple (default), KM
138 Pair cross sections = BH # NRC, BH (default)
139 Triplet production = Off # On, Off (default)
140 Electron Impact Ionization = Off # On, Off (default), casnati, kolbenstvedt, gryzinski
141 Bound Compton scattering = norej # On, Off, Simple, norej (default)
142 Radiative Compton corrections = Off # On, Off (default)
143 Rayleigh scattering = Off # On, Off (default), custom
144 Photoelectron angular sampling = On # On (default), Off
145 Atomic relaxations = On # On (default), Off
146 Photon cross sections = xcom # si, epdl, xcom (default) or user-supplied
147 Photon cross-sections output = Off # Off (default), On
148 Compton cross sections = comp_xsections # User-supplied
149 Photonuclear attenuation = Off # Off (default), On
150 Photonuclear cross sections = default # default (default), user-supplied
151 :stop MC transport parameter:
156 inline string addMediaExample() {
160 :start media definition:
161 ae = 0.521 # lowest energy for electron production (kinetic+0.511)
162 ap = 0.01 # lowest energy for photon production (kinetic)
163 ue = 50.511 # maximum energy for electrons (kinetic+0.511)
164 up = 50 # maximum energy for photons (kinetic) # maximum energy for photons (kinetic)
166 # Here is an example for defining water
168 density correction file = water_liquid
171 :stop media definition:
428 virtual int initSimulation();
439 virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun,
int npar,
int nchunk);
462 virtual int runSimulation();
472 virtual int finishSimulation();
480 virtual void describeSimulation();
496 virtual int simulateSingleShower();
503 virtual void getCurrentResult(
double &sum,
double &sum2,
double &norm,
516 virtual void analyzeResults() {};
523 virtual void outputResults() {};
538 virtual int combineResults();
546 virtual int combinePartialResults();
555 int howManyJobsDone();
573 virtual int outputData();
589 virtual int readData();
599 const string &getAppName()
const {
604 const string &getEgsHome()
const {
609 const string &getHenHouse()
const {
614 const string &getOutputFile()
const {
626 const string &getFinalOutputFile()
const {
627 return final_output_file;
637 string constructIOFileName(
const char *extension,
bool with_run_dir)
const;
640 const string &getAppDir()
const {
645 const string &getRunDir()
const {
650 const string &getWorkDir()
const {
669 BeforeAnnihFlight = 12,
670 AfterAnnihFlight = 13,
671 BeforeAnnihRest = 28,
684 FluorescentEvent = 25,
685 CosterKronigEvent = 26,
692 AfterSubElectron = 34,
701 virtual void setAusgabCall(AusgabCall call,
bool on_or_off) {
702 ausgab_flag[call] = on_or_off;
712 int getNparallel()
const {
722 int getIparallel()
const {
732 int getFirstParallel()
const {
733 return first_parallel;
741 EGS_Float &t,
int *newmed) {
743 geometry->resetErrorFlag();
745 int inew = geometry->howfar(ireg,x,u,t,newmed);
746 storeGeometryStep(ireg,inew,x,u,twant,t);
747 if (geometry->getLastError()) {
748 reportGeometryError();
759 inline EGS_Float hownear(
int ireg,
const EGS_Vector &x) {
760 return geometry->hownear(ireg,x);
764 inline int getMedium(
int ireg) {
765 return geometry->medium(ireg);
775 bool isRealRegion(
int ireg) {
776 return geometry->isRealRegion(ireg);
779 return geometry->isWhere(r);
783 int getGlobalRegionOffset(
const string geomName) {
784 return geometry->getGlobalRegionOffset(geomName);
802 void getNumberRegions(
const string &str, vector<int> ®s) {
803 geometry->getNumberRegions(str, regs);
814 void getLabelRegions(
const string &str, vector<int> ®s) {
815 geometry->getLabelRegions(str, regs);
826 EGS_Float getTimeIndex() {
827 return source->getTimeIndex();
833 void setTimeIndex(EGS_Float temp_time) {
834 source->setTimeIndex(temp_time);
843 int userScoring(
int iarg,
int ir=-1);
850 virtual int ausgab(
int) {
864 virtual void startNewParticle() { };
884 virtual void enterNewRegion() { };
894 virtual void fillRandomArray(
int n, EGS_Float *rns);
932 virtual EGS_I64 randomNumbersUsed()
const;
942 virtual void getElectronSteps(
double &ch_steps,
double &all_steps)
const {
959 virtual int addState(istream &data);
970 virtual void resetCounter();
979 virtual void describeUserCode()
const {};
983 virtual void appInformation(
const char *);
987 virtual void appWarning(
const char *);
991 virtual void appFatal(
const char *);
995 void checkDeviceFull(FILE *);
1006 static bool getArgument(
int &argc,
char **argv,
1007 const char *name1,
const char *name2,
string &arg);
1015 static void checkEnvironmentVar(
int &argc,
char **argv,
const char *env,
1016 const char *n1,
const char *n2,
string &var);
1033 virtual int initGeometry();
1048 virtual int initSource();
1064 virtual int initCrossSections() {
1075 virtual int initScoring() {
1095 virtual int initRunControl();
1108 virtual int initRNG();
1123 virtual int initEGSnrcBackEnd() {
1134 void initAusgabObjects();
1147 virtual int startNewShower();
1156 virtual int finishShower() {
1169 virtual int shower() {
1173 virtual void finishRun() { };
1175 void storeGeometryStep(
int ireg,
int inew,
const EGS_Vector &x,
1176 const EGS_Vector &u, EGS_Float twant, EGS_Float t);
1178 void reportGeometryError();
1186 bool ausgab_flag[UnknownCall];
1196 string final_output_file;
1198 string abs_pegs_file;
1210 EGS_I64 current_case;
1251 EGS_Float getFluence() {
1258 return geometry->
nMedia();
1260 const char *getMediumName(
int ind) {
1263 virtual EGS_Float getMediumRho(
int ind) {
1267 virtual EGS_Float getEdep() {
1270 virtual void setEdep(EGS_Float edep) {
1273 virtual EGS_Float getEcut() {
1276 virtual EGS_Float getPcut() {
1279 virtual EGS_Float getRM() {
1286 virtual void setRadiativeSplitting(
const EGS_Float &nsplit) {
1289 virtual void setRussianRoulette(
const EGS_Float &iSwitchRR) {
1292 virtual void splitTopParticleIsotropically(
const EGS_Float &fsplit) {
1299 virtual EGS_Float getTVSTEP() {
1309 string sourceType() {
1313 int sourceCharge() {
1321 virtual void setLatch(
const int &ip,
const int &latch) {
1326 virtual void incLatch(
const int &ip,
const int &increment) {
1331 virtual int getNp() {
1335 virtual int getNpOld() {
1342 virtual void setLatch(
int latch) {
1346 static unique_ptr<EGS_InputStruct> inputStructure;
1348 bool containsDynamic() {
1349 bool hasDynamic =
false;
1350 geometry->containsDynamic(hasDynamic);
1352 source->containsDynamic(hasDynamic);
1358 #define APP_MAIN(app_name) \
1359 int main(int argc, char **argv) { \
1360 app_name app(argc,argv); \
1361 int err = app.initSimulation(); \
1362 if( err ) return err; \
1363 err = app.runSimulation(); \
1364 if( err < 0 ) return err; \
1365 return app.finishSimulation(); \
1368 #define APP_SIMPLE_MAIN(app_name) \
1369 int main(int argc, char **argv) { \
1370 app_name app(argc,argv); \
1372 app.reportResults(); \
1377 #define APP_LIB(app_name) \
1379 APP_EXPORT EGS_Application* createApplication(int argc, char **argv) {\
1380 return new app_name(argc, argv);\
1382 APP_EXPORT shared_ptr<EGS_InputStruct> getAppInputs() {\
1383 shared_ptr<EGS_InputStruct> appInputStruct = make_shared<EGS_InputStruct>();\
1384 addmcBlock(appInputStruct);\
1385 addRngDefinitionBlock(appInputStruct);\
1386 addRunControlBlock(appInputStruct);\
1387 addMediaDefBlock(appInputStruct);\
1388 return appInputStruct;\
1390 APP_EXPORT string getmcExample() {\
1391 return addmcExample();\
1393 APP_EXPORT string getRunControlExample() {\
1394 return addRunControlExample();\
1396 APP_EXPORT string getRngDefinitionExample() {\
1397 return addRngDefinitionExample();\
1399 APP_EXPORT string getMediaExample() {\
1400 return addMediaExample();\
Base class for advanced EGSnrc C++ applications.
AusgabCall
Possible calls to the user scoring function ausgab().
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
static int nMedia()
Get the number of media registered so far by all geometries.
int regions() const
Returns the number of local regions in this geometry.
static const char * getMediumName(int ind)
Get the name of medium with index ind.
Base source class. All particle sources must be derived from this class.
virtual int getCharge() const
Get the charge of the source.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
A class for fast run-time interpolations.
const string & getObjectType() const
Get the object type.
Base random number generator class. All random number generators should be derived from this class.
A simple run control object for advanced EGSnrc C++ applications.
A class representing 3D vectors.
EGS_BaseGeometry class header file.
EGS_BaseSource class header file.
EGS_Interpolator class header file.
#define EGS_EXPORT
Export symbols from the egspp library.
EGS_RandomGenerator class header file.
EGS_RunControl and EGS_JCFControl class header file.
EGS_ScoringSingle and EGS_ScoringArray class header file.
EGS_SimpleContainer template class.
A structure holding the information of one particle.