A detector, comprising: a plurality of pixels, each pixel configured to count numbers of X-ray photons incident thereon whose energy falls in a plurality of bins of different energy ranges respectively, within a period of time; wherein the detector is configured to sum the numbers counted by all the pixels from the bins of the same energy range; and wherein the detector further comprises: an X-ray absorption layer comprising an electric contact; a first voltage comparator configured to compare a voltage of the electric contact to a first threshold; a second voltage comparator configured to compare the voltage to a second threshold; a controller; a plurality of counters each associated with a bin and configured to register a number of X-ray photons absorbed by one of the pixels wherein the energy of the X-ray photons falls in the bin; wherein 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; wherein the controller is configured to determine whether an energy of an X-ray photon falls into the bin; and wherein the controller is configured to cause the number registered by the counter associated with the bin to increase by one. a plurality of pixels, each pixel configured to count numbers of X-ray photons incident thereon whose energy falls in a plurality of bins of different energy ranges respectively, within a period of time; wherein the detector is configured to sum the numbers counted by all the pixels from the bins of the same energy range; and wherein the detector further comprises: an X-ray absorption layer comprising an electric contact; a first voltage comparator configured to compare a voltage of the electric contact to a first threshold; a second voltage comparator configured to compare the voltage to a second threshold; a controller; a plurality of counters each associated with a bin and configured to register a number of X-ray photons absorbed by one of the pixels wherein the energy of the X-ray photons falls in the bin; wherein 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; wherein the controller is configured to determine whether an energy of an X-ray photon falls into the bin; and wherein the controller is configured to cause the number registered by the counter associated with the bin to increase by one. an X-ray absorption layer comprising an electric contact; a first voltage comparator configured to compare a voltage of the electric contact to a first threshold; a second voltage comparator configured to compare the voltage to a second threshold; a controller; a plurality of counters each associated with a bin and configured to register a number of X-ray photons absorbed by one of the pixels wherein the energy of the X-ray photons falls in the bin; wherein 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; wherein the controller is configured to determine whether an energy of an X-ray photon falls into the bin; and wherein the controller is configured to cause the number registered by the counter associated with the bin to increase by one.