diff --git a/include/RMGHardware.hh b/include/RMGHardware.hh index 01ddc406..8328e2f7 100644 --- a/include/RMGHardware.hh +++ b/include/RMGHardware.hh @@ -76,6 +76,7 @@ class RMGHardware : public G4VUserDetectorConstruction { /// List of GDML files to load std::vector fGDMLFiles; bool fGDMLDisableOverlapCheck = false; + int fGDMLOverlapCheckNumPoints = 3000; /// Mapping between physical volume names and maximum (user) step size to apply std::map fPhysVolStepLimits; diff --git a/src/RMGHardware.cc b/src/RMGHardware.cc index 82e7ed29..9aafbab5 100644 --- a/src/RMGHardware.cc +++ b/src/RMGHardware.cc @@ -20,6 +20,7 @@ namespace fs = std::filesystem; #include "G4GDMLParser.hh" #include "G4GenericMessenger.hh" +#include "G4GeomTestVolume.hh" #include "G4LogicalVolume.hh" #include "G4PhysicalVolumeStore.hh" #include "G4SDManager.hh" @@ -43,7 +44,7 @@ G4VPhysicalVolume* RMGHardware::Construct() { if (!fGDMLFiles.empty()) { RMGLog::Out(RMGLog::debug, "Setting up G4GDMLParser"); G4GDMLParser parser; - parser.SetOverlapCheck(!fGDMLDisableOverlapCheck); + parser.SetOverlapCheck(false); // overlap check is performed below. for (const auto& file : fGDMLFiles) { RMGLog::Out(RMGLog::detail, "Reading ", file, " GDML file"); if (!fs::exists(fs::path(file.data()))) RMGLog::Out(RMGLog::fatal, file, " does not exist"); @@ -51,6 +52,14 @@ G4VPhysicalVolume* RMGHardware::Construct() { parser.Read(file, false); } fWorld = parser.GetWorldVolume(); + + // Check for overlaps, but with no verbose output. + if (!fGDMLDisableOverlapCheck) { + RMGLog::Out(RMGLog::summary, "Checking for overlaps in GDML geometry..."); + auto test_vol = + new G4GeomTestVolume(fWorld, 0, fGDMLOverlapCheckNumPoints, /* verbosity = */ false); + test_vol->TestOverlapInTree(); + } } else { fWorld = this->DefineGeometry(); if (!fWorld) @@ -193,6 +202,11 @@ void RMGHardware::DefineCommands() { .SetStates(G4State_PreInit) .SetToBeBroadcasted(false); + fMessenger->DeclareProperty("GDMLOverlapCheckNumPoints", fGDMLOverlapCheckNumPoints) + .SetGuidance("Change the number of points sampled for overlap checks") + .SetStates(G4State_PreInit) + .SetToBeBroadcasted(false); + fMessenger->DeclareMethod("IncludeGDMLFile", &RMGHardware::IncludeGDMLFile) .SetGuidance("Use GDML file for geometry definition") .SetParameterName("filename", false) diff --git a/tests/basics/CMakeLists.txt b/tests/basics/CMakeLists.txt index 15393a8d..d85d924e 100644 --- a/tests/basics/CMakeLists.txt +++ b/tests/basics/CMakeLists.txt @@ -27,3 +27,10 @@ set_tests_properties(${_macros_extra} PROPERTIES LABELS extra) list(TRANSFORM _macros_vis PREPEND "basics/") set_tests_properties(${_macros_vis} PROPERTIES LABELS vis) + +# further specific tests. + +# expect two overlaps from this prepared geometry. +add_test(NAME basics/overlaps.mac COMMAND remage-cli -- macros/overlaps.mac) +set_tests_properties(basics/overlaps.mac PROPERTIES PASS_REGULAR_EXPRESSION + "GeomVol1002.*GeomVol1002") diff --git a/tests/basics/gdml/overlaps.gdml b/tests/basics/gdml/overlaps.gdml new file mode 100644 index 00000000..016563c6 --- /dev/null +++ b/tests/basics/gdml/overlaps.gdml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/basics/macros/overlaps.mac b/tests/basics/macros/overlaps.mac new file mode 100644 index 00000000..da5ba72a --- /dev/null +++ b/tests/basics/macros/overlaps.mac @@ -0,0 +1,2 @@ +/RMG/Geometry/IncludeGDMLFile gdml/overlaps.gdml +/run/initialize