125 bool loadData(istream &data);
128 return ttypes[table->sample(rndm)];
133 bool EGS_ShellData::loadData(istream &data) {
136 data.read((
char *)&t,
sizeof(
char));
138 data.read((
char *)&ntrans,
sizeof(
short));
139 data.read((
char *)&be,
sizeof(
float));
141 if (data.fail() || ntrans > 10000) {
148 ttypes =
new unsigned short [ntrans];
149 EGS_Float *tmp =
new EGS_Float [ntrans];
151 for (
int i=0; i<ntrans; ++i) {
152 data.read((
char *)&ttypes[i],
sizeof(
unsigned short));
153 data.read((
char *)&aux,
sizeof(
float));
177 int loadData(
int iZ, istream &data);
195 int EGS_ElementRelaxData::loadData(
int iZ, istream &data) {
201 int pos = 2 + (Z-1)*
sizeof(
int);
202 data.seekg(pos,ios::beg);
203 data.read((
char *)&pos,
sizeof(
int));
205 egsWarning(
"Failed reading position for element %d\n",Z);
209 data.seekg(pos,ios::beg);
210 data.read((
char *)&nshell,
sizeof(nshell));
211 if (data.fail() || nshell < 1 || nshell > 63) {
212 egsWarning(
"Failed reading number of shells for Z=%d (got %d shells and fail()=%d\n",
213 Z,nshell,data.fail());
219 for (
int j=0; j<nshell; ++j) {
220 if (!shells[j].loadData(data)) {
221 egsWarning(
"Failed loading data for shell %d of element %d\n",j+1,Z);
234 data_file =
egsJoinPath(data_path,
"relax_onebyte.data");
239 for (
int j=0; j<nz; ++j) {
249 int loadData(
int Z, istream &data);
250 int loadData(
int Nz,
const int *Zarray);
253 int openDataFile(istream **data);
255 void checkData(
int Z,
int shell) {
256 static const char *func_name =
"checkData";
258 if (loadData(Z))
egsFatal(
"%s: failed to load data for Z=%d\n",
261 egsFatal(
"%s: Z=%d is outside of initialized range 1...%d\n",
263 if (shell < 0 || shell >= elements[Z-1]->nshell)
264 egsFatal(
"%s: element %d has %d shells but you are asking for "
265 "shell %d\n",func_name,Z,elements[Z-1]->nshell,shell);
268 void relax(
int Z,
int sh, EGS_Float ecut, EGS_Float pcut,
272 EGS_Float minE = pcut < ecut ? pcut : ecut;
273 relax(Z,sh,minE,ecut,pcut,rndm,edep,particles);
276 EGS_Float bindingEnergy(
int Z,
int shell) {
278 return elements[Z-1]->shells[shell].be;
281 int getNShell(
int Z) {
282 return elements[Z-1]->nshell;
285 void setBindingEnergy(
int Z,
int shell, EGS_Float new_be) {
287 elements[Z-1]->shells[shell].be = new_be;
290 EGS_Float getMaxGammaEnergy(
int Z,
int shell) {
292 int ntrans = elements[Z-1]->shells[shell].ntrans;
296 EGS_Float E = elements[Z-1]->shells[shell].be;
298 for (
int j=0; j<ntrans; ++j) {
299 int transition = elements[Z-1]->shells[shell].ttypes[j];
300 if (transition < 64) {
301 EGS_Float Egamma = E - elements[Z-1]->shells[transition].be;
310 EGS_Float getMaxElectronEnergy(
int Z,
int shell) {
312 int ntrans = elements[Z-1]->shells[shell].ntrans;
316 EGS_Float E = elements[Z-1]->shells[shell].be;
318 for (
int j=0; j<ntrans; ++j) {
319 int transition = elements[Z-1]->shells[shell].ttypes[j];
320 if (transition >= 64) {
321 int sh1 = (transition >> 6);
322 int sh2 = transition - (sh1 << 6);
323 EGS_Float Eelec = E - (elements[Z-1]->shells[sh1].be +
324 elements[Z-1]->shells[sh2].be);
333 void relax(
int Z,
int sh, EGS_Float minE, EGS_Float ecut, EGS_Float pcut,
336 EGS_Float E = elements[Z-1]->shells[sh].be;
338 if (E <= minE || elements[Z-1]->shells[sh].ntrans < 1) {
343 int transition = elements[Z-1]->shells[sh].sample(rndm);
345 if (transition < 64) {
346 EGS_Float Egamma = E - elements[Z-1]->shells[transition].be;
355 relax(Z,transition,minE,ecut,pcut,rndm,edep,particles);
358 int sh1 = (transition >> 6);
359 int sh2 = transition - (sh1 << 6);
360 EGS_Float Eelec = E - elements[Z-1]->shells[sh1].be - elements[Z-1]->shells[sh2].be;
369 relax(Z,sh1,minE,ecut,pcut,rndm,edep,particles);
370 relax(Z,sh2,minE,ecut,pcut,rndm,edep,particles);
380 int EGS_RelaxImplementation::openDataFile(istream **the_data) {
381 static const char *func_name =
"EGS_RelaxImplementation::openDataFile()";
383 ifstream *data =
new ifstream(data_file.c_str(),ios::binary);
385 egsWarning(
"%s: failed to open data file %s\n",
386 func_name,data_file.c_str());
390 data->read((
char *)&Nz,
sizeof(
short));
391 if (data->fail() || Nz < 1 || Nz > 200) {
392 egsWarning(
"%s: failed reading first record from %s\n",
393 func_name,data_file.c_str());
399 for (
int j=0; j<nz; ++j) {
400 new_elements[j] = elements[j];
405 for (
int j=0; j<Nz; ++j) {
409 elements = new_elements;
417 int EGS_RelaxImplementation::loadData(
int Z) {
418 static const char *func_name =
"EGS_RelaxImplementation::loadData()";
420 egsWarning(
"%s: called with Z=%d?\n",func_name,Z);
424 int res = openDataFile(&the_data);
425 if (res || !the_data) {
428 istream &data = *the_data;
430 egsWarning(
"%s: called with Z=%d, but I only have data for Z<=%d.\n",
434 res = loadData(Z,data);
439 int EGS_RelaxImplementation::loadData(
int Z, istream &data) {
444 return elements[Z-1]->loadData(Z,data);
447 int EGS_RelaxImplementation::loadData(
int Nz,
const int *Zarray) {
449 int res = openDataFile(&the_data);
450 if (res || !the_data) {
453 istream &data = *the_data;
454 for (
int j=0; j<Nz; ++j) {
455 res = loadData(Zarray[j],data);
464 int EGS_RelaxImplementation::loadAllData() {
466 int res = openDataFile(&the_data);
467 if (res || !the_data) {
470 istream &data = *the_data;
471 for (
int Z=1; Z<=nz; ++Z) {
472 res = loadData(Z,data);
489 char *hen_house = getenv(
"HEN_HOUSE");
491 egsWarning(
"EGS_AtomicRelaxations::EGS_AtomicRelaxations: "
492 "no active application and HEN_HOUSE not defined.\n"
493 " assuming local directory for relax data\n");
507 EGS_AtomicRelaxations::~EGS_AtomicRelaxations() {
512 return p->loadData(Z);
516 return p->loadData(nz,Zarray);
520 return p->loadAllData();
526 p->relax(Z,sh,ecut,pcut,rndm,edep,particles);
530 return p->bindingEnergy(Z,shell);
534 return p->getNShell(Z);
539 p->setBindingEnergy(Z,shell,new_be);
543 return p->getMaxGammaEnergy(Z,shell);
547 return p->getMaxElectronEnergy(Z,shell);
unsigned short type
shell type according to EADL nomenclature
EGS_SimpleAliasTable * table
for sampling transitions
EGS_Float getMaxGammaEnergy(int Z, int shell)
unsigned short * ttypes
types of the ntrans transitions
EGS_AliasTable class header file.
EGS_AtomicRelaxations(const char *data_path=0)
EGS_AtomicRelaxations class header file.
string egsJoinPath(const string &first, const string &second)
Join two path variables (or a path and a file name) using the platform specific directory separator a...
unsigned short Z
atomic number
Global egspp functions header file.
unsigned short ntrans
number of transitions
EGS_Float getBindingEnergy(int Z, int shell)
void relax(int Z, int sh, EGS_Float ecut, EGS_Float pcut, EGS_RandomGenerator *rndm, double &edep, EGS_SimpleContainer< EGS_RelaxationParticle > &particles)
EGS_Float getMaxElectronEnergy(int Z, int shell)
Base random number generator class. All random number generators should be derived from this class...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_RandomGenerator class header file.
A class for sampling random bins from a given probability distribution using the alias table techniqu...
void setBindingEnergy(int Z, int shell, EGS_Float new_be)
static EGS_Application * activeApplication()
Get the active application.
unsigned short nshell
number of shells
const string & getHenHouse() const
Returns the HEN_HOUSE directory.
EGS_ShellData * shells
shell data
EGS_Application class header file.
Base class for advanced EGSnrc C++ applications.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.