  We report a method for producing ultracold HD+ molecular ions populated in a
rotational ground state in an ion trap based on [2+1'] resonance-enhanced
threshold photoionization (RETPI) and sympathetic cooling with the laser-cooled
Be$^+$ ions. The effect of electric field of the ion trap on the RETPI process
of neutral HD molecules and the blackbody radiation (BBR) on the population
evolution of rotational states of the generated polar HD+ ions have been
studied. The initial rotational ground state population of HD$^+$ ions is
0.93(12). After the cumulation time of 5 s, the rotational ground state
population is reduced to 0.77(8) due to the BBR coupling. This method of
generating ultracold state-selected HD$^+$ ions is beneficial for the studies
in precision rovibrational spectroscopy, state-controlled cold chemical
reaction, and quantum logic spectroscopy.
