How to add a global or local MagneticField in REST?

System : Linux
REST version : v2.2.X

Hi,
I have a problem when I want to add the magnetic field into restG4.

After I overloaded the virtual function G4VUserDetectorConstruction::ConstructSDandField and constructed a simple global uniform magetic field, I met no errors in compiling but a crash in running.

void DetectorConstruction::ConstructSDandField()
{
G4MagneticField* magField =
new G4UniformMagField(G4ThreeVector(1.*tesla,0.,0.));

G4FieldManager* globalFieldMgr = G4TransportationManager:: GetTransportationManager()-> GetFieldManager();
globalFieldMgr->SetDetectorField(magField);
}

Is it because the sensitive volume is not defined in DetectorConstruction?
It seems that the EventAction class will check the user-specified sensitive volume in the GDML file to set the volume to store energy.

Or does REST provide any APIs related to magnetic field definition?

Looking forward to your help, thanks.

Dear Tao,

I dont know the details about overloading such function. However, I looked into the following slides to learn how to integrate a basic magnetic field into Geant4, and it seems to be working.

I have pushed few updates to the development branch. Now it is possible to define a uniform magnetic field in the world by defining a new magneticField parameter.

<parameter name="magneticField" value="(1,0,0)T" />

Here it is the result of launching a 5MeV electron at PandaX-III chamber (Xe-10bar) with or without magnetic field.

Screenshot 2020-11-28 at 10.19.52

I slightly modified the restG4/examples/01.NLDBD/NLDND.rml to launch 5MeV electrons where the field effect is more clear.

Here is the RML I used test.rml (4.1 KB)

Dear jgalan,

Thank you very much for your help. I’m going to have a try. :grinning: