예제 #1
0
 def filter_templates(self):
     """
     calculate array of Booleans in template id order to filter events
     """
     assert self.massspins is not None
     assert self.lo is not None
     assert self.hi is not None
     if self.args.verbose:
         print('Cutting on %s between %f - %f' %
               (self.bin_param, self.lo, self.hi))
     self.tpars = triggers.get_param(self.bin_param, None, *self.massspins)
     self.in_bin = filter_bin_lo_hi(self.tpars, self.lo, self.hi)
예제 #2
0
def template_param_bin_calc(padata, trdata, horizons):
    """
    Parameters
    ----------
    padata: PAstroData instance
        Static information on p astro calculation
    trdata: dictionary
        Trigger properties
    horizons: dictionary
        BNS horizon distances keyed on ifo

    Returns
    -------
    p_astro, p_terr: tuple of floats
    """
    massspin = (trdata['mass1'], trdata['mass2'],
                trdata['spin1z'], trdata['spin2z'])
    trig_param = triggers.get_param(padata.spec['param'], None, *massspin)
    # NB digitize gives '1' for first bin, '2' for second etc.
    bind = numpy.digitize(trig_param, padata.bank['bin_edges']) - 1
    logging.debug('Trigger %s is in bin %i', padata.spec['param'], bind)

    # Get noise rate density
    if 'bg_fac' not in padata.spec:
        expfac = 6.
    else:
        expfac = padata.spec['bg_fac']

    # FAR is in Hz, therefore convert to rate per year (per SNR)
    dnoise = noise_density_from_far(trdata['far'], expfac) * lal_s_per_yr
    logging.debug('FAR %.3g, noise density per yr per SNR %.3g',
                  trdata['far'], dnoise)
    # Scale by fraction of templates in bin
    dnoise *= padata.bank['tcounts'][bind] / padata.bank['num_t']
    logging.debug('Noise density in bin %.3g', dnoise)

    # Get signal rate density at given SNR
    dsig = signal_pdf_from_snr(trdata['network_snr'],
                               padata.spec['netsnr_thresh'])
    logging.debug('SNR %.3g, signal pdf %.3g', trdata['network_snr'], dsig)
    dsig *= padata.spec['sig_per_yr_binned'][bind]
    logging.debug('Signal density per yr per SNR in bin %.3g', dsig)
    # Scale by network sensitivity accounting for BNS horizon distances
    dsig *= signal_rate_rescale(horizons, padata.spec['ref_bns_horizon'])
    logging.debug('After horizon rescaling %.3g', dsig)

    p_astro = dsig / (dsig + dnoise)
    logging.debug('p_astro %.4g', p_astro)
    return p_astro, 1 - p_astro