Problem 495

Summary: Energy conservation of tracking in magnetic field
Product: Geant4 Reporter: Michel.Maire
Component: geometry/magneticfieldAssignee: John Apostolakis <John.Apostolakis>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 5.1   
Hardware: PC   
OS: Linux   

Description Michel.Maire 2003-05-28 11:52:04 CEST
the energy conservation is violated when tracking with magnetic field.
Moreover the result depend strongly of the step size.
Below is the energy deposited by an electron of 1 MeV.
The test code is on /afs/cern.ch/user/m/maire/public/N04.tar.gz
--------------------------------------------------------------------------------
no magnetic field:

 ---> Event 0	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1 MeV
 ---> Event 1	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1 MeV
 ---> Event 2	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1000
keV
 ---> Event 3	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1000
keV
 ---> Event 100	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1
MeV
 ---> Event 200	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1
MeV

magnetic field along z axis:

 ---> Event 0	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1.0356
MeV
 ---> Event 1	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
1.04015 MeV
 ---> Event 2	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 1.0356
MeV
 ---> Event 3	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
1.02851 MeV
 ---> Event 100	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
1.02045 MeV
 ---> Event 200	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
1.02143 MeV


magnetic field + stepLimit 1 cm (G4UserLimits):

 ---> Event 0	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
1.13404 MeV
 ---> Event 1	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event : 2.1691
MeV
 ---> Event 2	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
2.04874 MeV
 ---> Event 3	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
2.69503 MeV
 ---> Event 100	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
3.30301 MeV
 ---> Event 200	  Mean nb of tracks/event : 1	  Mean TotalEnergyDep/event :
3.39367 MeV
Comment 1 Gabriele Cosmo 2003-06-04 02:28:59 CEST
The problem is under investigation.
Comment 2 John Apostolakis 2003-07-07 03:56:59 CEST
The root cause for the sizable imprecision is the 'lax' set of default
parameters for the precision of integration/tracking in a field.  This combines
with the very large number of steps required for low energy electrons in a
sizable field, and causes the dependence on the step size and the overall
imprecision.

  These lax defaults will need to be reviewed and changed in the Geant4 code.
Nevertheless it is possible for a user to improve the performance of his/her
program already - by utilising the code segment below in the detector
construction or main program.

......................................................................
  G4PropagatorInField* globalPropagatorInFld;
  G4TransportationManager *transportMgr=
       G4TransportationManager::GetTransportationManager();

  globalPropagatorInFld= transportMgr->GetPropagatorInField();

  G4double minEps= 1.0e-5;
  G4double maxEps= 1.0e-6;
  globalPropagatorInFld->SetMinimumEpsilonStep( minEps );
  globalPropagatorInFld->SetMaximumEpsilonStep( maxEps );

  G4cout << "EpsilonStep: set min= " << minEps << " max= " << maxEps << G4endl;
.......................................................................

  By choosing minEps and maxEps to be small, you can minimise the main of the
sources of the error.  A simple proposal would be to set them equal, and to try
a value of 1.0e-6 or 1.0e-7.  You can then try increase the value, to 1.0e-5 or
1.0e-4 to investigate whether these provide reasonable stability for your case.

 I note that values which are smaller than 1.0e-7 have not been tested. It is
unclear whether these value improve the precision, due to the limited
precisions of arithmetic operations for double precision floating point
numbers.

  The recipe above will limit, but does not eliminate altogether the depedence
on the step size for the lowest energy electrons.  Further investigation is
ongoing.
Comment 3 John Apostolakis 2003-10-20 04:56:59 CEST
An additional protection for conserving energy has been included in patch 1 of
Geant4 5.2 (end August 2003).

Nevertheless the suggested actions outlined above remain an important way of
limitting the errors made -- and review their acceptable levels is important
for obtaining an appropriate level of accuracy and performance.

Further improvements taking into account 'best initial values' will be
undertaken in the coming months.
Comment 4 John Apostolakis 2008-01-29 18:30:36 CET
The default values for these parameters, have been revised:

  fEpsilonMinDefault(5.0e-5), 
  fEpsilonMaxDefault(0.001),

These values have been provided since Geant4 6.0