Skip to content

Implement range rejection AO#1071

Open
mainegra wants to merge 47 commits intodevelopfrom
feature-range-rejection-ao
Open

Implement range rejection AO#1071
mainegra wants to merge 47 commits intodevelopfrom
feature-range-rejection-ao

Conversation

@mainegra
Copy link
Copy Markdown
Contributor

Turns on EGSnrc intrinsic range rejection (rr) efficiency increasing technique.

TODO: Implement variance reduction technique (VRT) rr-based Russian roulette (RR)

@mainegra mainegra requested a review from a team as a code owner October 24, 2023 02:24
@mainegra mainegra self-assigned this Oct 24, 2023
Blake Walters and others added 24 commits January 14, 2025 15:01
This gets rid of compilation warnings that LITTLE_ENDIAN, BIG_ENDIAN,
and PDP_ENDIAN were already defined on macOS.
Add a new case for aarch64 in the config guess script. The
-mcmodel=medium option is not available on ARM architecture, so this is
handled. Some of the programs fail to build on aarch64 without setting
-Wno-narrowing compiler option, so this is added.
* setup.sh is called when container is created. It installs required
  packages and performs the EGSnrc configuration

* build-gui-apps.sh is called after the container is created and builds
  the GUI apps. It relies upon the configuration being created and
  the .bashrc having been setup

* .gitignore is updated to ignore the files created when building the
  devcontainer configuration. Also added additional QT conf files that
  are generated during build

* README.md provides some basic documentation about using devcontainer
Fix a bug in the field definition pop-up window for dynamic and sync
jaws in beamnrc_gui. The GUI would display an error about a bad window
parent.

Rebase on develop
Add particle tracks that including a time index

Add egs++ time synchronization and viewer support

Allow saving time index to the base source for all simulation objects,
as well as support to visualize simulations in time in the viewer.

Add a pause feature to the viewer play button

If user pushes the play button while the simulation is playing it will
pause the simulation at the current time index. Pushing play again
causes the simulation to restart from paused position. Also, simulations
will now play from current time index instead of defaulting to starting
at zero. If the current time index is the last one it will set time to
zero and start from the beginning.

Set initial position when the viewer is launched

Polish dynamic geometry comments and documentation

Update documentation and formatting

Remove motion control point numbering syntax

Update author first name to match other files

Fix a few minor typos and formatting issues

Apply egs coding style standard with astyle

Run astyle (3.4.11) on all files modified .cpp and .h files in this
dynamic geometry addition.

Tidy up comments to more uniform style and margin

Add time into the standard ptracks format

The ptracks file will now start with "include time index=" and then a
boolean value. egs_view has been updated to support this. This avoids
creating a new .syncptracks file extension, that was originally done in
this implementation. Also changed the default behaviour for
egs_track_scoring so that time index scoring is automatically turned on
when dynamic geometries or sources are used, if "include time index" is
excluded from the input file.

Update references of mu to be time index

This changes the egs_phsp_scoring input parameter "score mu" to instead
be "score time index". Both inputs are supported, for backwards
compatibility.
Add a shape that handles dynamic motion, synchronized with the motion
of geometries and sources.

Add dynamic shape doxygen documentation, astyle

Fix flickering of dynamic particle tracks

Fix flickering that occurred when dragging the time slider with the
mouse. Particle tracks would flash on the screen from a longer time
range than the selected window.

Fix memory leak in dynamic geometry and shape

Fix motion for shapes lacking source direction

Adjust the default viewer time window

Change the time window default to 1% of the simulation duration for
tracks visualization. Also add a new input in egs_view for the number of
time steps to take in the animation. This allows for better control of
the visual speed of the motion.

Remove shape motion control point numbering syntax

Adjust coding style to EGSnrc standard with astyle

Fix missing updateNumTimeSteps function

Somehow a function got deleted during some git manipulation, so this is
just adding it back it.

Set the slider based on the number of time steps
Add an application for calculating gamma spectrometry related
quantities, like detector efficiency and coincidence summing
corrections. The egs_radionuclide_source was changed slightly to allow
for the calculations - it now returns the number of decays from
getNextParticle, instead of the number of source particles. This does
not change the normalization when using the source, but apps specially
designed to use current_case and last_case for the radionuclide source
may be affected.
Change the radionuclide spectrum so that it is no longer part of
egs_spectra.cpp. Instead, it is in egs_radionuclide_source, because it
is not compatible with any other source. Also, add virtual functions to
the base source class to be able to extract information from the
radionuclide source without needing to do a static cast. These functions
were also added to the source collection and transformed source classes.
Add the feature for egs_gammaspec to get the gamma analysis energies
automatically from the radionuclide decay scheme, if one is used. Also
fix the normalization of the efficiency calculations.
Change the output spectra from egs_gammaspec to report the energy at the
middle of each energy bin, instead of the lower edge of the bin.
Fix a bug where some ensdf files from the nndc caused a segmentation
fault for egs_radionuclide source. This was due to comment lines
following gamma records in the file. The code did not check to see if a
normalization record existed before trying to use it, and this has been
fixed.
Fix a bug in egs_ensdf that resulted in the x-rays and auger electrons
in the ensdf file for Zn-65 not being used. This has no impact if the
relaxations are set to the default of using EADL data.
- Total fluence normalization bug during output:

  expression norm /= volume[k];

  reduces normalization for F[k] by V[k-1]*V[k-2]*...*V[1]

  changed to norm = norma/volume[k];

- Eliminate misleading message in fluence scoring When scoring photon
  fluence, no message related to electron fluence calculation method
  should be issued. Thanks to Alexandra Bourgouin for drawing my
  attention to this issue! Fixes issue #1002

- Read user-requested normalization not only when differential fluence
  requested as it is also needed for integral fluence
Same bug affecting total fluence whereby in the case of differential
fluence scoring in multiple regions the normalization for region i was
divided by the volume of the precedent regions.
If estimating differential fluence for several regions, one might want
to turn off diff fluence output to terminal. This can be achieved by
setting

verbose = no

In the AO input block. Added a clarifying message stating that diff
fluence is output as a Grace plot file.
It was being read outside that block which didn't make sense and was
error prone as one would have expected to find it inside that block.
Forgot to use proper spacing in IF block for diff fluence scaling
inputs.
BUG: Commit 8023cd0 labels fluorescent photons from EII as secondaries.
     The pertinent block for UBS and BCSE requires knowledge of the
     local region number IRL, which is only set later in AUSGAB.

FIX: Set IRL above the UBS/BCSE block in the AUSGAB routine.

Funnily enough this bug only showed when using BEAMnrc as library, not
during BEAM simulations. Perhaps IRL was taking values below smaller
than the dimension of the IREGION_TO_BIT array, set to 3000.
mainegra and others added 21 commits January 14, 2025 15:01
Follow-up on previous commit: Why did the bug not appear during
standalone BEAMnrc runs?

During direct BEAMnrc simulations, when IRL isn't set in the block to
split EII-generated secondary photons, it takes value 2, the first
region of the geometry, set during previous calls to AUSGAB.

When using BEAMnrc as a library with other applications, the memory
location IRL is pointing to can change, taking an arbitrary number. In
my case it was a very large integer.
Add libclean target to standard beam_makefile which removes BEAMnrc
library related files. Until now one had to do this manually!
Fixes
=====

- Average source energy calculation was assuming a statistical weight of
  1 and lumping all particles together. Now weight is accounted for, and
  average energy for photons and charge particles scored separately.
  Moreover, average energy of scoring photons is also estimated.

- Typos in differential fluence xmgrace file output

Additions
=========

- Flexible scoring region input spares user from having to enter huge
  number of regions one at the time. Here are the different input
  schemes:

  a) Individual entries using 'scoring regions' input key Simply enter
     scoring regions individually

  b) Initial and final region pairs using `scoring region ranges`
     Expects pairs of initial and final scoring regions

  c) Groups of regions using 'scoring start region' and 'scoring stop
     region' input keys. Requires using two input keys on two lines,
     similar to what is done for the dose scoring ausgab object.

  d) Equally spaced scoring regions using key 'Incremental scoring
     regions' The most general scheme, expects triplets of initial,
     final and increment regions allowing the definition of ranges where
     scoring is performed at specified intervals (increments) between
     regions. Note that using an increment of 1 is equivalent to schemes
     b) and c).

  If an error in these inputs is detected, code aborts with a warning
  message, rather than simply ignoring the error.

- Scoring regions mass input schemes:

  Using `scoring region masses` input key

  a) One value per region, regardless of scoring region input scheme

  b) One value per group (pair or triplet) when using scoring input
     options b, c, or d above.

  c) One value for all regions (positive)

  d) One value for whole scoring volume (negative)

  Using `scoring volume mass` input key assumes mass for whole scoring
  volume as in d).

- Fluence calculation expanded to estimating integral fluence on all
  scoring regions ir for each calculation geometry ig, Ftot(ig,ir), and
  differential fluence (spectrum) Fdiff(ig,E), for each calculation
  geometry ig in the total scoring volume.

  TODO: Add option to specify spectral scoring regions rather than using
        all scoring regions.

- Estimate average mass-energy absorption coefficient in each scoring
  region when integral fluence is calculated.

- Fix small typo in output
The new, more natural way of projection input, had a typo in the projection
variable iproj
Apply astyle 3.1 to a recent rebase on the develop branch.
Add the feature to select regions for source emission for the isotropic
source depending on the medium. The medium selection can include media,
or exclude them. Region selections are combined with the media
selections using an AND operation, so that a valid region must meet both
criteria.
Fix track sorting used for dynamic .ptracks files containing time
indices. Usually the original .ptracks file is overwritten by the sorted
one, but on Windows file deletion may be blocked. As a workaround for
this situation, the sorted .ptracks file is left as a separate file.
Revert changes to units in the output of egs_fluence_scoring and cavity.
This was needed to avoid compiler errors when using newer compilers.
Fix doxygen compiler errors for egs_dynamic_geometry. Also improve the
documentation for the dynamic geometry, shape and source.
Add support for gcc 4.8.5 in recent changes adding with the dynamic
geometry and dynamic track scoring.
Fix a compiler error that occurred when MXSTACK was increased to 1e7 or
higher. This was due to the line length of an output statement flowing
over 80 characters. The fix was just to split the line, so that more
characters are available.
BUG: Diff flu output for log scale is normalized to {log(Emax) -
log(Emin)}/Nbin rather than proper DE_i = E_i - E_i-1 which for
log-scale is not constant.

Fix: Applied proper DE_i when normalizing diff fluence.

- Fix another bug in egsdat output of ave. source energies as well as
scoring energies whereby no spaces were inserted between adjacent
values, making the analyzing or parallel processing fail when reading
the egsdat file.
Flag latch was being reset to 0 after call to getNextParticle which was
overriding settings from other applications such as BEAM.

Since egs_kerma only checks for negative values when a particle enters
an exclusion region, latch is only multiply by -1 in those cases.
Otherwise, latch is left unchanged.

This can be important for VRT AOs such as radiative splitting.
- To avoid potential clashes with BEAM sources and AOs that might rely
  on the use of latch, particles entering exclusion zones are now
  killed. This approach is about 40% faster for the example input file

  example_1m_40keV_FD.egsinp

  Results using both options, latch set to -1 or killing the photons
  when entering an exclusion regions are consistent within 0.004% k=1
  uncertainty when estimating concrete wall contributions to a 5 cm air
  sphere in the middle of an 8 m X 8 m room.

  Fixes bug noted by @bwalters when multiplying latch by -1 which was
  wrong for cases where latch = 0.

- A check has been added to verify that the user did not mistakenly
  define regions as being both scoring and exclusion regions. Although
  the code gives preferences to the scoring region, it is deemed safer
  to abort issuing a warning.
- It was still using the old file name emuen_icru90_1.5MeV.data
- It should be emuen_rho_air_1keV-1.5MeV.data
- Added comment line on top of the E*muen/rho file names stating that
  these values were ontained uding the g app with the MCDF-XCOM option
- For e- sources was adding the e- rest mass to the e- kinetic energy
  which is actually done in the EGS_AdvancedApplication::shower method
Fix missing initialization of variables for IAEA phase-spaces in the RZ
codes. While this didn't result in a crash, it did result in a bug where
all particles were assigned a charge of 0 during the transport.
Address issue where IAEA phase-space variables weren't properly
initialized in RZ applications, causing all particles to be incorrectly
processed as photons. This serious bug warrants release 2025a. 

IMPORTANT: Anyone who has ever utilized IAEA phase-space files 
with RZ applications should review their simulation results.
if (iiz >= 0 && iiz < nz) {
if (iix != ix || iiy != iy || iiz != iz) {
int cell1 = iix+iiy*nx+iiz*nz;
int cell1 = iix+iiy*nx+iiz*nxy;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this an intentional change? Seems out of place in this PR.

Turns on EGSnrc intrinsic range rejection (rr) efficiency increasing technique.

TODO: Implement variance reduction technique (VRT) rr-based Russian roulette (RR)

 Changes to be committed:
	modified:   ../Makefile
	new file:   egs_range_rejection/Makefile
	new file:   egs_range_rejection/egs_range_rejection.cpp
	new file:   egs_range_rejection/egs_range_rejection.h
	modified:   ../egs_advanced_application.cpp
	modified:   ../egs_advanced_application.h
	modified:   ../egs_application.h
	modified:   ../geometry/egs_nd_geometry/egs_nd_geometry.h
@rtownson rtownson force-pushed the feature-range-rejection-ao branch from 0d0f8e2 to f888307 Compare December 10, 2025 17:25
@rtownson
Copy link
Copy Markdown
Collaborator

Rebased on develop, resolved minor conflicts

@rtownson
Copy link
Copy Markdown
Collaborator

Can we remove the TODO comments, since it looks like Russian Roulette was already added in commit #5acdcd3?

@ftessier ftessier force-pushed the develop branch 2 times, most recently from c14f2dd to b25605d Compare March 24, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants