Index: trunk/www/dch/db_explorer.php
===================================================================
--- trunk/www/dch/db_explorer.php	(revision 19500)
+++ trunk/www/dch/db_explorer.php	(revision 19501)
@@ -76,4 +76,30 @@
    $offset = 0;
 
+switch($table)
+{
+case "LP":
+    $zdfactor="(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: 715 GeV
+    $crabflux="3.6";
+    break;
+case "ISDC":
+    $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";
+case "CutsLC":
+    $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";
+default:
+    $zdfactor="0";
+    $thfactor="0";
+    $crabflux="0";
+    break;
+}
+
+
 /*
 $join   = isset($_GET["join"]) ? "LEFT JOIN ".$_GET["join"]." USING(fNight,fRunID)" : "";
@@ -112,8 +138,8 @@
     $g = $_GET["good"];
 
-    if ($g&0x1) $good .= " AND fNumThreshold750/(cos(fZenithDistanceMean*PI()/180)+0.179*pow(sin(1.89*fZenithDistanceMean*PI()/180),5))/TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))/fEffectiveOn>3.7 ";
-    if ($g&0x2) $good .= " AND ((fNumEvtsAfterCleaning*1.0-fNum27Sec*1.0)/((-2381.1+2766.3*LOG10(fThresholdMinSet)-1049.9*POW(LOG10(fThresholdMinSet),2)+131.05*POW(LOG10(fThresholdMinSet),3))/21.15)/(COS(fZenithDistanceMean*PI()/180)+0.179*POW(SIN(1.89*fZenithDistanceMean*PI()/180),5)))/(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)>16.2 ";
-    if ($g&0x4) $good .= " AND (fNumEvtsAfterQualCuts/(cos(fZenithDistanceMean*PI()/180)+0.179*pow(sin(1.89*fZenithDistanceMean*PI()/180),5))/((8598.9- 13181*log10(fThresholdMinSet)+7567.4*pow(log10(fThresholdMinSet),2)-1925.2*pow(log10(fThresholdMinSet),3)+183*pow(log10(fThresholdMinSet),4))/9.2 ))/(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)>6.7 ";
-    if ($g&0x8) $good .= " AND (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)>0.6 ";
+    if ($g&0x1) $good .= " AND fR750Cor/fR750Ref BETWEEN 0.93 AND 1.3 ";
+    if ($g&0x2) $good .= " AND fZenithDistance < 45 ";
+    if ($g&0x4) $good .= " AND IF (ISNULL(fThresholdMinSet), fThresholdMedian, fThresholdMinSet) < 550 ";
+    if ($g&0x8) $good .= " AND fTNGDust<10 ";
 }
 
@@ -360,10 +386,10 @@
     $selecty="SUM(fNumSigEvts)/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)";
     $isnull="AND NOT ISNULL(fNumSigEvts)";
-    $titley="Signal events";
+    $titley="Signal rate";
     break;
 case 5:
     $selecty="SUM(fNumBgEvts)/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)";
     $isnull="AND NOT ISNULL(fNumBgEvts)";
-    $titley="Background events";
+    $titley="Background rate";
     break;
 case 6:
@@ -371,6 +397,33 @@
     $selecterr="EXCERR(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)*3600";
     $isnull="AND NOT ISNULL(fNumExcEvts) AND NOT ISNULL(fEffectiveOn)";
-    $titley="Excess events";
+    $titley="Excess rate";
     $unity="[1/h]";
+    $errors = $noerr ? 0 : 1;
+    break;
+case 31:
+    $selecty="SUM(fNumExcEvts/".$zdfactor."/".$thfactor.")*3600/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)";
+    $selecterr="EXCERR(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)*3600*SUM(fNumExcEvts/".$zdfactor."/".$thfactor.")/SUM(fNumExcEvts)";
+    $isnull="AND NOT ISNULL(fNumExcEvts) AND NOT ISNULL(fEffectiveOn) AND NOT ISNULL(fZenithDistanceMean) AND NOT (ISNULL(fThresholdMinSet) AND ISNULL(fThresholdMedian)) ";
+    $sqlhaving=" AND e < 1000 ";
+    $titley="Corrected excess rate";
+    $unity="[1/h]";
+    $errors = $noerr ? 0 : 1;
+    break;
+case 32:
+    $selecty="SUM(fNumExcEvts/".$zdfactor."/".$thfactor."/fCU)*3600/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)";
+    $selecterr="EXCERR(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)*3600*SUM(fNumExcEvts/".$zdfactor."/".$thfactor."/fCU)/SUM(fNumExcEvts)";
+    $isnull="AND NOT ISNULL(fNumExcEvts) AND NOT ISNULL(fEffectiveOn) AND NOT ISNULL(fZenithDistanceMean) AND NOT (ISNULL(fThresholdMinSet) AND ISNULL(fThresholdMedian)) ";
+    $sqlhaving=" AND e < 1000 ";
+    $titley="Flux";
+    $unity="[CU]";
+    $errors = $noerr ? 0 : 1;
+    break;
+case 33:
+    $selecty=$crabflux." * SUM(fNumExcEvts/".$zdfactor."/".$thfactor."/fCU)*3600/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)";
+    $selecterr=$crabflux." * EXCERR(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)*3600*SUM(fNumExcEvts/".$zdfactor."/".$thfactor."/fCU)/SUM(fNumExcEvts)";
+    $isnull="AND NOT ISNULL(fNumExcEvts) AND NOT ISNULL(fEffectiveOn) AND NOT ISNULL(fZenithDistanceMean) AND NOT (ISNULL(fThresholdMinSet) AND ISNULL(fThresholdMedian)) ";
+    $sqlhaving=" AND e < 1000 ";
+    $titley="Flux";
+    $unity="[10^-11/cm2/s]";
     $errors = $noerr ? 0 : 1;
     break;
@@ -898,4 +951,5 @@
 
     $( "#source" ).selectmenu();
+    $( "#table" ).selectmenu();
 
     $("#input_y").prop('disabled', $rate<42);
@@ -905,4 +959,5 @@
     $('#select_y').val($rate).selectmenu("refresh");
     $('#source').val($source).selectmenu("refresh");
+    $('#table').val('$table').selectmenu("refresh");
     $('#sql_cut').val("$cut");
     $('#input_x').val("$sql_x");
@@ -1177,10 +1232,16 @@
          <option value="42">Average</option>
       </optgroup>
-      <optgroup label="Analysis event rates [Effective on time]">
+      <optgroup label="Light curves">
+         <option value="6">Excess rate</option>
+         <option value="31">Corrected excess rate (Zd/TH)</option>
+         <option value="32">Flux [CU]</option>
+         <option value="33">Flux [10^-11/cm2/s]</option>
+      </optgroup>
+      <optgroup label="Analysis event rates [Eff. ontime]">
          <option value="5">Background rate</option>
          <option value="17">Signal rate</option>
          <option value="6">Excess rate</option>
       </optgroup>
-      <optgroup label="Raw event rates [Effective on time]">
+      <optgroup label="Raw event rates [Eff. ontime]">
          <option value="21">Physics trigger</option>
          <option value="22">Physics trigger minus 27s events</option>
@@ -1192,5 +1253,6 @@
       </optgroup>
 
-      <optgroup label="Corrected [Zd/TH] event rates [Eff. on time]">
+<!--
+      <optgroup label="Corrected [Zd/TH] event rates [Eff. ontime]">
          <option value="20">Events after cleaning minus 27s events</option>
 	 <option value="24">Events after background cuts</option>
@@ -1198,6 +1260,6 @@
          <option value="16">Artifical trigger TH750</option>
       </optgroup>
-
-      <optgroup label="Artificial trigger rates [Effective on time]">
+-->
+      <optgroup label="Artificial trigger rates [Eff. ontime]">
          <option value="7">27s events</option>
          <option value="8">TH500</option>
@@ -1211,11 +1273,12 @@
 
       <optgroup label="On time comparison">
-	 <option value="15">Avg difference Eff. on time minus Stop-Start time</option>
-	 <option value="26">Avg difference Eff. on time minus OnTimeAfterCuts</option>
+	 <option value="15">Avg Eff. ontime minus Stop-Start time</option>
+	 <option value="26">Avg Eff. ontime minus OnTimeAfterCuts</option>
 	 <option value="27">Avg Stop-Start time minus OnTimeAfterCuts</option>
 	 <option value="18">Avg FTM effective on time</option>
-	 <option value="19">Sum FTM on time divided by Sum FTM elapsed time</option>
-      </optgroup>
-
+	 <option value="19">Sum(FTM ontime) / Sum(FTM elapsed time)</option>
+      </optgroup>
+
+<!--
       <optgroup label="Others">
 	 <option value="28">Excess rate correction factor (fNumEvtsAfterBgCuts / PRELIMINARY)</option>
@@ -1223,4 +1286,5 @@
 	 <option value="30">Excess rate correction factor (fNumExcEvts / PRELIMINARY)</option>
       </optgroup>
+-->
     </select>
 
@@ -1232,4 +1296,15 @@
       <optgroup label="Sources">
 $sourceoptions
+      </optgroup>
+    </select>
+
+    <label for="table">Analysis</label>
+    <select name="t" id="table">
+      <optgroup label="Online Analysis">
+        <option value="LP">QLA</option>
+      </optgroup>
+      <optgroup label="Offline Analyses">
+        <option value="ISDC">ISDC</option>
+        <option value="CutsLC">CutsLC</option>
       </optgroup>
     </select>
@@ -1354,4 +1429,7 @@
   <dt>&r = 24</dt><dd>Rate after background cuts runwise corrected for zenith angle and threshold</dd>
   <dt>&r = 25</dz><dd>Rate after quallity cuts runwise corrected for zenith angle and threshold</dd>
+  <dt>&r = 31</dt><dd>corrected excess rate</dd>
+  <dt>&r = 32</dt><dd>flux [CU]</dd>
+  <dt>&r = 33</dt><dd>flux [10^-11/cm2/s]</dd>
   <dt>&r = 42</dz><dd>Plot average of &y=... (profile histogram with &y as weights)</dd>
   <dt>&r = 43</dz><dd>Plot sum of &y=... (histogram with &y as weights)</dd>
@@ -1373,5 +1451,5 @@
   <dt>&print</dt><dd>Show the plot only [&print] </dd>
   <dt>&s=...</dt><dd>Restrict to given source id [eg. &s=5] </dd>
-  <dt>&t=...</dt><dd>Choose table with analysis results (ISDC, LP:default) [eg. &t=ISDC] </dd>
+  <dt>&t=...</dt><dd>Choose table with analysis results (CutsLC, ISDC, LP:default) [eg. &t=CutsLC] </dd>
   <dt>&cut=...</dt><dd>Additional where statement to be added with AND [eg. &cut=fZenithDistance&lt;35]</dd>
   <dt>&min=...</dt><dd>y-axis minimum [eg. &min=0]</dd>
@@ -1385,4 +1463,5 @@
   <dt>&sum=...</dt><dd>short for &y=... [forces &r=43, eg. &y=fOnTime]</dd>
   <dt>&hist=...</dt><dd>short for &x=...  [forces &r=45, eg. &y=fOnTime]</dd>
+  <dt>&good=...</dt><dd>some predefined data quality selection: 1 (standard datacheck with R750), 2 (zd<45), 3 (TH<550), 4 (Dust<10), values can be combined [eg. &good=14]</dd>
 </dl>
 </div>
