An optimized Monte Carlo (PENELOPE) code for the characterization of gel-layer detectors in radiotherapy