EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_collimated_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ collimated 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: Hubert Ho
27 # Reid Townson
28 # Hannah Gallop
29 #
30 ###############################################################################
31 */
32 
33 
39 #include "egs_collimated_source.h"
40 #include "egs_input.h"
41 
42 static bool EGS_COLLIMATED_SOURCE_LOCAL inputSet = false;
43 
46  source_shape(0), target_shape(0), ctry(0), dist(1) {
47  EGS_Input *ishape = input->takeInputItem("source shape");
48  if (ishape) {
50  delete ishape;
51  }
52  if (!source_shape) {
53  string sname;
54  int err = input->getInput("source shape name",sname);
55  if (err)
56  egsWarning("EGS_CollimatedSource: missing/wrong inline source "
57  "shape definition and missing/wrong 'source shape name' input\n");
58  else {
60  if (!source_shape)
61  egsWarning("EGS_CollimatedSource: a shape named %s"
62  " does not exist\n",sname.c_str());
63  }
64  }
65  ishape = input->takeInputItem("target shape");
66  if (ishape) {
68  delete ishape;
69  }
70  if (!target_shape) {
71  string sname;
72  int err = input->getInput("target shape name",sname);
73  if (err)
74  egsWarning("EGS_CollimatedSource: missing/wrong inline target"
75  "shape definition and missing/wrong 'target shape name' input\n");
76  else {
78  if (!target_shape)
79  egsWarning("EGS_CollimatedSource: a shape named %s"
80  " does not exist\n",sname.c_str());
81  }
82  }
83  if (target_shape) {
85  egsWarning("EGS_CollimatedSource: the target shape %s, which is"
86  " of type %s, does not support the getPointSourceDirection()"
87  " method\n",target_shape->getObjectName().c_str(),
88  target_shape->getObjectType().c_str());
89  };
90  EGS_Float auxd;
91  int errd = input->getInput("distance",auxd);
92  if (!errd) {
93  dist = auxd;
94  }
95  setUp();
96 }
97 
98 void EGS_CollimatedSource::setUp() {
99  otype = "EGS_CollimatedSource";
100  if (!isValid()) {
101  description = "Invalid collimated source";
102  }
103  else {
104  description = "Collimated source from a shape of type ";
106  description += " onto a shape of type ";
108  description += " with ";
109  description += s->getType();
110  if (q == -1) {
111  description += ", electrons";
112  }
113  else if (q == 0) {
114  description += ", photons";
115  }
116  else if (q == 1) {
117  description += ", positrons";
118  }
119  else {
120  description += ", unknown particle type";
121  }
122  }
123 }
124 
125 extern "C" {
126 
127  static void setInputs() {
128  inputSet = true;
129 
130  setBaseSourceInputs();
131 
132  srcBlockInput->getSingleInput("library")->setValues({"egs_collimated_source"});
133 
134  // Format: name, isRequired, description, vector string of allowed values
135  auto source_shapePtr = srcBlockInput->addBlockInput("source shape");
136  auto target_shapePtr = srcBlockInput->addBlockInput("target shape");
137 
138  setShapeInputs(source_shapePtr);
139  setShapeInputs(target_shapePtr);
140 
141  srcBlockInput->addSingleInput("distance", false, "The source-target minimum distance, used for weighting the final result. This input does not impact the physical positioning of the source in any way. See the documentation for details.");
142  }
143 
144  EGS_COLLIMATED_SOURCE_EXPORT string getExample() {
145  string example;
146  example = {
147  R"(
148  # Example of egs_collimated_source
149  #:start source:
150  library = egs_collimated_source
151  name = my_source
152  :start source shape:
153  type = point
154  position = 0 0 5
155  :stop source shape:
156  :start target shape:
157  library = egs_rectangle
158  rectangle = -1 -1 1 1
159  :stop target shape:
160  distance = 5
161  charge = -1
162  :start spectrum:
163  type = monoenergetic
164  energy = 20
165  :stop spectrum:
166  :stop source:
167 )"};
168  return example;
169  }
170 
171  EGS_COLLIMATED_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
172  if(!inputSet) {
173  setInputs();
174  }
175  return srcBlockInput;
176  }
177 
178  EGS_COLLIMATED_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
179  EGS_ObjectFactory *f) {
180  return
181  createSourceTemplate<EGS_CollimatedSource>(input,f,"collimated source");
182  }
183 
184 }
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:64
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
Definition: egs_shapes.cpp:51
virtual bool supportsDirectionMethod() const
Definition: egs_shapes.h:238
Base class for 'simple' particle sources.
int q
The charge of this simple source.
EGS_BaseSpectrum * s
The energy spectrum of this source.
Base source class. All particle sources must be derived from this class.
string description
A short source description.
const string & getType() const
Get the spectrum type.
EGS_Float dist
source-target shape min. distance
EGS_CollimatedSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *sshape, EGS_BaseShape *tshape, const string &Name="", EGS_ObjectFactory *f=0)
EGS_BaseShape * source_shape
the source shape
EGS_BaseShape * target_shape
the target shape
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_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:229
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:341
An object factory.
string otype
The object type.
const string & getObjectType() const
Get the object type.
const string & getObjectName() const
Get the object name.
A collimated isotropic source.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.