Skip to content

Bug: Detector hits change when their beam is solved again #42

Closed

Description

@StackEnjoyer

Problem

  • A hit keeps a reference to its ray or beamlet, so solving the same beam again without empty!(detector) changes the hits of the earlier solves
  • Beam that hits with its first ray: all spots coincide. GaussianBeamlet: the summed field of 3 mirror positions is off by 97 %, and electric_field throws BoundsError when the new path has fewer segments
  • AstigmaticGaussianBeamlet: the field is right, but the automatic window covers only the last spot. Seen on master ff76d460 (0.14.0)
using BeamletOptics
pd = Detector(50e-3)
translate3d!(pd, [0, 100e-3, 0])
system = System([pd])
beam = Beam([0.0, 0, 0], [0.0, 1, 0])
for i in 1:5
    solve_system!(system, beam)
    zrotate3d!(beam, deg2rad(1))
end
length(unique(spot_diagram(pd)))     # 1, expected 5

Notes

  • Not affected since retracing was removed (Feature: remove retracing, SDF miss exit #111): a Beam that reaches the detector behind another object, its later rays are new objects in every solve
  • GaussianBeamletHit reads gauss.chief.rays[id] when the field is evaluated (src/OpticalComponents/Detectors/FieldCalculation.jl:99); AstigmaticGaussianBeamletHit reads the beam only for hit point and polarization (DetectorUtils.jl:174, FieldCalculation.jl:153)
  • deepcopy of a hit is no fix: it also copies the detector with all earlier hits, via Intersection.object
  • Needed for Adaptive discretization algorithm for detector surface #53

Activity

  1. self-assigned this
    on Oct 15, 2025
  2. added
    bug
    on Oct 15, 2025
  3. StackEnjoyer commented on Oct 15, 2025

    @StackEnjoyer
    OwnerAuthor

    It appears that deepcopy is not the desired quick fix, since some circular references exist within the general BMO architecture. This means that custom, ref-free hit types are required for a "simple" solution, since deepcopy grinds to a halt for multiple subsequent calls, e.g. on the GaussianBeamlet.

  4. added this to the v0.14.0 milestone on Oct 7, 2026
  5. changed the title [-]Detector hit ref bug[/-] [+]Bug: Detector hits change when their beam is solved again[/+] on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions