Repository navigation
Add OpNovice2 optical example - #7
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jlandOpNovice2.ipynbare 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
Run,HistoManagerandTrackInformationclasses are replaced by a simulation-data struct with FHist histograms and a pre-tracking action. The run uses one thread.G4IonisParamMat::SetBirksConstantis 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.G4Cerenkovbuilds its tables only once, for the materials that exist at the first initialization. The electron study therefore runs before the Fresnel one.GetNumPhotonsprintout are not included, because those methods aren't wrapped.boundary.macwithout 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, withSetBirksConstantremoved from the C++ version so that both use the same Birks constant: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.jlruns to completion (about 24 s).Pkg.test).🤖 Generated with Claude Code