diff --git a/include/RMGVertexConfinement.hh b/include/RMGVertexConfinement.hh index 5a22e4d7..6166affc 100644 --- a/include/RMGVertexConfinement.hh +++ b/include/RMGVertexConfinement.hh @@ -154,6 +154,7 @@ class RMGVertexConfinement : public RMGVVertexGenerator { SamplingMode fSamplingMode = kUnionAll; bool fOnSurface = false; + bool fForceContainmentCheck = false; // counters used for the current run. long fTrials = 0; diff --git a/src/RMGVertexConfinement.cc b/src/RMGVertexConfinement.cc index 1563f22b..ab61acf4 100644 --- a/src/RMGVertexConfinement.cc +++ b/src/RMGVertexConfinement.cc @@ -388,6 +388,7 @@ void RMGVertexConfinement::Reset() { fGeomVolumeSolids.clear(); fSamplingMode = RMGVertexConfinement::kUnionAll; fOnSurface = false; + fForceContainmentCheck = false; } bool RMGVertexConfinement::GenerateVertex(G4ThreeVector& vertex) { @@ -459,6 +460,14 @@ bool RMGVertexConfinement::ActualGenerateVertex(G4ThreeVector& vertex) { } else { vertex = choice.translation + choice.rotation * RMGGeneratorUtil::rand(choice.sampling_solid, fOnSurface); + if (fForceContainmentCheck) { + auto is_inside = physical_first ? fPhysicalVolumes.IsInside(vertex) + : fGeomVolumeSolids.IsInside(vertex); + if (!is_inside) + RMGLog::OutDev(RMGLog::error, + "Generated vertex not inside sampling volumes (forced containment check): ", + vertex / CLHEP::cm, " cm"); + } } // is it also in the other volume class (geometrical/physical)? @@ -531,6 +540,11 @@ bool RMGVertexConfinement::ActualGenerateVertex(G4ThreeVector& vertex) { vertex = choice.translation + choice.rotation * RMGGeneratorUtil::rand(choice.sampling_solid, fOnSurface); RMGLog::OutDev(RMGLog::debug, "Generated vertex: ", vertex / CLHEP::cm, " cm"); + if (fForceContainmentCheck && !all_volumes.IsInside(vertex)) { + RMGLog::OutDev(RMGLog::error, + "Generated vertex not inside sampling volumes (forced containment check): ", + vertex / CLHEP::cm, " cm"); + } } RMGLog::OutDev(RMGLog::debug, "Found good vertex ", vertex / CLHEP::cm, " cm", " after ", @@ -647,6 +661,15 @@ void RMGVertexConfinement::DefineCommands() { .SetStates(G4State_PreInit, G4State_Idle) .SetToBeBroadcasted(true); + fMessengers.back() + ->DeclareProperty("ForceContainmentCheck", fForceContainmentCheck) + .SetGuidance("If true (or omitted argument), perform a containment check even after sampling " + "from a natively sampleable object. This is only an extra sanity check that does" + "not alter the behaviour.") + .SetParameterName("flag", true) + .SetStates(G4State_PreInit, G4State_Idle) + .SetToBeBroadcasted(false); + fMessengers.push_back( std::make_unique(this, "/RMG/Generator/Confinement/Physical/", "Commands for setting physical volumes up for primary confinement")); diff --git a/tests/confinement/macros/complex-volume.mac b/tests/confinement/macros/complex-volume.mac index e82581bb..13576b2d 100644 --- a/tests/confinement/macros/complex-volume.mac +++ b/tests/confinement/macros/complex-volume.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true /RMG/Generator/Confinement/Physical/AddVolume BoxWithHole /RMG/Generator/Confinement/Physical/AddVolume BoxAndOrb diff --git a/tests/confinement/macros/geometrical-and-physical.mac b/tests/confinement/macros/geometrical-and-physical.mac index d045936d..81d93b1b 100644 --- a/tests/confinement/macros/geometrical-and-physical.mac +++ b/tests/confinement/macros/geometrical-and-physical.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true /RMG/Generator/Confinement/SamplingMode IntersectPhysicalWithGeometrical diff --git a/tests/confinement/macros/geometrical-or-physical.mac b/tests/confinement/macros/geometrical-or-physical.mac index 565f7f58..66b4c088 100644 --- a/tests/confinement/macros/geometrical-or-physical.mac +++ b/tests/confinement/macros/geometrical-or-physical.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true # /RMG/Generator/Confinement/SampleOnSurface diff --git a/tests/confinement/macros/geometrical.mac b/tests/confinement/macros/geometrical.mac index 4ea13589..291d3bc1 100644 --- a/tests/confinement/macros/geometrical.mac +++ b/tests/confinement/macros/geometrical.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true # /RMG/Generator/Confinement/SampleOnSurface diff --git a/tests/confinement/macros/native-surface.mac b/tests/confinement/macros/native-surface.mac index fba0f4d0..152a21b3 100644 --- a/tests/confinement/macros/native-surface.mac +++ b/tests/confinement/macros/native-surface.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true /RMG/Generator/Confinement/SampleOnSurface true /RMG/Generator/Confinement/Physical/AddVolume Box /RMG/Generator/Confinement/Physical/AddVolume Orb diff --git a/tests/confinement/macros/native-volume.mac b/tests/confinement/macros/native-volume.mac index 55ca366d..0cce9b7e 100644 --- a/tests/confinement/macros/native-volume.mac +++ b/tests/confinement/macros/native-volume.mac @@ -1,6 +1,7 @@ /control/execute macros/init.mac /RMG/Generator/Confine Volume +/RMG/Generator/Confinement/ForceContainmentCheck true /RMG/Generator/Confinement/Physical/AddVolume Box /RMG/Generator/Confinement/Physical/AddVolume Orb /RMG/Generator/Confinement/Physical/AddVolume Sphere