def round2bin(number, binsize, direction):
    """Round number to nearest histogram bin edge (either 'up' or 'down')."""
    if direction == 'down':
        return number - (number % binsize)
    elif direction == 'up':
        return number - (number % binsize) + binsize