Simulation of electric and magnetic fields and particle tracking