Optical photon generate with particular event

I am able to produce optical photon when a gamma hits the crystal.
I am simulating with gamma of 1 MeV. I want to generate the optical photons only when total energy deposition is 1 MeV. How to implement it?
Basically, I don’t want those event to generate optical photon which Compton scattered out of my scoring volume.
@mkelsey can you help ?

There is probably a few ways of doing this. I would suggest using the stepprocess information in stepping action to discriminate events in which comptonscattering occurs