Index: trunk/MagicSoft/Mars/msim/MSimMMCS.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9359)
+++ trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9362)
@@ -174,6 +174,14 @@
     // Convert from corsika frame to telescope frame, taking
     // the magnetic field into account: tel = corsika+offset
-    fMcEvt->SetTheta(fEvtHeader->GetZd());
-    fMcEvt->SetPhi(fEvtHeader->GetAz()+fRunHeader->GetMagneticFieldAz());
+    if (fRunHeader->HasViewCone())
+    {
+        fMcEvt->SetTheta(fPointingTel->GetZdRad());
+        fMcEvt->SetPhi(fPointingTel->GetAzRad());
+    }
+    else
+    {
+        fMcEvt->SetTheta(fEvtHeader->GetZd());
+        fMcEvt->SetPhi(fEvtHeader->GetAz()+fRunHeader->GetMagneticFieldAz());
+    }
 
     fMcEvt->SetEvtNumber(fEvtHeader->GetEvtNumber());
Index: trunk/MagicSoft/Mars/msim/MSimPointingPos.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimPointingPos.cc	(revision 9359)
+++ trunk/MagicSoft/Mars/msim/MSimPointingPos.cc	(revision 9362)
@@ -25,5 +25,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-//  MSimPointingPos
+// MSimPointingPos
+//
 //
 // This task is meant to simulate the pointing position (mirror orientation).
@@ -31,7 +32,23 @@
 // on the user request (e.g. Wobble mode).
 //
-// WARNING: Currently the telescope orientation is just fixed to the
-//          direction in the run-header (if a view cone was given) or
-//          the direction in the evt-header (if no view cone given)
+//
+// If fOffTragetDistance==0 the telescope is oriented depending on the
+// view cone option. If a view cone was given the orientation is fixed to
+// the main direction around the view cone was produced. If no view
+// cone was given the telescope is oriented parallel to the shower axis.
+//
+// If no view cone option was given and off-target observations are switched
+// on by setting fOffTargetDistance!=0 the poitnting position is calculated:
+//
+//  1) fOffTargetDistance < 0:
+//     The pointing position is randomly distributed in a disk of radius
+//     -fOffTragetDistance. fOffTargetDistance is silently ignored.
+//
+//  2) fOffTargetDistance > 0:
+//     The pointing position is set to a position in the given distance
+//     away from the shower axis. If fOffTargetPhi>=0 it is fixed at
+//     this phi value. For phi<0 it is randomly distributed at distances
+//     fOffTargetDistance. (phi==0 is the direction of positive theta)
+//
 //
 //  Input Containers:
@@ -41,5 +58,4 @@
 //  Output Containers:
 //   MPointingPos
-//   PointingCorsika [MPointingPos]
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -68,6 +84,6 @@
 //
 MSimPointingPos::MSimPointingPos(const char* name, const char *title)
-    : fRunHeader(0), fEvtHeader(0), fPointingCorsika(0), fPointingLocal(0),
-    fOffTargetDistance(-1), fOffTargetPhi(-1)
+    : fRunHeader(0), fEvtHeader(0), fPointing(0),
+    fOffTargetDistance(0), fOffTargetPhi(-1)
 
 {
@@ -83,10 +99,6 @@
 Int_t MSimPointingPos::PreProcess(MParList *pList)
 {
-//    fPointingCorsika = (MPointingPos*)pList->FindCreateObj("MPointingPos", "PointingCorsika");
-//    if (!fPointingCorsika)
-//        return kFALSE;
-
-    fPointingLocal = (MPointingPos*)pList->FindCreateObj("MPointingPos");
-    if (!fPointingLocal)
+    fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
+    if (!fPointing)
         return kFALSE;
 
@@ -105,13 +117,11 @@
     }
 
-    // FIXED offset
-    // Diffuse?  ( FOV of camera folded with mirror diameter as Corsika input? )
-    // Hour angle!
-    // Angle to magnetic field!
-
-    if (IsOffTargetObservation())
-    {
-        *fLog << inf;
-        *fLog << "Off target observations switched on with" << endl;
+    if (!IsOffTargetObservation())
+        return kTRUE;
+
+    *fLog << inf;
+    *fLog << "Off target observations switched on with" << endl;
+    if (fOffTargetDistance>0)
+    {
         *fLog <<"   a pointing distance of " << GetOffTargetDistance() << "deg ";
         if (fOffTargetPhi<0)
@@ -120,15 +130,35 @@
             *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
     }
+    else
+        *fLog << "   a homogenous distribution up to a distance of " << -GetOffTargetDistance() << "deg " << endl;
 
     return kTRUE;
 }
 
-/*
 Bool_t MSimPointingPos::ReInit(MParList *pList)
 {
+    if (fRunHeader->HasViewCone() && IsOffTargetObservation())
+    {
+        *fLog << warn;
+        *fLog << "WARNING - Combining the view cone option with off-target observations doesn't make sense." << endl;
+        *fLog << "          Option for off-target observations will be ignored." << endl;
+    }
     // FIXME: Check also the enlightened region on the ground!
     return kTRUE;
 }
-*/
+
+void MSimPointingPos::GetDelta(Double_t &dtheta, Double_t &dphi) const
+{
+    if (fOffTargetDistance>0)
+    {
+        dtheta = fOffTargetDistance;
+        dphi   = fOffTargetPhi>0 ? fOffTargetPhi : gRandom->Uniform(TMath::TwoPi());
+    }
+    else
+    {
+        dtheta = TMath::Sqrt(gRandom->Uniform(fOffTargetDistance));
+        dphi   = gRandom->Uniform(TMath::TwoPi());
+    }
+}
 
 // --------------------------------------------------------------------------
@@ -136,35 +166,36 @@
 Int_t MSimPointingPos::Process()
 {
-
     // If a view cone is given use the fixed telescope orientation
-    const Bool_t fixed = fRunHeader->HasViewCone();
+    const Bool_t viewcone = fRunHeader->HasViewCone();
 
     // Local sky coordinates (direction of telescope axis)
-    /*const*/ Double_t zd = fixed ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg();  // x==north
-    /*const*/ Double_t az = fixed ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg();  // y==west
-
-    if (!fixed && IsOffTargetObservation())
-    {
+    Double_t zd = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg();  // x==north
+    Double_t az = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg();  // y==west
+
+    if (!viewcone)
+    {
+        Double_t dtheta, dphi;
+        GetDelta(dtheta, dphi);
+
         const Double_t theta = zd*TMath::DegToRad();
         const Double_t phi   = az*TMath::DegToRad();
 
-        /*const*/ TVector3 source;
-        source.SetMagThetaPhi(1, theta, phi);
-
-        /*const*/ TVector3 point;
-        point.SetMagThetaPhi(1, theta+fOffTargetDistance, phi);
-
-        const Double_t delta = fOffTargetPhi>0 ? fOffTargetPhi :
-            gRandom->Uniform(TMath::TwoPi());
-
-        point.Rotate(delta, source);
-
-        zd = point.Theta()*TMath::RadToDeg();
-        az = point.Phi()*TMath::RadToDeg();
-    }
+        TVector3 src, pnt;
+        src.SetMagThetaPhi(1, theta,        phi);
+        pnt.SetMagThetaPhi(1, theta+dtheta, phi);
+
+        pnt.Rotate(dphi, src);
+
+        zd = pnt.Theta()*TMath::RadToDeg();
+        az = pnt.Phi()  *TMath::RadToDeg();
+    }
+
+    // Transform the corsika coordinate system (north is magnetic north)
+    // into the telescopes local coordinate system. Note, that all vectors
+    // are already correctly oriented.
+    az += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
 
     // Setup the pointing position
-//    fPointingCorsika->SetLocalPosition(zd, az/*+fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg()*/);
-    fPointingLocal->SetLocalPosition(zd, az+fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg());
+    fPointing->SetLocalPosition(zd, az);
 
     // Calculate incident angle between magnetic field direction
Index: trunk/MagicSoft/Mars/msim/MSimPointingPos.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimPointingPos.h	(revision 9359)
+++ trunk/MagicSoft/Mars/msim/MSimPointingPos.h	(revision 9362)
@@ -14,11 +14,13 @@
 {
 private:
-    MCorsikaRunHeader *fRunHeader;         //! Header storing event information
-    MCorsikaEvtHeader *fEvtHeader;         //! Header storing event information
-    MPointingPos      *fPointingCorsika;   //! Output storing telescope poiting position in corsika coordinate system (modulo magnetig field declination)
-    MPointingPos      *fPointingLocal;     //! Output storing telescope poiting position in local (telescope) coordinate system
+    MCorsikaRunHeader *fRunHeader;  //! Header storing event information
+    MCorsikaEvtHeader *fEvtHeader;  //! Header storing event information
+    MPointingPos      *fPointing;   //! Output storing telescope poiting position in local (telescope) coordinate system
 
-    Double_t fOffTargetDistance;  // [rad] Distance of the observed off-target position from the source
-    Double_t fOffTargetPhi;       // [rad] Rotation angle of the off-target position (phi==0 means south, phi=90 west) [0;2pi], phi<0 means random
+    Double_t fOffTargetDistance;    // [rad] Distance of the observed off-target position from the source
+    Double_t fOffTargetPhi;         // [rad] Rotation angle of the off-target position (phi==0 means south, phi=90 west) [0;2pi], phi<0 means random
+
+    // MSimPointingPos
+    void GetDelta(Double_t &dtheta, Double_t &dphi) const;
 
     // MParContainer
@@ -27,5 +29,5 @@
     // MTask
     Int_t  PreProcess(MParList *pList);
-    //Bool_t ReInit(MParList *pList);
+    Bool_t ReInit(MParList *pList);
     Int_t  Process();
 
@@ -34,13 +36,13 @@
 
     // Getter
-    Double_t GetOffTargetDistance() const { return fOffTargetDistance*TMath::RadToDeg(); }
+    Double_t GetOffTargetDistance() const { return fOffTargetDistance==0 ? 0 : fOffTargetDistance*TMath::RadToDeg(); }
     Double_t GetOffTargetPhi() const { return fOffTargetPhi*TMath::RadToDeg(); }
 
     // Setter
-    void SetOffTargetDistance(Double_t d=-1) { fOffTargetDistance = d*TMath::DegToRad(); }
-    void SetOffTargetPhi(Double_t p=-1) { fOffTargetPhi = p*TMath::DegToRad(); }
+    void SetOffTargetDistance(Double_t d=0) { fOffTargetDistance = d==0 ? 0 : d*TMath::DegToRad(); }
+    void SetOffTargetPhi(Double_t p=0) { fOffTargetPhi = p*TMath::DegToRad(); }
 
     // MSimPointingPos
-    Bool_t IsOffTargetObservation() const { return fOffTargetDistance>0; }
+    Bool_t IsOffTargetObservation() const { return fOffTargetDistance!=0; }
 
     // TObject
