def check_background_contamination(n, alpha=1, max_background_ratio=.05):
    """
    check if there are sufficenly few proton events in this energy bin and calculates
    scaling parameter if not
    scales `N_signal` in place.

    Parameters
    ----------
    n = [n_signal, n_backgr] : list
        the signal in the on-region (index 0) and background in the off-region (index 1)
    alpha : float (default: 1)
        ratio of the on- to off-region -- `n[1]` times `alpha` is used as background
        estimate for the on-region
    max_background_ratio : float
        maximum allowed proton contamination

    Returns
    -------
    scale_r : float
        factor to scale up gamma events if too high proton contamination
    """

    n_signal, n_backgr = n[0], n[1] * alpha

    n_tot = n_signal + n_backgr
    if n_signal < n_backgr * max_background_ratio:
        scale_r = (n_backgr * max_background_ratio) / n_signal
        n[0] *= scale_r
        return scale_r
    else:
        return 1