docs: def generate_event_set(ucerf, background_sids, src_filter, ses_idx, seed):
      """
      Generates the event set corresponding to a particular branch
      """
      serial = seed + ses_idx * TWO16
      # get rates from file
      with h5py.File(ucerf.source_file, 'r') as hdf5:
          occurrences = ucerf.tom.sample_number_of_occurrences(ucerf.rate, seed)
          indices, = numpy.where(occurrences)
          logging.debug(
              'Considering "%s", %d ruptures', ucerf.source_id, len(indices))
  
          # get ruptures from the indices
          ruptures = []
          rupture_occ = []
          for iloc, n_occ in zip(indices, occurrences[indices]):
              ucerf_rup = ucerf.get_ucerf_rupture(iloc, src_filter)
              if ucerf_rup:
                  ucerf_rup.serial = serial
                  serial += 1
                  ruptures.append(ucerf_rup)
                  rupture_occ.append(n_occ)
  
          # sample background sources
          background_ruptures, background_n_occ = sample_background_model(
              hdf5, ucerf.idx_set["grid_key"], ucerf.tom, seed,
              background_sids, ucerf.min_mag, ucerf.npd, ucerf.hdd, ucerf.usd,
              ucerf.lsd, ucerf.msr, ucerf.aspect, ucerf.tectonic_region_type)
          for i, brup in enumerate(background_ruptures):
              brup.serial = serial
              serial += 1
              ruptures.append(brup)
          rupture_occ.extend(background_n_occ)
  
      assert len(ruptures) < TWO16, len(ruptures)  # < 2^16 ruptures per SES
      return ruptures, rupture_occ