Particle-in-cell simulation of astrophysical plasmas: probing the origin of cosmic rays