Raw-data–based material decomposition in spectral CT using photon–counting energy–selective detectors relies on a precise forward model that predicts a count–rate given intersection lengths for each material. This re- quires extensive system–specific measurements or calibration techniques. Existing calibrations either estimate a detected spectrum and are able to account for spectrally distorted assumptions or correct the predicted count rate using a correction function and can accommodate for count rate–dependent effects such as pulse pileup. We propose a calibration method that uses transmission measurements to optimize a correction function that, unlike existing methods, depends both on the photon energy and the count rate. It is thus able to correct for both kinds of distortions. In a simulated material decomposition into water and iodine, the error was reduced by 96 % compared to the best performing reference method if only pulse pileup was present and reduced by 23 % if additionally spectral distortions were taken into account. In phantom measurements using a Dectris SANTIS prototype detector, the proposed method allowed to reduce the error by 29 % compared to the best performing reference method. Artifacts were below the noise level for the proposed method, while the reference methods either showed an offset in the water region or ring artifacts.