Change E/B field value inside interactive visualization

Dear Community,

I am new to Geant4.
I have managed to compile basic examples and get a flavour of the code.
I have tried to modify example field04 to create parallel E and B fields (superimposed and pointing onto the same direction), for the extent of one logical volume. That’s my aim and this is why I use geant4, to track charged particles in parallel E and B fields.

After the modifications to field04, I can visualize the fields as arrows pointing onto the expected direction with /vis/scene/add/magneticField or /vis/scene/add/electricField.

Problem:
I do not understand how to change the values of the fields “live” (on-air). I am missing understanding of how a messenger with commands (created by the user inside the .cpp source code) interacts with Geant4. If I set a new value of E-field and I do /run/beamOn 1 or any number, it seems that there’s no difference between 1 V/m and 10e15 V/m (I chose these 2 extremes to clarify that the computer doesn’t recognize the changes in real time).
Similarly for the B-field, the trajectory of the particles are the same when changing live the value of the B-field (from 0.0001 Tesla to 1000 Tesla).
I have strictly followed what was written in field04 example for the setter commands and the functions which actually set the new value.

I can change the value of the field in the source code and all behaves accordingly after I re-compile and re-run the executable, the trajectories do change relative to what I had before.

Is there any way to see the trajectories of the particles changing after I changed the E/B-field values inside the messenger?

I believe some sort of update command has to be issued to Geant4, to make it aware that the fields changed.

Inside the README of field04 example, I can see: "Before /run/initialize in the macro file or command, the update field command must have been issued if any of the other following field commands was employed:
/field/update
"
But there’s no /field/update command inside the interactive visualization. Running $/field/update (even if the tab completion doesn’t work, so the command clearly doesn’t exist) results in "command not found: “/field/update” ".

I can attach as an archive any piece of code to show how I modified the field04 example, then I can show how I query Geant4 inside an interactive-mode run using the messenger commands I defined in the source code.

I believe my Q is more general: how can I make sure that what I change via the messenger is ‘‘understood’’ by Geant4? How can I send an ‘‘update’’ command so that I am sure that the next /run/beamOn 1 command will interact and develop inside/with a modified geometry/fields/materials/incident_particle_energy etc?
For example, I created a command which does its job as I expect, and I can work with it it live, and the trajectories change accordingly. This command changes the mean value of the kinetic energy of the incident particle and similarly a command which changes the std. dev of the kinetic energy of the incident particle. Inside the interactive visualization, I write /gun/setMean 50.0 MeV and it understands this, the very next /run/beamOn 1 will shoot a proton which I see it’s behaving differently than those shot after a /gun/setMean 1000.0 MeV. Similarly with (say) /gun/stdDev 10.0 MeV.

Thank you a lot!

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