import math


def P_m_ma(m_array, m, top=True, n_top_ch=250, n_bot_ch=234):
    """Probability of m_array phds in a certain array to be found m in a certain channel.
    Assumed evenly distributed S1 pattern. For use case uneven S1 pattern, change either n_top_ch 
    or n_bot_ch to 1/occupancy of the channel of interest in a certain array (not the whole detector). 

    Args:
        m_array (int): number of phds in the specified array.
        m (int): number of phds in the channel of interest.
        top (bool, optional): whether or not we specify top array. Defaults to True.
        n_top_ch (int, optional): number of top array channels. Assign this to 1/occupancy in case of uneven S1 pattern. Defaults to 250.
        n_bot_ch (int, optional): number of bottom array channels. Assign this to 1/occupancy in case of uneven S1 pattern. Defaults to 234.

    Returns:
        (float): P(m|m_array)
    """
    if top: # top array
        p_m_ma = math.comb(m_array, m) * (1/n_top_ch)**m * (1-1/n_top_ch)**(m_array-m)
    else: # bottom array
        p_m_ma = math.comb(m_array, m) * (1/n_bot_ch)**m * (1-1/n_bot_ch)**(m_array-m)
    return p_m_ma