How do photons know they can or can't excite electrons in atoms? This might be a stupid question, but nonetheless, it has been bothering me.
If you take a photon, make it go through some atoms in a solid, liquid or whatever, then you have the chance of this photon being absorbed by an electron, and thereby exciting the electron. This requires the photon to have enough energy to actually excite the electron to another energy level.
My question is then: How does the photon know if it has enough energy or not? Do they interact very quickly to determine if it's okay or not, or is it just something it "knows?"
 A: Transparent media are transparent because the incoming photon does not match any of the available energy levels to transfer its energy to the atom, or molecule, or crystal. 
A classical analogy is thinking of energy levels as various size sieve holes which allow only certain size of particles to go through. Not any matter of knowing or adjusting, but inherent size of the sieve holes. 
The energy levels, that the electrons abide in when attached to matter, are specific and defined by the potentials entering the problem. If the photon has the correct frequency, it will interact with the atom/molecule/lattice and the energy it carries will be absorbed by the atom/molecule/lattice and the electron will either be ejected or just go to a higher level of energy and falling back give up a new photon.
The energy is not given up continuously but with the correct quantum increments defined by the matter it hits.
There do exist free electrons and they do interact with photons. In this case a photon may lose its energy in a non quantized manner, increasing the energy of the electron and becoming a photon of lower energy. That is another story.
A: If you take an isolated hydrogen atom then the electron sits in well defined atomic orbitals that are eigenfunctions of the Schrodinger equation. This is a stable system that doesn't change with time.
If you now introduce an oscillating electromagnetic field (i.e. light) then this changes the potential term in the Schrodinger equation and the hydrogen atomic orbitals are no longer eigenfunctions of Schrodinger equation. So the electron can no longer be described as a $1s$ or $2s$ or whatever orbital, but rather the electron and the photon now have a single time dependant wavefunction that describes both. What happens next depends on how this new wavefunction evolves with time. As the photon moves away we expect the new wavefunction to evolve into one of three possible final states:


*

*the electron orbital is unchanged

*the electron in a different atomic orbital (i.e. it's been excited) and no photon

*the electron in a different atomic orbital (i.e. it's been excited) and a photon with a different energy
You can't predict which will happen, but you can calculate the probability of the three final states. What you find is that the probability of (2) is only high when the photon energy is the same as the energy spacing between atomic orbitals, the probability of (1) approaches unity when the photon energy doesn't match an energy spacing in the atom, and the probability of (3) is generally negligable.
So the photon doesn't need to know whether or not it has the correct energy. The photon and atom interact to form a single system, and this evolves with time in accordance with Schrodinger's equation.
A: Energy of the electron changes with its interaction with photons, if it reaches more it gets excited, else remains in its position even though interacted with the photon, also it comes back during decay to release the photon.
Hence photons don't know the energy level they produce, but it happens by interaction.
