Index: trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C	(revision 8139)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C	(revision 8140)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.1 2006-10-19 18:45:51 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.2 2006-10-20 18:26:00 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -101,4 +101,5 @@
 
     TString fCondition;
+    Bool_t  fGroupBy;
 
     void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
@@ -298,4 +299,5 @@
 
         gz.DrawClone("AP");
+
         if (gz0.GetN()>0)
             gz0.DrawClone("P");
@@ -306,5 +308,5 @@
 public:
     MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
-        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1)
+        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kFALSE)
     {
     }
@@ -335,4 +337,5 @@
     { fCondition = cond; }
     void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
+    void EnableGroupBy(Bool_t b=kTRUE) { fGroupBy=b; }
 
     Int_t QueryKeyOfSource(TString src)
@@ -343,6 +346,6 @@
     Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
     {
-        TString named  = "OpticalData.fTimestamp";
-        TString named2 = "fSkyLevel";
+        TString named  = "OpticalData.fTimeStamp";
+        TString named2 = fGroupBy ? "AVG(fZenithDistance)" : "fZenithDistance";
         TString namev  = value;
         TString join   = "fSequenceFirst";
@@ -355,21 +358,12 @@
 
         TString query;
-        query  = Form("select %s, %s, %s ", valued.Data(), named2.Data(), valuev.Data());
+        query  = Form("select %s, %s, %s ", valued.Data(), named2.Data(), value);
         query += Form("from %s ",           tabled.Data());
 
-        const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
-
-        if (!fDataSet && !interval && tabled=="Star")
-        {
-            if (!query.Contains("Star.fSequenceFirst"))
-                query += "left join Star on Sequences.fSequenceFirst=Star.fSequenceFirst ";
-            query += "where Star.fEffOnTime>300 ";
-        }
-
-        if (interval)
-        {
-            query += query.Contains(" where ") ? "and " : "where ";
-            query += Form("fRunStart between '%s' and '%s' ",
-                          fRequestFrom.Data(), fRequestTo.Data());
+        //const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
+
+        if (TString(value).Contains("Object."))
+        {
+            query += "left join Object on Object.fObjectKEY=OpticalData.fObjectKEY ";
         }
 
@@ -381,5 +375,8 @@
         }
 
-        query += "order by fTimestamp";
+        if (fGroupBy)
+            query += " GROUP BY fTimeStamp ";
+
+        query += "order by fTimeStamp";
 
         TSQLResult *res = fServer.Query(query);
@@ -421,5 +418,5 @@
     plot.SetDescription("Aperture Radius;R_{A}", "ApRad");
     plot.Plot("OpticalData.fApertureRadius", 0, 10, 1);
-
+/*
     plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s");
     plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure",  0, 0.2, 0.005);
@@ -433,4 +430,32 @@
     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
     plot.Plot("OpticalData.fInstrumentalMagErr",  0, 1, 0.01);
+  */
+    plot.SetDescription("m_{1};m_{1}", "M1");
+    plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2);
+
+    cond += " and Object.fObjectName not like '%/BL' and not IsNull(Object.fMagnitude) ";
+    plot.SetCondition(cond);
+
+    TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)");
+    ext += "+0.0028*fZenithDistance-0.08";
+/*
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Object);m_{1}-m_{true}", "ExtObj");
+    plot.Plot(ext, 0.5, 1.2, 0.01);
+    */
+
+    plot.EnableGroupBy();
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg");
+    plot.Plot(Form("AVG(%s)", ext.Data()), 0.05, 1.2, 0.01);
+
+    plot.SetDescription("Error m_{1}-m_{true} (Extinction per Image);ERR m_{1}-m_{true}", "ExtImgErr");
+    plot.Plot(Form("STD(%s)", ext.Data()), 0, 0.3, 0.005);
+
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour");
+    plot.Plot(Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data()),
+              0.5, 1.2, 0.01);
+
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight");
+    plot.Plot(Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data()),
+              0.5, 1.2, 0.01);
 }
 
