Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8280)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8281)
@@ -18,4 +18,21 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2007/02/01 Thomas Bretz
+
+   * mhist/MHCamEvent.[h,cc]:
+     - allow to set a histogram for display from external
+
+   * mhist/MHCamera.[h,cc]:
+     - added functions to calc Median/Dev
+     - fixed adding a MHCamera with AddCamContent. It now takes also
+       the errors and binentries correctly into account
+     - simplified Reset() using TArray::Reset()
+
+   * mhvstime/MHSectorVsTime.[h,cc]:
+     - added option to use median/dev instead of mean/rms
+     - switched Grid on
+
+
 
  2007/01/30 Thomas Bretz
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;
Index: /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc	(revision 8280)
+++ /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc	(revision 8281)
@@ -1,3 +1,5 @@
 /* ======================================================================== *\
+! $Name: not supported by cvs2svn $:$Id: MHSectorVsTime.cc,v 1.13 2007-02-01 11:24:19 tbretz Exp $
+! --------------------------------------------------------------------------
 !
 ! *
@@ -18,5 +20,5 @@
 !   Author(s): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2006
 !
 !
@@ -70,4 +72,8 @@
 //  + Double_t fMaximum;      // User defined maximum
 //
+// Class Version 3:
+// ----------------
+//  + Bool_t fUseMedian;     
+//
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -101,5 +107,5 @@
 //
 MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
-    : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111),
+    : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111), fUseMedian(kFALSE),
     fType(0), fTypeErr(-1)
 {
@@ -226,5 +232,7 @@
     fHCamera.SetCamContent(*evt, fType);
 
-    const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
+    const Double_t val0 = fUseMedian ?
+        fHCamera.GetMedianSectors(fSectors, fAreaIndex) :
+        fHCamera.GetMeanSectors(fSectors, fAreaIndex);
 
     if (!TMath::Finite(val0))
@@ -235,7 +243,11 @@
     if (fTypeErr>=0)
     {
-        const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
+        const Double_t rms0 = fUseMedian ?
+            fHCamera.GetDevSectors(fSectors, fAreaIndex) :
+
+            fHCamera.GetRmsSectors(fSectors, fAreaIndex);
         if (!TMath::Finite(rms0))
             return kTRUE;
+
         ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
     }
@@ -334,4 +346,6 @@
     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
     pad->SetBorderMode(0);
+    pad->SetGridx();
+    pad->SetGridy();
     AppendPad(opt);
 }
Index: /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.h	(revision 8280)
+++ /trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.h	(revision 8281)
@@ -1,2 +1,5 @@
+/* ======================================================================== *\
+!  $Name: not supported by cvs2svn $:$Id: MHSectorVsTime.h,v 1.7 2007-02-01 11:24:19 tbretz Exp $
+\* ======================================================================== */
 #ifndef MARS_MHSectorVsTime
 #define MARS_MHSectorVsTime
@@ -25,13 +28,13 @@
 
 private:
-    TGraph *fGraph;
+    TGraph *fGraph;         // The TGraph output to the display
 
-    MCamEvent *fEvt;        //! the current event
-    MGeomCam  *fCam;        //! the camera geometry
+    MCamEvent *fEvt;        //! pointer to the current event
+    MGeomCam  *fCam;        //! pointer the camera geometry
 
-    MRawEvtHeader *fHeader; //!
-    MTime         *fTime;   //!
+    MRawEvtHeader *fHeader; //! pointer to the event header (DAQ Evt number instead of counter)
+    MTime         *fTime;   //! pointer to event time (time instead of number)
 
-    MHCamera fHCamera;      //!
+    MHCamera fHCamera;      //! The camera to be used for calculation
 
     Double_t fMin;          //! Calculation of minimum
@@ -41,12 +44,14 @@
     Double_t fMaximum;      // User defined maximum
 
-    TString fNameEvt;
-    TString fNameTime;
+    Bool_t fUseMedian;      // Whether to display median/dev instead of mean/rms
 
-    Int_t fType;
-    Int_t fTypeErr;
+    TString fNameEvt;       // Name of MCamEvent to be displayed
+    TString fNameTime;      // Name of MTime container to be used
 
-    TArrayI fSectors;
-    TArrayI fAreaIndex;
+    Int_t fType;            // Type for mean  used in GetPixelContent
+    Int_t fTypeErr;         // Type for error used in GetPixelContent (-1 = no error)
+
+    TArrayI fSectors;       // Which sectors shell be displayed
+    TArrayI fAreaIndex;     // Which pixel sized should be displayed
 
     // MH
@@ -69,4 +74,6 @@
     void SetMaximum(Double_t max=-1111) { fMaximum = max; }
 
+    void SetUseMedian(Bool_t b=kTRUE) { fUseMedian=b; }
+
     // Getter
     TH1 *GetHistByName(const TString name="") const;
@@ -80,5 +87,5 @@
     void Paint(Option_t *o=NULL);
 
-    ClassDef(MHSectorVsTime, 2) // Histogram to sum camera events
+    ClassDef(MHSectorVsTime, 3) // Histogram to sum camera events
 };
 
