46 static string EGS_ISOTROPIC_SOURCE_LOCAL typeStr(
"egs_isotropic_source");
47 static bool EGS_ISOTROPIC_SOURCE_LOCAL inputSet =
false;
51 regions(0), min_theta(0), max_theta(M_PI), min_phi(0), max_phi(2*M_PI),
52 nrs(0), gc(IncludeAll), media(0), nms(0), gcm(IncludeSelected) {
53 vector<EGS_Float> pos;
61 int err = input->
getInput(
"shape name",sname);
63 egsWarning(
"EGS_IsotropicSource: missing/wrong inline shape "
64 "definition and missing wrong 'shape name' input\n");
72 int err = input->
getInput(
"geometry",geom_name);
75 if (!geom)
egsWarning(
"EGS_IsotropicSource: no geometry named %s\n",
79 vector<string> reg_options;
80 reg_options.push_back(
"IncludeAll");
81 reg_options.push_back(
"ExcludeAll");
82 reg_options.push_back(
"IncludeSelected");
83 reg_options.push_back(
"ExcludeSelected");
85 if (gc == IncludeSelected || gc == ExcludeSelected) {
87 err = input->
getInput(
"selected regions",regs);
88 if (err || regs.size() < 1) {
89 egsWarning(
"EGS_IsotropicSource: region selection %d used "
90 "but no 'selected regions' input found\n",gc);
91 gc = gc == IncludeSelected ? IncludeAll : ExcludeAll;
95 regions =
new int [nrs];
96 for (
int j=0; j<nrs; j++) {
103 if (gcm == IncludeSelected || gcm == ExcludeSelected) {
104 vector<string> selectedMedia;
105 err = input->
getInput(
"selected media",selectedMedia);
106 if (err || selectedMedia.size() < 1) {
107 egsWarning(
"EGS_IsotropicSource: medium selection %d used "
108 "but no 'selected media' input found\n",gcm);
110 nms = selectedMedia.size();
111 media =
new int [nms];
112 for (
int j=0; j<nms; j++) {
120 err = input->
getInput(
"min theta", tmp_angle);
122 min_theta = tmp_angle/180.0*M_PI;
125 err = input->
getInput(
"max theta", tmp_angle);
127 max_theta = tmp_angle/180.0*M_PI;
130 if (min_theta > max_theta) {
131 egsFatal(
"EGS_IsotropicSource: max theta must be greater than min theta (theta ranges from 0 to 180 degrees).\n");
134 err = input->
getInput(
"min phi", tmp_angle);
136 min_phi = tmp_angle/180.0*M_PI;
139 err = input->
getInput(
"max phi", tmp_angle);
141 max_phi = tmp_angle/180.0*M_PI;
145 egsFatal(
"EGS_IsotropicSource: max phi must be greater than min phi. To collimate across the 0/360 degree boundary (e.g. from 300 degrees to 60 degrees), set max phi greater than 360 (e.g. min phi = 300, max phi = 420).\n");
148 buf_1 = cos(min_theta);
149 buf_2 = cos(max_theta);
154 void EGS_IsotropicSource::setUp() {
155 otype =
"EGS_IsotropicSource";
160 description =
"Isotropic source from a shape of type ";
181 description +=
" Filtered by regions using option: " + std::to_string(gc);
185 description +=
" Filtered by media using option: " + std::to_string(gcm);
188 for (
auto i=0; i<nms; ++i) {
190 description +=
" " + mediumName +
"(" + std::to_string(media[i]) +
")";
193 description +=
"\n\n Regions are only included if they match both the region filter and the medium filter.";
203 static void setInputs() {
206 setBaseSourceInputs();
208 srcBlockInput->getSingleInput(
"library")->setValues(vector<string>(1, typeStr));
210 auto shapePtr = srcBlockInput->addBlockInput(
"shape");
217 setShapeInputs(shapePtr);
219 auto geomPtr = srcBlockInput->addSingleInput(
"geometry",
false,
"The name of a geometry, used for complex source shapes. Only particles generated inside the geometry or some of its regions are used.");
220 auto regPtr = srcBlockInput->addSingleInput(
"region selection",
false,
"Include or exclude regions from the named geometry, to define a volume for source particle generation.", {
"IncludeAll",
"ExcludeAll",
"IncludeSelected",
"ExcludeSelected"});
221 regPtr->addDependency(geomPtr);
222 auto selPtr = srcBlockInput->addSingleInput(
"selected regions",
false,
"If region selection = IncludeSelected or ExcludeSelected, then this is a list of the regions in the named geometry to include or exclude.");
223 selPtr->addDependency(regPtr,
"IncludeSelected");
224 selPtr->addDependency(regPtr,
"ExcludeSelected");
225 srcBlockInput->addSingleInput(
"min theta",
false,
"The minimum theta angle in degrees, to restrict the directions of source particles. Defaults to 0.");
226 srcBlockInput->addSingleInput(
"max theta",
false,
"The maximum theta angle in degrees, to restrict the directions of source particles. Defaults to 180.");
227 srcBlockInput->addSingleInput(
"min phi",
false,
"The minimum phi angle in degrees, to restrict the directions of source particles. Defaults to 0.");
228 srcBlockInput->addSingleInput(
"max phi",
false,
"The maximum phi angle in degrees, to restrict the directions of source particles. Defaults to 360.");
231 EGS_ISOTROPIC_SOURCE_EXPORT
string getExample() {
236 library = egs_isotropic_source
238 geometry = my_envelope
239 region selection = IncludeSelected
240 selected regions = 1 2
257 EGS_ISOTROPIC_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
261 return srcBlockInput;
267 createSourceTemplate<EGS_IsotropicSource>(input,f,
"isotropic source");
int ref()
Increase the reference count to this geometry.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
static int getMediumIndex(const string &medname)
Get the index of a medium named medname.
static const char * getMediumName(int ind)
Get the name of medium with index ind.
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
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_BaseShape * shape
The shape from which particles are emitted.
EGS_IsotropicSource(int Q, EGS_BaseSpectrum *Spec, EGS_BaseShape *Shape, EGS_BaseGeometry *geometry, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
GeometryConfinement
Geometry confinement options.
EGS_Float min_phi
avoid multi-calculating cos(min_theta) and cos(max_theta)
string otype
The object type.
const string & getObjectType() const
Get the object type.
Attempts to fix broken math header files.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.