EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_parallel_beam.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ parallel beam 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: Reid Townson
27 # Hannah Gallop
28 #
29 ###############################################################################
30 */
31 
32 
38 #include "egs_parallel_beam.h"
39 #include "egs_input.h"
40 
41 static bool EGS_PARALLEL_BEAM_LOCAL inputSet = false;
42 
44  EGS_ObjectFactory *f) : EGS_BaseSimpleSource(input,f), shape(0), uo(0,0,1) {
45  vector<EGS_Float> dir;
46  if (!input->getInput("direction",dir)) {
47  if (dir.size() != 3) egsWarning("EGS_ParallelBeam: you must input"
48  " 3 numbers in the 'direction' input\n"
49  " but I got %d => ignoring the input\n",dir.size());
50  else {
51  uo.x = dir[0];
52  uo.y = dir[1];
53  uo.z = dir[2];
54  EGS_Float norm = uo.length();
55  if (norm < epsilon) {
56  egsWarning("EGS_ParallelBeam: the length of the direction"
57  " vector can not be zero => ignoring your input\n");
58  uo.x = 0;
59  uo.y = 0;
60  uo.z = 1;
61  }
62  else {
63  uo *= (1./norm);
64  }
65  }
66  }
67  EGS_Input *ishape = input->takeInputItem("shape");
68  if (ishape) {
69  //egsWarning("EGS_ParallelBeam: trying to construct the shape\n");
71  delete ishape;
72  }
73  if (!shape) {
74  string sname;
75  int err = input->getInput("shape name",sname);
76  if (err)
77  egsWarning("EGS_ParallelBeam: missing/wrong inline shape "
78  "definition and missing wrong 'shape name' input\n");
79  else {
81  if (!shape) egsWarning("EGS_ParallelBeam: a shape named %s"
82  " does not exist\n");
83  }
84  }
85  setUp();
86 }
87 
88 void EGS_ParallelBeam::setUp() {
89  otype = "EGS_ParallelBeam";
90  if (!isValid()) {
91  description = "Invalid parallel beam";
92  }
93  else {
94  description = "Parallel beam from a shape of type ";
96  description += " with ";
97  description += s->getType();
98  if (q == -1) {
99  description += ", electrons";
100  }
101  else if (q == 0) {
102  description += ", photons";
103  }
104  else if (q == 1) {
105  description += ", positrons";
106  }
107  else {
108  description += ", unknown particle type";
109  }
110  }
111 }
112 
113 extern "C" {
114 
115  static void setInputs() {
116  inputSet = true;
117 
118  setBaseSourceInputs();
119 
120  srcBlockInput->getSingleInput("library")->setValues({"egs_parallel_beam"});
121 
122  // Format: name, isRequired, description, vector string of allowed values
123  auto shapePtr = srcBlockInput->addBlockInput("shape");
124 
125  setShapeInputs(shapePtr);
126 
127  srcBlockInput->addSingleInput("direction", true, "Direction of the beam, as a unit vector: 'ux uy uz'");
128  }
129 
130  EGS_PARALLEL_BEAM_EXPORT string getExample() {
131  string example;
132  example = {
133  R"(
134  # Example of egs_parallel_beam
135  #:start source:
136  library = egs_parallel_beam
137  name = my_source
138  :start shape:
139  type = cylinder
140  radius = 1
141  height = 2
142  axis = 0 0 1
143  midpoint = 0
144  :stop shape:
145  direction = 0 0 1
146  charge = 0
147  :start spectrum:
148  type = monoenergetic
149  energy = 6
150  :stop spectrum:
151  :stop source:
152 )"};
153  return example;
154  }
155 
156  EGS_PARALLEL_BEAM_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
157  if(!inputSet) {
158  setInputs();
159  }
160  return srcBlockInput;
161  }
162 
163  EGS_PARALLEL_BEAM_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
164  EGS_ObjectFactory *f) {
165  return createSourceTemplate<EGS_ParallelBeam>(input,f,"parallel beam");
166  }
167 
168 }
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
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.
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.
EGS_Vector uo
The direction of the particles.
EGS_ParallelBeam(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseShape * shape
The shape.
EGS_Float y
y-component
Definition: egs_vector.h:62
EGS_Float z
z-component
Definition: egs_vector.h:63
EGS_Float x
x-component
Definition: egs_vector.h:61
EGS_Input class header file.
A parallel beam.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:62
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.