Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2487)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2488)
@@ -47,4 +47,20 @@
    * mraw/MRawEvtPixelIter.[h,cc]:
      - added a fixes for the case that fData->fLoGainPixId->GetArray()=NULL
+
+   * manalysis/Makefile, manalysis/AnalysisLinkDef.h:
+     - added MCameraData
+
+   * manalysis/MCameraData.[h,cc]:
+     - added
+     
+   * mhist/MHEvent.[h,cc]:
+     - fixed display of levels
+     - fixed unallowed characters
+     
+   * mimage/MImgCleanStd.[h,cc]:
+     - moved the calculation for signal/noise to MCameraData
+     
+   * mmain/MEventDisplay.cc:
+     - added display for cleaning data and levels
 
 
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2487)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2488)
@@ -11,5 +11,5 @@
 #pragma link C++ class MCerPhotCalc+;
 
-//#pragma link C++ class MRelSignal+;
+#pragma link C++ class MCameraData+;
 
 #pragma link C++ class MBlindPixels+;
Index: trunk/MagicSoft/Mars/manalysis/MCameraData.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 2488)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 2488)
@@ -0,0 +1,178 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MCameraData
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCameraData.h"
+
+#include "MCerPhotEvt.h"
+#include "MCerPhotPix.h"
+
+#include "MGeomCam.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+#include "MSigmabar.h"
+
+ClassImp(MCameraData);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Creates a MCerPhotPix object for each pixel in the event
+//
+MCameraData::MCameraData(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MCameraData";
+    fTitle = title ? title : "Photons/PedRMS Information";
+}
+
+// --------------------------------------------------------------------------
+//
+// This is not yet implemented like it should.
+//
+/*
+void MCameraData::Draw(Option_t* option) 
+{
+    //
+    //   FIXME!!! Here the Draw function of the CamDisplay
+    //   should be called to add the CamDisplay to the Pad.
+    //   The drawing should be done in MCamDisplay::Paint
+    //
+
+    //    MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
+    //    MCamDisplay *disp = new MCamDisplay(geom);
+    //    delete geom;
+    //    disp->DrawPhotNum(this);
+}
+*/
+
+void MCameraData::Calc(const MCerPhotEvt &evt, const MPedestalCam &cam,
+                      const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData.Set(n);
+    fData.Reset();
+
+    fValidity.Set(n);
+    fValidity.Reset();
+
+    const Int_t entries = evt.GetNumPixels();
+
+    //
+    // check the number of all pixels against the noise level and
+    // set them to 'unused' state if necessary
+    // 
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = evt[i];
+
+        const Int_t idx = pix.GetPixId();
+        const Float_t noise = cam[idx].GetPedestalRms();
+
+        if (noise<=0) // fData[idx]=0, fValidity[idx]=0
+            continue;
+
+        //
+	// We calculate a correction factor which accounts for the 
+	// fact that pixels have different size (see TDAS 02-14).
+	//
+        fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
+        fValidity[idx] = 1;
+    }
+}
+
+void MCameraData::Calc(const MCerPhotEvt &evt, const MSigmabar &sgb,
+                      const MGeomCam &geom)
+{
+    Calc(evt, sgb.GetSigmabarInner(), geom);
+}
+
+void MCameraData::Calc(const MCerPhotEvt &evt, Double_t noise,
+                      const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData.Set(n);
+    fData.Reset();
+
+    fValidity.Set(n);
+    fValidity.Reset();
+
+    if (noise<=0)
+        return;
+
+    const Int_t entries = evt.GetNumPixels();
+
+    //
+    // check the number of all pixels against the noise level and
+    // set them to 'unused' state if necessary
+    // 
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = evt[i];
+
+        const Int_t idx = pix.GetPixId();
+
+        //
+	// We calculate a correction factor which accounts for the 
+	// fact that pixels have different size (see TDAS 02-14).
+	//
+        fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise;
+        fValidity[idx] = 1;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns, depending on the type flag:
+//
+//  0: Number of Photons*PixRatio
+//  1: Error*sqrt(PixRatio)
+//  2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
+//  3: Number of Photons
+//  4: Error
+//
+Bool_t MCameraData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+    if (idx<0 || idx>=fData.GetSize())
+        return kFALSE;
+
+    val = fData[idx];
+    return fValidity[idx];
+}
+
+void MCameraData::DrawPixelContent(Int_t num) const
+{
+    *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
+}
Index: trunk/MagicSoft/Mars/manalysis/MCameraData.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 2488)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 2488)
@@ -0,0 +1,54 @@
+#ifndef MARS_MCameraData
+#define MARS_MCameraData
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+#ifndef ROOT_TArrayC
+#include <TArrayC.h>
+#endif
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+class MGeomCam;
+class MSigmabar;
+class MCerPhotEvt;
+class MPedestalCam;
+
+class MCameraData : public MCamEvent
+{
+private:
+    TArrayD fData;  //
+    TArrayC fValidity;
+
+public:
+    MCameraData(const char *name=NULL, const char *title=NULL);
+    ~MCameraData() { }
+
+    UInt_t GetNumPixels() const { return fData.GetSize(); }
+
+    void Calc(const MCerPhotEvt &evt, const MPedestalCam &fCam,
+              const MGeomCam &geom);
+    void Calc(const MCerPhotEvt &evt, const MSigmabar &sgb,
+              const MGeomCam &geom);
+    void Calc(const MCerPhotEvt &evt, Double_t noise,
+              const MGeomCam &geom);
+
+    void Calc(const MCerPhotEvt &evt, const MGeomCam &geom)
+    {
+        Calc(evt, 1, geom);
+    }
+
+    const TArrayD &GetData() const { return fData; }
+    const TArrayC &GetValidity() const  { return fValidity; }
+
+    Double_t operator[](int i) { return fData[i]; }
+
+    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+    void DrawPixelContent(Int_t num) const;
+
+    ClassDef(MCameraData, 2)    // class for an event containing cerenkov photons
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2487)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 2488)
@@ -37,4 +37,5 @@
            MGeomApply.cc \
            MCurrents.cc \
+           MCameraData.cc \
            MEnergyEst.cc \
            MEnergyEstimate.cc \
@@ -69,5 +70,4 @@
            MCT1PadONOFF.cc
 
-#           MRelSignal.cc \
 
 SRCS    = $(SRCFILES)
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2487)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2488)
@@ -1144,5 +1144,5 @@
          TIter Next(gPad->GetListOfPrimitives());
          TObject *o;
-         while (o=Next()) cout << o->GetName() << " " << o->IsA()->GetName() << endl;
+         while (o=Next()) cout << o << ": " << o->GetName() << " " << o->IsA()->GetName() << endl;
          */
 
Index: trunk/MagicSoft/Mars/mhist/MHEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 2487)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 2488)
@@ -64,4 +64,5 @@
 #include "MRawRunHeader.h"
 #include "MRawEvtData.h"
+#include "MImgCleanStd.h"
 
 ClassImp(MHEvent);
@@ -140,8 +141,11 @@
         break;
     case kEvtCleaningLevels:
+        if (!fImgCleanStd)
+        {
+            *fLog << err << "MImgCleanStd not found... aborting." << endl;
+            return kFALSE;
+        }
         fHist->SetName("CleanLevels");
         fHist->SetYTitle("L");
-        if (!fImgCleanStd)
-            return kFALSE;
         break;
     }
@@ -171,6 +175,14 @@
         break;
     case kEvtRelativeSignal:
+        fHist->SetCamContent(*(MCamEvent*)par, 0);
+        break;
     case kEvtCleaningLevels:
-        fHist->SetCamContent(*(MCamEvent*)par, 0);
+        {
+            TArrayF lvl(2);
+            lvl[0] = fImgCleanStd->GetCleanLvl2();
+            lvl[1] = fImgCleanStd->GetCleanLvl1();
+            fHist->SetCamContent(*(MCamEvent*)par, 0);
+            fHist->SetLevels(lvl);
+        }
         break;
     }
@@ -193,5 +205,5 @@
     if (fMcEvt)
     {
-        TString txt;// = "#splitline{";
+        TString txt("#splitline{");
 
         switch (fMcEvt->GetPartId())
@@ -214,5 +226,5 @@
         s.Insert(0, txt);
 
-        //s += "}{";
+        s += "}{";
         s += "  E=";
         if (fMcEvt->GetEnergy()>1000)
@@ -224,8 +236,8 @@
         s += "m ZA=";
         s += (int)(fMcEvt->GetTheta()*180/TMath::Pi()+.5);
-        s += "° ";
+        s += "\xb0 ";
         s += fMcEvt->GetPhotElfromShower();
         s += "PhEl";
-        //s += "}";
+        s += "}";
     }
 
Index: trunk/MagicSoft/Mars/mhist/MHEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 2487)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 2488)
@@ -15,5 +15,5 @@
 class MPedestalCam;
 class MImgCleanStd;
-class MRelSignal;
+class MCameraSignal;
 
 class MHEvent : public MH
@@ -34,4 +34,5 @@
     MPedestalCam  *fPedestalCam;   //!
     MImgCleanStd  *fImgCleanStd;   //!
+    MCameraSignal *fCamSignal;     //!
 
     MRawEvtData   *fClone;         //->
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 2487)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 2488)
@@ -266,4 +266,5 @@
 #include "MParList.h"
 #include "MSigmabar.h"
+#include "MCameraData.h"
 
 #include "MGeomPix.h"
@@ -312,59 +313,25 @@
 // --------------------------------------------------------------------------
 //
-//  NT 28/04/2003: now the option to use the standard method or the 
+// The first step of cleaning defines the CORE pixels. All the other pixels
+// are set as UNUSED and belong to RING 0.
+// After this point, only the CORE pixels are set as USED, with RING
+// number 1.
+//
+//  NT 28/04/2003: now the option to use the standard method or the
 //  democratic method is implemented:
 //
-//  KStandard: This method looks for all pixels with an entry (photons)
-//             that is three times bigger than the noise of the pixel
-//             (default: 3 sigma, clean level 1)
-//
-// --------------------------------------------------------------------------
-//
-//  Returns the maximum Pixel Id (used for ispixused in CleanStep2)
-//
-void MImgCleanStd::CleanStep1Std()
+//  kStandard:   This method looks for all pixels with an entry (photons)
+//               that is three times bigger than the noise of the pixel
+//               (default: 3 sigma, clean level 1)
+//
+//  kDemocratic: this method looks for all pixels with an entry (photons)
+//               that is n times bigger than the noise of the mean of the
+//               inner pixels (default: 3 sigmabar, clean level 1)
+//
+//
+void MImgCleanStd::CleanStep1()
 {
     const Int_t entries = fEvt->GetNumPixels();
-
-    //
-    // check the number of all pixels against the noise level and
-    // set them to 'unused' state if necessary
-    // 
-
-    for (Int_t i=0; i<entries; i++ )
-    {
-        MCerPhotPix &pix = (*fEvt)[i];
-
-        const Int_t idx = pix.GetPixId();
-
-        const Float_t entry = pix.GetNumPhotons();
-        const Float_t noise = (*fPed)[idx].GetPedestalRms();
-
-        //
-	// We calculate a correction factor which accounts for the 
-	// fact that pixels have different size (see TDAS 02-14).
-	//
-        const Double_t factor = fCam->GetPixRatioSqrt(idx);
-
-        // COBB: '<=' to skip entry=noise=0
-        if (entry * factor <= fCleanLvl1 * noise)
-            pix.SetPixelUnused();
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-//  NT 28/04/2003: now the option to use the standard method or the 
-//  democratic method is implemented:
-//
-//  "KDemocratic": this method looks for all pixels with an entry (photons)
-//                 that is n times bigger than the noise of the mean of the 
-//                 inner pixels (default: 3 sigmabar, clean level 1)
-//
-//  Returns the maximum Pixel Id (used for ispixused in CleanStep2)
-//
-void MImgCleanStd::CleanStep1Dem()
-{
-    const Int_t entries = fEvt->GetNumPixels();
+    const TArrayD &data = fData->GetData();
 
     //
@@ -376,32 +343,6 @@
         MCerPhotPix &pix = (*fEvt)[i];
 
-        const Int_t idx = pix.GetPixId();
-
-        const Float_t  entry = pix.GetNumPhotons();
-        const Double_t ratio = fCam->GetPixRatio(idx);
-
-        // COBB: '<=' to skip entry=noise=0
-        if (entry * ratio <= fCleanLvl1 * fInnerNoise)
+        if (data[pix.GetPixId()] <= fCleanLvl1)
             pix.SetPixelUnused();
-    }
-}
-
-// --------------------------------------------------------------------------
-// The first step of cleaning defines the CORE pixels. All the other pixels 
-// are set as UNUSED and belong to RING 0.		  
-// After this point, only the CORE pixels are set as USED, with RING 	  
-// number 1.								  
-// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
-//
-void MImgCleanStd::CleanStep1()
-{
-   switch (fCleaningMethod)
-    {
-    case kStandard:
-        CleanStep1Std();
-        return;
-    case kDemocratic:
-        CleanStep1Dem();
-        return;
     }
 }
@@ -487,55 +428,4 @@
 } 
 
-
-// --------------------------------------------------------------------------
-//
-//   Look for the boundary pixels around the core pixels
-//   if a pixel has more than 2.5 (clean level 2.5) sigma, and
-//   a core neigbor it is declared as used.
-//
-Bool_t MImgCleanStd::CleanStep3Std(const MCerPhotPix &pix)
-{
-    //
-    // get pixel id of this entry
-    //
-    const Int_t idx = pix.GetPixId();
-
-    //
-    // check the num of photons against the noise level
-    //
-    const Float_t entry = pix.GetNumPhotons();
-    const Float_t noise = (*fPed)[idx].GetPedestalRms();
-
-    //
-    // We calculate a correction factor which accounts for the 
-    // fact that pixels have different size (see TDAS 02-14).
-    //
-    const Double_t factor = fCam->GetPixRatioSqrt(idx);
-
-    return (entry * factor <= fCleanLvl2 * noise);
-}
-
-// --------------------------------------------------------------------------
-//
-//   Look for the boundary pixels around the core pixels
-//   if a pixel has more than 2.5 (clean level 2.5) sigmabar and
-//   a core neighbor, it is declared as used.
-//
-Bool_t MImgCleanStd::CleanStep3Dem(const MCerPhotPix &pix)
-{
-    //
-    // get pixel id of this entry
-    //
-    const Int_t idx = pix.GetPixId();
-
-    //
-    // check the num of photons against the noise level
-    //
-    const Float_t  entry = pix.GetNumPhotons();
-    const Double_t ratio = fCam->GetPixRatio(idx);
-
-    return (entry * ratio <= fCleanLvl2 * fInnerNoise);
-}
-
 void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
 {
@@ -598,11 +488,12 @@
 // --------------------------------------------------------------------------
 //
-//   Look for the boundary pixels around the core pixels
-//   if a pixel has more than 2.5 (clean level 2.5) sigma, and
-//   a core neigbor, it is declared as used.
+//  Look for the boundary pixels around the core pixels
+//  if a pixel has more than 2.5 (clean level 2.5) sigma, and
+//  a core neigbor, it is declared as used.
 //
 void MImgCleanStd::CleanStep3()
 {
     const Int_t entries = fEvt->GetNumPixels();
+    const TArrayD &data = fData->GetData();
 
     for (UShort_t r=1; r<fCleanRings+1; r++)
@@ -621,15 +512,6 @@
                 continue;
 
-            switch (fCleaningMethod)
-            {
-            case kStandard:
-                if (CleanStep3Std(pix))
-                    continue;
-                break;
-            case kDemocratic:
-                if (CleanStep3Dem(pix))
-                    continue;
-                break;
-            }
+            if (data[pix.GetPixId()] <= fCleanLvl2)
+                continue;
 
             if (r==1)
@@ -681,4 +563,8 @@
     }
 
+    fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
+    if (!fData)
+        return kFALSE;
+
     return kTRUE;
 }
@@ -691,5 +577,8 @@
 {
     if (fSgb)
-        fInnerNoise = fSgb->GetSigmabarInner();
+        fData->Calc(*fEvt, *fSgb, *fCam);
+    else
+        fData->Calc(*fEvt, *fPed, *fCam);
+
 #ifdef DEBUG
     *fLog << all << "CleanStep 1" << endl;
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 2487)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 2488)
@@ -11,4 +11,5 @@
 class MCerPhotEvt;
 class MPedestalCam;
+class MCameraData;
 
 class MGGroupFrame;
@@ -27,4 +28,5 @@
           MSigmabar    *fSgb;  //!
           MPedestalCam *fPed;  //!
+          MCameraData  *fData; //!
 
     CleaningMethod_t fCleaningMethod;
@@ -40,8 +42,4 @@
     void StreamPrimitive(ofstream &out) const;
 
-    void   CleanStep1Dem();
-    void   CleanStep1Std();
-    Bool_t CleanStep3Dem(const MCerPhotPix &pix);
-    Bool_t CleanStep3Std(const MCerPhotPix &pix);
     void   CleanStep3b(MCerPhotPix &pix);
     void   CleanStep4(UShort_t r, MCerPhotPix &pix);
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2487)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2488)
@@ -187,6 +187,6 @@
     MFillH            *fill3 = new MFillH(evt3, "MPedestalCam", "MFillH3");
     MFillH            *fill4 = new MFillH(evt4, "MPedestalCam", "MFillH4");
-    MFillH            *fill5 = new MFillH(evt5, "MRelSignal",   "MFillH5");
-    MFillH            *fill6 = new MFillH(evt6, "MRelSignal",   "MFillH6");
+    MFillH            *fill5 = new MFillH(evt5, "MCameraData",  "MFillH5");
+    MFillH            *fill6 = new MFillH(evt6, "MCameraData",  "MFillH6");
     MBlindPixelCalc   *blind = new MBlindPixelCalc;
     MHillasCalc       *hcalc = new MHillasCalc;
@@ -201,6 +201,6 @@
     tlist->AddToList(fill3);
     tlist->AddToList(fill4);
-//    tlist->AddToList(fill5);
-//    tlist->AddToList(fill6);
+    tlist->AddToList(fill5);
+    tlist->AddToList(fill6);
     tlist->AddToList(blind);
     tlist->AddToList(hcalc);
@@ -469,5 +469,5 @@
     //
     TObject *hillas = plist->FindObject("MHillas");
-    for (int i=1; i<5;i++)
+    for (int i=1; i<7;i++)
     {
         TCanvas *c = GetCanvas(i);
