A detection function is used during the migration-based detection of microseismic events. A potential event is detected when a detection function exceeds some specified threshold value. However, the value of this threshold is usually selected manually; therefore, the detection process is subjective and lacks constraints on the probability of exceeding the threshold. In practice, any change in the detection algorithm results in a change in the distribution of the detection-function values. Consequently, the threshold value must be adjusted to have the same probability of exceedance as before. I have developed a general probabilistic theory of the detection function that is valid for any migration-based detection method. For the sake of transparency and the interchangeability of the results, I recommend the definition of a threshold in terms of the exceedance probability. To do so, it is necessary to define a probability distribution of the detection function. I have also developed a general method for assessing the detectability of a given stacking method for the purpose of comparing different migration-based methods. A simple synthetic example indicates how to use the developed theory in practice.