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
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
d52f028
Add G4VecgeomConverter and dependency classes into celeritas
mrguilima May 31, 2022
cdad368
New VecgeomParams constructor for G4->VecGeom in-memory conversion
mrguilima May 31, 2022
5a5511e
New test: G4VecgeomConversion
mrguilima Jun 10, 2022
62617c0
Extended tests for the Geant4 -> VecGeom in-memory conversion
mrguilima Jun 9, 2022
cddbb42
Fixes to tests - ready for first review
mrguilima Jun 10, 2022
3608e81
Merge remote-tracking branch 'upstream/master' into g4vgConv
sethrj Dec 20, 2022
21ac995
Fix macros and interface
sethrj Dec 20, 2022
3c5a0a3
Add geant4+vecgeom test
sethrj Dec 20, 2022
665e887
Hack the test to work for now
sethrj Dec 20, 2022
f1161e0
Add VecGeom test of solids
sethrj Dec 20, 2022
002c0e2
Fix crash due to testing environment harness
sethrj Dec 20, 2022
1f5e9c8
Apply reviewer suggestions
mrguilima Dec 20, 2022
b5c7b9a
Drop redundant inclusion of Geant4 libraries
mrguilima Dec 21, 2022
390fe1b
Change decoding of trapezoid parameters to fix Vecgeom test
mrguilima Dec 22, 2022
5645386
Merge branch 'master' into g4vgConv
mrguilima Dec 22, 2022
814d6e2
Merge branch 'master' into g4vgConv
mrguilima Dec 28, 2022
83914e4
Tracking test passing, but investigating conversion issues
mrguilima Dec 28, 2022
53c8c19
Merge remote-tracking branch 'upstream/master' into g4vgConv
sethrj Dec 31, 2022
430bf2d
Testing mm-to-cm unit conversions for box, orb, trap (e.g. four-level…
mrguilima Dec 30, 2022
02c8d9f
Only one Geant4-converted will pass - disable SolidGeantTest
mrguilima Jan 4, 2023
cdbdcff
Move towards celeritas coding guidelines
mrguilima Jan 3, 2023
4395c67
Move G4VecGeomConverter et.al. to namespace celeritas
mrguilima Jan 4, 2023
dd87aba
Use 'else if' to avoid unnecessary checks
mrguilima Jan 4, 2023
d1c8936
Make FourLevels and FourLevelsGeant tracking tests code-identical
mrguilima Jan 4, 2023
194522b
Merge branch 'master' into g4vgConv
mrguilima Jan 4, 2023
516f0d5
Fix includes and cmake code and geant
sethrj Jan 6, 2023
ae615f0
Remove zombie files
sethrj Jan 6, 2023
fb3ad0d
Split vecgeom test into separate executions for geant
sethrj Jan 6, 2023
c074cad
Remove unsupported solids
sethrj Jan 6, 2023
325b56d
Add scaling factor, and convertion support for several new shapes
mrguilima Jan 9, 2023
b4244bc
Remove spurious space
mrguilima Jan 9, 2023
759355f
Some style improvements
mrguilima Jan 9, 2023
b199557
Add support to tessellated solids and fix arguments ordering for gene…
mrguilima Jan 9, 2023
52dfb4d
Merge branch 'master' into g4vgConv
mrguilima Jan 18, 2023
c7a8bb6
Merge branch 'srj/g4vgConv' into g4vgConv
sethrj Jan 20, 2023
172370b
Much improved solids.gdml
mrguilima Jan 20, 2023
af89ef3
Much improved solids.gdml
mrguilima Jan 20, 2023
2c2a400
Add conversion support for the paraboloid shape
mrguilima Jan 20, 2023
e17bf7d
Some quick cleanup
mrguilima Jan 20, 2023
481e249
Some optimization by reordering
mrguilima Jan 26, 2023
2694fcd
Fix Vecgeom test, but now it produces discrepant VGDML vs. Converted …
mrguilima Jan 26, 2023
371c402
Fix trapezoid conversion
mrguilima Jan 31, 2023
6111e29
Merge branch 'master' into g4vgConv
mrguilima Jan 31, 2023
7b98266
Merge branch 'master' into g4vgConv
mrguilima Feb 2, 2023
fd57211
GL: add zeros to solids.gdml hopefully reduces # exception throws
mrguilima Feb 13, 2023
1766bc6
GL: remove spaces to tags in solids.gdml hopefully reduces # exceptio…
mrguilima Feb 13, 2023
1aea67b
Get rid of unsupported quantity tags and expressions
mrguilima Feb 14, 2023
96ea872
Reorder daughters pushing problems for later parsing
mrguilima Feb 14, 2023
4773ff4
Debugging printouts
mrguilima Feb 14, 2023
3cbc91d
Better variable name
mrguilima Feb 14, 2023
3e002ce
Remove shapes not ready for prime time
mrguilima Feb 14, 2023
97c3e35
CUDA disabled does not preclude VecGeom w/CUDA=ON to be used
mrguilima Feb 16, 2023
ef63443
Add lunit=mm to all shapes and adapt shape dimensions
mrguilima Feb 16, 2023
d368bef
Fix all tracing tests in solids.gdml
mrguilima Feb 16, 2023
66cb151
Merge branch 'master' into g4vgConv
mrguilima Feb 16, 2023
8f0410f
Replace iostream's cout,cerr with the Logger and some cleanup
mrguilima Feb 17, 2023
1f00ce2
Fix the geomdump test and some cleanup
mrguilima Feb 17, 2023
ded26b7
Bug fix to trapezoid conversion
mrguilima Feb 22, 2023
6763e6f
Fix tracing tests in converted geometry
mrguilima Feb 22, 2023
02dba2c
Merge branch 'master' into g4vgConv
mrguilima Feb 22, 2023
c2a65bc
Adding units to <position> GDML tags, and fix tracing tests
mrguilima Feb 23, 2023
22450bc
Fix to EllipticalCone distance tests
mrguilima Feb 24, 2023
87cd312
Small adjustments to solid parameters
mrguilima Mar 2, 2023
834aac9
Make sure tessellated solids are properly closed after conversion
mrguilima Mar 2, 2023
8378cab
Fix style: member data naming
mrguilima Mar 2, 2023
098d156
Adjust logger precision like upstream
mrguilima Mar 3, 2023
b9b6b35
Remove commented out code
mrguilima Mar 3, 2023
907856f
Cleanup namespace qualifiers
mrguilima Mar 3, 2023
ffcfc7d
Changes to follow Celeritas style
mrguilima Mar 6, 2023
236a778
Fix geo-check test: normalize input direction
mrguilima Mar 6, 2023
ead7843
Merge branch 'master' into g4vgConv
mrguilima Mar 6, 2023
4de911f
Merge remote-tracking branch 'upstream/master' into g4vgConv
sethrj Mar 13, 2023
9a699d9
Fix build error with geant4@11.0.3
sethrj Mar 13, 2023
e012cee
Delete zombie files
sethrj Mar 14, 2023
0de96c0
Print warning for versions less than 1.2.2
sethrj Mar 14, 2023
bfc5dbf
fixup! Merge remote-tracking branch 'upstream/master' into g4vgConv
sethrj Mar 14, 2023
74c4eb6
Merge branch 'develop' into g4vgConv
mrguilima Mar 17, 2023
44819ac
Revert "Delete zombie files"
sethrj Mar 18, 2023
338282b
Prevent major/minor conflicts on rhel8
sethrj Mar 18, 2023
dfaa2f3
Reorder #includes so #undef does take effect
mrguilima Mar 20, 2023
1100b22
Minor fix in VecGeom version check
mrguilima Mar 20, 2023
3022aa5
Conditionally add 0x suffix to LogicalVolume names
mrguilima Mar 17, 2023
074b7e9
Rename G4VecGeomConvert[er] -> GeantGeometryImport[er]
mrguilima Mar 24, 2023
51b5a67
Remove Geant4-related Cmake config, and fix spacing
mrguilima Mar 24, 2023
be3ae7b
Review logged output
mrguilima Mar 24, 2023
00baf3a
Replace VecGeom's BidirectionalMap with standard std::map
mrguilima Mar 24, 2023
d7ed344
Avoid adding whole vecgeom namespace in header files
mrguilima Mar 24, 2023
700facb
Address reviewer suggestions
mrguilima Mar 27, 2023
a38ff20
Cleanup on comments
mrguilima Mar 27, 2023
5421908
Rename clear_vecgeom() into clear_maps()
mrguilima Mar 27, 2023
b7fe6ad
Explicitely define or delete constructors and assignment operators
mrguilima Mar 29, 2023
4e5d392
General cleanup, as suggested in PR review
mrguilima Mar 29, 2023
1345da6
Remove verbosity flag
mrguilima Mar 29, 2023
cd19ff2
Use G4GeomImporter constructor =default and operator()
mrguilima Mar 30, 2023
038107e
Documentation improvements
mrguilima Mar 30, 2023
da93be8
Revert formatting changes to main code
sethrj Mar 31, 2023
1f9739e
Fix sysmacro weirdness with new include
sethrj Mar 31, 2023
b43bdea
Update copyrights for heavily modified code
sethrj Mar 31, 2023
c02baf3
Fix to documentation comment
mrguilima Apr 3, 2023
a52c3a7
Get rid of VECGEOM_VECTORAPI macro
mrguilima Apr 3, 2023
a04bac1
Get rid of 'using namespace vecgeom' in header file
mrguilima Apr 3, 2023
c5cb7b7
Of course vecgeom doesn't define classes when compiler options change
sethrj Apr 4, 2023
0d01b49
Don't forcibly clear maps and they clear on destruction anyway
sethrj Apr 4, 2023
f8b6d06
Fix namespaces
sethrj Apr 4, 2023
78eebd8
Update license text for new files
sethrj Apr 4, 2023
4559dbe
Delete unused functions
sethrj Apr 4, 2023
c390019
Consolidate files by hiding geant implementation
sethrj Apr 4, 2023
e220a9d
REVERTME: update failing tests on macos
sethrj Apr 4, 2023
6338333
Remove unused code with syntax errors in it
sethrj Apr 4, 2023
c37030e
Use Celeritas helper classes
sethrj Apr 4, 2023
97011c8
Revert "REVERTME: update failing tests on macos"
mrguilima Apr 4, 2023
12fe177
Fix typos in comments
mrguilima Apr 11, 2023
a67d32b
REVERTME: remove torus from Solids.gdml to avoid MacOS discrepancies
mrguilima Apr 11, 2023
14a8912
Fix merge conflicts
sethrj Apr 12, 2023
ae7d34c
Merge remote-tracking branch 'upstream/develop' into g4vgConv
sethrj Apr 12, 2023
8a85741
Normalize input direction in geo-check app
amandalund Apr 6, 2023
f6eda96
Delete now-unused geant geo exporter
sethrj Apr 12, 2023
0b54d89
Update documentation
sethrj Apr 12, 2023
3808d2d
Fix leak of std::vectors
sethrj Apr 12, 2023
ca2ae7e
Disable lengthy output by default in tests
sethrj Apr 12, 2023
24e49e5
Rename importer to converter
sethrj Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ elseif(CELERITAS_USE_HIP)
endif()

if(CELERITAS_USE_Geant4 AND NOT Geant4_FOUND)
# Geant4 calls `include_directories` for CLHEP :( which is not what we want!
# Save and restore include directories around the call -- even though as a
# standalone project Celeritas will never have directory-level includes
get_directory_property(_include_dirs INCLUDE_DIRECTORIES)
find_package(Geant4 REQUIRED)
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${_include_dirs}")
endif()

if(CELERITAS_USE_HepMC3 AND NOT HepMC3_FOUND)
Expand Down Expand Up @@ -227,8 +222,7 @@ endif()
if(CELERITAS_USE_VecGeom)
find_package(VecGeom 1.1.17 REQUIRED)

if((CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND)
OR (NOT CELERITAS_USE_CUDA AND VecGeom_CUDA_FOUND))
if((CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND))
mrguilima marked this conversation as resolved.
Show resolved Hide resolved
message(SEND_ERROR "CUDA mismatch between the VecGeom installation "
"at ${VECGEOM_INSTALL_DIR} (VecGeom_CUDA_FOUND=${VecGeom_CUDA_FOUND}) "
"and Celeritas (CELERITAS_USE_CUDA=${CELERITAS_USE_CUDA})"
Expand Down
2 changes: 2 additions & 0 deletions app/geo-check/geo-check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "corecel/cont/Label.hh"
#include "corecel/cont/Range.hh"
#include "corecel/io/Logger.hh"
#include "corecel/math/ArrayUtils.hh"
#include "corecel/sys/Device.hh"
#include "orange/Types.hh"
#include "celeritas/geo/GeoParamsFwd.hh"
Expand Down Expand Up @@ -57,6 +58,7 @@ void run(std::istream& is, bool use_cuda)
pos[i] = inp.at("track_origin")[i].get<real_type>();
dir[i] = inp.at("track_direction")[i].get<real_type>();
}
normalize_direction(&dir);
GeoTrackInitializer trkinit{pos, dir};

CELER_ASSERT(geo_params);
Expand Down
11 changes: 11 additions & 0 deletions cmake/FindGeant4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ Find the Geant4 HEP library.

#]=======================================================================]

# Save and restore global settings changed by Geant's find script
get_directory_property(_include_dirs INCLUDE_DIRECTORIES)

find_package(Geant4 QUIET CONFIG)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Geant4 CONFIG_MODE)

if(Geant4_FOUND)
# Geant4 calls `include_directories` for CLHEP :( which is not what we want!
# Save and restore include directories around the call -- even though as a
# standalone project Celeritas will never have directory-level includes
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${_include_dirs}")
endif()
unset(_include_dirs)

if(Geant4_FOUND AND Geant4_VERSION VERSION_GREATER_EQUAL 11 AND CELERITAS_USE_CUDA)
foreach(_tgt Geant4::G4global Geant4::G4global-static)
if(TARGET ${_tgt})
Expand Down
12 changes: 9 additions & 3 deletions doc/appendices/license.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ Additional licenses

Small portions of Celeritas are derived from other open source projects.

BVHNavigator
------------
CERN Apache 2.0
---------------

Derived from AdePT_ under the following license::
The following VecGeom-related components are derivative works:

- BVHNavigator: from AdePT_
- GenericSolid, GenericPlacedVolume, GeantGeometryImporter: from VecGeomG4Solid_

with portions distributed under the following license::

Copyright 2020 CERN

Expand All @@ -52,3 +57,4 @@ Derived from AdePT_ under the following license::
limitations under the License.

.. _AdePT: https://github.com/apt-sim/AdePT
.. _VecGeomG4Solid: https://gitlab.cern.ch/VecGeom/g4vecgeomnav/-/raw/ce4a0bb2f777a6728e59dee96c764fd61fa8b785/include/VecGeomG4Solid.h
15 changes: 11 additions & 4 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ if(CELERITAS_RNG STREQUAL "CURAND")
endif()

if(CELERITAS_USE_Geant4)
celeritas_add_object_library(celeritas_geant4
set(_cg4_libs Celeritas::corecel XercesC::XercesC ${Geant4_LIBRARIES})
set(_cg4_sources
ext/LoadGdml.cc
ext/GeantImporter.cc
ext/GeantSetup.cc
Expand All @@ -111,9 +112,15 @@ if(CELERITAS_USE_Geant4)
ext/detail/GeantProcessImporter.cc
ext/detail/GeantVolumeVisitor.cc
)
target_link_libraries(celeritas_geant4
PRIVATE Celeritas::corecel XercesC::XercesC ${Geant4_LIBRARIES}
)
if(CELERITAS_USE_VecGeom)
list(APPEND _cg4_sources
ext/detail/GeantGeometryImporter.cc
)
list(APPEND _cg4_libs VecGeom::vecgeom)
endif()
celeritas_add_object_library(celeritas_geant4 ${_cg4_sources})

target_link_libraries(celeritas_geant4 PRIVATE ${_cg4_libs})
list(APPEND SOURCES $<TARGET_OBJECTS:celeritas_geant4>)
list(APPEND PRIVATE_DEPS celeritas_geant4)
endif()
Expand Down
21 changes: 7 additions & 14 deletions src/celeritas/ext/VecgeomParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "VecgeomData.hh" // IWYU pragma: associated
#include "detail/GeantGeoExporter.hh"
#include "detail/GeantGeometryImporter.hh"

namespace celeritas
{
Expand All @@ -40,7 +41,7 @@ namespace celeritas
*/
VecgeomParams::VecgeomParams(std::string const& filename)
{
CELER_LOG(info) << "Loading VecGeom geometry from GDML at " << filename;
CELER_LOG(status) << "Loading VecGeom geometry from GDML at " << filename;
if (!ends_with(filename, ".gdml"))
{
CELER_LOG(warning) << "Expected '.gdml' extension for GDML input";
Expand All @@ -62,25 +63,17 @@ VecgeomParams::VecgeomParams(std::string const& filename)
//---------------------------------------------------------------------------//
/*!
* Translate a geometry from Geant4.
*
* At present this just exports the geometry to GDML, then loads it through the
* VGDML reader.
*/
VecgeomParams::VecgeomParams(G4VPhysicalVolume const* world)
{
mrguilima marked this conversation as resolved.
Show resolved Hide resolved
CELER_EXPECT(world);

// Convert the geometry to VecGeom
#if CELERITAS_USE_GEANT4
auto filename = detail::GeantGeoExporter::make_tmpfile_name();
CELER_LOG(debug) << "Temporary file for Geant4 export: " << filename;
{
// Export file from Geant4
detail::GeantGeoExporter export_to(world);
export_to(filename);
}
{
// Import file into VecGeom
ScopedTimeAndRedirect time_and_output_("vgdml::Frontend");
vgdml::Frontend::Load(filename, /* validate_xml_schema = */ false);
detail::GeantGeometryImporter convert;
convert(world);
CELER_ASSERT(vecgeom::GeoManager::Instance().GetWorld());
}
#else
CELER_NOT_CONFIGURED("Geant4");
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/ext/VecgeomParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class VecgeomParams
//! Access geometry data on host
inline HostRef const& host_ref() const;

//! Access geometry data on host
//! Access geometry data on device
inline DeviceRef const& device_ref() const;

private:
Expand Down
Loading