Index: trunk/DataCheck/Tools/get_data.sh
===================================================================
--- trunk/DataCheck/Tools/get_data.sh	(revision 18895)
+++ trunk/DataCheck/Tools/get_data.sh	(revision 19028)
@@ -28,24 +28,8 @@
    # some basic query parts
 
-   # DataCheck (old)
-   ##data with old feedback and/or different bias voltage
-   #query=$query" AND fNight>20120420 AND NOT fNight IN (20120406,20120410,20120503) AND"
-   ## broken bias channel
-   #query=$query" NOT fNight BETWEEN 20121206 AND 20130110"
-   # bg-rate cut
-   zdparam=" pow(0.753833*cos(Radians(fZenithDistanceMean)), 7.647435)*exp(-5.753686*pow(Radians(fZenithDistanceMean),2.089609))"
-   thparam=" pow((if(isnull(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)-329.4203),2)*(-0.0000002044803) "
-   param=" (fNumEvtsAfterBgCuts/5-fNumSigEvts)/fOnTimeAfterCuts - "$zdparam" - "$thparam" "
-   dchold=" -0.085 < ("$param") "
-   dchold=$dchold" AND 0.25 > ("$param") "
-   # Datacheck (new) -> combine
-   dchval=" fNumEvtsAfterBgCuts/(1.41*POW(fZenithDistanceMean*PI()/180,2)+0.975)/(-7.53e-12*POW(10, LOG10(fThresholdMinSet)*3.69)+1.035)/TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))/fEffectiveOn "
-   # some semi-automatic datacheck
-   dch="  AND (("$dchval" BETWEEN 0.8 AND 1.7 AND fNight BETWEEN 20140520 AND 20150131) " #A
-   dch=$dch" OR  ("$dchval" BETWEEN 0.4 AND 1.6 AND fNight BETWEEN 20150201 AND 20150715) " #B
-   dch=$dch" OR  ("$dchval" BETWEEN 0.7 AND 1.4 AND fNight BETWEEN 20150716 AND 20160218) " #C
-   dch=$dch" OR  ("$dchval" BETWEEN 0.5 AND 1.0 AND fNight > 20160220) " #D
-   dch=$dch" OR  ("$dchold" AND fNight<20140520)) " #old
-
+   # data check based on artificial trigger rate
+   #dch=" AND fR750Cor/fR750Ref >0.93 "
+   dch=" AND fR750Cor/fR750Ref BETWEEN 0.93 AND 1.3 "
+   # ontime 
    ontime1=" TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn "
    ontime2=" fOnTimeAfterCuts "
@@ -56,6 +40,4 @@
    # some sanity checks
    where=$where" AND fRunTypeKey=1 "
-#   where=$where" AND NOT ISNULL(fNumSigEvts) AND NOT ISNULL(fNumBgEvts) "
-#   where=$where" AND NOT fRunStart='0000-00-00 00:00:00' AND NOT fRunStop='0000-00-00 00:00:00' "
    # zd cut
    where=$where" AND fZenithDistanceMax < "$zdmax
@@ -183,8 +165,8 @@
       queryint=$queryint" "$time" as time, "$start" as start, "$stop" as stop, "
       queryint=$queryint" round("$excrate", 1) as excrate, round("$correxcrate", 1) as correxcrate, "
-      queryint=$queryint" round($cu, 1) as cu, $flux as flux, "
+      queryint=$queryint" round("$cu", 2) as cu, "$flux" as flux, "
       queryint=$queryint" "$deltat" as deltat, round("$ontime", 1) as ontime, "
       queryint=$queryint" round("$excrateerr", 1) as excrateerr, round("$correxcrateerr", 1) as correxcrateerr, "
-      queryint=$queryint" round($cuerr, 1) as cuerr, $fluxerr as fluxerr, "
+      queryint=$queryint" round("$cuerr", 2) as cuerr, "$fluxerr" as fluxerr, "
       queryint=$queryint" round("$significance", 1) as significance, "
       queryint=$queryint" Min(fNight) as nightmin, "
@@ -257,10 +239,10 @@
       # AND NOT SUM(fNumBgEvts)=SUM(fNumSigEvts)
       
-      queryint=$queryint" "$querybase
-      queryext=$queryext" "$querybase
+      queryint=$queryint" "$querybase" order by 'time'"
+      queryext=$queryext" "$querybase" order by 'time'"
    fi
    
    
-   fileint=$path"/data/FACT_preliminary_"$name"_internal.dat"
+   fileint=$datapath"/FACT_preliminary_"$name"_internal.dat"
    if [ "$overwrite" = "yes" ]
    then 
@@ -279,5 +261,5 @@
    
    
-   fileext=$path"/data/FACT_preliminary_"$name".dat"
+   fileext=$datapath"/FACT_preliminary_"$name".dat"
    if [ "$overwrite" = "yes" ]
    then 
@@ -298,104 +280,42 @@
 # setup
 # db
-sqlpw=/home/$USER/.mysql.pw
-dbname=factdata20170804
-# selection
+sqlpw=/home/$USER/.mysql.pw # file with mysql credentials
+dbname=factdata # name of database
+# defaults for zd and threshold
+zdmax=90 # all data
+thmax=1500 # all data
+# output path
+path=`dirname $0`
+datapath=$path"/data"
+if ! [ -e $datapath ]
+then
+   mkdir $datapath
+fi
+# time unit 
+#timeunit=timestamp # default
+#timeunit=unix
 timeunit=mjd
-#bin=20 # min
+# time binning 
+# positive values: minutes
+# negative values: days
+# special case 0: period
+# for season binning choose -365 and according start date
+#bin=20 # minutes
 #bin=0 # period
+bin=-1 # nightly
 #bin=-365 # yearly
-bin=-1 # nightly
-zdmax=90
-thmax=1500
-path=`dirname $0`
-table="AnalysisResultsRunLP"
-table="AnalysisResultsAllQLA"
-overwrite="yes"
-bin=-1 # nightly
+# choose analysis 
+#table="AnalysisResultsAllQLA" # N/A
+#table="AnalysisResultsRunLP" # QLA 
+table="AnalysisResultsRunISDC"  # ISDC
+# time range
 nightmin=20111115
 nightmax=20171231
-
-
-# Mrk 421
-source=1
-name="Mrk421_nightly"
-bin=-1
-get_results
-name="Mrk421_20min"
-bin=20
-get_results
-name="Mrk421_3d"
-bin=-3
-get_results
-name="Mrk421_10d"
-bin=-10
-get_results
-name="Mrk421_period"
-bin=0
-get_results
-
-
-
-# Mrk 501
-source=2
-name="Mrk501_nightly"
-bin=-1
-get_results
-name="Mrk501_20min"
-bin=20
-get_results
-name="Mrk501_3d"
-bin=-3
-get_results
-name="Mrk501_10d"
-bin=-10
-get_results
-name="Mrk501_period"
-bin=0
-get_results
-
-
-
-# 2344
-source=3
-name="2344_nightly"
-bin=-1
-get_results
-name="2344_20min"
-bin=20
-get_results
-name="2344_period"
-bin=0
-get_results
-
-
-
-# 1959
-source=7
-name="1959_nightly"
-bin=-1
-get_results
-name="1959_20min"
-bin=20
-get_results
-name="1959_period"
-bin=0
-get_results
-
-
-
-# 0323
-source=12
-name="0323_nightly"
-bin=-1
-get_results
-name="0323_20min"
-bin=20
-get_results
-name="0323_period"
-bin=0
-get_results
-
-
+# overwrite dataset file? 
+# (useful to combine different binnings in one file -> set to "no")
+overwrite="yes"
+
+
+# example (adapt to your needs)
 
 # crab
@@ -418,7 +338,113 @@
 
 
+# end script here
 exit
 
+
+
+#
 # more examples
+#
+
+# Mrk 421
+source=1
+name="Mrk421_nightly"
+bin=-1
+get_results
+name="Mrk421_20min"
+bin=20
+get_results
+name="Mrk421_3d"
+bin=-3
+get_results
+name="Mrk421_10d"
+bin=-10
+get_results
+name="Mrk421_period"
+bin=0
+get_results
+
+
+
+# Mrk 501
+source=2
+name="Mrk501_nightly"
+bin=-1
+get_results
+name="Mrk501_20min"
+bin=20
+get_results
+name="Mrk501_3d"
+bin=-3
+get_results
+name="Mrk501_10d"
+bin=-10
+get_results
+name="Mrk501_period"
+bin=0
+get_results
+
+
+
+# 2344
+source=3
+name="2344_nightly"
+bin=-1
+get_results
+name="2344_20min"
+bin=20
+get_results
+name="2344_period"
+bin=0
+get_results
+
+
+
+# 1959
+source=7
+name="1959_nightly"
+bin=-1
+get_results
+name="1959_20min"
+bin=20
+get_results
+name="1959_period"
+bin=0
+get_results
+
+
+
+# 0323
+source=12
+name="0323_nightly"
+bin=-1
+get_results
+name="0323_20min"
+bin=20
+get_results
+name="0323_period"
+bin=0
+get_results
+
+
+
+# crab
+source=5
+name="Crab_nightly"
+bin=-1
+get_results
+name="Crab_20min"
+bin=20
+get_results
+name="Crab_period"
+bin=0
+get_results
+name="Crab_season"
+bin=-365
+nightmin=20110716
+nightmax=20180716
+get_results
+
+
 
 name="1959_2016"
@@ -486,8 +512,5 @@
 
 
-exit
-
 overwrite="yes"
-
 bin=0
 source=3
@@ -495,5 +518,5 @@
 get_results
 
-exit
+
 
 # flare night (HESS)
@@ -506,5 +529,4 @@
 
 
-exit
 
 # flare night (HESS)
@@ -517,5 +539,4 @@
 
 
-exit
 
 
@@ -537,5 +558,4 @@
 get_results
 
-exit
 
 
@@ -553,62 +573,3 @@
 
 
-# full sample 
-name="Mrk501_all_3d"
-source=2
-bin=-3
-get_results
-
-exit
-
-# full sample 
-name="Mrk421_all_3d"
-source=1
-bin=-3
-get_results
-
-name="1959_2016_nightly"
-source=7
-nightmin=20160301
-nightmax=20160831
-get_results
-
-# full sample 
-name="Mrk421_all_nightly"
-source=1
-get_results
-
-name="Mrk501_all_nightly"
-source=2
-get_results
-
-name="1959_all_nightly"
-source=7
-get_results
-
-bin=20 # min
-
-# full sample 
-name="Mrk421_all_20min"
-source=1
-get_results
-
-name="Mrk501_all_20min"
-source=2
-get_results
-
-name="1959_all_20min"
-source=7
-get_results
-
-exit
-
-name="Mrk501_all_weekly"
-nightmin=20140524
-nightmax=20140930
-source=2
-bin=-7
-get_results
-
-exit
-
-
+
