I want to run multiple simulations by changing the detector position along xyz coordinates for each simulation. I searched online and came across a post here Can geant4 define a moving detector? that uses G4GeometryManager.
Can someone please explain how the detector is called within the macro and how the coordinates are specified in the macro?
I will also be happy to know if there is a more efficient way to achieve this.
You would need to write your own messenger class (or use G4GenericMessenger) to define your own macro commands that set parameters in your geometry builder. You would need, in the messenger code, to ensure that when you change those parameters, you also set the “geometry has changed” flag so that the RunManager will rebuild the new geometry.
I did try to implement the G4GenericMessenger as you suggested. However, I came across an error which I am struggling to solve. Below is a screenshot of the error and a part my my detector construction where its implemented. Any further advise will be appreciated.
I am following B5 example to use G4GenericMessenger. Attached is a portion of my Detector Construction that tries to mimic the class. Please correct me if am wrong, line 198 checks if cryst_phys is created and then proceed to modify the geometry. Otherwise print the message “Detector has not yet been constructed.” Is that correct?
When I run my simulation, I get the message “Detector has not yet been constructed.” printed, so am assuming the code those not proceed beyond this stage. However, if I change thetaAngle from my macro using /nvisage/detector/thetaAngle it’s recognized.
I also attempted to ReinitialGeometry() after the BeginOfRunAction() as described in the UserGuide, but that also didn’t prevent the message from been printed.
Could you please look at the screenshot and advise what you think is wrong with my code?
correct. return makes the programm exit this function immediately.
Is there maybe a /run/initialize issued in between?
The message is assumingly printed because you try to alter the detector somewhere in macros that are run during program start!? After you make a (first) run, the message does not appear ever again during this session, only when you (re)start the simulation, correct?