Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1465)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1466)
@@ -25,4 +25,25 @@
      - some changes to the layout
      - added support for the sign in MHHillasExt
+
+   * manalysis/MBlindPixelCalc.[h,cc]:
+     - added the possibility to use the interpolation of the
+       surrounding pixels
+     - clean the array with the blind pixel IDs at any ReInit
+
+   * manalysis/MBlindPixels.h:
+     - IsBlind now checks also for the validity of the array
+
+   * manalysis/MCerPhotPix.h:
+     - added Set-function
+
+   * manalysis/MHillas.cc:
+     - Don't ouput a warning if fSize==0 or fNumUsedPixels<0
+       (happens too often)
+
+   * manalysis/MCameraSmooth.[h,cc]:
+     - added
+
+   * manalysis/Makefile, manalysis/AnalysisLinkDef.h:
+     - added MCameraSmooth
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 1465)
+++ trunk/MagicSoft/Mars/NEWS	(revision 1466)
@@ -59,4 +59,9 @@
      MHillasExt are now scaled with the pixel size, so that one get
      a four times smaller value for the bigger pixels in the outer ring.
+
+   - added new task to smooth the camera (MCameraSmooth)
+
+   - added possibility to use interpolated pixel values for blind pixels
+     instead of removing it completely from the analysis
 
 
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1466)
@@ -7,9 +7,10 @@
 #pragma link C++ class MCerPhotPix+;
 #pragma link C++ class MCerPhotEvt+;
+#pragma link C++ class MCerPhotAnal+;
 #pragma link C++ class MCerPhotCalc+;
-#pragma link C++ class MCerPhotAnal+;
 #pragma link C++ class MCerPhotCalc2+;
 
 #pragma link C++ class MImgCleanStd+;
+#pragma link C++ class MCameraSmooth+;
 
 #pragma link C++ class MBlindPixels+;
Index: trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1466)
@@ -51,7 +51,11 @@
 
 #include "MParList.h"
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
 #include "MCerPhotPix.h"
 #include "MCerPhotEvt.h"
 #include "MBlindPixels.h"
+
 #include "MMcRunHeader.hxx"
 
@@ -63,5 +67,5 @@
 //
 MBlindPixelCalc::MBlindPixelCalc(const char *name, const char *title)
-
+    : fUseInterpolation(kFALSE), fUseCentralPixel(kFALSE)
 {
     fName  = name  ? name  : "MBlindPixelCalc";
@@ -85,7 +89,11 @@
     if (!fEvt)
     {
-        *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
+        *fLog << err << dbginf << "MCerPhotEvt not found... aborting." << endl;
         return kFALSE;
     }
+
+    fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fGeomCam)
+        *fLog << warn << dbginf << "No camera geometry available... can't ude interpolation." << endl;
 
     const UShort_t size = fPixelsID.GetSize();
@@ -112,12 +120,10 @@
 }
 
-
-// --------------------------------------------------------------------------
-//
-// Remove the pixels.
-//
-Bool_t MBlindPixelCalc::Process()
+void MBlindPixelCalc::Interpolate() const
 {
     const UShort_t entries = fEvt->GetNumPixels();
+
+    Double_t *nphot = new Double_t[entries];
+    Double_t *perr  = new Double_t[entries];
 
     //
@@ -129,7 +135,68 @@
         MCerPhotPix &pix = (*fEvt)[i];
 
-	if (fPixels->IsBlind(pix.GetPixId()))
+        const Int_t id = pix.GetPixId();
+
+        if (!fPixels->IsBlind(id))
+            continue;
+
+        const MGeomPix &gpix = (*fGeomCam)[id];
+
+        const Int_t n = gpix.GetNumNeighbors();
+
+        nphot[i] = fUseCentralPixel ? (*fEvt)[id].GetNumPhotons() : 0;
+        perr[i]  = fUseCentralPixel ? (*fEvt)[id].GetErrorPhot()  : 0;
+        for (int j=0; j<n; j++)
+        {
+            const UShort_t nid = gpix.GetNeighbor(j);
+
+            nphot[i] += (*fEvt)[nid].GetNumPhotons();
+            perr[i]  += (*fEvt)[nid].GetErrorPhot();
+        }
+
+        nphot[i] /= fUseCentralPixel ? n+1 : n;
+        perr[i]  /= fUseCentralPixel ? n+1 : n;
+    }
+
+    if (fUseInterpolation && fGeomCam)
+        for (UShort_t i=0; i<entries; i++)
+        {
+            MCerPhotPix &pix = (*fEvt)[i];
+
+            if (fPixels->IsBlind(pix.GetPixId()))
+                pix.Set(nphot[i], perr[i]);
+        }
+
+    delete nphot;
+    delete perr;
+}
+
+void MBlindPixelCalc::Unmap() const
+{
+    const UShort_t entries = fEvt->GetNumPixels();
+
+    //
+    // remove the pixels in fPixelsID if they are set to be used,
+    // (set them to 'unused' state)
+    //
+    for (UShort_t i=0; i<entries; i++)
+    {
+        MCerPhotPix &pix = (*fEvt)[i];
+
+        if (fPixels->IsBlind(pix.GetPixId()))
             pix.SetPixelUnused();
-    }
+
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Remove the pixels.
+//
+Bool_t MBlindPixelCalc::Process()
+{
+    if (fUseInterpolation && fGeomCam)
+        Interpolate();
+    else
+        Unmap();
 
     return kTRUE;
@@ -165,4 +232,9 @@
 
     //
+    // Delete the old array holding the blind pixels for the last file
+    //
+    fPixels->Clear();
+
+    //
     // Set as blind some particular pixels because of a particular
     // Star Field of View.
@@ -180,5 +252,5 @@
     {
         *fLog << warn << "Warning - Detected Starfield unknown..." << endl;
-        return kSKIP;
+        return kTRUE;
     }
 
@@ -186,5 +258,4 @@
     // Case for Crab Nebula FOV
     //
-    fPixels->Clear();
     fPixels->SetPixelBlind(400);
     fPixels->SetPixelBlind(401);
Index: trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h	(revision 1466)
@@ -10,4 +10,5 @@
 #endif
 
+class MGeomCam;
 class MCerPhotEvt;
 class MBlindPixels;
@@ -18,9 +19,19 @@
     MCerPhotEvt  *fEvt;     //!
     MBlindPixels *fPixels;  //!
+    MGeomCam     *fGeomCam; //!
 
     TArrayS fPixelsID;  // Pixel IDs for blind pixels, which are entered by the user.
 
+    Bool_t fUseInterpolation;
+    Bool_t fUseCentralPixel;
+
+    void Interpolate() const;
+    void Unmap() const;
+
 public:
     MBlindPixelCalc(const char *name=NULL, const char *title=NULL);
+
+    void SetUseInterpolation(Bool_t b=kTRUE) { fUseInterpolation=kTRUE; }
+    void SetUseCetralPixel(Bool_t b=kTRUE)   { fUseCentralPixel=kTRUE; }
 
     Bool_t PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/manalysis/MBlindPixels.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MBlindPixels.h	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/MBlindPixels.h	(revision 1466)
@@ -23,5 +23,5 @@
     void Clear(Option_t *o="")  { fPixels.Reset(); }
 
-    Bool_t IsBlind(UShort_t id) { return (Bool_t)fPixels[id]; }
+    Bool_t IsBlind(UShort_t id) { return fPixels.GetSize() && fPixels[id]; }
 
     ClassDef(MBlindPixels, 1) // container to store blind pixels
Index: trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1466)
+++ trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1466)
@@ -0,0 +1,135 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 08/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MCameraSmooth                                                          //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCameraSmooth.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+#include "MBlindPixels.h"
+
+#include "MMcRunHeader.hxx"
+
+ClassImp(MCameraSmooth);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MCameraSmooth::MCameraSmooth(Byte_t n, const char *name, const char *title)
+    : fCounts(n), fUseCentralPixel(kTRUE)
+{
+    fName  = name  ? name  : "MCameraSmooth";
+    fTitle = title ? title : "Task which removes a list of pixel from analysis";
+}
+
+// --------------------------------------------------------------------------
+//
+//  - Try to find or create MBlindPixels in parameter list.
+//  - get the MCerPhotEvt from the parlist (abort if missing)
+//  - if no pixels are given by the user try to determin the starfield
+//    from the monte carlo run header.
+//
+Bool_t MCameraSmooth::PreProcess (MParList *pList)
+{
+    fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
+    if (!fEvt)
+    {
+        *fLog << err << dbginf << "MCerPhotEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fGeomCam)
+    {
+        *fLog << warn << dbginf << "No camera geometry available... aborting." << endl;
+
+        return kFALSE;
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Remove the pixels.
+//
+Bool_t MCameraSmooth::Process()
+{
+    const UShort_t entries = fEvt->GetNumPixels();
+
+    //
+    // remove the pixels in fPixelsID if they are set to be used,
+    // (set them to 'unused' state)
+    //
+
+    Double_t *photons = new Double_t[entries];
+    Double_t *errors  = new Double_t[entries];
+
+    for (int n=0; n<fCounts; n++)
+    {
+        for (UShort_t i=0; i<entries; i++)
+        {
+            MCerPhotPix &pix = (*fEvt)[i];
+
+            const Int_t id = pix.GetPixId();
+
+            const MGeomPix &gpix = (*fGeomCam)[id];
+
+            const Int_t n = gpix.GetNumNeighbors();
+
+            photons[i] = fUseCentralPixel ? (*fEvt)[id].GetNumPhotons() : 0;
+            errors[i]  = fUseCentralPixel ? (*fEvt)[id].GetErrorPhot()  : 0;
+            for (int j=0; j<n; j++)
+            {
+                const UShort_t nid = gpix.GetNeighbor(j);
+
+                photons[i] += (*fEvt)[nid].GetNumPhotons();
+                errors[i]  += (*fEvt)[nid].GetErrorPhot();
+            }
+
+            photons[i] /= fUseCentralPixel ? n+1 : n;
+            errors[i]  /= fUseCentralPixel ? n+1 : n;
+        }
+
+        for (UShort_t i=0; i<entries; i++)
+            (*fEvt)[i].Set(photons[i], errors[i]);
+    }
+
+    delete photons;
+    delete errors;
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MCameraSmooth.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraSmooth.h	(revision 1466)
+++ trunk/MagicSoft/Mars/manalysis/MCameraSmooth.h	(revision 1466)
@@ -0,0 +1,37 @@
+#ifndef MARS_MCameraSmooth
+#define MARS_MCameraSmooth
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#ifndef ROOT_TArrayS
+#include <TArrayS.h>
+#endif
+
+class MGeomCam;
+class MCerPhotEvt;
+class MBlindPixels;
+
+class MCameraSmooth : public MTask
+{
+private:
+    MCerPhotEvt *fEvt;     //!
+    MGeomCam    *fGeomCam; //!
+
+    Byte_t fCounts;
+    Bool_t fUseCentralPixel;
+
+public:
+    MCameraSmooth(Byte_t cnt=1, const char *name=NULL, const char *title=NULL);
+
+    void SetUseCetralPixel(Bool_t b=kTRUE) { fUseCentralPixel=kTRUE; }
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MCameraSmooth, 0) // task to smooth the camera contants
+}; 
+
+#endif
+
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1466)
@@ -37,6 +37,7 @@
     Bool_t  IsPixelCore() const      { return fIsCore;  }
 
-    void    SetNumPhotons(Float_t f) { fPhot    = f; }
-    void    SetErrorPhot(Float_t f)  { fErrPhot = f; }
+    void    SetNumPhotons(Float_t f)    { fPhot    = f; }
+    void    SetErrorPhot(Float_t f)     { fErrPhot = f; }
+    void    Set(Float_t np, Float_t ep) { fPhot = np; fErrPhot = ep; }
 
     void    Print(Option_t *opt = NULL) const;
Index: trunk/MagicSoft/Mars/manalysis/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1466)
@@ -279,5 +279,5 @@
     if (fSize==0)
     {
-        *fLog << warn << GetDescriptor() << ": Event has zero cerenkov photons... skipped." << endl;
+        //*fLog << inf << GetDescriptor() << ": Event has zero cerenkov photons... skipped." << endl;
         return kFALSE;
     }
@@ -285,5 +285,5 @@
     if (fNumUsedPixels<3)
     {
-        *fLog << warn << GetDescriptor() << ": Event has less than 3 used pixels... skipped." << endl;
+        //*fLog << inf << GetDescriptor() << ": Event has less than 3 used pixels... skipped." << endl;
         return kFALSE;
     }
@@ -327,9 +327,12 @@
     // If corrxy=0 (which should never happen, because fSize>0) we
     // cannot calculate Length and Width. The calculation failed
-    // and returnes kFALSE
+    // and returns kFALSE
+    // In reallity it is almost impossible to have a distribution
+    // of cerenkov photons in the used pixels which is exactly symmetric
+    // along one of the axis.
     //
     if (corrxy==0)
     {
-        *fLog << warn << GetDescriptor() << ": Event has CorrXY==0... skipped." << endl;
+        *fLog << inf << GetDescriptor() << ": Event has CorrXY==0... skipped." << endl;
         return kFALSE;
     }
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1465)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1466)
@@ -37,4 +37,5 @@
            MEnergyEstimate.cc \
            MSrcPosCam.cc \
+           MCameraSmooth.cc \
            MHadroness.cc \
            MCompProbCalc.cc \
