49 #define STRINGIFY(s) HELP_S(s)
51 #define F77_NAME(fname,FNAME) STRINGIFY(F77_OBJ(fname,FNAME))
52 #define F77_NAME_(fname,FNAME) STRINGIFY(F77_OBJ_(fname,FNAME))
70 int err1 = input->
getInput(
"beam code",beam_code);
72 int err2 = input->
getInput(
"pegs file",pegs_file);
74 int err3 = input->
getInput(
"input file",input_file);
76 egsWarning(
"EGS_BeamSource: no 'beam code' input\n");
79 egsWarning(
"EGS_BeamSource: no 'pegs file' input\n");
82 egsWarning(
"EGS_BeamSource: no 'input file' input\n");
84 if (err1 || err2 || err3) {
88 int err_eh = input->
getInput(
"egs_home",egs_home);
90 char *eh = getenv(
"EGS_HOME");
92 egsWarning(
"EGS_BeamSource: EGS_HOME is not defined\n");
103 int err_hh = input->
getInput(
"hen_house",hen_house);
105 char *hh = getenv(
"HEN_HOUSE");
107 egsWarning(
"EGS_BeamSource: HEN_HOUSE is not defined\n");
117 string path = egs_home;
122 InitFunction init = (InitFunction)
123 lib->
resolve(F77_NAME_(beamlib_init,BEAMLIB_INIT));
125 lib->
resolve(F77_NAME_(beamlib_finish,BEAMLIB_FINISH));
127 lib->
resolve(F77_NAME_(beamlib_sample,BEAMLIB_SAMPLE));
128 motionsample = (MotionSampleFunction)
129 lib->
resolve(F77_NAME_(beamlib_motionsample,BEAMLIB_MOTIONSAMPLE));
130 MaxEnergyFunction maxenergy = (MaxEnergyFunction)
131 lib->
resolve(F77_NAME_(beamlib_max_energy,BEAMLIB_MAX_ENERGY));
133 egsWarning(
"EGS_BeamSource: failed to resolve the init function\n");
136 egsWarning(
"EGS_BeamSource: failed to resolve the sample function\n");
139 egsWarning(
"EGS_BeamSource: failed to resolve the motionsample function\n");
142 egsWarning(
"EGS_BeamSource: failed to resolve the finish function\n");
145 egsWarning(
"EGS_BeamSource: failed to resolve the max. energy function\n");
159 init(&ipar,&npar,&ilog,hen_house.c_str(),egs_home.c_str(),
160 beam_code.c_str(),pegs_file.c_str(),input_file.c_str(),
161 hen_house.size(), egs_home.size(),
162 beam_code.size(),pegs_file.size(),input_file.size());
167 vector<EGS_Float> cutout;
168 int err = input->
getInput(
"cutout",cutout);
169 if (!err && cutout.size() == 4) {
170 setCutout(cutout[0],cutout[1],cutout[2],cutout[3]);
172 vector<string> ptype;
173 ptype.push_back(
"electrons");
174 ptype.push_back(
"photons");
175 ptype.push_back(
"positrons");
176 ptype.push_back(
"all");
177 ptype.push_back(
"charged");
178 particle_type = input->
getInput(
"particle type",ptype,3)-1;
180 vector<EGS_Float> wwindow;
181 err = input->
getInput(
"weight window",wwindow);
182 if (!err && wwindow.size() == 2) {
188 err = input->
getInput(
"reuse photons",ntmp);
189 if (!err && ntmp > 1) {
190 n_reuse_photon = ntmp;
192 err = input->
getInput(
"reuse electrons",ntmp);
193 if (!err && ntmp > 1) {
194 n_reuse_electron = ntmp;
201 motionsample(&tei,&txi,&tyi,&tzi,&tui,&tvi,&twi,&twti,&tqi,&tlatchi,&counti,&tiphati,&tmui);
203 if (tmui >= 0.0 && tmui <= 1.0) {
204 egsInformation(
"EGS_BeamSource:: Mu index passed from this source.\n");
209 use_iparticle =
true;
215 otype=
"EGS_BeamSource";
220 if (n_reuse_photon > 0 && i_reuse_photon < n_reuse_photon) {
231 if (n_reuse_electron > 0 && i_reuse_electron < n_reuse_electron) {
242 EGS_Float te,tx,ty,tz,tu,tv,tw,twt,tmu;
243 int tq,tlatch,tiphat;
264 motionsample(&te,&tx,&ty,&tz,&tu,&tv,&tw,&twt,&tq,&tlatch,&count,&tiphat,&tmu);
269 if (
mu_stored && (tmu < 0. || tmu > 1.0)) {
271 egsWarning(
"EGS_BeamSource::getNextParticle: Mu index is stored in this source but mu returned < 0\n");
283 if (particle_type < 2 && tq != particle_type) {
286 if (particle_type == 3 && !tq) {
289 if (tx < Xmin || tx > Xmax || ty < Ymin || ty > Ymax) {
292 if (twt < wmin || twt > wmax) {
297 i_reuse_electron = n_reuse_electron;
298 i_reuse_photon = n_reuse_photon;
303 bool save_it =
false;
304 if (n_reuse_photon > 1 && !tq) {
305 twt /= n_reuse_photon;
309 if (n_reuse_electron > 1 && tq) {
310 twt /= n_reuse_electron;
311 i_reuse_electron = 1;
330 EGS_BeamSource::~EGS_BeamSource() {
344 createSourceTemplate<EGS_BeamSource>(input,f,
"beam source");
A BEAM simulation source.
EGS_Library * lib
The BEAMnrc user code library.
A class for dynamically loading shared libraries.
SampleFunction sample
The function that returns the next particle.
A class representing 3D vectors.
int getIparallel() const
Returns the job number in a parallel run.
Global egspp functions header file.
const EGS_Float veryFar
A very large float.
int getNparallel() const
Returns the number of parallel jobs executing.
Base random number generator class. All random number generators should be derived from this class...
string egsExpandPath(const string &aname)
Expands first environment variable found in a file name.
bool mu_stored
true if mu index stored
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_Library class header file.
static EGS_Application * activeApplication()
Get the active application.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
string otype
The object type.
void * resolve(const char *func)
Returns the address of the exported symbol func.
EGS_Application class header file.
EGS_BeamSource(EGS_Input *, EGS_ObjectFactory *f=0)
Create a BEAM simulation source from the input inp.
Base class for advanced EGSnrc C++ applications.
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.