Index: trunk/MagicSoft/Mars/mpointing/MPointingDev.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDev.cc	(revision 7203)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDev.cc	(revision 7203)
@@ -0,0 +1,37 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MPointingDev
+//
+// Container stroing the telescope mispointing
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MPointingDev.h"
+
+ClassImp(MPointingDev);
+
+using namespace std;
+
Index: trunk/MagicSoft/Mars/mpointing/MPointingDev.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDev.h	(revision 7203)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDev.h	(revision 7203)
@@ -0,0 +1,32 @@
+#ifndef MARS_MPointingDev
+#define MARS_MPointingDev
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MPointingDev : public MParContainer
+{
+private:
+    Double_t fDevZd;  // [deg] Pointing offset zenith distance as calculated from starguider data
+    Double_t fDevAz;  // [deg] Pointing offset azimuth as calculated from starguider dat
+
+public:
+    MPointingDev(const char *name=0, const char *title=0) : fDevZd(0), fDevAz(0)
+    {
+        fName  = name ? name   : "MPointingDev";
+        fTitle = title ? title : "Container storing the telescope mispointing";
+    }
+
+    void SetDevZdAz(Double_t devzd, Double_t devaz) { fDevZd=devzd; fDevAz=devaz; }
+
+    Double_t GetDevZd() const  { return fDevZd; }
+    Double_t GetDevAz() const  { return fDevAz; }
+
+    Double_t GetDevZdRad() const  { return fDevZd*TMath::DegToRad(); }
+    Double_t GetDevAzRad() const  { return fDevAz*TMath::DegToRad(); }
+
+    ClassDef(MPointingDev, 1) //Container storing the telescope mispointing
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc	(revision 7203)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc	(revision 7203)
@@ -0,0 +1,222 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MPointingDevCalc
+//
+// Input Container:
+//   MReportStarguider
+//
+// Output Container:
+//   MPointingDev
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MPointingDevCalc.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MAstro.h"
+#include "MPointingDev.h"
+#include "MRawRunHeader.h"
+#include "MReportStarguider.h"
+
+ClassImp(MPointingDevCalc);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+Bool_t MPointingDevCalc::ReInit(MParList *plist)
+{
+    MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
+    if (!run)
+    {
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fNsbSum   = 0;
+    fNsbSq    = 0;
+    fNsbCount = 0;
+
+    fRunType = run->GetRunType();
+
+    switch (fRunType)
+    {
+/***/    case MRawRunHeader::kRTData:
+        /*
+        if (!fReport)
+        {
+            *fLog << err << "MReportStarguider not found... aborting." << endl;
+            return kFALSE;
+        }*/
+/***/        return kTRUE;
+
+    case MRawRunHeader::kRTMonteCarlo:
+        return kTRUE;
+
+    case MRawRunHeader::kRTPedestal:
+        *fLog << err << "Cannot work in a pedestal Run!... aborting." << endl;
+        return kFALSE;
+
+    case MRawRunHeader::kRTCalibration:
+        *fLog << err << "Cannot work in a calibration Run!... aborting." << endl;
+        return kFALSE;
+
+    default:
+        *fLog << err << "Run Type " << fRunType << " unknown!... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Search for 'MPointingPos'. Create if not found.
+//
+Int_t MPointingDevCalc::PreProcess(MParList *plist)
+{
+    fDeviation = (MPointingDev*)plist->FindCreateObj("MPointingDev");
+    fReport    = (MReportStarguider*)plist->FindObject("MReportStarguider");
+
+    // We use kRTNone here as a placeholder for data runs.
+    fRunType  = MRawRunHeader::kRTNone;
+
+    return fDeviation ? kTRUE : kFALSE;
+}
+
+Int_t MPointingDevCalc::ProcessStarguiderReport()
+{
+    Double_t devzd = fReport->GetDevZd(); // [deg]
+    Double_t devaz = fReport->GetDevAz(); // [deg]
+    if (devzd==0 && devaz==0)
+    {
+        fDeviation->SetDevZdAz(0, 0);
+        fSkip[1]++;
+        return kTRUE;
+    }
+
+    devzd /= 60; // Convert from arcmin to deg
+    devaz /= 60; // Convert from arcmin to deg
+
+    const Double_t nsb = fReport->GetSkyBrightness();
+    if (nsb>0)
+    {
+        if (nsb>30 && nsb<60)
+        {
+            fNsbSum += nsb;
+            fNsbSq  += nsb*nsb;
+            fNsbCount++;
+        }
+
+        if (fNsbCount>0)
+        {
+            const Double_t sum = fNsbSum/fNsbCount;
+            const Double_t sq  = fNsbSq /fNsbCount;
+
+            const Double_t rms = TMath::Sqrt(sq - sum*sum);
+
+            if (nsb<sum-3*rms || nsb>sum+3*rms)
+            {
+                fSkip[2]++;
+                return kTRUE;
+            }
+        }
+
+        if (fReport->GetNumIdentifiedStars()<8)
+        {
+            fSkip[3]++;
+            return kTRUE;
+        }
+    }
+
+    // Linear starguider calibration taken from April/May data
+    // For calibration add MDriveReport::GetErrorZd/Az !
+    devzd -= 2.686/60;
+    devaz -= 2.840/60;
+
+    // Calculate absolute deviation
+    const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
+
+    // Sanity check... larger deviation are strange and ignored
+    if (dev>0.25)
+    {
+        fSkip[4]++;
+        return kTRUE;
+    }
+
+    fSkip[0]++;
+    //fDeviation->SetDevZdAz(devzd, devaz);
+    fDeviation->SetDevZdAz(0, 0);
+
+    cout << "SETTING: " << devzd << " " << devaz << endl;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  See class description.
+//
+Int_t MPointingDevCalc::Process()
+{
+    switch (fRunType)
+    {
+    case MRawRunHeader::kRTNone:
+    case MRawRunHeader::kRTData:
+/***/        return fReport ? ProcessStarguiderReport() : kTRUE;
+
+    case MRawRunHeader::kRTMonteCarlo:
+        fSkip[0]++;
+        fDeviation->SetDevZdAz(0, 0);
+        return kTRUE;
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print execution statistics
+//
+Int_t MPointingDevCalc::PostProcess()
+{
+    if (GetNumExecutions()==0)
+        return kTRUE;
+
+    *fLog << inf << endl;
+    *fLog << GetDescriptor() << " execution statistics:" << endl;
+    PrintSkipped(fSkip[1], "Starguider deviation not set, is exactly 0/0");
+    PrintSkipped(fSkip[2], "NSB out of 3 sigma range");
+    PrintSkipped(fSkip[3], "Number of identified stars < 8");
+    PrintSkipped(fSkip[4], "Absolute deviation > 0.25deg");
+    *fLog << " " << (int)fSkip[0] << " (" << Form("%5.1f", 100.*fSkip[0]/GetNumExecutions()) << "%) Evts survived calculation!" << endl;
+    *fLog << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h	(revision 7203)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h	(revision 7203)
@@ -0,0 +1,48 @@
+#ifndef MARS_MPointingPositionCalc
+#define MARS_MPointingPositionCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+
+class MPointingDev;
+class MReportStarguider;
+
+class MPointingDevCalc : public MTask
+{
+private:
+    MReportStarguider *fReport;    //! MReportStarguider to get mispointing
+    MPointingDev      *fDeviation; //! Output container to store pointing deviation
+
+    UShort_t fRunType;             //! Run Type to decide where to get pointing position from
+
+    Double_t fNsbSum;              //! Sum of Nsb from Starguider
+    Double_t fNsbSq;               //! Sum of Sq of Nsb from Starguider
+    Int_t    fNsbCount;            //! Counter of Nsb entries from Starguider
+
+    TArrayI  fSkip;                //! Counter for execution statistics
+
+    // MPointingDevCalc
+    Int_t ProcessStarguiderReport();
+
+    // MTask
+    Bool_t ReInit(MParList *plist);
+    Int_t  PreProcess(MParList *plist);
+    Int_t  Process();
+    Int_t  PostProcess();
+
+public:
+    MPointingDevCalc() : fReport(0), fDeviation(0), fSkip(5)
+    {
+        fName  = "MPointingDevCalc";
+        fTitle = "Task calculating the pointing deviation";
+    }
+
+    ClassDef(MPointingDevCalc, 0) //Task calculating the pointing deviation
+};
+
+#endif
