Visualising magnetic field in a beamline

I am building a beamline in Geant4 and have quadrupoles and bends with magnetic fields read from a 2d field map file. I have that implemented and would now like to visualize the fields in each element. I checked the blinetracer example and tried to implement it. I understand it doesn’t work for regions without fields so I tried visualizing each element separately but the process just gets killed when I try to run it. Can someone please help with that ? In the example the known limitations and issues were mentioned and it said it will be developed, has there been any update on that ? Any help is much appreciated. Thank you in advance,

Best Regards,

Have you tried the field visualisation commands? See Application Developers Guide, Visualisation, Controlling Visualization from Commands, Visualization of fields.

Hi thank you so much for the suggestion. I tried it but I get something like this (attached) showing the field but I was hoping to visualize smooth magnetic field lines. This is an example of a quadrupole. Is there a way to maybe increase the number of lines to make it look continuous? Please let me know. If this doesn’t look reasonable I should check my magnetic field definition then. Thank you again in advance,


Yes you can change the spacing etc. Consult the guidance:

help /vis/scene/add/magneticField

(Always consult guidance, because it’s more extensive than the normal documentation. In fact we rely on the online guidance in the visualisation group - it IS our documentation - see “Application Guide, Built-in commands”.)

Thanks a lot for the reply. Its better now. :slight_smile:

Have a great day ahead,

Hello @allison, I followed your message then I added in vis.mac the line


but I can’t see the magnetic field lines

Here my vis.mac

vis.txt (4.7 KB)

Have you read the command guidance? Have you tried any of the suggestions therein?

Hello, @allison where do I’ve to write this command?

help /vis/scene/add/magneticField

If you are running in “interactive mode” - and it looks as though you are - just type it on the command line. If you are using the Qt UI, it will point you to the help tree. (If you are using the Qt UI, you can go straight to the help tree - see “Help” button towards the top-left corner of the window.)

If you are running in “batch mode”, you can add
/control/manual /vis/scene/add
to your macro. That will give you guidance for all the /vis/scene/add commands. (You could add it to your vis.mac anyway - but it does give rather a lot of output.)

But perhaps most of all, I can point you to the documentation. Let me remind you that I have already done that on this thread. Please use the documentation and command guidance. We have put a lot of effort into trying to give as much help as we can. If that fails to help, then let us know what you did and in what way it was not helpful - then we can improve it.

Here are some quotes from this thread…

Here is a direct link to the Built-in commands - Built-in Commands — Book For Application Developers 10.7 documentation.

1 Like

Hello @allison sorry, but I didn’t see yor reply…
I will try.
Thank you