I agree that you should rule out a medical problem, but more than likely it's just a means of self comforting that has become habitual. Suzmom has given you good advice. Whenever you notice the behavior, remind your daughter that she should only be handling her private body parts in a private place, like the bathroom or her bedroom. You will probably need to keep reminding her that touching her privates is private, and keep giving her the choice between TV or going to her room to continue.
There's nothing wrong with her touching herself in the privacy of her own room, again assuming that there is no rash or bladder infection. Some children use this as a way to relax into sleep, and most outgrow the habit if parents don't make a bit issue out of it. But if she smells like pee, there could very well be some physical problem that you should talk to her pediatrician about. And it might also help to make sure her panties fit her comfortably. Some kids can't abide seams rubbing in tender places.