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

Hi. I know it’s too late but for the next ones.

Add these lines in the Geometry::Construct() function at the beginning :
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();

Add /run/reinitializeGeometry to your macro.

It will work perfectly in batch mode and you will have some warning about Qt in visualization mode due to the fact that after the cleaning, the visualization has no volumes to point. But all become OK after the recreation of your geometry with the values.

Hope it will helps some people :slight_smile:

Hello ahuber33,

Unfortunatly this does not solve the issue.
The command you wrote are used when you want to reinitialize the geometry but my problem was about the redefinition of the materials when the geometry is reinitialized.

Moreover, it is not necessary to include these commands in the detector construction because they are automatically called when the RunManager::ReinitializeGeometry() method or the equivalent ui command /run/reinitializeGeometry are called.

Andrea

1 Like