Event generation and filtering

In general, when and where are events generated in the source code? I need to add a filter to generated primaries based off of their initial position and direction. I have the position and angular distributions defined in a macro file, and I need to draw from the defined distributions, but I also need to ignore the large majority of the particles generated based on their initial conditions or else the simulation will run too slowly. I can’t seem to find where events are generated so that I can filter them out before they’re tracked. Can somebody point me in the right direction?

resolved. I was unaware G4event->GetPrimaryVertex() defaults to the 0th primary.