Index: /trunk/Cosy/tpoint/plot.C
===================================================================
--- /trunk/Cosy/tpoint/plot.C	(revision 9952)
+++ /trunk/Cosy/tpoint/plot.C	(revision 9953)
@@ -1,82 +1,25 @@
+#include <iostream>
 #include <iomanip>
-
-Double_t GetResidual(Double_t fRawEl,  Double_t fRawAz,
-                     Double_t fStarEl, Double_t fStarAz)
-{
-    fRawEl *= TMath::DegToRad();
-    fRawAz *= TMath::DegToRad();
-    fStarEl *= TMath::DegToRad();
-    fStarAz *= TMath::DegToRad();
-    Double_t del = fRawEl-fStarEl;
-    Double_t daz = fRawAz-fStarAz;
-    Double_t dphi2 = daz/2.;
-    Double_t cos2  = cos(dphi2)*cos(dphi2);
-    Double_t sin2  = sin(dphi2)*sin(dphi2);
-    Double_t d = cos(del)*cos2 - cos(fRawEl+fStarEl)*sin2;
-
-    Double_t dist = acos(d);
-
-    return dist * TMath::RadToDeg();
-}
-
-void DrawMarker(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1)
-    {
-        TView *view = pad->GetView();
-
-        if (!view)
-        {
-            cout << "No View!" << endl;
-            return;
-        }
-
-        TMarker mark0;
-        TMarker mark1;
-        mark0.SetMarkerStyle(kStar);
-        mark1.SetMarkerStyle(kStar);
-        mark1.SetMarkerColor(kRed);
-    
-        r0 /= 90;
-        r1 /= 90;
-        phi0 *= TMath::DegToRad();
-        phi1 *= TMath::DegToRad();
-    
-        Double_t x0[3] = { r0*cos(phi0), r0*sin(phi0), 0};
-        Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0};
-
-        mark0.DrawMarker(x0[0], x0[1]);
-        mark1.DrawMarker(x1[0], x1[1]);
-
-        return;
-        Double_t y0[3], y1[3];
-    
-        view->WCtoNDC(x0, y0);
-        view->WCtoNDC(x1, y1);
-    
-        mark0.DrawMarker(y0[0], y0[1]);
-        mark1.DrawMarker(y1[0], y1[1]);
-    }
-
-int fill(const char *fname, TGraph *g, TH1 *h)
-{
-/*
-    TH2F h2res1("Res2D1", " Dataset positions on the sky ", 32, 0, 360,  10, 0, 90);
-    h2res1.SetBit(TH1::kNoStats);
-    h2res1.DrawCopy("surf1pol");
-    gPad->Modified();
-    gPad->Update();
-    gPad->SetTheta(90);
-    gPad->SetPhi(-90);
-
-    DrawMarker(gPad, 45, 0, 0, 0);
-    gPad->Modified();
-    gPad->Update();
-
-    return;
-
-  */
+#include <fstream>
+
+#include <TGraph.h>
+#include <TCanvas.h>
+#include <TSystem.h>
+
+#include "mars/MTime.h"
+#include "mars/MMath.h"
+#include "mars/MAstro.h"
+#include "mars/MDirIter.h"
+#include "mars/MStatusDisplay.h"
+
+using namespace std;
+
+int ReadFile(const char *fname, TGraph &g1, TGraph &g2, TGraph &g0)
+{
     ifstream fin(fname);
 
-    cout << "Reading " << setw(23) << fname << "..." << flush;
-
+    cout << "Reading " << setw(23) << gSystem->BaseName(fname) << "..." << flush;
+
+    MTime t;
     while (1)
     {
@@ -90,168 +33,264 @@
 
         Float_t alt, az, dalt, daz, mjd;
-        sscanf(str.Data(), "%f %f %*f %*f %*f %*f %f %f %f",
-               &alt, &az, &dalt, &daz, &mjd);
-
-        if (dalt==0/* ||  GetResidual(alt, az, alt+dalt, az+daz)>0.1*/)
-            continue;
-
-        //cout << dalt << " " << daz << " " << GetResidual(alt, az, alt+dalt, az+daz) << endl;
-
-        mjd -=  53140.097505;
-
-        Double_t res = GetResidual(alt, az, alt-dalt, az-daz);
-
-        g[0].SetPoint(g[0].GetN(), g[0].GetN(), fabs(dalt));
-        g[1].SetPoint(g[1].GetN(), g[1].GetN(), fabs(daz));
-        g[2].SetPoint(g[2].GetN(), g[2].GetN(), res);
-
-        h->Fill(res);
-    }
-
-    cout << "done (" << setw(3) << (Int_t)h->GetEntries() << "/";
-    cout << setw(4) << g[0].GetN() << ") " << flush;
-
-    return g[0].GetN();
-}
-
-struct Description_t
-{
-    const char *fName;
-    const char *fTitle;
-    const char *fFile;
-};
-
-const Int_t counts = 22;
-Description_t desc[counts] =
-{
-    // No good pointing model has been applied yet
-  //  {"0404",  "TPoints Residuals 4/2004" ,   "tpoint/tpoint0404.txt"},
-  //  {"0405",  "TPoints Residuals 5/2004" ,   "tpoint/tpoint0405.txt"},
-  //  {"04081", "TPoints Residuals 8/2004-1" , "tpoint/tpoint0408-1.txt"},
-    {"04082", "TPoints Residuals 8/2004-2" , "tpoint/tpoint0408-2.txt"},
-    {"0409",  "TPoints Residuals 9/2004" ,   "tpoint/tpoint0409.txt"},
-    // Culmination tests
-  //  {"0410",  "TPoints Residuals 10/2004" ,  "tpoint/tpoint0410.txt"},
-    {"0411",  "TPoints Residuals 11/2004" ,  "tpoint/tpoint0411.txt"},
-    {"0412",  "TPoints Residuals 12/2004" ,  "tpoint/tpoint0412.txt"},
-    // Worse pointing due to realignment of the mirror
-    {"0503",  "TPoints Residuals 3/2005" ,   "tpoint/tpoint0503.txt"},
-    {"0504",  "TPoints Residuals 4/2005" ,   "tpoint/tpoint0504.txt"},
-    {"05051", "TPoints Residuals 5/2005-1" , "tpoint/tpoint0505-1.txt"},
-    // Mirror alignment has been fixed
-    {"05052", "TPoints Residuals 5/2005-2" , "tpoint/tpoint0505-2.txt"},
-    // Fixes to pointing model due to fixing a screw
-    {"0506", "TPoints Residuals 6/2005" , "tpoint/tpoint0506.txt"},
-
-    {"0508", "TPoints Residuals 8/2005" , "tpoint/tpoint0508.txt"},
-    {"0509", "TPoints Residuals 9/2005" , "tpoint/tpoint0509.txt"},
-    // Quick-and-dirty mirror alignment
-    {"0510", "TPoints Residuals 10/2005" , "tpoint/tpoint0510.txt"},
-    // New mirror alignment after Tenerife meeting
-    {"0511", "TPoints Residuals 11/2005" , "tpoint/tpoint0511.txt"},
-
-    {"0512", "TPoints Residuals 12/2005" , "tpoint/tpoint0512.txt"},
-    {"0601", "TPoints Residuals 1/2006" ,  "tpoint/tpoint0601.txt"},
-    {"0603", "TPoints Residuals 3/2006" ,  "tpoint/tpoint0603.txt"},
-    {"0604", "TPoints Residuals 4/2006" ,  "tpoint/tpoint0604.txt"},
-    //{"0605", "TPoints Residuals 5/2006" ,  "tpoint/tpoint0605.txt"},
-    //{"0606", "TPoints Residuals 6/2006" ,  "tpoint/tpoint0606.txt"},
-    {"0701", "TPoints Residuals 1/2007" ,  "tpoint/tpoint0701.txt"},
-    {"0702", "TPoints Residuals 2/2007" ,  "tpoint/tpoint0702.txt"},
-    {"0703", "TPoints Residuals 3/2007" ,  "tpoint/tpoint0703.txt"},
-    {"0704", "TPoints Residuals 4/2007" ,  "tpoint/tpoint0704.txt"},
-    {"0705", "TPoints Residuals 5/2007" ,  "tpoint/tpoint0705.txt"},
-};
-
-void plot()
-{
-    TGraph g[3];
-
-    MBinning bins(10, 0, 0.2);
-
-    TArrayI n(counts);
-
-    TH1F hx[counts];
-    for (int i=0; i<counts; i++)
-    {
-        hx[i].SetNameTitle(desc[i].fName, desc[i].fTitle);
-        hx[i].SetDirectory(0);
-        bins.Apply(hx[i]);
-
-        cout << setw(2) << i << ": " << flush;
-        n[i] = fill(desc[i].fFile, g, &hx[i]);
-        cout << " Mean: " << setw(5) << setprecision(2) << hx[i].GetMean() << " deg +/- " <<  hx[i].GetRMS()<<endl;
-    }
-
-    g[0].SetMarkerColor(kGreen);
-    g[1].SetMarkerColor(kMagenta);
-    g[2].SetMarkerColor(kBlack);
-    //g[2].SetLineColor(kBlack);
-    g[0].SetMarkerStyle(kFullDotMedium);
-    g[1].SetMarkerStyle(kFullDotMedium);
-    g[2].SetMarkerStyle(kFullDotLarge);
-
-    // --------- First Canvas ----------
-
-    new TCanvas("Vs Time", "");
-
-    TObject *obj[4];
+        if (sscanf(str.Data(), "%f %f %*f %*f %*f %*f %f %f %f",
+                   &az, &alt, &dalt, &daz, &mjd)!=5)
+            continue;
+
+        if (dalt==0)
+            continue;
+
+        Double_t res = MAstro::GetDevAbs(90-(alt-dalt), -dalt, -daz)*60;
+
+        if (res>12)
+            continue;
+
+        t.SetMjd(mjd);
+
+        g0.SetPoint(g0.GetN(), t.GetAxisTime(), g0.GetN());
+        g1.SetPoint(g1.GetN(), t.GetAxisTime(), res);
+        g2.SetPoint(g2.GetN(), g2.GetN(),       res);
+    }
+
+    cout << g1.GetN() << endl;
+
+    return g1.GetN();
+}
+
+void DrawGrid(TH1 &h)
+{
+    TGraph l;
+    l.SetLineStyle(kDashed);
+    l.SetLineWidth(2);
+    l.SetLineColor(kBlue);
+
+    Int_t style[] = { kSolid, 9, 7 };
+
+    Double_t x[2] = { h.GetXaxis()->GetXmin(), h.GetXaxis()->GetXmax() };
+    Double_t y[2];
 
     for (int i=0; i<3; i++)
     {
-        g[i].SetFillColor(kWhite);
-        g[i].SetLineColor(kWhite);
-        obj[i] = g[i].Clone();
-        obj[i]->SetBit(kCanDelete);
-        obj[i]->Draw(i==0?"AP":"P");
-    }
-
-    TLegend leg(0.905, 0.86, 0.99, 0.99);
-    leg.AddEntry(obj[0], "  \\Delta\\theta");
-    leg.AddEntry(obj[1], "  \\Delta\\phi");
-    leg.AddEntry(obj[2], "  \\Delta");
-    leg.DrawClone()->SetBit(kCanDelete);
-
-    TLine l;
+        y[0] = y[1] = i+1;
+        l.SetLineStyle(style[i]);
+        l.DrawGraph(2, x, y, "L");
+    }
+
+    if (x[0]<1e6)
+        return;
+
+    Double_t X[2];
+    Double_t Y[2] = { h.GetMinimum(), h.GetMaximum() };
+
+    l.SetLineWidth(1);
+
+    for (int i=2004; i<2020; i++)
+    {
+        for (int j=0; j<12; j++)
+        {
+            X[0] = X[1] = MTime(i, 1+j, 1).GetAxisTime();
+
+            if (X[0]<x[0] || X[0]>x[1])
+                continue;
+
+            l.SetLineStyle(j==0 ? kDashed : kDotted);
+            l.DrawGraph(2, X, Y, "L");
+        }
+    }
+}
+
+void DrawTimes(TH1 &h)
+{
+    TGraph l;
     l.SetLineColor(kBlue);
-    for (int i=0; i<n.GetSize(); i++)
-        l.DrawLine(n[i], 0, n[i], 0.2);
-
-    // --------- Second Canvas ----------
-
-    new TCanvas("Distrib", "");
-
-    Double_t max=0;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        if (hx[i].GetEntries()==0)
-        {
-            cout << "Skip #" << i << endl;
-            continue;
-        }
-
-        hx[i].Scale(1./hx[i].GetEntries());
-        max = TMath::Max(max, hx[i].GetMaximum());
-    }
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        hx[i].SetMaximum(max*1.05);
-        if (i<6)
-            hx[i].SetLineColor(kRed+i);
-        else
-            hx[i].SetMarkerStyle(kPlus+i-6);
-
-
-    }
-
-    for (int i=0; i<counts; i++)
-        hx[i].DrawCopy(i==0?"LP":"LPsame");
-
-    return;
-
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        cout << "Mean:  " << Form("%.3f +- %.3f", hx[i].GetMean(), hx[i].GetRMS());
-        cout << "   (Overflows=" << hx[i].GetBinContent(hx[i].GetNbinsX()+1)*hx[i].GetEntries() << ")" << endl;
-    }
-}
+
+    Double_t x[2];
+    Double_t y[2] = { h.GetMinimum(), h.GetMaximum() };
+
+    for (int i=0; dates[i+1]>0; i++)
+    {
+        x[0] = x[1] = dates[i];
+        l.DrawGraph(2, x, y, "L");
+    }
+
+    DrawGrid(h);
+}
+
+Int_t GetBin(TGraph &times, Int_t i)
+{
+    return TMath::BinarySearch(times.GetN(), times.GetX(), dates[i]);;
+}
+
+void DrawIndices(TGraph &times, TH1 &h)
+{
+    TGraph l;
+    l.SetLineStyle(kDashed);
+    l.SetLineColor(kBlue);
+
+    Double_t x[2];
+    Double_t y[2] = { h.GetMinimum(), h.GetMaximum() };
+
+    for (int i=0; dates[i+1]>0; i++)
+    {
+        Int_t bin = GetBin(times, i);
+        if (bin<0)
+            continue;
+
+        x[0] = x[1] = bin+0.5;
+        l.DrawGraph(2, x, y, "L");
+    }
+
+    DrawGrid(h);
+}
+
+void plot(MDirIter &Next)
+{
+    Next.Sort();
+
+    TGraph g1;
+    TGraph g2;
+    TGraph g0;
+
+    while (1)
+    {
+        TString name=Next();
+        if (name.IsNull())
+            break;
+
+        ReadFile(name, g1, g2, g0);
+    }
+
+    MStatusDisplay *d = new MStatusDisplay;
+
+    gROOT->SetSelectedPad(0);
+    TCanvas &c0 = d->AddTab("TimeLine");
+    c0.SetGrid();
+
+    g0.SetTitle("TimeLine");
+    g0.GetXaxis()->SetTimeDisplay(1);
+    g0.SetMarkerStyle(kFullDotMedium);
+    g0.SetLineWidth(1);
+    g0.SetLineColor(kGreen);
+    g0.DrawClone("ALP");
+
+    DrawTimes(*g0.GetHistogram());
+
+
+    gROOT->SetSelectedPad(0);
+    TCanvas &c1 = d->AddTab("ResDate");
+    //c1.SetGrid();
+
+    g1.SetTitle("Measured Residual vs. Date");
+    g1.GetXaxis()->SetTimeDisplay(1);
+//    g1.SetMaximum(10);
+    g1.SetMarkerStyle(kFullDotMedium);
+    g1.DrawClone("AP");
+
+    DrawTimes(*g1.GetHistogram());
+
+
+    gROOT->SetSelectedPad(0);
+    TCanvas &c2 = d->AddTab("ResIdx");
+    c2.SetGrid();
+
+    g2.SetTitle("Measured Residual vs. Index");
+//    g2.SetMaximum(0.1);
+    g2.SetMarkerStyle(kFullDotMedium);
+    g2.DrawClone("AP");
+
+    DrawIndices(g0, *g2.GetHistogram());
+
+    Double_t prob[4] = { 0.5, MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
+    Double_t quant[4];
+
+    int n;
+    for (n=0; dates[n]>0; n++);
+
+    TH1F h0("Q98", "", n-1, dates);
+    TH1F h1("Q95", "", n-1, dates);
+    TH1F h2("Q68", "", n-1, dates);
+    TH1F h3("Q50", "", n-1, dates);
+
+    Int_t first = 0;
+
+    cout << "n=" << n << endl;
+
+    for (int i=0; dates[i+1]>0; i++)
+    {
+        Int_t bin0 = GetBin(g0, i);
+        Int_t bin1 = GetBin(g0, i+1);
+
+        cout << i << " " << bin0 << " " << bin1 << endl;
+        if (bin0<0)
+            continue;
+
+        if (bin0==bin1)
+            continue;
+
+        TMath::Quantiles(bin1-bin0, 4, g2.GetY()+bin0, quant, prob, kFALSE, NULL, 7);
+
+        h0.SetBinContent(i+1, quant[0]);
+        h1.SetBinContent(i+1, quant[1]);
+        h2.SetBinContent(i+1, quant[2]);
+        h3.SetBinContent(i+1, quant[3]);
+
+        if (first==0)
+            first = i;
+    }
+
+
+    gROOT->SetSelectedPad(0);
+    TCanvas &c4 = d->AddTab("Quantiles");
+    //c4.SetGrid();
+
+    h2.SetFillColor(19);
+    h1.SetFillColor(16);
+    h0.SetFillColor(13);
+
+    h2.SetTitle("Measured Residual-Distribution vs. Date");
+    h2.SetYTitle("Residual [arcmin]");
+    h2.SetStats(kFALSE);
+    h2.GetXaxis()->SetTimeDisplay(1);
+    h2.GetXaxis()->SetTimeFormat("%y/%m");
+    h2.GetYaxis()->CenterTitle();
+    h2.SetMinimum(0);
+    //.SetMaximum(h2.GetMaximum()*1.2);
+    h2.SetMarkerStyle(kFullDotMedium);
+    h2.GetXaxis()->SetRange(first, h3.GetNbinsX());
+    h2.DrawCopy();
+
+    //.DrawCopy("same");
+    h1.DrawCopy("same");
+    h0.DrawCopy("same");
+
+    TGraph g;
+    for (int i=0; i<h2.GetNbinsX(); i++)
+    {
+        Double_t x[2] = { h2.GetBinLowEdge(i+1), h2.GetBinLowEdge(i+1) };
+        Double_t y[2] = { 0, h2.GetBinContent(i+1) };
+
+        g.DrawGraph(2, x, y, "L");
+    }
+
+    DrawGrid(h2);
+
+    gROOT->SetSelectedPad(0);
+    TCanvas &c5 = d->AddTab("Combined");
+
+    h2.DrawCopy();
+    h1.DrawCopy("same");
+    h0.DrawCopy("same");
+
+    for (int i=0; i<h2.GetNbinsX(); i++)
+    {
+        Double_t x[2] = { h2.GetBinLowEdge(i+1), h2.GetBinLowEdge(i+1) };
+        Double_t y[2] = { 0, h2.GetBinContent(i+1) };
+
+        g.DrawGraph(2, x, y, "L");
+    }
+
+    g1.DrawClone("P");
+
+    DrawGrid(h2);
+
+
+}
Index: /trunk/Cosy/tpoint/plot_m1.C
===================================================================
--- /trunk/Cosy/tpoint/plot_m1.C	(revision 9952)
+++ /trunk/Cosy/tpoint/plot_m1.C	(revision 9953)
@@ -1,120 +1,7 @@
-#include <iomanip>
+#include "mars/MTime.h"
 
-void DrawMarker(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1)
-    {
-        TView *view = pad->GetView();
+using namespace std;
 
-        if (!view)
-        {
-            cout << "No View!" << endl;
-            return;
-        }
-
-        TMarker mark0;
-        TMarker mark1;
-        mark0.SetMarkerStyle(kStar);
-        mark1.SetMarkerStyle(kStar);
-        mark1.SetMarkerColor(kRed);
-    
-        r0 /= 90;
-        r1 /= 90;
-        phi0 *= TMath::DegToRad();
-        phi1 *= TMath::DegToRad();
-    
-        Double_t x0[3] = { r0*cos(phi0), r0*sin(phi0), 0};
-        Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0};
-
-        mark0.DrawMarker(x0[0], x0[1]);
-        mark1.DrawMarker(x1[0], x1[1]);
-
-        return;
-        Double_t y0[3], y1[3];
-    
-        view->WCtoNDC(x0, y0);
-        view->WCtoNDC(x1, y1);
-    
-        mark0.DrawMarker(y0[0], y0[1]);
-        mark1.DrawMarker(y1[0], y1[1]);
-    }
-
-int fill(const char *fname, TGraph *g, TH1 *h)
-{
 /*
-    TH2F h2res1("Res2D1", " Dataset positions on the sky ", 32, 0, 360,  10, 0, 90);
-    h2res1.SetBit(TH1::kNoStats);
-    h2res1.DrawCopy("surf1pol");
-    gPad->Modified();
-    gPad->Update();
-    gPad->SetTheta(90);
-    gPad->SetPhi(-90);
-
-    DrawMarker(gPad, 45, 0, 0, 0);
-    gPad->Modified();
-    gPad->Update();
-
-    return;
-
-  */
-    ifstream fin(fname);
-
-    cout << "Reading " << setw(23) << gSystem->BaseName(fname) << "..." << flush;
-
-    while (1)
-    {
-        TString str;
-        str.ReadLine(fin);
-        if (!fin)
-            break;
-
-        if (str.Contains("#"))
-            continue;
-
-        Float_t alt, az, dalt, daz, mjd;
-        sscanf(str.Data(), "%f %f %*f %*f %*f %*f %f %f %f",
-               &az, &alt, &dalt, &daz, &mjd);
-
-        if (dalt==0/* ||  GetResidual(alt, az, alt+dalt, az+daz)>0.1*/)
-            continue;
-
-        mjd -=  53140.097505;
-
-        Double_t res = MAstro::GetDevAbs(90-(alt-dalt), -dalt, -daz);
-
-        g[0].SetPoint(g[0].GetN(), g[0].GetN(), fabs(dalt));
-        g[1].SetPoint(g[1].GetN(), g[1].GetN(), fabs(daz));
-        g[2].SetPoint(g[2].GetN(), g[2].GetN(), res);
-
-        h->Fill(res);
-    }
-
-    cout << "done (" << setw(3) << (Int_t)h->GetEntries() << "/";
-    cout << setw(4) << g[0].GetN() << ") " << flush;
-
-    return g[0].GetN();
-}
-
-struct Description_t
-{
-    const char *fName;
-    const char *fTitle;
-    const char *fFile;
-};
-
-const Int_t counts = 29+10+18+1+13+11+31-27+3+5+18;
-Description_t desc[counts] =
-{
-    /*
-     //   29. Apr. 2004    ~25800
-     //    5. Aug. 2004    ~32000
-     //   19. Aug. 2004    ~33530
-     //    7. Jun. 2005    ~57650
-     //    8. Jun. 2005
-     //    9. Jun. 2005    ~57860
-     //   12. Sep. 2005    ~68338
-     //   24. Nov. 2005    ~75562
-     //   17. Oct. 2006   ~103130
-     //   17. Jun. 2007   ~248193
-     */
-
     // Culmination tests
     //{"0411",  "TPoints Residuals 11/2004" ,  "tpoint/tpoint0411.txt"},
@@ -146,471 +33,54 @@
     //{"05111", "TPoints Residuals 11/2005-1" , "tpoint/tpoint0511-1.txt"},
 
-    // New pointing model installed (24.11.2005)
-    {"05112", "TPoints Residuals 11/2005-2" , "tpoint/tpoint0511-2.txt"},
-    {"+0512", "TPoints Residuals 12/2005" , "tpoint/tpoint0512.txt"},
-    {"+0601", "TPoints Residuals 1/2006" ,  "tpoint/tpoint0601.txt"},
-    {"+0603-1", "TPoints Residuals 3/2006-1" ,  "tpoint/tpoint0603-1.txt"},
+    // [...]
+*/
 
-    // Changes to the mirror
-    {"0603-2", "TPoints Residuals 3/2006-2" ,  "tpoint/tpoint0603-2.txt"},
-    {"+0604", "TPoints Residuals 4/2006" ,  "tpoint/tpoint0604.txt"},
-    {"+0607", "TPoints Residuals  7/2006" ,  "tpoint/tpoint0607.txt"},
-    {"+0608", "TPoints Residuals  8/2006" ,  "tpoint/tpoint0608.txt"},
-    {"+0609", "TPoints Residuals  9/2006" ,  "tpoint/tpoint0609.txt"},
-    {"+0610", "TPoints Residuals 10/2006" ,  "tpoint/tpoint0610.txt"},
+Double_t dates[] = {
+    MTime(2005,  3, 20).GetAxisTime(),
+    MTime(2005,  4, 29).GetAxisTime(),
+    MTime(2005,  5, 25).GetAxisTime(),
+    MTime(2005,  6,  8).GetAxisTime(), // New pointing model
+    MTime(2005,  8, 15).GetAxisTime(),
+    //        MTime(2005,  9, 12).GetAxisTime(), // New pointing model
+    MTime(2005, 11, 10).GetAxisTime(), // New mirror alignment after Tenerife meeting
+    MTime(2005, 11, 24).GetAxisTime(), // New pointing model
+    MTime(2006,  3, 19).GetAxisTime(), // Changes to the mirror
+    //    2006,  4, 23                 // Mirror refocussing
+    MTime(2006, 10, 17).GetAxisTime(), // New pointing model
+    MTime(2007,  6, 17).GetAxisTime(), // New pointing model
+    MTime(2007,  8,  4).GetAxisTime(), // Mirror refocussing
+    MTime(2007, 10, 18).GetAxisTime(), // New pointing model
+    MTime(2008,  1, 14).GetAxisTime(), // New pointing model
+    MTime(2008,  6, 11).GetAxisTime(), // New pointing model
+    MTime(2008,  6, 18).GetAxisTime(), // New pointing model
+    //    2009,  3,  7                 // New pointing model
+    //    2009,  5, 14                 // New pointing model
+    // Are we missing TPoints between 080618 and 090501??
+    MTime(2009,  5,  1).GetAxisTime(), // Drive upgrade started
+    MTime(2009,  5, 11).GetAxisTime(), // Upgrade finished
+    MTime(2009,  5, 12).GetAxisTime(), // First new pointing model
+    MTime(2009,  5, 13).GetAxisTime(), // Second new pointing model
+    MTime(2009,  6, 11).GetAxisTime(), // Jump (reason unknown)
+    MTime(2009,  7, 23).GetAxisTime(), // New LUTs
+    MTime(2009,  8, 17).GetAxisTime(), // New pointing model
+    MTime(2010, 02, 01).GetAxisTime(), // New pointing model
+    //    2010, 02, 03                 // New LUTs for M2(!)
+    MTime(2010, 02, 27).GetAxisTime(), // New pointing model
+    MTime(2010, 03, 31).GetAxisTime(), // New pointing model
+    //    2010, 06, 14                 // New LUTs
+    MTime(2010, 07, 03).GetAxisTime(), // New LUTs
+    MTime(2010,  9, 29).GetAxisTime(), // New pointing model
+    MTime(-1).GetAxisTime(),
+    -1
+};
 
-    // New pointing model: 6/10/17
-    {"0611", "TPoints Residuals 11/2006" ,  "tpoint/tpoint0611.txt"},
-    {"+0612", "TPoints Residuals 12/2006" ,  "tpoint/tpoint0612.txt"},
-    {"+0701", "TPoints Residuals  1/2007" ,  "tpoint/tpoint0701.txt"},
-    {"+0702", "TPoints Residuals  2/2007" ,  "tpoint/tpoint0702.txt"},
-    {"+0703", "TPoints Residuals  3/2007" ,  "tpoint/tpoint0703.txt"},
-
-    {"+0704", "TPoints Residuals  4/2007" ,  "tpoint/tpoint0704.txt"},
-    {"+0705", "TPoints Residuals  5/2007" ,  "tpoint/tpoint0705.txt"},
-    {"+0706", "TPoints Residuals  6/2007" ,  "tpoint/tpoint0706.txt"},
-    {"+07071", "TPoints Residuals  7/2007-1" ,  "tpoint/tpoint0707-1.txt"},
-    {"+07072", "TPoints Residuals  7/2007-2" ,  "tpoint/tpoint0707-2.txt"},
-
-    // New pointing model: 07/06/17
-    {"",      "",                         ""},
-
-    // AMC adjust:         07/08/04
-    {"0708",  "TPoints Residuals 7/8/23", "tpoint/m1/tpoints20070823.txt"},
-
-    // New pointing model: 07/10/18
-    {"",      "",                         ""},
-
-    // New pointing model: 08/01/14
-    {"0801",  "TPoints Residuals 7/8/23", "tpoint/m1/tpoints20080115.txt"},
-
-    // New pointing model 080611
-    {"0806", "TPoints Residuals 7/8/23", "tpoint/tpoint0806.txt"},
-
-    // New pointing model 080618
-    {"0807",  "",                         "tpoint/tpoint0807.txt"},
-    {"+0807", "",                         "tpoint/tpoint0808.txt"},
-    {"+0807", "",                         "tpoint/tpoint0811.txt"},
-    {"+0807", "",                         "tpoint/tpoint0812.txt"},
-    {"+0901", "",                         "tpoint/tpoint0901.txt"},
-
-    // Drive upgrade started
-    {"", "",                         ""},
-
-    // Drive Upgrade finished 090511
-    {"090512", "TPoints Residuals 7/8/23",  "tpoint/m1/2009_05_12/tpoint_20090511_220118.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_221333.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_222434.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_223152.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_223706.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_224056.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090511_231933.txt"},
-    {"+090512", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_12/tpoint_20090512_011131.txt"},
-
-    // First new pointing model 090512
-    {"090513", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_13/tpoint_20090512_210644.txt"},
-    {"+090513", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_13/tpoint_20090513_002757.txt"},
-    {"+090513", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_13/tpoint_20090513_025124.txt"},
-    {"+090513", "TPoints Residuals 7/8/23", "tpoint/m1/2009_05_13/tpoint_20090513_033505.txt"},
-
-    // Second new pointing model 090513
-    {"090514", "TPoints 09/05/14", "tpoint/m1/2009_05_14/tpoint_20090514_011903.txt"},
-
-    {"090517", "TPoints 09/05/17" ,"tpoint/m1/2009_05_17/tpoint_20090516_234825.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_05_17/tpoint_20090517_023340.txt"},
-    // New period
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_01/tpoint_20090531_215148.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_01/tpoint_20090531_222549.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_02/tpoint_20090601_223009.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_03/tpoint_20090602_213509.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_03/tpoint_20090603_011936.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_04/tpoint_20090603_215840.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_04/tpoint_20090603_230510.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_05/tpoint_20090604_215943.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_05/tpoint_20090604_232320.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_10/tpoint_20090609_231948.txt"},
-    {"+090517","TPoints 09/05/17", "tpoint/m1/2009_06_11/tpoint_20090611_011155.txt"},
-
-    // ------- Something happened (reason unknown) --------
-
-    {"090613","TPoints 09/05/17", "tpoint/m1/2009_06_11/tpoint_20090611_023625.txt"},
-
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_06_13/tpoint_20090613_033838.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_06_14/tpoint_20090614_021257.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_06_18/tpoint_20090618_041433.txt"},
-
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_02/tpoint_20090701_215304.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_02/tpoint_20090701_222059.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_02/tpoint_20090701_224051.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_02/tpoint_20090701_225615.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_02/tpoint_20090701_230946.txt"},
-
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_03/tpoint_20090702_225940.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_04/tpoint_20090703_224721.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_05/tpoint_20090705_012638.txt"},
-
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_12/tpoint_20090712_014300.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_12/tpoint_20090712_024710.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_13/tpoint_20090713_004241.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_13/tpoint_20090713_025934.txt"},
-
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_14/tpoint_20090714_024729.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_15/tpoint_20090715_021320.txt"},
-    {"+090613","TPoints 09/05/17", "tpoint/m1/2009_07_15/tpoint_20090715_025237.txt"},
-
-    // ----- AMC adjust (23.7.) -----
-
-    {"090723","TPoints 09/05/17", "tpoint/m1/2009_07_24/tpoint_20090724_051142.txt"},
-    {"+090723", "TPoints 08/2009" , "tpoint/m1/2009_08_02/tpoint_20090801_223848.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_03/tpoint_20090802_224434.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_04/tpoint_20090803_230214.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_10/tpoint_20090809_233524.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_10/tpoint_20090810_014642.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_10/tpoint_20090810_020616.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_11/tpoint_20090810_232543.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_12/tpoint_20090812_001846.txt"},
-    {"+090723","TPoints 08/2009" , "tpoint/m1/2009_08_13/tpoint_20090813_030807.txt"},
-
-    // ------ 09/08/17 new pointing model -------
-
-    {"090817","TPoints", "tpoint/m1/2009_09_01/tpoint_20090831_233034.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_02/tpoint_20090901_231918.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_02/tpoint_20090902_005204.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_08/tpoint_20090907_213404.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_09/tpoint_20090908_225027.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_09/tpoint_20090908_231720.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_09/tpoint_20090909_010649.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_10/tpoint_20090909_235222.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_10/tpoint_20090910_025054.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_12/tpoint_20090912_004826.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_17/tpoint_20090917_015404.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_18/tpoint_20090917_202449.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_23/tpoint_20090922_223445.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_24/tpoint_20090923_204444.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_24/tpoint_20090924_041824.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_25/tpoint_20090924_225725.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_26/tpoint_20090925_212537.txt"},
-    {"+090817","TPoints", "tpoint/m1/2009_09_27/tpoint_20090926_212332.txt"},
-};
+#include "plot.C"
 
 void plot_m1()
 {
-    TGraph g[3];
 
-    MBinning bins(100, 0, 0.2);
+    MDirIter Next;
+    Next.AddDirectory("tpoint/m1", "tpoint*.txt", -1);
 
-    TArrayI n(counts);
-
-    TH1F hx[counts];
-    Int_t num = -1;
-    for (int i=0; i<counts; i++)
-    {
-        if (desc[i].fName[0]!='+')
-        {
-            num++;
-
-            hx[num].SetNameTitle(desc[i].fName, desc[i].fTitle);
-            hx[num].SetDirectory(0);
-            bins.Apply(hx[num]);
-        }
-
-        cout << setw(2) << num << ": " << flush;
-        n[num] = fill(desc[i].fFile, g, &hx[num]);
-        cout << " Mean: " << setw(5) << setprecision(3) << hx[num].GetMean()*3600 << " sec +/- " <<  hx[num].GetRMS()*3600 << endl;
-    }
-
-    n.Set(++num);
-
-    g[0].SetMarkerColor(kGreen);
-    g[1].SetMarkerColor(kMagenta);
-    g[2].SetMarkerColor(kBlack);
-    //g[2].SetLineColor(kBlack);
-    g[0].SetMarkerStyle(kFullDotMedium);
-    g[1].SetMarkerStyle(kFullDotMedium);
-    g[2].SetMarkerStyle(kFullDotLarge);
-
-    // --------- First Canvas ----------
-
-    new TCanvas("Vs Time", "");
-
-    TObject *obj[4];
-
-    for (int i=0; i<3; i++)
-    {
-        g[i].SetFillColor(kWhite);
-        g[i].SetLineColor(kWhite);
-        obj[i] = g[i].Clone();
-        obj[i]->SetBit(kCanDelete);
-        obj[i]->Draw(i==0?"AP":"P");
-    }
-
-    TLegend leg(0.905, 0.86, 0.99, 0.99);
-    leg.AddEntry(obj[0], "  \\Delta\\theta");
-    leg.AddEntry(obj[1], "  \\Delta\\phi");
-    leg.AddEntry(obj[2], "  \\Delta");
-    leg.DrawClone()->SetBit(kCanDelete);
-
-    TLine l;
-    l.SetLineColor(kBlue);
-    for (int i=0; i<n.GetSize(); i++)
-        l.DrawLine(n[i], 0, n[i], 0.2);
-
-    // --------- Second Canvas ----------
-
-    new TCanvas("Distrib", "");
-
-    Double_t max=0;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        if (hx[i].GetEntries()==0)
-        {
-            cout << "Skip #" << i << endl;
-            continue;
-        }
-
-        hx[i].Scale(1./hx[i].GetEntries());
-        max = TMath::Max(max, hx[i].GetMaximum());
-    }
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        hx[i].SetMaximum(max*1.05);
-        if (i<6)
-            hx[i].SetLineColor(kRed+i);
-        else
-            hx[i].SetMarkerStyle(kPlus+i-6);
-
-
-    }
-
-    for (int i=0; i<counts; i++)
-        hx[i].DrawCopy(i==0?"LP":"LPsame");
-
-    Double_t time[] = {
-        MTime(2005,  3, 20).GetAxisTime(),
-        MTime(2005,  4, 29).GetAxisTime(),
-        MTime(2005,  5, 25).GetAxisTime(),
-        MTime(2005,  6,  8).GetAxisTime(),
-        MTime(2005,  8, 15).GetAxisTime(),
-//        MTime(2005,  9, 12).GetAxisTime(),
-        MTime(2005, 11, 10).GetAxisTime(),
-        MTime(2005, 11, 24).GetAxisTime(),
-        MTime(2006,  3, 19).GetAxisTime(),
-        MTime(2006, 10, 17).GetAxisTime(),
-        MTime(2007,  6, 17).GetAxisTime(),
-        MTime(2007,  8,  4).GetAxisTime(),
-        MTime(2007, 10, 18).GetAxisTime(),
-        MTime(2008,  1, 14).GetAxisTime(),
-        MTime(2008,  6, 11).GetAxisTime(),
-        MTime(2008,  6, 18).GetAxisTime(),
-        // Are we missing TPoints between 080618 and 090501??
-        MTime(2009,  5, 1).GetAxisTime(),
-        MTime(2009,  5, 11).GetAxisTime(),
-        MTime(2009,  5, 12).GetAxisTime(),
-        MTime(2009,  5, 13).GetAxisTime(),
-        MTime(2009,  5, 16).GetAxisTime(),
-        MTime(2009,  6, 11).GetAxisTime(),
-        MTime(2009,  7, 23).GetAxisTime(),
-        MTime(2009,  8, 17).GetAxisTime(),
-        MTime(2009, 12, 31).GetAxisTime(),
-    };
-
-    TH1D histres[4];
-
-    MBinning bins;
-    bins.SetEdges(TArrayD(24, time));
-
-    bins.Apply(histres[0]);
-    bins.Apply(histres[1]);
-    bins.Apply(histres[2]);
-    bins.Apply(histres[3]);
-
-    TGraphAsymmErrors result[4];
-    TGraph resultm;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        cout << i+1 << " - Mean:  " << Form("%5.1f +- %5.1f", hx[i].GetMean()*3600, hx[i].GetRMS()*3600);
-        cout << "   (Overflows=" << hx[i].GetBinContent(hx[i].GetNbinsX()+1)*hx[i].GetEntries() << ")   " << (int)hx[i].GetEntries() << endl;
-
-        if (hx[i].GetEntries()<1)
-            continue;
-
-        /*
-         TF1 fg("fg", "gaus", 0, 1);
-         hx[i].Fit(&fg);
-         result2.SetPoint(result.GetN(), result.GetN()+7, hx[i].GetMean());
-         result2.SetPointError(result.GetN()-1, 0, hx[i].GetRMS()/sqrt(hx[i].GetEntries()));
-         result.SetPoint(result.GetN(), result.GetN()+7, fg.GetParameter(1));
-         result.SetPointError(result.GetN()-1, 0, fg.GetParameter(2));
-         */
-
-        //Double_t q[4] = { MMath::GaussProb(0.5), MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
-        Double_t q[4] = { 0.5, MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
-        Double_t rc[4];
-        hx[i].GetQuantiles(4, rc, q);
-
-        for (int j=0; j<4; j++)
-        {
-            histres[j].SetBinContent(i+1, 60*rc[j]);
-
-            result[j].SetPoint(i, time[i], 60*rc[j]);
-            result[j].SetPointError(i, 0, 0, 60*rc[j], 0);
-
-            //result[j].SetPoint(result[j].GetN(), result[j].GetN()+1, 60*rc[j]);
-            //result[j].SetPointError(result[j].GetN()-1, 0, 0, 60*rc[j], 0);
-        }
-
-//        result.SetPoint(result.GetN(), result.GetN()+1, rc[1]);
-//        result2.SetPoint(result2.GetN(), result2.GetN()+1, rc[2]);
-
-        //result.SetPointError(result.GetN()-1, 0.5, 0);//rc[2]-rc[1]);
-        //result2.SetPointError(result.GetN()-1, 0.5, 0);//rc[2]-rc[1]);
-
-//        result.SetPointError(result.GetN()-1, 0, 0, 0/*rc[1]-rc[0]*/, rc[2]-rc[1]);
-//        result2.SetPointError(result.GetN()-1, 0, 0, 0/*rc[1]-rc[0]*/, rc[2]-rc[1]);
-
-//        result2.SetPointError(result.GetN()-1, 0, 0, rc[2], 0);
-
-//        resultm.SetPoint(resultm.GetN(), resultm.GetN()+1, 60*hx[i].GetMean());
-        resultm.SetPoint(resultm.GetN(), (time[i]+time[i+1])/2, 60*hx[i].GetMean());
-
-    }
-
-    new TCanvas;
-
-    gPad->SetBorderMode(0);
-    gPad->SetFrameBorderMode(0);
-    gPad->SetFillColor(kWhite);
-    gPad->SetRightMargin(0.01);
-    gPad->SetTopMargin(0.01);
-    gPad->SetLeftMargin(0.06);
-    gPad->SetGridy();
-
-    //Int_t col[] = { 12, 15, 17, 19 };
-    //Int_t col[] = { 12, 16, 18, 0 };
-    Int_t col[] = { 13, 16, 19, 0 };
-
-    TH1 *h = &histres[2];//result[3].GetHistogram();
-    h->SetXTitle("");
-    h->SetYTitle("Residual / arcmin");
-    h->SetBit(TH1::kNoStats);
-    h->GetXaxis()->CenterTitle();
-    h->GetYaxis()->CenterTitle();
-    h->GetYaxis()->SetTitleOffset(0.75);
-//    h->GetXaxis()->SetTimeFormat("%m/%y %F1995-01-01 00:00:00 GMT");
-//    h->GetXaxis()->SetTimeDisplay(1);
-
-    h->GetXaxis()->SetLabelColor(kWhite);
-
-    TLine line;
-
-    for (int j=2; j>=0; j--)
-    {
-        histres[j].SetMinimum(0);
-        histres[j].SetFillColor(col[j]);//12+2*j);
-
-        histres[j].DrawCopy(j==2?"":"same");
-
-        /*
-        //result[j].SetLineColor(kBlue);
-        //result[j].SetLineWidth(2);
-        //result[j].SetMarkerColor(kBlue);
-        result[j].SetMinimum(0);
-        //result2.SetMarkerStyle(kFullDotMedium);
-        //result[j].SetMarkerStyle(23);
-        result[j].SetFillColor(col[j]);//12+2*j);
-        result[j].DrawClone(j==3 ? "ABX" : "B"); // E3 B
-        */
-    }
-
-
-    resultm.SetMarkerStyle(20);
-    resultm.SetMarkerSize(0.8);
-    resultm.DrawClone("P");
-
-    line.DrawLine(time[0], 0, time[0], histres[2].GetMaximum());
-    for (int i=0; i<bins.GetNumBins()-1; i++)
-        line.DrawLine(time[i+1], 0, time[i+1], histres[2].GetBinContent(i+1));
-
-    TText txt;
-    txt.SetTextSize(0.037);
-//    txt.SetTextAngle(-45);
-    txt.SetTextAlign(23);
-    for (int m=4; m<13; m++)
-    {
-        Double_t monl = MTime(2005, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2005, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/05", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2006, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2006, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/06", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2007, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2007, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/07", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2008, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2008, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/07", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2009, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2009, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/07", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-
-    Double_t y6 = MTime(2006,1,1,0).GetAxisTime();
-    Double_t y7 = MTime(2007,1,1,0).GetAxisTime();
-    Double_t y8 = MTime(2008,1,1,0).GetAxisTime();
-    Double_t y9 = MTime(2009,1,1,0).GetAxisTime();
-    Double_t y0 = MTime(2010,1,1,0).GetAxisTime();
-//    Double_t y0 = MTime(2009,5,1,0).GetAxisTime();
-
-    txt.SetTextSize(0.042);
-    txt.DrawText(y6-(y7-y6)/2, -0.6, "2005");
-    txt.DrawText((y6+y7)/2,    -0.6, "2006");
-    txt.DrawText((y7+y8)/2,    -0.6, "2007");
-    txt.DrawText((y8+y9)/2,    -0.6, "2008");
-    txt.DrawText((y9+y0)/2,    -0.6, "2009");
-
-    line.DrawLine(y6, -0.7, y6, 0.26);
-    line.DrawLine(y7, -0.7, y7, 0.26);
-    line.DrawLine(y8, -0.7, y8, 0.26);
-    line.DrawLine(y9, -0.7, y9, 0.26);
-    line.SetLineStyle(3);
-    line.DrawLine(y6, 0.26, y6, 1.05*histres[2].GetMaximum());
-    line.DrawLine(y7, 0.26, y7, 1.05*histres[2].GetMaximum());
-    line.DrawLine(y8, 0.26, y8, 1.05*histres[2].GetMaximum());
-    line.DrawLine(y9, 0.26, y9, 1.05*histres[2].GetMaximum());
-
-    line.SetLineColor(kBlue);
-    line.SetLineWidth(2);
-    line.SetLineStyle(kSolid);
-    line.DrawLine(time[0], 1*360/16384.*60, time[bins.GetNumBins()], 1*360/16384.*60);
-    line.SetLineStyle(9);
-    line.DrawLine(time[0], 2*360/16384.*60, time[bins.GetNumBins()], 2*360/16384.*60);
-    line.SetLineStyle(7);
-    line.DrawLine(time[0], 3*360/16384.*60, time[bins.GetNumBins()], 3*360/16384.*60);
-
-    /*    result.SetMinimum(-0.06);
-    result.SetMarkerStyle(kFullDotMedium);
-    result.DrawClone("LP");*/
+    plot(Next);
 }
Index: /trunk/Cosy/tpoint/plot_m2.C
===================================================================
--- /trunk/Cosy/tpoint/plot_m2.C	(revision 9952)
+++ /trunk/Cosy/tpoint/plot_m2.C	(revision 9953)
@@ -1,470 +1,26 @@
-#include <iomanip>
+#include "mars/MTime.h"
 
-void DrawMarker(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1)
-    {
-        TView *view = pad->GetView();
-
-        if (!view)
-        {
-            cout << "No View!" << endl;
-            return;
-        }
-
-        TMarker mark0;
-        TMarker mark1;
-        mark0.SetMarkerStyle(kStar);
-        mark1.SetMarkerStyle(kStar);
-        mark1.SetMarkerColor(kRed);
-    
-        r0 /= 90;
-        r1 /= 90;
-        phi0 *= TMath::DegToRad();
-        phi1 *= TMath::DegToRad();
-    
-        Double_t x0[3] = { r0*cos(phi0), r0*sin(phi0), 0};
-        Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0};
-
-        mark0.DrawMarker(x0[0], x0[1]);
-        mark1.DrawMarker(x1[0], x1[1]);
-
-        return;
-        Double_t y0[3], y1[3];
-    
-        view->WCtoNDC(x0, y0);
-        view->WCtoNDC(x1, y1);
-    
-        mark0.DrawMarker(y0[0], y0[1]);
-        mark1.DrawMarker(y1[0], y1[1]);
-    }
-
-int fill(const char *fname, TGraph *g, TH1 *h)
-{
-/*
-    TH2F h2res1("Res2D1", " Dataset positions on the sky ", 32, 0, 360,  10, 0, 90);
-    h2res1.SetBit(TH1::kNoStats);
-    h2res1.DrawCopy("surf1pol");
-    gPad->Modified();
-    gPad->Update();
-    gPad->SetTheta(90);
-    gPad->SetPhi(-90);
-
-    DrawMarker(gPad, 45, 0, 0, 0);
-    gPad->Modified();
-    gPad->Update();
-
-    return;
-
-  */
-    ifstream fin(fname);
-
-    cout << "Reading " << setw(23) << fname << "..." << flush;
-
-    while (1)
-    {
-        TString str;
-        str.ReadLine(fin);
-        if (!fin)
-            break;
-
-        if (str.Contains("#"))
-            continue;
-
-        Float_t alt, az, dalt, daz, mjd;
-        sscanf(str.Data(), "%f %f %*f %*f %*f %*f %f %f %f",
-               &az, &alt, &dalt, &daz, &mjd);
-
-        if (dalt==0/* ||  GetResidual(alt, az, alt+dalt, az+daz)>0.1*/)
-            continue;
-
-        mjd -=  53140.097505;
-
-        Double_t res = MAstro::GetDevAbs(90-(alt-dalt), -dalt, -daz);
-
-        g[0].SetPoint(g[0].GetN(), g[0].GetN(), fabs(dalt));
-        g[1].SetPoint(g[1].GetN(), g[1].GetN(), fabs(daz));
-        g[2].SetPoint(g[2].GetN(), g[2].GetN(), res);
-
-        h->Fill(res);
-    }
-
-    cout << "done (" << setw(3) << (Int_t)h->GetEntries() << "/";
-    cout << setw(4) << g[0].GetN() << ") " << flush;
-
-    return g[0].GetN();
-}
-
-struct Description_t
-{
-    const char *fName;
-    const char *fTitle;
-    const char *fFile;
+Double_t dates[] = {
+    MTime(2009,  3, 30).GetAxisTime(), // Start of M2 observations
+    MTime(2009,  4, 11).GetAxisTime(), // New pointing model
+    MTime(2009,  5, 11).GetAxisTime(), // New pointing model
+    MTime(2009,  6, 11).GetAxisTime(), // Something happened (readon unknown)
+    MTime(2009,  8, 17).GetAxisTime(), // New pointing model
+    MTime(2009,  9,  9).GetAxisTime(), // Something happened (reason unknown)
+    MTime(2010,  2,  1).GetAxisTime(), // New pointing model
+    // MTime(2010,  2,  3).GetAxisTime(), // New LUTs
+    MTime(2010,  2, 26).GetAxisTime(), // New pointing model
+    MTime(2010,  3, 31).GetAxisTime(), // New pointing model
+    MTime(-1).GetAxisTime(),
+    -1
 };
 
-const Int_t counts = 46+15;
-Description_t desc[counts] =
-{
-    {"090401",  "TPoints Residuals 8/2004-2" , "tpoint/m2/first/tpoints_m2_1.txt"},
-    {"+090401",  "TPoints Residuals 9/2004" ,  "tpoint/m2/first/tpoints_m2_2.txt"},
-    {"+090401",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090403_025841.txt"},
-    {"+090401",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090403_214619.txt"},
-    {"+090401",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090404_235955.txt"},
-    {"+090401",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090405_015920.txt"},
-    // New pointing model
-    {"090402",   "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090411_231731.txt"},
-    {"+090402",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090412_232919.txt"},
-    {"+090402",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090414_001746.txt"},
-    {"+090402",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090418_012742.txt"},
-    {"+090402",  "TPoints Residuals 11/2004" , "tpoint/m2/first/tpoint_20090418_024412.txt"},
-    // New pointing model
-    {"090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_12/tpoint_20090512_011933.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_12/tpoint_20090512_013112.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_13/tpoint_20090512_210644.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_13/tpoint_20090513_002758.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_13/tpoint_20090513_025123.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_13/tpoint_20090513_033504.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_05_14/tpoint_20090514_013332.txt"},
-    // Just start of a new observation period
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_01/tpoint_20090531_215139.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_01/tpoint_20090531_222548.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_02/tpoint_20090601_223001.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_03/tpoint_20090602_213508.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_03/tpoint_20090602_230944.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_03/tpoint_20090603_000616.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_03/tpoint_20090603_011935.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_04/tpoint_20090603_215841.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_05/tpoint_20090604_215941.txt"},
-
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_10/tpoint_20090609_232320.txt"},
-    {"+090512",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_11/tpoint_20090611_011148.txt"},
-
-    // Something happened (reason unknown)
-
-    {"090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_11/tpoint_20090611_023623.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_13/tpoint_20090613_033839.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_14/tpoint_20090614_021304.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_06_18/tpoint_20090618_041436.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_12/tpoint_20090712_014259.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_12/tpoint_20090712_024706.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_13/tpoint_20090713_004244.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_13/tpoint_20090713_025925.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_14/tpoint_20090714_022322.txt"},
-    {"+090611",  "TPoints Residuals 11/2004" , "tpoint/m2/2009_07_15/tpoint_20090715_021316.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_02/tpoint_20090801_225305.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_03/tpoint_20090802_224437.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_04/tpoint_20090803_231853.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_11/tpoint_20090810_234604.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_11/tpoint_20090811_020844.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_12/tpoint_20090812_001850.txt"},
-    {"+090611",  "TPoints Residuals 08/2009" , "tpoint/m2/2009_08_13/tpoint_20090813_030805.txt"},
-
-    // ------ 09/08/17 new pointing model -------
-
-    {"090817",  "TPoints" , "tpoint/m2/2009_09_01/tpoint_20090831_233035.txt"},
-    {"+090817",  "TPoints" , "tpoint/m2/2009_09_02/tpoint_20090901_231921.txt"},
-    {"+090817",  "TPoints" , "tpoint/m2/2009_09_08/tpoint_20090907_213405.txt"},
-    {"+090817",  "TPoints" , "tpoint/m2/2009_09_09/tpoint_20090908_225029.txt"},
-    {"+090817",  "TPoints" , "tpoint/m2/2009_09_09/tpoint_20090908_231713.txt"},
-
-    // ------ 09/08/17 What happened? -------
-
-    {"090910",  "TPoints" , "tpoint/m2/2009_09_10/tpoint_20090909_235225.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_10/tpoint_20090910_025048.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_12/tpoint_20090912_014815.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_17/tpoint_20090917_015406.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_18/tpoint_20090917_202447.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_23/tpoint_20090922_223447.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_24/tpoint_20090923_204442.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_25/tpoint_20090925_002702.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_26/tpoint_20090925_212533.txt"},
-    {"+090910",  "TPoints" , "tpoint/m2/2009_09_27/tpoint_20090926_212331.txt"},
-};
+#include "plot.C"
 
 void plot_m2()
 {
-    TGraph g[3];
+    MDirIter Next;
+    Next.AddDirectory("tpoint/m2", "tpoint*.txt", -1);
 
-    MBinning bins(100, 0, 0.2);
-
-    TArrayI n(counts);
-
-    TH1F hx[counts];
-    Int_t num = -1;
-    for (int i=0; i<counts; i++)
-    {
-        if (desc[i].fName[0]!='+')
-        {
-            num++;
-
-            hx[num].SetNameTitle(desc[i].fName, desc[i].fTitle);
-            hx[num].SetDirectory(0);
-            bins.Apply(hx[num]);
-        }
-
-        cout << setw(2) << num << ": " << flush;
-        n[num] = fill(desc[i].fFile, g, &hx[num]);
-        cout << " Mean: " << setw(5) << setprecision(2) << hx[num].GetMean() << " deg +/- " <<  hx[num].GetRMS()<< endl;
-    }
-
-    n.Set(++num);
-
-    g[0].SetMarkerColor(kGreen);
-    g[1].SetMarkerColor(kMagenta);
-    g[2].SetMarkerColor(kBlack);
-    //g[2].SetLineColor(kBlack);
-    g[0].SetMarkerStyle(kFullDotMedium);
-    g[1].SetMarkerStyle(kFullDotMedium);
-    g[2].SetMarkerStyle(kFullDotLarge);
-
-    // --------- First Canvas ----------
-
-    new TCanvas("Vs Time", "");
-
-    TObject *obj[4];
-
-    for (int i=0; i<3; i++)
-    {
-        g[i].SetFillColor(kWhite);
-        g[i].SetLineColor(kWhite);
-        obj[i] = g[i].Clone();
-        obj[i]->SetBit(kCanDelete);
-        obj[i]->Draw(i==0?"AP":"P");
-    }
-
-    TLegend leg(0.905, 0.86, 0.99, 0.99);
-    leg.AddEntry(obj[0], "  \\Delta\\theta");
-    leg.AddEntry(obj[1], "  \\Delta\\phi");
-    leg.AddEntry(obj[2], "  \\Delta");
-    leg.DrawClone()->SetBit(kCanDelete);
-
-    TLine l;
-    l.SetLineColor(kBlue);
-    for (int i=0; i<n.GetSize(); i++)
-        l.DrawLine(n[i], 0, n[i], 0.2);
-
-    // --------- Second Canvas ----------
-
-    new TCanvas("Distrib", "");
-
-    Double_t max=0;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        if (hx[i].GetEntries()==0)
-        {
-            cout << "Skip #" << i << endl;
-            continue;
-        }
-
-        hx[i].Scale(1./hx[i].GetEntries());
-        max = TMath::Max(max, hx[i].GetMaximum());
-    }
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        hx[i].SetMaximum(max*1.05);
-        if (i<6)
-            hx[i].SetLineColor(kRed+i);
-        else
-            hx[i].SetMarkerStyle(kPlus+i-6);
-
-
-    }
-
-    for (int i=0; i<counts; i++)
-        hx[i].DrawCopy(i==0?"LP":"LPsame");
-
-    Double_t time[] = {
-        MTime(2009,  3, 30).GetAxisTime(),
-        MTime(2009,  4, 11).GetAxisTime(),
-        MTime(2009,  5, 11).GetAxisTime(),
-        MTime(2009,  6, 11).GetAxisTime(),
-        MTime(2009,  8, 17).GetAxisTime(),
-        MTime(2009,  9,  9).GetAxisTime(),
-        MTime(2009, 12, 31).GetAxisTime(),
-    };
-
-    TH1D histres[4];
-
-    MBinning bins;
-    bins.SetEdges(TArrayD(7, time));
-
-    bins.Apply(histres[0]);
-    bins.Apply(histres[1]);
-    bins.Apply(histres[2]);
-    bins.Apply(histres[3]);
-
-    TGraphAsymmErrors result[4];
-    TGraph resultm;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        cout << i+1 << " - Mean:  " << Form("%.4f +- %.4f", hx[i].GetMean(), hx[i].GetRMS());
-        cout << "   (Overflows=" << hx[i].GetBinContent(hx[i].GetNbinsX()+1)*hx[i].GetEntries() << ")   " << (int)hx[i].GetEntries() << endl;
-
-        /*
-         TF1 fg("fg", "gaus", 0, 1);
-         hx[i].Fit(&fg);
-         result2.SetPoint(result.GetN(), result.GetN()+7, hx[i].GetMean());
-         result2.SetPointError(result.GetN()-1, 0, hx[i].GetRMS()/sqrt(hx[i].GetEntries()));
-         result.SetPoint(result.GetN(), result.GetN()+7, fg.GetParameter(1));
-         result.SetPointError(result.GetN()-1, 0, fg.GetParameter(2));
-         */
-
-        //Double_t q[4] = { MMath::GaussProb(0.5), MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
-        Double_t q[4] = { 0.5, MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
-        Double_t rc[4];
-        hx[i].GetQuantiles(4, rc, q);
-
-        for (int j=0; j<4; j++)
-        {
-            histres[j].SetBinContent(i+1, 60*rc[j]);
-
-            result[j].SetPoint(i, time[i], 60*rc[j]);
-            result[j].SetPointError(i, 0, 0, 60*rc[j], 0);
-
-            //result[j].SetPoint(result[j].GetN(), result[j].GetN()+1, 60*rc[j]);
-            //result[j].SetPointError(result[j].GetN()-1, 0, 0, 60*rc[j], 0);
-        }
-
-//        result.SetPoint(result.GetN(), result.GetN()+1, rc[1]);
-//        result2.SetPoint(result2.GetN(), result2.GetN()+1, rc[2]);
-
-        //result.SetPointError(result.GetN()-1, 0.5, 0);//rc[2]-rc[1]);
-        //result2.SetPointError(result.GetN()-1, 0.5, 0);//rc[2]-rc[1]);
-
-//        result.SetPointError(result.GetN()-1, 0, 0, 0/*rc[1]-rc[0]*/, rc[2]-rc[1]);
-//        result2.SetPointError(result.GetN()-1, 0, 0, 0/*rc[1]-rc[0]*/, rc[2]-rc[1]);
-
-//        result2.SetPointError(result.GetN()-1, 0, 0, rc[2], 0);
-
-//        resultm.SetPoint(resultm.GetN(), resultm.GetN()+1, 60*hx[i].GetMean());
-        resultm.SetPoint(resultm.GetN(), (time[i]+time[i+1])/2, 60*hx[i].GetMean());
-
-    }
-
-    new TCanvas;
-
-    gPad->SetBorderMode(0);
-    gPad->SetFrameBorderMode(0);
-    gPad->SetFillColor(kWhite);
-    gPad->SetRightMargin(0.01);
-    gPad->SetTopMargin(0.01);
-    gPad->SetLeftMargin(0.06);
-    gPad->SetGridy();
-
-    //Int_t col[] = { 12, 15, 17, 19 };
-    //Int_t col[] = { 12, 16, 18, 0 };
-    Int_t col[] = { 13, 16, 19, 0 };
-
-    TH1 *h = &histres[2];//result[3].GetHistogram();
-    h->SetXTitle("");
-    h->SetYTitle("Residual / arcmin");
-    h->SetBit(TH1::kNoStats);
-    h->GetXaxis()->CenterTitle();
-    h->GetYaxis()->CenterTitle();
-    h->GetYaxis()->SetTitleOffset(0.75);
-//    h->GetXaxis()->SetTimeFormat("%m/%y %F1995-01-01 00:00:00 GMT");
-//    h->GetXaxis()->SetTimeDisplay(1);
-
-    h->GetXaxis()->SetLabelColor(kWhite);
-
-    TLine line;
-
-    for (int j=2; j>=0; j--)
-    {
-        histres[j].SetMinimum(0);
-        histres[j].SetFillColor(col[j]);//12+2*j);
-
-        histres[j].DrawCopy(j==2?"":"same");
-
-        /*
-        //result[j].SetLineColor(kBlue);
-        //result[j].SetLineWidth(2);
-        //result[j].SetMarkerColor(kBlue);
-        result[j].SetMinimum(0);
-        //result2.SetMarkerStyle(kFullDotMedium);
-        //result[j].SetMarkerStyle(23);
-        result[j].SetFillColor(col[j]);//12+2*j);
-        result[j].DrawClone(j==3 ? "ABX" : "B"); // E3 B
-        */
-    }
-
-
-    resultm.SetMarkerStyle(20);
-    resultm.SetMarkerSize(0.8);
-    resultm.DrawClone("P");
-
-    line.DrawLine(time[0], 0, time[0], histres[2].GetMaximum());
-    for (int i=0; i<bins.GetNumBins()-1; i++)
-        line.DrawLine(time[i+1], 0, time[i+1], histres[2].GetBinContent(i+1));
-
-    TText txt;
-    txt.SetTextSize(0.037);
-//    txt.SetTextAngle(-45);
-    txt.SetTextAlign(23);
-    /*
-    for (int m=4; m<13; m++)
-    {
-        Double_t monl = MTime(2005, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2005, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/05", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2006, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2006, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/06", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-    for (int m=1; m<13; m++)
-    {
-        Double_t monl = MTime(2007, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2007, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/07", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }*/
-    for (int m=4; m<13; m++)
-    {
-        Double_t monl = MTime(2009, m,   1,0).GetAxisTime();
-        Double_t mont = MTime(2009, m,   15,0).GetAxisTime();
-//        txt.DrawText(mon, -0.12, Form("%02d/07", m));
-        txt.DrawText(mont, -0.10, Form("%d", m));
-        line.DrawLine(monl, -0.12, monl, 0.12);
-    }
-
-//    Double_t y6 = MTime(2006,1,1,0).GetAxisTime();
-//    Double_t y7 = MTime(2007,1,1,0).GetAxisTime();
-//    Double_t y8 = MTime(2008,1,1,0).GetAxisTime();
-    Double_t y9 = MTime(2009,1,1,0).GetAxisTime();
-    Double_t y0 = MTime(2010,1,1,0).GetAxisTime();
-
-    txt.SetTextSize(0.042);
-//    txt.DrawText(y6-(y7-y6)/2, -0.6, "2005");
-//    txt.DrawText((y6+y7)/2,    -0.6, "2006");
-//    txt.DrawText((y7+y8)/2,    -0.6, "2007");
-    txt.DrawText((y9+y0)/2,    -0.6, "2009");
-
-//    line.DrawLine(y6, -0.7, y6, 0.26);
-//    line.DrawLine(y7, -0.7, y7, 0.26);
-//    line.DrawLine(y8, -0.7, y8, 0.26);
-    line.DrawLine(y9, -0.7, y9, 0.26);
-    line.SetLineStyle(3);
-//    line.DrawLine(y6, 0.26, y6, 1.05*histres[2].GetMaximum());
-//    line.DrawLine(y7, 0.26, y7, 1.05*histres[2].GetMaximum());
-//    line.DrawLine(y8, 0.26, y8, 1.05*histres[2].GetMaximum());
-    line.DrawLine(y9, 0.26, y9, 1.05*histres[2].GetMaximum());
-
-    line.SetLineColor(kBlue);
-    line.SetLineWidth(2);
-    line.SetLineStyle(kSolid);
-    line.DrawLine(time[0], 1*360/16384.*60, time[bins.GetNumBins()], 1*360/16384.*60);
-    line.SetLineStyle(9);
-    line.DrawLine(time[0], 2*360/16384.*60, time[bins.GetNumBins()], 2*360/16384.*60);
-    line.SetLineStyle(7);
-    line.DrawLine(time[0], 3*360/16384.*60, time[bins.GetNumBins()], 3*360/16384.*60);
-
-    /*    result.SetMinimum(-0.06);
-    result.SetMarkerStyle(kFullDotMedium);
-    result.DrawClone("LP");*/
+    plot(Next);
 }
