Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 5717)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 5728)
@@ -67,4 +67,5 @@
 
 #include <TEnv.h>
+#include <TObjString.h>
 
 #include "MArrayD.h" // Used instead of TArrayD because operator[] has no range check
@@ -101,5 +102,5 @@
 //
 MBadPixelsTreat::MBadPixelsTreat(const char *name, const char *title)
-  : fFlags(0), fNumMinNeighbors(3), fNamePedPhotCam("MPedPhotCam")
+  : fFlags(0), fNumMinNeighbors(3)
 {
     fName  = name  ? name  : gsDefName.Data();
@@ -123,4 +124,9 @@
 }
 
+void MBadPixelsTreat::AddNamePedPhotCam(const char *name)
+{
+    fNamePedPhotCams.Add(new TObjString(name));
+}
+
 // --------------------------------------------------------------------------
 //
@@ -159,15 +165,37 @@
     }
 
-    fPedPhot = 0;
-    if (IsProcessPedestalEvt() || IsProcessPedestalRun())
-    {
-        fPedPhot = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
-        if (!fPedPhot)
-        {
-            *fLog << err << AddSerialNumber("MPedPhotCam") << " not found... aborting." << endl;
-            *fLog << " Use  MBadPixelsTreat::SetProcessPedestalRun(kFALSE)  and" << endl;
-            *fLog << " MBadPixelsTreat::SetProcessPedestalEvt(kFALSE) to switch" << endl;
-            *fLog << " Pedestal treatment off." << endl;
-            return kFALSE;
+    const Bool_t proc = IsProcessPedestalEvt() || IsProcessPedestalRun();
+
+    if (fNamePedPhotCams.GetSize()>0 && !proc)
+    {
+        *fLog << err << "Pedestal list contains entries, but pedestal treatment is switched off... abort." << endl;
+        return kFALSE;
+    }
+
+    if (proc)
+    {
+        if (fNamePedPhotCams.GetSize()==0)
+        {
+            *fLog << inf << "No container names specified... using default: MPedPhotCam." << endl;
+            AddNamePedPhotCam();
+        }
+
+        fPedPhotCams.Clear();
+
+        TIter Next(&fNamePedPhotCams);
+        TObject *o=0;
+        while ((o=Next()))
+        {
+            TObject *p = pList->FindObject(AddSerialNumber(o->GetName()), "MPedPhotCam");
+            if (!p)
+            {
+                *fLog << err << AddSerialNumber(o->GetName()) << " [MPedPhotCam] not found... aborting." << endl;
+                //*fLog << " Use  MBadPixelsTreat::SetProcessPedestalRun(kFALSE)  and" << endl;
+                //*fLog << " MBadPixelsTreat::SetProcessPedestalEvt(kFALSE) to switch" << endl;
+                //*fLog << " Pedestal treatment off." << endl;
+                return kFALSE;
+            }
+
+            fPedPhotCams.Add(p);
         }
     }
@@ -313,7 +341,7 @@
 // --------------------------------------------------------------------------
 //
-void MBadPixelsTreat::InterpolatePedestals() const
-{
-    const Int_t entries = fPedPhot->GetSize();
+void MBadPixelsTreat::InterpolatePedestals(MPedPhotCam &pedphot) const
+{
+    const Int_t entries = pedphot.GetSize();
 
     // Create arrays (FIXME: Check if its possible to create it only once)
@@ -336,5 +364,5 @@
         //
         const MGeomPix    &gpix = (*fGeomCam)[i];
-        const MPedPhotPix &ppix = (*fPedPhot)[i];
+        const MPedPhotPix &ppix = pedphot[i];
 
         // Do Not-Use-Central-Pixel
@@ -372,5 +400,5 @@
             //
             const Double_t    nratio = fGeomCam->GetPixRatio(nidx);
-            const MPedPhotPix &nppix = (*fPedPhot)[nidx];
+            const MPedPhotPix &nppix = pedphot[nidx];
 
             //
@@ -402,5 +430,21 @@
         rms[i]  = TMath::Sqrt(rms[i]/(num*ratio));
 
-        (*fPedPhot)[i].Set(ped[i], rms[i]);
+        pedphot[i].Set(ped[i], rms[i]);
+    }
+    pedphot.SetReadyToSave();
+}
+
+// --------------------------------------------------------------------------
+//
+// loop over all MPedPhotCam and interpolate them
+//
+void MBadPixelsTreat::InterpolatePedestals() const
+{
+    TIter Next(&fPedPhotCams);
+    MPedPhotCam *cam=0;
+    while ((cam=(MPedPhotCam*)Next()))
+    {
+        InterpolatePedestals(*cam);
+        cam->ReCalc(*fGeomCam, fBadPixels);
     }
 }
@@ -427,5 +471,5 @@
         const Int_t n0 = gpix.GetNumNeighbors();
 
-        MArrayD time(6);
+        MArrayD time(n0);
         for (int j=0; j<n0; j++)
             time[j] = (*fTimes)[gpix.GetNeighbor(j)];
@@ -436,13 +480,13 @@
         Double_t min=FLT_MAX;
         for (int j=0; j<n0; j++)
-            for (int k=1; k<j+1; k++)
+            for (int k=0; k<j; k++)
             {
-                const Double_t diff = TMath::Abs(time[n0-k] - time[n0-k-j]);
+                const Double_t diff = TMath::Abs(time[j] - time[k]);
 
                 if (diff>=min && diff<250)
                     continue;
 
-                p0 = n0-k;
-                p1 = n0-k-j;
+                p0  = j;
+                p1  = k;
                 min = diff;
             }
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 5717)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 5728)
@@ -16,13 +16,16 @@
 private:
     MGeomCam      *fGeomCam;   //!
-    MPedPhotCam   *fPedPhot;   //!
+    //MPedPhotCam   *fPedPhot;   //!
     MCerPhotEvt   *fEvt;       //!
     MArrivalTime  *fTimes;     //!
     MBadPixelsCam *fBadPixels; //!
 
+    TList fPedPhotCams;
+
     Byte_t fFlags;       // flag for the method which is used
     Byte_t fNumMinNeighbors;
 
-    TString fNamePedPhotCam; // name of the 'MPedPhotCam' container
+    //TString fNamePedPhotCam; // name of the 'MPedPhotCam' container
+    TList fNamePedPhotCams;
 
     enum
@@ -40,4 +43,5 @@
     void InterpolateTimes() const;
     void InterpolateSignal() const;
+    void InterpolatePedestals(MPedPhotCam &pedphot) const;
     void InterpolatePedestals() const;
 
@@ -92,5 +96,9 @@
 
     void SetNumMinNeighbors(Byte_t num) { fNumMinNeighbors=num; }
-    void SetNamePedPhotCam(const char *name)    { fNamePedPhotCam = name; }
+    void AddNamePedPhotCam(const char *name="MPedPhotCam");
+    void SetNamePedPhotCam(const char *name)
+    {
+        AddNamePedPhotCam(name);
+    } // Deprecated! Use AddNamePedPhotCam instead (directly)
 
     ClassDef(MBadPixelsTreat, 1) // Task to treat bad pixels (interpolation, unmapping)
