% Created 2026-04-13 Mon 12:58
% Intended LaTeX compiler: pdflatex
\documentclass[presentation,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{color}
\usepackage{listings}
\usepackage{minted}
\usemintedstyle{friendly}
\setminted{fontsize=\footnotesize}
\usetheme[height=20pt]{Rochester}
\usecolortheme{dolphin}
\author{Brett Viren and Claude the bot}
\date{2026-04-13}
\title{Optical Surface Support in GeGeDe}
\subtitle{Adding surface physics to GDML geometry builders}
\hypersetup{
 pdfauthor={Brett Viren and Claude the bot},
 pdftitle={Optical Surface Support in GeGeDe},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 30.1 (Org mode 9.8-pre)},
 pdflang={English}}

% Setup for code blocks [1/2]

\usepackage{fvextra}

\fvset{%
  commandchars=\\\{\},
  highlightcolor=white!95!black!80!blue,
  breaklines=true,
  breaksymbol=\color{white!60!black}\tiny\ensuremath{\hookrightarrow}}

% Make line numbers smaller and grey.
\renewcommand\theFancyVerbLine{\footnotesize\color{black!40!white}\arabic{FancyVerbLine}}

\usepackage{xcolor}

% In case engrave-faces-latex-gen-preamble has not been run.
\providecolor{EfD}{HTML}{f7f7f7}
\providecolor{EFD}{HTML}{28292e}

% Define a Code environment to prettily wrap the fontified code.
\usepackage[breakable,xparse]{tcolorbox}
\DeclareTColorBox[]{Code}{o}%
{colback=EfD!98!EFD, colframe=EfD!95!EFD,
  fontupper=\footnotesize\setlength{\fboxsep}{0pt},
  colupper=EFD,
  IfNoValueTF={#1}%
  {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
    boxrule=0.5pt, left=2pt}%
  {boxsep=2.5pt, arc=0pt, outer arc=0pt,
    boxrule=0pt, leftrule=1.5pt, left=0.5pt},
  right=2pt, top=1pt, bottom=0.5pt,
  breakable}

% Support listings with captions
\usepackage{float}
\floatstyle{plain}
\newfloat{listing}{htbp}{lst}
\newcommand{\listingsname}{Listing}
\floatname{listing}{\listingsname}
\newcommand{\listoflistingsname}{List of Listings}
\providecommand{\listoflistings}{\listof{listing}{\listoflistingsname}}


% Setup for code blocks [2/2]: syntax highlighting colors

\newcommand\efstrut{\vrule height 2.1ex depth 0.8ex width 0pt}
\definecolor{EFD}{HTML}{000000}
\definecolor{EfD}{HTML}{ffffff}
\newcommand{\EFD}[1]{\textcolor{EFD}{#1}} % default
\definecolor{EFvp}{HTML}{000000}
\newcommand{\EFvp}[1]{\textcolor{EFvp}{#1}} % variable-pitch
\definecolor{EFh}{HTML}{7f7f7f}
\newcommand{\EFh}[1]{\textcolor{EFh}{#1}} % shadow
\definecolor{EFsc}{HTML}{228b22}
\newcommand{\EFsc}[1]{\textcolor{EFsc}{\textbf{#1}}} % success
\definecolor{EFw}{HTML}{ff8e00}
\newcommand{\EFw}[1]{\textcolor{EFw}{\textbf{#1}}} % warning
\definecolor{EFe}{HTML}{ff0000}
\newcommand{\EFe}[1]{\textcolor{EFe}{\textbf{#1}}} % error
\definecolor{EFl}{HTML}{ff0000}
\newcommand{\EFl}[1]{\textcolor{EFl}{#1}} % link
\definecolor{EFlv}{HTML}{ff0000}
\newcommand{\EFlv}[1]{\textcolor{EFlv}{#1}} % link-visited
\definecolor{EFhi}{HTML}{ff0000}
\newcommand{\EFhi}[1]{\textcolor{EFhi}{#1}} % highlight
\definecolor{EFc}{HTML}{b22222}
\newcommand{\EFc}[1]{\textcolor{EFc}{#1}} % font-lock-comment-face
\definecolor{EFcd}{HTML}{b22222}
\newcommand{\EFcd}[1]{\textcolor{EFcd}{#1}} % font-lock-comment-delimiter-face
\definecolor{EFs}{HTML}{8b2252}
\newcommand{\EFs}[1]{\textcolor{EFs}{#1}} % font-lock-string-face
\definecolor{EFd}{HTML}{8b2252}
\newcommand{\EFd}[1]{\textcolor{EFd}{#1}} % font-lock-doc-face
\definecolor{EFm}{HTML}{008b8b}
\newcommand{\EFm}[1]{\textcolor{EFm}{#1}} % font-lock-doc-markup-face
\definecolor{EFk}{HTML}{9370db}
\newcommand{\EFk}[1]{\textcolor{EFk}{#1}} % font-lock-keyword-face
\definecolor{EFb}{HTML}{483d8b}
\newcommand{\EFb}[1]{\textcolor{EFb}{#1}} % font-lock-builtin-face
\definecolor{EFf}{HTML}{0000ff}
\newcommand{\EFf}[1]{\textcolor{EFf}{#1}} % font-lock-function-name-face
\definecolor{EFv}{HTML}{a0522d}
\newcommand{\EFv}[1]{\textcolor{EFv}{#1}} % font-lock-variable-name-face
\definecolor{EFt}{HTML}{228b22}
\newcommand{\EFt}[1]{\textcolor{EFt}{#1}} % font-lock-type-face
\definecolor{EFo}{HTML}{008b8b}
\newcommand{\EFo}[1]{\textcolor{EFo}{#1}} % font-lock-constant-face
\definecolor{EFwr}{HTML}{ff0000}
\newcommand{\EFwr}[1]{\textcolor{EFwr}{\textbf{#1}}} % font-lock-warning-face
\newcommand{\EFnc}[1]{#1} % font-lock-negation-char-face
\definecolor{EFpp}{HTML}{483d8b}
\newcommand{\EFpp}[1]{\textcolor{EFpp}{#1}} % font-lock-preprocessor-face
\newcommand{\EFrc}[1]{\textbf{#1}} % font-lock-regexp-grouping-construct
\newcommand{\EFrb}[1]{\textbf{#1}} % font-lock-regexp-grouping-backslash
\newcommand{\EFob}[1]{#1} % org-block
\newcommand{\EFobb}[1]{#1} % org-block-begin-line
\newcommand{\EFobe}[1]{#1} % org-block-end-line
\definecolor{EFOa}{HTML}{0000ff}
\newcommand{\EFOa}[1]{\textcolor{EFOa}{#1}} % outline-1
\definecolor{EFOb}{HTML}{a0522d}
\newcommand{\EFOb}[1]{\textcolor{EFOb}{#1}} % outline-2
\definecolor{EFOc}{HTML}{a020f0}
\newcommand{\EFOc}[1]{\textcolor{EFOc}{#1}} % outline-3
\definecolor{EFOd}{HTML}{b22222}
\newcommand{\EFOd}[1]{\textcolor{EFOd}{#1}} % outline-4
\definecolor{EFOe}{HTML}{228b22}
\newcommand{\EFOe}[1]{\textcolor{EFOe}{#1}} % outline-5
\definecolor{EFOf}{HTML}{008b8b}
\newcommand{\EFOf}[1]{\textcolor{EFOf}{#1}} % outline-6
\definecolor{EFOg}{HTML}{483d8b}
\newcommand{\EFOg}[1]{\textcolor{EFOg}{#1}} % outline-7
\definecolor{EFOh}{HTML}{8b2252}
\newcommand{\EFOh}[1]{\textcolor{EFOh}{#1}} % outline-8
\definecolor{EFhn}{HTML}{008b8b}
\newcommand{\EFhn}[1]{\textcolor{EFhn}{#1}} % highlight-numbers-number
\definecolor{EFhq}{HTML}{9370db}
\newcommand{\EFhq}[1]{\textcolor{EFhq}{#1}} % highlight-quoted-quote
\definecolor{EFhs}{HTML}{008b8b}
\newcommand{\EFhs}[1]{\textcolor{EFhs}{#1}} % highlight-quoted-symbol
\definecolor{EFrda}{HTML}{707183}
\newcommand{\EFrda}[1]{\textcolor{EFrda}{#1}} % rainbow-delimiters-depth-1-face
\definecolor{EFrdb}{HTML}{7388d6}
\newcommand{\EFrdb}[1]{\textcolor{EFrdb}{#1}} % rainbow-delimiters-depth-2-face
\definecolor{EFrdc}{HTML}{909183}
\newcommand{\EFrdc}[1]{\textcolor{EFrdc}{#1}} % rainbow-delimiters-depth-3-face
\definecolor{EFrdd}{HTML}{709870}
\newcommand{\EFrdd}[1]{\textcolor{EFrdd}{#1}} % rainbow-delimiters-depth-4-face
\definecolor{EFrde}{HTML}{907373}
\newcommand{\EFrde}[1]{\textcolor{EFrde}{#1}} % rainbow-delimiters-depth-5-face
\definecolor{EFrdf}{HTML}{6276ba}
\newcommand{\EFrdf}[1]{\textcolor{EFrdf}{#1}} % rainbow-delimiters-depth-6-face
\definecolor{EFrdg}{HTML}{858580}
\newcommand{\EFrdg}[1]{\textcolor{EFrdg}{#1}} % rainbow-delimiters-depth-7-face
\definecolor{EFrdh}{HTML}{80a880}
\newcommand{\EFrdh}[1]{\textcolor{EFrdh}{#1}} % rainbow-delimiters-depth-8-face
\definecolor{EFrdi}{HTML}{887070}
\newcommand{\EFrdi}[1]{\textcolor{EFrdi}{#1}} % rainbow-delimiters-depth-9-face
\definecolor{EFany}{HTML}{CDCD00}
\newcommand{\EFany}[1]{\textcolor{EFany}{#1}} % ansi-color-yellow
\definecolor{EFanr}{HTML}{CD0000}
\newcommand{\EFanr}[1]{\textcolor{EFanr}{#1}} % ansi-color-red
\definecolor{EFanb}{HTML}{000000}
\newcommand{\EFanb}[1]{\textcolor{EFanb}{#1}} % ansi-color-black
\definecolor{EFang}{HTML}{00CD00}
\newcommand{\EFang}[1]{\textcolor{EFang}{#1}} % ansi-color-green
\definecolor{EFanB}{HTML}{0000EE}
\newcommand{\EFanB}[1]{\textcolor{EFanB}{#1}} % ansi-color-blue
\definecolor{EFanc}{HTML}{00CDCD}
\newcommand{\EFanc}[1]{\textcolor{EFanc}{#1}} % ansi-color-cyan
\definecolor{EFanw}{HTML}{E5E5E5}
\newcommand{\EFanw}[1]{\textcolor{EFanw}{#1}} % ansi-color-white
\definecolor{EFanm}{HTML}{CD00CD}
\newcommand{\EFanm}[1]{\textcolor{EFanm}{#1}} % ansi-color-magenta
\definecolor{EFANy}{HTML}{EEEE00}
\newcommand{\EFANy}[1]{\textcolor{EFANy}{#1}} % ansi-color-bright-yellow
\definecolor{EFANr}{HTML}{EE0000}
\newcommand{\EFANr}[1]{\textcolor{EFANr}{#1}} % ansi-color-bright-red
\newcommand{\EFANb}[1]{#1} % ansi-color-bright-black
\definecolor{EFANg}{HTML}{00EE00}
\newcommand{\EFANg}[1]{\textcolor{EFANg}{#1}} % ansi-color-bright-green
\definecolor{EFANB}{HTML}{0000FF}
\newcommand{\EFANB}[1]{\textcolor{EFANB}{#1}} % ansi-color-bright-blue
\definecolor{EFANc}{HTML}{00EEEE}
\newcommand{\EFANc}[1]{\textcolor{EFANc}{#1}} % ansi-color-bright-cyan
\newcommand{\EFANw}[1]{#1} % ansi-color-bright-white
\newcommand{\EFANm}[1]{#1} % ansi-color-bright-magenta
\begin{document}

\maketitle
\section*{Changes}
\label{sec:orge9d3dd8}

\begin{frame}[label={sec:org0a11932},fragile]{What Was Added This Session}
 \begin{description}
\item[{\alert{GeGeDe Python API}}] \texttt{geom.surfaces.OpticalSurface}, \texttt{BorderSurface},
\texttt{SkinSurface} now emit correct GDML \texttt{<opticalsurface>}, \texttt{<bordersurface>},
\texttt{<skinsurface>} nodes
\item[{\alert{Geant4 energy-unit fix}}] GDML \texttt{<matrix>} values are read as bare MeV
(Geant4 internal units), not eV; all property-table energies in \texttt{optical.py}
now use the correct scale (e.g. \texttt{1.77e-6} for 1.77 eV / 700 nm)
\item[{\alert{Dispersive glass RINDEX}}] prism material now has a 7-point
wavelength-dependent table (\(n = 1.570\) at 700 nm → \(1.655\) at 400 nm,
Abbe \(V_d \approx 26\)) so colours separate visibly in simulation
\item[{\alert{Water optical properties}}] RINDEX (Sellmeier), ABSLENGTH (50–70 m peak),
RAYLEIGH (\(\lambda^4\) scaling) representative of SK-quality ultra-pure water
\item[{\alert{Full Geant4 sim app} (\texttt{g4app/})}] GPS primary generator,
\texttt{G4OpticalPhysics}, PMT hit collection via \texttt{G4OpBoundaryProcess::Detection},
CSV output (\texttt{hits.csv}, \texttt{trajectories.csv}), Python visualisers
\end{description}
\end{frame}
\section*{Adding Optical Surfaces}
\label{sec:orgb1d862b}

\begin{frame}[label={sec:org9830384},fragile]{How to Add Optical Properties in a GeGeDe Builder}
 \begin{block}{Material properties}
\begin{Code}
\begin{Verbatim}
\color{EFD}\EFcd{\#} \EFc{Energies in MeV (= eV × 1e-6) Geant4 GDML internal unit}
geom.matter.Molecule(\EFs{"Glass"}, ...,
    properties = [
        (\EFs{"RINDEX"}, [(1.771e-6, 1.570),   \EFcd{\#} \EFc{700 nm red}
                    (3.100e-6, 1.655)]),  \EFcd{\#} \EFc{400 nm violet}
    ])
geom.matter.Molecule(\EFs{"Water"}, ...,
    properties = [
        (\EFs{"RINDEX"},    [(1.77e-6, 1.331), (4.14e-6, 1.353)]),
        (\EFs{"ABSLENGTH"}, [(1.77e-6, 1e3),   (3.10e-6, 7e4)]),  \EFcd{\#} \EFc{mm}
        (\EFs{"RAYLEIGH"},  [(1.77e-6, 7.5e5), (4.14e-6, 3e3)]),  \EFcd{\#} \EFc{mm}
    ])
\end{Verbatim}
\end{Code}
\end{block}
\begin{block}{Surfaces}
\begin{Code}
\begin{Verbatim}
\color{EFD}geom.surfaces.OpticalSurface(\EFs{"pmt\_surface"},
    model=\EFs{"unified"}, finish=\EFs{"polished"}, \EFb{type}=\EFs{"dielectric\_metal"}, value=1.0,
    properties = [
        (\EFs{"REFLECTIVITY"}, [(\_ELO, 0.0),  (\_EHI, 0.0)]),   \EFcd{\#} \EFc{fully absorbing}
        (\EFs{"EFFICIENCY"},   [(\_ELO, 0.05), (\_EPEAK, 0.25), (\_EHI, 0.08)]),
    ])
\EFcd{\#} \EFc{SkinSurface covers all physical instances of pmt\_vol automatically}
geom.surfaces.SkinSurface(\EFs{"pmt\_skin"}, surface=\EFs{"pmt\_surface"}, volume=\EFs{"pmt\_vol"})
\EFcd{\#} \EFc{BorderSurface applies to a directed interface between two placements}
geom.surfaces.BorderSurface(\EFs{"air\_steel\_border"}, surface=\EFs{"steel\_air\_surface"},
                             physvol1=\EFs{"air\_in\_steel"}, physvol2=\EFs{"air\_in\_steel"})
\end{Verbatim}
\end{Code}
\end{block}
\end{frame}
\section*{Example Overview}
\label{sec:org8710de9}

\begin{frame}[label={sec:orgbf71d00},fragile]{The \texttt{optical/} Example: What It Models}
 \begin{columns}
\begin{column}{0.48\columnwidth}
\begin{block}{Geometry (all volumes share the world origin)}
\begin{center}
\begin{tabular}{lll}
Volume & Material & Size\\
\hline
\texttt{world\_vol} & stainless steel & 1 m cube\\
\texttt{air\_vol} & ultra-pure water & 90 cm cube\\
\texttt{prism\_vol} & dense flint glass & 30×20×20 cm\\
\texttt{pmt\_vol} & PMT window glass & R=5 cm hemi\\
\end{tabular}
\end{center}

\begin{itemize}
\item 384 PMTs: 8×8 grid on each of 6 faces, 10 cm pitch
\item Sensitive detector wired via GDML \texttt{<auxiliary auxtype="SensDet"/>}
\end{itemize}
\end{block}
\end{column}
\begin{column}{0.48\columnwidth}
\begin{block}{Surfaces}
\alert{Steel reflector} (\texttt{BorderSurface})
\begin{itemize}
\item \texttt{REFLECTIVITY} 90 \% (red) → 85 \% (UV)
\end{itemize}

\alert{PMT photocathode} (\texttt{SkinSurface})
\begin{itemize}
\item \texttt{REFLECTIVITY} = 0 (fully absorbing)
\item \texttt{EFFICIENCY} 5 \% (red), 25 \% (blue), 8 \% (UV)
\item Geant4 sets status \texttt{Detection} and kills track when photon passes QE roll
\end{itemize}

Build / run one-liner:
\begin{verbatim}
uv run gegede -o optical_prism.gdml optical.cfg
./g4app/build/optical_g4 macros/run.mac optical_prism.gdml
\end{verbatim}
\end{block}
\end{column}
\end{columns}
\end{frame}
\section*{Running the Examples}
\label{sec:org6c0eaca}

\begin{frame}[label={sec:orgad1089c},fragile]{Run 1: PMT Hits Isotropic Spectrum}
 \begin{columns}
\begin{column}{0.44\columnwidth}
\begin{block}{Macro (\texttt{macros/run.mac})}
\begin{verbatim}
/gps/particle opticalphoton
/gps/pos/centre 0 0 0 cm
/gps/ang/type   iso

/gps/ene/type      Lin
/gps/ene/min  1.77 eV   # 700 nm
/gps/ene/max  4.14 eV   # 300 nm
/gps/ene/gradient  0
/gps/ene/intercept 1

/run/beamOn 1000
\end{verbatim}

1000 isotropic photons from the centre; no trajectory storage.
Output: \texttt{hits.csv} (\texttt{\textasciitilde{}80 detections}, \texttt{\textasciitilde{}8 \%} detection rate).
Visualise: \texttt{python g4app/python/plot\_hits.py -{}-{}out hits.png}
\end{block}
\end{column}
\begin{column}{0.53\columnwidth}
\begin{block}{Result}
\begin{center}
\includegraphics[width=\textwidth]{hits.png}
\end{center}
\end{block}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orgb87e7a2},fragile]{Run 2: Trajectories - Isotropic Spectrum}
 \begin{columns}
\begin{column}{0.44\columnwidth}
\begin{block}{Macro (\texttt{macros/run\_traj.mac})}
\begin{verbatim}
/tracking/storeTrajectory 1

/gps/particle opticalphoton
/gps/pos/centre 0 0 0 cm
/gps/ang/type   iso

/gps/ene/type      Lin
/gps/ene/min  1.77 eV
/gps/ene/max  4.14 eV
/gps/ene/gradient  0
/gps/ene/intercept 1

/run/beamOn 50
\end{verbatim}

50 photons; every step point recorded.
Output: \texttt{hits.csv} + \texttt{trajectories.csv}.
Each track coloured by wavelength (Bruton algorithm).
Visualise: \texttt{python g4app/python/plot\_traj.py -{}-{}out traj.png}
\end{block}
\end{column}
\begin{column}{0.53\columnwidth}
\begin{block}{Result}
\begin{center}
\includegraphics[width=\textwidth]{traj.png}
\end{center}
\end{block}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org4ef04f3},fragile]{Run 3: Dark Side Of The Moon - Dispersion Demo}
 \begin{columns}
\begin{column}{0.44\columnwidth}
\begin{block}{Macro (\texttt{macros/dsotm.mac})}
\begin{verbatim}
# 7 equal-intensity GPS sources; same
# position/direction, one per colour.
/gps/source/add 1
/gps/particle   opticalphoton
/gps/pos/centre -35 8 0 cm
/gps/ang/type   beam1d
/gps/ang/sigma_r 0 deg
/gps/direction  1 0 0
/gps/ene/type   Mono
/gps/ene/mono   1.771 eV   # red 700 nm
# ... repeated for 2.000 2.138 2.340
#     2.530 2.755 3.100 eV
/tracking/storeTrajectory 1
/run/beamOn 700
\end{verbatim}

Parallel "white" beam enters prism left face; dispersive glass separates colours.
Visualise: \texttt{python g4app/python/plot\_traj.py -{}-{}view dsotm -{}-{}out dsotm.png}
\end{block}
\end{column}
\begin{column}{0.53\columnwidth}
\begin{block}{Result}
\begin{center}
\includegraphics[width=\textwidth]{dsotm.png}
\end{center}
\end{block}
\end{column}
\end{columns}
\end{frame}
\end{document}
