Index: trunk/DataCheck/Tools/get_data.sh
===================================================================
--- trunk/DataCheck/Tools/get_data.sh	(revision 19033)
+++ trunk/DataCheck/Tools/get_data.sh	(revision 19035)
@@ -35,6 +35,4 @@
 # ToDo (notes DD): 
 # ----------------
-# - limit creation of file for externals to nightly and 20 min
-# - add zd, th for internal for minute binning (daily done)
 # - update function for correction
 # - update CU for QLA
@@ -238,8 +236,14 @@
       
       # final part of the query
-      querybase=" FROM (SELECT fNight, @ot:="$ontimeif" AS ot, fRunStart AS start, fRunStop AS stop, fNumSigEvts AS sigevts, fNumBgEvts AS bgevts, "
+      querybase=" FROM (SELECT fNight, fZenithDistanceMin AS zdmin, fZenithDistanceMax AS zdmax, "$thresh" AS th, "
+      querybase=$querybase" @ot:="$ontimeif" AS ot, fRunStart AS start, fRunStop AS stop, fNumSigEvts AS sigevts, fNumBgEvts AS bgevts, "
       querybase=$querybase" "$correvts" AS corevts, CUQLA(fNight) AS cu, "
       querybase=$querybase" IF (@night=fNight AND FLOOR((@os+@ot)/"$bin"./60.)<1, @bl, @bl := @bl + 1) AS block, "
       querybase=$querybase" IF (@night=fNight AND FLOOR((@os+@ot)/"$bin"./60.)<1, @os:=@os + @ot, @os := @ot) AS os, @night :=fNight AS night "
+#      querybase=$querybase" IF (@zdmin<fZenithDistanceMin, @zdmin:=@zdmin, @zdmin:=fZenithDistanceMin) as zdmin, "
+#      querybase=$querybase" IF (@zdmin>fZenithDistanceMax, @zdmax:=@zdmax, @zdmax:=fZenithDistanceMax) as zdmax, "
+#      querybase=$querybase" IF (@thmin<"$thresh", @thmin:=@thmin, @thmin:="$thresh") as thmin, "
+#      querybase=$querybase" IF (@thmax>"$thresh", @thmax:=@thmax, @thmax:="$thresh") as thmax, "
+#      querybase=$querybase" fZenithDistanceMin as zdmin, fZenithDistanceMax as zdmax, "$thresh" as thmin, "$thresh" as thmax "
       querybase=$querybase$from" CROSS JOIN (SELECT @night :=0, @ot :=0, @os :=0, @bl:=0) PARAMS "
       querybase=$querybase$where" ORDER BY fRunStart) o GROUP BY block HAVING ontime>0.75*"$bin" ORDER BY 'time'"
@@ -252,5 +256,6 @@
       queryint=$queryint" "$significance2", "
       queryint=$queryint" avg(o.night) AS night, "
-      queryint=$queryint" "$numexc2", "$numsig2", "$numbg2" "
+      queryint=$queryint" "$numexc2", "$numsig2", "$numbg2", "
+      queryint=$queryint" Min(o.zdmin) AS zdmin, Max(o.zdmax) AS zdmax, Min(o.th) AS thmin, Max(o.th) AS thmax "
       queryint=$queryint" "$querybase
       
@@ -272,5 +277,5 @@
    if [ "$overwrite" = "yes" ]
    then 
-      echo "internal: "$fileint
+      echo "creating "$fileint" ..."
       echo "# This file was created at "`date` > $fileint
       # add query and policy here
@@ -283,22 +288,8 @@
    #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryint" 
    
-   
-   fileext=$datapath"/FACT_preliminary_"$name"_external.dat"
-   if [ "$overwrite" = "yes" ]
-   then 
-      echo "external: "$fileext
-      echo "# This file was created at "`date` > $fileext
-      # add query and policy here
-   fi
-   headerext="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] delta_time["$timeunit"] excrate_err[evts/h] "
-   echo $headerext >> $fileext
-   #echo "$queryext"
-   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryext" >> $fileext
-   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryext"
-
    filecol=$datapath"/FACT_preliminary_"$name"_collaborators.dat"
    if [ "$overwrite" = "yes" ]
    then 
-      echo "collaborators: "$filecol
+      echo "creating "$filecol" ..."
       echo "# This file was created at "`date` > $filecol
       # add query and policy here
@@ -310,4 +301,21 @@
    mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$querycol" >> $filecol
    #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$querycol
+   
+   # write file for externals only for allowed binnings
+   if [ $bin -eq 20 ] || [ $bin -eq -1 ]
+   then 
+      fileext=$datapath"/FACT_preliminary_"$name"_external.dat"
+      if [ "$overwrite" = "yes" ]
+      then 
+         echo "creating "$fileext" ..."
+         echo "# This file was created at "`date` > $fileext
+         # add query and policy here
+      fi
+      headerext="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] delta_time["$timeunit"] excrate_err[evts/h] "
+      echo $headerext >> $fileext
+      #echo "$queryext"
+      mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryext" >> $fileext
+      #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryext"
+   fi
 }
 
@@ -399,7 +407,14 @@
 nightmin=20140714
 nightmax=20140805
-get_results
-#bin=20
-#name="Mrk501_2014_forMAGIC20"
+#get_results
+
+bin=20
+nightmin=20140623
+nightmax=20140623
+name="Mrk501_test"
+get_results
+
+#bin=30
+#name="Mrk501_2014_forMAGIC30"
 #get_results
 
