source: trunk/DataCheck/QuickLook/FlareAlerts.sh@ 18790

Last change on this file since 18790 was 18783, checked in by Daniela Dorner, 8 years ago
added amon alerts (sending of alert, trigger criteria still to be defined)
  • Property svn:executable set to *
File size: 26.2 KB
Line 
1#!/bin/bash
2#
3
4# missing:
5# implement DB-entries for being called
6# prepare directly template for email
7# use current value for CU in triggers
8# add note for values > 70 evts/h for X-ray triggers
9#
10# add more information:
11# mjd, obs-summary, weather info (clouds? dust?), CU, corrected excrates
12#
13# evaluate output of all nights (check also for crab to estimate fluctuations)
14# error emails in case no DB content / no QLA
15# calculate delay of QLA and send email if > 30 Min
16
17# run for more nights:
18# for (( i=0; i < 70 ; i++)); do date=`date --date="-${i}days" +%Y%m%d`; /home/fact/SW.automatic.processing/DataCheck/QuickLook/FlareAlerts.sh $date; done > logfile
19
20source `dirname $0`/../Sourcefile.sh
21printprocesslog "INFO starting $0"
22
23emailfrom=dorner@astro.uni-wuerzburg.de
24emailto=fact-online@lists.phys.ethz.ch
25
26logfile=$runlogpath"/FlareAlerts-"$datetime".log"
27date > $logfile
28
29# get date
30if [ "$1" != "" ]
31then
32 checkstring=`echo $1 | grep -E -o '^20[0-9][0-9][01][0-9][0-3][0-9]$'`
33 echo $checkstring
34 if [ "$checkstring" = "" ]
35 then
36 night=`date +%Y%m%d --date="-12 HOUR"`
37 else
38 night=$1
39 fi
40else
41 night=`date +%Y%m%d --date="-12 HOUR"`
42fi
43
44echo "Processing "$night >> $logfile
45
46
47# get sources for current night from DB (RunInfo)
48query="SELECT fSourceKey FROM RunInfo WHERE fNight="$night" AND fRunTypeKey=1 AND NOT ISNULL(fSourceKey) GROUP BY fSourceKey"
49sourcekeys=( `sendquery` )
50if [ ${#sourcekeys[@]} -eq 0 ]
51then
52 echo "no sources found for "$night
53 finish
54fi
55
56printprocesslog "INFO Checking the "${#sourcekeys[@]}" sourcekeys: "${sourcekeys[@]}
57
58# some stuff for queries:
59ontime="IF(ISNULL(fEffectiveOn), fOnTimeAfterCuts, TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)"
60threshold="IF (ISNULL(fThresholdMinSet), fThresholdMedian, fThresholdMinSet)"
61cu="20.0"
62corr="1"
63# missing: corrected excessrates
64# missing: time-dependent CU
65
66function get_query_nightly_binning()
67{
68 # query to get information from DB
69 query="SELECT fSourceKey AS num, "
70 query=$query"fNight AS night, MIN(fRunID) AS runmin, MAX(fRunID) AS runmax, "
71 query=$query"MIN(fRunStart) AS start, MAX(fRunStop) AS stop, "
72 query=$query"ROUND(SUM("$ontime")/3600.,1) AS ontime, "
73 query=$query"SUM(fNumSigEvts) AS sig, SUM(fNumBgEvts) AS bg, "
74 query=$query"ROUND(SUM(fNumBgEvts)/SUM("$ontime")*3600,1) AS bgrate, "
75 query=$query"SUM(fNumExcEvts) AS exc, "
76 query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts)), 1) AS excerr, "
77 query=$query"ROUND(SUM(fNumExcEvts)/SUM("$ontime")*3600,1) AS excrate, "
78 query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600, 1) AS excrateerr, "
79 query=$query"ROUND(SUM(fNumExcEvts*"$corr")/SUM("$ontime")*3600,1) as corexcrate, " # put here correction factor
80 query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600*SUM(fNumExcEvts)/SUM(fNumExcEvts*"$corr"), 1) AS corexcrateerr, " # correctionfactor = exc / exc_cor, put here correction factor
81 query=$query"ROUND(LiMa(SUM(fNumSigEvts), SUM(fNumBgEvts)),1) AS signif, "
82 query=$query"ROUND(SUM(fNumExcEvts)/SUM("$ontime")*3600/"$cu",1) AS cu, " # make value time dependent
83 query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600/"$cu", 1) AS cuerr, " # make value time dependent
84 query=$query"ROUND(SUM(fNumExcEvts*"$corr")/SUM("$ontime")*3600/"$cu",1) as corcu, " # make value time dependent # put here correction factor
85 query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600*SUM(fNumExcEvts)/SUM(fNumExcEvts*"$corr")/"$cu", 1) AS corcuerr, " # correctionfactor = exc / exc_cor # make value time dependent # put here correction factor
86 query=$query"MIN(fZenithDistanceMin) as zdmin, MAX(fZenithDistanceMax) as zdmax, "
87 query=$query"MIN("$threshold") as thmin, MAX("$threshold") as thmax "
88 query=$query"FROM AnalysisResultsRunLP "
89 query=$query"LEFT JOIN RunInfo USING (fNight, fRunID) "
90 query=$query"WHERE fSourceKey="$sourcekey" AND fNight="$night" AND NOT ISNULL(fNumExcEvts) "
91 query=$query"GROUP BY fNight, fSourceKey "
92# query=$query"ORDER BY fRunStart "
93 query=$query"HAVING ontime > 0.5 " # at least 30 minutes of observation
94}
95
96function get_query_minute_binning()
97{
98 # set binning
99 if [ "$1" != "" ]
100 then
101 bin2=$1
102 else
103 bin2=$bin
104 fi
105 # query to get information from DB
106 query="SELECT MAX(o.b) AS num, "
107 query=$query"MIN(o.n) AS night, MIN(o.run) AS runmin, MAX(o.run) AS runmax, "
108 query=$query"MIN(o.start) AS start, MAX(o.stop) AS stop, "
109 query=$query"ROUND(SUM(o.ot)/60.,1) AS ontime, "
110 query=$query"SUM(o.sig) AS sig, SUM(o.bg) AS bg, "
111 query=$query"ROUND(SUM(o.bg)/SUM(o.ot)*3600,1) AS bgrate, "
112 query=$query"SUM(o.exc) AS exc, "
113 query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg)), 1) AS excerr, "
114 query=$query"ROUND(SUM(o.exc)/SUM(o.ot)*3600,1) AS excrate, "
115 query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600, 1) AS excrateerr, "
116 query=$query"ROUND(SUM(o.exccor)/SUM(o.ot)*3600,1) as corexcrate, "
117 query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600*SUM(o.exc)/SUM(o.exccor), 1) AS corexcrateerr, " # correctionfactor = exc / exc_cor
118 query=$query"ROUND(LiMa(SUM(o.sig), SUM(o.bg)),1) AS signif, "
119 query=$query"ROUND(SUM(o.exc)/SUM(o.ot)*3600/o.cu,1) AS cu, "
120 query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600/o.cu, 1) AS cuerr, "
121 query=$query"ROUND(SUM(o.exccor)/SUM(o.ot)*3600/o.cu,1) as corcu, "
122 query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600*SUM(o.exc)/SUM(o.exccor)/o.cu, 1) AS corcuerr, " # correctionfactor = exc / exc_cor
123 query=$query"MIN(o.zdmin) as zdmin, MAX(o.zdmax) as zdmax, "
124 query=$query"MIN(o.th) as thmin, MAX(o.th) as thmax "
125 query=$query"FROM ("
126 query=$query"SELECT "
127 query=$query"fRunID AS run, fNight AS n, "
128 query=$query"@ot:= "$ontime" AS ot, "
129 query=$query"fRunStart AS start, fRunStop AS stop, "
130 query=$query"fNumExcEvts AS exc, fNumBgEvts AS bg, fNumSigEvts AS sig, "
131 query=$query"fNumExcEvts*"$corr" AS exccor, " # put here correction factor
132 query=$query$cu" as cu, " # make value time dependent
133 query=$query"fZenithDistanceMin AS zdmin, fZenithDistanceMax AS zdmax, "
134 query=$query$threshold" AS th, "
135 query=$query"IF (@night=fNight AND FLOOR((@os+@ot)/"$bin2"./60.)<1, @bl, @bl := @bl + 1) AS b, "
136 query=$query"IF (@night=fNight AND FLOOR((@os+@ot)/"$bin2"./60.)<1, @os:=@os + @ot, @os := @ot) AS os, @"
137 query=$query"night :=fNight AS night FROM AnalysisResultsRunLP "
138 query=$query"LEFT JOIN RunInfo USING (fNight, fRunID) "
139 query=$query"CROSS JOIN (SELECT @night :=0, @ot :=0, @os :=0, @bl:=0) PARAMS "
140 query=$query"WHERE fSourceKey="$sourcekey" AND fNight="$night" AND NOT ISNULL(fNumExcEvts) "
141 if [ "$1" != "" ]
142 then
143 query=$query" AND fRunID <="${results[$num+3]}
144 fi
145 query=$query" ORDER BY fRunStart "
146 if [ "$1" != "" ]
147 then
148 query=$query"DESC"
149 fi
150 query=$query" ) o GROUP BY b HAVING ontime > "$bin2"*0.75 ORDER BY start "
151 if [ "$1" != "" ]
152 then
153 query=$query"DESC"
154 fi
155 #echo $query
156}
157
158function print_voevent_file()
159{
160 # put here voevent file
161 # make sure that it is written to amon-folder
162 echo '<?xml version="1.0" ?>'
163 echo '<voe:VOEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
164 echo 'xmlns:voe="http://www.ivoa.net/xml/VOEvent/v2.0"'
165 echo 'xsi:schemaLocation="http://www.ivoa.net/xml/VOEvent/v2.0 http://www.ivoa.net/xml/VOEvent/VOEvent-v2.0.xsd"'
166 echo ' version="2.0" role="test" ivorn="ivo://amon/fact_#5_3772_0">'
167 echo ' <Who>'
168 echo ' <AuthorIVORN>ivo://FACT</AuthorIVORN>'
169 echo ' <Date>'`date +%F\ %H:%M:%S`'</Date>'
170 echo ' </Who>'
171 # FACT = 5 in AMON
172 echo ' <What>'
173 echo ' <Param name="stream" dataType="float" value="5" ucd="meta.number" unit=" ">'
174 echo ' <Description>Stream number</Description>'
175 echo ' </Param>'
176 # event identifier
177 # nightly binning: night+sourcekey
178 # 20 min binning: night+source+?
179 echo ' <Param name="id" dataType="float" value="3772" ucd="meta.number" unit=" ">'
180 echo ' <Description>Id number</Description>'
181 echo ' </Param>'
182 # keep 0 for the beginning
183 # how to handle updates? e.g. in case of full disk and random processing
184 echo ' <Param name="rev" dataType="float" value="0" ucd="meta.number" unit=" ">'
185 echo ' <Description>Revision number</Description>'
186 echo ' </Param>'
187 # what to do with this? in IC it's number of neutrinos, but does number of gammas make sense?
188 # (excevts? depends on time range...)
189 echo ' <Param name="nevents" dataType="float" value="1" ucd="meta.number" unit=" ">'
190 echo ' <Description>Number of events</Description>'
191 echo ' </Param>'
192 # get time window (stop of last - start of first run)
193 # maybe: don't send alert if time window > xxx
194 echo ' <Param name="deltaT" dataType="float" value="0.0" ucd="time.duration" unit="s">'
195 echo ' <Description>Time window of the burst</Description>'
196 echo ' </Param>'
197 # probably 0
198 echo ' <Param name="sigmaT" dataType="float" value="0.0" ucd="time" unit="s">'
199 echo ' <Description>Uncertainty of the time window</Description>'
200 echo ' </Param>'
201 # FPR - to be calculated
202 echo ' <Param name="false_pos" dataType="float" value="-1" ucd="stat.probability" unit="s-1.sr-1 ">'
203 echo ' <Description>False positive rate</Description>'
204 echo ' </Param>'
205 # some significane value - how significant is the alert?
206 # to be discussed and calculated
207 echo ' <Param name="pvalue" dataType="float" value="1.0" ucd="stat.probability" unit=" ">'
208 echo ' <Description>Pvalue</Description>'
209 echo ' </Param>'
210 # use source RA/Dec? but then naming doesn't fit
211 # -> leave empty for the moment
212 echo ' <Param name="point_RA" dataType="float" value="-1.0" ucd="os.eq.ra" unit="deg">'
213 echo ' <Description>Pointing RA</Description>'
214 echo ' </Param>'
215 echo ' <Param name="point_dec" dataType="float" value="-1.0" ucd="os.eq.dec" unit="deg">'
216 echo ' <Description>Pointing Dec</Description>'
217 echo ' </Param>'
218 # shape of psf - to be determined - fit thetaplot? for crab or mc
219 echo ' <Param name="psf_type" dataType="string" value="fisher" ucd="meta.code.multip" unit=" ">'
220 echo ' <Description>Type of psf (skymap, fisher, kent, king)</Description>'
221 echo ' </Param>'
222 echo ' <Group name="aux_params">'
223 # which other information to add?
224 echo ' <Param name="zenith" dataType="float" value="0.0" ucd="os.lc.ze" unit="deg"/>'
225 echo ' <Param name="xyz" dataType="float" value="0.0" ucd="os.lc.ze" unit="xyz"/>'
226 echo ' </Group>'
227 echo ' </What>'
228 echo ' <WhereWhen>'
229 echo ' <ObsDataLocation>'
230 echo ' <ObservatoryLocation>'
231 echo ' <AstroCoordSystem id="UTC-GEOD-TOPO"/>'
232 echo ' <AstroCoords coord_system_id="UTC-GEOD-TOPO">'
233 echo ' <Position3D unit="deg-deg-m">'
234 echo ' <Name1>longitude</Name1>'
235 echo ' <Name2>latitude</Name2>'
236 echo ' <Name3>elevation</Name3>'
237 echo ' <Value3>'
238 echo ' <C1>-17.88</C1>'
239 echo ' <C2>28.76</C2>'
240 echo ' <C3>2200</C3>'
241 echo ' </Value3>'
242 echo ' </Position3D>'
243 echo ' </AstroCoords>'
244 echo ' </ObservatoryLocation>'
245 echo ' <ObservationLocation>'
246 echo ' <AstroCoordSystem id="UTC-ICRS-TOPO"/>'
247 echo ' <AstroCoords coord_system_id="UTC-ICRS-TOPO">'
248 echo ' <Time unit="s">'
249 echo ' <TimeInstant>'
250 # python needs the .0 in the time-format - as I don't have the time more accurately here, I put .0
251 echo ' <ISOTime>'${results[$num+4]}' '${results[$num+5]}'.0</ISOTime>'
252 echo ' </TimeInstant>'
253 echo ' </Time>'
254 echo ' <Position2D unit="deg-deg">'
255 echo ' <Name1>RA</Name1>'
256 echo ' <Name2>Dec</Name2>'
257 echo ' <Value2>'
258 echo ' <C1>'${sourceinfo[2]}'</C1>' # RA in deg
259 echo ' <C2>'${sourceinfo[0]}'</C2>' # decl in deg
260 echo ' </Value2>'
261 echo ' <Error2Radius>0.1</Error2Radius>' # PSF of FACT
262 echo ' </Position2D>'
263 echo ' </AstroCoords>'
264 echo ' </ObservationLocation>'
265 echo ' </ObsDataLocation>'
266 echo ' </WhereWhen>'
267 echo ' <Description>FACT flare event information</Description>'
268 echo '</voe:VOEvent>'
269
270}
271
272function evaluate_result()
273{
274 oldexc=0
275 exc=0
276 excold=0
277 slope=0
278 slopeprev=0
279 i=0
280 # be careful with start and stop (space inbetween) -> 27 columns instead of 25
281 while [ 0 -lt 1 ]
282 do
283 trigger=0
284 num=`echo "$i * 27" | bc -l`
285 if [ "${results[$num]}" = "" ]
286 then
287 break
288 fi
289 #night=${results[$num+1]}
290 runid=${results[$num+2]}
291 sig=${results[$num+18]} # significance
292 #exc=${results[$num+14]} # excrate
293 excold=$exc
294 exc=${results[$num+19]} # excrate in CU
295
296 if [ "$onlyifhigher" = "yes" ]
297 then
298 higher=` echo " $exc > $oldexc " | bc `
299 if [ $higher -eq 1 ]
300 then
301 # keep old value
302 oldexc=$exc
303 fi
304 fi
305
306 if [ "$bin" = "" ]
307 then
308 echo " ontime: "${results[$num+8]}" h" >> $logfile
309 fi
310
311 # fast rise/decay trigger
312 if [ $triggertype -eq 3 ]
313 then
314 slopeprev=$slope
315 sigprev=$sig
316 if [ "$excold" = "0" ]
317 then
318 slope=0
319 else
320 slope=`echo " scale=1; ( $exc - $excold ) / ( $bin / 60. ) " | bc -l `
321 fi
322 get_query_minute_binning 60
323 #echo $query
324 results2=( `sendquery` )
325 # need to check last hour backward
326 if [ "${results2[19]}" = "" ]
327 then
328 slope60=0
329 sig60=0
330 else
331 sig60=${results2[18]} # significance 1h
332 if [ "${results2[27+19]}" = "" ]
333 then
334 # maybe treat this case differently
335 slope60=${results2[19]}
336 else
337 slope60=`echo " ${results2[19]} - ${results2[27+19]} " | bc -l` # ie /1h
338 fi
339 fi
340 #echo "exc "$exc" excold "$excold
341 #echo "slope "$slope" prev "$slopeprev" sig "$sig" prevsig "$sigprev" sig60 "$sig60" slope60 "$slope60
342 fi
343 # missing: probably one should check also 20 min binning (s example 20170103)
344 # missing: check on still available observation time
345
346 echo " "$i" "${results[$num+2]}"-"${results[$num+3]}"["${results[$num+8]}"] "$exc" "$sig >> $logfile
347
348 case $triggertype in
349 1) #echo "std trigger: criteria ( $exc >= $exclimit && $sig >= $siglimit && $higher )"
350 trigger=`echo " $exc >= $exclimit && $sig >= $siglimit && $higher " | bc -l`
351 ;;
352 2) #echo "magic 501: criteria ( $exc >= $exclimit && $sig >= $siglimit && $higher )"
353 trigger=`echo " $exc >= $exclimit && $sig >= $siglimit && $higher " | bc -l`
354 ;;
355 3) #echo "magic fast rise/decay"
356 #trigger=`echo " $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit && $sig >= $siglimit " | bc -l`
357 trigger=`echo " ( ( $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit ) || ( - $slope >= $slopelimit && - $slopeprev >= $slopelimit && - $slope60 >= $slopelimit ) ) && $sig >= $siglimit " | bc -l`
358 ;;
359 4) #echo "std trigger: criteria ( $exc >= $exclimit && $sig >= $siglimit && $higher )"
360 trigger=`echo " $exc >= $exclimit && $sig >= $siglimit && $higher " | bc -l`
361 ;;
362 *) echo $triggertype" not yet implemented" >> $logfile
363 ;;
364 esac
365
366 # missing: maybe use $donetriggerfile for all cases - update of nightly case can be triggered differently
367 # missing: adapt triggerfilename for type 3 (slopelimit)
368 if [ $trigger -eq 1 ]
369 then
370 # do whatever to be done to trigger
371 # - send email/sms / call
372 # - create amon file
373 # - prepare email for alert
374 # - entry in DB
375
376 if [ "$bin" = "" ]
377 then
378 # nightly file: simply overwrite, but do not send trigger again
379 # or check value if it's increasing?
380 # missing: get information from previous trigger + interpret
381 triggerfile=$flarealertspath"/"$night"-"$exclimit"_"$siglimit"-source"$sourcekey".trigger"$triggertype
382 else
383 # smaller binning: check if trigger is identical
384 triggerfile=$flarealertspath"/"$night"_"`printf %03d $runid`"-"$exclimit"_"$siglimit"-source"$sourcekey".trigger"$triggertype
385 donetriggerfile=$triggerfile".done"
386 #ls $donetriggerfile
387 # write new file only if old files do not agree
388 if [ "$donetriggerfile" != "" ] && [ -e $donetriggerfile ]
389 then
390 diff $donetriggerfile $triggerfile >/dev/null
391 checkstatus=`echo $?`
392 if [ $checkstatus -eq 0 ]
393 then
394 echo " alert already done "$donetriggerfile >> $logfile
395 i=`echo $i +1 | bc -l`
396 continue
397 fi
398 fi
399 if [ -e $triggerfile ]
400 then
401 mv $triggerfile $donetriggerfile
402 fi
403 fi
404 #echo $night"_"$runid" "$sourcekey" -> "$triggerfile
405 echo " writing "$triggerfile >> $logfile
406 touch $triggerfile
407 echo "Trigger found: " > $triggerfile
408 echo "-------------- " >> $triggerfile
409 echo " type: "$triggertype >> $triggerfile
410 echo " excess limit: "$exclimit" evts/h" >> $triggerfile
411 echo " significance limit: "$siglimit" sigma" >> $triggerfile
412 if [ "$bin" = "" ]
413 then
414 echo " nightly binning " >> $triggerfile
415 else
416 echo " binning: "$bin" min" >> $triggerfile
417 fi
418 echo "Summary of flare event: " >> $triggerfile
419 echo "----------------------- " >> $triggerfile
420 echo " source: "$sourcename >> $triggerfile
421 echo " night: "${results[$num+1]} >> $triggerfile
422 echo " runs: "${results[$num+2]}" - "${results[$num+3]} >> $triggerfile
423 echo " start: "${results[$num+4]}" "${results[$num+5]}" UTC" >> $triggerfile
424 echo " stop: "${results[$num+6]}" "${results[$num+7]}" UTC" >> $triggerfile
425 if [ "$bin" = "" ]
426 then
427 echo " ontime: "${results[$num+8]}" h" >> $triggerfile
428 else
429 echo " ontime: "${results[$num+8]}" min" >> $triggerfile
430 fi
431 #echo " ontime: "`echo "scale=1; ${results[$num+8]} / 60. " | bc -l`" min" #scale doesn't round properly
432 echo " signal: "${results[$num+9]}" evts" >> $triggerfile
433 echo " background: "${results[$num+10]}" evts" >> $triggerfile
434 echo " bgrate: "${results[$num+11]}" evts/h" >> $triggerfile
435 echo " exc: "${results[$num+12]}" +- "${results[$num+13]}" evts" >> $triggerfile
436 echo " excrate: "${results[$num+14]}" +- "${results[$num+15]}" evts/h" >> $triggerfile
437 echo " corr. excrate: "${results[$num+16]}" - "${results[$num+17]}" evts/h" >> $triggerfile
438 echo " significance: "${results[$num+18]}" sigma" >> $triggerfile
439 echo " cu: "${results[$num+19]}" +- "${results[$num+20]}" CU" >> $triggerfile
440 echo " corr. cu: "${results[$num+21]}" +- "${results[$num+22]}" CU" >> $triggerfile
441 echo " zd: "${results[$num+23]}" - "${results[$num+24]}" degree" >> $triggerfile
442 echo " th: "${results[$num+25]}" - "${results[$num+26]}" DAC counts" >> $triggerfile
443 # additional information fast rise/decay trigger
444 if [ $triggertype -eq 3 ]
445 then
446 echo "Flux doubling/halfing times: " >> $triggerfile
447 echo "---------------------------- " >> $triggerfile
448 echo " excess: "$exc >> $triggerfile
449 echo " excess old: "$excold >> $triggerfile
450 echo " significance: "$sig >> $triggerfile
451 echo " significance old: "$sigprev >> $triggerfile
452 echo " slope: "$excold >> $triggerfile
453 echo " slope old: "$slopeold >> $triggerfile
454 echo " excess 60 min: "${results2[19]} >> $triggerfile
455 echo " excess 60 min old: "${results2[27+19]} >> $triggerfile
456 echo " slope 60 min: "$slope60 >> $triggerfile
457 echo " significance 60 min: "$sig60 >> $triggerfile
458 fi
459
460 if [ "$donetriggerfile" != "" ] && [ -e $donetriggerfile ]
461 then
462 diff $donetriggerfile $triggerfile >/dev/null
463 checkstatus=`echo $?`
464 if [ $checkstatus -gt 0 ]
465 then
466 rm $donetriggerfile
467 fi
468 fi
469 # missing: get summary of whole observation
470
471 # missing AMON cases - create VOEvent-File
472 if [ $triggertype -eq 4 ]
473 then
474 echo "amon"
475 voeventfile="/home/dorner/amon/test/"$night"_"`printf %03d $runid`"-"$exclimit"_"$siglimit"-source"$sourcekey".trigger"$triggertype".xml"
476 echo $voeventfile
477 echo ${sourceinfo[@]}
478 #print_voevent_file
479 print_voevent_file > $voeventfile
480 fi
481
482 # send email only of $donetriggerfile doesn't exists
483 if ! [ -e $donetriggerfile ]
484 then
485 cat $triggerfile | mail -s 'test flare alert ' -b $emailfrom -r $emailfrom $emailto
486 fi
487
488 #cat $triggerfile | mail -s "test flare alert for $sourcename " $emailto
489 # that's also the cases for making a call
490
491 fi
492
493 # counter
494 i=`echo $i +1 | bc -l`
495 done
496
497 echo " found "$i" data point(s)." >> $logfile
498 echo "" >> $logfile
499}
500
501
502# main part of the script
503
504# missing: check if twistd client is running
505# + check if there are remaining files in the to-send-folder of amon
506# -> send email if amon connection has problem
507
508
509for sourcekey in ${sourcekeys[@]}
510do
511 query="SELECT fSourceName FROM Source WHERE fSourceKey="$sourcekey
512 sourcename=`sendquery` #do not combine this with other source info as sourcename can have spaces
513
514 # getting some information on the source
515 query="SELECT fDeclination, fRightAscension, fRightAscension/24.*15 FROM Source WHERE fSourceKey="$sourcekey
516 sourceinfo=( `sendquery` )
517
518 # ignore Crab
519 if [ $sourcekey -eq 5 ]
520 then
521 continue
522 fi
523 printprocesslog "INFO Evaluation for $sourcename ... "
524 echo "Evaluation for $sourcename ... " >> $logfile
525
526 # missing: get limits from DB (structure needs to be defined)
527
528 # triggers in the frame of the MoU in the gamma-ray community
529 triggertype=1
530 # limits
531 siglimit=3.0 # sigma
532 #if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ]
533 if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 5 ]
534 then
535 exclimit=3.0 # CU
536 else
537 exclimit=0.5 # CU
538 fi
539 # only if rate goes even higher, we have to react
540 onlyifhigher="yes"
541 higher=1
542
543 printprocesslog "INFO checking for [General gamma-ray MoU]" >> $logfile
544 echo "[General gamma-ray MoU]" >> $logfile
545 echo " nightly binning..." >> $logfile
546 # checking nightly binning
547 bin=
548 get_query_nightly_binning
549 results=( `sendquery` )
550 evaluate_result
551
552 # 20 min binning
553 bin=20
554 echo " "$bin" min binning..." >> $logfile
555 get_query_minute_binning
556 results=( `sendquery` )
557 evaluate_result
558
559 # triggers to MAGIC
560 # Mrk 501 proposal
561 triggertype=2
562 if [ $sourcekey -eq 2 ]
563 then
564 siglimit=3.0
565 exclimit=2.0 # cu
566 printprocesslog "INFO checking for [Trigger to MAGIC 501 proposal]" >> $logfile
567 echo "[Trigger to MAGIC 501 proposal]" >> $logfile
568 echo " nightly binning..." >> $logfile
569 # checking nightly binning
570 bin=
571 get_query_nightly_binning
572 results=( `sendquery` )
573 evaluate_result
574 # 20 min binning
575 bin=20
576 echo " "$bin" min binning..." >> $logfile
577 get_query_minute_binning
578 results=( `sendquery` )
579 evaluate_result
580 fi
581 # Mother of ToO - fast rise/decay
582 # sources: Mrk 421, Mrk 501, 2344, 1959
583 triggertype=3
584 #if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ]
585 if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ] || [ $sourcekey -eq 5 ]
586 then
587 printprocesslog "INFO checking for [Trigger to MAGIC - fast rise/decay]" >> $logfile
588 echo "[Trigger to MAGIC - fast rise/decay]" >> $logfile
589 ## keep thresholds low (or do not use in evaluation)
590 #siglimit=2.0
591 #exclimit=0.5
592 # limits in slope
593 slopelimit=1.0 # 1CU/h
594 siglimit=3.0 # 1 sigma in 1 hour
595 # binning
596 bin=30
597 echo " "$bin" min binning..." >> $logfile
598 get_query_minute_binning
599 results=( `sendquery` )
600 evaluate_result
601 fi
602
603 # Triggers to AMON
604 triggertype=4
605 printprocesslog "INFO checking for [Trigger to AMON]" >> $logfile
606 echo "[Trigger to AMON]" >> $logfile
607 echo " still to be defined" >> $logfile
608 # missing: trigger limits and binning still to be defined
609 # also nightly?
610 # sub-threshold-triggers?
611 # FP-rate?
612 siglimit=2.0
613 exclimit=0.5
614 onlyifhigher="no"
615 bin=20
616 echo "AMON"
617 echo " "$bin" min binning..." >> $logfile
618 get_query_minute_binning
619 results=( `sendquery` )
620 evaluate_result
621
622 echo "" >> $logfile
623 echo "" >> $logfile
624done
625
626finish
627
628# for archival testing:
629for (( i=0; i < 100 ; i++))
630do
631 date=`date --date="-${i}days" +%Y%m%d`
632 /home/fact/SW.automatic.processing/DataCheck/QuickLook/FlareAlerts.sh $date
633done
634
635
Note: See TracBrowser for help on using the repository browser.