EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_isotropic_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ isotropic source
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, 2005
25 #
26 # Contributors: Long Zhang
27 # Hubert Ho
28 #
29 ###############################################################################
30 */
31 
32 
38 #include "egs_isotropic_source.h"
39 #include "egs_input.h"
40 #include "egs_math.h"
41 
43  EGS_ObjectFactory *f) : EGS_BaseSimpleSource(input,f), shape(0), geom(0),
44  regions(0), min_theta(0), max_theta(M_PI), min_phi(0), max_phi(2*M_PI),
45  nrs(0), gc(IncludeAll) {
46  vector<EGS_Float> pos;
47  EGS_Input *ishape = input->takeInputItem("shape");
48  if (ishape) {
50  delete ishape;
51  }
52  if (!shape) {
53  string sname;
54  int err = input->getInput("shape name",sname);
55  if (err)
56  egsWarning("EGS_IsotropicSource: missing/wrong inline shape "
57  "definition and missing wrong 'shape name' input\n");
58  else {
60  if (!shape) egsWarning("EGS_IsotropicSource: a shape named %s"
61  " does not exist\n");
62  }
63  }
64  string geom_name;
65  int err = input->getInput("geometry",geom_name);
66  if (!err) {
67  geom = EGS_BaseGeometry::getGeometry(geom_name);
68  if (!geom) egsWarning("EGS_IsotropicSource: no geometry named %s\n",
69  geom_name.c_str());
70  else {
71  vector<string> reg_options;
72  reg_options.push_back("IncludeAll");
73  reg_options.push_back("ExcludeAll");
74  reg_options.push_back("IncludeSelected");
75  reg_options.push_back("ExcludeSelected");
76  gc = (GeometryConfinement) input->getInput("region selection",reg_options,0);
77  if (gc == IncludeSelected || gc == ExcludeSelected) {
78  vector<int> regs;
79  err = input->getInput("selected regions",regs);
80  if (err || regs.size() < 1) {
81  egsWarning("EGS_IsotropicSource: region selection %d used "
82  "but no 'selected regions' input found\n",gc);
83  gc = gc == IncludeSelected ? IncludeAll : ExcludeAll;
84  egsWarning(" using %d\n",gc);
85  }
86  nrs = regs.size();
87  regions = new int [nrs];
88  for (int j=0; j<nrs; j++) {
89  regions[j] = regs[j];
90  }
91  }
92  }
93  }
94  EGS_Float tmp_theta;
95  err = input->getInput("min theta", tmp_theta);
96  if (!err) {
97  min_theta = tmp_theta/180.0*M_PI;
98  }
99 
100  err = input->getInput("max theta", tmp_theta);
101  if (!err) {
102  max_theta = tmp_theta/180.0*M_PI;
103  }
104 
105  err = input->getInput("min phi", tmp_theta);
106  if (!err) {
107  min_phi = tmp_theta/180.0*M_PI;
108  }
109 
110  err = input->getInput("max phi", tmp_theta);
111  if (!err) {
112  max_phi = tmp_theta/180.0*M_PI;
113  }
114 
115  buf_1 = cos(min_theta);
116  buf_2 = cos(max_theta);
117 
118  setUp();
119 }
120 
121 void EGS_IsotropicSource::setUp() {
122  otype = "EGS_IsotropicSource";
123  if (!isValid()) {
124  description = "Invalid isotropic source";
125  }
126  else {
127  description = "Isotropic source from a shape of type ";
129  description += " with ";
130  description += s->getType();
131  if (q == -1) {
132  description += ", electrons";
133  }
134  else if (q == 0) {
135  description += ", photons";
136  }
137  else if (q == 1) {
138  description += ", positrons";
139  }
140  else {
141  description += ", unknown particle type";
142  }
143 
144  if (geom) {
145  geom->ref();
146  }
147  }
148 }
149 
150 extern "C" {
151 
152  EGS_ISOTROPIC_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
153  EGS_ObjectFactory *f) {
154  return
155  createSourceTemplate<EGS_IsotropicSource>(input,f,"isotropic source");
156  }
157 
158 }
GeometryConfinement
Geometry confinement options.
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
Definition: egs_shapes.cpp:51
EGS_Input class header file.
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:63
EGS_IsotropicSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, EGS_BaseGeometry *geometry, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseSpectrum * s
The energy spectrum of this source.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
An object factory.
An isotropic source.
Attempts to fix broken math header files.
int q
The charge of this simple source.
const string & getObjectType() const
Get the object type.
int ref()
Increase the reference count to this geometry.
EGS_Float min_phi
avoid multi-calculating cos(min_theta) and cos(max_theta)
const string & getType() const
Get the spectrum type.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_BaseShape * shape
The shape from which particles are emitted.
string otype
The object type.
Base class for &#39;simple&#39; particle sources.
EGS_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:226
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 source class. All particle sources must be derived from this class.
string description
A short source description.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.