41 static bool EGS_DYNAMIC_SOURCE_LOCAL inputSet =
false;
52 int err = input->
getInput(
"base source",sname);
54 err = input->
getInput(
"source name",sname);
56 egsWarning(
"EGS_DynamicSource: missing/wrong inline source "
57 "definition and missing wrong 'base source' input\n");
64 " does not exist\n",sname.c_str());
69 vector<string> sync_options;
70 sync_options.push_back(
"no");
71 sync_options.push_back(
"yes");
72 sync = input->
getInput(
"synchronize motion",sync_options,0);
75 egsWarning(
"EGS_DynamicSource: source motion can only be synchronized with a source of type iaea_phsp_source or egs_beam_source.\n Will not synchronize.\n");
84 vector<EGS_Float> point;
91 string inputTag =
"control point";
92 string inputTag_backCompat =
"control point " + itos.str();
97 if (!currentInput || currentInput->
getInput(inputTag, point)) {
99 if (!currentInput || currentInput->
getInput(inputTag_backCompat, point)) {
106 if (point.size()!=8) {
107 egsWarning(
"EGS_DynamicSource: control point %i does not specify 8 values.\n",icpts);
111 if (ncpts>0 && point[7] < cpts[ncpts-1].time) {
112 egsWarning(
"EGS_DynamicSource: time index of control point %i < time index of control point %i\n",icpts,ncpts);
115 else if (point[7] < 0.) {
116 egsWarning(
"EGS_DynamicSource: time index of control point %i < 0.0\n",icpts);
121 if (ncpts ==1 && point[7] > 0.0) {
122 egsWarning(
"EGS_DynamicSource: time index of control point 1 > 0.0. This will generate many warning messages.\n");
125 cpt.iso =
EGS_Vector(point[0],point[1],point[2]);
126 cpt.dsource = point[3];
127 cpt.theta = point[4];
129 cpt.phicol = point[6];
136 inputTag_backCompat =
"control point " + itos.str();
141 egsWarning(
"EGS_DynamicSource: not enough or missing control points.\n");
144 if (cpts[ncpts-1].time == 0.0) {
145 egsWarning(
"EGS_DynamicSource: time index of last control point = 0. Something's wrong.\n");
150 for (
int i=0; i<=ncpts-1; i++) {
151 cpts[i].time /= cpts[ncpts-1].time;
156 egsWarning(
"EGS_DynamicSource: no control points input.\n");
162 void EGS_DynamicSource::setUp() {
164 otype=
"EGS_DynamicSource";
172 description +=
"\n Source will be synched with time values read in (if available).";
178 int EGS_DynamicSource::getCoord(EGS_Float rand, EGS_ControlPoint &ipt) {
181 for (i=0; i<ncpts; i++) {
182 if (rand < cpts[i].time-
epsilon) {
188 egsWarning(
"EGS_DynamicSource: could not locate control point.\n");
191 EGS_Float factor = (rand-cpts[iindex-1].time)/(cpts[iindex].time-cpts[iindex-1].time);
192 ipt.iso.x=cpts[iindex-1].iso.x+ (cpts[iindex].iso.x-cpts[iindex-1].iso.x)*factor;
193 ipt.iso.y=cpts[iindex-1].iso.y+ (cpts[iindex].iso.y-cpts[iindex-1].iso.y)*factor;
194 ipt.iso.z=cpts[iindex-1].iso.z+ (cpts[iindex].iso.z-cpts[iindex-1].iso.z)*factor;
195 ipt.dsource=cpts[iindex-1].dsource+ (cpts[iindex].dsource-cpts[iindex-1].dsource)*factor;
196 ipt.theta=cpts[iindex-1].theta+ (cpts[iindex].theta-cpts[iindex-1].theta)*factor;
197 ipt.phi=cpts[iindex-1].phi+ (cpts[iindex].phi-cpts[iindex-1].phi)*factor;
198 ipt.phicol=cpts[iindex-1].phicol+ (cpts[iindex].phicol-cpts[iindex-1].phicol)*factor;
213 static void setInputs() {
216 setBaseSourceInputs(
false,
false);
218 srcBlockInput->getSingleInput(
"library")->setValues({
"egs_dynamic_source"});
221 srcBlockInput->addSingleInput(
"base source",
true,
"The name of a previously defined source");
222 srcBlockInput->addSingleInput(
"synchronize motion",
false,
"Whether or not to synchronize with time indices in original 'base source'. Does not impact egs_dynamic_geometry.", {
"yes",
"no"});
224 auto motionPtr = srcBlockInput->addBlockInput(
"motion");
225 motionPtr->addSingleInput(
"control point",
false,
"xiso(1) yiso(1) ziso(1) dsource(1) theta(1) phi(1) phicol(1) mu(1)");
228 EGS_DYNAMIC_SOURCE_EXPORT
string getExample() {
232 # Example of egs_dynamic_source
234 library = egs_dynamic_source
236 base source = orig_source
237 # Source orig_source must already be defined
238 # Units in cm and degrees
240 control point = 0 0 0 100 0 0 0 0
241 control point = 0 0 0 100 360 0 0 0.5
242 control point = 0 0 0 100 90 0 0 0.5
243 control point = 0 0 0 100 90 360 0 1.0
250 EGS_DYNAMIC_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
254 return srcBlockInput;
260 createSourceTemplate<EGS_DynamicSource>(input,f,
"dynamic source");
Base source class. All particle sources must be derived from this class.
const char * getSourceDescription() const
Get a short description of this source.
static EGS_BaseSource * getSource(const string &Name)
Get a pointer to the source named Name.
string description
A short source description.
static EGS_BaseSource * createSource(EGS_Input *)
Create sources from the information pointed to by input.
EGS_BaseSource * source
The source being rotated.
EGS_DynamicSource(EGS_BaseSource *Source, vector< EGS_ControlPoint > cpts, const string &Name="", EGS_ObjectFactory *f=0)
Construct a dynamic source using Source as the source and cpts as the control points....
void containsDynamic(bool &hasdynamic)
Check if the simulation source contains time indices.
string otype
The object type.
const string & getObjectType() const
Get the object type.
A class representing 3D vectors.
A source with simulated time-varying rotations/translations.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.