def get_sec_cases_in_window(sim, r, t0, t1):
    """
    Helper function to extract the number of secondary cases from a simulation
    summary object `sim` within interval [t0, t1) for the random repeat `r`.
    """
    # Get the indices of new infections (both asymptomatic and symptomatic)
    new_inf_indices = (
        ((sim.state_started_at['iasy'][r] >= t0) & (sim.state_started_at['iasy'][r] < t1)) |
        ((sim.state_started_at['ipre'][r] >= t0) & (sim.state_started_at['ipre'][r] < t1)))
    # Count the number of secondary cases (while in all possible states)
    num_children = (sim.children_count_ipre[r, new_inf_indices] +
                sim.children_count_isym[r, new_inf_indices] +
                sim.children_count_iasy[r, new_inf_indices])
    return num_children