Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 4709)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 4710)
@@ -46,4 +46,5 @@
 
 
+
  2004/08/23: Thomas Bretz
 
@@ -90,4 +91,51 @@
    * mmain/MEventDisplay.cc:
      - added display of island index
+
+   * mhvstime/MHVsTime.[h,cc]:
+     - implemented the possibility to set a maximum number of points
+
+   * mbase/MParContainer.h:
+     - changed StreamPrimitive to public
+
+   * mcalib/MMcCalibrationCalc.[h,cc]:
+     - added fPar data member (MImagePar) to get number of 
+       saturating hi gain pixels
+
+   * mimage/Makefile, mimage/ImageLinkDef.h:
+     - added MImagePar
+     - added MHImagePar
+
+   * mimage/MConcentration.[h,cc]:
+     - removed obsolete destructor
+
+   * mimage/MHillas.[h,cc]:
+     - added a check for island index to calculation
+
+   * mimage/MHillasCalc.cc:
+     - added option kCalcImagePar
+     - added option kCalcHillasSrc
+     - added Print function
+     - added StreamPrimitive function
+     - added resource support (ReadEnv)
+
+   * mimage/MHillasExt.[h,cc]:
+     - added a check for island index to calculation
+     - replaced for-loop by iterator
+
+   * mimage/MHillasSrc.[h,cc]:
+     - changed argument to Calc from pointer to reference
+
+   * mimage/MHillasSrcCalc.[h,cc]:
+     - fixed StreamPrimitive
+     - added some const-qualifiers to data members
+     - adapted to change in MHillasSrc
+
+   * mimage/MNewImagePar.[h,cc]:
+     - moved saturating pixels to new class MImagePar
+     - added a check for island index to calculation
+     - increased version number
+
+   * mpointing/MSrcPosCam.h:
+     - made StreamPrimitive public
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 4709)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 4710)
@@ -20,4 +20,10 @@
      The index corresponds to the order of the islands in size.
 
+   - Changed calculation of image parameters such, that it can be done
+     for all used pixels or the pixels with a defined island index only
+
+   - implemented new image parameters displaying the number of islands,
+     saturated hi-gain and lo-gain pixels (MImagePar, MHImagePar)
+
 
 
@@ -25,5 +31,5 @@
  
    - new Signal Extractors: MExtractFixedWindowSpline 
-                         nd MExtractAmplitudeSpline
+     and MExtractAmplitudeSpline
 
    - implementes interleave in merpp to be able to merpp parts of a file
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 4710)
@@ -54,7 +54,4 @@
     Bool_t  fReadyToSave; // should be set to true if the contents of the container is changed somehow
 
-    // FIXME: Change to ostream!
-    virtual void StreamPrimitive(ofstream &out) const;
-
 public:
     enum {
@@ -103,4 +100,7 @@
 
     virtual void SetDisplay(MStatusDisplay *d) { fDisplay = d; }
+
+    // FIXME: Change to ostream!
+    virtual void StreamPrimitive(ofstream &out) const;
 
     TMethodCall *GetterMethod(const char *name) const;
Index: /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 4710)
@@ -61,4 +61,5 @@
 
 #include "MHillas.h"
+#include "MImagePar.h"
 #include "MNewImagePar.h"
 
@@ -139,4 +140,11 @@
     {
         *fLog << err << AddSerialNumber("MNewImagePar") << "not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fPar = (MImagePar*)pList->FindObject(AddSerialNumber("MImagePar"));
+    if (!fPar)
+    {
+        *fLog << err << AddSerialNumber("MImagePar") << "not found... aborting." << endl;
         return kFALSE;
     }
@@ -236,5 +244,5 @@
     // Exclude events with some saturated pixel
     //
-    if (fNew->GetNumSaturatedPixels()>0)
+    if (fPar->GetNumSatPixelsHG()>0)
         return kTRUE;
 
Index: /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 4710)
@@ -10,4 +10,5 @@
 class MGeomCam;
 class MHillas;
+class MImagePar;
 class MNewImagePar;
 class MMcEvt;
@@ -24,4 +25,5 @@
     MHillas                   *fHillas;
     MNewImagePar              *fNew;
+    MImagePar                 *fPar;
     MMcEvt                    *fMcEvt;
     MMcFadcHeader             *fHeaderFadc;
Index: /trunk/MagicSoft/Mars/mimage/ImageLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/ImageLinkDef.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/ImageLinkDef.h	(revision 4710)
@@ -15,4 +15,5 @@
 #pragma link C++ class MHillasCalc+;
 
+#pragma link C++ class MImagePar+;
 #pragma link C++ class MNewImagePar+;
 #pragma link C++ class MConcentration+;
@@ -21,4 +22,5 @@
 #pragma link C++ class MHHillasSrc+;
 #pragma link C++ class MHHillasExt+;
+#pragma link C++ class MHImagePar+;
 #pragma link C++ class MHNewImagePar+;
 #pragma link C++ class MStereoPar+;
Index: /trunk/MagicSoft/Mars/mimage/MConcentration.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MConcentration.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MConcentration.cc	(revision 4710)
@@ -75,12 +75,4 @@
 // --------------------------------------------------------------------------
 //
-// Destructor. 
-//
-MConcentration::~MConcentration()
-{
-}
-
-// --------------------------------------------------------------------------
-//
 // Initializes the values with defaults. For the default values see the
 // source code.
@@ -111,7 +103,8 @@
 // In case you don't call Calc from within an eventloop make sure, that
 // you call the Reset member function before.
+//
 // Returns:
 //    Nothing.
-
+//
 Int_t MConcentration::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hillas)
 {
Index: /trunk/MagicSoft/Mars/mimage/MConcentration.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MConcentration.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MConcentration.h	(revision 4710)
@@ -17,5 +17,4 @@
 public:
     MConcentration(const char *name=NULL, const char *title=NULL);
-    ~MConcentration();
 
     void Reset();
Index: /trunk/MagicSoft/Mars/mimage/MHImagePar.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHImagePar.cc	(revision 4710)
+++ /trunk/MagicSoft/Mars/mimage/MHImagePar.cc	(revision 4710)
@@ -0,0 +1,182 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Wolfgang Wittek, 03/2003 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Thomas Bretz, 04/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHImagePar
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MHImagePar.h"
+
+#include <math.h>
+
+#include <TH1.h>
+#include <TPad.h>
+#include <TCanvas.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MHillas.h"
+#include "MImagePar.h"
+
+ClassImp(MHImagePar);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Setup histograms 
+//
+MHImagePar::MHImagePar(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MHImagePar";
+    fTitle = title ? title : "Histograms of image parameters";
+
+    fHistSatHi.SetName("SatHi");
+    fHistSatHi.SetTitle("Number of pixels with saturating hi-gains");
+    fHistSatHi.SetXTitle("Pixels");
+    fHistSatHi.SetYTitle("Counts");
+    fHistSatHi.SetDirectory(NULL);
+    fHistSatHi.UseCurrentStyle();
+    fHistSatHi.SetFillStyle(4000);
+
+    fHistSatLo.SetName("SatLo");
+    fHistSatLo.SetTitle("Number of pixels with saturating lo-gains");
+    fHistSatLo.SetXTitle("Pixels");
+    fHistSatLo.SetYTitle("Counts");
+    fHistSatLo.SetLineColor(kBlue);
+    fHistSatLo.SetDirectory(NULL);
+    fHistSatLo.UseCurrentStyle();
+    fHistSatLo.SetFillStyle(4000);
+
+    fHistIslands.SetName("Islands");
+    fHistIslands.SetTitle("Number of Islands");
+    fHistIslands.SetXTitle("N");
+    fHistIslands.SetYTitle("Counts");
+    fHistIslands.SetDirectory(NULL);
+    fHistIslands.UseCurrentStyle();
+    fHistIslands.SetLineColor(kBlue);
+    fHistIslands.SetFillStyle(4000);
+
+    MBinning bins;
+
+    bins.SetEdges(75, 0, 150);
+    bins.Apply(fHistSatHi);
+    bins.Apply(fHistSatHi);
+
+    bins.SetEdges(16, 0, 15);
+    bins.Apply(fHistIslands);
+}
+
+// --------------------------------------------------------------------------
+//
+// Setup the Binning for the histograms automatically if the correct
+// instances of MBinning
+//
+Bool_t MHImagePar::SetupFill(const MParList *plist)
+{
+    ApplyBinning(*plist, "Pixels",  &fHistSatHi);
+    ApplyBinning(*plist, "Pixels",  &fHistSatHi);
+
+    ApplyBinning(*plist, "Islands", &fHistIslands);
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Fill the histograms with data from a MNewImagePar container.
+//
+Bool_t MHImagePar::Fill(const MParContainer *par, const Stat_t w)
+{
+    if (!par)
+    {
+        *fLog << err << "MImagePar::Fill: Pointer (!=NULL) expected." << endl;
+        return kFALSE;
+    }
+
+    const MImagePar &h = *(MImagePar*)par;
+
+    fHistSatHi.Fill(h.GetNumSatPixelsHG(), w);
+    fHistSatLo.Fill(h.GetNumSatPixelsLG(), w);
+
+    fHistIslands.Fill(h.GetNumIslands(),   w);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Creates a new canvas and draws the two histograms into it.
+// Be careful: The histograms belongs to this object and won't get deleted
+// together with the canvas.
+//
+void MHImagePar::Draw(Option_t *)
+{
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
+
+    pad->Divide(1,2);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
+    /*
+     gPad->SetLogy();
+     TAxis &x = *fHistSatHi.GetXaxis();
+     x.SetRangeUser(0.0, x.GetXmax());
+     fHistSatHi.SetMinimum(0.1);
+     fHistSatLo.SetMinimum(0.1);
+     fHistSatHi.SetMaximum(0.1);
+     fHistSatLo.SetMaximum(0.1);
+     */
+    MH::DrawSame(fHistSatHi, fHistSatLo, "Saturating Pixels");
+
+    pad->cd(2);
+    gPad->SetBorderMode(0);
+    fHistIslands.Draw();
+
+    pad->Modified();
+    pad->Update();
+}
+
+TH1 *MHImagePar::GetHistByName(const TString name)
+{
+    if (name.Contains("SatHi", TString::kIgnoreCase))
+        return &fHistSatHi;
+    if (name.Contains("SatLo", TString::kIgnoreCase))
+        return &fHistSatLo;
+    if (name.Contains("Islands", TString::kIgnoreCase))
+        return &fHistIslands;
+
+    return NULL;
+}
Index: /trunk/MagicSoft/Mars/mimage/MHImagePar.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHImagePar.h	(revision 4710)
+++ /trunk/MagicSoft/Mars/mimage/MHImagePar.h	(revision 4710)
@@ -0,0 +1,41 @@
+#ifndef MARS_MHImagePar
+#define MARS_MHImagePar
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+#ifndef ROOT_TH1
+#include <TH1.h>
+#endif
+
+class MHillas;
+
+class MHImagePar : public MH
+{
+private:
+    TH1F fHistSatHi;   // Number of pixels with sat hi-gain
+    TH1F fHistSatLo;   // Number of pixels with sat lo-gain
+
+    TH1F fHistIslands; // Number of islands per event
+
+public:
+    MHImagePar(const char *name=NULL, const char *title=NULL);
+
+    Bool_t SetupFill(const MParList *plist);
+    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+
+    TH1 *GetHistByName(const TString name);
+
+    TH1F &GetHistSatHi()   { return fHistSatHi; }
+    TH1F &GetHistSatLo()   { return fHistSatLo; }
+
+    TH1F &GetHistIslands() { return fHistIslands; }
+
+    void Draw(Option_t *opt=NULL);
+
+    ClassDef(MHImagePar, 1) // Histograms of image parameters
+};
+
+#endif
+
+
Index: /trunk/MagicSoft/Mars/mimage/MHillas.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 4710)
@@ -188,5 +188,5 @@
 //   4  CorrXY == 0
 //
-Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
+Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, Int_t island)
 {
     //
@@ -215,4 +215,7 @@
     while ((pix=(MCerPhotPix*)Next()))
     {
+        if (island>=0 && pix->GetIdxIsland()!=island)
+            continue;
+
         const MGeomPix &gpix = geom[pix->GetPixId()];
 
@@ -257,4 +260,7 @@
     while ((pix=(MCerPhotPix*)Next()))
     {
+        if (island>=0 && pix->GetIdxIsland()!=island)
+            continue;
+
         const MGeomPix &gpix = geom[pix->GetPixId()];
 
Index: /trunk/MagicSoft/Mars/mimage/MHillas.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillas.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillas.h	(revision 4710)
@@ -31,5 +31,5 @@
     void Reset();
 
-    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix);
+    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix, Int_t island=-1);
 
     void Print(const MGeomCam &geom) const;
Index: /trunk/MagicSoft/Mars/mimage/MHillasCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasCalc.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasCalc.cc	(revision 4710)
@@ -27,9 +27,13 @@
 //
 //  MHillasCalc
+//  ===========
 //
 //  This is a task to calculate the Hillas parameters from each event
 //
-//  By default MHillas, MHillasExt and MNewImagePar are calculated
-//  with the information from MCerPhotEvt and MGeomCam.
+//
+//   Flags
+//  --------
+//
+//  By default all flags are set:
 //
 //  To switch of the calculation you may use:
@@ -37,8 +41,18 @@
 //   - Disable(MHillasCalc::kCalcHillasExt)
 //   - Disable(MHillasCalc::kCalcNewImagePar)
+//   - Disable(MHillasCalc::kCalcImagePar)
+//   - Disable(MHillasCalc::kCalcSrcPosCam)
+//   - Disable(MHillasCalc::kCalcConc)
 //
 //  If the calculation of MHillas is switched off a container MHillas
 //  in the parameter list is nevertheless necessary for the calculation
-//  of MHillasExt and MNewImagePar.
+//  of some other containers, see below.
+//
+//  If kCalcHillasSrc is set and no corresponding MSrcPosCam is found
+//  in the parameter list an empty container (X=0, Y=0) is created.
+//
+//
+//   Container names
+//  -----------------
 //
 //  The names of the containers to be used can be set with:
@@ -46,25 +60,90 @@
 //   - SetNameHillasExt("NewName")
 //   - SetNameNewImgPar("NewName")
-//
-//  Input Containers:
-//   MCerPhotEvt
-//   MGeomCam
-//   [MHillas]
-//
-//  Output Containers:
-//   [MHillas]
-//   MHillasExt
-//   MNewImagePar
+//   - SetNameImagePar("NewName")
+//   - SetNameSrcPosCam("NewName")
+//   - SetNameConc("NewName")
+//   - SetNameHillasSrc("NewName")
+//
+//
+//   Islands
+//  ---------
+//
+//  You can change the islands for which the caluclations are done by:
+//   - SetNumIsland()
+//  The default is to use all used pixels (-1)
+//
+//  fIdxIslands effects the calculations:
+//   - kCalcHillas
+//   - kCalcHillasExt
+//   - kCalcNewImgPar
+//
+//
+//   Example
+//  ---------
+//
+//   MHillasCalc calc0; // calculate all image parameters except source dep.
+//   MHillasCalc calc1; // calculate source dependant image parameters for 'Source'
+//   MHillasCalc calc2; // calculate source dependant image parameters for 'AntiSource'
+//   MHillasCalc calc3; // calculate hillas parameters only for biggest island
+//   MHillasCalc calc4; // calculate hillas parameter for 2nd biggest island
+//   // setup names of input-/output-containers
+//   calc1.SetNameSrcPosCam("Source");
+//   calc2.SetNameSrcPosCam("AntiSource");
+//   calc1.SetNameHillasSrc("MHillasSource");
+//   calc2.SetNameHillasSrc("MHillasAntiSource");
+//   calc3.SetNameHillas("MHillas0");
+//   calc4.SetNameHillas("MHillas1");
+//   // setup calculations to be done
+//   calc0.Disable(MHillasCalc::kCalcHillasSrc);
+//   calc1.SetFlags(MHillasCalc::kCalcHillasSrc);
+//   calc2.SetFlags(MHillasCalc::kCalcHillasSrc);
+//   calc3.SetFlags(MHillasCalc::kCalcHillas);
+//   calc4.SetFlags(MHillasCalc::kCalcHillas);
+//   // choode index of island
+//   calc3.SetNumIsland(0);
+//   calc4.SetNumIsland(1);
+//
+//   // setup tasklist
+//   MTaskList list;
+//   list.Add(&calc0);
+//   list.Add(&calc1);
+//   list.Add(&calc2);
+//   list.Add(&calc3);
+//   list.Add(&calc4);
+//
+//
+//   Input/Output Containers
+//  -------------------------
+//
+//    1) MGeomCam          5) MHillas         8) MImagePar
+//    2) MCerPhotEvt       6) MHillasSrc      9) MNewImagePar
+//    3) MSrcPosCam        7) MHillasExt     10) MConcentration
+//    4) fIdxIslands
+//
+//     Flag           | Input Container | Output
+//   -----------------+-----------------+--------
+//    kCalcHillas     |  1  2     4     |    5
+//    kCalcHillasSrc  |        3  4  5  |    6
+//    kCalcHillasExt  |  1  2     4  5  |    7
+//    kCalcImagePar   |     2           |    8
+//    kCalcNewImgPar  |  1  2     4  5  |    9
+//    kCalcConc       |  1  2        5  |   10
+//   -----------------+-----------------+--------
 //
 /////////////////////////////////////////////////////////////////////////////
 #include "MHillasCalc.h"
 
+#include <fstream> // StreamPrimitive
+
 #include "MParList.h"
+
+#include "MCerPhotEvt.h"
 
 #include "MHillas.h"
 #include "MHillasExt.h"
+#include "MHillasSrc.h"
+#include "MImagePar.h"
 #include "MNewImagePar.h"
 #include "MConcentration.h"
-#include "MCerPhotEvt.h"
 
 #include "MLog.h"
@@ -75,4 +154,15 @@
 using namespace std;
 
+const TString MHillasCalc::gsDefName         = "MHillasCalc";
+const TString MHillasCalc::gsDefTitle        = "Calculate Hillas and other image parameters";
+
+const TString MHillasCalc::gsNameHillas      = "MHillas";        // default name of the 'MHillas' container
+const TString MHillasCalc::gsNameHillasExt   = "MHillasExt";     // default name of the 'MHillasExt' container
+const TString MHillasCalc::gsNameNewImagePar = "MNewImagePar";   // default name of the 'MNewImagePar' container
+const TString MHillasCalc::gsNameConc        = "MConcentration"; // default name of the 'MConcentration' container
+const TString MHillasCalc::gsNameImagePar    = "MImagePar";      // default name of the 'MImagePar' container
+const TString MHillasCalc::gsNameHillasSrc   = "MHillasSrc";     // default name of the 'MHillasSrc' container
+const TString MHillasCalc::gsNameSrcPosCam   = "MSrcPosCam";     // default name of the 'MSrcPosCam' container
+
 // --------------------------------------------------------------------------
 //
@@ -80,47 +170,57 @@
 //
 MHillasCalc::MHillasCalc(const char *name, const char *title)
-    : fNameHillas("MHillas"), fNameHillasExt("MHillasExt"),
-    fNameNewImgPar("MNewImagePar"), fNameConc("MConcentration"),
-    fFlags(0xff), fErrors(5)
-{
-    fName  = name  ? name  : "MHillasCalc";
-    fTitle = title ? title : "Calculate Hillas and other image parameters";
-}
-
-// --------------------------------------------------------------------------
-//
-// Check for a MCerPhotEvt object from which the Hillas are calculated.
-// Try to find the Geometry conatiner. Depending on the flags
-// try to find (and maybe create) the containers MHillas, MHillasExt,
-// MNewImagePar, too.
+        : fNameHillas(gsNameHillas),       fNameHillasExt(gsNameHillasExt),
+          fNameHillasSrc(gsNameHillasSrc), fNameSrcPosCam(gsNameSrcPosCam),
+          fNameConc(gsNameConc),           fNameImagePar(gsNameImagePar),
+          fNameNewImagePar(gsNameNewImagePar),
+          fErrors(5), fFlags(0xff), fIdxIsland(-1)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+// Check for in-/output containers, see class description
 //
 Int_t MHillasCalc::PreProcess(MParList *pList)
 {
-    // necessary
-    fCerPhotEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
-    if (!fCerPhotEvt)
-    {
-        *fLog << err << "MCerPhotEvt not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    // necessary
-    fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
-    if (!fGeomCam)
-    {
-        *fLog << err << "MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
-        return kFALSE;
+    if (TestFlags(~kCalcHillasSrc))
+    {
+        fCerPhotEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
+        if (!fCerPhotEvt)
+        {
+            *fLog << err << "MCerPhotEvt not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
+
+    if (TestFlags(kCalcHillas|kCalcHillasExt|kCalcNewImagePar|kCalcConc))
+    {
+        fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+        if (!fGeomCam)
+        {
+            *fLog << err << "MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
+            return kFALSE;
+        }
     }
 
     // depend on whether MHillas is an in- or output container
     if (TestFlag(kCalcHillas))
+    {
         fHillas = (MHillas*)pList->FindCreateObj("MHillas", AddSerialNumber(fNameHillas));
-    else
+        if (!fHillas)
+            return kFALSE;
+    }
+
+    if (TestFlags(kCalcHillasExt|kCalcNewImagePar|kCalcConc|kCalcHillasSrc))
     {
         fHillas = (MHillas*)pList->FindObject(AddSerialNumber(fNameHillas), "MHillas");
-        *fLog << err << fNameHillas << " [MHillas] not found... aborting." << endl;
-    }
-    if (!fHillas)
-        return kFALSE;
+        if (!fHillas)
+        {
+            *fLog << err << fNameHillas << " [MHillas] not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
 
     // if enabled
@@ -133,12 +233,39 @@
 
     // if enabled
+    if (TestFlag(kCalcHillasSrc))
+    {
+        const MSrcPosCam *src = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fNameSrcPosCam), "MSrcPosCam");
+        if (!src)
+        {
+            *fLog << warn << AddSerialNumber(fNameSrcPosCam) << " [MSrcPosCam] not found... creating default container." << endl;
+            src = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fNameSrcPosCam));
+        }
+        if (!src)
+            return kFALSE;
+
+        fHillasSrc = (MHillasSrc*)pList->FindCreateObj("MHillasSrc", AddSerialNumber(fNameHillasSrc));
+        if (!fHillasSrc)
+            return kFALSE;
+
+        fHillasSrc->SetSrcPos(src);
+    }
+
+    // if enabled
     if (TestFlag(kCalcNewImagePar))
     {
-        fNewImgPar = (MNewImagePar*)pList->FindCreateObj("MNewImagePar", AddSerialNumber(fNameNewImgPar));
+        fNewImgPar = (MNewImagePar*)pList->FindCreateObj("MNewImagePar", AddSerialNumber(fNameNewImagePar));
         if (!fNewImgPar)
             return kFALSE;
     }
 
-     // if enabled
+    // if enabled
+    if (TestFlag(kCalcImagePar))
+    {
+        fImagePar = (MImagePar*)pList->FindCreateObj("MImagePar", AddSerialNumber(fNameImagePar));
+        if (!fImagePar)
+            return kFALSE;
+    }
+
+    // if enabled
     if (TestFlag(kCalcConc))
     {
@@ -150,4 +277,6 @@
     memset(fErrors.GetArray(), 0, sizeof(Char_t)*fErrors.GetSize());
 
+    Print();
+
     return kTRUE;
 }
@@ -164,5 +293,5 @@
     if (TestFlag(kCalcHillas))
     {
-        Int_t rc = fHillas->Calc(*fGeomCam, *fCerPhotEvt);
+        Int_t rc = fHillas->Calc(*fGeomCam, *fCerPhotEvt, fIdxIsland);
         if (rc<0 || rc>4)
         {
@@ -175,9 +304,21 @@
     }
 
+    if (TestBit(kCalcHillasSrc))
+    {
+        if (!fHillasSrc->Calc(*fHillas))
+        {
+            fErrors[5]++;
+            return kCONTINUE;
+        }
+    }
+
     if (TestFlag(kCalcHillasExt))
-        fHillasExt->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
+        fHillasExt->Calc(*fGeomCam, *fCerPhotEvt, *fHillas, fIdxIsland);
+
+    if (TestFlag(kCalcImagePar))
+        fImagePar->Calc(*fCerPhotEvt);
 
     if (TestFlag(kCalcNewImagePar))
-        fNewImgPar->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
+        fNewImgPar->Calc(*fGeomCam, *fCerPhotEvt, *fHillas, fIdxIsland);
 
     if (TestFlag(kCalcConc))
@@ -209,11 +350,19 @@
         return kTRUE;
 
+    if (!TestBit(kCalcHillas) && !TestBit(kCalcHillasSrc))
+        return kTRUE;
+
     *fLog << inf << endl;
     *fLog << GetDescriptor() << " execution statistics:" << endl;
     *fLog << dec << setfill(' ');
-    PrintSkipped(1, "Less than 3 pixels (before cleaning)");
-    PrintSkipped(2, "Calculated Size == 0 (after cleaning)");
-    PrintSkipped(3, "Number of used pixels < 3");
-    PrintSkipped(4, "CorrXY==0");
+    if (TestBit(kCalcHillas))
+    {
+        PrintSkipped(1, "Less than 3 pixels (before cleaning)");
+        PrintSkipped(2, "Calculated Size == 0 (after cleaning)");
+        PrintSkipped(3, "Number of used pixels < 3");
+        PrintSkipped(4, "CorrXY==0");
+    }
+    if (TestBit(kCalcHillasSrc))
+        PrintSkipped(5, "Dist==0");
     *fLog << " " << (int)fErrors[0] << " (" << (int)(100.*fErrors[0]/GetNumExecutions()) << "%) Evts survived Hillas calculation!" << endl;
     *fLog << endl;
@@ -221,2 +370,77 @@
     return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Print 'Dataflow'
+//
+void MHillasCalc::Print(Option_t *o) const
+{
+    *fLog << inf << GetDescriptor() << ":" << endl;
+    if (TestFlag(kCalcHillas))
+        *fLog << " - Calculating " << fNameHillas << " from MGeomCam, MCerPhotEvt and fIdxIsland=" << fIdxIsland << endl;
+    if (TestFlag(kCalcHillasSrc))
+        *fLog << " - Calculating " << fNameHillasSrc << " from " << fNameSrcPosCam << ", " << fNameHillas << " and fIdxIsland=" << fIdxIsland << endl;
+    if (TestFlag(kCalcHillasExt))
+        *fLog << " - Calculating " << fNameHillasExt << " from MGeomCam, MCerPhotEvt, " << fNameHillas << " and fIdxIsland=" << fIdxIsland << endl;
+    if (TestFlag(kCalcImagePar))
+        *fLog << " - Calculating " << fNameImagePar << " from MCerPhotEvt" << endl;
+    if (TestFlag(kCalcNewImagePar))
+        *fLog << " - Calculating " << fNameNewImagePar << " from MGeomCam, MCerPhotEvt, " << fNameHillas << " and fIdxIsland=" << fIdxIsland << endl;
+    if (TestFlag(kCalcConc))
+        *fLog << " - Calculating " << fNameConc << " from MGeomCam, MCerPhotEvt and " << fNameHillas << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MHillasCalc::StreamPrimitive(ofstream &out) const
+{
+    out << "   MHillasCalc " << GetUniqueName() << "(";
+    if (fName!=gsDefName || fTitle!=gsDefTitle)
+    {
+        out << ", \"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+    }
+    out << ");" << endl;
+
+    if (TestFlags(kCalcHillasExt|kCalcNewImagePar|kCalcConc|kCalcHillasSrc))
+    {
+        if (fNameHillas!=gsNameHillas)
+            out << "   " << GetUniqueName() << ".SetNameHillas(\"" << fNameHillas << "\");" << endl;
+    }
+    if (TestFlag(kCalcHillasSrc) && fNameHillasSrc!=gsNameHillasSrc)
+    {
+        out << "   " << GetUniqueName() << ".SetNameHillasSrc(\"" << fNameHillasSrc << "\");" << endl;
+        out << "   " << GetUniqueName() << ".SetNameSrcPosCam(\"" << fNameSrcPosCam << "\");" << endl;
+    }
+    if (TestFlag(kCalcHillasExt) && fNameHillasExt!=gsNameHillasExt)
+        out << "   " << GetUniqueName() << ".SetNameHillasExt(\"" << fNameHillasExt << "\");" << endl;
+    if (TestFlag(kCalcConc) && fNameConc!=gsNameConc)
+        out << "   " << GetUniqueName() << ".SetNameConc(\"" << fNameConc << "\");" << endl;
+    if (TestFlag(kCalcImagePar) && fNameImagePar!=gsNameImagePar)
+        out << "   " << GetUniqueName() << ".SetNameImagePar(\"" << fNameImagePar << "\");" << endl;
+    if (TestFlag(kCalcNewImagePar) && fNameNewImagePar!=gsNameNewImagePar)
+        out << "   " << GetUniqueName() << ".SetNameNewImagePar(\"" << fNameNewImagePar << "\");" << endl;
+
+    if (!TestFlag(kCalcHillas))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcHillas);" << endl;
+    if (!TestFlag(kCalcHillasExt))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcHillasExt);" << endl;
+    if (!TestFlag(kCalcHillasSrc))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcHillasSrc);" << endl;
+    if (!TestFlag(kCalcNewImagePar))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcNewImagePar);" << endl;
+    if (!TestFlag(kCalcConc))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcConc);" << endl;
+    if (!TestFlag(kCalcImagePar))
+        out << "   " << GetUniqueName() << ".Disable(MHilllasCalc::kCalcImagePar);" << endl;
+
+    if (fIdxIsland>=0)
+        out << "   " << GetUniqueName() << ".SetNumIsland(" << fIdxIsland << ");" << endl;
+}
+
Index: /trunk/MagicSoft/Mars/mimage/MHillasCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasCalc.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasCalc.h	(revision 4710)
@@ -21,28 +21,53 @@
 class MHillas;
 class MHillasExt;
+class MHillasSrc;
+class MImagePar;
 class MNewImagePar;
 class MConcentration;
+class MSrcPosCam;
 
 class MHillasCalc : public MTask
 {
-    const MGeomCam    *fGeomCam;    //! Camera Geometry used to calculate Hillas
-    const MCerPhotEvt *fCerPhotEvt; //! Cerenkov Photon Event used for calculation
+    static const TString gsDefName;         // default name
+    static const TString gsDefTitle;        // default title
 
-    MHillas           *fHillas;     //! output container to store result
-    MHillasExt        *fHillasExt;  //! output container to store result
-    MNewImagePar      *fNewImgPar;  //! output container to store result
-    MConcentration    *fConc;       //! output container to store result
+    static const TString gsNameHillas;      // default name of the 'MHillas' container
+    static const TString gsNameHillasExt;   // default name of the 'MHillasExt' container
+    static const TString gsNameNewImagePar; // default name of the 'MNewImagePar' container
+    static const TString gsNameConc;        // default name of the 'MConcentration' container
+    static const TString gsNameImagePar;    // default name of the 'MImagePar' container
+    static const TString gsNameHillasSrc;   // default name of the 'MHillasSrc' container
+    static const TString gsNameSrcPosCam;   // default name of the 'MSrcPosCam' container
 
-    TString            fNameHillas;    // name of the 'MHillas' container
-    TString            fNameHillasExt; // name of the 'MHillasExt' container
-    TString            fNameNewImgPar; // name of the 'MNewImagePar' container
-    TString            fNameConc;      // name of the 'MConcentration' container
+    const MGeomCam      *fGeomCam;          //! Camera Geometry used to calculate Hillas
+    const MCerPhotEvt   *fCerPhotEvt;       //! Cerenkov Photon Event used for calculation
 
-    Int_t              fFlags;      // Flags defining the behaviour of MHillasCalc
+    MHillas             *fHillas;           //! output container to store result
+    MHillasExt          *fHillasExt;        //! output container to store result
+    MHillasSrc          *fHillasSrc;        //! output container to store result
+    MImagePar           *fImagePar;         //! output container to store result
+    MNewImagePar        *fNewImgPar;        //! output container to store result
+    MConcentration      *fConc;             //! output container to store result
 
-    TArrayL            fErrors;     //! Error counter. Do we have to change to Double?
+    TString              fNameHillas;       // name of the 'MHillas' container
+    TString              fNameHillasExt;    // name of the 'MHillasExt' container
+    TString              fNameHillasSrc;    // name of the 'MHillasSrc' container
+    TString              fNameSrcPosCam;    // name of the 'MSrcPosCam' container
+    TString              fNameConc;         // name of the 'MConcentration' container
+    TString              fNameImagePar;     // name of the 'MImagePar' container
+    TString              fNameNewImagePar;  // name of the 'MNewImagePar' container
 
+    TArrayL              fErrors;           //! Error counter. Do we have to change to Double?
+
+    Int_t                fFlags;            // Flags defining the behaviour of MHillasCalc
+    Short_t              fIdxIsland;        // Number of island to use for calculation
+
+    // Helper
     void  PrintSkipped(int i, const char *str) const;
 
+    // MParContainer
+    void StreamPrimitive(ofstream &out) const;
+
+    // MTask
     Int_t PreProcess(MParList *pList);
     Int_t Process();
@@ -50,23 +75,39 @@
 
 public:
+    // Constructor
+    MHillasCalc(const char *name=NULL, const char *title=NULL);
+
+    // Flags
     enum CalcCont_t {
         kCalcHillas      = BIT(0),
         kCalcHillasExt   = BIT(1),
-        //kCalcHillasSrc   = BIT(2),
+        kCalcHillasSrc   = BIT(2),
         kCalcNewImagePar = BIT(3),
-        kCalcConc        = BIT(4)
+        kCalcConc        = BIT(4),
+        kCalcImagePar    = BIT(5)
     };
 
-    MHillasCalc(const char *name=NULL, const char *title=NULL);
+    // Setup flags
+    void SetFlags(Int_t f) { fFlags  =  f; }
+    void Enable(Int_t f)   { fFlags |=  f; }
+    void Disable(Int_t f)  { fFlags &= ~f; }
 
-    void   SetNameHillas(const char *name)    { fNameHillas = name;    }
-    void   SetNameHillasExt(const char *name) { fNameHillasExt = name; }
-    void   SetNameNewImgPar(const char *name) { fNameNewImgPar = name; }
-    void   SetNameConc(const char *name)      { fNameConc = name;      }
+    Bool_t TestFlag(CalcCont_t i) const { return fFlags&i; }
+    Bool_t TestFlags(Int_t i) const     { return fFlags&i; }
 
-    void   SetFlags(Int_t f) { fFlags  =  f; }
-    void   Enable(Int_t f)   { fFlags |=  f; }
-    void   Disable(Int_t f)  { fFlags &= ~f; }
-    Bool_t TestFlag(CalcCont_t i) const { return fFlags&i; }
+    // Setup container names
+    void SetNameHillas(const char *name)      { fNameHillas      = name; }
+    void SetNameHillasExt(const char *name)   { fNameHillasExt   = name; }
+    void SetNameHillasSrc(const char *name)   { fNameHillasSrc   = name; }
+    void SetNameNewImagePar(const char *name) { fNameNewImagePar = name; }
+    void SetNameConc(const char *name)        { fNameConc        = name; }
+    void SetNameImagePar(const char *name)    { fNameImagePar    = name; }
+    void SetNameSrcPosCam(const char *name)   { fNameSrcPosCam   = name; }
+
+    // Setup island number
+    void SetIdxIsland(Short_t idx) { fIdxIsland = idx; }
+
+    // TObject
+    void Print(Option_t *o="") const;
 
     ClassDef(MHillasCalc, 0) // Task to calculate Hillas and other image parameters
Index: /trunk/MagicSoft/Mars/mimage/MHillasExt.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 4710)
@@ -138,5 +138,5 @@
 // and the cerenkov photon event
 //
-Int_t MHillasExt::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hil)
+Int_t MHillasExt::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hil, Int_t island)
 {
     //
@@ -151,6 +151,4 @@
     Double_t m3x = 0;
     Double_t m3y = 0;
-
-    const UInt_t npixevt = evt.GetNumPixels();
 
     Int_t maxpixid  = 0;
@@ -158,11 +156,13 @@
     Float_t maxdist = 0;
 
-    for (UInt_t i=0; i<npixevt; i++)
+    MCerPhotPix *pix = 0;
+
+    TIter Next(evt);
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-        if (!pix.IsPixelUsed())
+        if (island>=0 && pix->GetIdxIsland()!=island)
             continue;
 
-        const Int_t pixid = pix.GetPixId();
+        const Int_t pixid = pix->GetPixId();
 
         const MGeomPix &gpix = geom[pixid];
@@ -170,5 +170,5 @@
         const Double_t dy = gpix.GetY() - hil.GetMeanY();      // [mm]
 
-        Double_t nphot = pix.GetNumPhotons();                  // [1]
+        Double_t nphot = pix->GetNumPhotons();                  // [1]
 
         const Double_t dzx =  hil.GetCosDelta()*dx + hil.GetSinDelta()*dy; // [mm]
Index: /trunk/MagicSoft/Mars/mimage/MHillasExt.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasExt.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasExt.h	(revision 4710)
@@ -33,5 +33,6 @@
     Float_t GetMaxDist() const { return fMaxDist; }
 
-    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix, const MHillas &hil);
+    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix,
+               const MHillas &hil, Int_t island=-1);
 
     void Print(Option_t *opt=NULL) const;
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 4710)
@@ -99,14 +99,14 @@
 //  you call the Reset member function before.
 //
-Bool_t MHillasSrc::Calc(const MHillas *hillas)
+Bool_t MHillasSrc::Calc(const MHillas &hillas)
 {
-    const Double_t mx = hillas->GetMeanX();     // [mm]
-    const Double_t my = hillas->GetMeanY();     // [mm]
+    const Double_t mx = hillas.GetMeanX();     // [mm]
+    const Double_t my = hillas.GetMeanY();     // [mm]
 
     const Double_t sx = mx - fSrcPos->GetX();   // [mm]
     const Double_t sy = my - fSrcPos->GetY();   // [mm]
 
-    const Double_t sd = hillas->GetSinDelta();  // [1]
-    const Double_t cd = hillas->GetCosDelta();  // [1]
+    const Double_t sd = hillas.GetSinDelta();  // [1]
+    const Double_t cd = hillas.GetCosDelta();  // [1]
 
     //
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrc.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 4710)
@@ -32,5 +32,5 @@
     void Print(const MGeomCam &geom) const;
 
-    virtual Bool_t Calc(const MHillas *hillas);
+    virtual Bool_t Calc(const MHillas &hillas);
 
     void Set(const TArrayF &arr);
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc	(revision 4710)
@@ -114,5 +114,5 @@
 Int_t MHillasSrcCalc::Process()
 {
-    if (!fHillasSrc->Calc(fHillas))
+    if (!fHillasSrc->Calc(*fHillas))
     {
         fErrors++;
@@ -150,12 +150,12 @@
 void MHillasSrcCalc::StreamPrimitive(ofstream &out) const
 {
-    if (fHillas)
-        fHillas->SavePrimitive(out);
+    if (fHillas && !fHillas->IsSavedAsPrimitive())
+        fHillas->StreamPrimitive(out);
 
-    if (fSrcPos)
-        fSrcPos->SavePrimitive(out);
+    if (fSrcPos && !fSrcPos->IsSavedAsPrimitive())
+        fSrcPos->StreamPrimitive(out);
 
-    if (fHillasSrc)
-        fHillasSrc->SavePrimitive(out);
+    if (fHillasSrc && !fHillasSrc->IsSavedAsPrimitive())
+        fHillasSrc->StreamPrimitive(out);
 
     out << "   MHillasSrcCalc " << GetUniqueName() << "(";
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.h	(revision 4710)
@@ -13,7 +13,7 @@
 {
 private:
-    MHillas    *fHillas;     //! Pointer to the source independant hillas parameters
-    MSrcPosCam *fSrcPos;     //! Pointer to the source position
-    MHillasSrc *fHillasSrc;  //! Pointer to the output container for the source dependant parameters
+    const MHillas    *fHillas;     //! Pointer to the source independant hillas parameters
+    const MSrcPosCam *fSrcPos;     //! Pointer to the source position
+          MHillasSrc *fHillasSrc;  //! Pointer to the output container for the source dependant parameters
 
     TString     fSrcName;
Index: /trunk/MagicSoft/Mars/mimage/MImagePar.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImagePar.cc	(revision 4710)
+++ /trunk/MagicSoft/Mars/mimage/MImagePar.cc	(revision 4710)
@@ -0,0 +1,109 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MImagePar
+//
+// Storage Container for new image parameters
+//
+//    Short_t fNumIslands;           // number of islands found
+//
+//    Short_t fNumHGSaturatedPixels; // number of pixels with saturating hi-gains
+//    Short_t fNumSaturatedPixels;   // number of pixels with saturating lo-gains
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MImagePar.h"
+
+#include <fstream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MCerPhotEvt.h"
+#include "MCerPhotPix.h"
+
+ClassImp(MImagePar);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MImagePar::MImagePar(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MImagePar";
+    fTitle = title ? title : "New image parameters";
+
+    Reset();
+}
+
+// --------------------------------------------------------------------------
+//
+void MImagePar::Reset()
+{
+    fNumIslands = -1;
+
+    fNumSatPixelsHG = -1;
+    fNumSatPixelsLG = -1;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Calculation of new image parameters
+//
+void MImagePar::Calc(const MCerPhotEvt &evt)
+{
+    // Get number of saturating pixels
+    fNumSatPixelsHG = 0;
+    fNumSatPixelsLG = 0;
+
+    const UInt_t npixevt = evt.GetNumPixels();
+    for (UInt_t i=0; i<npixevt; i++)
+    {
+        const MCerPhotPix &pix = evt[i];
+
+	if (pix.IsPixelHGSaturated())
+            fNumSatPixelsHG++;
+	if (pix.IsPixelSaturated())
+            fNumSatPixelsLG++;
+    }
+
+    // Get number of islands
+    fNumIslands = evt.GetNumIslands();
+
+    SetReadyToSave();
+}
+
+// --------------------------------------------------------------------------
+//
+void MImagePar::Print(Option_t *) const
+{
+    *fLog << all;
+    *fLog << "Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Num Islands    [#]   = " << fNumIslands << " Islands" << endl;
+    *fLog << " - Sat.Pixels/HG  [#]   = " << fNumSatPixelsHG << " Pixels" << endl;
+    *fLog << " - Sat.Pixels/LG  [#]   = " << fNumSatPixelsLG << " Pixels" << endl;
+}
Index: /trunk/MagicSoft/Mars/mimage/MImagePar.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImagePar.h	(revision 4710)
+++ /trunk/MagicSoft/Mars/mimage/MImagePar.h	(revision 4710)
@@ -0,0 +1,37 @@
+#ifndef MARS_MImagePar
+#define MARS_MImagePar
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MHillas;
+class MGeomCam;
+class MCerPhotEvt;
+
+class MImagePar : public MParContainer
+{
+private:
+    Short_t fNumIslands;     // Number of islands found
+
+    Short_t fNumSatPixelsHG; // number of pixels with saturating hi-gains
+    Short_t fNumSatPixelsLG; // number of pixels with saturating lo-gains
+
+public:
+    MImagePar(const char *name=NULL, const char *title=NULL);
+
+    void Reset();
+
+    Short_t GetNumIslands() const { return fNumIslands; }
+
+    Short_t GetNumSatPixelsHG() const { return fNumSatPixelsHG; }
+    Short_t GetNumSatPixelsLG() const { return fNumSatPixelsLG; }
+
+    void Print(Option_t *opt=NULL) const;
+
+    void Calc(const MCerPhotEvt &evt);
+
+    ClassDef(MImagePar, 1) // Container to hold (geometry and island independant) image parameters
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mimage/MNewImagePar.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 4710)
@@ -59,4 +59,10 @@
 //  - added fCoreArea
 //
+// Version 4:
+// ----------
+//  - moved cleaning/island independant parameters to MImagePar:
+//    + removed fNumHGSaturatedPixels
+//    + removed fNumSaturatedPixels
+//
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -88,4 +94,6 @@
     fName  = name  ? name  : "MNewImagePar";
     fTitle = title ? title : "New image parameters";
+
+    Reset();
 }
 
@@ -109,7 +117,4 @@
     fUsedArea = -1;
     fCoreArea = -1;
-
-    fNumSaturatedPixels = -1;
-    fNumHGSaturatedPixels = -1;
 }
 
@@ -119,5 +124,5 @@
 //
 void MNewImagePar::Calc(const MGeomCam &geom, const MCerPhotEvt &evt,
-                        const MHillas &hillas)
+                        const MHillas &hillas, Int_t island)
 {
     fNumUsedPixels = 0;
@@ -127,10 +132,5 @@
     fCoreArea = 0;
 
-    fNumSaturatedPixels = 0;
-    fNumHGSaturatedPixels = 0;
-
     fInnerSize = 0;
-
-    const UInt_t npixevt = evt.GetNumPixels();
 
     Double_t edgepix1 = 0;
@@ -143,24 +143,19 @@
     Float_t maxpix2 = 0;                                 // [#phot]
 
-    for (UInt_t i=0; i<npixevt; i++)
+    MCerPhotPix *pix = 0;
+
+    TIter Next(evt);
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-
-        // count saturated pixels
-	if (pix.IsPixelHGSaturated())
-            fNumHGSaturatedPixels++;
-	if (pix.IsPixelSaturated())
-            fNumSaturatedPixels++;
-
-        // skip unused pixels
-        if (!pix.IsPixelUsed())
+        // Check for requested islands
+        if (island>=0 && pix->GetIdxIsland()!=island)
             continue;
 
         // Get geometry of pixel
-        const Int_t pixid = pix.GetPixId();
+        const Int_t pixid = pix->GetPixId();
         const MGeomPix &gpix = geom[pixid];
 
         // count used and core pixels
-        if (pix.IsPixelCore())
+        if (pix->IsPixelCore())
         {
             fNumCorePixels++;
@@ -172,5 +167,5 @@
         fUsedArea += gpix.GetA();
 
-        Double_t nphot = pix.GetNumPhotons();
+        Double_t nphot = pix->GetNumPhotons();
 
         //
@@ -239,6 +234,4 @@
     *fLog << " - Used Area     [mm^2] = " << fUsedArea             << endl;
     *fLog << " - Core Area     [mm^2] = " << fCoreArea             << endl;
-    *fLog << " - Sat.Pixels/HG  [#]   = " << fNumHGSaturatedPixels << " Pixels" << endl;
-    *fLog << " - Sat.Pixels/LG  [#]   = " << fNumSaturatedPixels   << " Pixels" << endl;
 }
 
@@ -263,5 +256,3 @@
     *fLog << " - Used Area    [deg^2] = " << fUsedArea*geom.GetConvMm2Deg()*geom.GetConvMm2Deg() << endl;
     *fLog << " - Core Area    [deg^2] = " << fCoreArea*geom.GetConvMm2Deg()*geom.GetConvMm2Deg() << endl;
-    *fLog << " - Sat.Pixels/HG  [#]   = " << fNumHGSaturatedPixels << " Pixels" << endl;
-    *fLog << " - Sat.Pixels/LG  [#]   = " << fNumSaturatedPixels   << " Pixels" << endl;
-}
+}
Index: /trunk/MagicSoft/Mars/mimage/MNewImagePar.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 4710)
@@ -13,4 +13,6 @@
 {
 private:
+    // FIXME: MOVE ALL PARAMETRS WHICH DOES'T DEPEND ON THE IMAGE
+    //        CLEANING TO A NEW CLASS!
     Float_t fLeakage1;             // (photons in most outer ring of pixels) over fSize
     Float_t fLeakage2;             // (photons in the 2 outer rings of pixels) over fSize
@@ -26,6 +28,4 @@
     Short_t fNumUsedPixels;        // Number of pixels which survived the image cleaning
     Short_t fNumCorePixels;        // number of core pixels
-    Short_t fNumHGSaturatedPixels; // number of pixels with saturating hi-gains
-    Short_t fNumSaturatedPixels;   // number of pixels with saturating lo-gains
 
 public:
@@ -50,14 +50,11 @@
     Float_t GetCoreArea() const { return fCoreArea; }
 
-    Short_t GetNumSaturatedPixels() const { return fNumSaturatedPixels; }
-    Short_t GetNumHGSaturatedPixels() const { return fNumHGSaturatedPixels; }
-
     void Print(Option_t *opt=NULL) const;
     void Print(const MGeomCam &geom) const;
 
     void Calc(const MGeomCam &geom, const MCerPhotEvt &evt,
-              const MHillas &hillas);
+              const MHillas &hillas, Int_t island=-1);
 
-    ClassDef(MNewImagePar, 3) // Container to hold new image parameters
+    ClassDef(MNewImagePar, 4) // Container to hold new image parameters
 };
 
Index: /trunk/MagicSoft/Mars/mimage/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mimage/Makefile	(revision 4709)
+++ /trunk/MagicSoft/Mars/mimage/Makefile	(revision 4710)
@@ -34,4 +34,5 @@
            MHillasCalc.cc \
            MHillasSrcCalc.cc \
+           MImagePar.cc \
 	   MNewImagePar.cc \
 	   MConcentration.cc \
@@ -39,4 +40,5 @@
            MHHillasSrc.cc \
            MHHillasExt.cc \
+           MHImagePar.cc \
 	   MHNewImagePar.cc \
 	   MStereoPar.cc \
Index: /trunk/MagicSoft/Mars/mpointing/MSrcPosCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mpointing/MSrcPosCam.h	(revision 4709)
+++ /trunk/MagicSoft/Mars/mpointing/MSrcPosCam.h	(revision 4710)
@@ -13,6 +13,4 @@
     Float_t fX; // [mm] x position of source in camera
     Float_t fY; // [mm] y position of source in camera
-
-    void StreamPrimitive(ofstream &out) const;
 
 public:
@@ -31,4 +29,5 @@
 
     void Print(Option_t *opt=NULL) const;
+    void StreamPrimitive(ofstream &out) const;
 
     //void AsciiRead(ifstream &fin);
