Index: trunk/MagicSoft/Mars/mpointing/MPointing.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointing.cc	(revision 4871)
+++ trunk/MagicSoft/Mars/mpointing/MPointing.cc	(revision 4966)
@@ -80,4 +80,6 @@
 #include "MTime.h"
 
+ClassImp(AltAz);
+ClassImp(ZdAz);
 ClassImp(MPointing);
 
@@ -602,4 +604,15 @@
 }
 
+TVector3 MPointing::Correct(const TVector3 &v) const
+{
+    // Correct [rad]
+    // zdaz    [rad]
+    AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
+    AltAz c = Correct(p);
+    TVector3 rc;
+    rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
+    return rc;
+}
+
 ZdAz MPointing::CorrectBack(const ZdAz &zdaz) const
 {
@@ -611,4 +624,15 @@
 }
 
+TVector3 MPointing::CorrectBack(const TVector3 &v) const
+{
+    // Correct [rad]
+    // zdaz    [rad]
+    AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
+    AltAz c = CorrectBack(p);
+    TVector3 rc;
+    rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
+    return rc;
+}
+
 void MPointing::SetParameters(const Double_t *par, Int_t n)
 {
Index: trunk/MagicSoft/Mars/mpointing/MPointing.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointing.h	(revision 4871)
+++ trunk/MagicSoft/Mars/mpointing/MPointing.h	(revision 4966)
@@ -4,4 +4,8 @@
 #ifndef ROOT_TArrayD
 #include <TArrayD.h>
+#endif
+
+#ifndef ROOT_TVector3
+#include <TVector3.h>
 #endif
 
@@ -24,4 +28,5 @@
     Double_t Alt() const { return fX; }
     Double_t Az() const  { return fY; }
+    ClassDef(AltAz, 1)
 };
 
@@ -34,4 +39,5 @@
     Double_t Zd() const { return fX; }
     Double_t Az() const { return fY; }
+    ClassDef(ZdAz, 1)
 };
 #endif
@@ -95,12 +101,15 @@
     void Reset();
 
-    ZdAz  Correct(const ZdAz &zdaz) const;
-    AltAz Correct(const AltAz &aaz) const;
-
-    ZdAz  CorrectBack(const ZdAz &zdaz) const;
-    AltAz CorrectBack(const AltAz &aaz) const;
-
-    ZdAz operator()(const ZdAz &zdaz) const { return Correct(zdaz); }
-    AltAz operator()(const AltAz &aaz) const { return Correct(aaz); }
+    ZdAz     Correct(const ZdAz &zdaz) const;
+    AltAz    Correct(const AltAz &aaz) const;
+    TVector3 Correct(const TVector3 &v) const;
+
+    ZdAz     CorrectBack(const ZdAz &zdaz) const;
+    AltAz    CorrectBack(const AltAz &aaz) const;
+    TVector3 CorrectBack(const TVector3 &v) const;
+
+    ZdAz     operator()(const ZdAz &zdaz)  const { return Correct(zdaz); }
+    AltAz    operator()(const AltAz &aaz)  const { return Correct(aaz); }
+    TVector3 operator()(const TVector3 &v) const { return Correct(v); }
 
     ZdAz operator()(const ZdAz &zdaz, void (*fcn)(ZdAz &zdaz, Double_t *par)) const
@@ -122,4 +131,13 @@
     }
 
+    TVector3 operator()(const TVector3 &aaz, void (*fcn)(TVector3 &aaz, Double_t *par)) const
+    {
+        Double_t par[fNumPar];
+        GetParameters(par);
+        TVector3 v = aaz;
+        fcn(v, par);
+        return v;
+    }
+
     AltAz  AddOffsets(const AltAz &aa) const;
     ZdAz   AddOffsets(const ZdAz &zdaz) const
@@ -129,4 +147,12 @@
         return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
     }
+    TVector3 AddOffsets(const TVector3 &v) const
+    {
+        AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
+        AltAz c = AddOffsets(p);
+        TVector3 rc;
+        rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
+        return rc;
+    }
 
     AltAz  SubtractOffsets(const AltAz &aa) const;
@@ -136,4 +162,12 @@
         AltAz c = SubtractOffsets(p);
         return ZdAz(TMath::Pi()/2-c.Alt(), c.Az());
+    }
+    TVector3 SubtractOffsets(const TVector3 &v) const
+    {
+        AltAz p(TMath::Pi()/2-v.Theta(), v.Phi());
+        AltAz c = SubtractOffsets(p);
+        TVector3 rc;
+        rc.SetMagThetaPhi(1, TMath::Pi()/2-c.Alt(), c.Az());
+        return rc;
     }
 
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.cc	(revision 4871)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.cc	(revision 4966)
@@ -39,4 +39,6 @@
 #include "MPointing.h"
 #include "MSrcPosCam.h"
+#include "MAstro.h"
+#include "MAstroCatalog.h" // MVector3
 #include "MAstroSky2Local.h"
 #include "MPointingPos.h"
@@ -57,8 +59,6 @@
     fTitle = title ? title : "";
 
-    fPoint0401 = new MPointing("bending0401.txt");
+    fPoint0401 = new MPointing("bending-fit.txt");
     fPoint0405 = new MPointing("bending0405.txt");
-    fPointOld  = new MPointing("bending-old.txt");
-    fPointNew  = new MPointing("bending0408.txt");
 }
 
@@ -67,6 +67,4 @@
     delete fPoint0401;
     delete fPoint0405;
-    delete fPointOld;
-    delete fPointNew;
 }
 
@@ -97,11 +95,4 @@
         return kFALSE;
     }
-/*
-    fReport = (MReportDrive*)pList->FindObject("MReportDrive");
-    if (!fReport)
-    {
-        *fLog << err << "MReportDrive not found... aborting." << endl;
-        return kFALSE;
-    }
 
     fObservatory = (MObservatory*)pList->FindObject("MObservatory");
@@ -119,11 +110,4 @@
     }
 
-    fTime2 = (MTime*)pList->FindObject("MTimeDrive", "MTime");
-    if (!fTime2)
-    {
-        *fLog << err << "MTimeDrive not found... aborting." << endl;
-        return kFALSE;
-    }
-    */
     fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
     if (!fSrcPos)
@@ -132,48 +116,5 @@
     return kTRUE;
 }
-/*
-TVector2 MSrcPosFromModel::CalcXYinCamera(const ZdAz &pos0, const ZdAz &pos1) const
-{
-    MVector3 p0, p1;
-    p0.SetZdAz(pos0.X(), pos0.Y());
-    p1.SetZdAz(pos1.X(), pos1.Y());
 
-    return CalcXYinCamera(p0, p1);
-}
-
-// --------------------------------------------------------------------------
-//
-// Loc0LocToCam
-//
-// Input :   (theta0, phi0)   direction for the position (0,0) in the camera  
-//           ( theta,  phi)   some other direction
-// 
-// Output :  (X, Y)      position in the camera corresponding to (theta, phi)
-//
-TVector2 MSrcPosFromModel::CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const
-{
-    const Double_t theta0 = pos0.Theta();
-    const Double_t phi0   = pos0.Phi();
-
-    const Double_t theta  = pos.Theta();
-    const Double_t phi    = pos.Phi();
-
-    //--------------------------------------------
-
-    // pos0[3] = TMath::Cos(theta0)
-
-    const Double_t YC0 = TMath::Cos(theta0)*TMath::Tan(theta)*TMath::Cos(phi-phi0) - TMath::Sin(theta0);
-    const Double_t YC1 = TMath::Cos(theta0) + TMath::Sin(theta0)*TMath::Tan(theta);
-    const Double_t YC  = YC0 / YC1;
-
-    //--------------------------------------------
-
-    const Double_t XC0 =  TMath::Cos(theta0) - YC*TMath::Sin(theta0);
-    const Double_t XC  = -TMath::Sin(phi-phi0) * TMath::Tan(theta) * XC0;
-
-    //--------------------------------------------
-    return TVector2(XC, -YC);
-}
-*/
 // --------------------------------------------------------------------------
 //
@@ -182,68 +123,24 @@
 Int_t MSrcPosFromModel::Process()
 {
-    MPointing *conv1 = 0;
-    MPointing *conv2 = 0;
+    MPointing *conv = 0;
 
-    if (!conv1 && fRun->GetRunNumber()<26237)
-    {
-        conv1 = fPoint0401;
-        conv2 = fPointOld;
-    }
-    if (!conv1 && fRun->GetRunNumber()<31684)
-    {
-        conv1 = fPoint0405;
-        conv2 = fPointOld;
-    }
-    /*
-     MVector3 sky;
-     sky.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
-     MVector3 loc = MAstroSky2Local(*fTime2, *fObservatory)*sky;
-     ZdAz za(loc.Theta(), loc.Phi());
-     */
+    if (!conv && fRun->GetRunNumber()<26237)
+        conv = fPoint0401;
+    if (!conv && fRun->GetRunNumber()<31684)
+        conv = fPoint0405;
 
-    // Get current pointing position from Drive system
-    ZdAz za(fPointPos->GetZd(), fPointPos->GetAz());
-    za *= TMath::DegToRad();
+    MVector3 sky;
+    sky.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
 
-    // Get corresponding Shaftencoder positions for 'Used-Mode'
-    const ZdAz za2 = conv1->Correct(za);  // [deg] --> [se]
-    // Get corresponding Shaftencoder positions for 'Correct-Mode'
-    const ZdAz za1 = conv2->Correct(za);  // [deg] --> [se]
+    // Get current star position (off center)
+    MVector3 vl2 = MAstroSky2Local(*fTime, *fObservatory)*sky;
+    // Get corrected position camera center)
+    TVector3 vl1 = conv->Correct(vl2);
 
-    // The difference of the shaftencoder positions for both model
-    // correspond in a first order approximation to the misspointing
-    TVector2 v0 = TVector2(za2.Y()-za1.Y(), za2.X()-za1.X());
-
-    // Convert misspointing to millimeters
-    v0 *= TMath::RadToDeg()/fGeom->GetConvMm2Deg();
+    // Calculate x,y of za2
+    TVector2 d = MAstro::GetDistOnPlain(vl1, vl2, fGeom->GetCameraDist()*1000);
 
     // Set Source position
-    fSrcPos->SetXY(v0);
-
-    /*
-    TVector2 v0 = CalcXYinCamera(za1, za0)*fGeom->GetCameraDist()*(-1000);
-    TVector2 v1 = CalcXYinCamera(za0, za1)*fGeom->GetCameraDist()*(+1000);
-
-    fSrcPos->SetXY(TVector2(0,0)); // v1
-
-    za0 *= TMath::RadToDeg();
-    za1 *= TMath::RadToDeg();
-
-    *fLog << warn << endl;
-    *fLog << "-1->  " << za0.X() << " " << za0.Y() << "   " << v0.X() << " " << v0.Y() << "   " << v0.X()*fGeom->GetConvMm2Deg() << " " << v0.Y()*fGeom->GetConvMm2Deg() << endl;
-    *fLog << "-2->  " << za1.X() << " " << za1.Y() << "   " << v1.X() << " " << v1.Y() << "   " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
-
-    Double_t rho = fPointPos->RotationAngle(*fObservatory, *fTime2);
-    *fLog << "-3->  " << rho*TMath::RadToDeg() << endl;
-
-    v1=v1.Rotate(-rho);
-    *fLog << "-4->  " << "       " << " " << "        " << "   " << v1.X() << " " << v1.Y() << "   " << v1.X()*fGeom->GetConvMm2Deg() << " " << v1.Y()*fGeom->GetConvMm2Deg() << endl;
-
-    */
-    /*
-     *fLog << dbg << endl;
-     *fLog << "Time: " << setprecision(12) << fTime2->GetMjd() << " " << *fTime2 << endl;
-     *fLog << setprecision(6);
-     */
+    fSrcPos->SetXY(d);
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.h	(revision 4871)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosFromModel.h	(revision 4966)
@@ -10,5 +10,4 @@
 #endif
 
-//class MVector3;
 class MPointingPos;
 class MSrcPosCam;
@@ -16,8 +15,6 @@
 class MPointing;
 class MRawRunHeader;
-//class MTime;
-//class MObservatory;
-//class MReportDrive;
-//class ZdAz;
+class MTime;
+class MObservatory;
 
 class MSrcPosFromModel : public MTask
@@ -28,14 +25,9 @@
     MGeomCam      *fGeom;       //! Camera geometry
     MRawRunHeader *fRun;        //! Run Header storing the run-number
-    //MTime         *fTime;
-    //MTime         *fTime2;
-    //MReportDrive  *fReport;
-    //MObservatory  *fObservatory;
+    MTime         *fTime;
+    MObservatory  *fObservatory;
 
     MPointing    *fPoint0401;   //! Pointing Model used since 1/2004
     MPointing    *fPoint0405;   //! Pointing Model used since 5/2004
-
-    MPointing    *fPointOld;    //! Pointing Model valid until 8/2004
-    MPointing    *fPointNew;    //! Pointing Model valid since 8/2004
 
     Int_t PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/mpointing/PointingLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/PointingLinkDef.h	(revision 4871)
+++ trunk/MagicSoft/Mars/mpointing/PointingLinkDef.h	(revision 4966)
@@ -14,3 +14,6 @@
 #pragma link C++ class MSrcPosFromModel+;
 
+#pragma link C++ class AltAz+;
+#pragma link C++ class ZdAz+;
+
 #endif
