A study of the composition and energy spectra of anomalous cosmic rays using the geomagnetic field