Error with ToolsSG function : GetOrCreateNode

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: 11.2.1
Operating System: Ubuntu

I have developed a DetectorMessenger, and initially, everything is OK. However, upon running the program in interactive mode, I encountered an issue after modifying the source parameters through the command line. Specifically, after entering the command “/run/reinitializeGeometry” and pressing the play button, a critical error occurred.

It appears that this problem is unique to the newer version of the software, as indicated by the following error message:

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : ToolsSG-0000
      issued by : G4ToolsSGSceneHandler::GetOrCreateNode
World mis-match - not possible(!?)
*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------

Just moving to the Vis category as it looks to originate from code in that area, so may get a better response here!

Typically that would happen if you had changed your geometry and failed to inform the run manager. Or if you changed the world volume. If you think you have correctly changed your geometry, please get back to us.

Perhaps you can be a little more specific about “modifying the source parameters through the command line”. How, exactly, did you do that? If you change geometry, there is a sequence of calls that need to be made. Have a look at Dynamic Geometry Setups — Book For Application Developers 11.2 documentation.

Hi Allison,

I made changes to my geometry following a tutorial video, and I suspect that the version of Geant4 may play an important role here.

Actually, I haven’t realized the problem that requires me to make a sequence of calls to Runmanager. Could you demonstrate how to incorporate these calls into my code? (2.4 KB)

Not my area of expertise, but see Dynamic Geometry Setups — Book For Application Developers 11.2 documentation.

However, if the problem persists, I will look at the G4ToolsSGSceneHandler code. Does it happen with other vis drivers? What drivers are registered (look at the top of Geant4 output)? Perhaps you could try with Qt3D (/vis/open Qt3D).

I’ve been read the documentation, but I’m feeling no idea when it comes to debugging. Additionally, I’m encountering an issue where visualization only seems to work when I run with “/vis/open” in vis.mac, and not when I use “/vis/open Qt3D”. I’ve been testing the DetectorMessenger in the B2a example, and here’s what I’ve tried so far. Could you please review my steps and see if there’s anything I might be missing?

  1. First, I build the program using the provided build file.
  2. Then, I run the program with “./exampleB2a”. Since I’m in interactive mode, it automatically executes the command line “/control/execute init_vis.mac”.
  3. Next, I execute the command line “/B2/det/setTargetMaterial G4_AIR”, and the terminal confirms with " ----> The target is made of G4_AIR".
  4. After that, I execute the command line “/run/reinitializeGeometry”, and the terminal responds with “/vis/scene/notifyHandlers scene-0”.
  5. Now, regardless of whether I use the command line “/run/beamOn 1” or press the play button, it pops up an Error window with the following message:
-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : GeomMgt0003
      issued by : G4GeometryManager::SetMaximumExtent()
Extent can be set only BEFORE creating any geometry object!
*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------

I’m encountering several issues with the DetectorMessenger class. Could you please help me understand the critical steps necessary for its use?

Your assistance would be greatly appreciated.

Hi FruitGG

Thankyou for spelling out what you did. That means I could easily try it and test.

Yes, it runs fine with /run/beamOn.

OK. But why do you want to do that? It should all be dealt with. examples/basic/B2/README doesn’t ask you to do this.

Yes, I get the same. I don’t know why it does that. But I can setTargetMaterial, /run/beamOn, setTargetMaterial again with something different, and /run/beamOn again.

This example allows you to set some things, but they are relatively “harmless” as far as geometry is concerned. If you try to change a dimension or position of a volume, that’s a different proposition. The you initialise a run, it optimises the geometry, and if you change a dimension you need to re-optimise. As I said, that’s not my area of expertise, but there is a way of doing that.

But may I ask your use case? Why do want to change geometry/material at run time? If you do, do it before initialising the run (I think it’s called “PreInit”), and do it only once.

Hope that helps.


I forgot to say, /vis/open Qt3D will only work if you have built with Qt.

Hi John,

I aim to change the position or size of a volume using DetectorMessenger in my case. I want to write a basic code for myself, which other programs could be developed from. So, I want the code to be simple and convenient enough to account for some variances. Additionally, I need this code to demonstrate the features of Monte Carlo simulation to my membership, so I could run it in interactive mode and easily change the properties of the source or target.

By the way, I found that adding some code to clean up old geometry in the Construct function doesn’t pop up the Error window, but the source also disappears. Was my code modification correct as follows? How can I make it display according to my intention?

G4VPhysicalVolume* DetectorConstruction::Construct()
  // Cleanup old geometry

  // Get nist material manager
  G4NistManager* nist = G4NistManager::Instance();

  // Option to switch on/off checking of volumes overlaps
  G4bool checkOverlaps = true;

  // World 100 * 100 cm
  G4Material* world_mat = nist->FindOrBuildMaterial("G4_AIR");

  auto solidWorld = new G4Box("World",                           // its name
    0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ);  // its size

  auto logicWorld = new G4LogicalVolume(solidWorld,  // its solid
    world_mat,                                       // its material
    "World");                                        // its name

  auto physWorld = new G4PVPlacement(nullptr,  // no rotation
    G4ThreeVector(),                           // at (0,0,0)
    logicWorld,                                // its logical volume
    "World",                                   // its name
    nullptr,                                   // its mother  volume
    false,                                     // no boolean operation
    0,                                         // copy number
    checkOverlaps);                            // overlaps checking

  G4Material* Source_mat = nist->FindOrBuildMaterial("G4_WATER");
  auto solidSphere = new G4Sphere("Source", 0, fSourceRadius, 0, 360 * degree, 0, 180 * degree);
  auto logicSphere = new G4LogicalVolume(solidSphere, Source_mat, "Source");
  new G4PVPlacement(nullptr, fSourcePos, logicSphere, "Source", logicWorld, false, 0);

  // Visualization attributes
  G4VisAttributes* Source_VisAtt = new G4VisAttributes(G4Colour(0.5,0.5,0.5));

  return physWorld;

Hi FruitGG

Yes, I think that is the right approach. I have discovered this Forum thread: New materials when the geometry is reinitialized - #6 by Andrea. Just add those 4 lines to your DetectorConstruction, and when you change something in the geometry, /run/reinitializeGeometry and all should be well.

I’m sorry this has taken us a little while to sort out. I hope it works for you and your membership.


1 Like

After /run/reinitializeGeometry , ‘/vis/drawVolume’ also need to be add :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.