EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_fano_source.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ Fano 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 # Authors: Ernesto Mainegra-Hing, 2016
25 # Hugo Bouchard, 2016
26 #
27 # Contributors:
28 #
29 ###############################################################################
30 */
31 
32 
39 #include "egs_fano_source.h"
40 #include "egs_input.h"
41 #include "egs_math.h"
42 #include <sstream>
43 
45  EGS_ObjectFactory *f) :
46  EGS_BaseSimpleSource(input,f), shape(0), geom(0),
47  regions(0), nrs(0), min_theta(0), max_theta(M_PI), min_phi(0), max_phi(2*M_PI),
48  max_mass_density(0.0) {
49 
50  vector<EGS_Float> pos;
51  EGS_Input *ishape = input->takeInputItem("shape");
52  if (ishape) {
53  egsWarning("EGS_FanoSource: trying to construct the shape\n");
55  delete ishape;
56  }
57  if (!shape) {
58  string sname;
59  int err = input->getInput("shape name",sname);
60  if (err)
61  egsWarning("EGS_FanoSource: missing/wrong inline shape "
62  "definition and missing wrong 'shape name' input\n");
63  else {
65  if (!shape) egsWarning("EGS_FanoSource: a shape named %s"
66  " does not exist\n");
67  }
68  }
69  string geom_name;
70  int err = input->getInput("geometry",geom_name);
71  if (!err) {
72  geom = EGS_BaseGeometry::getGeometry(geom_name);
73  if (!geom) egsFatal("EGS_FanoSource: no geometry named %s in input file!\n",
74  geom_name.c_str());
75  else {
76  int errF = input->getInput("max mass density", max_mass_density);
77  if (errF) {
78  egsFatal("EGS_FanoSource: A Fano source requires a maximum density input.\n");
79  }
80  }
81  }
82  else {
83  egsFatal("EGS_FanoSource: A Fano source requires a valid geometry name.\n");
84  }
85 
86  EGS_Float tmp_theta;
87  err = input->getInput("min theta", tmp_theta);
88  if (!err) {
89  min_theta = tmp_theta/180.0*M_PI;
90  }
91 
92  err = input->getInput("max theta", tmp_theta);
93  if (!err) {
94  max_theta = tmp_theta/180.0*M_PI;
95  }
96 
97  err = input->getInput("min phi", tmp_theta);
98  if (!err) {
99  min_phi = tmp_theta/180.0*M_PI;
100  }
101 
102  err = input->getInput("max phi", tmp_theta);
103  if (!err) {
104  max_phi = tmp_theta/180.0*M_PI;
105  }
106 
107  buf_1 = cos(min_theta);
108  buf_2 = cos(max_theta);
109 
110  setUp();
111 }
112 
113 void EGS_FanoSource::setUp() {
114  otype = "EGS_FanoSource";
115  if (!isValid()) {
116  description = "Invalid Fano source";
117  }
118  else {
119  description = "Fano source from a shape of type ";
121  description += " with ";
122  description += s->getType();
123  if (q == -1) {
124  description += ", electrons";
125  }
126  else if (q == 0) {
127  description += ", photons";
128  }
129  else if (q == 1) {
130  description += ", positrons";
131  }
132  else {
133  description += ", unknown particle type";
134  }
135  ostringstream str_density;
136  str_density << scientific << max_mass_density;
137  description += "\n maximum density = " + str_density.str() + " g/cm3";
138  description += "\n Fano geometry = " + geom->getName();
139  if (geom) {
140  geom->ref();
141  }
142  }
143 }
144 
145 extern "C" {
146 
147  EGS_FANO_SOURCE_EXPORT EGS_BaseSource *createSource(EGS_Input *input,
148  EGS_ObjectFactory *f) {
149  return createSourceTemplate<EGS_FanoSource>(input, f, "fano source");
150  }
151 
152 }
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.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
An object factory.
Attempts to fix broken math header files.
EGS_Float min_phi
avoid multi-calculating cos(min_theta) and cos(max_theta)
A Fano source.
int q
The charge of this simple source.
const string & getObjectType() const
Get the object type.
EGS_BaseShape * shape
The shape from which particles are emitted.
int ref()
Increase the reference count to this geometry.
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
const string & getName() const
Get the name of this geometry.
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
EGS_FanoSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, EGS_BaseGeometry *geometry, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
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.