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

Use custom overlap check instead of the one from G4GDML #83

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions include/RMGHardware.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class RMGHardware : public G4VUserDetectorConstruction {
/// List of GDML files to load
std::vector<std::string> fGDMLFiles;
bool fGDMLDisableOverlapCheck = false;
int fGDMLOverlapCheckNumPoints = 3000;
/// Mapping between physical volume names and maximum (user) step size to apply
std::map<std::string, double> fPhysVolStepLimits;

Expand Down
16 changes: 15 additions & 1 deletion src/RMGHardware.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -43,14 +44,22 @@ 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");
// TODO: decide here
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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
32 changes: 32 additions & 0 deletions tests/basics/gdml/overlaps.gdml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">
<define/>
<materials/>
<solids>
<box name="World" x="10" y="10" z="10" lunit="m"/>
<box name="Box" x="1" y="1" z="1" lunit="m"/>
</solids>
<structure>
<volume name="Box">
<materialref ref="G4_Pb"/>
<solidref ref="Box"/>
</volume>
<volume name="World">
<materialref ref="G4_Pb"/>
<solidref ref="World"/>
<physvol name="Box1">
<volumeref ref="Box"/>
<position name="Box_pos" x="0" y="0" z="0" unit="m"/>
<rotation name="Box_rot" x="0" y="0" z="0" unit="rad"/>
</physvol>
<physvol name="Box2">
<volumeref ref="Box"/>
<position name="Box_pos" x="0" y="0.5" z="0" unit="m"/>
<rotation name="Box_rot" x="0" y="0" z="0" unit="rad"/>
</physvol>
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="World"/>
</setup>
</gdml>
2 changes: 2 additions & 0 deletions tests/basics/macros/overlaps.mac
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/RMG/Geometry/IncludeGDMLFile gdml/overlaps.gdml
/run/initialize