Computing the Joint Distribution of Tree Shape and Tree Distance for Gene Tree Inference and Recombination Detection