From 4c831994f9750a20b960c4367b5dbf4f8d48baa1 Mon Sep 17 00:00:00 2001
From: Kipp Cannon <kipp.cannon@ligo.org>
Date: Wed, 29 Nov 2017 08:39:21 -0600
Subject: [PATCH] gstlal-inspiral: re-enable --min-log-L feature

- by finishing the construction of the dataless ranking statistic
- this makes gstlal_inspiral_fake_diststats obsolete, so it is deleted
---
 gstlal-inspiral/bin/Makefile.am               |   1 -
 .../bin/gstlal_inspiral_fake_diststats        | 182 ------------------
 gstlal-inspiral/python/far.py                 |  27 +--
 gstlal-inspiral/python/inspiral.py            |  16 +-
 gstlal-inspiral/python/stats/inspiral_lr.py   | 118 +++++++++---
 .../share/O2/Makefile.BNS_test_dag            |  13 +-
 .../share/O2/Makefile.O2_offline_dag          |  29 +--
 .../O2/Makefile.O2_offline_hybridbank_dag     |  29 +--
 .../O2/Makefile.O2_offline_injections_dag     |   2 +-
 .../share/O2/Makefile.online_analysis         |   2 +-
 10 files changed, 117 insertions(+), 302 deletions(-)
 delete mode 100755 gstlal-inspiral/bin/gstlal_inspiral_fake_diststats

diff --git a/gstlal-inspiral/bin/Makefile.am b/gstlal-inspiral/bin/Makefile.am
index c829e1b25b..0b5c1cec32 100644
--- a/gstlal-inspiral/bin/Makefile.am
+++ b/gstlal-inspiral/bin/Makefile.am
@@ -8,7 +8,6 @@ dist_bin_SCRIPTS = \
 	gstlal_inspiral_calc_rank_pdfs \
 	gstlal_inspiral_coinc_extractor \
 	gstlal_inspiral_create_prior_diststats \
-	gstlal_inspiral_fake_diststats \
 	gstlal_inspiral_fake_zerolag_counts \
 	gstlal_inspiral_iir_bank_pipe \
 	gstlal_inspiral_injection_snr \
diff --git a/gstlal-inspiral/bin/gstlal_inspiral_fake_diststats b/gstlal-inspiral/bin/gstlal_inspiral_fake_diststats
deleted file mode 100755
index 44b0004756..0000000000
--- a/gstlal-inspiral/bin/gstlal_inspiral_fake_diststats
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2010--2014  Kipp Cannon, Chad Hanna
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-# Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-## @file gstlal_ll_inspiral_create_prior_diststats
-# A program to create some prior likelihood data to seed an online analysis
-#
-# ### Command line interface
-#
-#		--verbose, action = "store_true", help = "Be verbose."
-#		--coincidence-threshold, metavar = "value", type = "float", default = 0.005, help = "Set the coincidence window in seconds (default = 0.005).  The light-travel time between instruments will be added automatically in the coincidence test."
-#		--min-instruments, metavar = "count", type = "int", default = 2, help = "Set the minimum number of instruments that must contribute triggers to form a candidate (default = 2).
-#		--num-templates, metavar = "N", default = 1000, type = "int", help = "Set the number of templates per bank. default 1000")
-#		--num-banks, metavar = "N", default = 1, type = "int", help = "Set the number of banks. default 1")
-#		--svd-bank-file metavar = "File", help = "Set the number of templates per bank. default 1000"
-#		--output, metavar = "string", default = "prior.xml.gz", help = "Write likelihood files to disk with this basename: default prior.xml.gz.")
-#		--segment-and-horizon, action = "append", help = "Append to a list of segments and horizon distances for a given instrument.  Argument specified as IFO:start:end:horizon, e.g., H1:1000000000:1000000100:120 ")
-#		--injection-prefactors, metavar = "s,e", default = "0.001,0.01", help = "Set the range of prefactors on the chi-squared distribution for the signal model: default 0.001,0.01")
-
-#
-# =============================================================================
-#
-#                                   Preamble
-#
-# =============================================================================
-#
-
-
-import itertools
-import os
-import shutil
-import sys
-from gstlal import far
-from gstlal import inspiral_pipe
-from gstlal.stats import horizonhistory
-from gstlal import paths as gstlal_config_paths
-from gstlal import svd_bank
-from glue.ligolw import utils as ligolw_utils
-from glue.ligolw.utils import process as ligolw_process
-from glue.ligolw import ligolw
-from glue.ligolw import lsctables
-from glue.ligolw import array as ligolw_array
-from glue.ligolw import param as ligolw_param
-from glue import segments
-from lal import LIGOTimeGPS
-from lal import rate
-from lal.utils import CacheEntry
-from optparse import OptionParser
-
-class DefaultContentHandler(ligolw.LIGOLWContentHandler):
-	pass
-ligolw_array.use_in(DefaultContentHandler)
-ligolw_param.use_in(DefaultContentHandler)
-lsctables.use_in(DefaultContentHandler)
-
-def parse_command_line():
-	parser = OptionParser(
-		version = "Name: %%prog\n%s" % "" # FIXME
-	)
-	parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
-	# FIXME:  default must be kept identical to gstlal_inspiral's
-	parser.add_option("--coincidence-threshold", metavar = "value", type = "float", default = 0.005, help = "Set the coincidence window in seconds (default = 0.005).  The light-travel time between instruments will be added automatically in the coincidence test.")
-	# FIXME:  default must be kept identical to gstlal_inspiral's
-	parser.add_option("--min-instruments", metavar = "count", type = "int", default = 2, help = "Set the minimum number of instruments that must contribute triggers to form a candidate (default = 2).")
-
-	parser.add_option("--svd-bank-file", metavar = "File", help = "Set the number of templates per bank and mchirp. default 1000 templates at mchirp 0.8")
-	parser.add_option("--output", metavar = "string", default = "prior.xml.gz", help = "Write likelihood files to disk with this basename: default prior.xml.gz.")
-	parser.add_option("--segment-and-horizon", action = "append", help = "Append to a list of segments and horizon distances for a given instrument.  Argument specified as IFO:start:end:horizon, e.g., H1:1000000000:1000000100:120 ")
-	#parser.add_option("--override-background-prior", metavar = "N", type = "float", help = "Override the count in the SNR/chisquared bins to be this value")
-	parser.add_option("--injection-prefactors", metavar = "s,e", default = "0.0001,0.1", help = "Set the range of prefactors on the chi-squared distribution for the signal model: default 0.001,0.1")
-	options, filenames = parser.parse_args()
-
-	process_params = dict(options.__dict__)
-
-	def parse_segment_and_horizon(options = options):
-		seglistdict = segments.segmentlistdict()
-		horizon_history = {}
-		for x in options.segment_and_horizon:
-			ifo, start, stop, horizon = x.split(":")
-			seglistdict.setdefault(ifo, segments.segmentlist()).append(segments.segment([LIGOTimeGPS(start), LIGOTimeGPS(stop)]))
-			horizon_history.setdefault(ifo, horizonhistory.NearestLeafTree())[float(start)] = float(horizon)
-			horizon_history.setdefault(ifo, horizonhistory.NearestLeafTree())[float(stop)] = float(horizon)
-		return seglistdict, horizon_history
-
-	if options.segment_and_horizon is None:
-		raise ValueError("--segment-and-horizon required")
-	seglistdict, horizon_history = parse_segment_and_horizon(options)
-
-	options.instruments = frozenset(seglistdict)
-	if not options.instruments:
-		raise ValueError("must specify at least one instrument")
-	if options.min_instruments > len(options.instruments):
-		raise ValueError("--min-instruments is greater than number of available instruments")
-
-	if options.svd_bank_file:
-		banks = svd_bank.read_banks(options.svd_bank_file, contenthandler = DefaultContentHandler, verbose = options.verbose)
-		num_templates = sum([len(b.sngl_inspiral_table) for b in banks])
-		mchirp = max([max([row.mchirp for row in b.sngl_inspiral_table]) for b in banks])
-	else:
-		num_templates = 1000
-		mchirp = 0.8
-	return options, process_params, seglistdict, horizon_history, num_templates, mchirp
-
-
-options, process_params, segs, horizon_history, num_templates, mchirp = parse_command_line()
-segs.coalesce()	# just in case
-
-if options.verbose:
-	print >> sys.stderr, "Livetime: ", abs(segs)
-	print >> sys.stderr, "Extent: ", segs.extent_all()
-	print >> sys.stderr, "Number of templates: ", num_templates
-	print >> sys.stderr, "max chirp mass: ", mchirp
-
-#
-# quantities derived from input
-#
-
-#
-# Number of background events in each detector
-#
-# This is calculated assuming the following
-# 1) num_templates in the analysis
-# 2) Each template produces exactly 1 trigger for every second that a given
-# detector is on according to the user provided segments
-#
-# FIXME what should zero lag be? Right now we set them to be the same
-#
-
-n_trigs = float(abs(segs.extent_all())) * num_templates
-
-#
-# Initialize an empty RankingStat class
-#
-
-diststats = far.RankingStat(instruments = set(segs), delta_t = options.coincidence_threshold, min_instruments = options.min_instruments)
-
-#
-# Add background, zero_lag and injection prior distributions in the SNR and chi-squared plane
-# 
-
-# This a guess at a mass dependent snr chisq prior
-diststats.denominator.add_noise_model(number_of_events = n_trigs, prefactors_range = ((1. / mchirp)**.33, 25.), df = 40, inv_snr_pow = 3.)
-
-# fill in the background to the requested amount
-for instrument, seglist in segs.items():
-	if options.verbose:
-		print "setting number of singles events in %s to %d" % (instrument, n_trigs)
-	mean_rate = n_trigs / float(abs(seglist))
-	for seg in seglist:
-		# I/O code requires counts to be integers
-		diststats.denominator.triggerrates[instrument].add_ratebin(seg, int(round(float(abs(seg)) * mean_rate)))
-diststats.numerator.add_signal_model(prefactors_range = tuple(float(x) for x in options.injection_prefactors.split(",")), df = 40)
-
-#
-# Update the horizon distance history with our fake, user provided horizon history
-#
-
-diststats.numerator.horizon_history.update(horizon_history)
-
-#
-# Prep an output XML file
-#
-
-xmldoc = ligolw.Document()
-xmldoc.appendChild(ligolw.LIGO_LW())
-process = ligolw_process.register_to_xmldoc(xmldoc, u"gstlal_ll_inspiral_create_prior_diststats", ifos = options.instruments, paramdict = process_params)
-far.gen_likelihood_control_doc(xmldoc, diststats, None)
-ligolw_utils.write_filename(xmldoc, options.output, gz = options.output.endswith(".gz"), verbose = options.verbose)
diff --git a/gstlal-inspiral/python/far.py b/gstlal-inspiral/python/far.py
index 77dd8c2662..3416f9c333 100644
--- a/gstlal-inspiral/python/far.py
+++ b/gstlal-inspiral/python/far.py
@@ -257,26 +257,19 @@ class RankingStat(snglcoinc.LnLikelihoodRatioMixin):
 		return xml
 
 
-# FIXME: this is not finished.  when complete, make sure its use in
-# inspiral.py is still correct
 class DatalessRankingStat(RankingStat):
+	# NOTE:  .__iadd__(), .copy() and I/O are forbidden, but these
+	# operations will be blocked by the .numerator and .denominator
+	# instances, no need to add extra code here to prevent these
+	# operations
 	def __init__(self, *args, **kwargs):
-		super(DatalessRankingStat, self).__init__(*args, **kwargs)
-		self.numerator = inspiral_lr.DatalessLnSignalDensity(instruments = self.numerator.instruments, delta_t = self.numerator.delta_t, min_instruments = self.numerator.min_instruments)
-		self.denominator = inspiral_lr.DatalessLnNoiseDensity(instruments = self.denominator.instruments, delta_t = self.denominator.delta_t, min_instruments = self.denominator.min_instruments)
+		self.numerator = inspiral_lr.DatalessLnSignalDensity(*args, **kwargs)
+		self.denominator = inspiral_lr.DatalessLnNoiseDensity(*args, **kwargs)
 
-	#
-	# do not allow I/O.  the on-disk representation would be
-	# indistinguishable from a genuine ranking statistic object, and
-	# could lead to accidents
-	#
-
-	@classmethod
-	def from_xml(cls, *args, **kwargs):
-		raise NotImplementedError
-
-	def to_xml(self, *args, **kwargs):
-		raise NotImplementedError
+	def finish(self):
+		# no zero-lag
+		self.numerator.finish()
+		self.denominator.finish()
 
 
 #
diff --git a/gstlal-inspiral/python/inspiral.py b/gstlal-inspiral/python/inspiral.py
index affadcff04..72ff7c73d6 100644
--- a/gstlal-inspiral/python/inspiral.py
+++ b/gstlal-inspiral/python/inspiral.py
@@ -514,7 +514,7 @@ class Data(object):
 			coincidence_threshold = rankingstat.delta_t,
 			thinca_interval = thinca_interval,	# seconds
 			min_instruments = rankingstat.min_instruments,
-			#min_log_L = min_log_L,	# FIXME: temporarily disabled until dataless ranking stat implementation is complete
+			min_log_L = min_log_L,
 			sngls_snr_threshold = sngls_snr_threshold
 		)
 
@@ -595,11 +595,15 @@ class Data(object):
 		# the dataless ranking statistic variant
 		#
 
-		# FIXME:  temporarily disabled until dataless ranking stat is working
-		#if self.likelihood_snapshot_interval is None and min_log_L is not None:
-		#	dataless_rankingstat = far.DatalessRankingStat(instruments = rankingstat.instruments, min_instruments = rankingstat.min_instruments, delta_t = rankingstat.delta_t)
-		#	dataless_rankingstat.finish()
-		#	self.stream_thinca.rankingstat = dataless_rankingstat
+		if self.likelihood_snapshot_interval is None and min_log_L is not None:
+			dataless_rankingstat = far.DatalessRankingStat(
+				template_ids = rankingstat.template_ids,
+				instruments = rankingstat.instruments,
+				min_instruments = rankingstat.min_instruments,
+				delta_t = rankingstat.delta_t
+			)
+			dataless_rankingstat.finish()
+			self.stream_thinca.rankingstat = dataless_rankingstat
 
 		#
 		# Fun output stuff
diff --git a/gstlal-inspiral/python/stats/inspiral_lr.py b/gstlal-inspiral/python/stats/inspiral_lr.py
index 3cd644c85d..0feaadbaad 100644
--- a/gstlal-inspiral/python/stats/inspiral_lr.py
+++ b/gstlal-inspiral/python/stats/inspiral_lr.py
@@ -484,26 +484,36 @@ class DatalessLnSignalDensity(LnSignalDensity):
 
 	Used, for example, to implement low-significance candidate culls,
 	etc.
+
+	Assumes all available instruments are on and have the same horizon
+	distance, and assess candidates based only on SNR and \chi^2
+	distributions.
 	"""
+	def __init__(self, *args, **kwargs):
+		super(DatalessLnSignalDensity, self).__init__(*args, **kwargs)
+		# so we're ready to go!
+		self.add_signal_model()
 
-	#
-	# assume all instruments have this horizon distance, all the time
-	#
+	def __call__(self, segments, snrs, phase, dt, **kwargs):
+		# evaluate P(t) \propto number of templates
+		lnP = math.log(len(self.template_ids))
 
-	class FixedHorizon(object):
-		def __getitem__(self, item):
-			return 100.0
+		# evaluate SNR PDF.  assume all instruments have 100 Mpc
+		# horizon distance
+		horizons = dict.fromkeys(segments, 100.)
+		lnP += self.SNRPDF.lnP_instruments(snrs.keys(), horizons, self.min_instruments) + self.SNRPDF.lnP_snrs(snrs, horizons, self.min_instruments)
 
-	def __init__(self, *args, **kwargs):
-		super(DatalessLnSignalDensity, self).__init__(*args, **kwargs)
-		# replace horizon_history's contents with our FixedHorizon
-		# hack
-		for key in self.horizon_history:
-			self.horizon_history[key] = self.FixedHorizon()
+		# evalute the (snr, \chi^2 | snr) PDFs (same for all
+		# instruments)
+		interp = self.interps["snr_chi"]
+		return lnP + sum(interp(*value) for name, value in kwargs.items() if name.endswith("_snr_chi"))
 
 	def __iadd__(self, other):
 		raise NotImplementedError
 
+	def increment(self, *args, **kwargs):
+		raise NotImplementedError
+
 	def copy(self):
 		raise NotImplementedError
 
@@ -641,25 +651,29 @@ class LnNoiseDensity(LnLRDensity):
 		# extrapolated background.
 		#
 
+		# pick a canonical PDF to definine the binning (we assume
+		# they're all the same and only compute this array once to
+		# save time
+		lnpdf = self.densities.values()[0]
+		arr = numpy.zeros_like(lnpdf.array)
+
+		snrindices, rcossindices = lnpdf.bins[self.snr_min:1e10, 1e-6:1e2]
+		snr, dsnr = lnpdf.bins[0].centres()[snrindices], lnpdf.bins[0].upper()[snrindices] - lnpdf.bins[0].lower()[snrindices]
+		rcoss, drcoss = lnpdf.bins[1].centres()[rcossindices], lnpdf.bins[1].upper()[rcossindices] - lnpdf.bins[1].lower()[rcossindices]
+
+		prcoss = numpy.ones(len(rcoss))
+		psnr = 1e-8 * snr**-6 #(1. + 10**6) / (1. + snr**6)
+		psnrdcoss = numpy.outer(numpy.exp(-(snr - 2**.5)**2/ 2.) * dsnr, numpy.exp(-(rcoss - .05)**2 / .00015*2) * drcoss)
+		arr[snrindices, rcossindices] = psnrdcoss
+
+		# normalize to the requested count.  give 99% of the
+		# requested events to this portion of the model
+		arr *= 0.99 * number_of_events / arr.sum()
+
 		for lnpdf in self.densities.values():
-			# will need to normalize results so need new
-			# storage
-			arr = numpy.zeros_like(lnpdf.array)
-
-			snrindices, rcossindices = lnpdf.bins[self.snr_min:1e10, 1e-6:1e2]
-			snr, dsnr = lnpdf.bins[0].centres()[snrindices], lnpdf.bins[0].upper()[snrindices] - lnpdf.bins[0].lower()[snrindices]
-			rcoss, drcoss = lnpdf.bins[1].centres()[rcossindices], lnpdf.bins[1].upper()[rcossindices] - lnpdf.bins[1].lower()[rcossindices]
-
-			prcoss = numpy.ones(len(rcoss))
-			psnr = 1e-8 * snr**-6 #(1. + 10**6) / (1. + snr**6)
-			psnrdcoss = numpy.outer(numpy.exp(-(snr - 2**.5)**2/ 2.) * dsnr, numpy.exp(-(rcoss - .05)**2 / .00015*2) * drcoss)
-			arr[snrindices, rcossindices] = psnrdcoss 
-
-			# normalize to the requested count.  give 99% of
-			# the requested events to this portion of the model
-			lnpdf.array += arr * (0.99 * number_of_events / arr.sum())
-			# give 1% of the requested events to the "glitch
-			# model"
+			# add in the 99% noise model
+			lnpdf.array += arr
+			# add 1% from the "glitch model"
 			inspiral_extrinsics.NumeratorSNRCHIPDF.add_signal_model(lnpdf, n = 0.01 * number_of_events, prefactors_range = prefactors_range, df = df, inv_snr_pow = inv_snr_pow, snr_min = self.snr_min)
 			# re-normalize
 			lnpdf.normalize()
@@ -785,15 +799,57 @@ class DatalessLnNoiseDensity(LnNoiseDensity):
 
 	Used, for example, to implement low-significance candidate culls,
 	etc.
-	"""
 
+	Assumes all available instruments are on and have the same horizon
+	distance, and assess candidates based only on SNR and \chi^2
+	distributions.
+	"""
 	def __init__(self, *args, **kwargs):
 		super(DatalessLnNoiseDensity, self).__init__(*args, **kwargs)
+		# this a guess at a mass dependent snr chisq prior.  10
+		# *million* events gets the density estimation kernel to be
+		# a sensible size.
+		# FIXME:  initialize from template information instead of
+		# guessing mchirp.
+		mchirp = 0.8
+		self.add_noise_model(number_of_events = 10000000, prefactors_range = ((1. / mchirp)**.33, 25.), df = 40, inv_snr_pow = 3.)
+
+	def __call__(self, segments, snrs, phase, dt, **kwargs):
+		# assume all instruments are on, 1 trigger per second per
+		# template
+		triggers_per_second_per_template = dict.fromkeys(segments, 1.)
+
+		# P(t | noise) = (candidates per unit time @ t) / total
+		# candidates.  by not normalizing by the total candidates
+		# the return value can only ever be proportional to the
+		# probability density, but we avoid the problem of the
+		# ranking statistic definition changing on-the-fly while
+		# running online, allowing candidates collected later to
+		# have their ranking statistics compared meaningfully to
+		# the values assigned to candidates collected earlier, when
+		# the total number of candidates was smaller.
+		lnP = math.log(sum(self.coinc_rates.strict_coinc_rates(**triggers_per_second_per_template).values()) * len(self.template_ids))
+
+		# P(instruments | t, noise)
+		lnP += self.coinc_rates.lnP_instruments(**triggers_per_second_per_template)[frozenset(snrs)]
+
+		# evaluate the SNR, \chi^2 factors
+		interps = self.interps
+		return lnP + sum(interps[name](*value) for name, value in kwargs.items() if name in interps)
 
 	def random_params(self):
 		# won't work
 		raise NotImplementedError
 
+	def __iadd__(self, other):
+		raise NotImplementedError
+
+	def increment(self, *args, **kwargs):
+		raise NotImplementedError
+
+	def copy(self):
+		raise NotImplementedError
+
 	def to_xml(self, name):
 		# I/O not permitted:  the on-disk version would be
 		# indistinguishable from a real ranking statistic and could
diff --git a/gstlal-inspiral/share/O2/Makefile.BNS_test_dag b/gstlal-inspiral/share/O2/Makefile.BNS_test_dag
index f66b590aa7..cda1273433 100644
--- a/gstlal-inspiral/share/O2/Makefile.BNS_test_dag
+++ b/gstlal-inspiral/share/O2/Makefile.BNS_test_dag
@@ -184,7 +184,7 @@ all : dag SNR_sed
 SNR_sed : gstlal_inspiral_injection_snr.sub
 	sed -i 's@environment = GST_REGISTRY_UPDATE=no;@environment = "GST_REGISTRY_UPDATE=no LD_PRELOAD=${MKLROOT}/lib/intel64/libmkl_core.so"@g' gstlal_inspiral_injection_snr.sub
 
-dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES) reference_likelihood_file.xml.gz
+dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES)
 	gstlal_inspiral_pipe \
 		--data-source frames \
 		--gps-start-time $(START) \
@@ -214,18 +214,9 @@ dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WE
 		--request-cpu 2 \
 		--request-memory 5GB \
 		--min-log-L 4. \
-		--min-instruments $(MIN_IFOS) \
-		--reference-likelihood-file reference_likelihood_file.xml.gz
+		--min-instruments $(MIN_IFOS)
 	sed -i '1s/^/JOBSTATE_LOG logs\/trigger_pipe.jobstate.log\n/' trigger_pipe.dag
 
-reference_likelihood_file.xml.gz:
-	gstlal_inspiral_fake_diststats \
-		--segment-and-horizon=H1:$(H1PRIORSTART):$(H1PRIORSTOP):$(H1PRIORRANGE) \
-		--segment-and-horizon=L1:$(L1PRIORSTART):$(L1PRIORSTOP):$(L1PRIORRANGE) \
-		--output $@ \
-		--min-instruments $(MIN_IFOS) \
-		--verbose
-
 %_split_bank.cache : H1-TMPLTBANK-$(START)-2048.xml
 	mkdir -p $*_split_bank
 	gstlal_bank_splitter \
diff --git a/gstlal-inspiral/share/O2/Makefile.O2_offline_dag b/gstlal-inspiral/share/O2/Makefile.O2_offline_dag
index f7ef9eb3ae..3022174bc4 100644
--- a/gstlal-inspiral/share/O2/Makefile.O2_offline_dag
+++ b/gstlal-inspiral/share/O2/Makefile.O2_offline_dag
@@ -127,19 +127,6 @@ L1_CHANNEL=GDS-CALIB_STRAIN
 #L1_CHANNEL=
 CHANNEL_NAMES:=--channel-name=H1=$(H1_CHANNEL) --channel-name=L1=$(L1_CHANNEL)
 
-#######################################################
-# Set ranges and times for reference likelihood files #
-#######################################################
-
-# NOTE needed to make 10000s duration to get sufficient zero lag triggers
-H1PRIORSTART=$(shell python -c "print $(shell lalapps_tconvert)-15000")
-H1PRIORSTOP=$(shell python -c "print $(shell lalapps_tconvert)-5000")
-L1PRIORSTART=$(shell python -c "print $(shell lalapps_tconvert)-10000")
-L1PRIORSTOP=$(shell python -c "print $(shell lalapps_tconvert)")
-H1PRIORRANGE=60
-L1PRIORRANGE=80
-# L1 was typically more sensitive than H1 during O2 (at least chunk 1)
-
 ###################################################################################
 # Get some basic definitions.  NOTE this comes from the share directory probably. #
 ###################################################################################
@@ -158,7 +145,7 @@ SNR_sed : gstlal_inspiral_injection_snr.sub
 	sed -i 's@environment = GST_REGISTRY_UPDATE=no;@environment = "GST_REGISTRY_UPDATE=no LD_PRELOAD=${MKLROOT}/lib/intel64/libmkl_core.so"@g' gstlal_inspiral_injection_snr.sub
 
 # Run inspiral pipe to produce dag
-dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES) reference_likelihood_file.xml.gz
+dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES)
 	gstlal_inspiral_pipe \
 		--data-source frames \
 		--gps-start-time $(START) \
@@ -184,23 +171,13 @@ dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WE
 		$(ADDITIONAL_DAG_OPTIONS) \
 		$(CONDOR_COMMANDS) \
 		--ht-gate-threshold-linear 0.8:15.0-45.0:100.0 \
-		--min-log-L 3.5 \
+		--min-log-L -50.0 \
 		--singles-threshold 100.0 \
 		--request-cpu 2 \
 		--request-memory 5GB \
-		--min-instruments $(MIN_IFOS) \
-		--reference-likelihood-file reference_likelihood_file.xml.gz
+		--min-instruments $(MIN_IFOS)
 	sed -i '1s/^/JOBSTATE_LOG logs\/trigger_pipe.jobstate.log\n/' trigger_pipe.dag
 
-# Produce refrence likelihood file
-reference_likelihood_file.xml.gz :
-	gstlal_inspiral_fake_diststats \
-		--segment-and-horizon=H1:$(H1PRIORSTART):$(H1PRIORSTOP):$(H1PRIORRANGE) \
-		--segment-and-horizon=L1:$(L1PRIORSTART):$(L1PRIORSTOP):$(L1PRIORRANGE) \
-		--output $@ \
-		--min-instruments $(MIN_IFOS) \
-		--verbose
-
 # Produce split banks
 %_split_bank.cache : gstlal_bank.xml.gz
 	mkdir -p $*_split_bank
diff --git a/gstlal-inspiral/share/O2/Makefile.O2_offline_hybridbank_dag b/gstlal-inspiral/share/O2/Makefile.O2_offline_hybridbank_dag
index 5c28918c0c..c5f04ea771 100644
--- a/gstlal-inspiral/share/O2/Makefile.O2_offline_hybridbank_dag
+++ b/gstlal-inspiral/share/O2/Makefile.O2_offline_hybridbank_dag
@@ -131,19 +131,6 @@ L1_CHANNEL=GDS-CALIB_STRAIN
 #L1_CHANNEL=
 CHANNEL_NAMES:=--channel-name=H1=$(H1_CHANNEL) --channel-name=L1=$(L1_CHANNEL)
 
-#######################################################
-# Set ranges and times for reference likelihood files #
-#######################################################
-
-# NOTE needed to make 10000s duration to get sufficient zero lag triggers
-H1PRIORSTART=$(shell python -c "print $(shell lalapps_tconvert)-15000")
-H1PRIORSTOP=$(shell python -c "print $(shell lalapps_tconvert)-5000")
-L1PRIORSTART=$(shell python -c "print $(shell lalapps_tconvert)-10000")
-L1PRIORSTOP=$(shell python -c "print $(shell lalapps_tconvert)")
-H1PRIORRANGE=60
-L1PRIORRANGE=80
-# L1 was typically more sensitive than H1 during O2 (at least chunk 1)
-
 ###################################################################################
 # Get some basic definitions.  NOTE this comes from the share directory probably. #
 ###################################################################################
@@ -167,7 +154,7 @@ SNR_sed : gstlal_inspiral_injection_snr.sub
 	sed -i 's@environment = GST_REGISTRY_UPDATE=no;@environment = "GST_REGISTRY_UPDATE=no LD_PRELOAD=${MKLROOT}/lib/intel64/libmkl_core.so"@g' gstlal_inspiral_injection_snr.sub
 
 # Run inspiral pipe to produce dag
-dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES) reference_likelihood_file.xml.gz
+dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WEBDIR) $(INJECTIONS) $(BANK_CACHE_FILES)
 	gstlal_inspiral_pipe \
 		--data-source frames \
 		--gps-start-time $(START) \
@@ -195,23 +182,13 @@ dag : segments.xml.gz vetoes.xml.gz frame.cache inj_tisi.xml tisi.xml plots $(WE
 		$(ADDITIONAL_DAG_OPTIONS) \
 		$(CONDOR_COMMANDS) \
 		--ht-gate-threshold-linear 0.8:15.0-45.0:100.0 \
-		--min-log-L 3.5 \
+		--min-log-L -50.0 \
 		--singles-threshold 100.0 \
 		--request-cpu 2 \
 		--request-memory 5GB \
-		--min-instruments $(MIN_IFOS) \
-		--reference-likelihood-file reference_likelihood_file.xml.gz
+		--min-instruments $(MIN_IFOS)
 	sed -i '1s/^/JOBSTATE_LOG logs\/trigger_pipe.jobstate.log\n/' trigger_pipe.dag
 
-# Produce refrence likelihood file
-reference_likelihood_file.xml.gz :
-	gstlal_inspiral_fake_diststats \
-		--segment-and-horizon=H1:$(H1PRIORSTART):$(H1PRIORSTOP):$(H1PRIORRANGE) \
-		--segment-and-horizon=L1:$(L1PRIORSTART):$(L1PRIORSTOP):$(L1PRIORRANGE) \
-		--output $@ \
-		--min-instruments $(MIN_IFOS) \
-		--verbose
-
 # Produce split banks #FIXME REPLACE BANK FILES
 %_split_bank_0.cache : bank_mtotal80split_00.xml.gz
 	mkdir -p $*_split_bank_0
diff --git a/gstlal-inspiral/share/O2/Makefile.O2_offline_injections_dag b/gstlal-inspiral/share/O2/Makefile.O2_offline_injections_dag
index 7016a17093..31c9dabc6a 100644
--- a/gstlal-inspiral/share/O2/Makefile.O2_offline_injections_dag
+++ b/gstlal-inspiral/share/O2/Makefile.O2_offline_injections_dag
@@ -121,7 +121,7 @@ dag : svd_bank.cache dist_stats.cache $(REF_PSD) $(ZERO_LAG_DB) $(SEGMENTS) $(VE
 		--reference-likelihood-file reference_likelihood_file.xml.gz \
 		--request-cpu 4 \
 		--request-memory 7GB \
-		--min-log-L 4. \
+		--min-log-L -50.0 \
 		--min-instruments 1 \
 		$(ADDITIONAL_DAG_OPTIONS)
 	sed -i '1s/^/JOBSTATE_LOG logs\/trigger_pipe.jobstate.log\n/' trigger_pipe.dag
diff --git a/gstlal-inspiral/share/O2/Makefile.online_analysis b/gstlal-inspiral/share/O2/Makefile.online_analysis
index 9a09b71103..655c0e69f1 100644
--- a/gstlal-inspiral/share/O2/Makefile.online_analysis
+++ b/gstlal-inspiral/share/O2/Makefile.online_analysis
@@ -152,7 +152,7 @@ dag : marginalized_likelihood.xml.gz prior.cache plots ll_simplify_and_cluster.s
 		--injection-file $(NSBHINJFILE) \
 		--injection-file $(BBHINJFILE) \
 		--time-slide-file tisi.xml
-		#--min-log-L 2 \
+		#--min-log-L -50.0 \
 
 ll_simplify_and_cluster.sql:
 	wget http://versions.ligo.org/cgit/gstlal/plain/gstlal-inspiral/share/ll_simplify_and_cluster.sql
-- 
GitLab