Skip to content

fix(u4solid): remove sphere deltaPhi assertion that crashes on dRICH mirror#289

Closed
ggalgoczi wants to merge 2 commits into
mainfrom
fix-sphere-phicut-assert
Closed

fix(u4solid): remove sphere deltaPhi assertion that crashes on dRICH mirror#289
ggalgoczi wants to merge 2 commits into
mainfrom
fix-sphere-phicut-assert

Conversation

@ggalgoczi
Copy link
Copy Markdown
Contributor

The assertion required deltaPhi == 2pi for all spheres, but the dRICH mirror sphere has deltaPhi < 2pi from DD4hep construction. The phi clipping is handled by the parent IntersectionSolid, so the sphere primitive does not need to enforce it.

The assertion required deltaPhi == 2*pi for all spheres, but the dRICH
mirror sphere has deltaPhi < 2*pi from DD4hep construction. The phi
clipping is handled by the parent IntersectionSolid, so the sphere
primitive does not need to enforce it.
@ggalgoczi ggalgoczi requested a review from plexoos April 12, 2026 20:51
@ggalgoczi ggalgoczi self-assigned this Apr 12, 2026
@ggalgoczi ggalgoczi added the bug Something isn't working label Apr 12, 2026
@plexoos plexoos changed the title fix: remove sphere deltaPhi assertion that crashes on dRICH mirror fix(u4solid): remove sphere deltaPhi assertion that crashes on dRICH mirror Apr 14, 2026
@plexoos
Copy link
Copy Markdown
Member

plexoos commented Apr 14, 2026

I’m concerned this change is broader than the problem it is trying to solve.

Deleting the assert does unblock the dRICH case, but it also removes the only fail-fast check that told us when a G4Sphere with deltaPhi < 2*pi could not be represented by the current U4Solid sphere conversion. U4Solid::init_Sphere_ still only produces sn::Sphere / sn::ZSphere, and it still has the TODO: bring over phicut handling from X4Solid comment. So after this change, any partial-phi sphere is silently converted as a full-phi sphere.

That may be acceptable for the specific dRICH mirror if the DD4hep construction is really IntersectionSolid(partial sphere, clip solid) and the clipping solid fully replaces the sphere’s phi boundaries. But this patch changes behavior for every partial-phi sphere, not just that geometry. In particular, it looks too broad given that we already have sphere phi-cut dev/test geometries in-tree (SphereWithPhiCutDEV, SphereWithPhiSegment, GeneralSphereDEV).

I also looked at the old X4Solid implementation for the general case. Historically, X4Solid::convertSphere_ did not just drop the phi segment: when deltaPhi < 360 and X4Solid_convertSphere_enable_phi_segment was enabled, it intersected the converted sphere/z-sphere tree with intersectWithPhiSegment(...). There was also a DEV path that applied intersectWithPhiCut(...) explicitly. That code was marked as experimental / poorly tested, so I do not think it should be copied blindly, but it does confirm that the intended direction was explicit sphere phi handling rather than removing the unsupported-geometry guard.

So I think we should either:

  1. narrow this workaround to the known dRICH construction and keep fail-fast behavior for unsupported general sphere phi cuts, or
  2. port proper sphere phi-cut handling into U4Solid, likely in a form closer to the current U4Polycone phicut handling.

@ggalgoczi
Copy link
Copy Markdown
Contributor Author

I’m concerned this change is broader than the problem it is trying to solve.

Deleting the assert does unblock the dRICH case, but it also removes the only fail-fast check that told us when a G4Sphere with deltaPhi < 2*pi could not be represented by the current U4Solid sphere conversion. U4Solid::init_Sphere_ still only produces sn::Sphere / sn::ZSphere, and it still has the TODO: bring over phicut handling from X4Solid comment. So after this change, any partial-phi sphere is silently converted as a full-phi sphere.

That may be acceptable for the specific dRICH mirror if the DD4hep construction is really IntersectionSolid(partial sphere, clip solid) and the clipping solid fully replaces the sphere’s phi boundaries. But this patch changes behavior for every partial-phi sphere, not just that geometry. In particular, it looks too broad given that we already have sphere phi-cut dev/test geometries in-tree (SphereWithPhiCutDEV, SphereWithPhiSegment, GeneralSphereDEV).

I also looked at the old X4Solid implementation for the general case. Historically, X4Solid::convertSphere_ did not just drop the phi segment: when deltaPhi < 360 and X4Solid_convertSphere_enable_phi_segment was enabled, it intersected the converted sphere/z-sphere tree with intersectWithPhiSegment(...). There was also a DEV path that applied intersectWithPhiCut(...) explicitly. That code was marked as experimental / poorly tested, so I do not think it should be copied blindly, but it does confirm that the intended direction was explicit sphere phi handling rather than removing the unsupported-geometry guard.

So I think we should either:

1. narrow this workaround to the known dRICH construction and keep fail-fast behavior for unsupported general sphere phi cuts, or

2. port proper sphere phi-cut handling into `U4Solid`, likely in a form closer to the current `U4Polycone` phicut handling.

I agree, this could cause problems for geometries, that have spherical mirrors and are not clipped. I can not think of such geometry right now. However I agree that this should not be a final fix. I would choose solution number 1.

However I am unsure how to detect "this is the dRICH construction" from inside init_Sphere. The converter only sees the G4Sphere primitive. What do you suggest?

@ggalgoczi
Copy link
Copy Markdown
Contributor Author

@plexoos what exactly is required from your side to merge this? Can you address my questions?

plexoos added a commit that referenced this pull request May 18, 2026
Add `SpherePhiCutQuarterShellTest` and a minimal GDML fixture covering a
partial-phi spherical shell with no parent `G4IntersectionSolid`.

A proposed change in `U4Solid::init_Sphere_()` removes the assert
guarding `deltaPhi != 2*pi`
(#289). That allows conversion
to proceed for phi-cut `G4Sphere` inputs even though `init_Sphere_()`
still only produces `sn::Sphere` or `sn::ZSphere` and does not model the
phi cut itself. In the general case this risks silently converting
a clipped spherical shell into a full-phi shell instead of failing fast.

This test records the current standalone partial-phi sphere case and
keeps it usable across both implementation states. It loads a reduced
GDML reproducer, verifies that the shape contains partial-phi sphere
primitives and no parent `G4IntersectionSolid`, then runs
`U4Solid::Convert()` in a child process so CTest can observe either the
current fail-fast rejection or a future successful conversion without
killing the test runner.

Keeping this regression test separate from any geometry-specific
intersection-clipping case makes the intent explicit: removing the
assert in `U4Solid::init_Sphere_()` is not a safe general fix unless
real sphere phi-cut support is added. If such support is added later,
this test continues to cover the fixture and conversion path, while a
separate positive test should verify the geometric correctness of the
resulting phi-cut solid.
plexoos added a commit that referenced this pull request May 18, 2026
Add `SpherePhiCutQuarterShellTest` and a minimal GDML fixture covering a partial-phi spherical shell
with no parent `G4IntersectionSolid`.

A proposed change in `U4Solid::init_Sphere_()` removes the assert guarding `deltaPhi != 2*pi`
(#289). That allows conversion to proceed for phi-cut
`G4Sphere` inputs even though `init_Sphere_()` still only produces `sn::Sphere` or `sn::ZSphere` and
does not model the phi cut itself. In the general case this risks silently converting a clipped
spherical shell into a full-phi shell instead of failing fast.

This test records the current standalone partial-phi sphere case and keeps it usable across both
implementation states. It loads a reduced GDML reproducer, verifies that the shape contains
partial-phi sphere primitives and no parent `G4IntersectionSolid`, then runs `U4Solid::Convert()` in
a child process so CTest can observe either the current fail-fast rejection or a future successful
conversion without killing the test runner.

Keeping this regression test separate from any geometry-specific intersection-clipping case makes
the intent explicit: removing the assert in `U4Solid::init_Sphere_()` is not a safe general fix
unless real sphere phi-cut support is added. If such support is added later, this test continues to
cover the fixture and conversion path, while a separate positive test should verify the geometric
correctness of the resulting phi-cut solid.
plexoos added a commit that referenced this pull request May 18, 2026
Add `SpherePhiCutQuarterShellTest` and a minimal GDML fixture covering a partial-phi spherical shell
with no parent `G4IntersectionSolid`.

A proposed change in `U4Solid::init_Sphere_()` removes the assert guarding `deltaPhi != 2*pi`
(#289). That allows conversion to proceed for phi-cut
`G4Sphere` inputs even though `init_Sphere_()` still only produces `sn::Sphere` or `sn::ZSphere` and
does not model the phi cut itself. In the general case this risks silently converting a clipped
spherical shell into a full-phi shell instead of failing fast.

This test records the current standalone partial-phi sphere case and keeps it usable across both
implementation states. It loads a reduced GDML reproducer, verifies that the shape contains
partial-phi sphere primitives and no parent `G4IntersectionSolid`, then runs `U4Solid::Convert()` in
a child process so CTest can observe either the current fail-fast rejection or a future successful
conversion without killing the test runner.

Keeping this regression test separate from any geometry-specific intersection-clipping case makes
the intent explicit: removing the assert in `U4Solid::init_Sphere_()` is not a safe general fix
unless real sphere phi-cut support is added. If such support is added later, this test continues to
cover the fixture and conversion path, while a separate positive test should verify the geometric
correctness of the resulting phi-cut solid.
@ggalgoczi ggalgoczi closed this May 19, 2026
@ggalgoczi ggalgoczi deleted the fix-sphere-phicut-assert branch May 19, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants