Hello, I have prepared small test program which shows problem of incorrect tracking in local magnetic field. Configuration is following: world volume filled with G4_Vacuum beam of electrons directed along axis Z local magnetic field directed along axis Z In this configuration the simulation run shows a deviation along axis X or Y, which should not be. Here is a part of output: -------------------------------------------------------------------------- Start Run processing. ===================================== G4EventManager::ProcessOneEvent() ===================================== 1 primaries are passed from G4EventTransformer. !!!!!!! Now start processing an event !!!!!!! ********************************************************************************************************* * G4Track Information: Particle = e-, Track ID = 1, Parent ID = 0 ********************************************************************************************************* Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName 0 0 0 0 1 0 0 0 world initStep 1 -0.248 10.6 60 1 1.69e-24 62.3 62.3 OutOfWorld Transportation Track (trackID 1, parentID 0) is processed with stopping code 2 NULL returned from G4StackManager. Terminate current event processing. Run terminated. --------------------------------------------------------------------------- Anton
Created attachment 65 [details] test
I have discovered the issue with the test program. There is a mismatch between the Magnetic field created, and the electro-magnetic equation which was used. // --- fields G4UniformMagField* elmagField = new G4UniformMagField(G4ThreeVector(0., 0., 10.*gauss)); G4EqMagElectricField* elmagEquation = new G4EqMagElectricField(elmagField); This was possible due to the existing inheritance between G4ElectroMagneticField (base class) and G4MagneticField (derived class). If instead the equation of motion for the (pure) Magnetic field is used, the program exhibits the expected (correct) behaviour. An excerpt of a program which does this and its results are below. A revision which flags this problem when the user compile (or runs) the program should be considered. // Revised source code G4MagIntegratorStepper* stepper= 0; G4Field* field= 0; G4double fieldValue= 10.0 * gauss; // --- fields // Magnetic field only - Field defines only elements [0 to 2] G4UniformMagField* magField = new G4UniformMagField( G4ThreeVector(0., fieldValue, 0.) ); // Equation requires field elements [0 to 2] G4Mag_EqRhs* magEquation = new G4Mag_UsualEqRhs( magField ); stepper = new G4ClassicalRK4(magEquation, 6); // x: 0-2, p: 3-5 field= magField;
The missing output (using a revised G4SteppingVerbose with additional fields (momentum) and different precision is below. "dir-X,Y and Z" are the momentum directions ********************************************************************************************************* * G4Track Information: Particle = e-, Track ID = 1, Parent ID = 0 ********************************************************************************************************* #Step# X(mm) Y(mm) Z(mm) dir-X dir-Y dir-Z Safety: Pre/Post (mm)KinE(MeV) dE(MeV) StepLeng TrackLeng StepStatus ProcName NextVolume Material: Current/Next 0 0 0 0 0 0 1 0 N/A 1 0 0 0 initStep world G4_Galactic Next:N/A #Step# 1/L X(mm) Y(mm) Z(mm) dir-X dir-Y dir-Z Safety: Pre/Post (mm)KinE(MeV) dE(MeV) StepLeng TrackLeng StepStatus ProcName NextVolume Material: Current/Next 1 0.3795 0 60 0.01265 0 0.9999 0 0 1 1.624e-24 60 60 Status= 0 World-Boundary Transportation OutOfWorld G4_Galactic
Created attachment 320 [details] Revised DetectorConstrucion.cc file Revised DetectorConstruction file for the test program.
The test program points out a weakness / error in the design of the Geant4 field classes - the magnetic field derives from the electromagnetic field. This allows the user to use an equation created for magnetic fields also for fields which have an electric component - which is incorrect and should result in a compilation error. A fix will be prepared.
Fix included in 10.5-beta.