Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8600)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8601)
@@ -19,4 +19,37 @@
                                                  -*-*- END OF LINE -*-*-
 
+
+ 2007/06/23 Thomas Bretz
+
+   * mbadpixels/MBadPixelsCam.cc:
+     - fixed some Print output
+
+   * mhflux/MHAlpha.cc:
+     - added the missing include of MHillas.h 
+     - removed the obsolete ClassImp(MAlphaFitter)
+
+   * mhflux/MHFalseSource.cc, mimage/MHillasSrc.cc:
+     - added the missing include MHillas.h
+
+   * mimage/MHHillasSrc.cc, mimage/MHillasSrc.h:
+     - removed obsolete include of MHillas.h
+
+   * mpointing/MPointingDevCalc.[h,cc]:
+     - added the real starguider calibration using a pointing model
+       for the strguider. The dates for which the model is valid
+       can still be tuned.
+
+   * mpointing/MSrcPosCalc.cc, mreport/MReportStarguider.cc:
+     - added some comment
+
+
+
+ 2007/06/23 Thomas Bretz
+
+   * mpointing/MPointing.cc:
+     - improved output
+
+
+
  2007/06/23 Daniela Dorner
 
@@ -51,4 +84,11 @@
    * mhflux/MHThetaSqN.cc:
      - fixed optimization (it just didn't work)
+
+   * mpointing/MPointing.[h,cc]:
+     - added some checks in Load
+     - fixed a problem with the constructors (the pointers MUST be
+       initialized to 0)
+     - renamed fNumPar to fgNumPar
+     - Load and Save now return kTRUE or kFALSE
 
 
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 8601)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.cc,v 1.51 2007-06-18 14:35:39 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.cc,v 1.52 2007-06-24 16:31:57 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -455,6 +455,4 @@
   *fLog << endl;
 
-  // TO BE FIXED!!!
-
   PrintBadPixels(MBadPixelsPix::kPreviouslyExcluded,"Previously excluded");
   PrintBadPixels(MBadPixelsPix::kChargeIsPedestal,"Signal smaller 3 Pedestal RMS");
@@ -468,11 +466,11 @@
   PrintBadPixels(MBadPixelsPix::kLoGainOverFlow,"Low-Gain Histogram Overflow");
   PrintBadPixels(MBadPixelsPix::kDeadPedestalRms,"Presumably dead from Ped. Rms");
-//  PrintBadPixels(MBadPixelsPix::kFluctuatingArrivalTimes,"Fluctuating Pulse Arrival Times");
+  PrintBadPixels(MBadPixelsPix::kDeviatingAbsTimeResolution,"Deviating abs. time resolution");
+  PrintBadPixels(MBadPixelsPix::kDeviatingRelTimeResolution,"Deviating rel. time resolution");
+  //  PrintBadPixels(MBadPixelsPix::kFluctuatingArrivalTimes,"Fluctuating Pulse Arrival Times");
 
   *fLog << endl;
   *fLog << all << "Unreliable pixels statistics:" << endl;
   *fLog << endl;
-
-  // TO BE FIXED!!!
 
   PrintBadPixels(MBadPixelsPix::kChargeSigmaNotValid,"Signal Sigma smaller Pedestal RMS");
@@ -634,13 +632,9 @@
       break;
     case 6:
-      if  (!(*this)[idx].GetUnsuitableCalLevel())
-        return kFALSE;
       val = (*this)[idx].GetUnsuitableCalLevel();
-      break;
+      return val>0;
     case 7:
-      if  (!(*this)[idx].GetUnreliableCalLevel())
-        return kFALSE;
       val = (*this)[idx].GetUnreliableCalLevel();
-      break;
+      return val>0;
     case 8:
       if  (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8601)
@@ -55,4 +55,5 @@
 
 #include "MSrcPosCam.h"
+#include "MHillas.h"
 #include "MHillasSrc.h"
 #include "MTime.h"
@@ -71,5 +72,4 @@
 
 ClassImp(MHAlpha);
-ClassImp(MAlphaFitter);
 
 using namespace std;
Index: trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc	(revision 8601)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.21 2006-11-01 08:29:45 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.22 2007-06-24 16:31:57 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -132,4 +132,5 @@
 #include "MGeomCam.h"
 #include "MSrcPosCam.h"
+#include "MHillas.h"
 #include "MHillasSrc.h"
 #include "MTime.h"
Index: trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 8601)
@@ -45,5 +45,4 @@
 #include "MParList.h"
 
-#include "MHillas.h"
 #include "MHillasSrc.h"
 
Index: trunk/MagicSoft/Mars/mimage/MHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 8601)
@@ -78,4 +78,5 @@
 
 #include "MGeomCam.h"
+#include "MHillas.h"
 #include "MSrcPosCam.h"
 
Index: trunk/MagicSoft/Mars/mimage/MHillasSrc.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 8600)
+++ trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 8601)
@@ -2,8 +2,12 @@
 #define MARS_MHillasSrc
 
-#ifndef MARS_MHillas
-#include "MHillas.h"
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
 #endif
 
+class TArrayF;
+
+class MHillas;
+class MGeomCam;
 class MSrcPosCam;
 
Index: trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.cc	(revision 8601)
@@ -65,4 +65,5 @@
 
 #include "MAstro.h"
+#include "MPointing.h"
 #include "MPointingDev.h"
 #include "MRawRunHeader.h"
@@ -73,5 +74,47 @@
 using namespace std;
 
-// --------------------------------------------------------------------------
+const TString MPointingDevCalc::fgFileName="resources/starguider.txt";
+
+// --------------------------------------------------------------------------
+//
+// Delete fPointing and set pointing to NULL
+//
+void MPointingDevCalc::Clear(Option_t *o)
+{
+    if (fPointing)
+        delete fPointing;
+
+    fPointing = NULL;
+}
+
+// --------------------------------------------------------------------------
+//
+// Clear the pointing model. If run-number >= 87751 read the new
+// pointing model with fFileName
+//
+Bool_t MPointingDevCalc::ReadPointingModel(const MRawRunHeader &run)
+{
+    if (run.GetRunNumber()<87751)
+    {
+        Clear();
+        return kTRUE;
+    }
+
+    if (!fPointing)
+        fPointing = new MPointing;
+
+    if (fFileName==fPointing->GetName())
+    {
+        *fLog << inf << fFileName << " already loaded." << endl;
+        return kTRUE;
+    }
+
+    return fPointing->Load(fFileName);
+}
+
+// --------------------------------------------------------------------------
+//
+// Check the file/run type from the run-header and if it is a data file
+// load starguider calibration.
 //
 Bool_t MPointingDevCalc::ReInit(MParList *plist)
@@ -95,5 +138,5 @@
         if (!fReport)
             *fLog << warn << "MReportStarguider not found... skipped." << endl;
-        return kTRUE;
+        return ReadPointingModel(*run);
 
     case MRawRunHeader::kRTMonteCarlo:
@@ -153,10 +196,83 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Do a full starguider calibration using a pointing model for the starguider.
+//
+void MPointingDevCalc::DoCalibration(Double_t devzd, Double_t devaz) const
+{
+    if (!fPointing)
+    {
+        // Do a simple starguider calibration using a simple offset in x and y
+        fDeviation->SetDevZdAz(devzd, devaz);
+
+        // Linear starguider calibration taken from April/May data
+        // For calibration add MDriveReport::GetErrorZd/Az !
+        fDeviation->SetDevXY(fDx, fDy); // 1arcmin ~ 5mm
+        //devzd -= 2.686/60;   
+        //devaz -= 2.840/60;
+
+        return;
+    }
+
+    // def?: 20.105, 773
+    // 0/0 : 20.119, 763
+    // -/- : 19.417  726
+    // +mis: 19.80,  756
+
+    // Get the nominal position the star is at the sky
+    // Unit: deg
+    ZdAz nom(fReport->GetNominalZd(), fReport->GetNominalAz());
+    nom *= TMath::DegToRad();
+
+    // Get the mispointing measured by the telescope. It is
+    // calculate as follows:
+    //
+    // Position at which the starguider camera is pointing in real:
+    //       pointing position = nominal position - mis
+    ZdAz mis(devzd, devaz);
+    mis *= TMath::DegToRad();
+
+    // The pointing mode is the conversion from the real pointing
+    // position of the telescope into the pointing position measured
+    // by the starguider.
+    //
+    //  --> To get the real poiting position of the telescope we have
+    //      to convert the measured position back;
+    //
+
+    // Position at which the starguider camera is pointing in real:
+    //       pointing position = nominal position - dev
+    //
+    // The position measured as the starguider's pointing position
+    ZdAz pos(nom);        // cpos = sao - dev
+    pos -= mis;
+
+    // Now we convert the starguider's pointing position into the
+    // telescope pointing position (the pointing model converts
+    // the telescope pointing position into the starguider pointing
+    // position)
+    ZdAz point = fPointing->CorrectBack(pos);
+
+    // MSrcPosCalc uses the following condition to calculate the
+    // source position in the camera:
+    //    real pointing pos = nominal pointing pos - dev
+    //
+    // Therefor we calculate dev as follows:
+    ZdAz dev(nom);
+    dev -= point;
+    dev *= TMath::RadToDeg();
+
+    // Set Measured mispointing and additional offset
+    fDeviation->SetDevZdAz(dev.Zd(), dev.Az());
+    fDeviation->SetDevXY(0, 0);
+}
+
 Int_t MPointingDevCalc::ProcessStarguiderReport()
 {
     /************* CHECK STATUS!!! ******************/
 
-    Double_t devzd = fReport->GetDevZd(); // [deg]
-    Double_t devaz = fReport->GetDevAz(); // [deg]
+    Double_t devzd = fReport->GetDevZd(); // [arcmin]
+    Double_t devaz = fReport->GetDevAz(); // [arcmin]
     if (devzd==0 && devaz==0)
     {
@@ -205,4 +321,6 @@
     }
 
+    // >= 87751 (31.3.06 12:00)
+
     // Calculate absolute deviation
     const Double_t dev = MAstro::GetDevAbs(fReport->GetNominalZd(), devzd, devaz);
@@ -215,11 +333,5 @@
     }
 
-    fDeviation->SetDevZdAz(devzd, devaz);
-
-    // Linear starguider calibration taken from April/May data
-    // For calibration add MDriveReport::GetErrorZd/Az !
-    fDeviation->SetDevXY(fDx, fDy);
-    //devzd -= 2.686/60;   // 1arcmin ~ 5mm
-    //devaz -= 2.840/60;
+    DoCalibration(devzd, devaz);
 
     fSkip[0]++;
Index: trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h	(revision 8600)
+++ trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h	(revision 8601)
@@ -10,5 +10,7 @@
 #endif
 
+class MPointing;
 class MPointingDev;
+class MRawRunHeader;
 class MReportStarguider;
 
@@ -16,6 +18,9 @@
 {
 private:
+    static const TString fgFileName; //! default file name of pointing model
+
     MReportStarguider *fReport;    //! MReportStarguider to get mispointing
     MPointingDev      *fDeviation; //! Output container to store pointing deviation
+    MPointing         *fPointing;  //! MPointing, pointing model for the calibration
 
     UShort_t fRunType;             //! Run Type to decide where to get pointing position from
@@ -27,4 +32,6 @@
     TArrayI  fSkip;                //! Counter for execution statistics
     Double_t fLastMjd;             //! Time of last processed report
+
+    TString fFileName;             // File name of pointing model
 
     UInt_t  fNumMinStars;          // Minimum number of identified stars
@@ -39,4 +46,8 @@
 
     // MPointingDevCalc
+    void DoCalibration(Double_t devzd, Double_t devaz) const;
+
+    Bool_t ReadPointingModel(const MRawRunHeader &run);
+
     Int_t ProcessStarguiderReport();
     void  Skip(Int_t i);
@@ -52,6 +63,8 @@
 
 public:
-    MPointingDevCalc() : fReport(0), fDeviation(0), fSkip(7), fNumMinStars(8),
-        fNsbLevel(3), fNsbMin(30), fNsbMax(60), fMaxAbsDev(15), fMaxAge(1), fDx(-7), fDy(16)
+    MPointingDevCalc() : fReport(0), fDeviation(0), fPointing(0),
+        fSkip(7), fFileName(fgFileName), fNumMinStars(8),
+        fNsbLevel(3), fNsbMin(30), fNsbMax(60), fMaxAbsDev(15),
+        fMaxAge(1), fDx(-7), fDy(16)
     {
         fName  = "MPointingDevCalc";
@@ -60,4 +73,10 @@
         AddToBranchList("MReportStarguider.*");
     }
+    ~MPointingDevCalc()
+    {
+        Clear();
+    }
+
+    void Clear(Option_t *o="");
 
     void SetNumMinStars(UInt_t n)  { fNumMinStars=n; }
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8601)
@@ -375,7 +375,10 @@
     pos0 *= conv;
 
-    TVector2 vx;
+    //TVector2 vx;
     if (fDeviation)
     {
+        // Position at which the starguider camera is pointing in real:
+        //       pointing position = nominal position - dev
+        //
         //vx = CalcXYinCamera(pos0, pos)*fGeom->GetCameraDist()*1000;
         pos0.SetZdAz(pos0.Theta()-fDeviation->GetDevZdRad(),
Index: trunk/MagicSoft/Mars/mreport/MReportStarguider.cc
===================================================================
--- trunk/MagicSoft/Mars/mreport/MReportStarguider.cc	(revision 8600)
+++ trunk/MagicSoft/Mars/mreport/MReportStarguider.cc	(revision 8601)
@@ -38,4 +38,6 @@
 // The sky brightness and the number of identified stars since 2005/03/17
 //
+// Position at which the starguider camera is pointing in real:
+//       pointing position = nominal position - dev
 //
 // Class Version 1:
