Select which of a number of geometries are build using .mac commands

Is it possible to build a user chosen geometry by issuing macro file commands. For example:

/example/chooseDetector <detectorType>

which will then (via a messenger class) build the specified geometry in a DetectorConstruction.cc type file?

I am not able to pass arguments into the G4VUserDetectorConstruction* Construct() method and trigger conditional statements in the DetectorConstruction.cc file such as:

if (G4String& detectorChoice == <detectorType>){
  
   "Build detector of choice"
 
}

Also, it would be great if the user defined detectorType would be build in a constant phantom size, such that it would be simple to switch geometries from the macro file whilst retaining the same environment.

Any help would be great!

Thanks.

I think (but am not certain) that the world is built before the macro is read. Two options for a user-specified geometry are

  1. Use a dynamic geometry as described here:
    https://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/ForApplicationDeveloper/html/Detector/Geometry/geomDynamic.html#dynamic-geometry-setups
    together with messenger commands.
  2. Set the geometry before before building the world. For example as a command line argument. In main, have something like:
    if (argv[1] == ‘A’) { detector = new MyDetectorConstruction_A();}
    else …