calculate threshold