Advices on improving simulation efficiency


I want to study how much energy is deposited in three detectors which are placed in certain positions. I don’t want them to influence each other so I’m thinking about the most convenient way to move on with the simulation:

  • Shift them and place particle sources for each one
  • Shift them but move all of them via z through the beams of the particle sources
  • Remove two detectors and run each simulation independently from them
  • …?

This. With a nice command line parameter to pick which detector to use :slight_smile:

1 Like

Thanks for your input!

Where would I put such a line? :smiley:
Can I remove an object in the run.mac file or so?

there are examples with a basic command line parameter: geant4/ at v11.1.0 · Geant4/geant4 · GitHub

or be inspired

int main(int argc,char** argv) {

    G4String macro;
    G4int detectorID = 0;

    for ( G4int i=1; i<argc; i=i+2 ) {
        if      (G4String(argv[i]) == "-m" ) macro = argv[i+1];
        else if (G4String(argv[i]) == "-d" ) detectorID = G4UIcommand::ConvertToInt(argv[i+1]);
        else {
            return 1;

and run like so: epicSimulation -m run.mac -d 0



I’m receiving error C2064: term does not evaluate to a function taking 1 arguments?

I’m trying to use it like this:

G4int detectorID = 0;
if(argc > 1)
detectorID = G4UIcommand::ConvertToInt(argv[2])
G4cout << Detector cmd:  << detectorID << G4endl;

which is quite the same as:

auto runManager = G4RunManagerFactory::CreateRunManager();
if (argc==3) {
G4int nThreads = G4UIcommand::ConvertToInt(argv[2]);


it’s not the same, in the first there is a ; missing

1 Like

Omg, with the ; it’s working now…
Thank you!

How do I parse an argument argv to the respectively where the geometry is built up?
Is there an example somewhere?

I just added a class member to my G4VUserDetectorConstruction, and set the value when calling auto detector = new DetectorConstruction(myParameter);

a more elaborate example is

1 Like

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