How can create a run loop?

Dear all,
I want to create a run loop via hard code because I want to change the geometry between two runs.
Can anyone help me, please? or give me an example.

Thank you in advance.

1 Like

you could also write your “detectorGeometryChangeMessenger” with an appropriate command, and do the loop via macro. What is the benefit of having the loop hardcoded?

otherwise:

auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::MT)
...
runManager->Initialize();

G4int N = 100;
for(G4int i = 0; i<10; i++) {
  /// do some stuff
  // ...
  runManager->BeamOn(N);
}

Thanks @weller,
My purpose is to change the geometry, for example, by rotating a volume.
I don’t want to use a run loop in a macro file because I think it isn’t flexible.

I found an instruction to change the detector geometry in the manual. But I want to create a new class to manage the run loop and change geometry. Is it a good way to perform?

macro would be more flexibel in my opinion, as you don’t need to recompile to change configurations (e.g., number of steps per revolution for the rotation).

you just place the code to open, alter and close the geometry into a function that is then called via messenger command (check out the examples, I think I learned how to do that from there) and then construct the loop (rotate, bramOn, repeat) in a macro - done!