Visualisation of B-field [No Magnetic field in this extent]

Hello,

I am doing a simulation with B-field using the G4LineCurrentMagField in the DetectorConstructor.cc. Here are the B-field code:

G4LineCurrentMagFieldfield2 =new G4LineCurrentMagField(32 2teslamm);
G4FieldManager *fman2= new G4FieldManager();
fman2->SetDetectorField(field2);
fman2->CreateChordFinder(field2);
LogicalV->SetFieldManager(fman2,true);

I try to visualise the B-field, following the example “purging_magnet”, by using the command
/vis/scene/add/magneticField (and “/vis/scence/activateModel Field false” and then “/vis/scene/add/magneticField”). It worked perfectly (showing arrows) when I was running “purging_magnet” but I got “No Magnetic field in this extent” while running my simulation.

I fired a low energy electron in the B-field volume and saw a curved trajectory thus I am sure the B-field existed in the simulation.

I tried using the “/vis/set/extentForField xx xx xx xx xx xx mm"or " /vis/set/volumeForField phyV” and then /vis/scene/add/magneticField, still got “No Magnetic field in this extent”.

I read the source code of “purging_magnet” but I cannot find code about visualisation of B-field.

Can anyone give some hints what I have missed or overlooked ?

This is strange. I can see field arrows in purging_magnet, and if I use /vis/set/volumeForField Gap1, then /vis/scene/add/magneticField, I get additional arrows, more closely spaced, in Gap1. (I had to /vis/geometry/set/forceSolid Gap1 ! false so that I could see inside.)

I see your nicely curved trajectory in your picture. All I can think is:

  1. /vis/scene/add/magneticField alone asks the vis manager to draw arrows spaced out over the whole scene, and it may simply miss your volume.
  2. Are you sure the parameters of /vis/set/extentForField and /vis/set/volumeForField are correct? Type /vis/scene/list to get some more information. /vis/drawTree to verify the names of volumes.

The code for drawing is, of course, in the visualization category. I could be more specific if you want to debug deeper.