Skip to content

qbnd/qsim: carry source-medium matline across CSG sibling-pair faces#346

Open
ggalgoczi wants to merge 3 commits into
mainfrom
qbnd-sibling-pair-matline
Open

qbnd/qsim: carry source-medium matline across CSG sibling-pair faces#346
ggalgoczi wants to merge 3 commits into
mainfrom
qbnd-sibling-pair-matline

Conversation

@ggalgoczi
Copy link
Copy Markdown
Contributor

@ggalgoczi ggalgoczi commented May 29, 2026

Two CSG sibling primitives sharing a coincident face (daughters of one parent: segmented radiator bars + glue, or the coincident surfaces of a multi-layer lens) are not enumerated as a boundary by GBndLib, so OptiX mishandles them two independent ways — wrong material and wrong face. This PR fixes both.

Wrong material: the boundary OptiX picks has m1/m2 that do not reference the photon's current medium, so absorption/scattering sample the wrong material1. Carry the photon's matline (seeded from the genstep at birth in CSGOptiX7.cu, updated each propagate_at_boundary) in sctx::current_matline and use it as m1 in qbnd::fill_state when valid. No-op for correctly-enumerated boundaries (carried == the boundary's own m1_line). Wrong face: at the coincident face OptiX sorts the two coplanar intersections inconsistently; the exiting hit (cosTheta>0) carries the parent medium as m2 -> the photon refracts through a phantom parent-medium sliver, and on a TIR light-guide (DIRC bars) hits the critical angle and is lost. Bias the t reported to OptiX by +10 um on the exit side (cosI>0) in __intersection__is so the entering sibling wins; the real unbiased isect.w still goes to prd->q0.f so position advancement is unperturbed. Gated per boundary by index contrast |n_m1-n_m2|>0.1 (max over wavelength), computed in CSGOptiX::initSimulate from the bnd table into params.boundary_face_bias: a flat bias over-steps near-index-matched thin gaps (aerogel/air ~0.025 across 10-50 um => -6..-9% on dRICH), so high-contrast faces (quartz/air ~0.47) gate on and low-contrast ones gate off. No per-detector hardcode; nullptr => always-on.

The two fixes are complementary -- the matline picks the right material, the bias picks the right face; on a TIR light-guide either one alone collapses the GPU hit count. Verified ePIC hpDIRC mu- 3 GeV: GPU/CPU 0.987, bit-identical to the unconditional bias (all glued-sibling faces clear the threshold); low-index-contrast detectors unchanged.

GBndLib does not enumerate boundary entries for CSG sibling-pair faces (two daughters of one parent sharing a face), so OptiX can pick a boundary whose m1/m2 do not reference the photon's current medium -> absorption/scattering sampled in the wrong material1. Carry the photon's matline (seeded from the genstep at birth in CSGOptiX7.cu, updated each propagate_at_boundary) in sctx::current_matline and use it as m1 in qbnd::fill_state when valid. No-op for correctly-enumerated boundaries (carried == the boundary's own m1_line).
@ggalgoczi ggalgoczi self-assigned this May 29, 2026
@ggalgoczi ggalgoczi added the enhancement New feature or request label May 29, 2026
@ggalgoczi ggalgoczi marked this pull request as draft May 29, 2026 14:09
@ggalgoczi ggalgoczi marked this pull request as ready for review May 30, 2026 14:57
@ggalgoczi ggalgoczi requested a review from plexoos May 30, 2026 14:57
@ggalgoczi ggalgoczi force-pushed the qbnd-sibling-pair-matline branch from 15e0da7 to 6f9d9bd Compare May 30, 2026 15:00
…dent faces

At a face shared by two sibling primitives (segmented radiator bars + glue,
multi-layer CSG lens) OptiX sorts the two coplanar intersections
inconsistently; the "exiting" hit (cosI>0) carries the parent medium as m2,
wrong for a sibling crossing. Bias the t reported to OptiX's closest-hit sort
by +10 um on the exit side so the entering sibling wins. The real unbiased
distance is preserved in the PRD, so photon position advancement is unperturbed.

Gate the bias per boundary by index contrast |n_m1 - n_m2| > 0.1 (max over
wavelength), computed at translation in CSGOptiX::initSimulate from the bnd
table and read in __intersection__is. High-contrast faces (e.g. quartz/air
~0.47) need the entering-sibling selection; low-contrast thin gaps (e.g.
aerogel/air ~0.025) are harmed by it and gate off. No per-detector hardcode;
nullptr => always-on fallback.

Stacks on the matline-carry m1 fix (carry source-medium matline across CSG
sibling-pair faces): that fixes *which material* m1 is sampled; this fixes
*which face* OptiX selects. The two are complementary - on a TIR light-guide
either alone collapses the GPU hit count.

Verified ePIC hpDIRC mu- 3 GeV: GPU/CPU 0.987, bit-identical to the ungated
bias (all glued-sibling faces clear the 0.1 threshold). Low-index-contrast
detectors are unaffected (gate stays off at their thin gaps).
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v20.1.2) reports: 2 file(s) not formatted
  • CSGOptiX/Params.h
  • qudarap/qbnd.h

Have any feedback or feature suggestions? Share it here.

@ggalgoczi ggalgoczi force-pushed the qbnd-sibling-pair-matline branch from a212e4c to 325e81f Compare May 30, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant