The Fourier coefficients $v_2$ and $v_3$ characterizing the anisotropy of the azimuthal distribution of charged particles produced in PbPb collisions at $\sqrt{ s_{\mathrm{NN}} } = $ 5.02 TeV are measured with data collected by the CMS experiment. The measurements cover a broad transverse momentum range, $p_{\mathrm{T}}= $ 1-100 GeV/$c$. The analysis focuses on $p_{\mathrm{T}} > $ 10 GeV/$c$ range, where anisotropic azimuthal distributions should reflect the path-length dependence of parton energy loss in the created medium. Results are presented in several bins of PbPb collision centrality, spanning the 60% most central events. The $v_2$ coefficient is measured with the scalar product and the multiparticle cumulant methods, which have different sensitivities to the initial-state fluctuations. The values of both methods remain positive up to $p_{\mathrm{T}} ≈ $ 70 GeV/$c$, in all examined centrality classes. The $v_3$ coefficient, only measured with the scalar product method, tends to zero for $p_{\mathrm{T}} \gtrsim $ 20 GeV/$c$. Comparisons between theoretical calculations and data provide new constraints on the path-length dependence of parton energy loss in heavy ion collisions and highlight the importance of the initial-state fluctuations.