Automated Runs with a Script

Dear experts and users,

I am working on a multilevel optimization problem and I am curious if there is a way to automate the runs by writing a script and integrating it into the files, in my case DetectorConstruction class. What I would like to do is to make that script communicate with the DetectorConstruction class to modify the detector size with an algorithm.
If there is an example related to this, I would like to have a look at it.

I tried to find a similar topic but I didn’t see anything related.

Any help is appreciated.

Thanks,
Faruk

To control the G4 application there is a set of UI commands that you can pass (more info in the user guide).
What you need is to define your own commands (by implementing a G4UImessenger class) that will set whatever you need to change in your detector in order to optimise it. Have a look how it is done in basic/B2 example (B2aDetectorMessenger and B2aDetectorConstruction). There are also more examples of UI messenger, e.g. extended/electromagnetic/TestEm2.