Measurement of relative branching fractions of B decays to psi(2S) and J/psi mesons