Monte Carlo simulation of ripple filters designed for proton and carbon ion beams in hadrontherapy with active scanning technique