Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4701)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4702)
@@ -34,4 +34,34 @@
    * mimage/MHHillas.[h,cc]:
      - added display of camera on top of MeanXY-plot
+
+   * mraw/MRawSocketRead.h:
+     - added GetFileName()
+
+   * manalysis/MCerPhotEvt.[h,cc]:
+     - added new data member fNumIslands
+     - added new functions (CalcIsland/CalcIslands to calculate islands)
+     - added new member function to sort pixels by index
+     - added island index in GetPixelContent
+     - increased version number
+
+   * manalysis/MCerPhotPix.[h,cc]:
+     - added fIdxIsland data member
+     - overloaded Compare function to be able to sort by pixel index
+     - increased version number
+
+   * mhist/MHEvent.[h,cc]:
+     - added new option for island index
+
+   * mimage/MImgCleanStd.[h,cc]:
+     - added island calculation after image cleaning
+     - fixed some output to be consistent
+     - added ReadEnv
+     - updated StreamPrimitive
+
+   * mimage/Makefile:
+     - added mhist
+
+   * mmain/MEventDisplay.cc:
+     - added display of island index
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 4701)
+++ trunk/MagicSoft/Mars/NEWS	(revision 4702)
@@ -16,4 +16,7 @@
 
    - Implemented automatic file splitting in MWriteRootFile
+
+   - After image cleaning an island index is assigned to all used pixels.
+     The index corresponds to the order of the islands in size.
 
 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 4701)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 4702)
@@ -31,4 +31,8 @@
 //       risk!
 //
+// Class Version 3:
+// ----------------
+//  - added fNumIslands
+//            
 // Class Version 2:
 // ----------------
@@ -46,4 +50,5 @@
 #include <fstream>
 
+#include <TArrayD.h>
 #include <TCanvas.h>
 
@@ -52,4 +57,5 @@
 
 #include "MGeomCam.h"
+#include "MGeomPix.h"
 
 ClassImp(MCerPhotEvt);
@@ -96,6 +102,7 @@
 void MCerPhotEvt::Reset()
 {
-    fNumPixels =  0;
-    fMaxIndex  = -1;
+    fNumPixels  =  0;
+    fMaxIndex   = -1;
+    fNumIslands = -1;
     fLut.Set(0);
     // fPixels->Delete();
@@ -346,13 +353,27 @@
 void MCerPhotEvt::RemoveUnusedPixels()
 {
+    // Create iterator
     TIter Next(fPixels);
     MCerPhotPix *pix = NULL;
 
+    fMaxIndex = -1;
+
+    // Remove all unused pixels from list, calculate new fMaxIndex
     while ((pix=(MCerPhotPix*)Next()))
+    {
         if (!pix->IsPixelUsed())
             fPixels->Remove(pix);
-
+        else
+            fMaxIndex = TMath::Max(fMaxIndex, pix->GetPixId());
+    }
+
+    // Crompress array
     fPixels->Compress();
+
+    // Get new number of entries in array
     fNumPixels=fPixels->GetEntriesFast();
+
+    // Rebuild lookup table
+    RebuildLut();
 }
 
@@ -409,4 +430,145 @@
 // --------------------------------------------------------------------------
 //
+// This function recursively finds all pixels of one island and assigns
+// the number num as island number to the pixel.
+//
+//  1) Check whether a pixel with the index idx exists, is unused
+//     and has not yet a island number assigned.
+//  2) Assign the island number num to the pixel
+//  3) Loop over all its neighbors taken from the geometry geom. For all
+//     neighbors recursively call this function (CalcIsland)
+//  4) Sum the size of the pixel and all neighbors newly assigned
+//     (by CalcIsland) to this island
+//
+// Returns the sum of the pixel size.
+//
+Double_t MCerPhotEvt::CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num)
+{
+    // Try to get the pixel information of a pixel with this index
+    MCerPhotPix *pix = GetPixById(idx);
+
+    // If a pixel with this index is not existing... do nothing.
+    if (!pix)
+        return 0;
+
+    // If an island number was already assigned to this pixel... do nothing.
+    if (pix->GetIdxIsland()>=0)
+        return 0;
+
+    // If the pixel is an unused pixel... do nothing.
+    if (!pix->IsPixelUsed())
+        return 0;
+
+    // Assign the new island number num to this used pixel
+    pix->SetIdxIsland(num);
+
+    // Get the geometry information (neighbors) of this pixel
+    const MGeomPix &gpix = geom[idx];
+
+    // Get the size of this pixel
+    Double_t size = pix->GetNumPhotons();
+
+    // Now do the same with all its neighbors and sum the
+    // sizes which they correspond to
+    const Int_t n = gpix.GetNumNeighbors();
+    for (int i=0; i<n; i++)
+        size += CalcIsland(geom, gpix.GetNeighbor(i), num);
+
+    // return size of this (sub)cluster
+    return size;
+}
+
+// --------------------------------------------------------------------------
+//
+// Each pixel which is maked as used is assigned an island number
+// (starting from 0). A pixel without an island number assigned
+// has island number -1.
+//
+// The index 0 corresponds to the island with the highest size (sum
+// of GetNumPhotons() in island). The size is decreasing with
+// increasing indices.
+//
+// The information about pixel neighbory is taken from the geometry
+// MGeomCam geom;
+//
+// You can access this island number of a pixel with a call to
+// MCerPhotPix->GetIdxIsland. The total number of islands available
+// can be accessed with MCerPhotEvt->GetNumIslands.
+//
+// CalcIslands returns the number of islands found. If an error occurs,
+// eg the geometry has less pixels than the highest index stored, -1 is
+// returned.
+//
+Int_t MCerPhotEvt::CalcIslands(const MGeomCam &geom)
+{
+    if (fMaxIndex<0 || fNumPixels<=0)
+    {
+        *fLog << err << "ERROR - MCerPhotEvt doesn't contain pixels!" << endl;
+        fNumIslands = 0;
+        return -1;
+    }
+
+    if ((UInt_t)fMaxIndex>=geom.GetNumPixels())
+    {
+        *fLog << err << "ERROR - MCerPhotEvt::CalcIslands: Size mismatch - geometry too small!" << endl;
+        return -1;
+    }
+
+    // Create a list to hold the sizes of the islands (The maximum
+    // number of islands possible is rougly fNumPixels/4)
+    TArrayD size(fNumPixels/3);
+
+    // Calculate Islands
+    Int_t n=0;
+
+    // We could loop over all indices which looks more straight
+    // forward but should be a lot slower (assuming zero supression)
+    MCerPhotPix *pix=0;
+
+    TIter Next(*this);
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+    {
+        // This 'if' is necessary (although it is done in GetIsland, too)
+        // because otherwise the counter (n) would be wrong.
+        // So only 'start' a new island for used pixels (selected by
+        // using the Iterator) which do not yet belong to another island.
+        if (pix->GetIdxIsland()<0)
+        {
+            Double_t sz = CalcIsland(geom, pix->GetPixId(), n);
+            size[n++] = sz;
+        }
+    }
+
+    // Create an array holding the indices
+    TArrayI idx(n);
+
+    // Sort the sizes descending
+    TMath::Sort(n, size.GetArray(), idx.GetArray(), kTRUE);
+
+    // Replace island numbers by size indices -- After this
+    // islands indices are sorted by the island size
+    Next.Reset();
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+    {
+        const Short_t i = pix->GetIdxIsland();
+
+        // Find new index
+        Short_t j;
+        for (j=0; j<n; j++)
+            if (idx[j]==i)
+                break;
+
+        pix->SetIdxIsland(j==n ? -1 : j);
+    }
+
+    // Now assign number of islands found
+    fNumIslands = n;
+
+    // return number of island
+    return fNumIslands;
+}
+
+// --------------------------------------------------------------------------
+//
 // Returns, depending on the type flag:
 //
@@ -416,4 +578,5 @@
 //  3: Number of Photons
 //  4: Error
+//  5: Island index
 //
 Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
@@ -442,4 +605,7 @@
         val = pix->GetErrorPhot();
         break;
+    case 5:
+        val = pix->GetIdxIsland();
+        break;
     default:
         val = pix->GetNumPhotons()*ratio;
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 4701)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 4702)
@@ -24,7 +24,26 @@
 private:
     UInt_t        fNumPixels;
+    Short_t       fNumIslands;
      Int_t        fMaxIndex;
     TArrayI       fLut;        // Lookup tabel to lookup pixel by index
     TClonesArray *fPixels;     //-> FIXME: Change TClonesArray away from a pointer?
+
+    void RebuildLut()
+    {
+        // Resize Lut
+        fLut.Set(fMaxIndex+1);
+
+        // Reset Lut
+        fLut.Reset(-1);
+
+        // Rebuild Lut
+        for (UInt_t i=0; i<GetNumPixels(); i++)
+        {
+            const MCerPhotPix &pix = (*this)[i];
+            fLut[pix.GetPixId()] = i;
+        }
+    }
+
+    Double_t CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num);
 
 public:
@@ -32,10 +51,11 @@
     ~MCerPhotEvt() { delete fPixels; }
 
-    UInt_t GetNumPixels() const { return fNumPixels; }
-    //void   InitSize(UInt_t num) { fPixels->Expand(num); }
+    // Setter function to fill pixels
+    MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);
+    void FixSize();
 
-    MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);
-
-    void FixSize();
+    // Getter functions
+    UInt_t  GetNumPixels() const { return fNumPixels; }
+    Short_t GetNumIslands() const { return fNumIslands; };
 
     Bool_t  IsPixelExisting(Int_t id) const;
@@ -52,14 +72,25 @@
     Float_t GetErrorPhotMax(const MGeomCam *geom=NULL) const;
 
+    // Getter functions to access single pixels
     MCerPhotPix &operator[](int i)       { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
     MCerPhotPix &operator[](int i) const { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
 
+    MCerPhotPix *GetPixById(Int_t idx) const;
+
+    // Functions to change the contained data
     void Scale(Double_t f) { fPixels->ForEach(MCerPhotPix, Scale)(f); }
     void RemoveUnusedPixels();
+    Int_t CalcIslands(const MGeomCam &geom);
+    void Sort(Int_t upto = kMaxInt)
+    {
+        // Sort pixels by index
+        fPixels->Sort(upto);
+        RebuildLut();
+    } // For convinience: Sort pixels by index
 
-    MCerPhotPix *GetPixById(Int_t idx) const;
-
+    // class MParContainer
     void Reset();
 
+    // class TObject
     void Print(Option_t *opt=NULL) const;
     void Clear(Option_t *opt=NULL) { Reset(); }
@@ -69,4 +100,5 @@
     void DrawPixelContent(Int_t num) const;
 
+    // To build an iterator for this class
     operator TIterator*() const;
 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc	(revision 4701)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc	(revision 4702)
@@ -45,4 +45,8 @@
 //  - added fIsHGSaturated
 //
+// Version 5:
+// ----------
+//  - added fIdxIsland
+//
 ////////////////////////////////////////////////////////////////////////////
 #include "MCerPhotPix.h"
@@ -60,8 +64,25 @@
 //
 MCerPhotPix::MCerPhotPix(Int_t pix, Float_t phot, Float_t errphot) :
-    fPixId(pix), fRing(1), fIsCore(kFALSE), fPhot(phot), fErrPhot(errphot), 
+    fPixId(pix), fIsCore(kFALSE), fRing(1), fIdxIsland(-1),
+    fPhot(phot), fErrPhot(errphot),
     fIsSaturated(kFALSE), fIsHGSaturated(kFALSE)
 {
 } 
+
+// --------------------------------------------------------------------------
+//
+// From TObject:
+//  Compare abstract method. Must be overridden if a class wants to be able
+//  to compare itself with other objects. Must return -1 if this is smaller
+//  than obj, 0 if objects are equal and 1 if this is larger than obj.
+//
+// Here:
+//  Index numbers are compared
+//
+Int_t MCerPhotPix::Compare(const TObject *o) const
+{
+    const Int_t diff = fPixId - static_cast<const MCerPhotPix*>(o)->fPixId;
+    return diff==0 ? 0 : TMath::Sign(1, diff);
+}
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 4701)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 4702)
@@ -12,6 +12,7 @@
     Int_t    fPixId;     // the pixel Id
 
-   Short_t fRing;      // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters)
-    Bool_t   fIsCore;    // the pixel is a Core pixel -> kTRUE
+    Bool_t   fIsCore;     // the pixel is a Core pixel -> kTRUE
+    Short_t  fRing;       // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters)
+    Short_t  fIdxIsland;  // the pixel is a Core pixel -> kTRUE
 
     Float_t  fPhot;      // The number of Cerenkov photons
@@ -26,37 +27,41 @@
     MCerPhotPix(Int_t pix=-1, Float_t phot=0, Float_t errphot=0);
 
-    Int_t    GetPixId() const            { return fPixId;   }
-    Float_t  GetNumPhotons() const       { return fPhot;    }
-    Float_t  GetErrorPhot() const        { return fErrPhot; }
+    Int_t   GetPixId() const            { return fPixId;   }
+    Float_t GetNumPhotons() const       { return fPhot;    }
+    Float_t GetErrorPhot() const        { return fErrPhot; }
     
-    Bool_t   IsPixelUsed() const         { return fRing>0; }
-    Bool_t   IsPixelUnmapped() const     { return fRing==-1; }
-    void     SetPixelUnused()            { fRing=0; }
-    void     SetPixelUsed()              { fRing=1; }
-    void     SetPixelUnmapped()          { fRing=-1;}
+    Bool_t  IsPixelUsed() const         { return fRing>0; }
+    Bool_t  IsPixelUnmapped() const     { return fRing==-1; }
+    void    SetPixelUnused()            { fRing=0; }
+    void    SetPixelUsed()              { fRing=1; }
+    void    SetPixelUnmapped()          { fRing=-1;}
+    void    SetIdxIsland(Short_t num)   { fIdxIsland=num; }
+    Short_t GetIdxIsland() const        { return fIdxIsland; }
 
-    void     SetRing(UShort_t r)         { fRing = r;   }
-    Short_t  GetRing() const             { return fRing;}
+    void    SetRing(UShort_t r)         { fRing = r;   }
+    Short_t GetRing() const             { return fRing;}
 
-    void     SetPixelCore()              { fIsCore = kTRUE; }
-    Bool_t   IsPixelCore() const         { return fIsCore;  }
+    void    SetPixelCore()              { fIsCore = kTRUE; }
+    Bool_t  IsPixelCore() const         { return fIsCore;  }
 
-    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    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     SetPixelSaturated()         { fIsSaturated = kTRUE; }
-    Bool_t   IsPixelSaturated() const    { return fIsSaturated; }
+    void    SetPixelSaturated()         { fIsSaturated = kTRUE; }
+    Bool_t  IsPixelSaturated() const    { return fIsSaturated; }
 
-    void     SetPixelHGSaturated()         { fIsHGSaturated = kTRUE; }
-    Bool_t   IsPixelHGSaturated() const    { return fIsHGSaturated; }
+    void    SetPixelHGSaturated()       { fIsHGSaturated = kTRUE; }
+    Bool_t  IsPixelHGSaturated() const  { return fIsHGSaturated; }
 
-    void     AddNumPhotons(Float_t f)    { fPhot += f; }
+    void    AddNumPhotons(Float_t f)    { fPhot += f; }
 
-    void     Scale(Float_t f)            { fPhot/=f; }
+    void    Scale(Float_t f)            { fPhot/=f; }
 
-    void     Print(Option_t *opt = NULL) const;
+    void    Print(Option_t *opt = NULL) const;
+    Int_t   Compare(const TObject *obj) const;
+    Bool_t  IsSortable() const { return kTRUE; }
 
-    ClassDef(MCerPhotPix, 4)  // class containing information about the Cerenkov Photons in a pixel
+    ClassDef(MCerPhotPix, 5)  // class containing information about the Cerenkov Photons in a pixel
 };
 
Index: trunk/MagicSoft/Mars/mhist/MHEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 4701)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 4702)
@@ -96,6 +96,6 @@
     fMcEvt       = (MMcEvt*)plist->FindObject("MMcEvt");
 
-     fRawEvtData = (MRawEvtData*)plist->FindObject("MRawEvtData");
-     if (!fRawEvtData)
+    fRawEvtData = (MRawEvtData*)plist->FindObject("MRawEvtData");
+    if (!fRawEvtData)
         *fLog << warn << "MRawEvtData not found..." << endl;
 
@@ -165,4 +165,9 @@
         fHist->SetName("Triggered pix");
         fHist->SetYTitle("ON/OFF");
+        fHist->SetPrettyPalette();
+        break;
+     case kEvtIslandIndex:
+        fHist->SetName("Island Index");
+        fHist->SetYTitle("Index");
 	fHist->SetPrettyPalette();
         break;
@@ -224,4 +229,7 @@
     case kEvtTrigPix:
         fHist->SetCamContent(*event, 0);
+        break; 
+    case kEvtIslandIndex:
+        fHist->SetCamContent(*event, 5);
         break; 
     }
Index: trunk/MagicSoft/Mars/mhist/MHEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 4701)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 4702)
@@ -22,5 +22,5 @@
         kEvtSignalRaw, kEvtSignalDensity, kEvtPedestal, 
         kEvtPedestalRMS, kEvtRelativeSignal, kEvtCleaningLevels,
-        kEvtIdxMax, kEvtArrTime, kEvtTrigPix 
+        kEvtIdxMax, kEvtArrTime, kEvtTrigPix, kEvtIslandIndex
     };
 
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 4701)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 4702)
@@ -250,4 +250,6 @@
 #include <fstream>        // ofstream, SavePrimitive
 
+#include <TEnv.h>
+
 #include <TGFrame.h>      // TGFrame
 #include <TGLabel.h>      // TGLabel
@@ -279,4 +281,6 @@
 static const TString gsDefName  = "MImgCleanStd";
 static const TString gsDefTitle = "Task to perform image cleaning";
+
+const TString MImgCleanStd::gsNamePedPhotCam="MPedPhotCam"; // default name of the 'MPedPhotCam' container
 
 // --------------------------------------------------------------------------
@@ -291,5 +295,5 @@
                            const char *name, const char *title)
     : fCleaningMethod(kStandard), fCleanLvl1(lvl1),
-      fCleanLvl2(lvl2), fCleanRings(1), fNamePedPhotContainer("MPedPhotCam")
+      fCleanLvl2(lvl2), fCleanRings(1), fNamePedPhotCam(gsNamePedPhotCam)
 
 {
@@ -499,5 +503,5 @@
     if (!fCam)
     {
-        *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
+        *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
         return kFALSE;
     }
@@ -506,14 +510,18 @@
     if (!fEvt)
     {
-        *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
+        *fLog << err << "MCerPhotEvt not found... aborting." << endl;
         return kFALSE;
     }
 
-    fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotContainer), "MPedPhotCam");
+    fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
     if (!fPed)
     {
-        *fLog << dbginf << "MPedPhotCam not found... aborting." << endl;
+        *fLog << err << "MPedPhotCam not found... aborting." << endl;
         return kFALSE;
     }
+
+    fTime = (MArrivalTime*)pList->FindObject(AddSerialNumber("MArrivalTime"));
+    if (!fTime && fCleaningMethod==kProbability)
+        *fLog << warn << "MArrivalTime not found... probability cleaning done with signal only!" << endl;
 
     fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
@@ -541,4 +549,10 @@
         fData->CalcCleaningLevelDemocratic(*fEvt, *fPed, *fCam);
         break;
+        /*
+    case kProbability:
+        fData->CalcCleaningProbability(*fEvt, *fPed, *fCam, fTime);
+        break;*/
+    default:
+        break;
     }
 
@@ -556,11 +570,18 @@
     // For speed reasons skip the rest of the cleaning if no
     // action will be taken!
-    if (fCleanLvl1<=fCleanLvl2)
-        return kTRUE;
-
+    if (fCleanLvl1>fCleanLvl2)
+    {
 #ifdef DEBUG
-    *fLog << all << "CleanStep 3" << endl;
+        *fLog << all << "CleanStep 3" << endl;
 #endif
-    CleanStep3();
+        CleanStep3();
+    }
+
+#ifdef DEBUG
+        *fLog << all << "Calc Islands" << endl;
+#endif
+    // Takes roughly 10% of the time
+    fEvt->CalcIslands(*fCam);
+
 #ifdef DEBUG
     *fLog << all << "Done." << endl;
@@ -587,4 +608,7 @@
     case kScaled:
         *fLog << "scaled";
+        break;
+    case kProbability:
+        *fLog << "probability";
         break;
     }
@@ -711,12 +735,66 @@
     out << ");" << endl;
 
-    if (fCleaningMethod!=kDemocratic)
-        return;
-
-    out << "   " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
-
-    if (fCleanRings==1)
-        return;
-
-    out << "   " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
-}
+    if (fCleaningMethod!=kStandard)
+    {
+        out << "   " << GetUniqueName() << ".SetMethod(MImgCleanStd::k";
+        switch (fCleaningMethod)
+        {
+        case kScaled:      out << "Scaled";      break;
+        case kDemocratic:  out << "Democratic";  break;
+        case kProbability: out << "Probability"; break;
+        default:
+            break;
+        }
+        out << ");" << endl;
+    }
+    if (fCleanRings!=1)
+        out << "   " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
+
+    if (gsNamePedPhotCam!=fNamePedPhotCam)
+        out << "   " << GetUniqueName() << ".SetNamePedPhotCam(\"" << fNamePedPhotCam << "\");" << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Read the setup from a TEnv, eg:
+//   MImgCleanStd.CleanLevel1: 3.0
+//   MImgCleanStd.CleanLevel2: 2.5
+//   MImgCleanStd.CleanMethod: Standard, Scaled, Democratic, Probability
+//   MImgCleanStd.CleanRings:  1
+//
+Int_t MImgCleanStd::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "CleanRings", print))
+    {
+        rc = kTRUE;
+        SetCleanRings(GetEnvValue(env, prefix, "CleanRings", fCleanRings));
+    }
+    if (IsEnvDefined(env, prefix, "CleanLevel1", print))
+    {
+        rc = kTRUE;
+        fCleanLvl1 = GetEnvValue(env, prefix, "CleanLevel1", fCleanLvl1);
+    }
+    if (IsEnvDefined(env, prefix, "CleanLevel2", print))
+    {
+        rc = kTRUE;
+        fCleanLvl2 = GetEnvValue(env, prefix, "CleanLevel2", fCleanLvl2);
+    }
+
+    if (IsEnvDefined(env, prefix, "CleanMethod", print))
+    {
+        rc = kTRUE;
+        TString s = GetEnvValue(env, prefix, "CleanMethod", "");
+        s.ToLower();
+        if (s.BeginsWith("standard"))
+            SetMethod(kStandard);
+        if (s.BeginsWith("scaled"))
+            SetMethod(kScaled);
+        if (s.BeginsWith("democratic"))
+            SetMethod(kDemocratic);
+        if (s.BeginsWith("probability"))
+            SetMethod(kProbability);
+    }
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 4701)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 4702)
@@ -11,4 +11,5 @@
 class MCerPhotEvt;
 class MPedPhotCam;
+class MArrivalTime;
 class MCameraData;
 
@@ -21,29 +22,33 @@
         kStandard,
         kScaled,
-        kDemocratic
+        kDemocratic,
+        kProbability
     } CleaningMethod_t;
 
 private:
-    const MGeomCam    *fCam;  //!
-          MCerPhotEvt *fEvt;  //!
-          MPedPhotCam *fPed;  //!
-          MCameraData *fData; //!
+    static const TString gsNamePedPhotCam; // default name of the 'MPedPhotCam' container
+
+    const MGeomCam     *fCam;  //!
+          MCerPhotEvt  *fEvt;  //!
+          MPedPhotCam  *fPed;  //!
+          MArrivalTime *fTime; //!
+          MCameraData  *fData; //!
 
     CleaningMethod_t fCleaningMethod;
 
-    Float_t fCleanLvl1;
-    Float_t fCleanLvl2;
+    Float_t  fCleanLvl1;
+    Float_t  fCleanLvl2;
 
     UShort_t fCleanRings;
 
-    Float_t fInnerNoise;      //!
-    TString fNamePedPhotContainer; // name of the 'MPedPhotCam' container
+    TString  fNamePedPhotCam; // name of the 'MPedPhotCam' container
 
 
-    void CreateGuiElements(MGGroupFrame *f);
-    void StreamPrimitive(ofstream &out) const;
+    void  CreateGuiElements(MGGroupFrame *f);
+    void  StreamPrimitive(ofstream &out) const;
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
-    void   CleanStep3b(MCerPhotPix &pix);
-    void   CleanStep4(UShort_t r, MCerPhotPix &pix);
+    void  CleanStep3b(MCerPhotPix &pix);
+    void  CleanStep4(UShort_t r, MCerPhotPix &pix);
 
     void  CleanStep1();
@@ -56,5 +61,5 @@
 public:
     MImgCleanStd(const Float_t lvl1=3.0, const Float_t lvl2=2.5,
-              const char *name=NULL, const char *title=NULL);
+                 const char *name=NULL, const char *title=NULL);
     void Print(Option_t *o="") const;
 
@@ -67,5 +72,5 @@
 
     Bool_t ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2);
-    void SetNamePedPhotContainer(const char *name)    { fNamePedPhotContainer = name; }
+    void SetNamePedPhotCam(const char *name)  { fNamePedPhotCam = name; }
 
     ClassDef(MImgCleanStd, 2)    // task doing the image cleaning
Index: trunk/MagicSoft/Mars/mimage/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mimage/Makefile	(revision 4701)
+++ trunk/MagicSoft/Mars/mimage/Makefile	(revision 4702)
@@ -20,5 +20,9 @@
 #
 INCLUDES = -I. -I../mbase -I../mhbase -I../mgeom -I../manalysis \
-	   -I../mgui -I../mmc -I../mpointing -I../mpedestal
+	   -I../mgui -I../mmc -I../mpointing -I../mpedestal \
+           -I../mhist
+
+# mhist: MHHillas (MHCamera)
+
 
 SRCFILES = MImgCleanStd.cc \
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 4701)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 4702)
@@ -215,48 +215,52 @@
     fEvtLoop->SetParList(plist);
 
-    MHEvent *evt1 = new MHEvent(MHEvent::kEvtSignalRaw);
-    MHEvent *evt2 = new MHEvent(MHEvent::kEvtSignalRaw);
-    MHEvent *evt3 = new MHEvent(MHEvent::kEvtPedestal);
-    MHEvent *evt4 = new MHEvent(MHEvent::kEvtPedestalRMS);
-    MHEvent *evt5 = new MHEvent(MHEvent::kEvtRelativeSignal);
-    MHEvent *evt6 = new MHEvent(MHEvent::kEvtCleaningLevels);
-    MHEvent *evt7 = new MHEvent(MHEvent::kEvtIdxMax);
-    MHEvent *evt8 = new MHEvent(MHEvent::kEvtArrTime);
-    MHEvent *evt9 = new MHEvent(MHEvent::kEvtTrigPix);
-
-    evt1->SetName("Signal");
-    evt2->SetName("Cleaned");
-    evt3->SetName("Pedestal");
-    evt4->SetName("PedRMS");
-    evt5->SetName("Signal/PedRMS");
-    evt6->SetName("CleanLevels");
-    evt7->SetName("Max Slice Idx");
-    evt8->SetName("Arrival Time");
-    evt9->SetName("Trigger");
+    MHEvent *evt01 = new MHEvent(MHEvent::kEvtSignalRaw);
+    MHEvent *evt02 = new MHEvent(MHEvent::kEvtSignalRaw);
+    MHEvent *evt03 = new MHEvent(MHEvent::kEvtPedestal);
+    MHEvent *evt04 = new MHEvent(MHEvent::kEvtPedestalRMS);
+    MHEvent *evt05 = new MHEvent(MHEvent::kEvtRelativeSignal);
+    MHEvent *evt06 = new MHEvent(MHEvent::kEvtCleaningLevels);
+    MHEvent *evt07 = new MHEvent(MHEvent::kEvtIdxMax);
+    MHEvent *evt08 = new MHEvent(MHEvent::kEvtArrTime);
+    MHEvent *evt09 = new MHEvent(MHEvent::kEvtTrigPix);
+    MHEvent *evt10 = new MHEvent(MHEvent::kEvtIslandIndex);
+
+    evt01->SetName("Signal");
+    evt02->SetName("Cleaned");
+    evt03->SetName("Pedestal");
+    evt04->SetName("PedRMS");
+    evt05->SetName("Signal/PedRMS");
+    evt06->SetName("CleanLevels");
+    evt07->SetName("Max Slice Idx");
+    evt08->SetName("Arrival Time");
+    evt09->SetName("Trigger");
+    evt10->SetName("Islands");
 
     // This makes sure, that the containers are deleted...
-    plist->AddToList(evt1);
-    plist->AddToList(evt2);
-    plist->AddToList(evt3);
-    plist->AddToList(evt4);
-    plist->AddToList(evt5);
-    plist->AddToList(evt6);
-    plist->AddToList(evt7);
-    plist->AddToList(evt8);
-    plist->AddToList(evt9);
-
-    MCerPhotAnal2     *nanal = new MCerPhotAnal2;
-    MFillH            *fill1 = new MFillH(evt1, "MCerPhotEvt", "MFillH1");
-    MImgCleanStd      *clean = new MImgCleanStd;
-    MFillH            *fill2 = new MFillH(evt2, "MCerPhotEvt", "MFillH2");
-    MFillH            *fill3 = new MFillH(evt3, "MPedPhotCam", "MFillH3");
-    MFillH            *fill4 = new MFillH(evt4, "MPedPhotCam", "MFillH4");
-    MFillH            *fill5 = new MFillH(evt5, "MCameraData", "MFillH5");
-    MFillH            *fill6 = new MFillH(evt6, "MCameraData", "MFillH6");
+    plist->AddToList(evt01);
+    plist->AddToList(evt02);
+    plist->AddToList(evt03);
+    plist->AddToList(evt04);
+    plist->AddToList(evt05);
+    plist->AddToList(evt06);
+    plist->AddToList(evt07);
+    plist->AddToList(evt08);
+    plist->AddToList(evt09);
+    plist->AddToList(evt10);
+
+    MCerPhotAnal2      *nanal  = new MCerPhotAnal2;
+    MFillH             *fill01 = new MFillH(evt01, "MCerPhotEvt", "MFillH01");
+    MImgCleanStd       *clean  = new MImgCleanStd;
+    MFillH             *fill02 = new MFillH(evt02, "MCerPhotEvt", "MFillH02");
+    MFillH             *fill03 = new MFillH(evt03, "MPedPhotCam", "MFillH03");
+    MFillH             *fill04 = new MFillH(evt04, "MPedPhotCam", "MFillH04");
+    MFillH             *fill05 = new MFillH(evt05, "MCameraData", "MFillH05");
+    MFillH             *fill06 = new MFillH(evt06, "MCameraData", "MFillH06");
 //    MBlindPixelCalc   *blind = new MBlindPixelCalc;
-    MHillasCalc       *hcalc = new MHillasCalc;
-    MHillasSrcCalc    *scalc = new MHillasSrcCalc;
-    MMcTriggerLvl2Calc *trcal = new MMcTriggerLvl2Calc;
-    MFillH            *fill9 = new MFillH(evt9, "MMcTriggerLvl2", "MFillH9");
+    MHillasCalc        *hcalc  = new MHillasCalc;
+    MHillasSrcCalc     *scalc  = new MHillasSrcCalc;
+    MMcTriggerLvl2Calc *trcal  = new MMcTriggerLvl2Calc;
+    MFillH             *fill09 = new MFillH(evt09, "MMcTriggerLvl2", "MFillH09");
+    MFillH             *fill10 = new MFillH(evt10, "MCerPhotEvt",    "MFillH10");
 
     // If no pedestal or no calibration file is availble
@@ -285,5 +289,6 @@
         mcupd->SetFilter(f1);
         mccal->SetFilter(f1);
-	trcal->SetFilter(f1);
+        trcal->SetFilter(f1);
+        //fill09->SetFilter(f1);
 
         // Data
@@ -309,26 +314,27 @@
     }
 
-    tlist->AddToList(fill1);
+    tlist->AddToList(fill01);
     tlist->AddToList(clean);
-    tlist->AddToList(fill2);
-    tlist->AddToList(fill3);
-    tlist->AddToList(fill4);
-    tlist->AddToList(fill5);
-    tlist->AddToList(fill6);
+    tlist->AddToList(fill02);
+    tlist->AddToList(fill03);
+    tlist->AddToList(fill04);
+    tlist->AddToList(fill05);
+    tlist->AddToList(fill06);
 //    tlist->AddToList(blind);
     tlist->AddToList(hcalc);
     tlist->AddToList(scalc);
+    tlist->AddToList(fill10);
 
     if (!pcam || !ccam)
     {
         MArrivalTimeCalc  *tcalc = new MArrivalTimeCalc;
-        MFillH            *fill7 = new MFillH(evt7, "MRawEvtData",     "MFillH7");
-        MFillH            *fill8 = new MFillH(evt8, "MArrivalTimeCam", "MFillH8");
+        MFillH            *fill07 = new MFillH(evt07, "MRawEvtData",     "MFillH7");
+        MFillH            *fill08 = new MFillH(evt08, "MArrivalTimeCam", "MFillH8");
         tlist->AddToList(tcalc);
-        tlist->AddToList(fill7);
-        tlist->AddToList(fill8);
+        tlist->AddToList(fill07);
+        tlist->AddToList(fill08);
 
 	tlist->AddToList(trcal);
-	tlist->AddToList(fill9);
+	tlist->AddToList(fill09);
     }
 
