1 -- Copyright (C) 2011--2012,2014,2015 Kipp Cannon, Chad Hanna
3 -- This program is free software; you can redistribute it and/or modify it
4 -- under the terms of the GNU General Public License as published by the
5 -- Free Software Foundation; either version 2 of the License, or (at your
6 -- option) any later version.
8 -- This program is distributed in the hope that it will be useful, but
9 -- WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 -- Public License for more details.
13 -- You should have received a copy of the GNU General Public License along
14 -- with this program; if not, write to the Free Software Foundation, Inc.,
15 -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 DROP table if EXISTS sim_inspiral;
20 -- process clean up. same computer, unix process ID, and start time =
24 CREATE INDEX tmpindex ON process (node, unix_procid, start_time);
25 CREATE TEMPORARY TABLE __idmap__ AS
27 old.process_id AS old,
28 MIN(new.process_id) AS new
31 JOIN process AS new ON (
33 AND new.unix_procid == old.unix_procid
34 AND new.start_time == old.start_time
39 CREATE INDEX tmpindex ON __idmap__ (old);
40 CREATE INDEX tmpindex2 ON __idmap__ (new, old);
42 UPDATE coinc_event SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
43 UPDATE segment SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
44 UPDATE segment_definer SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
45 UPDATE segment_summary SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
46 UPDATE sngl_inspiral SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
47 UPDATE time_slide SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
49 DELETE FROM process WHERE process_id IN (SELECT old FROM __idmap__ WHERE old != new);
50 DELETE FROM process_params WHERE process_id NOT IN (SELECT process_id FROM process);
57 -- coinc_definer clean up
60 CREATE TEMPORARY TABLE __idmap__ AS
62 old.coinc_def_id AS old,
63 MIN(new.coinc_def_id) AS new
66 JOIN coinc_definer AS new ON (
67 new.search == old.search
68 AND new.search_coinc_type == old.search_coinc_type
72 CREATE INDEX tmpindex ON __idmap__ (old);
73 CREATE INDEX tmpindex2 ON __idmap__ (new, old);
75 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM __idmap__ WHERE old == coinc_def_id);
76 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM __idmap__ WHERE old != new);
83 -- segment_definer clean up. NOTE: this assumes no meaningful information
84 -- is stored in the version and comment columns, and will scramble it if
85 -- there is. that is, two segment_definer rows are considered to be
86 -- equivalent even if their version and comment values differ, and the one
87 -- with the higher ID will be discarded.
90 CREATE TEMPORARY TABLE __idmap__ AS
92 old.segment_def_id AS old,
93 MIN(new.segment_def_id) AS new
95 segment_definer AS old
96 JOIN segment_definer AS new ON (
98 AND new.name == old.name
102 CREATE INDEX tmpindex ON __idmap__ (old);
104 UPDATE segment_summary SET segment_def_id = (SELECT new FROM __idmap__ WHERE old == segment_def_id);
105 UPDATE segment SET segment_def_id = (SELECT new FROM __idmap__ WHERE old == segment_def_id);
106 DELETE FROM segment_definer WHERE segment_def_id IN (SELECT old FROM __idmap__ WHERE old != new);
109 DROP TABLE __idmap__;
112 -- segment clean up. NOTE: this assumes that nothing references segment
113 -- rows by ID, so that redundant rows can be deleted without correcting
114 -- references to their IDs in other tables
117 CREATE INDEX tmpindex ON segment(segment_def_id, start_time, start_time_ns, end_time, end_time_ns, segment_id);
128 other.segment_def_id == segment.segment_def_id
129 AND other.start_time == segment.start_time
130 AND other.start_time_ns == segment.start_time_ns
131 AND other.end_time == segment.end_time
132 AND other.end_time_ns == segment.end_time_ns
133 AND other.segment_id < segment.segment_id
138 -- time_slide clean up
141 CREATE TEMPORARY TABLE __idmap__ AS
143 time_slide_id AS old,
144 (SELECT group_concat(instrument || "=" || offset) FROM time_slide AS time_slide_a WHERE time_slide_a.time_slide_id == time_slide.time_slide_id ORDER BY instrument) AS repr,
150 CREATE INDEX tmpindex ON __idmap__ (repr, old);
152 UPDATE __idmap__ SET new = (SELECT MIN(old) FROM __idmap__ AS a WHERE a.repr == __idmap__.repr);
154 CREATE INDEX tmpindex ON __idmap__ (old);
156 UPDATE coinc_event SET time_slide_id = (SELECT __idmap__.new FROM __idmap__ WHERE __idmap__.old == time_slide_id);
157 DELETE FROM time_slide WHERE time_slide_id IN (SELECT old FROM __idmap__ WHERE old != new);
160 DROP TABLE __idmap__;
169 "Number of coincs before clustering: " || count(*)
174 -- create a look-up table of info required for clustering
177 CREATE INDEX tmpindex1 ON coinc_event_map (coinc_event_id);
178 CREATE INDEX tmpindex2 ON coinc_event (coinc_event_id);
180 CREATE TEMPORARY TABLE _cluster_info_ AS
182 coinc_event.coinc_event_id AS coinc_event_id,
183 coinc_event.time_slide_id AS category,
184 (coinc_inspiral.end_time - (SELECT MIN(end_time) FROM coinc_inspiral)) + 1e-9 * coinc_inspiral.end_time_ns AS end_time,
185 coinc_inspiral.snr AS snr,
186 -- NOTE FIXME we are using bank_chisq to hold a chisq weighted snr value
187 (SELECT SUM(sngl.bank_chisq * sngl.bank_chisq) FROM sngl_inspiral as sngl WHERE sngl.event_id IN (SELECT event_id FROM coinc_event_map WHERE coinc_event_map.coinc_event_id == coinc_event.coinc_event_id)) AS ranking_stat
190 JOIN coinc_inspiral ON (
191 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
193 DROP INDEX tmpindex1;
194 DROP INDEX tmpindex2;
196 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
197 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
200 -- delete coincs that are within 1 s of coincs with higher ranking
201 -- statistic in the same category. break ties by root-sum-square of SNRs,
202 -- break ties by coinc_event_id
212 _cluster_info_ AS _cluster_info_a_
213 JOIN _cluster_info_ AS _cluster_info_b_ ON (
214 _cluster_info_b_.category == _cluster_info_a_.category
215 AND (_cluster_info_b_.end_time BETWEEN _cluster_info_a_.end_time - 0.1 AND _cluster_info_a_.end_time + 0.1)
216 AND (_cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat OR
217 _cluster_info_b_.ranking_stat == _cluster_info_a_.ranking_stat AND (_cluster_info_b_.snr > _cluster_info_a_.snr OR _cluster_info_b_.snr == _cluster_info_a_.snr AND (_cluster_info_b_.coinc_event_id > _cluster_info_a_.coinc_event_id))
221 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
223 DROP INDEX tmpindex1;
224 DROP INDEX tmpindex2;
225 DROP TABLE _cluster_info_;
228 "Number of coincs after clustering: " || count(*)
233 -- delete unused coinc_inspiral rows
239 coinc_event_id NOT IN (
247 -- delete unused coinc_event_map rows
253 coinc_event_id NOT IN (
261 -- delete unused sngl_inspiral rows
267 sngl_inspiral.snr < (
269 -- if they aren't all the same err on the size of
275 program == "gstlal_inspiral"
276 AND param == "--singles-threshold"
278 AND event_id NOT IN (
284 table_name == 'sngl_inspiral'