Reinitialize geometry failed with G4OpRayleigh physics on

Hi everyone. I’m working on an optical simulaiton that needs to take optical Rayleigh process into account. I need to change my geometry’s size to see the difference.

To change the geometry conveniently I created my own command and use it in a mac file. The command calls this function:

void DetectorConstruction::SetLightGuideRadius(G4double r)
{
fLightGuideRadius = r;
G4RunManager::GetRunManager()->ReinitializeGeometry();
}

And a part of my optical physics list is this:
fRayleighScatteringProcess = new G4OpRayleigh();
if (particleName == “opticalphoton”)
{
G4cout << " AddDiscreteProcess to OpticalPhoton " << G4endl;
pmanager->AddDiscreteProcess(fAbsorptionProcess);

        pmanager->AddDiscreteProcess(fRayleighScatteringProcess);//This line

        pmanager->AddDiscreteProcess(fMieHGScatteringProcess);
        pmanager->AddDiscreteProcess(fBoundaryProcess);
        pmanager->AddDiscreteProcess(fWLSProcess);
    }

The weird thing is that if I comment that Rayleigh line above the program runs well and the geometry can be reinitialized repeatedly. However if I add that line into the code the program gives segmentation fault. I tested other optical processes and they seem to have no such effect. Only OpRayleigh can cause segmentation fault.

Here is the fault info:
*** Break *** segmentation violation
Generating stack trace…
0x00007f5c62b70cc4 in G4VDiscreteProcess::PostStepGetPhysicalInteractionLength(G4Track const&, double, G4ForceCondition*) + 0xb4 from /mnt/d/geant4.10.06.p02/install/lib/libG4processes.so
0x00007f5c66255140 in G4SteppingManager::DefinePhysicalStepLength() + 0x130 from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5c662535a8 in G4SteppingManager::Stepping() + 0x2b8 from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5c6625eebc in G4TrackingManager::ProcessOneTrack(G4Track*) + 0x11c from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5c6629d2be in G4EventManager::DoProcessing(G4Event*) + 0x48e from /mnt/d/geant4.10.06.p02/install/lib/libG4event.so
0x00007f5c6634d99c in G4WorkerRunManager::DoEventLoop(int, char const*, int) + 0x1cc from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5c66341602 in G4RunManager::BeamOn(int, char const*, int) + 0x62 from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5c6634f2db in G4WorkerRunManager::DoWork() + 0x36b from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5c66358dfe in G4MTRunManagerKernel::StartThread(G4WorkerThread*) + 0x19e from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5c60f06cb4 in from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
0x00007f5c609d6609 in from /usr/lib/x86_64-linux-gnu/libpthread.so.0
0x00007f5c60be2103 in clone + 0x43 from /usr/lib/x86_64-linux-gnu/libc.so.6

So does this mean I can’t reinitialize geometry with OpRayleigh physics on? Why is this one special? I checked the OpRayleigh.cc source code but still don’t understand why it can cause this problem.

I can really use some advice. Thanks a lot!

There’s not expected to be any connection between the Rayleigh process (or any other), and rebuilding the geometry. What happens if you try the included G4OpticalPhysics list rather than using your own (as a test, at least)?

Well that is the weird part.

I have disabled my own optical list and used G4OpticalPhysics list by
RegisterPhysics(new G4OpticalPhysics()), but the result remains exactly the same: the program starts to run and after a reinitialization it stops again.
Here is the segmentation fault:
*** Break *** segmentation violation
Generating stack trace…
0x00007f5ad4ce0cc4 in G4VDiscreteProcess::PostStepGetPhysicalInteractionLength(G4Track const&, double, G4ForceCondition*) + 0xb4 from /mnt/d/geant4.10.06.p02/install/lib/libG4processes.so
0x00007f5ad83c5140 in G4SteppingManager::DefinePhysicalStepLength() + 0x130 from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5ad83c35a8 in G4SteppingManager::Stepping() + 0x2b8 from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5ad83ceebc in G4TrackingManager::ProcessOneTrack(G4Track*) + 0x11c from /mnt/d/geant4.10.06.p02/install/lib/libG4tracking.so
0x00007f5ad840d2be in G4EventManager::DoProcessing(G4Event*) + 0x48e from /mnt/d/geant4.10.06.p02/install/lib/libG4event.so
0x00007f5ad84bd99c in G4WorkerRunManager::DoEventLoop(int, char const*, int) + 0x1cc from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5ad84b1602 in G4RunManager::BeamOn(int, char const*, int) + 0x62 from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5ad84bf2db in G4WorkerRunManager::DoWork() + 0x36b from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5ad84c8dfe in G4MTRunManagerKernel::StartThread(G4WorkerThread*) + 0x19e from /mnt/d/geant4.10.06.p02/install/lib/libG4run.so
0x00007f5ad3076cb4 in from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
0x00007f5ad2b46609 in from /usr/lib/x86_64-linux-gnu/libpthread.so.0
0x00007f5ad2d52103 in clone + 0x43 from /usr/lib/x86_64-linux-gnu/libc.so.6

Actually I checked the G4 source code, and my own optical physics is nearly the same as the G4OpticalPhysics. I too believe that there should not be any connection between Rayleigh physics and reinitializing geometry but this does happened. Maybe you can test it with a simple program? Just enable G4OpticalPhysics and try reinitializing geometry?

Thanks a lot!

I read the G4OpRayleigh.cc more carefully this time. Seems like if I didn’t assign a RAYLEIGH property to a material with a material properties table G4 assign water’s Rayleigh property to this material. Could this cause the problem? I think it should be something to do with its PhysicsTable.

Reinitializing the geometry works with LXe example, and this macro:

/run/verbose 1
/run/numberOfThreads 1
/control/verbose 1
/tracking/verbose 0
/process/optical/verbose 1
/LXe/detector/MainScintYield 10000
#/process/optical/processActivation Cerenkov false

/run/initialize

/gun/particle gamma
/gun/energy 511 keV

/run/printProgress 10

/vis/disable
/run/beamOn 10

/LXe/detector/pmtRadius 1.15 cm
/run/beamOn 10

Thanks for trying!
I have solved this problem. I think the reason for this problem is the function I called in Construct(), which contains this line:
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
After I deleted this function in Construct() it all worked out. Though I still don’t quite understand why this line only contradict with Rayleigh process. But I guess it doesn’t matter for the result.
Thanks a lot!

Hello,

the best advice : do not reinitialized geometry, especially in the MT mode. Using UI command define geometry before “/run/initialise”. We removed re-initialization from many EM examples already.

VI

Thanks for the tip!
I’m simulating the effect of the geometry on the system’s performance, and that’s why I want to reinitialize geometry in a mac file. This way I don’t have to change mac file manually each time. But I guess using shell commands will also do the job. Thanks!