Index: trunk/MagicSoft/Cosy/tpoint/tpointfit.C
===================================================================
--- trunk/MagicSoft/Cosy/tpoint/tpointfit.C	(revision 1811)
+++ trunk/MagicSoft/Cosy/tpoint/tpointfit.C	(revision 1819)
@@ -27,7 +27,4 @@
     friend ifstream &operator>>(ifstream &fin, Set &set);
 private:
-    Double_t fOrigStarAz;
-    Double_t fOrigStarEl;
-
     Double_t fStarAz;
     Double_t fStarEl;
@@ -47,15 +44,14 @@
     Double_t GetResidual() const
     {
-        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(2*fOrigStarEl+del)*sin2;
-
-        Double_t  dist = acos(d);
-
-        return dist * 180 / TMath::Pi();
+         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 * 180 / TMath::Pi();
     }
 
@@ -112,7 +108,4 @@
     set.fStarEl = v[1]*TMath::Pi()/180;
 
-    set.fOrigStarAz = v[0]*TMath::Pi()/180;
-    set.fOrigStarEl = v[1]*TMath::Pi()/180;
-
     set.fRawAz  = v[2]*TMath::Pi()/180;
     set.fRawEl  = v[3]*TMath::Pi()/180;
@@ -284,8 +277,10 @@
         phi0 += scale*d;
         phi1 -= scale*d;
-    }
-
-    DrawPolLine(pad, r0, phi0, r1, phi1);
-    DrawMarker(pad,  r0, phi0, r1, phi1);
+
+        DrawPolLine(pad, r0, phi0, r1, phi1);
+        DrawMarker(pad,  r0, phi0, r1, phi1);
+    }
+    else
+        DrawMarker(pad,  r1, phi1, 0 ,0);
 }
 
@@ -296,6 +291,6 @@
     gCoordinates.SetOwner();
 
-    TH1F hres1("Res1", "  Residuals before correction     ", 10, 0, 180);
-    TH1F hres2("Res2", "  Residuals after correction     ",  10, 0,   1);
+    TH1F hres1("Res1", "  Residuals before correction     ", 10, 0,   4);
+    TH1F hres2("Res2", "  Residuals after correction     ",  40, 0,   4);
 
     hres1.SetXTitle("\\Delta [\\circ]");
@@ -316,5 +311,5 @@
     gzd.SetTitle(" \\Delta Zd vs. Zd ");
 
-    ifstream fin("tpoint/tpoint3.txt");
+    ifstream fin("/home/tbretz/pc4/results/tpoint3.txt");
 
     while (fin && fin.get()!='\n');
@@ -395,4 +390,13 @@
 
     //
+    // Correct for Offsets only
+    //
+    double par[16];
+    bending.GetParameters(par);
+    for (int i=2; i<16; i++) par[i]=0;
+    MBending b2;
+    b2.SetParameters(par);
+
+    //
     // Calculate correction and residuals
     //
@@ -403,5 +407,12 @@
         ZdAz za = set0.GetStarZdAz()*kRad2Deg;
 
-        hres1.Fill(set0.GetResidual());
+        //
+        // Correct for offsets only
+        //
+        Set set1(set0);
+        set1.Adjust(b2);
+
+        hres1.Fill(set1.GetResidual());
+
         set0.Adjust(bending);
         hres2.Fill(set0.GetResidual());
@@ -412,8 +423,8 @@
 
         static int j=0;
-        gdzd.SetPoint(j, za.Az()/*   set0.GetStarAz()*/, set0.GetDZd());
-        gaz.SetPoint( j, za.Az()/*   set0.GetStarAz()*/, dz);
-        gdaz.SetPoint(j, za.Zd()/*90-set0.GetStarEl()*/, dz);
-        gzd.SetPoint( j, za.Zd()/*90-set0.GetStarEl()*/, set0.GetDZd());
+        gdzd.SetPoint(j, za.Az(), set0.GetDZd());
+        gaz.SetPoint( j, za.Az(), dz);
+        gdaz.SetPoint(j, za.Zd(), dz);
+        gzd.SetPoint( j, za.Zd(), set0.GetDZd());
         j++;
     }
@@ -463,5 +474,7 @@
     cout << "Spead after:  " << hres2.GetMean() << "deg  +-  " << hres2.GetRMS() << "deg" << endl;
     cout << "Spead before: " << (int)(hres1.GetMean()*60+.5) << "'  +-  " << (int)(hres1.GetRMS()*60+.5) << "'" << endl;
+    cout << "Spead before: " << (int)(hres1.GetMean()*60*60/23.4+.5) << "pix  +-  " << (int)(hres1.GetRMS()*60*60/23.4+.5) << "pix" << endl;
     cout << "Spead after:  " << (int)(hres2.GetMean()*60+.5) << "'  +-  " << (int)(hres2.GetRMS()*60+.5) << "'" << endl;
+    cout << "Spead after:  " << (int)(hres2.GetMean()*60*60/23.4+.5) << "pix  +-  " << (int)(hres2.GetRMS()*60*60/23.4+.5) << "pix" << endl;
     cout << "Spead after:  " << (int)(hres2.GetMean()*16384/360+.5) << "SE  +-  " << (int)(hres2.GetRMS()*16384/360+.5) << "SE" << endl;
     cout << endl;
@@ -505,5 +518,5 @@
     gPad->Update();
     for (int i=0; i<gCoordinates.GetSize(); i++)
-        DrawSet(gPad, *(Set*)list.At(i), 10./hres1.GetMean());
+        DrawSet(gPad, *(Set*)list.At(i));//, 10./hres1.GetMean());
 
     c1->cd(3);
