Index: trunk/MagicSoft/Cosy/tpoint/plot.C
===================================================================
--- trunk/MagicSoft/Cosy/tpoint/plot.C	(revision 7104)
+++ trunk/MagicSoft/Cosy/tpoint/plot.C	(revision 7105)
@@ -1,2 +1,4 @@
+#include <iomanip>
+
 Double_t GetResidual(Double_t fRawEl,  Double_t fRawAz,
                      Double_t fStarEl, Double_t fStarAz)
@@ -75,4 +77,6 @@
     ifstream fin(fname);
 
+    cout << "Reading from " << fname << "..." << flush;
+
     while (1)
     {
@@ -105,36 +109,55 @@
     }
 
+    cout << "done (" << g[0].GetN() << ")" << endl;
+
     return g[0].GetN();
 }
 
+struct Description_t
+{
+    const char *fName;
+    const char *fTitle;
+    const char *fFile;
+};
+
+const Int_t counts = 12-4;
+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/2004-1" , "tpoint/tpoint0505-1.txt"},
+    // Mirror alignment has been fixed
+    {"05052", "TPoints Residuals 5/2004-2" , "tpoint/tpoint0505-2.txt"}
+};
+
 void plot()
 {
     TGraph g[3];
 
-    TH1F h0("0404", "TPoints Residuals 4/2004",  35, 0, 0.2);
-    TH1F h1("0405", "TPoints Residuals 5/2004",  35, 0, 0.2);
-    TH1F h2("0408", "TPoints Residuals 8/2004",  35, 0, 0.2);
-    TH1F h3("0409", "TPoints Residuals 9/2004",  35, 0, 0.2);
-    TH1F h4("0410", "TPoints Residuals 10/2004", 35, 0, 0.2);
-    TH1F h5("0411", "TPoints Residuals 11/2004", 35, 0, 0.2);
-    TH1F h6("0412", "TPoints Residuals 12/2004", 35, 0, 0.2);
-    TH1F h7("0503", "TPoints Residuals 3/2005",  35, 0, 0.2);
-    TH1F h8("0504", "TPoints Residuals 4/2005",  35, 0, 0.2);
-
-    TH1 *h[9] = { &h0, &h1, &h2, &h3, &h4, &h5, &h6, &h7, &h8 };
-
-    TArrayI n(9);
-    n[0] = fill("tpoint0404.txt", g, &h0);
-    n[1] = fill("tpoint0405.txt", g, &h1);
-    n[2] = fill("tpoint0408.txt", g, &h2);
-    n[3] = fill("tpoint0409.txt", g, &h3);
-    n[4] = fill("tpoint0410.txt", g, &h4);
-    n[5] = fill("tpoint0411.txt", g, &h5);
-    n[6] = fill("tpoint0412.txt", g, &h6);
-    n[7] = fill("tpoint0503.txt", g, &h7);
-    n[8] = fill("tpoint0504.txt", g, &h8);
-
-//    for (int i=0; i<n.GetSize(); i++)
-//        cout << "Overflows: " << Form("%4.0f", h[i]->GetBinContent(h[i]->GetNbinsX()+1)*h[i]->GetEntries()/h[i]->GetEntries()) << "/" << Form("%4.0f", h[i]->GetEntries()) << endl;
+    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]);
+    }
 
     g[0].SetMarkerColor(kGreen);
@@ -170,5 +193,5 @@
     l.SetLineColor(kBlue);
     for (int i=0; i<n.GetSize(); i++)
-        l.DrawLine(n[i], gPad->GetUymin(), n[i], gPad->GetUymax());
+        l.DrawLine(n[i], 0, n[i], 0.2);
 
     // --------- Second Canvas ----------
@@ -176,27 +199,29 @@
     new TCanvas("Distrib", "");
 
-    Double_t max = 0;
-    for (int i=0; i<n.GetSize(); i++)
-    {
-        h[i]->Scale(1./h[i]->GetEntries());
-        max = TMath::Max(max, h[i]->GetMaximum());
-    }
-    for (int i=0; i<n.GetSize(); i++)
-        h[i]->SetMaximum(max*1.05);
-
-    h0.SetLineColor(kYellow);
-    h1.SetLineColor(kGreen);
-    h2.SetLineColor(kBlue);
-    //h3.SetLineColor(kYellow);
-
-    h7.DrawCopy();
-    h0.DrawCopy("same");
-    h1.DrawCopy("same");
-    h2.DrawCopy("same");
-    h3.DrawCopy("same");
-    h4.DrawCopy("same");
-    h5.DrawCopy("same");
-    h6.DrawCopy("same");
-    h7.DrawCopy("same");
+    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;
@@ -204,6 +229,6 @@
     for (int i=0; i<n.GetSize(); i++)
     {
-        cout << "Mean:  " << Form("%.3f +- %.3f", h[i]->GetMean(), h[i]->GetRMS());
-        cout << "   (Overflows=" << h[i]->GetBinContent(h[i]->GetNbinsX()+1)*h[i]->GetEntries() << ")" << endl;
+        cout << "Mean:  " << Form("%.3f +- %.3f", hx[i].GetMean(), hx[i].GetRMS());
+        cout << "   (Overflows=" << hx[i].GetBinContent(hx[i].GetNbinsX()+1)*hx[i].GetEntries() << ")" << endl;
     }
 }
