Transverse momentum spectra of hadrons in high energy pp and heavy ion collisions