The astrophysics of cosmic rays