New materials when the geometry is reinitialized

Hello,

I have a problem with the definition of new materials when the geometry is reinitialized.

I create a geometry, initialize it and run my simulation correctly.
After that, I would like to change the geometry and so I call the ReinitializeGeometry method of the master RunManager and then /run/initialize, and the geometry is correctly rebuilt.

Here are the problems:

  • The code that defines the new geometry also defines some materials and they are recreated together with the geometry and G4 tells me (rightly) that these materials have already been defined (I know that the definition of the materials should be separated but I would like to take this situation into account in my application).
  • Another situation is that I would like to recreate the materials because I would like to change some parameters, but maintain the same names.

The question: is there a way to “reset” (all) the materials registered in Geant4 in order to be able to recreate them without resulting in duplicates?

Note: I tried G4Material::GetMaterialTable()->clear() before constructing the geometry and this remove the warning about the creation of material duplicates but when the run is started, in the production cut table the “old” materials are still present.

A couple of a bit off-topic questions:

  • After the reinitialization of the geometry, is it correct that is necessary to rerun the commands relative to the visualization of trajectories in Qt?
  • After the first call to the ReinitializeGeometry method, the volumes disappear in the GUI (Qt) and, after the /run/initialize, I have to rerun /vis/drawVolume command to make them visible, but the second time I call the ReinitializeGeometry method, the original volume remains, and when I run the /run/initialize command the geometry appear automatically. Can you explain this behavior? Is it correct or am I doing something wrong?

Thank al lot
Andrea

3 Likes

Dear all,

does anyone have any advice on this problem?

Thanks a lot
Andrea

Dear Andrea,

Did you find a solution to your problem ?

I am facing the same situation.

Best regards,
Fahad

Dear Fahad,

Unfortunately, at the moment I haven’t found a solution to this problem.
If you recreate a material with the same name, G4 uses the last one, so the simulation runs correctly. However, it is still quite annoying because there is a material duplicate, memory leakage, and so on.

It should be fine if you don’t need to redefine the same material many times.

Best,
Andrea

2 Likes