A three-dimensional electromagnetic particle-in-cell code to simulate heavy ion beam propagation in the reaction chamber