51 #define STRINGIFY(s) HELP_S(s)
53 #define F77_NAME(fname,FNAME) STRINGIFY(F77_OBJ(fname,FNAME))
54 #define F77_NAME_(fname,FNAME) STRINGIFY(F77_OBJ_(fname,FNAME))
56 static bool EGS_BEAM_SOURCE_LOCAL inputSet =
false;
74 int err1 = input->
getInput(
"beam code",beam_code);
76 int err2 = input->
getInput(
"pegs file",pegs_file);
78 int err3 = input->
getInput(
"input file",input_file);
80 egsWarning(
"EGS_BeamSource: no 'beam code' input\n");
83 egsWarning(
"EGS_BeamSource: no 'pegs file' input\n");
86 egsWarning(
"EGS_BeamSource: no 'input file' input\n");
88 if (err1 || err2 || err3) {
92 int err_eh = input->
getInput(
"egs_home",egs_home);
94 char *eh = getenv(
"EGS_HOME");
96 egsWarning(
"EGS_BeamSource: EGS_HOME is not defined\n");
107 int err_hh = input->
getInput(
"hen_house",hen_house);
109 char *hh = getenv(
"HEN_HOUSE");
111 egsWarning(
"EGS_BeamSource: HEN_HOUSE is not defined\n");
121 string path = egs_home;
126 InitFunction init = (InitFunction)
127 lib->
resolve(F77_NAME_(beamlib_init,BEAMLIB_INIT));
129 lib->
resolve(F77_NAME_(beamlib_finish,BEAMLIB_FINISH));
131 lib->
resolve(F77_NAME_(beamlib_sample,BEAMLIB_SAMPLE));
132 motionsample = (MotionSampleFunction)
133 lib->
resolve(F77_NAME_(beamlib_motionsample,BEAMLIB_MOTIONSAMPLE));
134 MaxEnergyFunction maxenergy = (MaxEnergyFunction)
135 lib->
resolve(F77_NAME_(beamlib_max_energy,BEAMLIB_MAX_ENERGY));
137 egsWarning(
"EGS_BeamSource: failed to resolve the init function\n");
140 egsWarning(
"EGS_BeamSource: failed to resolve the sample function\n");
143 egsWarning(
"EGS_BeamSource: failed to resolve the motionsample function\n");
146 egsWarning(
"EGS_BeamSource: failed to resolve the finish function\n");
149 egsWarning(
"EGS_BeamSource: failed to resolve the max. energy function\n");
163 init(&ipar,&npar,&ilog,hen_house.c_str(),egs_home.c_str(),
164 beam_code.c_str(),pegs_file.c_str(),input_file.c_str(),
165 hen_house.size(), egs_home.size(),
166 beam_code.size(),pegs_file.size(),input_file.size());
171 vector<EGS_Float> cutout;
172 int err = input->
getInput(
"cutout",cutout);
173 if (!err && cutout.size() == 4) {
174 setCutout(cutout[0],cutout[1],cutout[2],cutout[3]);
176 vector<string> ptype;
177 ptype.push_back(
"electrons");
178 ptype.push_back(
"photons");
179 ptype.push_back(
"positrons");
180 ptype.push_back(
"all");
181 ptype.push_back(
"charged");
182 particle_type = input->
getInput(
"particle type",ptype,3)-1;
184 vector<EGS_Float> wwindow;
185 err = input->
getInput(
"weight window",wwindow);
186 if (!err && wwindow.size() == 2) {
192 err = input->
getInput(
"reuse photons",ntmp);
193 if (!err && ntmp > 1) {
194 n_reuse_photon = ntmp;
196 err = input->
getInput(
"reuse electrons",ntmp);
197 if (!err && ntmp > 1) {
198 n_reuse_electron = ntmp;
204 motionsample(&tei,&txi,&tyi,&tzi,&tui,&tvi,&twi,&twti,&tqi,&tlatchi,&counti,&tiphati,&ttimei);
207 if (ttimei >= 0.0 && ttimei <= 1.0) {
208 egsInformation(
"EGS_BeamSource:: Time index passed from this source.\n");
213 use_iparticle =
true;
219 otype=
"EGS_BeamSource";
224 if (n_reuse_photon > 0 && i_reuse_photon < n_reuse_photon) {
235 if (n_reuse_electron > 0 && i_reuse_electron < n_reuse_electron) {
246 EGS_Float te,tx,ty,tz,tu,tv,tw,twt,ttime;
247 int tq,tlatch,tiphat;
268 motionsample(&te,&tx,&ty,&tz,&tu,&tv,&tw,&twt,&tq,&tlatch,&count,&tiphat,&ttime);
275 egsWarning(
"EGS_BeamSource::getNextParticle: Time index is stored in this source but time returned < 0\n");
287 if (particle_type < 2 && tq != particle_type) {
290 if (particle_type == 3 && !tq) {
293 if (tx < Xmin || tx > Xmax || ty < Ymin || ty > Ymax) {
296 if (twt < wmin || twt > wmax) {
301 i_reuse_electron = n_reuse_electron;
302 i_reuse_photon = n_reuse_photon;
307 bool save_it =
false;
308 if (n_reuse_photon > 1 && !tq) {
309 twt /= n_reuse_photon;
313 if (n_reuse_electron > 1 && tq) {
314 twt /= n_reuse_electron;
315 i_reuse_electron = 1;
354 EGS_BeamSource::~EGS_BeamSource() {
365 static void setInputs() {
368 setBaseSourceInputs(
false,
false);
370 srcBlockInput->getSingleInput(
"library")->setValues({
"egs_beam_source"});
373 srcBlockInput->addSingleInput(
"beam code",
true,
"The name of the BEAMnrc user code. Note that it must be compiled as a shared library, which is not done by default.");
374 srcBlockInput->addSingleInput(
"pegs file",
true,
"The name of the PEGS file to be used in the BEAMnrc simulation. Use 'pegsless' if a pegs file is not used.");
375 srcBlockInput->addSingleInput(
"input file",
true,
"The name of the BEAMnrc input file, that must reside in the accelerator directory. Make sure to test running BEAMnrc with it before using it here!");
376 srcBlockInput->addSingleInput(
"cutout",
false,
"Discard particles outside of a rectanglular field: 'x1 y1 x2 y2'");
377 srcBlockInput->addSingleInput(
"particle type",
false,
"The type of particle to keep from the BEAMnrc simulation. Other types are discarded.", {
"all",
"electrons",
"photons",
"positrons",
"charged"});
378 srcBlockInput->addSingleInput(
"weight window",
false,
"A weight window, outside of which particles are discarded: 'wtmin wtmax'. This allows you to discard high weight particles.");
381 EGS_BEAM_SOURCE_EXPORT
string getExample() {
385 # Example of egs_beam_source
387 library = egs_beam_source
389 beam code = BEAM_EX10MeVe
397 EGS_BEAM_SOURCE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
401 return srcBlockInput;
407 createSourceTemplate<EGS_BeamSource>(input,f,
"beam source");
Base class for advanced EGSnrc C++ applications.
static EGS_Application * activeApplication()
Get the active application.
int getNparallel() const
Returns the number of parallel jobs executing.
int getIparallel() const
Returns the job number in a parallel run.
Base source class. All particle sources must be derived from this class.
string description
A short source description.
SampleFunction sample
The function that returns the next particle.
void containsDynamic(bool &hasdynamic)
Check if the simulation source contains time indices.
EGS_BeamSource(EGS_Input *, EGS_ObjectFactory *f=0)
Create a BEAM simulation source from the input inp.
bool time_stored
true if time index stored
EGS_Library * lib
The BEAMnrc user code library.
A class for dynamically loading shared libraries.
void * resolve(const char *func)
Returns the address of the exported symbol func.
string otype
The object type.
Base random number generator class. All random number generators should be derived from this class.
A class representing 3D vectors.
EGS_Application class header file.
A BEAM simulation source.
Global egspp functions header file.
EGS_Library class header file.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
string egsExpandPath(const string &aname)
Expands first environment variable found in a file name.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
const EGS_Float veryFar
A very large float.