Opticks : GPU Optical Photon Simulation for Particle Physics with NVIDIA OptiX

Opticks : GPU Optical Photon Simulation for Particle Physics with NVIDIA® OptiX™

Simon Blyth, National Taiwan University — https://bitbucket.org/simoncblyth/opticks — Jan 2017, PSROC

Opticks Benefits

Outline

/env/presentation/newtons-opticks.png

Optical Photon Simulation Problem...

JPMT Before Contact 2

Ray Traced Image Synthesis ≈ Optical Photon Simulation

Geometry, light sources, optical physics ->
  • pixel values at image plane
  • photon parameters at detectors (eg PMTs)
Ray tracing has many applications :
  • advertising, design, entertainment, games,...
  • BUT : most ray tracers just render images
NVIDIA OptiX had foresight to be less specific:
  • general geometry intersection API
  • OptiX is to ray tracing what OpenGL is to rasterization


rasterization
project 3D primitives onto 2D image plane, combine fragments into pixel values
ray tracing
cast rays thru image pixels into scene, recursively reflect/refract with geometry intersected, combine returns into pixel values

NVIDIA OptiX 1

NVIDIA OptiX 2

/env/presentation/1px.png

https://research.nvidia.com/publication/optix-general-purpose-ray-tracing-engine

Opticks : Translate Geant4 Geometry "Context" for GPU

Export Tesselated Geometry
Load G4DAE XML
  • label primitives with boundary indices
  • find repeated geometry "instances"
  • write NumPy serialization .npy geocache

Geocache -> few seconds startup, instead of few minutes

Load/upload geocache
  • load geocache from file
  • upload OptiX textures to GPU
  • upload geometry buffers to GPU
GPU geometry buffers read by:
  • OptiX bounding box and intersection programs
  • OpenGL GLSL shaders for visualization

Large Geometry Techniques : Instancing Mandatory

Geometry analysed to find instances

JUNO: ~90M --> 0.1M triangles

OpenGL/OptiX instancing

Multiple Renderers

Geometry Modelling : Tesselated vs Analytic Photomultiplier Tubes

/env/graphics/ggeoview/dpib-triangulated-pmt.png /env/nuwa/detdesc/pmt/hemi-pmt-analytic-near-clipped.png /env/presentation/1px.png

Analytic : more realistic, faster, less memory, much more effort

For Dayabay PMT:

Aim : analytic description of geometry on critical optical path, remainder tesselated

Hybrid Geant4/Opticks Event Workflow

Geant4/Detector Simulation

Opticks (OptiX/Thrust GPU interoperation)

Geant4/Detector Simulation

Multi-event handling

Compare Opticks/Geant4 Simulations with Simple Lights/Geometries

/env/graphics/ggeoview/rainbow-spol-disc-incident-sphere.png

1M Photons -> Water Sphere (S-Polarized)

/env/graphics/ggeoview/PmtInBox-approach.png

0.5M Photons -> Dayabay PMT

/env/presentation/1px.png
Photon step records
128 bit per step : highly compressed position, time, wavelength, polarization vector, material/history codes
Photon flag sequence
16x 4-bit step flags recorded in uint64 sequence, indexed using Thrust GPU sort (1M indexed ~0.040s)

Sequence index -> interactive OpenGL selection of photons by flag sequence

1M Rainbow S-Polarized, Comparison Opticks/Geant4

Deviation angle(degrees) of 1M parallel monochromatic photons in disc shaped beam incident on water sphere. Numbered bands are visible range expectations of first 11 rainbows. S-Polarized intersection (E field perpendicular to plane of incidence) arranged by directing polarization radially.

/env/optix/cfg4/rainbow-cfg4-spol.png

PMT Opticks/Geant4 step distribution comparison TO BT [SD]

Good agreement reached, after several fixes: geometry, total internal reflection, group velocity

/env/numerics/npy/PmtInBox_TOBTSD_xyzt.png

position(xyz), time(t)

/env/numerics/npy/PmtInBox_TOBTSD_abcr.png

polarization(abc), radius(r)

PMT Opticks/Geant4 step distribution comparison : chi2/ndf

4/PMT In Box/torch : X Y Z T A B C R
340271/340273 : [TO] BT SA 1.15 1.00 0.00 0.00 1.06 1.03 0.00 1.21
340271/340273 : TO [BT] SA 1.15 1.00 1.06 0.91 1.06 1.03 0.00 1.21
340271/340273 : TO BT [SA] 0.97 1.02 1.05 0.99 1.06 1.03 0.00 1.29
107598/107251 : [TO] BT SD 0.91 0.73 0.56 0.56 0.98 1.09 0.56 0.94
107598/107251 : TO [BT] SD 0.91 0.73 0.81 0.93 0.98 1.09 0.56 0.94
107598/107251 : TO BT [SD] 0.99 0.83 0.97 0.99 0.98 1.09 0.56 0.93
23217/23260 : [TO] BT BT SA 0.94 0.82 0.04 0.04 0.97 0.89 0.04 0.57
23217/23260 : TO [BT] BT SA 0.94 0.82 0.70 0.50 0.97 0.89 0.04 0.57
23217/23260 : TO BT [BT] SA 0.91 0.94 0.43 0.60 0.97 0.89 0.04 0.05
23217/23260 : TO BT BT [SA] 0.94 0.88 0.04 0.35 0.97 0.89 0.04 0.72
18866/19048 : [TO] AB 0.99 1.10 0.87 0.87 0.85 0.84 0.87 1.00
18866/19048 : TO [AB] 0.99 1.10 0.93 0.92 0.85 0.84 0.87 1.00
3179/3133 : [TO] SC SA 1.07 0.83 0.34 0.34 0.86 0.96 0.34 0.73
3179/3133 : TO [SC] SA 1.07 0.83 0.98 1.05 0.98 1.06 0.98 0.73
3179/3133 : TO SC [SA] 0.96 1.04 0.93 0.97 0.98 1.06 0.98 1.10
2204/2249 : [TO] BT AB 0.85 1.04 0.45 0.45 0.99 0.92 0.45 1.06
2204/2249 : TO [BT] AB 0.85 1.04 0.95 0.88 0.99 0.92 0.45 1.06
2204/2249 : TO BT [AB] 0.98 0.94 1.01 1.00 0.99 0.92 0.45 0.90
1696/1732 : [TO] BT BT AB 1.05 0.85 0.38 0.38 0.86 1.09 0.38 0.26
1696/1732 : TO [BT] BT AB 1.05 0.85 1.48 1.28 0.86 1.09 0.38 0.26
1696/1732 : TO BT [BT] AB 0.99 0.86 1.17 1.40 0.86 1.09 0.38 0.86
1696/1732 : TO BT BT [AB] 1.15 0.88 1.08 1.06 0.86 1.09 0.38 0.79
1446/1455 : [TO] BR SA 1.21 0.94 0.03 0.03 0.90 0.87 0.03 1.09
1446/1455 : TO [BR] SA 1.21 0.94 1.02 1.01 0.90 0.87 0.03 1.09
1446/1455 : TO BR [SA] 1.00 0.93 0.97 0.99 0.90 0.87 0.03 1.04

tconcentric : test geometry configured via boundaries

tconcentric-testconfig(){
    local test_config=(
        mode=BoxInBox
        analytic=1
        shape=sphere boundary=StainlessSteel///Acrylic         parameters=0,0,0,$(( 5000 + 5 ))
        shape=sphere boundary=Acrylic//RSOilSurface/MineralOil parameters=0,0,0,$(( 5000 - 5 ))
        shape=sphere boundary=MineralOil///Acrylic             parameters=0,0,0,$(( 4000 + 5 ))
        shape=sphere boundary=Acrylic///LiquidScintillator     parameters=0,0,0,$(( 4000 - 5 ))
        shape=sphere boundary=LiquidScintillator///Acrylic     parameters=0,0,0,$(( 3000 + 5 ))
        shape=sphere boundary=Acrylic///GdDopedLS              parameters=0,0,0,$(( 3000 - 5 ))
    )
    echo "$(join _ ${test_config[@]})"
}

https://bitbucket.org/simoncblyth/opticks/src/tip/tests/tconcentric.bash

tconcentric : spherical GdLS/LS/MineralOil

/env/presentation/tconcentric-8cccccccc9ccccd.png

tconcentric : Opticks/Geant4 chi2 comparison

.      seqhis_ana  1:concentric   -1:concentric     c2
.                       1000000   1000000       373.13/356 =  1.05  (pval:0.256 prob:0.744)
0000           8ccccd    669843    670001             0.02  [6 ] TO BT BT BT BT SA
0001               4d     83950     84149             0.24  [2 ] TO AB
0002          8cccc6d     45490     44770             5.74  [7 ] TO SC BT BT BT BT SA
0003           4ccccd     28955     28718             0.97  [6 ] TO BT BT BT BT AB
0004             4ccd     23187     23170             0.01  [4 ] TO BT BT AB
0005          8cccc5d     20238     20140             0.24  [7 ] TO RE BT BT BT BT SA
0006          8cc6ccd     10214     10357             0.99  [7 ] TO BT BT SC BT BT SA
0007          86ccccd     10176     10318             0.98  [7 ] TO BT BT BT BT SC SA
0008          89ccccd      7540      7710             1.90  [7 ] TO BT BT BT BT DR SA
0009         8cccc55d      5976      5934             0.15  [8 ] TO RE RE BT BT BT BT SA
0010              45d      5779      5766             0.01  [3 ] TO RE AB
0011  8cccccccc9ccccd      5339      5269             0.46  [15] TO BT BT BT BT DR BT BT BT BT BT BT BT BT SA
0012          8cc5ccd      5111      4940             2.91  [7 ] TO BT BT RE BT BT SA
0013              46d      4797      4886             0.82  [3 ] TO SC AB
0014      8cccc9ccccd      4494      4469             0.07  [11] TO BT BT BT BT DR BT BT BT BT SA
0015      8cccccc6ccd      3317      3302             0.03  [11] TO BT BT SC BT BT BT BT BT BT SA
0016         8cccc66d      2670      2675             0.00  [8 ] TO SC SC BT BT BT BT SA
0017          49ccccd      2432      2383             0.50  [7 ] TO BT BT BT BT DR AB
0018          4cccc6d      2043      1991             0.67  [7 ] TO SC BT BT BT BT AB
0019            4cc6d      1755      1826             1.41  [5 ] TO SC BT BT AB

Top 20 chart above, (category 100 down to ~100 photons for propagation of 1M photons)

tconcentric : Opticks/Geant4 history counts chi2/df ~ 1.0

Match achieved between two optical simulations, run from single executable

CPU
Daya Bay detsim optical physics updated to G4 10.2
GPU
above ported to CUDA/OptiX

Match achieved only after many bug fixes, including:

Work guided by the next largest chi2 contributor

https://bugzilla-geant4.kek.jp/show_bug.cgi?id=1275

Photon Propagation Times Geant4 cf Opticks

/env/optix/cfg4/PmtInBox-cfg4-2.png
Test Geant4 10.2 Opticks Interop Opticks Compute
Rainbow 1M(S) 56 s 1.62 s 0.28 s
Rainbow 1M(P) 58 s 1.71 s 0.25 s
PmtInBox 0.5M 41 s 0.81 s 0.15 s

[1] MacBook Pro (2013), NVIDIA GeForce GT 750M, 2048 MB, 384 cores

OpticksDocs

Summary

/env/presentation/1px.png

Opticks enables Geant4 based simulations to benefit from optical photon simulation taking effectively zero time and zero CPU memory, thanks to massive parallelism made accessible by NVIDIA OptiX.

/env/presentation/1px.png
  • The more photons the bigger the overall speedup (99% -> 100x)
  • Drastic speedup -> better detector understanding -> greater precision
  • Large PMT based neutrino experiments, such as JUNO, can benefit the most
/env/presentation/1px.png

https://bitbucket.org/simoncblyth/opticks

OptiX ray trace of boolean CSG box-sphere, photons approaching

Boolean CSG may allow fully analytic GPU geometry translations

/env/tests/tboolean_box_minus_sphere_before.png

tboolean box-sphere after

Photon propagation step point positions.

/env/tests/tboolean_box_minus_sphere_after.png

YouTube Video

https://www.youtube.com/watch?v=CBpOha4RzIs

Daya Bay Composite Ray Traced geometry and rasterized Cerenkov propagation

/env/ok/dyb_raytrace_composite_cerenkov.png