How can I make Geant abort the simulation when there is an overlap of volumes (G4Exception)?

Hi there,

I have MC simulation batches that run for hours or days, although there are warnings like the following at the very beginning when constructing the geometry:

Checking overlaps for volume Tankwall:0 (G4Tubs) ... 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomVol1002
      issued by : G4PVPlacement::CheckOverlaps()
Overlap with volume already placed !
          Overlap is detected for volume Tankwall:0 (G4Tubs) with Detector0:100000 (G4Tubs)
          overlap at local point (-86.2826,-53.5501,-57.493) by 450.487 um  (max of 1 cases)
NOTE: Reached maximum fixed number -1- of overlaps reports for this volume !
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Why does Geant consider these exceptions as mere warnings and continue with the simulation?

I want Geant to actually throw that exception, so that I can catch it and abort the simulation, instead of wasting hours of simulation time on a non-sense geometry.

How can I achieve that?

Dear Joerg,

I suggest you to check geometry overlapping when you place the geometry in ‘DetectionConstruction.cc’.

For example,

#include “G4RunManager.hh”

G4RunManager* runManager = G4RunManager::GetRunManager();
G4VPhysicalVolume*
pGeo = new G4PVPlacement(0, //no rotation
G4ThreeVector(0.,0.,0.), //at (0,0,0)
fLogical, //logical volume
“World”, //name
0, //mother volume
false, //no boolean operation
0);

if(pGeo->CheckOverlaps()==True) runManager-> AbortRun();

I think there may have error but you can fix it!

Best regards,
Jaeyoung Jeong

Thank you.
Would G4PVPlacement::CheckOverlaps() also generate the console output?

Is there a way to actually make Geant THROW the G4Exception? That would be easier for our setup, since the Exception would contain the detailed error message about what went wrong in the geometry.

Also your suggestion means that the overlap has to be computed twice. Once internally by Geant and once by me manually. This seems to be unnecessary overhead.

How about write a new “G4PVPlacement.cc”?

In G4PVPlacement::CheckOverlaps() function, it calls G4Exception class like below.

G4Exception(“G4PVPlacement::CheckOverlaps()”, “GeomVol1002”, JustWarning, message);

Then, you can write exact same G4PVPlacement.cc but with a different level of severity in the above code line.

G4Exception(“G4PVPlacement::CheckOverlaps()”, “GeomVol1002”, RunMustBeAborted, message);

G4PVPlacement::CheckOverlaps() is the method which will be in invoked by the G4PVPlacement contructor if the overlap check is requested. You can switch off the overlap check by setting the last parameter in the G4PVPlacement constructor equal to false (btw, pSurfChk = false is the default).

The overlap check, in case if it is requested, is done at the initialisation time, when the geometry model is constructed. It is assumed that the overlap check is used for checking geometry correctness. If you are happy with the geometry, then you can switch it off.

BTW, in your case the overlap is very tiny, and very probably will not affect the result of simulation.