An image forming apparatus, comprising: an image forming device adapted to eject an ink; and a spectrometer adapted to disperse incident light, wherein the spectrometer includes: a window section adapted to transmit the light, a dispersing element adapted to disperse light transmitted by the window section, and a light receiving element adapted to receive the light dispersed by the dispersing element and to output detection signals indicative of light amount of a plurality of wavelengths; and a light source that irradiates a target; a spectral measurement unit adapted to determine measured values for each of the plurality of wavelengths based on the detection signals from the light receiving element; a dirtiness detecting unit adapted to detect a residue on the window section based on the measured values from the spectral measurement unit and reference values corresponding to each of the plurality of wavelengths, and characterized by a cleaning mechanism that cleans adapted to the window section; and a cleaning control unit adapted to operate the cleaning mechanism to carry out the cleaning of the window section when residue is detected by the dirtiness detecting unit, wherein: the cleaning mechanism includes an abutting member adapted to abut the window section when the cleaning of the window section is carried out and to be positioned in a standby position distanced from the window section at times other than when the cleaning is carried out, and the light quantity variation determination unit determines whether there is variation in the light quantity of a light source based on a slope of a regression line that is based on the reference values and the measured values, wherein: the spectrometer includes the light source that irradiates a target with light via the window section, and after the cleaning of the window section is carried out, the light quantity variation determination unit determines whether there is variation in the light quantity of the light source based on the slope of the regression line. an image forming device adapted to eject an ink; and a spectrometer adapted to disperse incident light, wherein the spectrometer includes: a window section adapted to transmit the light, a dispersing element adapted to disperse light transmitted by the window section, and a light receiving element adapted to receive the light dispersed by the dispersing element and to output detection signals indicative of light amount of a plurality of wavelengths; and a light source that irradiates a target; a window section adapted to transmit the light, a dispersing element adapted to disperse light transmitted by the window section, and a light receiving element adapted to receive the light dispersed by the dispersing element and to output detection signals indicative of light amount of a plurality of wavelengths; and a light source that irradiates a target; a spectral measurement unit adapted to determine measured values for each of the plurality of wavelengths based on the detection signals from the light receiving element; a dirtiness detecting unit adapted to detect a residue on the window section based on the measured values from the spectral measurement unit and reference values corresponding to each of the plurality of wavelengths, and characterized by a cleaning mechanism that cleans adapted to the window section; and a cleaning control unit adapted to operate the cleaning mechanism to carry out the cleaning of the window section when residue is detected by the dirtiness detecting unit, the cleaning mechanism includes an abutting member adapted to abut the window section when the cleaning of the window section is carried out and to be positioned in a standby position distanced from the window section at times other than when the cleaning is carried out, and the light quantity variation determination unit determines whether there is variation in the light quantity of a light source based on a slope of a regression line that is based on the reference values and the measured values, wherein: the spectrometer includes the light source that irradiates a target with light via the window section, and after the cleaning of the window section is carried out, the light quantity variation determination unit determines whether there is variation in the light quantity of the light source based on the slope of the regression line. the spectrometer includes the light source that irradiates a target with light via the window section, and after the cleaning of the window section is carried out, the light quantity variation determination unit determines whether there is variation in the light quantity of the light source based on the slope of the regression line.