# Figure 5.6: relative cooling function of CII and Lyman alpha as a function of temperature
T1 = 92 # CII
T2 = 1.18e5 # Ly alpha
T3 = 1.58e5 # Ly continuum
nsteps = 100
lT_min = 1.0
lT_max = np.log10(T3)
lT = np.linspace(lT_min, lT_max, nsteps)
T = 10**lT
fig = plt.figure(figsize=(6,4))
ax1 = fig.add_subplot(111)
ax1.set_xlabel("log$_{10}$ [$T$ (K)]", fontsize=16)
ax1.set_ylabel(r"log$_{10}$ [$\Lambda$]", fontsize=16)
# CII cooling
y1 = (T1/T)**0.5 / np.exp(T1/T)
norm = 1/y1.max()
y1 *= norm
ax1.plot(lT, np.log10(y1), 'k:', lw=2)
ax1.text(2.0,-0.7,'CII',fontsize=14)
# Lyman alpha cooling, schematically shown as 1000 times stronger than CII (peak to peak)
y2 = (T2/T)**0.5 / np.exp(T2/T)
y2 *= 1000 * norm
ax1.plot(lT, np.log10(y2), 'k:', lw=2)
#ax1.plot(lT_max, np.log10(y2[-1]),'ko')
ax1.plot([lT_max,lT_max], [np.log10(y2[-1])-0.1,np.log10(y2[-1])+0.1], 'k-', lw=3)
ax1.text(4.5,1.2,'Ly$\\alpha$',fontsize=14)
cooling = y1+y2
ax1.plot(lT, np.log10(cooling), 'k-', lw=3)
ax1.set_xlim(1,5.5)
ax1.set_ylim(-2,3.5)
plt.savefig('HI_cooling.pdf')