  We present a lattice QCD study of charmonium resonances and bound states with
$J^{PC}=1^{--}$ and $3^{--}$ near the open-charm threshold, taking into account
their strong transitions to $\bar DD$. Vector charmonia are the most abundant
in the experimentally established charmonium spectrum, while recently LHCb
reported also the first discovery of a charmonium with likely spin three. The
$\bar DD$ scattering amplitudes for partial waves $l=1$ and $l=3$ are extracted
on the lattice by means of the L\"uscher formalism, using multiple volumes and
inertial frames. Parameterizations of the scattering amplitudes provide masses
and widths of the resonances, as well as the masses of bound states. CLS
ensembles with 2+1 dynamical flavors of non-perturbatively $O(a)$ improved
Wilson quarks are employed with $m_\pi\simeq 280$ MeV, a single lattice spacing
of $a\simeq0.086$ fm and two lattice spatial extents of $L=24$ and $32$. Two
values of the charm quark mass are considered to examine the influence of the
position of the $\bar{D}D$ threshold on the hadron masses. For the lighter
charm quark mass we find the vector resonance $\psi(3770)$ with mass
$m=3780(7)$ MeV and coupling $g=16.0(^{+2.1}_{-0.2})$ (related to the width),
both consistent with their experimental values. The vector $\psi(2S)$ appears
as a bound state with $m=3666(10)$ MeV. The charmonium resonance with
$J^{PC}=3^{--}$ is found at $m=3831(^{+10}_{-16})$ MeV, consistent with the
$X(3842)$ recently discovered by LHCb. At our heavier charm-quark mass the
$\psi(2S)$ as well as the $\psi(3770)$ are bound states and the $X(3842)$
remains a resonance. We stress that all quoted uncertainties are only
statistical, while lattice spacing effects and the approach to the physical
point still need to be explored. This study of conventional charmonia sets the
stage for more challenging future studies of unconventional charmonium-like
states.
