How to catch shadow only from certain objects?

I want to create modular image, like digital artists do, e.g edit with/without character’s hat, parts of clothes, any object in scene. Shadow catcher option seems like what I need, but it catches shadows from all objects, so if I want to render only hat, I turn on shadow catcher on character’s model and I get dark silhouette of the whole character with hat on it

This used to be done through render layers. I believe now the same or at least similar thing can be achieved with collections.