def sum_entries(hist_data, default=True):
    """Recursively get sum of entries of histogram

    Sometimes hist.entries gives zero as answer? This function always works though.

    :param hist_data: input histogrammar histogram
    :param bool default: if false, do not use default HG method for evaluating entries, but exclude nans, of, uf.
    :return: total sum of entries of histogram
    :rtype: int
    """
    if default:
        entries = hist_data.entries
        if entries > 0:
            return entries

    # double check number of entries, sometimes not well set
    sume = 0
    if hasattr(hist_data, "bins"):
        # loop over all counters and integrate over y (=j)
        for i in hist_data.bins:
            bi = hist_data.bins[i]
            sume += sum_entries(bi)
    elif hasattr(hist_data, "values"):
        # loop over all counters and integrate over y (=j)
        for i, bi in enumerate(hist_data.values):
            sume += sum_entries(bi)
    elif hasattr(hist_data, "entries"):
        # only count histogrammar.Count() objects
        sume += hist_data.entries
    return sume