Skip to content

Add OpNovice2 optical example - #7

Merged
peremato merged 2 commits into
mainfrom
opnovice2-example
Oct 29, 2026
Merged

peremato merged 2 commits into
mainfrom
opnovice2-example

Conversation

@peremato

@peremato peremato commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Julia port of the Geant4 example extended/optical/OpNovice2, in extended/OpNovice/.

It reproduces four of the C++ macros:

  • electron.mac: 1 MeV electrons in a scintillating BGO tank. The example prints the Cerenkov and scintillation yields and plots their spectra and the scintillation time profile.
  • fresnel.mac: polarized optical photons with random direction hit a polished water/air surface. The example plots the refracted and reflected fractions against the incident angle, and compares the Brewster and critical angles with the expected values.
  • coated.mac: photons hit a surface with a 100 nm coating. The example compares the reflectance at normal incidence with the thin-film interference formula. It also scans the incident angle for p and s polarization and plots the analytic curve on top, which goes beyond the C++ macro (normal incidence only).
  • boundary.mac: the 21 surface configurations of the macro (unified, glisur, DAVIS and LUT models with their types and finishes). The example prints the fraction of each boundary outcome and shows them as a heatmap.

Files

  • OpNovice2.lit: Literate source. OpNovice2.jl and OpNovice2.ipynb are generated from it.
  • OpDetector.jl: detector with configurable optical properties. The /opnovice2/boxProperty, surfaceFinish, … UI commands become keyword arguments.
  • README.md: description and differences with the C++ version.
  • test/runtests.jl: the example is added to the test suite.

Differences with the C++ example

  • The Run, HistoManager and TrackInformation classes are replaced by a simulation-data struct with FHist histograms and a pre-tracking action. The run uses one thread.
  • G4IonisParamMat::SetBirksConstant is not wrapped in Geant4.jl, so BGO uses Geant4's default Birks constant (0.0084 mm/MeV) instead of 0.126 mm/MeV. This gives about 15% more scintillation photons.
  • G4Cerenkov builds its tables only once, for the materials that exist at the first initialization. The electron study therefore runs before the Fresnel one.
  • The group-velocity check and the GetNumPhotons printout are not included, because those methods aren't wrapped.
  • In boundary.mac without a polarization angle, the C++ generator keeps the first photon's random polarization for the whole run. The Julia generator picks a new one for each photon.

Validation against C++

I built the C++ example against the same Geant4_jll (11.4.1) and compared the two.

  • fresnel.mac, per 100k photons, p- and s-polarized: the refraction, reflection and total internal reflection counts agree within about 1σ. Both versions find the Brewster angle at 35.5 ± 0.5° (expected 35.71°) and the critical angle at 45.5 ± 0.5° (expected 45.96°).
  • electron.mac, 10k electrons, with SetBirksConstant removed from the C++ version so that both use the same Birks constant:
C++ Julia
Cerenkov photons per event 42.85 43.01
Scintillation photons per event 3506.6 3526.5
Scintillation spectrum, mean 5.431 eV 5.431 eV
Scintillation time, mean 48.41 ns 48.40 ns
Fresnel refraction / Lambertian reflection fraction 32.84% / 33.44% 32.84% / 33.44%
  • coated.mac: reflectance at normal incidence is 10.7% in C++ and 10.6% in Julia (expected 10.74%). The angular scans follow the analytic thin-film curve.
  • boundary.mac: all 21 configurations agree within statistics (10k photons each). For example, unified ground gives 75.0% refraction and 10.2% transmission in C++, and 75.2% and 10.4% in Julia. The largest gap is transmission in glisur groundbackpainted, 11.7% against 10.8% (about 2σ).

Test plan

  • julia extended/OpNovice/OpNovice2.jl runs to completion (about 24 s).
  • CI (Pkg.test).

🤖 Generated with Claude Code

peremato and others added 2 commits October 29, 2026 14:33
Julia port of the Geant4 extended/optical/OpNovice2 example. It
reproduces the electron.mac (Cerenkov and scintillation in BGO) and
fresnel.mac (Brewster and critical angles on a polished surface)
studies. The /opnovice2/... UI commands become keyword arguments of
the OpDetector structure. Run, HistoManager and TrackInformation are
replaced by a simulation-data struct with FHist histograms and a
pre-tracking action.

The example is added to the test suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- coated.mac: reflectance of a thin coating at normal incidence, compared
  with the thin-film interference formula, plus an angular scan for p and
  s polarization with the analytic curve overlaid.
- boundary.mac: the 21 surface configurations of the macro (unified,
  glisur, DAVIS and LUT models), with the boundary outcomes printed and
  shown as a heatmap.
- setgun! normalizes the direction; the run summary can be switched off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@peremato
peremato merged commit 23bf487 into main Oct 29, 2026
2 checks passed
@peremato
peremato deleted the opnovice2-example branch October 29, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant