Skip to content

Commit

Permalink
confinement: add flag for checking containment for natively sampleabl…
Browse files Browse the repository at this point in the history
…e object (for tests)
  • Loading branch information
ManuelHu committed Apr 26, 2024
1 parent d1c3ad2 commit 8c5ca3f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/RMGVertexConfinement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions src/RMGVertexConfinement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ void RMGVertexConfinement::Reset() {
fGeomVolumeSolids.clear();
fSamplingMode = RMGVertexConfinement::kUnionAll;
fOnSurface = false;
fForceContainmentCheck = false;
}

bool RMGVertexConfinement::GenerateVertex(G4ThreeVector& vertex) {
Expand Down Expand Up @@ -460,6 +461,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)?
Expand Down Expand Up @@ -532,6 +541,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 ",
Expand Down Expand Up @@ -648,6 +662,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<G4GenericMessenger>(this, "/RMG/Generator/Confinement/Physical/",
"Commands for setting physical volumes up for primary confinement"));
Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/complex-volume.mac
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/geometrical-and-physical.mac
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/control/execute macros/init.mac

/RMG/Generator/Confine Volume
/RMG/Generator/Confinement/ForceContainmentCheck true

/RMG/Generator/Confinement/SamplingMode IntersectPhysicalWithGeometrical

Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/geometrical-or-physical.mac
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/control/execute macros/init.mac

/RMG/Generator/Confine Volume
/RMG/Generator/Confinement/ForceContainmentCheck true

# /RMG/Generator/Confinement/SampleOnSurface

Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/geometrical.mac
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/control/execute macros/init.mac

/RMG/Generator/Confine Volume
/RMG/Generator/Confinement/ForceContainmentCheck true

# /RMG/Generator/Confinement/SampleOnSurface

Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/native-surface.mac
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/confinement/macros/native-volume.mac
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8c5ca3f

Please sign in to comment.