private ScoreDistributionTop score_distribution_under_pvalue(double pvalue) throws HashOverflowException {
final int maxNumberOfAttempts = 2;
int numberOfAttempts = 0;
ScoreDistributionTop scoreDistribution;
CanFindThresholdApproximation gaussianThresholdEstimation = gaussianThresholdEstimator();
double pvalue_to_estimate_threshold = pvalue;
try {
do {
numberOfAttempts += 1;
if (numberOfAttempts > maxNumberOfAttempts) {
return score_distribution(); // calculate whole distribution
}
// calculate only top part of distribution cause it's faster
double approximate_threshold = gaussianThresholdEstimation.thresholdByPvalue(pvalue_to_estimate_threshold);
scoreDistribution = score_distribution_above_threshold(approximate_threshold);
pvalue_to_estimate_threshold *= 2;
} while (scoreDistribution.top_part_pvalue() < pvalue);
return scoreDistribution;