Index: trunk/DataCheck/Tools/get_data.sh
===================================================================
--- trunk/DataCheck/Tools/get_data.sh	(revision 19445)
+++ trunk/DataCheck/Tools/get_data.sh	(revision 19446)
@@ -31,20 +31,14 @@
 
 
-
-
 # ToDo (notes DD): 
 # ----------------
-# - finalize policy and references
-# must-have
-# - update function for zd/th-correction
-# - update CU for QLA
-# - add CU for ISDC analysis
+# - check ETh and crabflux factor for QLA
+# - do conversion to fluxes using FACT Crab spectrum
 # - add < 20121212 data for QLA
-# - check crab flux
+# - new version of zd/th-correction and CU from Aachen when ready
 # nice-to-have
 # - add E2dNdE
 # - functionality to determine start time for seaon-binning
-# - offer several predefined datachecks?
-# - file as attachment to email ofr download.php
+# - file as attachment to email for download.php
 
 #
@@ -97,5 +91,5 @@
       echo "# If you intend to use data or information from this website, please let us know for reference."
    else
-      echo "#   As a member or associated member of the FACT Collaboration, you have access to internal information."
+      echo "#   As a member, associated member or collaborator of the FACT Collaboration, you have access to internal information."
       echo "#   Any publication using FACT internal information has to have the full FACT author list."
    fi
@@ -107,5 +101,5 @@
    echo "#" 
    echo "# Your Selection: " 
-   sourcename=`mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "SELECT fSourceName FROM Source WHERE fSourceKey="$source`
+   sourcename=`mysql --defaults-file=$sqlpw -s -e "SELECT fSourceName FROM Source WHERE fSourceKey="$source`
    echo "#   Source: "$sourcename 
    echo "#   Time range: "$nightmin"-"$nightmax 
@@ -124,5 +118,5 @@
    binning=`echo $bin | sed -e 's/-//'`" "$unit
    echo "#   Binning: "$binning
-   if [ "$expert" = "yes" ]
+   if [ "$expert" != "no" ]
    then
       echo "# Additional Internal Selection: "
@@ -146,5 +140,11 @@
       if [ "$usedch" == "yes" ]
       then
-         echo "#   Data quality selection based on the cosmic ray rate was applied."
+         echo "#   Data quality selection was applied. "
+         if [ "$dch" == "" ]
+         then 
+            echo "#      Standard data check based on cosmic-ray rate: "$dchstd
+         else
+            echo "#      You selected a custom datacheck: "$dch
+         fi
       fi
    fi
@@ -155,9 +155,39 @@
 {
    # some query parts
-
-   # some numbers for flux calculation
-   crabflux="3.37e-11"
-   fluxprec=13
-   crabflux="3.37"
+   
+   # these values use the Crab spectrum from HESS 2006 
+   case "$table" in 
+   "AnalysisResultsRunISDC")
+      zdfactor="pow(cos(fZenithDistanceMean*PI()/180)*exp(1-cos(fZenithDistanceMean*PI()/180)),4.2)" 
+      thfactor="(1.18-IF(ISNULL(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)*0.00062)" 
+      # ETh: 764 GeV 
+      crabflux="3.3"
+      ;;
+   "AnalysisResultsRunCutsLC")
+      zdfactor="pow(cos(fZenithDistanceMean*PI()/180)*exp(1-cos(fZenithDistanceMean*PI()/180)),4.5)" 
+      thfactor="(1.37-IF(ISNULL(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)*0.00118)" 
+      # ETh: 543 GeV
+      crabflux="5.7"
+      ;;
+   "AnalysisResultsRunLP")
+      zdfactor="(pow(cos(fZenithDistanceMean*PI()/180),3)+14.8/21.9*pow(sin(2*fZenithDistanceMean*PI()/180),5))" 
+      #zdfactor="(1/(pow(cos(fZenithDistanceMean*PI()/180),3)+14.8/21.9*pow(sin(2*fZenithDistanceMean*PI()/180),5)))" 
+      thfactor="(1-0.00124/1.21*(fThresholdMinSet-500)*(fThresholdMinSet>=500))"                                 
+      # ETh: 750 GeV ----> CHECK
+      crabflux="3.37"
+      ;;
+   "*")
+      zdfactor="0"
+      thfactor="0"
+      crabflux="0"
+      ;;
+   esac
+
+   # conversion from crab units to fluxes (if a different value is given in setup
+   if [ "$crabfluxconv" != "" ]
+   then
+      crabflux=$crabfluxconv #e-11
+   fi
+   #echo "crabflux: "$crabflux
    fluxprec=2
    
@@ -170,9 +200,8 @@
    zenith="fZenithDistance"
    thresh="IF(ISNULL(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)"
-   # correction factor for excess rate (formula by TB)
-   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))) "
-   # conversion to CU (determined by DD for QLA)
-   # https://www.fact-project.org/logbook/showthread.php?tid=4927
-   cufactor="CUQLA(fNight)" # missing: ISDC analysis
+   # correction for zd- and th-dependence
+   correvts=" fNumExcEvts/"$zdfactor"/"$thfactor
+   # conversion to CU - stored in each result-table (determined by DD Feb 2019)
+   cufactor="fCU" 
    # some calculations
    excerr="ExcErr(Sum(fNumSigEvts), SUM(fNumBgEvts))"
@@ -412,6 +441,6 @@
       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"
+      mysql --defaults-file=$sqlpw -s -e "$queryext" >> $fileext
+      #mysql --defaults-file=$sqlpw -e "$queryext"
    fi
    if [ "$mode" == "auto" ] && [ "$expert" == "no" ]
@@ -439,6 +468,6 @@
    echo $headerint >> $fileint
    #echo "$queryint"
-   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryint" >> $fileint
-   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryint" 
+   mysql --defaults-file=$sqlpw -s -e "$queryint" >> $fileint
+   #mysql --defaults-file=$sqlpw -e "$queryint" 
    if [ "$mode" == "auto" ]
    then
@@ -453,7 +482,7 @@
       print_policy >> $filecol
       print_selection >> $filecol
-      echo "# The following query was used: " >> $filecol
-      echo "# "$querycol >> $filecol
-      echo "#" >> $filecol
+      #echo "# The following query was used: " >> $filecol
+      #echo "# "$querycol >> $filecol
+      #echo "#" >> $filecol
    fi
    headercol="# time["$timeunit"] start["$timeunit"] stop["$timeunit"] excess-rate[evts/h] corrected_excess-rate[evts/h] flux[CU] flux[e-11/cm2/s] (stop-start)/2["$timeunit"] ontime[min]"
@@ -461,6 +490,6 @@
    echo $headercol >> $filecol
    #echo "$querycol"
-   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$querycol" >> $filecol
-   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$querycol
+   mysql --defaults-file=$sqlpw -s -e "$querycol" >> $filecol
+   #mysql --defaults-file=$sqlpw -e "$querycol
 }
 
@@ -472,11 +501,11 @@
    mode="auto"
    overwrite="yes"
-   # setup
+   # setup for usage with download.php
    datapath="/home/factwww/dch/data"
    #datapath="./data"
    sqlpw=/home/fact/.mysql.pw 
-   #sqlpw=/home/fact/.mysql.pw2 
-   host=10.0.100.21 
-   dbname=factdata 
+   #sqlpw=/home/fact/.mysql.pw2
+   #host=10.0.100.21 
+   #dbname=factdata 
    nightmin=$1
    nightmax=$2
@@ -537,12 +566,6 @@
 #  DB SETUP
 # ----------
-# path to file with mysql password
-sqlpw=/home/$USER/.mysql.pw 
-# host of mysql server with FACT DB
-#host=lp-fact # ISDC
-host=10.0.100.21 # LP or LP via vpn
-#host=localhost # your local machine in case you have a copy of DB
-# name of database
-dbname=factdata 
+# path to file with mysql setup (user, password, host, db-name)
+sqlpw=/home/$USER/.mysql.pw.local
 #
 # -------------
@@ -572,6 +595,7 @@
 # choose analysis 
 #table="AnalysisResultsAllQLA" # N/A
-table="AnalysisResultsRunLP" # QLA 
+#table="AnalysisResultsRunLP" # QLA 
 #table="AnalysisResultsRunISDC"  # ISDC
+table="AnalysisResultsRunCutsLC" # CutsLC
 # time range
 nightmin=20111115
@@ -596,4 +620,6 @@
 #dust=1
 #dust=10
+# use different conversion from CU to fluxes
+#crabfluxconv="2.5"
 
 
@@ -604,5 +630,5 @@
 # Adapt the lines below to your needs.                                                   #
 # Overwrite default settings above.                                                      #
-# The  data-request is sent with the line 'get_results.'                                 #
+# The  data-request is sent with the line 'get_results'.                                 #
 # Minumum setup: Define source key and name for file.                                    #
 # The list of source keys can be found at                                                #
@@ -610,9 +636,53 @@
 # More examples can be found further down.                                               #
 #                                                                                        #
-# REMARKS:                                                                               #
-# - correction of effect of zd and threshold not yet finalized and only valid for QLA    #
-# - no CU-conversion available for ISDC-analysis so far (that for QLA is used instead)   #
-#                                                                                        #
 # -------------------------------------------------------------------------------------- #
+
+#expert="yes"
+
+# Mrk 501
+source=2
+zdmax=90
+thmax=1500
+# new analysis
+table="AnalysisResultsRunCutsLC" # CutsLC
+nightmin=20140520
+nightmax=20140930
+name="Mrk501_nightly_newAnalysis_forHESS"
+bin=-1
+get_results
+name="Mrk501_7d_newAnalysis_forHESS"
+bin=-7
+get_results
+nightmin=20140623
+nightmax=20140623
+name="Mrk501_5min_FlareNight_newAnalysis_forHESS"
+bin=5
+get_results
+# isdc analysis
+thmax=850
+table="AnalysisResultsRunISDC"
+nightmin=20140520
+nightmax=20140930
+name="Mrk501_nightly_stdAnalysis_forHESS"
+bin=-1
+get_results
+name="Mrk501_7d_stdAnalysis_forHESS"
+bin=-7
+get_results
+nightmin=20140623
+nightmax=20140623
+name="Mrk501_5min_FlareNight_stdAnalysis_forHESS"
+bin=5
+get_results
+# qla
+thmax=500
+table="AnalysisResultsRunLP"
+nightmin=20140520
+nightmax=20140930
+name="Mrk501_nightly_QLA_forHESS"
+bin=-1
+get_results
+
+exit
 
 # 501 MAGIC 
@@ -620,7 +690,16 @@
 name="Mrk501_2014_forMAGIC"
 bin=-1
+crabfluxconv="2.87" # using threshold of 830GeV
+crabfluxconv="3.01" # using threshold of 830GeV and MAGIC Crab spectrum
 nightmin=20140714
 nightmax=20140805
 get_results
+
+name="Mrk501_2014_forMAGIC_20min"
+bin=20
+get_results
+
+
+exit
 
 bin=30
