def updateStimSum(sumstim, nevents1, s1, sumsq1, found_s1, nevents2, s2,
    sumsq2, found_s2):
    """Update sums for averages of stim positions.

    Parameters
    ----------
    sumstim: tuple with current sums
        n1      number of events for first stim
        sum1y   sum for first stim, Y coordinate
        sum1x   sum for first stim, X coordinate
        sumsq1y sum of squares for first stim, Y coordinate
        sumsq1x sum of squares for first stim, X coordinate
        n2      number of events for second stim
        sum2y   sum for second stim, Y coordinate
        sum2x   sum for second stim, X coordinate
        sumsq2y sum of squares for second stim, Y coordinate
        sumsq2x sum of squares for second stim, X coordinate

    nevents1: int
        Number of events for first stim in current time interval.

    s1: tuple of two floats
        Tuple of (y,x) coordinates of the first stim in current interval.

    found_s1: boolean
        True if the first stim was actually found.

    nevents2: int
        Number of events for second stim in current time interval.

    s2: tuple of two floats
        Same as s1, but for the second stim.

    found_s2: boolean
        True if the second stim was actually found.

    Returns
    -------
    tuple
        An updated sumstim tuple.

    nevents1 and nevents2 are used as weights when incrementing the
    sums.  n1 and n2 are the total number of events for the first and
    second stims respectively.
    """
    (n1, sum1y, sum1x, sumsq1y, sumsq1x, n2, sum2y, sum2x, sumsq2y, sumsq2x
        ) = sumstim
    if found_s1:
        n1 = n1 + nevents1
        sum1y = sum1y + s1[0] * nevents1
        sum1x = sum1x + s1[1] * nevents1
        sumsq1y = sumsq1y + sumsq1[0]
        sumsq1x = sumsq1x + sumsq1[1]
    if found_s2:
        n2 = n2 + nevents2
        sum2y = sum2y + s2[0] * nevents2
        sum2x = sum2x + s2[1] * nevents2
        sumsq2y = sumsq2y + sumsq2[0]
        sumsq2x = sumsq2x + sumsq2[1]
    return (n1, sum1y, sum1x, sumsq1y, sumsq1x, n2, sum2y, sum2x, sumsq2y,
        sumsq2x)
