Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3489)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3490)
@@ -19,4 +19,29 @@
                                                  -*-*- END OF LINE -*-*-
 
+ 2004/03/12: Thomas Bretz
+
+   * merpp.cc:
+     - added 'force' option
+
+   * manalysis/MCerPhotAnal2.cc:
+     - extract pedestal and pedestal rms from lo-gain if hi-gain not
+       above a certain athreshold 
+
+   * mastro/MAstroCatalog.[h,c]:
+     - added text argument to DrawStar
+
+   * mbase/MStatusDisplay.cc:
+     - some small changes to output of SaveAsPS
+
+   * mfilter/MFCosmics.cc:
+     - changed output of filter statistics
+
+   * mbadpixels/MBadPixelsTreat.[h,cc]:
+     - fixed some problems with the code - now it should work like
+       expected
+     - added a new member function to be able to change the number
+       of required neighbors
+
+
 
  2004/03/12: Wolfgang Wittek
@@ -28,4 +53,5 @@
      - include MObservatory.h
      - call member function Rotationangle() of MObservatory
+
 
 
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 3489)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 3490)
@@ -34,4 +34,8 @@
 //  an existing MBadPixelsCam.
 //
+//  It check if there are enough neighbors to calculate the mean
+//  If not, unmap the pixel. The minimum number of good neighbors
+//  should be set using SetNumMinNeighbors
+//
 //  Input Containers:
 //   MCerPhotEvt
@@ -79,5 +83,5 @@
 //
 MBadPixelsTreat::MBadPixelsTreat(const char *name, const char *title)
-    : fFlags(0)
+    : fFlags(0), fNumMinNeighbors(3)
 {
     fName  = name  ? name  : gsDefName.Data();
@@ -147,8 +151,10 @@
     for (UShort_t i=0; i<entries; i++)
     {
+        MCerPhotPix *pix = fEvt->GetPixById(i);
+
         //
         // Check whether pixel with idx i is blind
         //
-        if (!(*fBadPixels)[i].IsBad())
+        if (pix && (*fBadPixels)[i].IsOK())
             continue;
 
@@ -157,7 +163,9 @@
         // create a new entry for this pixel in MCerPhotEvt
         //
-        MCerPhotPix *pix = fEvt->GetPixById(i);
         if (!pix)
+        {
             pix = fEvt->AddPixel(i, 0, 0);
+            (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
+        }
 
         //
@@ -193,5 +201,5 @@
             // Do not use blind neighbors
             //
-            if (!(*fBadPixels)[i].IsBad())
+            if ((*fBadPixels)[i].IsBad())
                 continue;
 
@@ -254,5 +262,5 @@
         // Check whether pixel with idx i is blind
         //
-        if (!(*fBadPixels)[i].IsBad())
+        if ((*fBadPixels)[i].IsOK())
             continue;
 
@@ -290,5 +298,5 @@
             // Do not use blind neighbors
             //
-            if (!(*fBadPixels)[i].IsBad())
+            if ((*fBadPixels)[i].IsBad())
                 continue;
 
@@ -302,5 +310,5 @@
             //The error is calculated as the quadratic sum of the errors
             //
-            ped[i] += (nratio*nppix.GetMean());
+            ped[i] += nratio*nppix.GetMean();
             rms[i] += nratio*Pow2(nppix.GetRms());
 
@@ -310,6 +318,6 @@
         // Check if there are enough neighbors to calculate the mean
         // If not, unmap the pixel. The minimum number of good neighbors
-        // should be 3
-        if (num < 3)
+        // should be fNumMinNeighbors
+        if (num < fNumMinNeighbors)
         {
             MCerPhotPix *pix =fEvt->GetPixById(i);
@@ -350,8 +358,8 @@
     // Create arrays
     //
-    Double_t *nphot  = new Double_t[entries];
-    Double_t *perr   = new Double_t[entries];
-    Double_t *ped    = new Double_t[entries];
-    Double_t *pedrms = new Double_t[entries];
+    TArrayD nphot(entries);
+    TArrayD perr(entries);
+    TArrayD ped(entries);
+    TArrayD pedrms(entries);
  
     //
@@ -360,8 +368,10 @@
     for (UShort_t i=0; i<entries; i++)
     {
+        MCerPhotPix *pix = fEvt->GetPixById(i);
+
         //
         // Check whether pixel with idx i is blind
         //
-        if ((*fBadPixels)[i].IsBad())
+        if (pix && (*fBadPixels)[i].IsOK())
             continue;
 
@@ -370,7 +380,9 @@
         // create a new entry for this pixel in MCerPhotEvt
         //
-        const MCerPhotPix *pix = fEvt->GetPixById(i);
         if (!pix)
+        {
             pix = fEvt->AddPixel(i, 0, 0);
+            (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
+        }
 
         //
@@ -395,8 +407,11 @@
         const Double_t ratio = fGeomCam->GetPixRatio(i);
 
-        nphot[i]  *= ratio;
-	ped[i]    *= ratio;
-        perr[i]   *= Pow2(ratio);
-	pedrms[i] *= Pow2(pedrms[i]);
+        if (nucp)
+        {
+            nphot[i]  *= ratio;
+            perr[i]   *= ratio;
+            ped[i]    *= ratio;
+            pedrms[i] *= ratio;
+        }
 
         //
@@ -411,5 +426,5 @@
             // Do not use blind neighbors
             //
-            if ((*fBadPixels)[i].IsBad())
+            if ((*fBadPixels)[nidx].IsBad())
                 continue;
 
@@ -428,12 +443,22 @@
 
             //
-	    //The error is calculated as the quadratic sum of the errors
+	    // The error is calculated as the quadratic sum of the errors
 	    //
+            nphot[i]  += nratio*evtpix->GetNumPhotons();
             ped[i]    += nratio*nppix.GetMean();
-            nphot[i]  += nratio*evtpix->GetNumPhotons();
-            perr[i]   += Pow2(nratio*evtpix->GetErrorPhot());
-	    pedrms[i] += Pow2(nratio*nppix.GetRms());
+            perr[i]   += nratio*Pow2(evtpix->GetErrorPhot());
+	    pedrms[i] += nratio*Pow2(nppix.GetRms());
 
             num++;
+        }
+
+        if (num<2)
+        {
+            pix->SetPixelUnmapped();
+            nphot[i]  = 0;
+            ped[i]    = 0;
+            perr[i]   = 0;
+            pedrms[i] = 0;
+            continue;
         }
 
@@ -443,6 +468,6 @@
 	nphot[i] /= num*ratio;
         ped[i]   /= num*ratio;
-        perr[i]   = TMath::Sqrt(perr[i]/num)*ratio;
-        pedrms[i] = TMath::Sqrt(pedrms[i]/num)*ratio;
+        perr[i]   = TMath::Sqrt(perr[i]/(num*ratio));
+        pedrms[i] = TMath::Sqrt(pedrms[i]/(num*ratio));
 
     }
@@ -457,5 +482,5 @@
         // Do not use blind neighbors
         //
-        if ((*fBadPixels)[i].IsBad())
+        if ((*fBadPixels)[i].IsOK())
             continue;
 
@@ -466,12 +491,4 @@
         (*fPedPhot)[i].Set(ped[i], pedrms[i]);
     }
-
-    //
-    // Delete the intermediat arrays
-    //
-    delete nphot;
-    delete perr;
-    delete ped;
-    delete pedrms;
 }
 
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 3489)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 3490)
@@ -20,4 +20,6 @@
 
     Byte_t fFlags;       // flag for the method which is used
+    Byte_t fNumMinNeighbors;
+
 
     enum
@@ -50,4 +52,5 @@
         b ? SETBIT(fFlags, kUseCentralPixel) : CLRBIT(fFlags, kUseCentralPixel);
     }
+    void SetNumMinNeighbors(UShort_t num) { fNumMinNeighbors=num; }
 
 
