On-line analysis of 4D treatment deliveries for scanned proton and carbon ion beams