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 #
29 ###############################################################################
30 */
31 
32 
38 #include "egs_collimated_source.h"
39 #include "egs_input.h"
40 
43  source_shape(0), target_shape(0), ctry(0), dist(1) {
44  EGS_Input *ishape = input->takeInputItem("source shape");
45  if (ishape) {
47  delete ishape;
48  }
49  if (!source_shape) {
50  string sname;
51  int err = input->getInput("source shape name",sname);
52  if (err)
53  egsWarning("EGS_CollimatedSource: missing/wrong inline source "
54  "shape definition and missing/wrong 'source shape name' input\n");
55  else {
57  if (!source_shape)
58  egsWarning("EGS_CollimatedSource: a shape named %s"
59  " does not exist\n",sname.c_str());
60  }
61  }
62  ishape = input->takeInputItem("target shape");
63  if (ishape) {
65  delete ishape;
66  }
67  if (!target_shape) {
68  string sname;
69  int err = input->getInput("target shape name",sname);
70  if (err)
71  egsWarning("EGS_CollimatedSource: missing/wrong inline target"
72  "shape definition and missing/wrong 'target shape name' input\n");
73  else {
75  if (!target_shape)
76  egsWarning("EGS_CollimatedSource: a shape named %s"
77  " does not exist\n",sname.c_str());
78  }
79  }
80  if (target_shape) {
82  egsWarning("EGS_CollimatedSource: the target shape %s, which is"
83  " of type %s, does not support the getPointSourceDirection()"
84  " method\n",target_shape->getObjectName().c_str(),
85  target_shape->getObjectType().c_str());
86  };
87  EGS_Float auxd;
88  int errd = input->getInput("distance",auxd);
89  if (!errd) {
90  dist = auxd;
91  }
92  setUp();
93 }
94 
95 void EGS_CollimatedSource::setUp() {
96  otype = "EGS_CollimatedSource";
97  if (!isValid()) {
98  description = "Invalid collimated source";
99  }
100  else {
101  description = "Collimated source from a shape of type ";
103  description += " onto a shape of type ";
105  description += " with ";
106  description += s->getType();
107  if (q == -1) {
108  description += ", electrons";
109  }
110  else if (q == 0) {
111  description += ", photons";
112  }
113  else if (q == 1) {
114  description += ", positrons";
115  }
116  else {
117  description += ", unknown particle type";
118  }
119  }
120 }
121 
122 extern "C" {
123 
124  EGS_COLLIMATED_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
125  EGS_ObjectFactory *f) {
126  return
127  createSourceTemplate<EGS_CollimatedSource>(input,f,"collimated source");
128  }
129 
130 }
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:206
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: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
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.