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:
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_parallel_beam.h"
38 #include "egs_input.h"
39 
41  EGS_ObjectFactory *f) : EGS_BaseSimpleSource(input,f), shape(0), uo(0,0,1) {
42  vector<EGS_Float> dir;
43  if (!input->getInput("direction",dir)) {
44  if (dir.size() != 3) egsWarning("EGS_ParallelBeam: you must input"
45  " 3 numbers in the 'direction' input\n"
46  " but I got %d => ignoring the input\n",dir.size());
47  else {
48  uo.x = dir[0];
49  uo.y = dir[1];
50  uo.z = dir[2];
51  EGS_Float norm = uo.length();
52  if (norm < epsilon) {
53  egsWarning("EGS_ParallelBeam: the length of the direction"
54  " vector can not be zero => ignoring your input\n");
55  uo.x = 0;
56  uo.y = 0;
57  uo.z = 1;
58  }
59  else {
60  uo *= (1./norm);
61  }
62  }
63  }
64  EGS_Input *ishape = input->takeInputItem("shape");
65  if (ishape) {
66  //egsWarning("EGS_ParallelBeam: trying to construct the shape\n");
68  delete ishape;
69  }
70  if (!shape) {
71  string sname;
72  int err = input->getInput("shape name",sname);
73  if (err)
74  egsWarning("EGS_ParallelBeam: missing/wrong inline shape "
75  "definition and missing wrong 'shape name' input\n");
76  else {
78  if (!shape) egsWarning("EGS_ParallelBeam: a shape named %s"
79  " does not exist\n");
80  }
81  }
82  setUp();
83 }
84 
85 void EGS_ParallelBeam::setUp() {
86  otype = "EGS_ParallelBeam";
87  if (!isValid()) {
88  description = "Invalid parallel beam";
89  }
90  else {
91  description = "Parallel beam from a shape of type ";
93  description += " with ";
94  description += s->getType();
95  if (q == -1) {
96  description += ", electrons";
97  }
98  else if (q == 0) {
99  description += ", photons";
100  }
101  else if (q == 1) {
102  description += ", positrons";
103  }
104  else {
105  description += ", unknown particle type";
106  }
107  }
108 }
109 
110 extern "C" {
111 
112  EGS_PARALLEL_BEAM_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
113  EGS_ObjectFactory *f) {
114  return createSourceTemplate<EGS_ParallelBeam>(input,f,"parallel beam");
115  }
116 
117 }
A parallel beam.
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.
EGS_Float y
y-component
Definition: egs_vector.h:61
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:63
EGS_ParallelBeam(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
EGS_BaseSpectrum * s
The energy spectrum of this source.
EGS_Float z
z-component
Definition: egs_vector.h:62
An object factory.
EGS_Vector uo
The direction of the particles.
int q
The charge of this simple source.
const string & getObjectType() const
Get the object type.
EGS_Float x
x-component
Definition: egs_vector.h:60
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:61
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
string otype
The object type.
Base class for &#39;simple&#39; particle sources.
EGS_BaseShape * shape
The shape.
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.