Measurement of the production of charged pions by protons on a tantalum target