Modify geometry in a loop

_Geant4 Version: 11.2
_Operating System: Windows - Ubuntu

Hi! Posting again in the forum.

I am having a concern regarding changing geometry in a loop.

For a Cross Section calculation I obtain a certain ratio and inside my code i want to set that if my ratio is out of my range of 30% - 50% change the width of my material and calculate it again until my ratio is inside tha range.

After this while or for loop i want to save that thickness.

Im trying to implement it in my EndOfRunAction()

´´´
void MyRunAction::EndOfRunAction(const G4Run*)
{
fRun->EndOfRun();

}
´´´
and inside EndOfRun()
´´´
void CrossRun::EndOfRun()
{
ObtainRatio();
While (ratio < 30%)
{
targetWidth += 1 mm;
// My messenger command
UImanager->ApplyCommand("/detector/targetWidth " + std::to_string(thickness));
G4RunManager::GetRunManager()->ReinitializeGeometry();

   // Here is where i dont know what to do
   G4RunManager::GetRunManager()->Initialize(); // ???
   UImanager->ApplyCommand("/run/beamOn 1000");  // ???

   ObtainRatio(); 
}

}
´´´

I have a G4RunManager::GetRunManager()->Initialize() in my main also.

When I execute i obtain the next messages i declared

Actual ratio: 0.034205 over 1.2 mm
Loop Ratio: 0.034205
1.22 mm
/detector/targetWidth 1.220000 mm
Geometry reinitialized
Beam sent
Volume thick: 1.22

And then it stops. I think the code actualy runs /run/beamOn but do not send any particle.

HELP.

We already solved this issue. The solution wasn´t from GEANT itself, intead we used python to create differente mac files and running the .exe of the simulation.

We also were able to automate changes in geometry based on the output from a geant run by processing the root file in python to find the better results based on these changes with just one click to run the python file.

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