An apparatus for detecting X-ray, comprising: an X-ray absorption layer comprising an electrode; a first voltage comparator configured to compare a voltage of an electrode to a first threshold; a second voltage comparator configured to compare the voltage to a second threshold; a counter configured to register a number of X-ray photons absorbed by the X-ray absorption layer; a controller; the controller is configured to start a time delay from a time at which the first voltage comparator determines that an absolute value of the voltage equals or exceeds an absolute value of the first threshold; the controller is configured to activate the second voltage comparator during the time delay; the controller is configured to cause the number registered by the counter to increase by one, if, during the time delay, the second voltage comparator determines that an absolute value of the voltage equals or exceeds an absolute value of the second threshold.