Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Geant4 geometry to VecGeom in memory #557

Merged
merged 121 commits into from
Apr 12, 2023

Conversation

mrguilima
Copy link
Contributor

This is a first "working" version of the Geant4-to-VecGeom in-memory geometry conversion, for a first round of comments.

Known issues:

  • Geant4 geometry could not be deleted. Attempt to call G4PhysicalVolumeStore::GetInstance()->Clean() results into a crash at the second test Setup()
  • Similarly, there are duplicated materials from the second Setup() onwards
  • Geant4 units are properly read in mm units, but VecGeom model is built without a mm->cm conversion in volume units. To be checked and discussed.

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @mrguilima ! I've left a first round of comments.

src/CMakeLists.txt Outdated Show resolved Hide resolved
src/celeritas/ext/VecgeomParams.hh Outdated Show resolved Hide resolved
src/celeritas/ext/VecgeomParams.hh Outdated Show resolved Hide resolved
src/celeritas/ext/VecgeomParams.cc Outdated Show resolved Hide resolved
src/celeritas/ext/VecgeomParams.cc Outdated Show resolved Hide resolved
test/CMakeLists.txt Outdated Show resolved Hide resolved
test/celeritas/ext/G4VecgeomConversion.test.cc Outdated Show resolved Hide resolved
test/celeritas/ext/G4VecgeomConversion.test.cc Outdated Show resolved Hide resolved
test/celeritas/ext/G4VecgeomConversion.test.cc Outdated Show resolved Hide resolved
test/celeritas/ext/G4VecgeomConversion.test.cc Outdated Show resolved Hide resolved
@sethrj sethrj marked this pull request as draft November 24, 2022 13:44
@sethrj sethrj changed the title [WIP] Geant4->VecGeom in-memory conversion Convert Geant4 geometry to VecGeom in memory Nov 24, 2022
@sethrj
Copy link
Member

sethrj commented Nov 26, 2022

FYI the CI is failing, possibly because of a version difference between the VecGeom versions?

FAILED: src/celeritas/CMakeFiles/celeritas_objects.dir/ext/detail/G4VecgeomConverter.cc.o 
/usr/bin/c++ -DG4LIB_BUILD_DLL -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -DVECCORE_ENABLE_CUDA -I/var/jenkins/workspace/Celeritas_PR-557/src -I/var/jenkins/workspace/Celeritas_PR-557/build/include -isystem /opt/view/include/Geant4 -isystem /usr/local/cuda/include -isystem /opt/view/include -isystem /opt/vecgeom/include -Wall -Wextra -pedantic -Werror -Wno-error=deprecated-declarations -O3 -DNDEBUG -fPIC -fopenmp -faligned-new -std=c++14 -MD -MT src/celeritas/CMakeFiles/celeritas_objects.dir/ext/detail/G4VecgeomConverter.cc.o -MF src/celeritas/CMakeFiles/celeritas_objects.dir/ext/detail/G4VecgeomConverter.cc.o.d -o src/celeritas/CMakeFiles/celeritas_objects.dir/ext/detail/G4VecgeomConverter.cc.o -c /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/G4VecgeomConverter.cc
In file included from /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/G4VecgeomConverter.cc:193:
/var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/GenericSolid.hh: In member function 'vecgeom::cxx::VPlacedVolume* GenericSolid<S>::SpecializedVolume(const vecgeom::cxx::LogicalVolume*, const vecgeom::cxx::Transformation3D*, TranslationCode, RotationCode, vecgeom::cxx::VPlacedVolume*) const':
/var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/GenericSolid.hh:186:62: error: invalid new-expression of abstract class type 'GenericPlacedVolume'
  186 |         return new GenericPlacedVolume(volume, transformation);
      |                                                              ^
In file included from /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/GenericSolid.hh:17,
                 from /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/G4VecgeomConverter.cc:193:
/var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/GenericPlacedVolume.hh:30:7: note:   because the following virtual functions are pure within 'GenericPlacedVolume':
   30 | class GenericPlacedVolume : public vecgeom::VPlacedVolume
      |       ^~~~~~~~~~~~~~~~~~~
In file included from /opt/vecgeom/include/VecGeom/management/GeoManager.h:14,
                 from /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/G4VecgeomConverter.hh:20,
                 from /var/jenkins/workspace/Celeritas_PR-557/src/celeritas/ext/detail/G4VecgeomConverter.cc:14:
/opt/vecgeom/include/VecGeom/volumes/PlacedVolume.h:407:16: note: 	'virtual void vecgeom::cxx::VPlacedVolume::SafetyToInMinimize(const vecgeom::cxx::SOA3D<double>&, vecgeom::cxx::Precision*) const'
  407 |   virtual void SafetyToInMinimize(SOA3D<Precision> const &points, Precision *const safeties) const = 0;
      |                ^~~~~~~~~~~~~~~~~~

src/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, there is still plenty that can be improved, but since the plan is to move this to a separate library (and because it's derivative code) let's just call it good. I'm going to add to the code list to LICENSE before merging.

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrguilima I built your branch and spent some detailed time looking it over last night and fixing issues.

  • It didn't build on my mac at first (because vecgeom doesn't define DeviceVec if CUDA isn't enabled)
  • I didn't catch that these detail classes weren't in the detail namespace
  • By removing geant4 includes from the header I'm able to directly include the file from VecgeomParams
  • Several functions were unused and several unused macro-blocked pieces of code had errors in them; I deleted both
  • Temporarily changed the test results to pass on my mac: particles are getting stuck in the torus

The last one is particularly worrisome because it means we're getting different results from different builds of VecGeom. Since the torus tracking fails both in direct vecgeom and on the G4 constructed one, perhaps it's better to punt on that, remove the torus from our unit test, and report a bug on vecgeom jira?

Three other big things:

  1. I think the converter is leaking a ton of memory. It's unclear from the code which of the bajillion pointers take ownership.
  2. Constructing boolean volumes (addition, subtraction) results in duplicate name warnings like warning: Geometry contains duplicate volume names: "placedB_bool_right" (10), "placedB_bool_right" (12). These duplicate names are all over the place in the CMS run 3 geometry (even with VGDML) and seem to break our ability to transport on it. Can you figure out why these are being constructed and how? Is one a temporary?
  3. It looks like the world pointer that we pass to geo_manager.SetWorld get copied instead of owned, so we won't be able to play any tricks with the pointer maps we build so the vecgeom pointers are useless. We'll need to build a separate map of g4_logical_volume.GetInstanceID() to vecgeom_logical_volume.id().

Copy link
Contributor Author

@mrguilima mrguilima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit e220a9d breaks my VecGeom tests in Linux (as that commit message implies).

src/celeritas/ext/detail/GenericPlacedVolume.hh Outdated Show resolved Hide resolved
src/celeritas/ext/detail/GenericSolid.hh Outdated Show resolved Hide resolved
@sethrj
Copy link
Member

sethrj commented Apr 6, 2023

Following up from @mrguilima 's tests: building vecgeom (can you confirm it's 1.2.2?) with:

/opt/homebrew/bin/cmake \
    -G Ninja \
    -DBUILD_SHARED_LIBS="OFF" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX="/Users/lima/work/cele/install" \
    -DCMAKE_PREFIX_PATH="/Users/lima/work/cele/install" \
    -DVECGEOM_BACKEND="scalar" \
    -DVECGEOM_BUILTIN_VECCORE="OFF" \
    -DVECGEOM_GDML="ON" \
    -DVECGEOM_GEANT4="OFF" \
    -DVECGEOM_NO_SPECIALIZATION="ON" \
    -DVECGEOM_ROOT="OFF" \
    -DVECGEOM_TEST_BENCHMARK="OFF" \
    -DVECGEOM_TEST_VALIDATION="OFF" \
    -DVECGEOM_USE_NAVINDEX="ON" \
    -DXercesC_INCLUDE_DIR="/Users/lima/work/cele/install/include" \
    -DXercesC_LIBRARY="/Users/lima/work/cele/install/lib/libxerces-c.dylib" \
    /Users/lima/work/cele/deps/vecgeom

the tests pass without the REVERTME changes I added... i.e. they don't show the epsilon bumps through the torus. This is with an M1 laptop running MacOS Monterey 12.6.4 and clang 14.0.0.

@sethrj
Copy link
Member

sethrj commented Apr 12, 2023

Once the CI passes I'm going to merge! 🎉

@sethrj sethrj merged commit 667e19f into celeritas-project:develop Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request external Integration with external components (VecGeom, Geant4, ROOT, HepMC3)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Geant4 to Vecgeom in-memory converter
4 participants