Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 8280)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 8281)
@@ -214,4 +214,12 @@
 }
 
+void MHCamEvent::SetHist(const MHCamera &cam)
+{
+    if (fSum)
+        delete fSum;
+
+    fSum = static_cast<MHCamera*>(cam.Clone());
+}
+
 void MHCamEvent::Paint(Option_t *)
 {
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 8280)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 8281)
@@ -44,4 +44,6 @@
     void SetType(Int_t type) { fType = type; }
 
+    void SetHist(const MHCamera &cam);
+
     TH1 *GetHistByName(const TString name="") const;
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 8280)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 8281)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.97 2007-01-30 14:20:47 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.98 2007-02-01 11:24:18 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -319,44 +319,4 @@
 // ------------------------------------------------------------------------
 //
-// Return the median value on the y-axis (profile option is correctly taken
-// into account)
-//
-Stat_t MHCamera::GetMedian() const
-{
-    // Just for speed reasons
-    if (!TestBit(kProfile))
-        return TMath::Median(GetSize()-2, GetArray()+1);
-
-    // Copy profiled data into new array (FIXME: Should we take errors into account?)
-    TArrayD arr(fNcells-2);
-    for (int i=1; i<fNcells-1; i++)
-        arr[i-1] = GetBinContent(i);
-
-    // return Median of the profile data
-    return TMath::Median(arr.GetSize(), arr.GetArray());
-}
-
-// ------------------------------------------------------------------------
-//
-// Return the median value (divided by MMath::GausProb(1.0)) of the
-// distribution of abs(y[i]-Median). This is my Median equivalent of the RMS
-//
-Stat_t MHCamera::GetMedianDev() const
-{
-    // Just for speed reasons
-    if (!TestBit(kProfile))
-        return MMath::MedianDev(GetSize()-2, GetArray()+1);
-
-    // Copy profiled data into new array (FIXME: Should we take errors into account?)
-    TArrayD arr(fNcells-2);
-    for (int i=1; i<fNcells-1; i++)
-        arr[i-1] = GetBinContent(i);
-
-    // return MedianDev of the profile data
-    return MMath::MedianDev(arr.GetSize(), arr.GetArray());
-}
-
-// ------------------------------------------------------------------------
-//
 // Return the mean value of all entries which are used if all=kFALSE and
 // of all entries if all=kTRUE if sector<0. If sector>=0 only
@@ -388,17 +348,16 @@
 // ------------------------------------------------------------------------
 //
-// Return the sqrt variance of all entries which are used if all=kFALSE and
+// Return the median value of all entries which are used if all=kFALSE and
 // of all entries if all=kTRUE if sector<0. If sector>=0 only
 // entries with match the given sector are taken into account.
 //
-Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
+Stat_t MHCamera::GetMedianSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
 {
     if (fNcells<=1)
-        return -1;
-
+        return 0;
+
+    TArrayD arr(fNcells-2);
     Int_t n=0;
-
-    Stat_t sum = 0;
-    Stat_t sq  = 0;
+ 
     for (int i=0; i<fNcells-2; i++)
     {
@@ -408,4 +367,34 @@
                 continue;
 
+            arr[n++] = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
+        }
+    }
+
+    // return Median of the profile data
+    return TMath::Median(n, arr.GetArray());
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the sqrt variance of all entries which are used if all=kFALSE and
+// of all entries if all=kTRUE if sector<0. If sector>=0 only
+// entries with match the given sector are taken into account.
+//
+Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
+{
+    if (fNcells<=1)
+        return -1;
+
+    Int_t n=0;
+
+    Stat_t sum = 0;
+    Stat_t sq  = 0;
+    for (int i=0; i<fNcells-2; i++)
+    {
+        if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
+        {
+            if (TestBit(kProfile) && fBinEntries[i+1]==0)
+                continue;
+
             const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
 
@@ -423,4 +412,35 @@
 
     return TMath::Sqrt(sq-sum*sum);
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the median value (divided by MMath::GausProb(1.0)=68.3%) of the
+// distribution of abs(y[i]-Median). This is my Median equivalent of the RMS.
+// Return the deviation of all entries which are used if all=kFALSE and
+// of all entries if all=kTRUE if sector<0. If sector>=0 only
+// entries with match the given sector are taken into account.
+//
+Stat_t MHCamera::GetDevSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
+{
+    if (fNcells<=1)
+        return 0;
+
+    TArrayD arr(fNcells-2);
+    Int_t n=0;
+ 
+    for (int i=0; i<fNcells-2; i++)
+    {
+        if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
+        {
+            if (TestBit(kProfile) && fBinEntries[i+1]==0)
+                continue;
+
+            arr[n++] = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
+        }
+    }
+
+    // return Median of the profile data
+    return MMath::MedianDev(n, arr.GetArray());
 }
 
@@ -1391,16 +1411,53 @@
     {
     case 1:
+        // Under-/Overflow bins not handled!
         for (Int_t idx=0; idx<fNcells-2; idx++)
-            Fill(idx, d.GetBinError(idx+1));
+            if (d.IsUsed(idx))
+                Fill(idx, d.GetBinError(idx+1));
+        fEntries++;
         break;
     case 2:
+        // Under-/Overflow bins not handled!
         for (Int_t idx=0; idx<fNcells-2; idx++)
-            if (d.GetBinContent(idx+1)!=0)
+            if (d.GetBinContent(idx+1)!=0 && d.IsUsed(idx))
                 Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
+        fEntries++;
         break;
     default:
+        if (TestBit(kProfile)!=d.TestBit(kProfile))
+            gLog << warn << "WARNING - You have tried to call AddCamContent for two different kind of histograms (kProfile set or not)." << endl;
+
+        // environment
+        fEntries += d.fEntries;
+        fTsumw   += d.fTsumw;
+        fTsumw2  += d.fTsumw2;
+        fTsumwx  += d.fTsumwx;
+        fTsumwx2 += d.fTsumwx2;
+        // Bin contents
+        for (Int_t idx=1; idx<fNcells-1; idx++)
+        {
+            if (!d.IsUsed(idx-1))
+                continue;
+
+            fArray[idx]          += d.fArray[idx];
+            fBinEntries[idx]     += d.fBinEntries[idx];
+            fSumw2.fArray[idx]   += d.fSumw2.fArray[idx];
+        }
+        // Underflow bin
+        fArray[0]                += d.fArray[0];
+        fBinEntries[0]           += d.fBinEntries[0];
+        fSumw2.fArray[0]         += d.fSumw2.fArray[0];
+        // Overflow bin
+        fArray[fNcells-1]        += d.fArray[fNcells-1];
+        fBinEntries[fNcells-1]   += d.fBinEntries[fNcells-1];
+        fSumw2.fArray[fNcells-1] += d.fSumw2.fArray[fNcells-1];
+        break;
+/*    default:
+        if (TestBit(kProfile)!=d.TestBit(kProfile))
+            gLog << warn << "WARNING - You have tried to call AddCamContent for two different kind of histograms (kProfile set or not)." << endl;
+
         for (Int_t idx=0; idx<fNcells-2; idx++)
             Fill(idx, d.GetBinContent(idx+1));
-        break;
+        break;*/
     }
     fEntries++;
@@ -1629,13 +1686,9 @@
     TH1::Reset(opt);
 
-    for (Int_t i=0; i<fNcells-2; i++)
-    {
-        fArray[i+1]=0;
-        fBinEntries[i]=0;
-        ResetUsed(i);
-    }
-
-    fArray[0]         = 0;
-    fArray[fNcells-1] = 0;
+    fUsed.Reset();
+    fBinEntries.Reset();
+
+    for (Int_t i=0; i<fNcells; i++)
+        fArray[i] = 0;
 } 
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 8280)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 8281)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.61 2007-01-30 14:16:45 tbretz Exp $
+!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.62 2007-02-01 11:24:18 tbretz Exp $
 \* ======================================================================== */
 #ifndef MARS_MHCamera
@@ -156,6 +156,6 @@
     virtual void     AddCamContent(const TArrayD &arr, const TArrayC *used=NULL);
     virtual void     AddCamContent(const MArrayD &arr, const TArrayC *used=NULL);
-    virtual void     SetCamContent(const MCamEvent &evt, Int_t type=0) { Reset(); AddCamContent(evt, type); }
-    virtual void     SetCamContent(const MHCamera &d, Int_t type=0) { Reset(); AddCamContent(d, type); fEntries=d.fEntries; }
+    virtual void     SetCamContent(const MCamEvent &evt, Int_t type=0)           { Reset(); AddCamContent(evt, type); }
+    virtual void     SetCamContent(const MHCamera &cam, Int_t type=0)            { Reset(); AddCamContent(cam, type); }
     virtual void     SetCamContent(const TArrayD &evt, const TArrayC *used=NULL) { Reset(); AddCamContent(evt, used); }
     virtual void     SetCamContent(const MArrayD &evt, const TArrayC *used=NULL) { Reset(); AddCamContent(evt, used); }
@@ -243,12 +243,13 @@
     void     AddNotify(TObject *event);
 
-    Stat_t   GetMean(Bool_t ball) const { return GetMeanSectors(TArrayI(), TArrayI(), ball); }
-    Stat_t   GetRMS(Bool_t ball)  const { return GetRmsSectors(TArrayI(), TArrayI(), ball); }
-
-    Stat_t   GetMean(Int_t=0) const { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
-    Stat_t   GetRMS(Int_t=0)  const { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
-
-    Stat_t   GetMedian() const;
-    Stat_t   GetMedianDev() const;
+    Stat_t   GetMean(Bool_t ball) const   { return GetMeanSectors(TArrayI(), TArrayI(), ball); }
+    Stat_t   GetMedian(Bool_t ball) const { return GetMedianSectors(TArrayI(), TArrayI(), ball); }
+    Stat_t   GetRMS(Bool_t ball)  const   { return GetRmsSectors(TArrayI(), TArrayI(), ball); }
+    Stat_t   GetDev(Bool_t ball)  const   { return GetDevSectors(TArrayI(), TArrayI(), ball); }
+
+    Stat_t   GetMean(Int_t=0) const   { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
+    Stat_t   GetMedian(Int_t=0) const { return GetMedianSectors(TArrayI(), TArrayI(), kFALSE); }
+    Stat_t   GetRMS(Int_t=0)  const   { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
+    Stat_t   GetDev(Int_t=0)  const   { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
 
     Stat_t   GetMeanSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
@@ -256,11 +257,21 @@
         return GetMeanSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
     }
+    Stat_t   GetMedianSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
+    {
+        return GetMedianSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
+    }
     Stat_t   GetRmsSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
     {
         return GetRmsSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
     }
+    Stat_t   GetDevSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
+    {
+        return GetDevSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
+    }
 
     Stat_t   GetMeanSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
+    Stat_t   GetMedianSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
     Stat_t   GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
+    Stat_t   GetDevSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
 
     UInt_t   GetNumPixels() const;
