It takes judgement and experience (or known lines/concrete calculation) and isn't really very easy to generalise.
To bring your rook to a d file quickly, if you plan a pawn advance on the kingside, if your pawn structure is ruined on the kingside, if your opponents pieces are aimed at the kingside etc.
It depends what lines your opponent has open for attack, your plans and ultimately a judgment on where your king will be safest.
When is it good to castle King side and when is it good to castle Queen side?
For instance, let's say there's an open or semi-open d file and my a,b,c,f,g,h are on 2. Should I O-O-O there?