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.

Dears,I have the same idea,but I don’t know how to realize it.So do you have some improvements on this issue? I want to have a deep communication with you. Thank you anvace.

In general, please do not resurrect old threads like this - it is better and cleaner to start a fresh one, cross-referencing back to this one if needed.

The solution is as already posted above by @Anna.