Ahead of time, you either use viral tools or other genetic modifications to make specific cell types express the photorecrptor.
*there is an effect of light/heat that all cells are subject to, and good experiments try to control for this as best they can