Can a Kensei monk spend a bonus action to use the Kensei’s Shot feature after they make an attack roll, and still do the extra damage on that attack?

The Way of the Kensei monk’s Path of the Kensei feature grants several benefits, including Kensei’s Shot. The wording of Kensei’s Shot is as follows (Xanathar’s Guide to Everything, p. 34):

You can use a bonus action on your turn to make your ranged attacks with a kensei weapon more deadly. When you do so, any target you hit with a ranged attack using a kensei weapon takes an extra 1d4 damage of the weapon’s type. You retain this benefit until the end of the current turn.

Can you choose to spend the bonus action to use Kensei’s Shot after rolling to hit, and still gain the extra damage on the attack you just made? Or do you have to declare that you’re using Kensei’s Shot before you make the attack roll?