Can someone explain how pair production happens?

I know that if a photon has enough energy, it can split off into a particle and anti-particle. But how does that happen exactly? Does the photon just randomly decides to split off?

With annihilation (opposite of pair production), the process is much easier to visualize for me, because you basically have a particle and anti-particle coming together in a collision, annihilating each other and turning their mass into energy, it all makes sense.

By the way, this is A-level (school) stuff I'm working on, so no need to go too much into detail because it'll probably just fly over my head lol

Annihilation is not the opposite of pair production. Annihilation is particle+antiparticle -> 2 photons, while pair production is photon + nucleus -> particle+antiparticle+nucleus

why does it have to be a nucleus? and why does the photon do this when in close proximity with a nucleus?

I mean, for example when a photon gets close to an electron, it doesn't produce a particle-antiparticle pair, it just gets absorbed or reflected off instead (if the photon's energy isn't enough to move the electron to the next level of orbit)

when a photon gets close to an electron, it doesn't produce a particle-antiparticle pair, it just gets absorbed or reflected off instead (if the photon's energy isn't enough to move the electron to the next level of orbit)

A free electron can not absorb photon.You can do some relativistic calculation to verify that it gives non sense results.

Consider that a photon has energy AND momentum. If you absorb a photon, BOTH have to be put somewhere.

Free photon in a vacuum has no way of doing ANYTHING, for the simple reason that it has no time or energy. You can simply change your observation frame, and a gamma ray photon is indistinguishable from a radio wave.

Only if the photon encounters another particle with a different velocity do the energy and momentum of photon have a meaning. (Different velocity includes another photon travelling in a different, including opposite, direction.)

Now, consider that for any particle, energy, rest mass and momentum are connected by relationship
E²=(pc)²+(mc²)²
If a photon encounters a massive particle it can interact with, one thing it can do is undergo elastic scattering. You can always choose a frame where the photon and the massive particle have equal and opposite momenta, and merely change direction. That is Compton scattering.

But there are various inelastic things that can happen.

A photon cannot be destroyed merely accelerating any massive system. It can only be destroyed if an amount of energy goes into changing its state. Like exciting an atom, or ionizing it.

An electron has no constituent parts. It is a fundamental particle, and has no excited states.

I suppose that a photon might "excite" an electron by reaction
e-+γ=μ-+νe+ν~μ
and likewise with tauon, but these need a lot of energy and also are weak interaction processes where photons do not partake.

Now, electron-positron pair position needs less energy. But still.

The energy needed for the rest mass of the positronium alone is 1,022 MeV. But the electron and positron have then no momentum, and the photon had some. The only way the energy and momentum can be conserved is by giving some momentum to another particle.

With nuclei, the recoil of a massive nucleus will take up the photon energy with a low speed and thus low recoil energy.

Since an electron is light, it has high recoil energy for a given momentum. It turns out that in a reaction
γ+e-=2e-+e+
in a frame where the original electron is at rest, the needed energy of a photon is exactly double the energy needed for pair production with no recoil energy.

Can someone comment how the cross-sections for Compton scattering, nuclear pair production and electron pair production compare in the energy range where all three are allowed?

Annihilation is not the opposite of pair production. Annihilation is particle+antiparticle -> 2 photons, while pair production is photon + nucleus -> particle+antiparticle+nucleus

Why two photons cannot combine to produce, for example, an electron and a positron? I thought QED is time-reversal invariant. Surely this reaction is quite rare, but still possible, right. This process could be considered as an annihilation of two photons (particle+antiparticle) into two massive fermions.