Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 6855)
@@ -18,5 +18,5 @@
 #pragma link C++ class MHAlphaEnergyTheta+;
 #pragma link C++ class MHGamma+;
-#pragma link C++ class MHSigmaTheta;
+//#pragma link C++ class MHSigmaTheta;
 #pragma link C++ class MHThetabarTime+;
 #pragma link C++ class MHThetabarTheta+;
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 6855)
@@ -33,9 +33,4 @@
 // =====
 //
-// To plot sqrt(variance) instead of the rms use:
-//    MHCamEvent::SetBit(MHCamera::kSqrtVariance);
-//  or
-//    MHCamEvent::EnableSqrtVariance()
-//
 // To count how often a certain pixel is above or below a threshold do:
 //    MHCamEvent::SetThreshold(5.5);  // Default=LowerBound
@@ -121,13 +116,4 @@
     if (fSum)
         delete fSum;
-}
-
-// --------------------------------------------------------------------------
-//
-// use this to display the variance instead of the rms.
-//
-void MHCamEvent::EnableSqrtVariance(Bool_t b)
-{
-    b ? SetBit(MHCamera::kSqrtVariance) : ResetBit(MHCamera::kSqrtVariance);
 }
 
@@ -173,6 +159,4 @@
         fSum->SetYTitle("a.u.");
     fSum->SetBit(MHCamera::kProfile);
-    if (TestBit(MHCamera::kSqrtVariance))
-        fSum->SetBit(MHCamera::kSqrtVariance);
 
     fSum->SetXTitle("Pixel Idx");
@@ -261,28 +245,22 @@
 {
     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
+    const Int_t col = pad->GetFillColor();
     pad->SetBorderMode(0);
 
     AppendPad();
 
-    TString name = Form("%s_5", pad->GetName());
-    TPad *p = new TPad(name,name,6./8,0.25,0.99,0.5,pad->GetFillColor(),0,0);
-    p->SetNumber(5);
-    p->Draw();
-
-    name = Form("%s_6", pad->GetName());
-    p = new TPad(name,name,6./8,0.01,0.99,0.25,pad->GetFillColor(),0,0);
-    p->SetNumber(6);
-    p->Draw();
-
-    pad->Divide(2,2);
-
-    pad->cd(1);
-    gPad->SetBorderMode(0);
-    gPad->SetPad(0.01, 0.5, 0.66, 0.99);
+    TString name = Form("%s_1", pad->GetName());
+    TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
+    p->SetNumber(1);
+    p->Draw();
+    p->cd();
     fSum->Draw("EPhist");
 
-    pad->cd(2);
-    gPad->SetBorderMode(0);
-    gPad->SetPad(0.66, 0.5, 0.99, 0.99);
+    pad->cd();
+    name = Form("%s_2", pad->GetName());
+    p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
+    p->SetNumber(2);
+    p->Draw();
+    p->cd();
     TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
     h->SetTitle("Projection");
@@ -290,16 +268,22 @@
     h->Draw();
 
-    pad->cd(3);
-    gPad->SetPad(0.01, 0.01, 3./8, 0.5);
-    gPad->SetBorderMode(0);
+    pad->cd();
+    name = Form("%s_3", pad->GetName());
+    p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
+    p->SetNumber(3);
+    p->Draw();
+    p->cd();
     fSum->Draw();
 
-    pad->cd(4);
-    gPad->SetPad(3./8, 0.01, 6./8, 0.5);
-    gPad->SetBorderMode(0);
+    pad->cd();
+    name = Form("%s_4", pad->GetName());
+    p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
+    p->SetNumber(4);
+    p->Draw();
+    p->cd();
 
     MHCamera *cam = new MHCamera(*fSum->GetGeometry());
     cam->SetName(Form("%s;err", fName.Data()));
-    cam->SetTitle(fSum->TestBit(MHCamera::kSqrtVariance)?"Sqrt(Variance)":"Root Mean Squared (rms)");
+    cam->SetTitle("Sqrt(Variance)");
     cam->SetYTitle(fSum->GetYaxis()->GetTitle());
     cam->SetCamContent(*fSum, 1);
@@ -307,5 +291,10 @@
     cam->Draw();
 
-    pad->cd(5);
+    pad->cd();
+    name = Form("%s_5", pad->GetName());
+    p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
+    p->SetNumber(5);
+    p->Draw();
+    p->cd();
     h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
     h->SetTitle("Radial Profile");
@@ -313,5 +302,10 @@
     h->Draw();
 
-    pad->cd(6);
+    pad->cd();
+    name = Form("%s_6", pad->GetName());
+    p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
+    p->SetNumber(6);
+    p->Draw();
+    p->cd();
     h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
     h->SetTitle("Azimuth Profile");
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 6855)
@@ -15,4 +15,5 @@
     static const TString gsDefTitle;
 
+protected:
     MHCamera  *fSum;       // storing the sum
     MCamEvent *fEvt;       //! the current event
@@ -50,5 +51,4 @@
 
     void SetThreshold(Float_t f, Char_t direction=kIsLowerBound) { fThreshold = f; fUseThreshold=direction; }
-    void EnableSqrtVariance(Bool_t b=kTRUE);
 
     ClassDef(MHCamEvent, 1) // Histogram to sum camera events
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 6855)
@@ -164,5 +164,8 @@
     fUsed.Set(geom.GetNumPixels());
     for (Int_t i=0; i<fNcells-2; i++)
-      ResetUsed(i);
+        ResetUsed(i);
+
+    fBinEntries.Set(geom.GetNumPixels()+2);
+    fBinEntries.Reset();
 }
 
@@ -213,4 +216,5 @@
    const Int_t bin = (Int_t)x+1;
    AddBinContent(bin);
+   fBinEntries[bin]++;
    if (fSumw2.fN)
        fSumw2.fArray[bin]++;
@@ -249,4 +253,5 @@
    const Int_t bin = (Int_t)x+1;
    AddBinContent(bin, w);
+   fBinEntries[bin]++;
    if (fSumw2.fN)
        fSumw2.fArray[bin] += w*w;
@@ -319,10 +324,13 @@
         if ((all || IsUsed(i)) && MatchSector(i, sector, aidx))
         {
-            mean += fArray[i+1];
+            if (TestBit(kProfile) && fBinEntries[i+1]==0)
+                continue;
+
+            mean += TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
             n++;
         }
     }
 
-    return n==0 ? 0 : Profile(mean/n);
+    return n==0 ? 0 : mean/n;
 }
 
@@ -346,6 +354,11 @@
         if ((all || IsUsed(i)) && MatchSector(i, sector, aidx))
         {
-            sum += fArray[i+1];
-            sq  += fArray[i+1]*fArray[i+1];
+            if (TestBit(kProfile) && fBinEntries[i+1]==0)
+                continue;
+
+            const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
+
+            sum += val;
+            sq  += val*val;
             n++;
         }
@@ -358,5 +371,5 @@
     sq  /= n;
 
-    return Profile(TMath::Sqrt(sq-sum*sum));
+    return TMath::Sqrt(sq-sum*sum);
 }
 
@@ -377,9 +390,15 @@
     Double_t minimum=FLT_MAX;
 
-    for (Int_t idx=0; idx<fNcells-2; idx++)
-        if (MatchSector(idx, sector, aidx) && (all || IsUsed(idx)) && fArray[idx+1]<minimum)
-            minimum = fArray[idx+1];
-
-    return Profile(minimum);
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        if (TestBit(kProfile) && fBinEntries[i+1]==0)
+            continue;
+
+        const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
+        if (MatchSector(i, sector, aidx) && (all || IsUsed(i)) && val<minimum)
+            minimum = val;
+    }
+
+    return minimum;
 }
 
@@ -399,9 +418,15 @@
 
     Double_t maximum=-FLT_MAX;
-    for (Int_t idx=0; idx<fNcells-2; idx++)
-        if (MatchSector(idx, sector, aidx) && (all || IsUsed(idx)) && fArray[idx+1]>maximum)
-            maximum = fArray[idx+1];
-
-    return Profile(maximum);
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        if (TestBit(kProfile) && fBinEntries[i+1]==0)
+            continue;
+
+        const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
+        if (MatchSector(i, sector, aidx) && (all || IsUsed(i)) && val>maximum)
+            maximum = val;
+    }
+
+    return maximum;
 }
 
@@ -458,5 +483,6 @@
         // resized in paint to keep the correct aspect ratio
         //
-        pad->Divide(1, 1, 0, 0, col);
+        // The margin != 0 is a workaround for a problem in root 4.02/00
+        pad->Divide(1, 1, 1e-10, 1e-10, col);
         pad->cd(1);
         gPad->SetBorderMode(0);
@@ -1125,7 +1151,8 @@
         Double_t val=0;
         if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
+        {
             SetUsed(idx);
-
-        Fill(idx, val); // FIXME: Slow!
+            Fill(idx, val); // FIXME: Slow!
+        }
     }
     fEntries++;
@@ -1153,6 +1180,34 @@
 }
 
+Stat_t MHCamera::GetBinContent(Int_t bin) const
+{
+    if (fBuffer) ((TProfile*)this)->BufferEmpty();
+    if (bin < 0) bin = 0;
+    if (bin >= fNcells) bin = fNcells-1;
+    if (!fArray) return 0;
+
+    if (!TestBit(kProfile))
+        return Stat_t (fArray[bin]);
+
+    if (fBinEntries.fArray[bin] == 0) return 0;
+    return fArray[bin]/fBinEntries.fArray[bin];
+}
+
 Stat_t MHCamera::GetBinError(Int_t bin) const
 {
+    if (!TestBit(kProfile))
+        return TH1D::GetBinError(bin);
+
+    const UInt_t n = (UInt_t)fBinEntries[bin];
+
+    if (n==0)
+        return 0;
+
+    const Double_t sqr = fSumw2.fArray[bin] / n;
+    const Double_t val = fArray[bin]        / n;
+
+    return sqr>val*val ? TMath::Sqrt(sqr - val*val) / n : 0;
+
+    /*
     Double_t rc = 0;
     if (TestBit(kSqrtVariance) && GetEntries()>0) // error on the mean
@@ -1165,5 +1220,5 @@
         rc = TH1D::GetBinError(bin);
 
-    return Profile(rc);
+    return Profile(rc);*/
 }
 
@@ -1266,12 +1321,49 @@
     {
         Double_t val=threshold;
-        if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
+        const Bool_t rc = event.GetPixelContent(val, idx, *fGeomCam, type);
+        if (rc)
+            SetUsed(idx);
+
+        const Bool_t cond =
+            ( isabove && val>threshold) ||
+            (!isabove && val<threshold);
+
+        Fill(idx, rc && cond ? 1 : 0);
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to add a MCamEvent on top of the present contents.
+// - the contents of the pixels in event are added to each pixel
+//   if the pixel of thresevt<threshold (in case isabove is set
+//   to kTRUE == default)
+// - the contents of the pixels in event are  added to each pixel
+//   if the pixel of thresevt<threshold (in case isabove is set
+//   to kFALSE)
+//
+// in unused pixel is not counted if it didn't fullfill the condition.
+//
+void MHCamera::CntCamContent(const MCamEvent &event, Int_t type1, const MCamEvent &thresevt, Int_t type2, Double_t threshold, Bool_t isabove)
+{
+    if (fNcells<=1 || IsFreezed())
+        return;
+
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Double_t th=0;
+        if (!thresevt.GetPixelContent(th, idx, *fGeomCam, type2))
+            continue;
+
+        if ((isabove && th>threshold) || (!isabove && th<threshold))
+            continue;
+
+        Double_t val=th;
+        if (event.GetPixelContent(val, idx, *fGeomCam, type1))
         {
             SetUsed(idx);
-
-            if (isabove && val>threshold)
-                Fill(idx);
-            if (!isabove && val<threshold)
-                Fill(idx);
+            Fill(idx, val);
         }
     }
@@ -1672,5 +1764,5 @@
         return;
 
-    gLog << all << GetTitle() << " <" << GetName() << ">" << endl;
+    gLog << all << GetTitle() << " <" << GetName() << ">" << dec << endl;
     gLog << "Software Pixel Idx: " << idx << endl;
     gLog << "Hardware Pixel Id:  " << idx+1 << endl;
@@ -1678,5 +1770,5 @@
     if (GetBinError(idx+1)>0)
         gLog << " +/- " << GetBinError(idx+1);
-    gLog << "  <" << (IsUsed(idx)?"on":"off") << ">" << endl;
+    gLog << "  <" << (IsUsed(idx)?"on":"off") << ">  n=" << fBinEntries[idx+1] << endl;
 
     if (fNotify && fNotify->GetSize()>0)
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 6855)
@@ -10,7 +10,4 @@
 #ifndef ROOT_TArrayI
 #include <TArrayI.h>
-#endif
-#ifndef ROOT_TArrayD
-#include <TArrayD.h>
 #endif
 #ifndef ROOT_MArrayD
@@ -40,12 +37,14 @@
 public:
     enum {
-        kProfile      = BIT(18), // FIXME: When changing change max/min!
-        kFreezed      = BIT(19),
-        kNoLegend     = BIT(20),
-        kSqrtVariance = BIT(21)
+        kProfile            = BIT(18), // FIXME: When changing change max/min!
+        kFreezed            = BIT(19),
+        kNoLegend           = BIT(20)/*,
+        kSqrtVariance       = BIT(21),
+        kSinglePixelProfile = BIT(22)*/
     };
 private:
     MGeomCam      *fGeomCam;     // pointer to camera geometry (y-axis)
     TArrayC        fUsed;        // array containing flags
+    TArrayI        fBinEntries;  // number of entries per bin
 
     TArrayI        fColors;      //! Color conversion table
@@ -59,5 +58,5 @@
 
     void Init();
-
+/*
     Stat_t Profile(Stat_t val) const
     {
@@ -68,5 +67,5 @@
         return n>0 ? val/n : val;
     }
-
+  */
     Int_t GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog);
 
@@ -162,6 +161,7 @@
     virtual void     CntCamContent(const MCamEvent &evt, TArrayD threshold, Int_t type=0, Bool_t isabove=kTRUE);
     virtual void     CntCamContent(const TArrayD &evt, Double_t threshold, Bool_t ispos=kTRUE);
-
-    Stat_t   GetBinContent(Int_t bin) const { return Profile(TH1D::GetBinContent(bin)); }
+    virtual void     CntCamContent(const MCamEvent &event, Int_t type1, const MCamEvent &thresevt, Int_t type2, Double_t threshold, Bool_t isabove);
+
+    Stat_t   GetBinContent(Int_t bin) const;
     Stat_t   GetBinContent(Int_t binx, Int_t biny) const { return GetBinContent(binx); }
     Stat_t   GetBinContent(Int_t binx, Int_t biny, Int_t binz) const { return GetBinContent(binx); }
Index: trunk/MagicSoft/Mars/mhist/MHEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.cc	(revision 6855)
@@ -59,5 +59,5 @@
 #include "MTaskList.h"
 #include "MParList.h"
-#include "MCerPhotEvt.h"
+#include "MSignalCam.h"
 #include "MRawEvtHeader.h"
 #include "MRawRunHeader.h"
@@ -239,5 +239,5 @@
         break;
     case kEvtArrTime:
-        fHist->SetCamContent(*event, 0);
+        fHist->SetCamContent(*event, 6);
         break; 
     case kEvtTrigPix:
Index: trunk/MagicSoft/Mars/mhist/MHEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/MHEvent.h	(revision 6855)
@@ -13,5 +13,5 @@
 class MMcEvt;
 class MMcTrig;
-class MCerPhotEvt;
+class MSignalCam;
 class MImgCleanStd;
 
@@ -34,5 +34,5 @@
     MMcEvt        *fMcEvt;         //!
     MMcTrig       *fMcTrig;        //!
-    MCerPhotEvt   *fCerPhotEvt;    //!
+    MSignalCam    *fCerPhotEvt;    //!
     MImgCleanStd  *fImgCleanStd;   //!
 
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 6569)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 6855)
@@ -40,5 +40,4 @@
            MHThetabarTheta.cc \
            MHGamma.cc \
-           MHSigmaTheta.cc \
 	   MHSigmaPixel.cc \
 	   MHSigmabarTheta.cc \
