| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | # ---------------------------------------------------------------- #
|
|---|
| 4 | # README README README README README README README README README #
|
|---|
| 5 | # ---------------------------------------------------------------- #
|
|---|
| 6 | # #
|
|---|
| 7 | # To use this script, you need #
|
|---|
| 8 | # - a computer with access to the FACT database in La Palma #
|
|---|
| 9 | # - a file with the password of a valid mysql-user #
|
|---|
| 10 | # - to define the setup below for #
|
|---|
| 11 | # a) the DB access #
|
|---|
| 12 | # b) the data you want to have #
|
|---|
| 13 | # #
|
|---|
| 14 | # To define the setup, search for SETUP in this script and #
|
|---|
| 15 | # read the details there #
|
|---|
| 16 | # #
|
|---|
| 17 | # Per data request, you get up to 3 files: #
|
|---|
| 18 | # *_internal.dat #
|
|---|
| 19 | # *_collaborators.dat #
|
|---|
| 20 | # *_external.dat (only if binning is 20min or nightly) #
|
|---|
| 21 | # #
|
|---|
| 22 | # Please have in mind that this started as a tool for myself, then #
|
|---|
| 23 | # others started using it. Also the script is not yet finalized. #
|
|---|
| 24 | # In case you find problems and/or have a feature request, please #
|
|---|
| 25 | # send and email to dorner@astro.uni-wuerzburg.de #
|
|---|
| 26 | # #
|
|---|
| 27 | # ---------------------------------------------------------------- #
|
|---|
| 28 | # README README README README README README README README README #
|
|---|
| 29 | # ---------------------------------------------------------------- #
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | # ToDo (notes DD):
|
|---|
| 36 | # ----------------
|
|---|
| 37 | # must-have
|
|---|
| 38 | # - fix bug for timeunit=timestamp (min-binning)
|
|---|
| 39 | # - add policy
|
|---|
| 40 | # - add email sending and return values
|
|---|
| 41 | # - update function for zd/th-correction
|
|---|
| 42 | # - update CU for QLA
|
|---|
| 43 | # - add CU for ISDC analysis
|
|---|
| 44 | # - add < 20121212 data for QLA
|
|---|
| 45 | # - check crab flux
|
|---|
| 46 | # nice-to-have
|
|---|
| 47 | # - add E2dNdE
|
|---|
| 48 | # - functionality to determine start time for seaon-binning
|
|---|
| 49 | # - offer several predefined datachecks?
|
|---|
| 50 |
|
|---|
| 51 | #
|
|---|
| 52 | # content of files (wish list):
|
|---|
| 53 | # -----------------------------
|
|---|
| 54 | # REMARK: keep order of columns to allow for reading with TGraph directly from file: X Y EX EY
|
|---|
| 55 | #
|
|---|
| 56 | # internal
|
|---|
| 57 | # --------
|
|---|
| 58 | # time: time, delta time, start, stop, ontime
|
|---|
| 59 | # flux: excrate, excerr, corrate, corerr, CU CUerr, flux, fluxerr,
|
|---|
| 60 | # other info on flux: signif, cu-factor, num exc, num sig, num bg
|
|---|
| 61 | # other info: zd th R750cor R750ref
|
|---|
| 62 | #
|
|---|
| 63 | # external (allow only 20min and nightly binning)
|
|---|
| 64 | # --------
|
|---|
| 65 | # time: time, delta time, start, stop
|
|---|
| 66 | # flux: excrate, excerr
|
|---|
| 67 | #
|
|---|
| 68 | # collaborators
|
|---|
| 69 | # -------------
|
|---|
| 70 | # time: time, delta time, start, stop, ontime
|
|---|
| 71 | # flux: excrate, excerr, corrate, corerr, flux, flux-err, significance
|
|---|
| 72 | #
|
|---|
| 73 | # additional information to put:
|
|---|
| 74 | # ------------------------------
|
|---|
| 75 | # timestamp of creation
|
|---|
| 76 | # query (for debugging / answering questions)
|
|---|
| 77 | # policy (adapted for internal/collaborators/external) [define in files to be used also by Send_Data*.sh
|
|---|
| 78 | #
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | function get_results()
|
|---|
| 83 | {
|
|---|
| 84 | # some query parts
|
|---|
| 85 |
|
|---|
| 86 | # some numbers for flux calculation
|
|---|
| 87 | crabflux="3.37e-11"
|
|---|
| 88 | fluxprec=13
|
|---|
| 89 | crabflux="3.37"
|
|---|
| 90 | fluxprec=2
|
|---|
| 91 |
|
|---|
| 92 | # some names and definitions needed several times below
|
|---|
| 93 | # ontime
|
|---|
| 94 | ontime1=" TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn "
|
|---|
| 95 | ontime2=" fOnTimeAfterCuts "
|
|---|
| 96 | ontimeif=" IF(ISNULL(fEffectiveOn), "$ontime2", "$ontime1") "
|
|---|
| 97 | # zd and threshold
|
|---|
| 98 | zenith="fZenithDistance"
|
|---|
| 99 | thresh="IF(ISNULL(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)"
|
|---|
| 100 | # correction factor for excess rate (formula by TB)
|
|---|
| 101 | correvts=" fNumExcEvts*(pow(cos("$zenith"Mean*PI()/180),3)+14.8/21.9*pow(sin(2*"$zenith"Mean*PI()/180),5))/((1-0.00124/1.21*("$thresh"-500)*("$thresh">=500))) "
|
|---|
| 102 | # conversion to CU (determined by DD for QLA)
|
|---|
| 103 | # https://www.fact-project.org/logbook/showthread.php?tid=4927
|
|---|
| 104 | cufactor="CUQLA(fNight)" # missing: ISDC analysis
|
|---|
| 105 | # some calculations
|
|---|
| 106 | excerr="ExcErr(Sum(fNumSigEvts), SUM(fNumBgEvts))"
|
|---|
| 107 | CU="SUM("$correvts"/"$cufactor")/SUM("$ontimeif")*3600"
|
|---|
| 108 | CUerr=$excerr"/SUM("$ontimeif")*3600*SUM("$correvts"/"$cufactor")/SUM(fNumExcEvts)"
|
|---|
| 109 | excerr2="ExcErr(SUM(o.sigevts),SUM(o.bgevts))"
|
|---|
| 110 | CU2="SUM(o.corevts/o.cufactor)/SUM(o.ot)*3600"
|
|---|
| 111 | CUerr2=$excerr2"/SUM(o.ot)*3600*SUM(o.corevts/o.cufactor)/(SUM(o.sigevts)-SUM(o.bgevts))"
|
|---|
| 112 |
|
|---|
| 113 | # columns to be selected
|
|---|
| 114 | # for night-binning
|
|---|
| 115 | ontime=" ROUND(SUM("$ontimeif")/60., 1) AS ontime"
|
|---|
| 116 | excrate=" ROUND(SUM(fNumExcEvts)/SUM("$ontimeif")*3600, 1) AS excrate"
|
|---|
| 117 | significance="ROUND(LiMa(Sum(fNumSigEvts), SUM(fNumBgEvts)), 1) AS significance"
|
|---|
| 118 | numexc="Sum(fNumExcEvts) AS numexc"
|
|---|
| 119 | numsig="Sum(fNumSigEvts) AS numsig"
|
|---|
| 120 | numbg="Sum(fNumBgEvts) AS numbg"
|
|---|
| 121 | excrateerr=" ROUND("$excerr"/SUM("$ontimeif")*3600, 1) AS excrateerr"
|
|---|
| 122 | correxcrate=" ROUND(SUM("$correvts")/SUM("$ontimeif")*3600, 1) AS correxcrate"
|
|---|
| 123 | correxcrateerr=" ROUND("$excerr"/SUM("$ontimeif")*3600*SUM("$correvts")/SUM(fNumExcEvts), 1) AS correxcrateerr"
|
|---|
| 124 | cu=" ROUND("$CU", 2) AS cu"
|
|---|
| 125 | cuerr=" ROUND("$CUerr", 2) AS cuerr"
|
|---|
| 126 | flux="ROUND("$CU" * "$crabflux", 2) AS flux"
|
|---|
| 127 | fluxerr="ROUND("$CUerr" * "$crabflux", 2) AS fluxerr"
|
|---|
| 128 | # for minute binning
|
|---|
| 129 | ontime2=" ROUND(SUM(o.ot)/60., 1) AS ontime"
|
|---|
| 130 | excrate2=" ROUND((SUM(o.sigevts)-SUM(o.bgevts))/SUM(o.ot)*3600, 1) AS excrate"
|
|---|
| 131 | significance2=" ROUND(LiMa(SUM(o.sigevts),SUM(o.bgevts)), 1) AS significance"
|
|---|
| 132 | numexc2="Sum(o.sigevts-o.bgevts) AS numexc"
|
|---|
| 133 | numsig2="Sum(o.sigevts) AS numsig"
|
|---|
| 134 | numbg2="Sum(o.bgevts) AS numbg"
|
|---|
| 135 | excrateerr2=" ROUND("$excerr2"/SUM(o.ot)*3600, 1) AS excrateerr"
|
|---|
| 136 | correxcrate2=" ROUND(SUM(o.corevts)/SUM(o.ot)*3600, 1) AS correxcrate"
|
|---|
| 137 | correxcrateerr2=" ROUND("$excerr2"/SUM(o.ot)*3600*SUM(o.corevts)/(SUM(o.sigevts)-SUM(o.bgevts)), 1) AS correxcrateerr"
|
|---|
| 138 | cu2=" ROUND("$CU2", 2) AS cu"
|
|---|
| 139 | cuerr2=" ROUND("$CUerr2", 2) AS cuerr"
|
|---|
| 140 | flux2="ROUND("$CU2" * "$crabflux", "$fluxprec") AS flux"
|
|---|
| 141 | fluxerr2="ROUND("$CUerr2" *"$crabflux", "$fluxprec") AS fluxerr"
|
|---|
| 142 |
|
|---|
| 143 | case $timeunit in
|
|---|
| 144 | mjd) delta="(Mjd(MAX(fRunStop))-Mjd(MIN(fRunStart)))/2"
|
|---|
| 145 | start=" Mjd(MIN(fRunStart)) AS start"
|
|---|
| 146 | stop=" Mjd(MAX(fRunStop)) AS stop"
|
|---|
| 147 | deltat=$delta" AS deltat"
|
|---|
| 148 | time=" Mjd(MIN(fRunStart))+"$delta" AS time"
|
|---|
| 149 | delta2="(Mjd(MAX(o.stop))-Mjd(MIN(o.start)))/2"
|
|---|
| 150 | start2=" Mjd(MIN(o.start)) AS start"
|
|---|
| 151 | stop2=" Mjd(MAX(o.stop)) AS stop"
|
|---|
| 152 | deltat2=$delta2" AS deltat"
|
|---|
| 153 | time2=" Mjd(MIN(o.start))+"$delta2" AS time"
|
|---|
| 154 | ;;
|
|---|
| 155 | unix) delta="(Unix_timestamp(CONVERT_TZ(MAX(fRunStop), '+00:00', 'SYSTEM')) - Unix_timestamp(CONVERT_TZ(MIN(fRunStart), '+00:00', 'SYSTEM')))/2"
|
|---|
| 156 | start="Unix_timestamp(CONVERT_TZ(MIN(fRunStart), '+00:00', 'SYSTEM')) AS start"
|
|---|
| 157 | stop="Unix_timestamp(CONVERT_TZ(MAX(fRunStop), '+00:00', 'SYSTEM')) AS stop"
|
|---|
| 158 | deltat=$delta" AS deltat"
|
|---|
| 159 | time=" Unix_timestamp(CONVERT_TZ(MIN(fRunStart), '+00:00', 'SYSTEM'))+"$delta" AS time"
|
|---|
| 160 | delta2="(Unix_timestamp(CONVERT_TZ(MAX(o.stop), '+00:00', 'SYSTEM')) - Unix_timestamp(CONVERT_TZ(MIN(o.start), '+00:00', 'SYSTEM')))/2"
|
|---|
| 161 | startstop2=" Unix_timestamp(CONVERT_TZ(MIN(o.start), '+00:00', 'SYSTEM')) AS start"
|
|---|
| 162 | startstop2=$starstop2" Unix_timestamp(CONVERT_TZ(MAX(o.stop), '+00:00', 'SYSTEM')) AS stop"
|
|---|
| 163 | deltat2=$delta2" AS deltat"
|
|---|
| 164 | time2=" Unix_timestamp(CONVERT_TZ(MIN(o.start), '+00:00', 'SYSTEM'))+"$delta2" AS time"
|
|---|
| 165 | ;;
|
|---|
| 166 | *) delta="sec_to_time(time_to_sec(timediff(MAX(fRunStop), MIN(fRunStart)))/2)"
|
|---|
| 167 | start=" MIN(fRunStart) AS start"
|
|---|
| 168 | stop=" MAX(fRunStop) AS stop"
|
|---|
| 169 | deltat=$delta" AS deltat"
|
|---|
| 170 | time=" addtime(MIN(fRunStart), "$delta") AS time"
|
|---|
| 171 | delta2="sec_to_time(time_to_sec(timediff(MAX(o.stop), MIN(o.start)))/2)"
|
|---|
| 172 | start2=" MIN(o.start) AS start"
|
|---|
| 173 | stop2=" MAX(o.stop) AS stop"
|
|---|
| 174 | deltat2=$delta" AS deltat"
|
|---|
| 175 | time2=" addtime(MIN(o.start), "$delta2") AS time"
|
|---|
| 176 | ;;
|
|---|
| 177 | esac
|
|---|
| 178 |
|
|---|
| 179 | # from and join of query
|
|---|
| 180 | from=" FROM RunInfo LEFT JOIN "$table" USING (fNight, fRunID) "
|
|---|
| 181 |
|
|---|
| 182 | # data check based on artificial trigger rate
|
|---|
| 183 | # details see https://www.fact-project.org/logbook/showthread.php?tid=5790
|
|---|
| 184 | #dch=" AND fR750Cor/fR750Ref >0.93 "
|
|---|
| 185 | dchstd=" AND fR750Cor/fR750Ref BETWEEN 0.93 AND 1.3 "
|
|---|
| 186 |
|
|---|
| 187 | # put together where-clause of query
|
|---|
| 188 | # time range and source
|
|---|
| 189 | where=" WHERE fSourceKey="$source" AND fNight BETWEEN "$nightmin" AND "$nightmax
|
|---|
| 190 | where=$where" AND NOT ISNULL(fNumExcEvts) "
|
|---|
| 191 | # some sanity checks
|
|---|
| 192 | where=$where" AND fRunTypeKey=1 "
|
|---|
| 193 | # zd cut
|
|---|
| 194 | if [ "$zdmax" != "" ]
|
|---|
| 195 | then
|
|---|
| 196 | where=$where" AND fZenithDistanceMax < "$zdmax
|
|---|
| 197 | fi
|
|---|
| 198 | # th cut
|
|---|
| 199 | if [ "$thmax" != "" ]
|
|---|
| 200 | then
|
|---|
| 201 | where=$where" AND "$thresh" < "$thmax
|
|---|
| 202 | fi
|
|---|
| 203 | # dust cut
|
|---|
| 204 | if [ "$dust" != "" ]
|
|---|
| 205 | then
|
|---|
| 206 | where=$where" AND fTNGDust<"$dust
|
|---|
| 207 | fi
|
|---|
| 208 | # light condition cut
|
|---|
| 209 | if [ "$light" == "no moon" ]
|
|---|
| 210 | then
|
|---|
| 211 | where=$where" AND fZenithDistanceMoon>90"
|
|---|
| 212 | fi
|
|---|
| 213 | if [ "$light" == "dark" ]
|
|---|
| 214 | then
|
|---|
| 215 | where=$where" AND fMoonZenithDistance>90 AND fSunZenithDistance>108 "
|
|---|
| 216 | fi
|
|---|
| 217 | querybase=$from$where
|
|---|
| 218 |
|
|---|
| 219 | if [ "$usedch" == "yes" ]
|
|---|
| 220 | then
|
|---|
| 221 | if [ "$dch" == "" ]
|
|---|
| 222 | then
|
|---|
| 223 | querydch=$dchstd
|
|---|
| 224 | else
|
|---|
| 225 | echo "you are using for datacheck: "$dch
|
|---|
| 226 | querydch=$dch
|
|---|
| 227 | fi
|
|---|
| 228 | fi
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 | if [ $bin -le 0 ]
|
|---|
| 232 | then
|
|---|
| 233 | num="#bin"
|
|---|
| 234 | # first part of the query
|
|---|
| 235 | querystart="SELECT "
|
|---|
| 236 | if [ $bin -eq 0 ]
|
|---|
| 237 | then
|
|---|
| 238 | querystart=$querystart" fPeriod AS num, "
|
|---|
| 239 | else
|
|---|
| 240 | querystart=$querystart" FLOOR((Mjd(fRunStart)-Mjd("$nightmin")-0.5)/"`echo $bin | sed -e 's/-//'`".) AS num, "
|
|---|
| 241 | fi
|
|---|
| 242 | querystart=$querystart" "$time", "$start", "$stop", "
|
|---|
| 243 |
|
|---|
| 244 | # final part of the query
|
|---|
| 245 | queryend=" GROUP BY num "
|
|---|
| 246 | if [ "$ontimelimit" = "" ]
|
|---|
| 247 | then
|
|---|
| 248 | queryend=$queryend" HAVING SUM("$ontimeif")>1200 ORDER BY num " # 20 min
|
|---|
| 249 | else
|
|---|
| 250 | queryend=$queryend" HAVING SUM("$ontimeif")>"$ontimelimit" ORDER BY num "
|
|---|
| 251 | fi
|
|---|
| 252 |
|
|---|
| 253 | # internal
|
|---|
| 254 | queryint=$querystart
|
|---|
| 255 | queryint=$queryint" "$excrate", "$correxcrate", "$cu", "$flux", "
|
|---|
| 256 | queryint=$queryint" "$deltat", "$ontime", "
|
|---|
| 257 | queryint=$queryint" "$excrateerr", "$correxcrateerr", "$cuerr", "$fluxerr", "
|
|---|
| 258 | queryint=$queryint" "$significance", "
|
|---|
| 259 | queryint=$queryint" MIN(fNight) AS nightmin, MAX(fNight) AS nightmax, "
|
|---|
| 260 | queryint=$queryint" "$numexc", "$numsig", "$numbg", "
|
|---|
| 261 | queryint=$queryint" MIN("$zenith"Min) AS zdmin, MAX("$zenith"Max) AS zdmax, "
|
|---|
| 262 | queryint=$queryint" MIN("$thresh") AS thmin, MAX("$thresh") AS thmax, "
|
|---|
| 263 | queryint=$queryint" ROUND(AVG("$cufactor"), 1) AS cufactor, ROUND(AVG(fR750Cor), 2) AS R750cor, ROUND(AVG(fR750Ref), 2) AS R750ref "
|
|---|
| 264 | queryint=$queryint" "$querybase" "$querydch" "$queryend
|
|---|
| 265 |
|
|---|
| 266 | # for collaborators
|
|---|
| 267 | querycol=$querystart
|
|---|
| 268 | querycol=$querycol" "$excrate", "$correxcrate", "$cu", "$flux", "
|
|---|
| 269 | querycol=$querycol" "$deltat", "$ontime", "
|
|---|
| 270 | querycol=$querycol" "$excrateerr", "$correxcrateerr", "$cuerr", "$fluxerr", "
|
|---|
| 271 | querycol=$querycol" "$significance
|
|---|
| 272 | querycol=$querycol" "$querybase" "$querydch" "$queryend
|
|---|
| 273 |
|
|---|
| 274 | # external
|
|---|
| 275 | # no datacheck applied for external files
|
|---|
| 276 | queryext=$querystart" "$excrate", "$deltat", "$excrateerr" "$querybase" "$queryend
|
|---|
| 277 |
|
|---|
| 278 | else
|
|---|
| 279 | num=
|
|---|
| 280 | # first part of the query
|
|---|
| 281 | querystart="SELECT "
|
|---|
| 282 | querystart=$querystart" "$time2", "$start2", "$stop2", "
|
|---|
| 283 |
|
|---|
| 284 | # final part of the query
|
|---|
| 285 | querybase=" FROM (SELECT fNight, fZenithDistanceMin AS zdmin, fZenithDistanceMax AS zdmax, "$thresh" AS th, "
|
|---|
| 286 | querybase=$querybase" fR750Cor AS R750cor, fR750Ref AS R750ref, "$cufactor" AS cufactor, "
|
|---|
| 287 | querybase=$querybase" @ot:="$ontimeif" AS ot, fRunStart AS start, fRunStop AS stop, "
|
|---|
| 288 | querybase=$querybase" fNumSigEvts AS sigevts, fNumBgEvts AS bgevts, "$correvts" AS corevts, "
|
|---|
| 289 | querybase=$querybase" IF (@night=fNight AND FLOOR((@os+@ot)/"$bin"./60.)<1, @bl, @bl := @bl + 1) AS block, "
|
|---|
| 290 | querybase=$querybase" IF (@night=fNight AND FLOOR((@os+@ot)/"$bin"./60.)<1, @os:=@os + @ot, @os := @ot) AS os, @night :=fNight AS night "
|
|---|
| 291 | querybase=$querybase$from" CROSS JOIN (SELECT @night :=0, @ot :=0, @os :=0, @bl:=0) PARAMS "
|
|---|
| 292 | querybase=$querybase$where" ORDER BY fRunStart) o GROUP BY block HAVING ontime>0.75*"$bin" ORDER BY 'time'"
|
|---|
| 293 |
|
|---|
| 294 | # internal
|
|---|
| 295 | queryint=$querystart
|
|---|
| 296 | queryint=$queryint" "$excrate2", "$correxcrate2", "$cu2", "$flux2", "
|
|---|
| 297 | queryint=$queryint" "$deltat2", "$ontime2", "
|
|---|
| 298 | queryint=$queryint" "$excrateerr2", "$correxcrateerr2", "$cuerr2", "$fluxerr2", "
|
|---|
| 299 | queryint=$queryint" "$significance2", "
|
|---|
| 300 | queryint=$queryint" avg(o.night) AS night, "
|
|---|
| 301 | queryint=$queryint" "$numexc2", "$numsig2", "$numbg2", "
|
|---|
| 302 | queryint=$queryint" MIN(o.zdmin) AS zdmin, MAX(o.zdmax) AS zdmax, MIN(o.th) AS thmin, MAX(o.th) AS thmax, "
|
|---|
| 303 | queryint=$queryint" ROUND(AVG(o.cufactor), 1) AS cufactor, ROUND(AVG(o.R750cor), 2) AS R750cor, ROUND(AVG(o.R750ref), 2) AS R750ref "
|
|---|
| 304 | queryint=$queryint" "$querybase
|
|---|
| 305 |
|
|---|
| 306 | # for collaborators
|
|---|
| 307 | querycol=$querystart
|
|---|
| 308 | querycol=$querycol" "$excrate2", "$correxcrate2", "$cu2", "$flux2", "
|
|---|
| 309 | querycol=$querycol" "$deltat2", "$ontime2", "
|
|---|
| 310 | querycol=$querycol" "$excrateerr2", "$correxcrateerr2", "$cuerr2", "$fluxerr2", "
|
|---|
| 311 | querycol=$querycol" "$significance2
|
|---|
| 312 | querycol=$querycol" "$querybase
|
|---|
| 313 |
|
|---|
| 314 | # external
|
|---|
| 315 | queryext=$querystart" "$excrate2", "$deltat2", "$ontime2", "$excrateerr2" "$querybase
|
|---|
| 316 |
|
|---|
| 317 | fi
|
|---|
| 318 |
|
|---|
| 319 | # write file for externals only for allowed binnings
|
|---|
| 320 | if [ $bin -eq 20 ] || [ $bin -eq -1 ]
|
|---|
| 321 | then
|
|---|
| 322 | fileext=$datapath"/FACT_preliminary_"$name"_external.dat"
|
|---|
| 323 | if [ "$overwrite" = "yes" ]
|
|---|
| 324 | then
|
|---|
| 325 | echo "creating "$fileext" ..."
|
|---|
| 326 | echo "# This file was created at "`date` > $fileext
|
|---|
| 327 | # add policy here
|
|---|
| 328 | fi
|
|---|
| 329 | headerext="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] delta_time["$timeunit"] excrate_err[evts/h] "
|
|---|
| 330 | echo $headerext >> $fileext
|
|---|
| 331 | #echo "$queryext"
|
|---|
| 332 | mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryext" >> $fileext
|
|---|
| 333 | #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryext"
|
|---|
| 334 | fi
|
|---|
| 335 | if [ "$mode" == "auto" ] && [ "$expert" == "no" ]
|
|---|
| 336 | then
|
|---|
| 337 | return
|
|---|
| 338 | fi
|
|---|
| 339 |
|
|---|
| 340 | fileint=$datapath"/FACT_preliminary_"$name"_internal.dat"
|
|---|
| 341 | if [ "$overwrite" = "yes" ]
|
|---|
| 342 | then
|
|---|
| 343 | echo "creating "$fileint" ..."
|
|---|
| 344 | echo "# This file was created at "`date` > $fileint
|
|---|
| 345 | echo "# The following query was used: " >> $fileint
|
|---|
| 346 | echo "# "$queryint >> $fileint
|
|---|
| 347 | # add policy here
|
|---|
| 348 | fi
|
|---|
| 349 | headerint="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
|
|---|
| 350 | headerint=$headerint" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance night num_exc num_sig num_bg "
|
|---|
| 351 | headerint=$headerint" zdmin zdmax thmin thmax avg(cufactor) avg(R750cor) avg(R750ref) "
|
|---|
| 352 | echo $headerint >> $fileint
|
|---|
| 353 | #echo "$queryint"
|
|---|
| 354 | mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryint" >> $fileint
|
|---|
| 355 | #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryint"
|
|---|
| 356 | if [ "$mode"="auto" ]
|
|---|
| 357 | then
|
|---|
| 358 | return
|
|---|
| 359 | fi
|
|---|
| 360 |
|
|---|
| 361 | filecol=$datapath"/FACT_preliminary_"$name"_collaborators.dat"
|
|---|
| 362 | if [ "$overwrite" = "yes" ]
|
|---|
| 363 | then
|
|---|
| 364 | echo "creating "$filecol" ..."
|
|---|
| 365 | echo "# This file was created at "`date` > $filecol
|
|---|
| 366 | echo "# The following query was used: " >> $filecol
|
|---|
| 367 | echo "# "$querycol >> $filecol
|
|---|
| 368 | # add policy here
|
|---|
| 369 | fi
|
|---|
| 370 | headercol="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
|
|---|
| 371 | headercol=$headercol" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance "
|
|---|
| 372 | echo $headercol >> $filecol
|
|---|
| 373 | #echo "$querycol"
|
|---|
| 374 | mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$querycol" >> $filecol
|
|---|
| 375 | #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$querycol
|
|---|
| 376 |
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | # evaluation of command line options (for usage with download.php)
|
|---|
| 380 |
|
|---|
| 381 | if [ ${#@} -eq 13 ]
|
|---|
| 382 | then
|
|---|
| 383 | #get_data.sh $start $stop $source $timebin $email $table $time $expert $dch $zd $th $light $dust
|
|---|
| 384 | mode="auto"
|
|---|
| 385 | # setup
|
|---|
| 386 | path=`dirname $0`
|
|---|
| 387 | datapath=$path"/data"
|
|---|
| 388 | sqlpw=/home/$USER/.mysql.pw2
|
|---|
| 389 | host=10.0.100.21
|
|---|
| 390 | dbname=factdata
|
|---|
| 391 | nightmin=$1
|
|---|
| 392 | nightmax=$2
|
|---|
| 393 | source=$3
|
|---|
| 394 | bin=$4
|
|---|
| 395 | email=$5
|
|---|
| 396 | table=$6
|
|---|
| 397 | timeunit=$7
|
|---|
| 398 | expert=$8
|
|---|
| 399 | usedch=$9 # novalue gives same result as no
|
|---|
| 400 | if [ "${10}" != "novalue" ] && [ "${10}" != "all" ]
|
|---|
| 401 | then
|
|---|
| 402 | zdmax=${10}
|
|---|
| 403 | fi
|
|---|
| 404 | if [ "${11}" != "novalue" ] && [ "${11}" != "all" ]
|
|---|
| 405 | then
|
|---|
| 406 | thmax=${11}
|
|---|
| 407 | fi
|
|---|
| 408 | if [ "${12}" != "novalue" ] && [ "${12}" != "all" ]
|
|---|
| 409 | then
|
|---|
| 410 | light=${12}
|
|---|
| 411 | fi
|
|---|
| 412 | if [ "${13}" != "novalue" ] && [ "${13}" != "all" ]
|
|---|
| 413 | then
|
|---|
| 414 | dust=${13}
|
|---|
| 415 | fi
|
|---|
| 416 | name=`echo $email | sed -e 's/@/-at-/'`
|
|---|
| 417 | get_results
|
|---|
| 418 |
|
|---|
| 419 | if [ "$expert" == "yes" ]
|
|---|
| 420 | then
|
|---|
| 421 | echo $fileint
|
|---|
| 422 | else
|
|---|
| 423 | echo $fileext
|
|---|
| 424 | fi
|
|---|
| 425 |
|
|---|
| 426 | # next: light, dust
|
|---|
| 427 | # implement all options
|
|---|
| 428 | # make dch swi
|
|---|
| 429 |
|
|---|
| 430 | exit
|
|---|
| 431 | fi
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 | # -------------------------------------------------------------------------------------- #
|
|---|
| 436 | # SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP #
|
|---|
| 437 | # -------------------------------------------------------------------------------------- #
|
|---|
| 438 | # #
|
|---|
| 439 | # The lines below define the basic setup for the database and give examples and #
|
|---|
| 440 | # explanations for the various options available. #
|
|---|
| 441 | # The request of the data itself is done with a smaller setup further down. #
|
|---|
| 442 | # #
|
|---|
| 443 | # -------------------------------------------------------------------------------------- #
|
|---|
| 444 | #
|
|---|
| 445 | # ----------
|
|---|
| 446 | # DB SETUP
|
|---|
| 447 | # ----------
|
|---|
| 448 | # path to file with mysql password
|
|---|
| 449 | sqlpw=/home/$USER/.mysql.pw
|
|---|
| 450 | # host of mysql server with FACT DB
|
|---|
| 451 | #host=lp-fact # ISDC
|
|---|
| 452 | host=10.0.100.21 # LP or LP via vpn
|
|---|
| 453 | #host=localhost # your local machine in case you have a copy of DB
|
|---|
| 454 | # name of database
|
|---|
| 455 | dbname=factdata
|
|---|
| 456 | #
|
|---|
| 457 | # -------------
|
|---|
| 458 | # BASIC SETUP
|
|---|
| 459 | # -------------
|
|---|
| 460 | # output path
|
|---|
| 461 | path=`dirname $0`
|
|---|
| 462 | datapath=$path"/data"
|
|---|
| 463 | # create directory for data files
|
|---|
| 464 | if ! [ -e $datapath ]
|
|---|
| 465 | then
|
|---|
| 466 | mkdir $datapath
|
|---|
| 467 | fi
|
|---|
| 468 | # time unit
|
|---|
| 469 | #timeunit=timestamp # default
|
|---|
| 470 | #timeunit=unix
|
|---|
| 471 | timeunit=mjd
|
|---|
| 472 | # time binning
|
|---|
| 473 | # positive values: minutes
|
|---|
| 474 | # negative values: days
|
|---|
| 475 | # special case 0: period
|
|---|
| 476 | # for season binning choose -365 and according start date
|
|---|
| 477 | #bin=20 # minutes
|
|---|
| 478 | #bin=0 # period
|
|---|
| 479 | bin=-1 # nightly
|
|---|
| 480 | #bin=-365 # yearly
|
|---|
| 481 | # choose analysis
|
|---|
| 482 | #table="AnalysisResultsAllQLA" # N/A
|
|---|
| 483 | table="AnalysisResultsRunLP" # QLA
|
|---|
| 484 | #table="AnalysisResultsRunISDC" # ISDC
|
|---|
| 485 | # time range
|
|---|
| 486 | nightmin=20111115
|
|---|
| 487 | nightmax=20201231
|
|---|
| 488 | # overwrite dataset file?
|
|---|
| 489 | # (useful to combine different binnings in one file -> set to "no")
|
|---|
| 490 | overwrite="yes"
|
|---|
| 491 | # optional: require minimal ontime per bin (default 20 min)
|
|---|
| 492 | #ontimelimit=30 # 30 min
|
|---|
| 493 | ontimelimit= # default 20 min
|
|---|
| 494 | # data quality selection
|
|---|
| 495 | # if you explicitely don't want a datacheck, you can comment the following line
|
|---|
| 496 | usedch="yes"
|
|---|
| 497 | # use your own datacheck instead
|
|---|
| 498 | # use a line like the following defining your own data quality selection cut
|
|---|
| 499 | #dch=" AND fR750Cor/fR750Ref BETWEEN 0.93 AND 1.3 "
|
|---|
| 500 | # apply additional predefined cuts
|
|---|
| 501 | # light conditions
|
|---|
| 502 | #light="no moon" # only data with no moon (but twilight allowed)
|
|---|
| 503 | #light="dark" # only dark night data
|
|---|
| 504 | # TNG dust - cut away data with calima
|
|---|
| 505 | #dust=1
|
|---|
| 506 | #dust=10
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 | # -------------------------------------------------------------------------------------- #
|
|---|
| 510 | # SETUP - GET YOUR DATA HERE - SETUP - GET YOUR DATA HERE - SETUP - GET YOUR DATA HERE #
|
|---|
| 511 | # -------------------------------------------------------------------------------------- #
|
|---|
| 512 | # #
|
|---|
| 513 | # Adapt the lines below to your needs. #
|
|---|
| 514 | # Overwrite default settings above. #
|
|---|
| 515 | # The data-request is sent with the line 'get_results.' #
|
|---|
| 516 | # Minumum setup: Define source key and name for file. #
|
|---|
| 517 | # The list of source keys can be found at #
|
|---|
| 518 | # https://fact-project.org/run_db/db/printtable.php?fTable=Source&fSortBy=fSourceKEY+ #
|
|---|
| 519 | # More examples can be found further down. #
|
|---|
| 520 | # #
|
|---|
| 521 | # REMARKS: #
|
|---|
| 522 | # - correction of effect of zd and threshold not yet finalized and only valid for QLA #
|
|---|
| 523 | # - no CU-conversion available for ISDC-analysis so far (that for QLA is used instead) #
|
|---|
| 524 | # #
|
|---|
| 525 | # -------------------------------------------------------------------------------------- #
|
|---|
| 526 |
|
|---|
| 527 | # 501 MAGIC
|
|---|
| 528 | source=2
|
|---|
| 529 | name="Mrk501_2014_forMAGIC"
|
|---|
| 530 | bin=-1
|
|---|
| 531 | nightmin=20140714
|
|---|
| 532 | nightmax=20140805
|
|---|
| 533 | get_results
|
|---|
| 534 |
|
|---|
| 535 | bin=30
|
|---|
| 536 | name="Mrk501_2014_forMAGIC30"
|
|---|
| 537 | get_results
|
|---|
| 538 |
|
|---|
| 539 | bin=0
|
|---|
| 540 | name="P"
|
|---|
| 541 | nightmin=20140501
|
|---|
| 542 | nightmax=20140930
|
|---|
| 543 | get_results
|
|---|
| 544 |
|
|---|
| 545 | bin=20
|
|---|
| 546 | nightmin=20140623
|
|---|
| 547 | nightmax=20140623
|
|---|
| 548 | name="Mrk501_test"
|
|---|
| 549 | get_results
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 | # end script here
|
|---|
| 553 | exit
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 | #
|
|---|
| 558 | # more examples
|
|---|
| 559 | #
|
|---|
| 560 |
|
|---|
| 561 | # Mrk 421
|
|---|
| 562 | source=1
|
|---|
| 563 | name="Mrk421_nightly"
|
|---|
| 564 | bin=-1
|
|---|
| 565 | get_results
|
|---|
| 566 | name="Mrk421_20min"
|
|---|
| 567 | bin=20
|
|---|
| 568 | get_results
|
|---|
| 569 | name="Mrk421_3d"
|
|---|
| 570 | bin=-3
|
|---|
| 571 | get_results
|
|---|
| 572 | name="Mrk421_10d"
|
|---|
| 573 | bin=-10
|
|---|
| 574 | get_results
|
|---|
| 575 | name="Mrk421_period"
|
|---|
| 576 | bin=0
|
|---|
| 577 | get_results
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 | # Mrk 501
|
|---|
| 582 | source=2
|
|---|
| 583 | name="Mrk501_nightly"
|
|---|
| 584 | bin=-1
|
|---|
| 585 | get_results
|
|---|
| 586 | name="Mrk501_20min"
|
|---|
| 587 | bin=20
|
|---|
| 588 | get_results
|
|---|
| 589 | name="Mrk501_3d"
|
|---|
| 590 | bin=-3
|
|---|
| 591 | get_results
|
|---|
| 592 | name="Mrk501_10d"
|
|---|
| 593 | bin=-10
|
|---|
| 594 | get_results
|
|---|
| 595 | name="Mrk501_period"
|
|---|
| 596 | bin=0
|
|---|
| 597 | get_results
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 | # 2344
|
|---|
| 602 | source=3
|
|---|
| 603 | name="2344_nightly"
|
|---|
| 604 | bin=-1
|
|---|
| 605 | get_results
|
|---|
| 606 | name="2344_20min"
|
|---|
| 607 | bin=20
|
|---|
| 608 | get_results
|
|---|
| 609 | name="2344_period"
|
|---|
| 610 | bin=0
|
|---|
| 611 | get_results
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 | # 1959
|
|---|
| 616 | source=7
|
|---|
| 617 | name="1959_nightly"
|
|---|
| 618 | bin=-1
|
|---|
| 619 | get_results
|
|---|
| 620 | name="1959_20min"
|
|---|
| 621 | bin=20
|
|---|
| 622 | get_results
|
|---|
| 623 | name="1959_period"
|
|---|
| 624 | bin=0
|
|---|
| 625 | get_results
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 | # 0323
|
|---|
| 630 | source=12
|
|---|
| 631 | name="0323_nightly"
|
|---|
| 632 | bin=-1
|
|---|
| 633 | get_results
|
|---|
| 634 | name="0323_20min"
|
|---|
| 635 | bin=20
|
|---|
| 636 | get_results
|
|---|
| 637 | name="0323_period"
|
|---|
| 638 | bin=0
|
|---|
| 639 | get_results
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 | # crab
|
|---|
| 644 | source=5
|
|---|
| 645 | name="Crab_nightly"
|
|---|
| 646 | bin=-1
|
|---|
| 647 | get_results
|
|---|
| 648 | name="Crab_20min"
|
|---|
| 649 | bin=20
|
|---|
| 650 | get_results
|
|---|
| 651 | name="Crab_period"
|
|---|
| 652 | bin=0
|
|---|
| 653 | get_results
|
|---|
| 654 | name="Crab_season"
|
|---|
| 655 | bin=-365
|
|---|
| 656 | nightmin=20110716
|
|---|
| 657 | nightmax=20180716
|
|---|
| 658 | get_results
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 | name="1959_2016"
|
|---|
| 663 | source=7
|
|---|
| 664 | bin=-1
|
|---|
| 665 | nightmin=20160201
|
|---|
| 666 | nightmax=20161105
|
|---|
| 667 | get_results
|
|---|
| 668 |
|
|---|
| 669 | name="1959_all_variable"
|
|---|
| 670 | overwrite="no"
|
|---|
| 671 | source=7
|
|---|
| 672 | bin=-365
|
|---|
| 673 | nightmin=20120201
|
|---|
| 674 | nightmax=20130131
|
|---|
| 675 | get_results
|
|---|
| 676 | nightmin=20130201
|
|---|
| 677 | nightmax=20140131
|
|---|
| 678 | get_results
|
|---|
| 679 | nightmin=20140201
|
|---|
| 680 | nightmax=20150131
|
|---|
| 681 | get_results
|
|---|
| 682 | bin=0
|
|---|
| 683 | nightmin=20150201
|
|---|
| 684 | nightmax=20160131
|
|---|
| 685 | get_results
|
|---|
| 686 | bin=-1
|
|---|
| 687 | nightmin=20160201
|
|---|
| 688 | nightmax=20170131
|
|---|
| 689 | get_results
|
|---|
| 690 | bin=0
|
|---|
| 691 | nightmin=20170201
|
|---|
| 692 | nightmax=20180131
|
|---|
| 693 | get_results
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 | overwrite="yes"
|
|---|
| 698 | name="1959_all_variable2"
|
|---|
| 699 | overwrite="no"
|
|---|
| 700 | source=7
|
|---|
| 701 | bin=-365
|
|---|
| 702 | nightmin=20120201
|
|---|
| 703 | nightmax=20130131
|
|---|
| 704 | get_results
|
|---|
| 705 | nightmin=20130201
|
|---|
| 706 | nightmax=20140131
|
|---|
| 707 | get_results
|
|---|
| 708 | nightmin=20140201
|
|---|
| 709 | nightmax=20150131
|
|---|
| 710 | get_results
|
|---|
| 711 | bin=0
|
|---|
| 712 | nightmin=20150201
|
|---|
| 713 | nightmax=20160131
|
|---|
| 714 | get_results
|
|---|
| 715 | bin=-1
|
|---|
| 716 | nightmin=20160201
|
|---|
| 717 | nightmax=20160817
|
|---|
| 718 | get_results
|
|---|
| 719 | bin=0
|
|---|
| 720 | nightmin=20160818
|
|---|
| 721 | nightmax=20180131
|
|---|
| 722 | get_results
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 | overwrite="yes"
|
|---|
| 727 | bin=0
|
|---|
| 728 | source=3
|
|---|
| 729 | name="2344period"
|
|---|
| 730 | get_results
|
|---|
| 731 |
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 | # flare night (HESS)
|
|---|
| 735 | name="Mrk501_10min_flarenight"
|
|---|
| 736 | source=2
|
|---|
| 737 | bin=10
|
|---|
| 738 | nightmin=20140623
|
|---|
| 739 | nightmax=20140623
|
|---|
| 740 | get_results
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 | # flare night (HESS)
|
|---|
| 745 | name="Mrk501_5min_flarenight"
|
|---|
| 746 | source=2
|
|---|
| 747 | bin=5
|
|---|
| 748 | nightmin=20140623
|
|---|
| 749 | nightmax=20140623
|
|---|
| 750 | get_results
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 | # full sample
|
|---|
| 756 | name="Mrk421_all_nightly"
|
|---|
| 757 | source=1
|
|---|
| 758 | get_results
|
|---|
| 759 |
|
|---|
| 760 | name="Mrk501_all_nightly"
|
|---|
| 761 | source=2
|
|---|
| 762 | get_results
|
|---|
| 763 |
|
|---|
| 764 | name="1959_all_nightly"
|
|---|
| 765 | source=7
|
|---|
| 766 | get_results
|
|---|
| 767 |
|
|---|
| 768 | name="2344_all_nightly"
|
|---|
| 769 | source=3
|
|---|
| 770 | get_results
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 | name="HESE20160427"
|
|---|
| 775 | source=19
|
|---|
| 776 | nightmin=20160425
|
|---|
| 777 | bin=-10
|
|---|
| 778 | get_results
|
|---|
| 779 |
|
|---|
| 780 | name="AMON20160731"
|
|---|
| 781 | source=21
|
|---|
| 782 | nightmin=20160730
|
|---|
| 783 | bin=-10
|
|---|
| 784 | get_results
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|