Simulation for relativistic particles in electromagnetic fields