When should I declare that I want to twin my spell?

A simple question: when should I declare that I want to match my spell: before the attack roll, after the attack roll or after the dm, it tells me if it hits or not. In addition, I lose witchcraft if I have to declare it before the attacking role and that is missing.