Computational routines for proton and ion radiotherapy