code: def compute_efficiency(f_dist, m_dist, dbins):
      '''
      Compute the efficiency as a function of distance for the given sets of found
      and missed injection distances.
      Note that injections that do not fit into any dbin get lost :(
      '''
      efficiency = numpy.zeros(len(dbins) - 1)
      error = numpy.zeros(len(dbins) - 1)
      for j, dlow in enumerate(dbins[:-1]):
          dhigh = dbins[j + 1]
          found = numpy.sum((dlow <= f_dist) * (f_dist < dhigh))
          missed = numpy.sum((dlow <= m_dist) * (m_dist < dhigh))
          if found+missed == 0:
              # avoid divide by 0 in empty bins
              missed = 1.
          efficiency[j] = float(found) / (found + missed)
          error[j] = numpy.sqrt(efficiency[j] * (1 - efficiency[j]) /
                                (found + missed))
  
      return efficiency, errof compute_efficiency(f_dist, m_dist, dbins):
      '''
      Compute the efficiency as a function of distance for the given sets of found
      and missed injection distances.
      Note that injections that do not fit into any dbin get lost :(
      '''
      efficiency = numpy.zeros(len(dbins) - 1)
      error = numpy.zeros(len(dbins) - 1)
      for j, dlow in enumerate(dbins[:-1]):
          dhigh = dbins[j + 1]
          found = numpy.sum((dlow <= f_dist) * (f_dist < dhigh))
          missed = numpy.sum((dlow <= m_dist) * (m_dist < dhigh))
          if found+missed == 0:
              # avoid divide by 0 in empty bins
              missed = 1.
          efficiency[j] = float(found) / (found + missed)
          error[j] = numpy.sqrt(efficiency[j] * (1 - efficiency[j]) /
                                (found + missed))
  
      return efficiency, error
docs: Compute the efficiency as a function of distance for the given sets of found
      and missed injection distances.
      Note that injections that do not fit into any dbin get lost :(