Segmentation fault after changing Material of a volume back to the first defined material for this volume

Hi all,

I work with Geant4 for more than 18 years and I have written codes very similar to the one described below.
But this time I have a very strange problem that I can not understand.
I don’t know if it is related to the Material, MaterialTable or to the Physics.

I have a very simple setup.
It is an empty World (3 x 3 x 3 m) at the beginning with a source of particles at the center (0,0,0).
I put one plate with dimensions of (x=100, y=100, z=5) mm at (0,0,z=5) cm to absorb the radiation.
I used gammas of 1 MeV for the tests, but with electrons there is the same problem.

This plate has some initial Material (for example G4_Al) for the first run.
It runs without problem (I have tried up to 10^7 events).

THE PROBLEM:
I have a method to change the material of this plate.
I tried to change to several materials of the NIST table using the FindOrBuild method.
The program RUNS WITHOUT PROBLEMS UNTIL I CHANGE IT BACK TO THE INITIAL MATERIAL.
I have tried to change a lot of materials in sequece, for example from G4_Al to
G4_WATER, G4_Fe, G4_Pb, G4_Ti, back to G4_WATER, back to G4_Fe, then G4_Cd, G4_Si, etc.
The problem appears only when I change back to the initial material G4_Al.
It gives me a segmentation fault.

I have tried to put other materials as the initial material, like G4_Cu.
Then I have changed to other materials as before, including G4_Al. It runs without problem, even with G4_Al.
When I put back to the initial material G4_Cu, segmentation fault again.

I am using Geat4.10.06.p02.
Physics list: the same as “Hadrontherapy_1” from Hadrontherapy example. Among other models it uses the electromagnetic model standard_opt4.
I have tried to use the EM Option3, but the same problem appears.

Each time that I change the material I use
G4RunManager::GetRunManager()->ReinitializeGeometry();
and my Construct() method deletes and rebuilds all the geometry again.
I think this is not the problem because it works fine until I put the initial material back.

The following lines show the output using /tracking/verbose 2 until the segmentation fault, after changing the Material back to the initial Material.
“placa1” is the volume that has the different materials.
“Falha de segmentação” is “Segmentation fault” in portuguese.

Run 13 starts.


  • G4Track Information: Particle = gamma, Track ID = 1, Parent ID = 0

Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName
0 -16.3 -9.66 0 1 0 0 0 mundo initStep
1 -16.3 -9.66 85 1 0 85 85 placa1 Transportation
2 -16.3 -9.66 92 0.814 2.03e-05 7.01 92 placa1 compt
:----- List of 2ndaries - #SpawnInStep= 2(Rest= 0,Along= 0,Post= 2), #SpawnTotal= 2 ---------------
: -16.3 -9.66 92 0.186 e-
: -16.3 -9.66 92 6.09e-05 e-
:----------------------------------------------------------------- EndOf2ndaries Info ---------------
3 -8.76 -20.1 115 0.814 0 26.3 118 mundo Transportation
4 447 -647 1.5e+03 0.814 0 1.59e+03 1.71e+03 OutOfWorld Transportation


  • G4Track Information: Particle = e-, Track ID = 3, Parent ID = 1

Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName
0 -16.3 -9.66 92 6.09e-05 0 0 0 placa1 initStep
Falha de segmentação

When the particle is an 1 MeV e-

Run 15 starts.


  • G4Track Information: Particle = e-, Track ID = 1, Parent ID = 0

Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName
0 -6.68 -13.7 0 1 0 0 0 mundo initStep
1 -6.71 -13.4 97.2 0.984 0.0165 97.5 97.5 mundo msc
2 -6.72 -13.4 97.5 0.984 0 0.352 97.9 placa1 Transportation
Falha de segmentação

It would be nice if someone could help me.

Mauricio Moarlles

1 Like

I repeated your exercise with TestEm1. Macro and output in attachment. I do not see any anomaly.
moralles.mac.txt (426 Bytes)
moralles.out.txt (7.1 KB)

I have the same problem with code I have written: segmentation fault when I switch back to the original material. I’m using Geant4.10.06.p02.

On my machine, I do not have 10.06.p02 installed.
Can you run TestEm1 with the macro above and tell me the result ?

Hi. TestEm1 works OK with the macro you provided (see my attached log).

output.txt (36.2 KB)

Dear Michel,

After some time I tried to reproduce my problem using the TestEm1 example and finally I got it.
But it is a mistery to me. I describe it below in four runs:

Description:

  1. I used the version 10.06.p02 with your mac file: moralles.mac.txt
    RESULT: OK, no errors.
  2. I changed from emstandard_opt0 to emstandard_opt4.
    RESULT: OK, no errors.

After this I have changed the SetMaterial method to reproduce the way I do it in my code:

I have commented
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
and I have included
G4RunManager::GetRunManager()->ReinitializeGeometry();

So, the Construct() will be called again after material changes.

  1. I used your mac file: moralles.mac.txt
    RESULT: OK, no errors.
  2. I changed from emstandard_opt0 to emstandard_opt4.
    RESULT: SEGMENTAION FAULT when the material come back to G4_Al.

So, there is a combination to produce the error:
G4RunManager::GetRunManager()->ReinitializeGeometry();
with
emstandard_opt4
with
material change.

I hope someone can explain what what happens in this case.

Thank you.
moralles_opt4_Reinitialize.out.txt (33.8 KB) moralles_opt4.mac.txt (426 Bytes) DetectorConstruction.cc (9.9 KB)

Maybe, you can open a bug report. Thanks, Michel

Hi mmoralles,

Did you file this as an official bug with Geant4?

Thanks,

David

Hi David,

No I did not reported this bug officialy.

Best regards,

Mauricio

I have made an official bug report for this:

It is the first time I have raised a bug report, so I hope I have done it correctly.

Hi,

For me, inserting the line

G4RunManager::GetRunManager()->PhysicsHasBeenModified();

before

G4RunManager::GetRunManager()->ReinitializeGeometry();

seems to solve my problem. Does it help for you?

Kind regards,

David

¨Hello,

yes, ```
G4RunManager::GetRunManager()->PhysicsHasBeenModified();


VI