Repository navigation
Convert G4MultiUnion solids - #48
austinschneider wants to merge 2 commits into
Conversation
Extracted from the standalone G4VG snapshot dated 2025-06-30 that the CCM experiment has carried in production since, rebased onto current main. The conversion code is unchanged from that snapshot. Co-authored-by: Seth R. Johnson <johnsonsr@ornl.gov>
for more information, see https://pre-commit.ci
sethrj
left a comment
There was a problem hiding this comment.
Thanks a bunch @austinschneider ! There are a couple things (most importantly testing) to address but this is great looking work.
| G4Transform3D const& tr = solid.GetTransformation(i); | ||
| G4RotationMatrix const rot = tr.getRotation().inverse(); | ||
| G4ThreeVector const trans = tr.getTranslation(); | ||
| Transformation3D const vgtr = transform_(trans, &rot); |
There was a problem hiding this comment.
It would be a little nicer to use the same technique as convert_bool_impl:
| G4Transform3D const& tr = solid.GetTransformation(i); | |
| G4RotationMatrix const rot = tr.getRotation().inverse(); | |
| G4ThreeVector const trans = tr.getTranslation(); | |
| Transformation3D const vgtr = transform_(trans, &rot); | |
| Transformation3D const vgtr = transform_(solid.GetTransformation(i).inverse()); |
by defining a new overload to Transformer:
inline result_type operator()(G4Transform3D const& t) const;| } | ||
| result_type result = make_unplaced_boolean<kUnion>( | ||
| placed[0], placed.size() > 1 ? placed[1] : placed[0]); | ||
|
|
There was a problem hiding this comment.
A diagnostic message would be nice to indicate that the union has been converted to a nested bool:
G4VG_LOG(info) << "Converted multiunion '" << solid.GetName() << "' to a depth-" << level << " union";| // A G4MultiUnion's constituents may overlap, which VecGeom's | ||
| // UnplacedMultiUnion handles via its own BVH but a tree of binary | ||
| // booleans does not: overlapping constituents leave internal | ||
| // boundaries that the navigator reports as real surface crossings. | ||
| // Native mode is therefore the physically faithful conversion, but | ||
| // UnplacedMultiUnion has no working GPU copy (its nodes are not | ||
| // transferred), so the boolean tree is the only device-capable form. | ||
| // G4VG_MULTIUNION=native selects the faithful path (host only). |
There was a problem hiding this comment.
Is the vecgeom team aware of this bug?
| << "': " << n_inside << "/" << n_total | ||
| << " points inside, " << n_mismatch | ||
| << " containment mismatches"; | ||
| } |
There was a problem hiding this comment.
This would be a great comparison check to add to testing, but probably shouldn't be part of the conversion process itself. (It doesn't need any temporary internal data from the conversion process.) Could you try adding a GDML file test/data/multiunions.gdml and a MultiUnionsTest that does this check?
| { | ||
| char const* mode = std::getenv("G4VG_MULTIUNION"); | ||
| if (mode && std::string_view{mode} == "native") | ||
| { |
There was a problem hiding this comment.
Instead of being an environment variable, this should live in Options (see G4VG.hh) and be passed into the SolidConverter. Once the bug is fixed upstream, we can set the default conversion option based on the VecGeom version being used (and/or whether CUDA is enabled).
| result_type result = make_unplaced_boolean<kUnion>( | ||
| placed[0], placed.size() > 1 ? placed[1] : placed[0]); |
There was a problem hiding this comment.
I'm not sure this is correct: if the size is 1 then it makes a union of the shape and itself? What if you changed the loop to placed.size() > 1, then assert that placed.size() == 1 and the result is just placed.front()?
|
hi @austinschneider ! I think your PR here was auto-generated, but it would still be useful if you want to send your robot minions to finish the work 😄 it woudl be a valuable additoin. |
|
Ping @austinschneider |
This offers G4MultiUnion conversion support that the CCM experiment has been carrying in production since mid-2025. The code originates from a standalone G4VG snapshot dated 2025-06-30 (authored by @sethrj — credit preserved via co-author trailer; happy to re-attribute however you prefer). We extracted the MultiUnion delta against the snapshot's base (the tree matches upstream at #36 plus exactly these 125 lines) and rebased it onto current
main; it applies cleanly with no other changes.On our side this has compiled and run in every GPU production stack build for the CCM liquid-argon geometry (VecGeom 1.2.11, CUDA 12.8, sm_80), where the detector geometry contains G4MultiUnion solids.
One caveat for the device leg:
vecgeom::UnplacedMultiUnion::CopyToGputakes the generic byte-copy path and never copies the constituent node structure, so first device use of a converted MultiUnion is an illegal memory access until that is fixed in VecGeom — we run with a workaround and are reporting the VecGeom defect separately. Host-side conversion and use are unaffected.Opening as a draft; glad to add a unit test in the repo's Gdml/Custom test style if you want this to proceed.