There are a few ways that a doctor would be able to tell if you had sex; for example, if you showed positive signs of an STI or STD during a pelvic exam or screening. A positive result of a urine or blood test for pregnancy would be another way. Other examples would be if semen was present within your vagina during an examination, and obviously if you have told your doctor that you are sexually active. A doctor can't tell if you had sex just by the appearance of a 'broken' hymen, because there are various ways a hymen can be ruptured without involving sexual intercourse (using tampons, an injury, vigorous activities/sports, etc.). Hope this has helped answer your question.