Optimization of the spectroscopic response of the Timepix detector