Index: trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 8983)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 8986)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.45 2008-06-16 14:58:26 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.46 2008-06-21 13:53:33 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -133,9 +133,9 @@
         // Create TGraph objects
         TGraph &gt = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
-        gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
+        gt.SetNameTitle(Form("%s_time", res.GetFieldName(2)), Form("%s vs %s", res.GetFieldName(2), res.GetFieldName(0)));
         gt.SetMarkerStyle(kFullDotMedium);
 
         TGraph gz;
-        gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
+        gz.SetNameTitle(res.GetFieldName(2), Form("%s vs %s", res.GetFieldName(2), res.GetFieldName(1)));
         gz.SetMarkerStyle(kFullDotMedium);
 
@@ -257,4 +257,25 @@
         cerr << endl;
 
+        // format axis
+        TH1 *h = gt.GetHistogram();
+
+        const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
+        const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
+
+        // Create histogram
+        const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
+
+        TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
+        hist.SetDirectory(0);
+
+        // Fill data into histogra,
+        for (int i=0; i<gt.GetN(); i++)
+            hist.Fill(gt.GetY()[i]);
+
+        // Format histogram
+        if (fDescription.IsNull())
+            hist.SetXTitle(name);
+        hist.SetYTitle("Counts");
+
         TVirtualPad *pad = gPad;
 
@@ -269,9 +290,6 @@
         gPad->SetBottomMargin(0.08);
 
-        // format axis
-        TH1 *h = gt.GetHistogram();
-
         h->SetXTitle("Time");
-        h->SetYTitle(name);
+        h->SetYTitle(hist.GetXaxis()->GetTitle());
         h->GetXaxis()->SetTimeDisplay(1);
         h->GetYaxis()->SetTitleOffset(0.8);
@@ -312,10 +330,4 @@
             gPad->SetGridx();
 
-        const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
-        const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
-
-        // Use this to save the pad with the time development to a file
-        //gPad->SaveAs(Form("plotdb-%s.eps", title.Data()));
-
         // Go back to first (upper) pad, format it and divide it again
         pad->cd(1);
@@ -333,19 +345,4 @@
         gPad->SetGridy();
 
-        // Create histogram
-        const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
-
-        TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
-        hist.SetDirectory(0);
-
-        // Fill data into histogra,
-        for (int i=0; i<gt.GetN(); i++)
-            hist.Fill(gt.GetY()[i]);
-
-        // Format histogram
-        if (fDescription.IsNull())
-            hist.SetXTitle(name);
-        hist.SetYTitle("Counts");
-
         // plot histogram
         hist.DrawCopy("");
@@ -357,12 +354,8 @@
         gPad->SetGridy();
 
-        // format graph
-        TH1 *h2 = gz.GetHistogram();
-
-        h2->SetXTitle("Zd");
-        h2->SetYTitle(name);
-
         // draw graph
         gROOT->SetSelectedPad(0);
+        gz.GetXaxis()->SetTitle(res.GetFieldName(1));
+        gz.GetYaxis()->SetTitle(hist.GetXaxis()->GetTitle());
         gz.DrawClone("AP");
 
@@ -399,8 +392,11 @@
     void SetCondition(const char *cond="") { fCondition = cond; }
     void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
+    void SetTabName(const char *t) { fNameTab = t; }
     void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
     void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
     void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; }
     void SetSecondary(const char *ts) { fSecondary=ts; }
+
+    MStatusDisplay *GetDisplay() { return fDisplay; }
 
     Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
@@ -473,4 +469,5 @@
 
         TString where(fCondition);
+        /*
         if (!fDataSet && !interval && tablev=="Star")
         {
@@ -479,5 +476,5 @@
             where += "Star.fMuonNumber>300 ";
         }
-
+        */
         if (interval)
         {
@@ -496,4 +493,5 @@
             query += "WHERE ";
             query += where;
+            query += " ";
         }
 
@@ -504,5 +502,4 @@
         }
         query += Form("ORDER BY %s ", valued.Data()+1);
-
 
         // ------------------------------
@@ -526,5 +523,5 @@
 };
 
-void plotall(MPlot &plot)
+void plotalldb(MPlot &plot)
 {
     //plot.SetGroupBy(MPlot::kGroupByNight);
@@ -532,5 +529,5 @@
     plot.SetPrimaryDate("Sequences.fRunStart");
     plot.SetPrimaryNumber("Sequences.fSequenceFirst");
-    plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2");
+    plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2 as '<Zd>'");
 
     //inner camera
@@ -592,6 +589,8 @@
     //plot.Plot("Calibration.fPulsePosVar", 0, 0.03, 0.001);
 
+
     //from star*.root
     //muon
+    plot.SetCondition("Star.fMuonNumber>300");
     plot.SetDescription("Point Spred Function;PSF [mm]");
     plot.Plot("Star.fPSF",                     0,  30, 0.5);
@@ -600,4 +599,6 @@
     plot.SetDescription("Muon Rate after Muon Cuts;R [Hz]");
     plot.Plot("Star.fMuonRate",                0, 2.0, 0.05);
+    plot.SetCondition();
+
     //quality
     plot.SetDescription("Datarate [Hz]", "Rate");
@@ -656,5 +657,5 @@
     plot.SetDescription("RMS Arrival Time outer Camera;\\sigma_{T,O} [sl]", "RmsArrTmO");
     plot.Plot("Calibration.fArrTimeRmsOuter",  0, 4.5, 0.01);
-    plot.SetDescription("Number of unsuitable pixels outer Camera;N{O}", "UnsuitO");
+    plot.SetDescription("Number of unsuitable pixels outer Camera;N_{O}", "UnsuitO");
     plot.Plot("Calibration.fUnsuitableOuter",  0, 25, 1);
     //from signal*.root
@@ -690,5 +691,5 @@
     plot.SetDisplay(d);
     plot.SetRequestRange(from, to);
-    plotall(plot);
+    plotalldb(plot);
     d->SaveAsRoot("plotdb.root");
     d->SaveAsPS("plotdb.ps");
@@ -722,5 +723,5 @@
     plot.SetDisplay(d);
     plot.SetRequestRange("", "");
-    plotall(plot);
+    plotalldb(plot);
     d->SaveAsRoot("plotdb.root");
     d->SaveAsPS("plotdb.ps");
@@ -754,5 +755,5 @@
     plot.SetDisplay(d);
     plot.SetRequestPeriod(period);
-    plotall(plot);
+    plotalldb(plot);
     d->SaveAsRoot("plotdb.root");
     d->SaveAsPS("plotdb.ps");
