Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9335)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9336)
@@ -18,4 +18,70 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2009/02/15 Thomas Bretz
+
+   * mjobs/MJCalibrateSignal.cc:
+     - updated the rule to allow for file names without the leading date
+
+   * mjobs/MJSpectrum.[h,cc]:
+     - set the kMustCleanup bit for sanity
+     - replaced a lot of Form by MString::Format
+     - moved the getting of the right Alpha-histogram to GetHAlpha
+     - the tlist2 doesn't neet to replace anything because all previous
+       tasklists added to the list have been removed again
+     - "DataType" already in parlist? Don't add a second one
+     - replaced some gLog by fLog
+     - make sure that the "Done." message is printed even in case
+       no output is written at the end
+
+   * ceres.rc:
+     - added some more info
+
+   * datacenter/scripts/runcorsika:
+     - added magnetic field Azimuth direction (ARRANG), currently
+       at ~ -7deg at La Palma
+
+   * mbase/MLog.cc:
+     - finallyadded a really stupid hack/workaround to suppress these
+       annoying errors in case of a log-scale set too early
+
+   * mbase/MTask.[h,cc]:
+     - Replaced OverwritesProcess by Overwrites
+
+   * mcorsika/MCorsikaEvtHeader.cc:
+     - fixed particle momentum coordinate system
+
+   * mcorsika/MCorsikaRunHeader.[h,cc]:
+     - added magnetic field values
+     - improved output
+
+   * mjobs/MJSimulation.cc:
+     - updated height scale
+     - use MPhotonStatistics.fLength
+     - plot median dev of photon arrival times
+
+   * mmc/MMcRunHeader.hxx:
+     - added a getter IsCeres
+     - added a setter for the Corsika Version
+
+   * mpedestal/MMcPedestalCopy.cc:
+     - use the new IsCeres
+
+   * msim/MSimMMCS.[h,cc]:
+     - use the telescope pointing in telescope coordinates for MMcEvt
+     - correct the shower direction by the magnetic field azimuth
+     - set corsika program version
+
+   * msim/MSimPointingPos.[h,cc]:
+     - splitted the output into coordinated in the corsika frame
+       (module the magnetic field) and the poiting direction in
+       telescope coordinates
+     - added possibility to "observe" in off-target mode
+
+   * msimreflector/MSimReflector.cc:
+     - use new pointing direction in the corsika frame
+
+
+
+
  2009/02/13 Thomas Bretz
 
@@ -66,4 +132,7 @@
      - added reading of a default psf from the input file
 
+   * mjobs/MSequence.cc:
+     - fixed a bug in GetArrays which could cause seg-faults
+     - added a sanity check
 
 
Index: trunk/MagicSoft/Mars/ceres.rc
===================================================================
--- trunk/MagicSoft/Mars/ceres.rc	(revision 9335)
+++ trunk/MagicSoft/Mars/ceres.rc	(revision 9336)
@@ -60,5 +60,5 @@
 
 # -------------------------------------------------------------------------
-# Ceres specific setup
+# Ceres general setup
 # -------------------------------------------------------------------------
 
@@ -68,4 +68,16 @@
 # Force the use of the "hardware" trigger for calibration data
 #ForceTrigger: Yes
+
+
+# -------------------------------------------------------------------------
+# Here you can control the poiting of the telescope.
+# To switch on off-target observations set a value for the distance >0.
+# Whether they are randomly disributed (<0) or at a fixed phi can also 
+# be decided. Note, that this is options are ignored in the case
+# a view-cone was used. (All valued given in degree)
+# -------------------------------------------------------------------------
+
+#MSimPointingPos.OffTargetDistance: 0.4
+#MSimPointingPos.OffTargetPhi: -1
 
 
@@ -183,2 +195,3 @@
 
 #MSimReadout.fConversionFactor: 1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runcorsika
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9335)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9336)
@@ -65,4 +65,7 @@
    # the detector, BZ is the vertical component (muT) downwards)
    echo "MAGNET 30.3 24.1"
+   # Rotation angle between array x-direction and magnetic north direction
+   # positive if array x-direction points to the west
+   echo "ARRANG -7.0"
    # Atmosphere
    echo "ATMOSPHERE 11 T"
Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 9336)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MLog.cc,v 1.62 2009-02-07 20:40:07 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MLog.cc,v 1.63 2009-02-15 13:24:59 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -814,5 +814,5 @@
         gLog << ": " << msg << std::endl;
     else
-        if (!location || strlen(location) == 0)
+        if (location==0 || location[0]==0)
             gLog << ": " << msg << std::endl;
         else
@@ -830,4 +830,9 @@
     if (ErrorHandlerIgnore(level))
         return;
+
+    // This is a really stupid hack/workaround to suppress these
+    // annoying errors in case of a log-scale set too early
+    if (level==kError && !strcmp(location, "THistPainter::PaintInit"))
+        level=kInfo;
 
     gLog << std::flush;
Index: trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 9336)
@@ -452,5 +452,5 @@
 void MTask::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const
 {
-    if (!OverwritesProcess() && IsA()!=MTask::Class())
+    if (!Overwrites("Process") && IsA()!=MTask::Class())
         return;
 
@@ -511,5 +511,5 @@
 // leave out the argument.
 //
-Bool_t MTask::OverwritesProcess(TClass *cls) const
+Bool_t MTask::Overwrites(const char *name, TClass *cls) const
 {
     if (!cls)
@@ -525,5 +525,5 @@
     // Check whether the class cls overwrites Process
     //
-    if (cls->GetMethodAny("Process"))
+    if (cls->GetMethodAny(name))
         return kTRUE;
 
@@ -535,5 +535,5 @@
     while ((base=(TBaseClass*)NextBase()))
     {
-        if (OverwritesProcess(base->GetClassPointer()))
+        if (Overwrites(name, base->GetClassPointer()))
             return kTRUE;
     }
Index: trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.h	(revision 9335)
+++ trunk/MagicSoft/Mars/mbase/MTask.h	(revision 9336)
@@ -79,5 +79,5 @@
 
     const TList *GetListOfBranches() const { return fListOfBranches; }
-    Bool_t OverwritesProcess(TClass *cls=NULL) const;
+    Bool_t Overwrites(const char *name, TClass *cls=NULL) const;
 
     // Filter functions
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9336)
@@ -121,6 +121,6 @@
     // Pointing along particle direction
     // (x=east, y=north, z=upwards)
-    fMomentumX = -f[7];
-    fMomentumY =  f[6];
+    fMomentumX =  f[7];
+    fMomentumY = -f[6];
     fMomentumZ = -f[8];
 
@@ -136,9 +136,6 @@
     }
 
-    //fX = f[97];
-    //fY = f[117];
-
-    fX =  f[117];
-    fY = -f[97];
+    fX =  f[117];   //fX = f[97];
+    fY = -f[97];    //fY = f[117];
 
     fin.seekg(1088-273*4, ios::cur);
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9336)
@@ -34,4 +34,7 @@
 //  + UInt_t fParticleID
 //  + Float_t fImpactMax
+//  + Float_t fMagneticFieldX
+//  + Float_t fMagneticFieldZ
+//  + Float_t fMagneticFieldAz
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -86,5 +89,5 @@
     fRunStart.SetCorsikaTime(f[1]);
 
-    fProgramVersion = f[2];          //FIXME: INT???
+    fProgramVersion = f[2];
     fNumObsLevel    = TMath::Nint(f[3]);
 
@@ -149,5 +152,8 @@
     fParticleID = TMath::Nint(g[1]);
 
-    fImpactMax = g[86];
+    // MAGNETIC FIELD: x/z-component of earth magnetic field in muT
+    fMagneticFieldX  =  g[69];  // x-component ( BX)
+    fMagneticFieldZ  = -g[70];  // z-component (-BZ)
+    fMagneticFieldAz =  g[91];  // Azimuth angle of magnetic north expressed in telescope coordinates
 
     fZdMin = g[79];                // lower edge of theta in °
@@ -157,4 +163,14 @@
     // FIXME: Correct for direction of magnetic field!
 
+    // Number of cherenkov detectors in x
+    // Number of cherenkov detectors in y
+    // Grid spacing x
+    // Grid spacing y
+
+    // g[93] angle between array x-direction and magnetic north
+
+
+    fImpactMax = g[86];
+
     fWavelengthMin = g[95];        // Cherenkov bandwidth lower end in nm
     fWavelengthMax = g[96];        // Cherenkov bandwidth upper end in nm
@@ -222,20 +238,24 @@
 {
     *fLog << all << endl;
-    *fLog << "Run Number:  " << fRunNumber << "  (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
-    *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
+    *fLog << "Run Number:    " << fRunNumber << "  (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
+    *fLog << "Particle ID:   " << MMcEvt::GetParticleName(fParticleID) << endl;
     if (fNumEvents>0)
-        *fLog << "Num Events:  " << fNumEvents << endl;
-    *fLog << "Obs Level:  ";
+        *fLog << "Num Events:    " << fNumEvents << endl;
+    *fLog << "Obs Level:    ";
     for (Byte_t i=0; i<fNumObsLevel; i++)
         *fLog << " " << fObsLevel[i]/100. << "m";
     *fLog << endl;
-    *fLog << "Spectrum:    Slope=" << fSlopeSpectrum << "  (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" <<  endl;
+
+    *fLog << "MagneticField: X/Z=(" << fMagneticFieldX << "/";
+    *fLog << fMagneticFieldZ << ")  Az=" << fMagneticFieldAz*TMath::RadToDeg() << "deg" << endl;
+
+    *fLog << "Spectrum:      Slope=" << fSlopeSpectrum << "  (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" <<  endl;
 
     if (fViewConeOuterAngle>0)
-        *fLog << "ViewCone:    " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
+        *fLog << "ViewCone:      " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
 
     if (fZdMax>=0)
     {
-        *fLog << "Zd/Az:       " << fZdMin << "deg";
+        *fLog << "Zd/Az:         " << fZdMin << "deg";
         if (fZdMin==fZdMax)
             *fLog << " (fixed)";
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9335)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9336)
@@ -16,23 +16,27 @@
 
 private:
-    UInt_t   fRunNumber;              // Run number
-    UInt_t   fParticleID;             // Particle ID (see MMcEvtBasic or CORSIKA manual)
-    UInt_t   fNumEvents;              // Number of events
-    MTime    fRunStart;               // Date of begin (yymmdd)
-    Float_t  fProgramVersion;         // Version of program
+    UInt_t  fRunNumber;               // Run number
+    UInt_t  fParticleID;              // Particle ID (see MMcEvtBasic or CORSIKA manual)
+    UInt_t  fNumEvents;               // Number of events
+    MTime   fRunStart;                // Date of begin (yymmdd)
+    Float_t fProgramVersion;          // Version of program
 
-    Byte_t   fNumObsLevel;            // Number of observation levels
-    Float_t  fObsLevel[10];           // Observation levels [cm]
+    Byte_t  fNumObsLevel;             // Number of observation levels
+    Float_t fObsLevel[10];            // Observation levels [cm]
 
-    Float_t  fImpactMax;              // [cm] Maximum simulated impact
+    Float_t fImpactMax;               // [cm] Maximum simulated impact
 
-    Float_t  fSlopeSpectrum;          // Slope of energy spectrum
-    Float_t  fEnergyMin;              // Lower limit of energy range
-    Float_t  fEnergyMax;              // Upper limit of energy range
+    Float_t fSlopeSpectrum;           // Slope of energy spectrum
+    Float_t fEnergyMin;               // Lower limit of energy range
+    Float_t fEnergyMax;               // Upper limit of energy range
 
-    Float_t  fZdMin;                  // [rad] Zenith distance
-    Float_t  fZdMax;                  // [rad] Zenith distance
-    Float_t  fAzMin;                  // [rad] Azimuth (north=0; east=90)
-    Float_t  fAzMax;                  // [rad] Azimuth (north=0; east=90) (north denotes the magnet north which is defined to be in the geografic north!)
+    Float_t fZdMin;                   // [rad] Zenith distance
+    Float_t fZdMax;                   // [rad] Zenith distance
+    Float_t fAzMin;                   // [rad] Azimuth (north=0; east=90)
+    Float_t fAzMax;                   // [rad] Azimuth (north=0; east=90) (north denotes the magnet north which is defined to be in the geografic north!)
+
+    Float_t fMagneticFieldX;          // [muT] x-component of earth magnetic field (ceres coordinate system)
+    Float_t fMagneticFieldZ;          // [muT] z-component of earth magnetic field (ceres coordinate system)
+    Float_t fMagneticFieldAz;         // [rad] Azimuth angle of magnetic north expressed in telescope coordinates
 
     Float_t fWavelengthMin;           // [nm] Wavelength bandwidth lo edge
@@ -50,5 +54,7 @@
     UInt_t GetNumEvents() const { return fNumEvents; }
 
-    UInt_t GetFormatVersion() const { return (UInt_t)fProgramVersion; }
+    const MTime &GetRunStart() const { return fRunStart; }
+
+    Float_t GetProgramVersion() const { return fProgramVersion; }
 
     Float_t GetZdMin() const { return fZdMin; }
@@ -67,4 +73,8 @@
     Float_t GetImpactMax() const { return fImpactMax; }
 
+    Float_t GetMagneticFieldX() const  { return fMagneticFieldX; }
+    Float_t GetMagneticFieldZ() const  { return fMagneticFieldZ; }
+    Float_t GetMagneticFieldAz() const { return fMagneticFieldAz; }
+
     Float_t GetViewConeOuterAngle() const { return fViewConeOuterAngle; }
     Bool_t HasViewCone() const { return fViewConeOuterAngle>0; }
Index: trunk/MagicSoft/Mars/mjobs/MJSimulation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9336)
@@ -331,8 +331,8 @@
     MBinning binss( 100,     1, 10000000, "BinningSize",   "log");
     MBinning binsi(  50,  -250,      250, "BinningImpact");
-    MBinning binsh(  50,     0,       12, "BinningHeight");
-    MBinning binsaz(360,  -360,      360, "BinningAz");
+    MBinning binsh( 150,     0,       50, "BinningHeight");
+    MBinning binsaz(720,  -360,      360, "BinningAz");
     MBinning binszd( 70,     0,       70, "BinningZd");
-    MBinning binsvc(155,     0,       31, "BinningViewCone");
+    MBinning binsvc( 45,     0,        9, "BinningViewCone");
     MBinning binsew(150,     0,       50, "BinningEvtWidth");
     MBinning binstr("BinningTrigPos");
@@ -357,7 +357,10 @@
     mhtp.SetTitle("Trigger position w.r.t. the first photon hitting a detector");
 
-    MH3 mhew("MPhotonStatistics.fTimeLast-MPhotonStatistics.fTimeFirst - MRawRunHeader.GetFreqSampling/1000.*MRawRunHeader.fNumSamplesHiGain - 2*MPulseShape.GetPulseWidth");
+    MH3 mhew("MPhotonStatistics.fLength");
     mhew.SetName("EvtWidth");
     mhew.SetTitle("Time between first and last photon hitting a detector");
+
+    MH3 mhed("MPhotonStatistics.fTimeMedDev");
+    mhed.SetName("EvtMedDev;EvtWidth");
 
     MFillH fillh1(&mhn1, "", "FillCorsika");
@@ -366,4 +369,5 @@
     MFillH filltp(&mhtp, "", "FillTriggerPos");
     MFillH fillew(&mhew, "", "FillEvtWidth");
+    MFillH filled(&mhed, "", "FillMedDev");
     fillh1.SetNameTab("Corsika",    "Distribution as simulated by Corsika");
     fillh2.SetNameTab("Detectable", "Distribution of events hit the detector");
@@ -371,4 +375,5 @@
     filltp.SetNameTab("TrigPos",    "TriggerPosition w.r.t the first photon");
     fillew.SetNameTab("EvtWidth",   "Time between first and last photon hitting a detector");
+    filled.SetNameTab("MedDev",     "Time between first and last photon hitting a detector");
 
     MHPhotonEvent planeG(1);     // Get from MaxImpact
@@ -621,5 +626,8 @@
     }
     if (header.IsDataRun())
+    {
         tasks.AddToList(&fillew);
+        tasks.AddToList(&filled);
+    }
     if (!header.IsPedestalRun())
     {
Index: trunk/MagicSoft/Mars/mpedestal/MMcPedestalCopy.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MMcPedestalCopy.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/mpedestal/MMcPedestalCopy.cc	(revision 9336)
@@ -114,5 +114,5 @@
 
     // Check if it is a ceres file
-    if (mcrun && mcrun->GetCamVersion()==UShort_t(-1))
+    if (mcrun && mcrun->IsCeres())
     {
         *fLog << inf << "This is a ceres file... subtracting Baseline from ElectronicNoise [MPedestalCam]." << endl;
Index: trunk/MagicSoft/Mars/msim/MSimMMCS.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/msim/MSimMMCS.cc	(revision 9336)
@@ -84,6 +84,6 @@
         return kFALSE;
 
-    fPointingPos = (MPointingPos*)plist->FindObject("MPointingPos");
-    if (!fPointingPos)
+    fPointingTel = (MPointingPos*)plist->FindObject("MPointingPos");
+    if (!fPointingTel)
     {
         *fLog << err << "MPointingPos not found... aborting." << endl;
@@ -134,6 +134,9 @@
 
     //    fNumPheFromDNSB        MMcPedestalNSBAdd   // Number of phe/ns from diffuse NSB
+
+    // FIXME: Is there a way to write them as LAST entry in the file?
     mrh->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
     mrh->SetImpactMax(fRunHeader->GetImpactMax());
+    mrh->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
 
     // ----------------------------------------------------
@@ -148,4 +151,5 @@
     const UInt_t id = fRunHeader->GetParticleID();
 
+    // FIXME: Is there a way to write them as LAST entry in the file?
     rh->SetRunInfo(1, fRunHeader->GetRunNumber(), 0);
     rh->SetSourceInfo(MMcEvtBasic::GetParticleName(id));
@@ -166,6 +170,6 @@
     fMcEvtBasic->SetImpact(fEvtHeader->GetImpact());
 
-    fMcEvtBasic->SetTelescopeTheta(fPointingPos->GetZdRad());
-    fMcEvtBasic->SetTelescopePhi(fPointingPos->GetAzRad());
+    fMcEvtBasic->SetTelescopeTheta(fPointingTel->GetZdRad());
+    fMcEvtBasic->SetTelescopePhi(fPointingTel->GetAzRad());
 
     fMcEvtBasic->SetReadyToSave();
@@ -173,6 +177,8 @@
     static_cast<MMcEvtBasic&>(*fMcEvt) = *fMcEvtBasic;
 
+    // Convert from corsika franme to telescope frame, taking
+    // the magnetic field into account: tel = corsika+offset
     fMcEvt->SetTheta(fEvtHeader->GetZd());
-    fMcEvt->SetPhi(fEvtHeader->GetAz());
+    fMcEvt->SetPhi(fEvtHeader->GetAz()+fRunHeader->GetMagneticFieldAz());
 
     fMcEvt->SetEvtNumber(fEvtHeader->GetEvtNumber());
Index: trunk/MagicSoft/Mars/msim/MSimMMCS.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimMMCS.h	(revision 9335)
+++ trunk/MagicSoft/Mars/msim/MSimMMCS.h	(revision 9336)
@@ -18,5 +18,5 @@
     MMcEvtBasic       *fMcEvtBasic;
     MMcEvt            *fMcEvt;
-    MPointingPos      *fPointingPos;
+    MPointingPos      *fPointingTel;  //! telescope poiting position in local (telescope) coordinate system
     MCorsikaEvtHeader *fEvtHeader;
     MCorsikaRunHeader *fRunHeader;
Index: trunk/MagicSoft/Mars/msim/MSimPointingPos.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimPointingPos.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/msim/MSimPointingPos.cc	(revision 9336)
@@ -41,7 +41,11 @@
 //  Output Containers:
 //   MPointingPos
+//   PointingCorsika [MPointingPos]
 //
 //////////////////////////////////////////////////////////////////////////////
 #include "MSimPointingPos.h"
+
+#include <TRandom.h>
+#include <TVector3.h>
 
 #include "MLog.h"
@@ -64,5 +68,7 @@
 //
 MSimPointingPos::MSimPointingPos(const char* name, const char *title)
-    : fRunHeader(0), fEvtHeader(0), fPointing(0)
+    : fRunHeader(0), fEvtHeader(0), fPointingCorsika(0), fPointingLocal(0),
+    fOffTargetDistance(-1), fOffTargetPhi(-1)
+
 {
     fName  = name  ? name  : "MSimPointingPos";
@@ -77,6 +83,10 @@
 Int_t MSimPointingPos::PreProcess(MParList *pList)
 {
-    fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
-    if (!fPointing)
+    fPointingCorsika = (MPointingPos*)pList->FindCreateObj("MPointingPos", "PointingCorsika");
+    if (!fPointingCorsika)
+        return kFALSE;
+
+    fPointingLocal = (MPointingPos*)pList->FindCreateObj("MPointingPos");
+    if (!fPointingLocal)
         return kFALSE;
 
@@ -95,6 +105,30 @@
     }
 
+    // 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;
+        *fLog <<"   a pointing distance of " << GetOffTargetDistance() << "deg ";
+        if (fOffTargetPhi<0)
+            *fLog << "randomly distributed in phi." << endl;
+        else
+            *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
+    }
+
     return kTRUE;
 }
+
+/*
+Bool_t MSimPointingPos::ReInit(MParList *pList)
+{
+    // FIXME: Check also the enlightened region on the ground!
+    return kTRUE;
+}
+*/
 
 // --------------------------------------------------------------------------
@@ -102,34 +136,58 @@
 Int_t MSimPointingPos::Process()
 {
+
     // If a view cone is given use the fixed telescope orientation
     const Bool_t fixed = 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
+    /*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())
+    {
+        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();
+    }
 
     // Setup the pointing position
-    fPointing->SetLocalPosition(zd, az);
+    fPointingCorsika->SetLocalPosition(zd, az);
+    fPointingLocal->SetLocalPosition(zd, az+fRunHeader->GetMagneticFieldAz());
+
+    // Calculate incident angle between magnetic field direction
+    // and pointing direction ( phi and theta? )
 
     return kTRUE;
 }
 
-/*
 Int_t MSimPointingPos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
 {
     Bool_t rc = kFALSE;
-    if (IsEnvDefined(env, prefix, "FileName", print))
+    if (IsEnvDefined(env, prefix, "OffTargetDistance", print))
     {
         rc = kTRUE;
-        SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
+        SetOffTargetDistance(GetEnvValue(env, prefix, "OffTargetDistance", GetOffTargetDistance()));
     }
 
-    if (IsEnvDefined(env, prefix, "UseTheta", print))
+    if (IsEnvDefined(env, prefix, "OffTargetPhi", print))
     {
         rc = kTRUE;
-        SetUseTheta(GetEnvValue(env, prefix, "UseTheta", fUseTheta));
+        SetOffTargetPhi(GetEnvValue(env, prefix, "OffTargetPhi", GetOffTargetPhi()));
     }
 
     return rc;
 }
-*/
+
Index: trunk/MagicSoft/Mars/msim/MSimPointingPos.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MSimPointingPos.h	(revision 9335)
+++ trunk/MagicSoft/Mars/msim/MSimPointingPos.h	(revision 9336)
@@ -14,20 +14,33 @@
 {
 private:
-    MCorsikaRunHeader *fRunHeader;  //! Header storing event information
-    MCorsikaEvtHeader *fEvtHeader;  //! Header storing event information
-    MPointingPos      *fPointing;   //! Output storing telescope poiting position
+    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
+
+    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
 
     // MParContainer
-    //Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 
     // MTask
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
-
+    Int_t  PreProcess(MParList *pList);
+    //Bool_t ReInit(MParList *pList);
+    Int_t  Process();
 
 public:
     MSimPointingPos(const char *name=NULL, const char *title=NULL);
 
+    // Getter
+    Double_t GetOffTargetDistance() const { return 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(); }
+
     // MSimPointingPos
+    Bool_t IsOffTargetObservation() const { return fOffTargetDistance>0; }
 
     // TObject
Index: trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc
===================================================================
--- trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc	(revision 9335)
+++ trunk/MagicSoft/Mars/msimreflector/MSimReflector.cc	(revision 9336)
@@ -147,5 +147,5 @@
     }
 
-    fPointing = (MPointingPos*)pList->FindObject("MPointingPos");
+    fPointing = (MPointingPos*)pList->FindObject("PointingCorsika", "MPointingPos");
     if (!fPointing)
     {
