Possibility to retrieve Nth event occurrence using EventEnablingPredicateFilter

Dear all,
is it possible to retrieve specific event occurrences using EventEnablingPredicateFilter? For example, if I am using the ApsideDetector to detect events of type APOGEE, can I detect specifically just the 2nd and the 5th event occurrences of this event? Currently I am able to get all the occurrences of the APOGEE event, but I was wondering if there is an efficient way to retrieve directly only the one I need without getting them all during a timespan.

Many thanks.

Hi @fpan

I can recommend you to use an EventHandler with counter (i.e., an int) which is updated each time the eventOccured is called.
Another possibility is to use a Map<Integer, SpacecraftState> to store the information. The map updated each time the eventOcurred method is called.

A last solution could be to use an EventLogger.

Best regards,
Bryan

Do you want only to filter out unwanted events (in which case an EventHandler as suggested by Bryan is the easiest way) or do you want the detector to not spend time finding the unwanted events in the first place?
If you want to avoid detecting some events, then EventEnablingPredicate would be the way to go, for example using a very rough estimation of event times using for example Keplerian motion and setting up intervals covering about one half orbit around the apogees you want to detect.

Thanks a lot Bryan and Luc for your replies.

I was trying to combine both your suggestions to use an EventHandler saving a Map<Integer, SpacecraftState> each time the eventOccurred method is called and I was passing the detector with this handler to the EventEnablingPredicateFilter, because I wanted to keep only the events that have a SpacecraftState equal to that listed in the map populated inside the EventHandler.

The Map<Integer, SpacecraftState> is populated together with EventEnablingPredicateFilter during the propagation but I noticed that when the first event occurred and the map get the first entry, the state saved in the map (and therefore also the date of the event occurrence) is different from the state that is given inside the eventIsEnabled(final SpacecraftState state, final EventDetector detector, final double g): in particular the state of the eventIsEnabled is one step after the current map state.

In this way it is not possible to compare the map state with the state of the eventIsEnabled in order for them to match when I want to keep the event, since the latter will be always after in time and it will have already returned FALSE in the predicate filter during the previous step.

I was wondering, is this an expected behaviour?

Many thanks.