We present a new model for the formation of diamondlike films by ion deposition. In particular we model the observed ion energy dependence for the formation of tetrahedral amorphous carbon (ta-C). Ion deposition is treated as a cylindrical thermal spike, with energy loss along the ion track, collision cascade effects, and conversion of energy into phonons and electronic excitations taken into account. Spike-induced atomic rearrangements appear to be crucial for the evolution of a diamondlike phase, but do not lead to density relaxation. For the measured deposition conditions best suited to grow ta-C our model reveals complete rearrangement of the spike volume, resembling a liquidlike phase which is rapidly quenched. We introduce the ratio n(T)/n(S) of n(T) rearrangements and ns atoms in the spike volume as the crucial parameter characterizing the ability of a given ion-target combination to achieve complete rearrangement of the spike volume. n-(T)/n(S) > 1 is the optimum condition for diamond-like film growth. For a-C films the ion energy dependence of n(T)/n(S) agrees well with the measured sp(3) bond fraction. For Ar+-ion-assisted deposition of a-C we find n(T)/n(S) > 1 above 50 eV with no pronounced ion energy dependence. Furthermore, our model predicts optimum conditions for the formation of cubic boron nitride between 50 eV and 3 keV.