  The momentum spectra of charged pions ($\pi^+$ and $\pi^-$) and kaons ($K^+$
and $K^-$), as well as protons ($p$), produced in the beam protons induced
collisions in a 90-cm-long graphite target [proton-carbon ($p$-C) collisions]
at the beam momentum $p_{Lab}=31$ GeV/$c$ are studied in the framework of a
multisource thermal model by using Boltzmann distribution and Monte Carlo
method. The theoretical model results are approximately in agreement with the
experimental data measured by the NA61/SHINE Collaboration. The related free
parameters (effective temperature, rapidity shifts, and fraction of non-leading
protons) and derived quantities (average transverse momentum and initial
quasi-temperature) under given experimental conditions are obtained. It is
shown that the considered free parameters and derived quantities to be strongly
dependent on emission angle over a range from 0 to 380 mrad and weakly
dependent on longitudinal position (graphite target thickness) over a range
from 0 to 90 cm.
