gstlal-inspiral  1.9.2
 All Classes Namespaces Files Functions
gstlal_inspiral_marginalize_likelihoods_online
1 #!/bin/bash
2 #
3 # Copyright (C) 2012,2014 Kipp Cannon
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 ### This program runs gstlal_inspiral_marginalize_likelihood in a while True
20 ### loop; See gstlal_inspiral_marginalize_likelihoods_online for more details
21 ###
22 ###
23 ### This program is not meant to be executed standalone by a user. It should be
24 ### part of a DAG managing a running gstlal_inspiral online analysis.
25 ###
26 ### This program takes two or more arguments;
27 ###
28 ### 1. The path of the output file name
29 ### 2. One or more paths to text files each containing a single line giving
30 ### the root URL of a web server from which to retrieve event parameter
31 ### distribution data (e.g., "http://node001.ligo.caltech.edu")
32 ###
33 ### This program queries each running gstlal_inspiral job via the URL,
34 ### computes PDFs of the likelihood ratio ranking statistics from the
35 ### parameter distribution data, then marginalizes the ranking statistic PDFs
36 ### across jobs and writes the result to the given output file.
37 ###
38 ### It continues to do that in an infinite loop with a 10 minute pause on
39 ### each iteration. Files are not overwritten directly, but rather via a
40 ### temporary file and mv operation to ensure that no files are corrupted in
41 ### a POSIX file environment.
42 ###
43 ### Review status
44 ### -------------
45 ###
46 ### +---------------------------------------------+---------------------------------------------+------------+
47 ### | Names | Hash | Date |
48 ### +=============================================+=============================================+============+
49 ### | Florent, Jolien, Kipp, Chad | 0e96523b8846e5a4597ba3477c8462443470cd94 | 2015-05-15 |
50 ### +---------------------------------------------+---------------------------------------------+------------+
51 ###
52 
53 #
54 # get the output file name
55 #
56 
57 OUTPUT="${1}"
58 shift
59 
60 #
61 # paths to data objects on each job's web management interface
62 #
63 
64 LIKELIHOOD_PATH="rankingstat.xml"
65 ZEROLAG_COUNTS_PATH="zerolag_rankingstatpdf.xml"
66 
67 #
68 # pause for each iteration (seconds)
69 #
70 
71 SLEEP="600"
72 
73 #
74 # loop forever
75 #
76 
77 while true ; do
78  echo "... sleeping for ${SLEEP} seconds ..."
79  sleep ${SLEEP}
80 
81  # collect the current coinc parameter PDF data from each job, and
82  # run some iterations of the ranking statistic sampler to generate
83  # noise and signal model ranking statistic histograms for each job.
84  # NOTE: the zero-lag ranking statistic histograms in the files
85  # generated here are all 0.
86  RANKING_PDF_FILES=
87  for REG in "$@" ; do
88  date +"%H:%M:%S" >&2
89  SERVER=$(cat ${REG}) || exit 1
90  RANKING_PDF_FILE=$(mktemp --suffix .xml.gz) || exit 1
91  RANKING_PDF_FILES="${RANKING_PDF_FILES} ${RANKING_PDF_FILE}"
92  # get 4,000,000 samples total
93  echo gstlal_inspiral_calc_rank_pdfs --verbose --ranking-stat-samples $(python -c "print 10000000 / $#") --output ${RANKING_PDF_FILE} ${SERVER}${LIKELIHOOD_PATH} || exit 1
94  gstlal_inspiral_calc_rank_pdfs --verbose --ranking-stat-samples $(python -c "print 10000000 / $#") --output ${RANKING_PDF_FILE} ${SERVER}${LIKELIHOOD_PATH} || exit 1
95  done || break
96  date +"%H:%M:%S" >&2
97 
98  # sum the noise and signal model ranking statistic histograms
99  # across jobs, and collect and sum the current observed zero-lag
100  # ranking statistic histograms from all jobs. combine with the
101  # noise and signal model ranking statistic histograms. NOTE: the
102  # noise and signal model ranking statistic histograms in the
103  # zero-lag counts files downloaded from the jobs must be all 0, and
104  # the zero-lag counts in the output generated by
105  # gstlal_inspiral_calc_rank_pdfs must be 0. NOTE: this is where
106  # the zero-lag counts have the density estimation transform
107  # applied.
108  ZEROLAG_COUNTS_URLS=
109  for REG in gstlal_ll_inspiral_trigger_counter_registry.txt ; do
110  SERVER=$(cat ${REG}) || exit 1
111  ZEROLAG_COUNTS_URLS="${ZEROLAG_COUNTS_URLS} ${SERVER}${ZEROLAG_COUNTS_PATH}"
112  done || break
113  # NOTE comment this to unmix in previous samples
114  if [ -f ${OUTPUT} ]; then
115  cp -v ${OUTPUT} prev_${OUTPUT}
116  PREV_OUTPUT=prev_${OUTPUT}
117  gstlal_inspiral_reset_zerolag_counts ${PREV_OUTPUT}
118  else
119  PREV_OUTPUT=""
120  fi
121  echo "Previous output: " ${PREV_OUTPUT}
122  #PREV_OUTPUT=""
123  # ENDNOTE
124  gstlal_inspiral_marginalize_likelihood --verbose --marginalize ranking-stat-pdf --density-estimate-zero-lag --output ${OUTPUT} ${RANKING_PDF_FILES} ${PREV_OUTPUT} ${ZEROLAG_COUNTS_URLS} || break
125  date +"%H:%M:%S" >&2
126  rm -vf ${RANKING_PDF_FILES}
127 done
128 
129 #
130 # if this program ends its an error, always, so condor will restart it
131 #
132 
133 exit 1