Dissociation and recombination of a diatomic gas in a background medium