Current advances in the development of hybrid pixel detectors allow analyzing an energy spectrum of the incoming X-ray radiation with a keV resolution. This spectral information can be utilized to determine the material composition of the studied object based on the known material attenuation dependency on energy. The algorithm discussed and implemented in this article solves an optimization problem with a cost function based on Beer's Law. A successful application of this procedure to the real data requires an accurate model of the detector response. A Monte-Carlo simulation of the registration process in the Timepix3-based detector is performed for the generation of the detector signal corresponding to a monochromatic beam depending on th...