JUNO+Opticks : Geometry Issues

JUNO+Opticks : XJfixtureConstruction + trunk Geometry

Open source, https://bitbucket.org/simoncblyth/opticks

Opticks replaces Geant4 optical photon simulation with an equivalent implementation that benefits from state-of-the-art GPU ray tracing from NVIDIA OptiX. All optically relevant aspects of Geant4 context must be translated+copied to GPU:

  • geometry : solids, structure, material+surface properties
  • generation : Cerenkov + Scintillation (using Gensteps from Geant4)
  • propagation : Rayleigh scattering, absorption, reemission, boundary

Achieving+maintaining equivalence is time consuming, BUT:

  • transformative performance benefits >1000x Geant4

Simon C Blyth — 7 March 2022


Investigate XJfixtureConstruction Solid

Investigate XJfixtureConstruction Solid


cxr_geochain_XJfixtureConstruction_ALL_jpg

EYE=3,0.5,-1 UP=0,0,1 ZOOM=4 TMIN=0 PUB=1 ./cxr_geochain.sh

holy geometry : celtic cross (tubs + FOUR box) atop an altar (TWO box)
union of annular tubs and SIX boxes

cxr_geochain_XJfixtureConstruction_ALL_otherside_jpg

EYE=-3,0.5,-1 UP=0,0,1 ZOOM=4 TMIN=0 PUB=otherside  ./cxr_geochain.sh

cxr_geochain_XJfixtureConstruction_ALL_upper_jpg

EYE=-3,0.5,1 UP=0,0,1 ZOOM=4 TMIN=0 PUB=upper ./cxr_geochain.sh

cxr_geochain_XJfixtureConstruction_ALL_speckle_jpg

EYE=-3,0.5,0.8 UP=0,0,1 ZOOM=4 TMIN=2.7 CAM=0 PUB=speckle ./cxr_geochain.sh

XJfixtureConstruction CSG Tree (Geant4 Height 5, Opticks Height 6)

NODE:13 PRIM:7

                                                                        Uni
                                                                        U
                                                                        9


                                                        Uni                             Uni
                                                        U                               U
                                                        7                               11


                                        Uni                     Box             Box             Box
                                        U                       U               U               U
                                        5                       8               10              12


                        Uni                     Box
                        U                       U
                        3                       6


        Uni                     Box
        U                       U
        1                       4


Tub             Box
U               U
0               2


0                  0.00            0.00           50.00          -50.00            0.00            0.00 zdelta

6                 11.50           11.50           65.00          -35.00           40.00           65.00 az1
-6               -11.50          -11.50           35.00          -65.00          -40.00          -65.00 az0

XJfixtureConstruction CSG Tree After Balancing (Height 3)


                                                                       un
                                                                      1
                                                                         0.00
                                                                        -0.00

                               un                                                                              un
                              2                                                                               3
                                 0.00                                                                            0.00
                                -0.00                                                                           -0.00

           un                                      un                                      in                                      un
          4                                       5                                       6                                       7
             0.00                                    0.00                                    0.00                                    0.00
            -0.00                                   -0.00                                   -0.00                                   -0.00

 bo                  bo                  bo                  bo                  cy                 !cy                  bo                  bo
8                   9                   10                  11                  12                  13                  14                  15
   6.50                6.50                6.50                6.50                6.50                6.57              -16.50               -6.50
  -6.50               -6.50               -6.50               -6.50               -6.50               -6.57              -33.50              -16.50

cxs_custom_XJfixtureConstructionXY

COMP=custom_XY ./cxs_solidXJfixture.sh
cross section view of standalone solidXJfixture
All interior red intersects are spurious : not easy to fix.
probable cause of history discrepancy

So many spurious intersects : Easier to start over with fewer constituent solids


XJfixtureConstruction_YZ_two_types_of_spurious.jpg0

XJfixtureConstruction_YZ_two_types_of_spurious.jpg1

XJfixtureConstruction_XY_spurious_internal.jpg0

rays generated in XY plane from genstep positions (yellow dots)
yellow lines and arrows : rays and spurious internal intersects

XJfixtureConstruction_XY_spurious_internal.jpg1

Algorithm for Ray Intersection onto Shape defined by CSG Tree

Tree intersect is constituent node intersect, which depends on:

Algorithm:

  1. classify constituent intersects Enter/Exit/Miss
  2. determine action combining classifications using six lookup tables for UNION, INTERSECTION and DIFFERENCE operators and which intersect is closer.
  3. actions RETURN_A RETURN_B RETURN_MISS push binary decision onto stack for use at higher level of tree
  4. actions LOOP_A LOOP_B advance t_min for one constituent to get otherside and compare again
Surface-centric CSG (Opticks)

no use of "is this point inside the shape" queries

  • LOW RESOURCE USAGE : small stack of ~4*float4 isect
Volume-centric CSG (Geant4)
always asking "is this point inside the shape"

CSG Intersection Algorithm : UNION Lookup Table and Examples

+-----------------+-----------------+-----------------+-----------------+       UX1 : UNION FROM INSIDE ONE                     UX2 : UNION FROM OUTSIDE 0,1,2
| UNION           |                 |                 |                 |                                                       UX3 : UNION FROM INSIDE BOTH 3,4,5
|                 | B Enter         | B Exit          | B Miss          |
| A Closer        |                 |                 |                 |                    +-----------------------+                     +-----------------------+
| B Closer        |                 |                 |                 |                    |                     B |                     |                     B |
|                 |                 |                 |                 |         +------------------+               |          +------------------+               |
+-----------------+-----------------+-----------------+-----------------+         | A        |       |               |          | A        |       |               |
|                 |                 |                 |                 |         |          |       |               |          |          |       |               |
| A Enter         |                 |                 |                 |         |          |       |               |          |          |       |               |
|                 | RETURN_A        | LOOP_A          | RETURN_A        |         |   0- - - 1 - - - 2 - - - - - - -[3]     0 -[1]- - - -  2       |               |
|                 | RETURN_B        | RETURN_B        | RETURN_A        |         |          E       X               X          E          E   3 - 4 - - - - - - -[5]
|                 |                 |                 |                 |         |          |       |               |          |          |       X               X
+-----------------+-----------------+-----------------+-----------------+         |          +-------|---------------+          |          +-------|---------------+
|                 |                 |                 |                 |         |                  |                          |                  |
| A Exit          |                 |                 |                 |         |                  |                          |                  |
|                 | RETURN_A        | RETURN_B        | RETURN_A        |         +------------------+                          +------------------+
|                 | LOOP_B          | RETURN_A        | RETURN_A        |
|                 |                 |                 |                 |
+-----------------+-----------------+-----------------+-----------------+       0: origin                                     0: origin
|                 |                 |                 |                 |       1: B Enter                                    1: A Enter
| A Miss          |                 |                 |                 |       2: A Exit                                     2: B Enter
|                 | RETURN_B        | RETURN_B        | RETURN_MISS     |       1,2: B Closer        ==> LOOP_B               1,2: A Closer        ==> RETURN_A
|                 | RETURN_B        | RETURN_B        | RETURN_MISS     |       3: B Exit
|                 |                 |                 |                 |       2,3: A closer        ==> RETURN_B             3: origin
+-----------------+-----------------+-----------------+-----------------+                                                     4: A Exit
                                                                                                                              5: B Exit
Ordering states (Closer,Further)                                                                                              4,5 A Closer         ==> RETURN_B

(A Enter, B Enter)                                                                    UX4 : DISJOINT UNION  0,[1],2
    origin outside both -> return closest
                                                                                        +---------------------+                +---------------------+
(A Exit, B Exit)                                                                        | A                   |                |                   B |
    origin inside both  -> return furthest                                              |                     |                |                     |
                                                                                        |                     |                |                     |
(A Exit, B Enter)                                                                       |                     |                |                     |
    origin inside A                                                                     |                     |                |                     |
                                                                                        |         0- - - - - [1] -  - - - - - -2                     |
    * if A closer return A (means disjoint)                                             |                     X                E                     |
    * if B closer loop B (find otherside of B, then compare again)                      |                     |                |                     |
                                                                                        |                     |                |                     |
                                                                                        |                     |                |                     |
                                                                                        +---------------------+                +---------------------+

                                                                                    0: origin   1: A Exit   2: B Enter    1,2: A Closer => RETURN_A [1]

CSG Intersection Algorithm : INTERSECTION Lookup Table and Examples

+-----------------+-----------------+-----------------+-----------------+        Ordering states (Closer,Further)
| INTERSECTION    |                 |                 |                 |
|                 | B Enter         | B Exit          | B Miss          |        (Enter, Exit) -> Return Closer One : the Enter
| A Closer        |                 |                 |                 |
| B Closer        |                 |                 |                 |        (Exit, Exit) -> Return Closer Exit
|                 |                 |                 |                 |
+-----------------+-----------------+-----------------+-----------------+        (Exit, Enter) -> Loop Closer (the Exit)
|                 |                 |                 |                 |            One might first imagine that having just exited so there will be no otherside ?
| A Enter         |                 |                 |                 |            But that assumes simple convex constituent shapes whereas the alg needs to
|                 | LOOP_A          | RETURN_A        | RETURN_MISS     |            handle less simple shapes like torus or annulus
|                 | LOOP_B          | LOOP_B          | RETURN_MISS     |
|                 |                 |                 |                 |        (Enter, Enter) -> Loop Closer
+-----------------+-----------------+-----------------+-----------------+            Find otherside of Closer Enter
|                 |                 |                 |                 |            (by advancing t_min, intersecting that constituent again, comparing again)
| A Exit          |                 |                 |                 |
|                 | LOOP_A          | RETURN_A        | RETURN_MISS     |
|                 | RETURN_B        | RETURN_B        | RETURN_MISS     |                    +-------------+
|                 |                 |                 |                 |                    | A           |
+-----------------+-----------------+-----------------+-----------------+                    |      +------|-------+      0:Origin
|                 |                 |                 |                 |                    |      |      |     B |      1:A_Enter
| A Miss          |                 |                 |                 |              0- - -1 - - [2]- - -3       |      2:B_Enter
|                 | RETURN_MISS     | RETURN_MISS     | RETURN_MISS     |                    E      E      X       |      (1:A_Enter,2:B_Enter) => A_Closer => LOOP_A => 3
|                 | RETURN_MISS     | RETURN_MISS     | RETURN_MISS     |                    |      |      |       |      3:A Exit
|                 |                 |                 |                 |                    +------|------+       |      (2:B Enter,3:A Exit) => RETURN_B 2:B_Enter
+-----------------+-----------------+-----------------+-----------------+                           |              |
                                                                                                    +--------------+

XJfixtureConstructionUnbalanced_XY_unbalanced_ok.jpg0

XJfixtureConstructionUnbalanced_XY_unbalanced_ok.jpg1

CSG Compound "List-Nodes" => Much Smaller CSG trees

CSG_CONTIGUOUS Union
similar to G4MultiUnion : n-ary CSG intersection (needs distance sorting)
CSG_DISCONTIGUOUS Union
user guarantees no overlaps
CSG_OVERLAP Intersection
user guarantees overlap, aims to handle general G4Sphere with inner radius, thetacut and phicut

Communicating shape more precisely => better suited alg => less resources => faster

Generalized Opticks CSG into three levels : tree < node < leaf

Three levels avoids recursion in intersect (disallowed by NVIDIA OptiX)

CSG_CONTIGUOUS Union : n-ary (not bin-ary) CSG intersection

  1. zeroth pass : find nearest_enter and count exits
  2. zero exits => outside compound => return nearest_enter
  3. first pass : collect enter distances, farthest_exit
  4. order enter indices making enter distances ascend
    • n-ary : store, sort enters (cf bin-ary : compare two)
    • no tree overheads, but must store+sort distances
  5. 2nd pass : loop over enters in distance order
    • contiguous requirement : tminAdvanced < farthest_exit
    • find Exits for Enters that qualify as contiguous
  6. return farthest_exit that qualifies as contiguous
         +----------------+     +-------------------+                  DISJOINT MUST BE DISQUALIFIED
         |B               |     |D                  |
    +----|----+      +----|-----|----+       +------|----------+             +-----------+
    |A   |    |      |C   |     |    |       |E     |          |             |           |
    |    |    |      |    |     |    |       |      |          |             |           |
    | 0 E1    X2     E3  X4    E5   X6      E7     X8        [X9]           E10         X11
    |    |    |      |    |     |    |       |      |          |             |           |
    |    |    |      |    |     |    |       |      |          |             |           |
    +----|----+      +----|-----|----+       +------|----------+             +-----------+
         |                |     |                   |
         +----------------+     +-------------------+

         E           E          E            E                               E
              X           X          X              X          X                         X
 

CSG_DISCONTIGUOUS Union : CSG intersection

User guarantees : absolutely no overlapping between constituents

 +-------+          +-------+          +-------+          +-------+         +-------+
 |       |          |       |          |       |          |       |         |       |
 |       |          |       |          |       |          |       |         |       |
 +-------+          +-------+          +-------+          +-------+         +-------+

 +-------+          +-------+          +-------+          +-------+         +-------+
 |       |          |       |          |       |          |       |         |       |
 |       |          |       |          |       |          |       |         |       |
 +-------+          +-------+          +-------+          +-------+         +-------+

 

CSG_OVERLAP Intersection : CSG intersection

User guarantees : all constituents overlap => ( farthest_enter or nearest_exit ) with all overlap requirement:

farthest_enter < nearest_exit and max(enter_count, exit_count) == num_sub

                                                   1X,2M -> MISS
                                    +----------------1X-------------+
                                    |               /             C |
                                    |              0                |
                          +---------------------------------+       |
                          |         |                     B |       |
               +----------------------------+         0- - -1 - - - 2     2X,1M -> MISS
               | A        |         | . ABC |               X       X
               |          |         | . . . |               |       |
      0 - - - -1- - - - - 2- - - - [3]- - - 4               |       |
               E          E         E . . . X               |       |
               |          |         | . . . |               |       |
               |          |         | .0- -[1]- - - - - - - 2 - - - 3 - -
               |          |         | . . . X               X       X
               |          |         +-------------------------------+
               |          |                 |               |
         0 - - 1 - - - - -2 - - - - - - - - 3 - - - - - - - 4
               E          E   (2E,1M)-> M   X               X   (2X,1M) -> M
               |          +---------------------------------+
               |                            |
               +----------------------------+
 

Avoid tree overheads for suitable shapes (eg general sphere:inner-radius,phicut,thetacut)

AltXJfixtureConstruction_XY_internal_spurious.jpg

AltXJfixtureConstruction_XY_sorted_enter_fix.jpg

Check Latest JUNO Geometry

Check Latest JUNO Geometry (trunk:March 2nd 2022)

cxr_overview_emm_t8,_moi_-1_broken_trans_perhaps.jpg

cxr_overview_emm_0,_moi_-1_part_of_chimney_correct.jpg

EMM=0, EYE=-0.6,0,0.3 LOOK=0,0,0 ./cxr_overview.sh

cxr_overview_emm_0,_moi_-1_part_of_chimney_correct.jpg_0.5

EMM=0, EYE=-0.6,0,0.3 LOOK=0,0,0 TMIN=0.5 ./cxr_overview.sh

cxr_view___eye_-10,0,0__zoom_1__tmin_0_sChimneyAcrylic_sticks_disappeared.jpg

MOI=sChimneyAcrylic EYE=-10,0,0 TMIN=0 ./cxr_view.sh

struts and part of Chimney mis-placed

cxr_view___eye_-10,0,0__zoom_1__tmin_0_sChimneyAcrylic_now_struts.jpg

MOI=sChimneyAcrylic EYE=-10,0,0 TMIN=0 ./cxr_view.sh

BACK AGAIN AFTER FIX

cxr_view___eye_-10,0,0__zoom_1__tmin_0_sChimneySteel_steel_ok.jpg

MOI=sChimneySteel EYE=-10,0,0 TMIN=0 ./cxr_view.sh

cxr_view___eye_-2,0,0__zoom_1__tmin_0.1_sChimneyLS_chimney_mid_LS.jpg

MOI=sChimneyLS EYE=-2,0,0 TMIN=0.1 ./cxr_view.sh

part of Chimney in middle of CD

cxr_overview_emm_t0_moi_-1_simple_transform_check.jpg

simple transform check (g4ok/G4OKVolumeTest.sh) fails to reproduce issue
(using nnvtBodyLogGrid from j/PMTSim lib)

OTracerTest_Frame000_raster.jpg

g4ok/G4OKVolumeTest.sh with GEOM=ListJustOrb,BoxMinusOrb

ok/ott.sh OTracerTest OpenGL raster view looks normal

OTracerTest_Frame000_raytrace.jpg

ok/ott.sh OTracerTest OptiX raytrace : reproduces issue
global(non-instanced) leaf nodes are mis-placed : at origin

cxr_overview_emm_t0_moi_-1_confirmed_fix.jpg

./cxr_overview.sh
after fix : 0.0126  (cf 0.0054 from Dec 2021)

TODO: investigate cause of slowdown

Next Steps

Next Steps

Repeat January checks with current geometry

https://simoncblyth.bitbucket.io/env/presentation/opticks_20220118_juno_collaboration_meeting.html

AltXJfixtureConstruction with CSG_CONTIGUOUS

After Geometry Issues Fixed : port OptiXRap sim to QUDARap (for OptiX 7)

CSGOptix : depends on QUDARap for generation + propagation, adds geometry intersection

LHCb RICH SWIFT-HEP UK GPU Hackathon with NVIDIA Engineers

Opticks updated for LHCb RICH Simplified geometry:

Added externally set bounding box functionality (CSG_EXBB)

Contributing to UK GPU Hackathon