Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 7365)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 7366)
@@ -124,4 +124,59 @@
     MAstro::Mjd2Ymd(fMjd, y, m, d);
 }
+
+// --------------------------------------------------------------------------
+//
+// GetMoonPhase - calculate phase of moon as a fraction:
+//  Returns -1 if calculation failed
+//
+//  see MAstro::GetMoonPhase
+//
+Double_t MTime::GetMoonPhase() const
+{
+    return MAstro::GetMoonPhase(GetMjd());
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the Period to which the time belongs to. The Period is defined
+// as the number of synodic months ellapsed since the first full moon
+// after Jan 1st 1980 (which was @ MJD=44240.37917)
+//
+//   see MAstro::GetMoonPeriod
+//
+Double_t MTime::GetMoonPeriod() const
+{
+    return MAstro::GetMoonPeriod(GetMjd());
+}
+
+// --------------------------------------------------------------------------
+//
+// To get the moon period as defined for MAGIC observation we take the
+// nearest integer mjd, eg:
+//   53257.8 --> 53258
+//   53258.3 --> 53258
+// Which is the time between 13h and 12:59h of the following day. To
+// this day-period we assign the moon-period at midnight. To get
+// the MAGIC definition we now substract 284.
+//
+// For MAGIC observation period do eg:
+//   GetMagicPeriod(53257.91042)
+// or
+//   MTime t;
+//   t.SetMjd(53257.91042);
+//   GetMagicPeriod(t.GetMjd());
+// or
+//   MTime t;
+//   t.Set(2004, 1, 1, 12, 32, 11);
+//   GetMagicPeriod(t.GetMjd());
+//
+//
+//  see MAstro::GetMagicPeriod
+//
+Int_t MTime::GetMagicPeriod() const
+{
+    return MAstro::GetMagicPeriod(GetMjd());
+}
+
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 7365)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 7366)
@@ -100,4 +100,7 @@
     TTime    GetRootTime() const;
     Double_t GetAxisTime() const;
+    Double_t GetMoonPhase() const;
+    Double_t GetMoonPeriod() const;
+    Int_t    GetMagicPeriod() const;
     Long_t   GetTime() const { return (Long_t)fTime; } // [ms] Time of Day returned in the range [-11h, 13h)
     void     GetTime(Byte_t &h, Byte_t &m, Byte_t &s, UShort_t &ms) const;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 7365)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 7366)
@@ -277,9 +277,9 @@
 
   PrintUncalibrated(MBadPixelsPix::kDeviatingTimeResolution,    
-                    Form("%s%2.1f%s","Time resol. less than ",fRelTimeResolutionLimit," FADC sl. from Mean:     "));
+                    Form("%s%2.1f%s","Time resol. less than ", fRelTimeResolutionLimit, " FADC sl. from Mean:"));
   PrintUncalibrated(MBadPixelsPix::kRelTimeOscillating,   
-                    "Pixels with changing Rel. Times over time:             ");
+                    "Pixels with changing Rel. Times over time:");
   PrintUncalibrated(MBadPixelsPix::kRelTimeNotFitted,     
-                    "Pixels with unsuccesful Gauss fit to the times:        ");
+                    "Pixels with unsuccesful Gauss fit to the times:");
 
   if (asciilog)
@@ -494,8 +494,6 @@
     if (fGeom->InheritsFrom("MGeomCamMagic"))
     {
-        *fLog << " Uncalibrated Pixels:            Inner: "
-            << Form("%3i",unsuit[0]) << " Outer: " << Form("%3i",unsuit[1]) << endl;
-        *fLog << " Unreliable Pixels:              Inner: "
-            << Form("%3i",unrel[0])  << " Outer: " << Form("%3i",unrel[1])  << endl;
+        PrintUncalibrated("Uncalibrated Pixels:", unsuit[0], unsuit[1]);
+        PrintUncalibrated("Unreliable Pixels:",   unrel[0],  unrel[1]);
     }
 }
@@ -522,6 +520,14 @@
     }
 
-    *fLog << " " << text << "Inner: " << Form("%3i",countinner);
-    *fLog << " Outer: " << Form("%3i", countouter) << endl;
+    PrintUncalibrated(text, countinner, countouter);
+}
+
+void MCalibrationRelTimeCalc::PrintUncalibrated(const char *text, Int_t in, Int_t out) const
+{
+    *fLog << " " << setfill(' ') << setw(56) << setiosflags(ios::left) << text;
+    *fLog << " Inner: " << Form("%3i", in);
+    *fLog << " Outer: " << Form("%3i", out);
+    *fLog << resetiosflags(ios::left) << endl;
+
 }
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 7365)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 7366)
@@ -65,5 +65,6 @@
   void   FinalizeUnsuitablePixels ();
 
-  void   PrintUncalibrated( MBadPixelsPix::UncalibratedType_t typ, const char *text) const;
+  void   PrintUncalibrated(const char *text, Int_t in, Int_t out) const;
+  void   PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const;
 
   // Query checks
Index: trunk/MagicSoft/Mars/mmuon/MHMuonPar.cc
===================================================================
--- trunk/MagicSoft/Mars/mmuon/MHMuonPar.cc	(revision 7365)
+++ trunk/MagicSoft/Mars/mmuon/MHMuonPar.cc	(revision 7366)
@@ -238,5 +238,5 @@
     AppendPad("pad4");
 }
-
+/*
 Double_t MHMuonPar::Integral(const TProfile &p, Int_t a, Int_t b) const
 {
@@ -252,5 +252,5 @@
     return denominator==0 ? 0 : numerator/denominator;
 }
-
+*/
 Double_t MHMuonPar::Integral(const TProfile &p, Float_t a, Float_t b) const
 {
@@ -258,5 +258,4 @@
     const Int_t bin2 = p.GetXaxis()->FindFixBin(b);
 
-//    return Integral(p, bin1, bin2);
     return p.Integral(bin1, bin2);
 }
@@ -268,5 +267,4 @@
         const TString txt = Form("\\Sigma_{%.2f\\circ}^{%.2f\\circ} = %.3f",
                                  fgIntegralLoLim, fgIntegralUpLim, Integral(fHistBroad));
-//                                 fgIntegralLoLim, fgIntegralUpLim, Integral(fHistBroad)*1000);
 
         TLatex text(0.55, 0.93, txt);
Index: trunk/MagicSoft/Mars/mmuon/MHMuonPar.h
===================================================================
--- trunk/MagicSoft/Mars/mmuon/MHMuonPar.h	(revision 7365)
+++ trunk/MagicSoft/Mars/mmuon/MHMuonPar.h	(revision 7366)
@@ -33,5 +33,5 @@
     Float_t fMm2Deg;
 
-    Double_t Integral(const TProfile &p, Int_t a, Int_t b) const;
+    //Double_t Integral(const TProfile &p, Int_t a, Int_t b) const;
     Double_t Integral(const TProfile &p, Float_t a=fgIntegralLoLim, Float_t b=fgIntegralUpLim) const;
 
Index: trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc
===================================================================
--- trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc	(revision 7365)
+++ trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc	(revision 7366)
@@ -130,5 +130,5 @@
     fHistTime.SetTitle("HistTime");
     fHistTime.SetXTitle("timing difference");
-    fHistTime.SetYTitle("number of pixels");
+    fHistTime.SetYTitle("Counts");
     fHistTime.SetDirectory(NULL);
     fHistTime.SetFillStyle(4000);
@@ -180,5 +180,5 @@
     ApplyBinning(*plist, "ArcPhi",    &fHistPhi);
     ApplyBinning(*plist, "MuonWidth", &fHistWidth);
-    ApplyBinning(*plist, "MuonTime", &fHistTime);
+    ApplyBinning(*plist, "MuonTime",  &fHistTime);
 
     return kTRUE;
@@ -213,9 +213,9 @@
 
         // if the signal is not near the estimated circle, it is ignored.
-        if (dist < fMuonSearchPar->GetRadius() + fMargin &&
-            dist > fMuonSearchPar->GetRadius() - fMargin)
+        if (TMath::Abs(dist-fMuonSearchPar->GetRadius())<fMargin)
         {
             fHistTime.Fill(pix.GetArrivalTime()-fMuonSearchPar->GetTime());
         }
+
         // use only the inner pixles. FIXME: This is geometry dependent
         if(i>397)
@@ -240,7 +240,7 @@
 
     //    Double_t err;
-    Double_t mean, meanerr, sig, sigerr;
-    gMinuit->GetParameter(2, sig, sigerr); // get the sigma value
-    gMinuit->GetParameter(1, mean, meanerr); // get the sigma value
+    Double_t mean, meanerr, dummy;
+    gMinuit->GetParameter(2, sig,  dummy);  // get the sigma value
+    gMinuit->GetParameter(1, mean, dummy);  // get the sigma value
 
     for (Int_t i=0; i<entries; i++)
@@ -255,9 +255,8 @@
 
         // if the signal is not near the estimated circle, it is ignored.
-        if (dist < fMuonSearchPar->GetRadius() + fMargin &&
-            dist > fMuonSearchPar->GetRadius() - fMargin)
+        if (TMath::Abs(dist-fMuonSearchPar->GetRadius())<fMargin &&
+            TMath::Abs(pix.GetArrivalTime()-fMuonSearchPar->GetTime()-mean) < 2*sig)
         {
-            if(TMath::Abs(pix.GetArrivalTime()-(fMuonSearchPar->GetTime()+mean))<2*sig)
-                fHistPhi.Fill(TMath::ATan2(dx, dy)*TMath::RadToDeg(), pix.GetNumPhotons());
+            fHistPhi.Fill(TMath::ATan2(dx, dy)*TMath::RadToDeg(), pix.GetNumPhotons());
         }
     }
