How to determine RGB values given a display spectral response curve? I am reading Physically Based Rendering section 2.2.2 on RGB color.
I am trying to understand how, given a display spectral response curves for rgb intensities, we can choose the intensities so that the display will emit an equivalent spectrum (a CIE xyz metamer)
It is my understanding that the following section tries to explain exactly that.

Given an (x,y,z) representation of an SPD, we can convert it to corresponding
RGB coefficients, given the choice of a particular set of SPDs that
define red, green, and blue for a display of interest. Given the
spectral response curves R(lambda), G(lambda), and B(lambda), for a particular display, RGB
coefficients can be computed by integrating the response curves with
the SPD S(lambda) and using the tristimulus theory of color perception:


I can't understand this formula. Why it is considered correct? Why choosing r this way makes the display emit the correct / equivalent SPD?
Can someone break it down for me?
I'll try my best to give an overview of the subject, and english is not my first language so feel free to ask more detailed information in comments etc.

Here are some terms, light is an electro magnetic radiation. When the power of this radiation falls between a certain wave length, it becomes visible for human beings. S is the function that takes wave length value as input and gives a power value as output and is called a s(pectral) p(ower) d(istribution).
Color on the other hand means different things to different people. We can define color based on our perception of it, or based on the measured spectral power distribution, based on the average physical capacity of human eye etc.
The thing is spectral distributions change over time constantly, but the color does not change at the same speed. This means that variations in the spectral distribution does not map to color one to one, which shows that there must be a transformation happening between what we perceive as color and what we measure as spectral distribution.
Now the needs for an accurate and standardised representation of color was quite important for daily life (think of colors around road signs, lamps, etc), the CIE defined its trichomatic system for this purpose. The main idea behind the trichromatic system was that given a carefully chosen three reference spectral distribution, we can represent all of the perceivable colors by mixing these three spds.
Notice that I did two things over there. I passed from mixing spds, which should produce an spd at the end, to color values which are generally represented with trichromatic system, and I added perceived. The last one is to signal that this is an experimental procedure, that is people did a lot of experiments to come up to this idea of mixing reference spds.
How do we arrive from mixing spds which should produce an spd to a color value in rgb ? Simple by summing all the power values of the spd resulting from the mix.
The mix is $R(\lambda)S(\lambda)$ part where R is the reference spd and S is any given spd. $\int$ indicates that we are summing the resulting multiplication.
$\lambda$ is the wave length.
A great reference on the subject is McCluney 1994, Introduction to Radiometry, chapter 11. Read through 11.2 and then 11.4, that should clarify anything and everything with respect to spds and their transformation to trichromatic values