45 #ifndef EGS_FLUENCE_SCORING_
46 #define EGS_FLUENCE_SCORING_
59 #ifdef BUILD_FLUENCE_SCORING_DLL
60 #define EGS_FLUENCE_SCORING_EXPORT __declspec(dllexport)
62 #define EGS_FLUENCE_SCORING_EXPORT __declspec(dllimport)
64 #define EGS_FLUENCE_SCORING_LOCAL
68 #ifdef HAVE_VISIBILITY
69 #define EGS_FLUENCE_SCORING_EXPORT __attribute__ ((visibility ("default")))
70 #define EGS_FLUENCE_SCORING_LOCAL __attribute__ ((visibility ("hidden")))
72 #define EGS_FLUENCE_SCORING_EXPORT
73 #define EGS_FLUENCE_SCORING_LOCAL
82 enum ParticleType { electron = -1, photon = 0, positron = 1, unknown = -99 };
108 void getSensitiveRegions(
EGS_Input *inp);
110 void getNumberRegions(
const string &str, vector<int> ®s);
112 void getLabelRegions(
const string &str, vector<int> ®s);
114 void setUpRegionFlags();
118 int getDigits(
int i) {
123 return (
int)log10((
float)imax);
126 void flagSecondaries(
const int &iarg,
const int &q) {
127 int npold = app->getNpOld(),
129 if (scoring_charge) {
156 for (
int ip = npold+1; ip <= np; ip++) {
166 app->setLatch(np-1,1);
180 for (
int ip = npold; ip <= np; ip++) {
190 EGS_I64 current_ncase;
202 vector<bool> is_sensitive;
203 vector<bool> is_source;
205 vector <int> f_start, f_stop;
206 vector <int> f_region;
207 vector <int> s_region;
208 string f_regionsString;
209 string s_regionsString;
210 int n_scoring_regions;
211 int n_source_regions;
215 bool score_in_all_regions;
216 bool source_in_all_regions;
221 EGS_Float flu_a, flu_a_i,
231 string particle_name;
332 else if (score_primaries &&
349 inline int hitsField(
const EGS_Particle &p, EGS_Float *dist);
350 inline void score(
const EGS_Particle &p,
const int &ivoxel);
356 void reportResults();
359 int q = app->top_p.q,
362 if (q == scoring_charge && ir >= 0 && is_sensitive[ir]) {
366 ixy = hitsField(app->top_p,&distance);
378 if (xstep.length() >= distance) {
380 m_tot += app->top_p.wt;
381 score(app->top_p, ixy);
396 if (score_primaries && ir >= 0 && !is_source[ir]) {
397 flagSecondaries(iarg, q);
404 void setCurrentCase(EGS_I64 ncase) {
405 if (ncase != current_ncase) {
406 current_ncase = ncase;
408 fluT->setHistory(ncase);
411 for (
int j = 0; j < Nx*Ny; j++) {
412 flu[j]->setHistory(ncase);
416 if (score_primaries) {
417 fluT_p->setHistory(ncase);
419 for (
int j = 0; j < Nx*Ny; j++) {
420 flu_p[j]->setHistory(ncase);
427 void resetCounter() {
431 for (
int j = 0; j < Nx*Ny; j++) {
435 if (score_primaries) {
438 for (
int j = 0; j < Nx*Ny; j++) {
444 bool storeState(ostream &data)
const;
445 bool setState(istream &data);
446 bool addState(istream &data);
461 EGS_Float ax, ay, vx, vy;
462 int Nx, Ny, n_sensitive_regs, ixy;
571 else if (score_primaries &&
598 void reportResults();
602 int q = app->top_p.q,
604 latch = app->top_p.latch;
606 if (q == scoring_charge && ir >= 0 && is_sensitive[ir]) {
612 EGS_Float wtstep = app->top_p.wt*app->getTVSTEP();
614 fluT->score(ir,wtstep);
615 if (score_primaries && !latch) {
616 fluT_p->score(ir,wtstep);
620 EGS_Float e = app->top_p.E;
627 if (e > flu_xmin && e <= flu_xmax) {
628 ae = flu_a*e + flu_b;
629 je = min((
int)ae,flu_nbin-1);
631 aux->
score(je,wtstep);
632 if (score_primaries && !latch) {
633 flu_p[ir]->score(je,wtstep);
641 EGS_Float edep = app->getEdep();
651 EGS_Float weight = app->top_p.wt;
652 bool score_p = score_primaries && !latch;
662 EGS_Float a_step = weight*app->getTVSTEP();
663 auxT->
score(ir,a_step);
665 auxT_p->score(ir,a_step);
677 EGS_Float Eb = app->top_p.E - app->getRM(),
697 if (xb > flu_xmin && xe < flu_xmax) {
702 ab = flu_a*xb + flu_b;
706 ab = (Eb*a_const[jb]-1)*r_const;
719 ae = flu_a*xe + flu_b;
723 ae = (Ee*a_const[je]-1)*r_const;
743 binDist->score(jb-je,weight);
745 EGS_Float totStep = 0, the_step = app->getTVSTEP();
765 int imed = app->getMedium(ir);
769 step = weight*(ab-ae)*getStepPerEnergyLoss(imed,xb,xe);
777 aux_p->
score(jb,step);
785 Ee = flu_xmin + jb*flu_a_i;
787 step = weight*ab*getStepPerEnergyLoss(imed,Eb,Ee);
795 aux_p->
score(jb,step);
802 Eb = flu_xmin+(je+1)*flu_a_i;
803 step = weight*(1-ae)*getStepPerEnergyLoss(imed,Eb,Ee);
811 aux_p->
score(je,step);
817 for (
int j=je+1; j<jb; j++) {
818 if (flu_stpwr == stpwrO5) {
820 Eb = flu_xmin + (j+1)*flu_a_i;
828 step = weight*getStepPerEnergyLoss(imed,Eb,Ee);
831 step = weight*Lmid_i[j + imed*flu_nbin];
840 aux_p->
score(j,step);
860 EGS_Float step, wtstep = weight*app->getTVSTEP()/edep;
863 step = wtstep*(ab-ae);
871 aux_p->
score(jb,step);
887 aux_p->
score(jb,step);
893 step = wtstep*(1-ae);
901 aux_p->
score(je,step);
905 for (
int j=je+1; j<jb; j++) {
911 aux->
score(j,wtstep);
913 aux_p->
score(j,wtstep);
921 EGS_Float edep_step = totStep*flu_a_i, diff = edep_step/the_step;
922 EGS_Float astep = step_a*the_step + step_b;
923 int jstep = (int) astep;
924 if (jstep < 0 || jstep > n_step_bins) {
925 egsFatal(
"\n**** EGS_VolumetricFluence::processEvent-> jstep = %d\n is out of bound!\n");
927 stepDist->score(jstep,app->top_p.wt);
928 relStepDiff->score(jstep,diff);
946 if (score_primaries && ir >= 0 && !is_source[ir]) {
947 flagSecondaries(iarg, q);
970 const EGS_Float &Ee) {
971 EGS_Float stpFrac, eps, lnEmid;
973 eps = 1 - exp(Ee-Eb);
975 lnEmid = 0.5*(Eb+Ee+0.25*eps*eps*(1+eps*(1+0.875*eps)));
978 if (flu_stpwr == stpwrO5) {
981 lnEmid = log(0.5*(Eb+Ee));
984 EGS_Float dedxmid_i = dedx_i[imed].interpolate(lnEmid);
988 if (!isfinite(dedxmid_i)) {
989 if (isnan(dedxmid_i)) {
998 egsInformation(
"\n Is negative? dedxmid_i = %g Emid = %g lnEmid = %g index = %d",
999 dedxmid_i,exp(lnEmid),lnEmid, dedx_i[imed].getIndex(lnEmid));
1001 if (dedxmid_i > 1.E10) {
1002 egsInformation(
"\n Is very large? dedxmid_i = %g Emid = %g lnEmid = %g",dedxmid_i,exp(lnEmid),lnEmid);
1008 if (flu_stpwr == stpwr) {
1013 EGS_Float b = i_dedx[imed].get_b(i_dedx[imed].getIndexFast(lnEmid));
1014 EGS_Float aux = b*dedxmid_i;
1015 aux = aux*(1+2*aux)*pow(eps/(2-eps),2)/6;
1017 stpFrac = dedxmid_i*(1+aux);
1022 void setCurrentCase(EGS_I64 ncase) {
1023 if (ncase != current_ncase) {
1024 current_ncase = ncase;
1025 fluT->setHistory(ncase);
1026 if (score_primaries) {
1027 fluT_p->setHistory(ncase);
1030 for (
int j = 0; j < nreg; j++) {
1031 if (is_sensitive[j]) {
1032 flu[j]->setHistory(ncase);
1035 if (score_primaries) {
1036 for (
int j = 0; j < nreg; j++) {
1037 if (is_sensitive[j]) {
1038 flu_p[j]->setHistory(ncase);
1045 binDist->setHistory(ncase);
1046 if (scoring_charge) {
1047 stepDist->setHistory(ncase);
1048 relStepDiff->setHistory(ncase);
1053 void resetCounter() {
1056 if (score_primaries) {
1060 for (
int j = 0; j < nreg; j++) {
1061 if (is_sensitive[j]) {
1066 if (score_primaries) {
1067 for (
int j = 0; j < nreg; j++) {
1068 if (is_sensitive[j]) {
1076 if (scoring_charge) {
1078 relStepDiff->reset();
1083 bool storeState(ostream &data)
const;
1085 bool setState(istream &data);
1087 bool addState(istream &data);
1111 vector<EGS_Float> volume;
1115 vector <EGS_Float> vol_list;
1119 int one_bin, multi_bin;
1124 EGS_Float step_a, step_b;
1125 EGS_I32 n_step_bins;
A class for scoring an array of quantities (e.g. a dose distribution) in a Monte Carlo simulation...
EGS_AusgabObject interface class header file.
after a Compton scattering event
Ausgab object for scoring fluence at circular or rectangular fields.
AusgabCall
Possible calls to the user scoring function ausgab().
A class representing 3D vectors.
after a bremsstrahlung interaction
A structure holding the information of one particle.
after annihilation in flight
after an inelastic collision (e+)
after coherent scattering
after a photo-absorption event
Base class for fluence scoring.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
after an inelastic collision (e-)
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
A class for fast run-time interpolations.
Ausgab object for scoring fluence in arbitrary geometry regions.
void score(int ireg, EGS_Float f)
Add f to the score in the element ireg.
after annihilation at rest
EGS_Float getStepPerEnergyLoss(const int &imed, const EGS_Float &Eb, const EGS_Float &Ee)
EGS_ScoringSingle and EGS_ScoringArray class header file.
EGS_Interpolator class header file.
Base class for advanced EGSnrc C++ applications.