An optimization method for ion based radiotherapy includes inverse planning based on optimization variables related to the particle energy, a range modulator or ridge filter, a block and/or a range compensator. This enables automatic optimization of complex cases.