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 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_collimated_source.h"
38 #include "egs_input.h"
39 
42  source_shape(0), target_shape(0), ctry(0), dist(1) {
43  EGS_Input *ishape = input->takeInputItem("source shape");
44  if (ishape) {
46  delete ishape;
47  }
48  if (!source_shape) {
49  string sname;
50  int err = input->getInput("source shape name",sname);
51  if (err)
52  egsWarning("EGS_CollimatedSource: missing/wrong inline source "
53  "shape definition and missing/wrong 'source shape name' input\n");
54  else {
56  if (!source_shape)
57  egsWarning("EGS_CollimatedSource: a shape named %s"
58  " does not exist\n",sname.c_str());
59  }
60  }
61  ishape = input->takeInputItem("target shape");
62  if (ishape) {
64  delete ishape;
65  }
66  if (!target_shape) {
67  string sname;
68  int err = input->getInput("target shape name",sname);
69  if (err)
70  egsWarning("EGS_CollimatedSource: missing/wrong inline target"
71  "shape definition and missing/wrong 'target shape name' input\n");
72  else {
74  if (!target_shape)
75  egsWarning("EGS_CollimatedSource: a shape named %s"
76  " does not exist\n",sname.c_str());
77  }
78  }
79  if (target_shape) {
81  egsWarning("EGS_CollimatedSource: the target shape %s, which is"
82  " of type %s, does not support the getPointSourceDirection()"
83  " method\n",target_shape->getObjectName().c_str(),
84  target_shape->getObjectType().c_str());
85  };
86  EGS_Float auxd;
87  int errd = input->getInput("distance",auxd);
88  if (!errd) {
89  dist = auxd;
90  }
91  setUp();
92 }
93 
94 void EGS_CollimatedSource::setUp() {
95  otype = "EGS_CollimatedSource";
96  if (!isValid()) {
97  description = "Invalid collimated source";
98  }
99  else {
100  description = "Collimated source from a shape of type ";
102  description += " onto a shape of type ";
104  description += " with ";
105  description += s->getType();
106  if (q == -1) {
107  description += ", electrons";
108  }
109  else if (q == 0) {
110  description += ", photons";
111  }
112  else if (q == 1) {
113  description += ", positrons";
114  }
115  else {
116  description += ", unknown particle type";
117  }
118  }
119 }
120 
121 extern "C" {
122 
123  EGS_COLLIMATED_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
124  EGS_ObjectFactory *f) {
125  return
126  createSourceTemplate<EGS_CollimatedSource>(input,f,"collimated source");
127  }
128 
129 }
EGS_BaseShape * target_shape
the target shape
EGS_BaseShape * source_shape
the source shape
const string & getObjectName() const
Get the object name.
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_BaseSpectrum * s
The energy spectrum of this source.
virtual bool supportsDirectionMethod() const
Definition: egs_shapes.h:204
An object factory.
EGS_CollimatedSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *sshape, EGS_BaseShape *tshape, const string &Name="", EGS_ObjectFactory *f=0)
EGS_Float dist
source-target shape min. distance
int q
The charge of this simple source.
const string & getObjectType() const
Get the object type.
const string & getType() const
Get the spectrum type.
A collimated isotropic source.
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_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.