37 #ifndef EGS_RADIONUCLIDE_SOURCE_
38 #define EGS_RADIONUCLIDE_SOURCE_
55 #ifdef BUILD_RADIONUCLIDE_SOURCE_DLL
56 #define EGS_RADIONUCLIDE_SOURCE_EXPORT __declspec(dllexport)
58 #define EGS_RADIONUCLIDE_SOURCE_EXPORT __declspec(dllimport)
60 #define EGS_RADIONUCLIDE_SOURCE_LOCAL
64 #ifdef HAVE_VISIBILITY
65 #define EGS_RADIONUCLIDE_SOURCE_EXPORT __attribute__ ((visibility ("default")))
66 #define EGS_RADIONUCLIDE_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
68 #define EGS_RADIONUCLIDE_SOURCE_EXPORT
69 #define EGS_RADIONUCLIDE_SOURCE_LOCAL
94 vector<BetaRecordLeaf *> myBetas = decays->getBetaRecords();
96 for (vector<BetaRecordLeaf *>::iterator beta = myBetas.begin();
97 beta != myBetas.end(); beta++) {
100 if ((*beta)->getCharge() == 1 &&
101 (*beta)->getPositronIntensity() == 0) {
105 unsigned short int daughterZ = (*beta)->getZ();
108 "Energy, Z, A, forbidden: %f %d %d %d\n",
109 (*beta)->getFinalEnergy(), daughterZ,
110 (*beta)->getAtomicWeight(), (*beta)->getForbidden()
114 EGS_Float *e =
new EGS_Float [nbin];
115 EGS_Float *spec =
new EGS_Float [nbin];
116 EGS_Float *spec_y =
new EGS_Float [nbin];
118 double de, s_y, factor, se_y;
124 emax = (*beta)->getFinalEnergy();
125 zzz[0] = (double)daughterZ;
126 rmass = (*beta)->getAtomicWeight();
133 if (daughterZ == 18 && (*beta)->getCharge() == -1) {
138 else if (daughterZ == 54 && emax < 0.154 && emax > 0.150) {
143 else if (daughterZ == 56 && emax > 1.173 && emax < 1.177) {
148 else if (daughterZ == 82) {
153 else if (daughterZ == 84) {
157 lamda[0] = (*beta)->getForbidden();
162 if ((*beta)->getCharge() == 1) {
175 de=((int)(etop[0]*10.0+1)/10.)/nbin;
179 for (
int ib=0; ib<nbin; ib++) {
186 for (
int ib=0; ib<nbin; ib++) {
189 sp(e[ib],spec_y[ib],factor);
196 se_y=se_y+spec_y[ib]*e[ib];
199 for (
int ib=0; ib<nbin; ib++) {
200 spec[ib]=1/de*(spec_y[ib]/s_y);
205 (*beta)->setSpectrum(bspec);
208 if (outputBetaSpectra ==
"yes") {
211 ostr << decays->radionuclide <<
"_" << emax <<
".spec";
213 egsInformation(
"EGS_RadionuclideBetaSpectrum: Outputting beta spectrum to file: %s\n", ostr.str().c_str());
216 specStream.open(ostr.str().c_str());
217 for (
int ib=0; ib<nbin; ib++) {
218 spec[ib]=1/de*(spec_y[ib]/s_y);
219 specStream << e[ib] <<
" " << spec[ib] << endl;
228 complex<double> cgamma(complex<double> z) {
230 static const int g=7;
231 static const double pi = 3.1415926535897932384626433832795028841972;
232 static const double p[g+2] = {0.99999999999980993, 676.5203681218851,
237 -0.13857109526572012,
238 9.9843695780195716e-6,
239 1.5056327351493116e-7
243 return pi / (sin(pi*z)*cgamma(
double(1.0)-z));
247 complex<double> x=p[0];
248 for (
int i=1; i<g+2; i++) {
249 x += p[i]/(z+complex<double>(i,0));
251 complex<double> t = z + (g + double(0.5));
253 return double(sqrt(2.*pi)) * pow(t,z+
double(0.5)) * exp(-t) * x;
256 complex<double> clgamma(complex<double> z) {
257 complex<double> u, v, h, p, r;
259 static const double pi = 3.1415926535897932384626433832795028841972;
260 static const double c1 = 9.189385332046727e-1;
261 static const double c2 = 1.144729885849400;
262 static const double c[10] = {8.333333333333333e-2,
263 -2.777777777777777e-3,
264 7.936507936507936e-4,
265 -5.952380952380952e-4,
266 8.417508417508417e-4,
267 -1.917526917526917e-3,
268 6.410256410256410e-3,
269 -2.955065359477124e-2,
270 1.796443723688305e-1,
274 static const double hf = 0.5;
280 if (y == 0 && -abs(x) ==
int(x)) {
286 u = double(1.) - complex<double>(x, ya);
289 u = complex<double>(x, ya);
299 for (
int i=1; i<=6-int(ur); i++) {
301 u = complex<double>(ur, ui);
303 a = a + atan2(ui, ur);
305 h = complex<double>(hf * log(pow(real(h),2) + pow(imag(h),2)),
311 r = double(1.) / pow(u,2);
314 for (
int i=8; i>=1; i--) {
318 h = c1 + (u-hf)*log(u) - u + (c[0]+p) / u - h;
321 ur = double(
int(x)) - 1.;
324 double t = exp(-x-x);
326 t = x + hf * log(t*pow(a,2)+pow(hf*(1.-t),2));
327 a = atan2(cos(ui)*tanh(x),a) - ur*pi;
328 h = c2 - complex<double>(t,a) - h;
338 void slfact(
double p,
double z,
double radf,
double xl[4]) {
341 double dfac[4]= {1.0, 3.0, 15.0, 105.0};
342 double pi,c137,az,w,rad,pr,y,x1,gk,bb,cc,dd,x2;
354 for (
int k=1; k<=4; k++) {
356 gk = sqrt(k*k-az*az);
357 x1 = pow((pow(p,k-1)/dfac[k-1]),2);
359 aa = clgamma(complex<double>(gk,y));
360 double aa_real = real(aa);
362 bb=lgamma((
double)k);
363 cc=lgamma(2.0*k +1.0);
364 dd=lgamma(2.0*gk+1.0);
367 pow(2.0*pr, 2.0*(gk-k)) *
368 exp(pi*y+2.0*(aa_real+cc-bb-dd)) *
373 az*pr*(2.0*w*(2.0*k+1.0)/(p*k*(2.0*gk+1.0)) -
374 2.0*p*gk/(w*k*(2.0*gk+1.0))) -
375 2.0*k*pr*pr/((2.0*k+1.0)*(k+gk));
376 xl[k-1] = x1*ff[k-1]/ff[0]*x2;
382 void bsp(
double e,
double &bspec,
double &factor) {
405 double pi,c137,zab,v,z,x,w,psq,p,y,qsq,g,cab,f,radf;
420 v = 1.13*pow(zab,1.333)/pow(c137,2);
430 psq = w*w-double(1.0);
434 qsq = 3.83*pow(emax-e,2);
439 g = qsq*2.0*pi*pow(z,(2.0*x-1.0));
443 a = complex<double>(x,y);
446 f = pow(psq,x-1.0)*exp(pi*y)*pow(cab,2);
456 radf = 1.2*pow(rmass,0.333);
457 slfact(p,zz,radf,xl);
460 bspec = g*(qsq*xl[0]+9.0*xl[1]);
464 bspec = g*(pow(qsq,2)*xl[0]+30.0*qsq*xl[1]+225.0*xl[2]);
468 bspec = g*(pow(qsq,3.0)*xl[0]+63.0*pow(qsq,2)*xl[1]+
469 1575.0*qsq*xl[2] + 11025.0*xl[3]);
479 bspec = bspec*(qsq*xl[0]+20.07*xl[1]);
484 bspec = bspec*(psq+10.0*qsq);
489 bspec = bspec*(qsq*xl[0]+0.045*xl[1]);
494 bspec = bspec*(1.0-1.677*e+ 2.77*e*e);
499 bspec = bspec*(1.78-2.35*e+e*e);
507 void sp(
double e,
double &spec,
double &factor) {
512 for (
int icomp=0; icomp<ncomps; icomp++) {
517 spec= spec+bspec*rel[icomp]/area[icomp];
523 double zz,emax,rmass;
524 double zzz[9],etop[9],rel[9],area[9],lamda[9];
651 const EGS_Float relativeActivity,
const string relaxType,
const string outputBetaSpectra,
const bool scoreAlphasLocally,
const bool allowMultiTransition);
696 return spectrumWeight;
701 spectrumWeight = newWeight;
728 void printSampledEmissions();
734 bool storeState(ostream &data)
const {
738 bool setState(istream &data) {
742 void resetCounter() {
746 totalGammaEnergy = 0;
755 vector<BetaRecordLeaf *> myBetas;
756 vector<AlphaRecord *> myAlphas;
757 vector<GammaRecord *> myGammas,
759 myUncorrelatedGammas;
760 vector<LevelRecord *> myLevels;
761 vector<double> xrayIntensities,
765 vector<EGS_I64> numSampledXRay,
767 vector<const LevelRecord *> multiTransitions;
771 unsigned int emissionType;
772 EGS_Float currentTime,
778 string relaxationType;
779 bool scoreAlphasLocal;
992 if (!baseSource->deref()) {
996 for (vector<EGS_RadionuclideSpectrum * >::iterator it =
998 it!=decays.end(); it++) {
1007 int &q,
int &latch, EGS_Float &E, EGS_Float &wt,
1017 return (ishower+1)*(baseSource->getFluence()/sCount);
1032 return experimentTime;
1040 unsigned int getEmissionType()
const {
1041 return emissionType;
1046 egsInformation(
"\n======================================================\n");
1048 for (
unsigned int i=0; i<decays.size(); ++i) {
1049 decays[i]->printSampledEmissions();
1052 egsInformation(
"======================================================\n\n");
1094 vector<EGS_Ensdf *> decayEnsdf;
1095 for (
auto dec: decays) {
1096 decayEnsdf.push_back(dec->getRadionuclideEnsdf());
1113 vector<int> q_allowed;
1114 vector<EGS_RadionuclideSpectrum *> decays;
1118 bool disintegrationOccurred;
1125 unsigned int emissionType;
A class for sampling random values from a given probability distribution using the alias table techni...
Base class for advanced EGSnrc C++ applications.
static EGS_Application * activeApplication()
Get the active application.
Base source class. All particle sources must be derived from this class.
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
virtual void resetCounter()
Reset the source state.
virtual EGS_I64 getNextParticle(EGS_RandomGenerator *rndm, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)=0
Sample the next source particle from the source probability distribution.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
virtual vector< EGS_Ensdf * > getRadionuclideEnsdf()
Get the radionuclide ENSDF object from the source.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
The ensdf class for reading ensdf format data files.
Beta spectrum generation for EGS_RadionuclideSpectrum.
EGS_RadionuclideBetaSpectrum(EGS_Ensdf *decays, const string outputBetaSpectra)
Construct beta spectra for a radionuclide.
double getTime() const
Returns the emission time of the most recent particle.
EGS_Float getEmax() const
Returns the maximum energy out of all the spectra.
void printSampledEmissions()
Outputs the emission stats of the spectra.
EGS_Float getFluence() const
Returns the current fluence (number of disintegrations)
bool isValid() const
Checks the validity of the source.
~EGS_RadionuclideSource()
Destructor.
double getExperimentTime() const
Get the total possible length of the experiment that is being modelled.
EGS_I64 getShowerIndex() const
Returns the shower index of the most recent particle.
unsigned int getEmissionType() const
Get the emission type of the most recent source particle.
~EGS_RadionuclideSpectrum()
Destructor.
EGS_Float getSpectrumWeight() const
Get the relative weight assigned to this spectrum.
EGS_Float maxEnergy() const
Returns the maximum energy that may be emitted.
EGS_I64 getShowerIndex() const
Get the shower index of the most recent emission.
double getTime() const
Get the emission time of the most recent emission.
EGS_Float getEdep() const
Get energy that should be deposited locally from relaxations/alphas.
void setSpectrumWeight(EGS_Float newWeight)
Set the relative weight assigned to this spectrum.
int getCharge() const
Get the charge of the most recent emission.
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.
EGS_BaseGeometry class header file.
EGS_BaseSource class header file.
The ensdf implementation.
#define EGS_EXPORT
Export symbols from the egspp library.
Attempts to fix broken math header files.
EGS_RandomGenerator class header file.
EGS_BaseShape and shape classes header file.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
bool EGS_EXPORT egsStoreI64(ostream &data, EGS_I64 n)
Writes the 64 bit integer n to the output stream data and returns true on success,...
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
bool EGS_EXPORT egsGetI64(istream &data, EGS_I64 &n)
Reads a 64 bit integer from the stream data and assigns it to n. Returns true on success,...