Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2152)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2153)
@@ -1,3 +1,21 @@
                                                  -*-*- END OF LINE -*-*-
+
+ 2003/06/03: Thomas Bretz
+ 
+   * macros/readcurrents.C:
+     - display currents in Log-Scale
+
+   * mgui/MCamDisplay.[h,cc]:
+     - introduced fMinimum
+     - introduced fMaximum
+     - introduced fData
+     - removed Set-functions
+     - introduced Update()
+     - introduced Log-Scale
+
+   * macros/readCT1.C:
+     - fixed a typo
+
+
 
  2003/06/03: Wolfgang Wittek
@@ -45,5 +63,4 @@
    * mhist/MH.[h,cc]:
      - added usescreenfactor to MakeDefCanvas
-     
 
 
Index: trunk/MagicSoft/Mars/macros/readcurrents.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readcurrents.C	(revision 2152)
+++ trunk/MagicSoft/Mars/macros/readcurrents.C	(revision 2153)
@@ -79,4 +79,5 @@
     MCamDisplay display(&geomcam);
     display.Draw();
+    gPad->SetLogz();
 
     int gifcnt = 0;
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 2152)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 2153)
@@ -16,8 +16,8 @@
 !
 !
-!   Author(s): Thomas Bretz  05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!   Author(s): Harald Kornmayer 1/2001
+!   Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Harald Kornmayer, 1/2001
 !
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -30,4 +30,7 @@
 // Camera Display. The Pixels are displayed in
 // contents/area [somthing/mm^2]
+//
+// To change the scale to a logarithmic scale SetLogz() of the Pad.
+//
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -72,5 +75,5 @@
 //
 MCamDisplay::MCamDisplay()
-    : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
+    : fGeomCam(NULL), fAutoScale(kTRUE)
 {
     fNumPixels = 0;
@@ -84,4 +87,9 @@
     fLegRadius = NULL;
     fLegDegree = NULL;
+
+    fMinimum = 0;
+    fMaximum = 1;
+
+    //fData.Set(0);
 }
 
@@ -91,5 +99,5 @@
 //
 MCamDisplay::MCamDisplay(MGeomCam *geom)
-    : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
+    : fGeomCam(NULL), fAutoScale(kTRUE), fData(geom->GetNumPixels()), fMinimum(0), fMaximum(1)
 {
     fGeomCam = (MGeomCam*)geom->Clone(); 
@@ -119,4 +127,5 @@
 #endif
         pix.SetFillColor(16);
+        pix.ResetBit(kIsUsed);
     }
 
@@ -176,5 +185,4 @@
     SetPalette(51, 0);
 #endif
-
 }
 
@@ -204,88 +212,4 @@
 }
 
-inline void MCamDisplay::SetPixColor(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
-{
-    if (i>=fNumPixels)
-        return;
-
-    //
-    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
-    //
-    const Float_t ratio = fGeomCam->GetPixRatio(i);
-    const Float_t pnum  = ratio*pix.GetNumPhotons();
-
-    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
-}
-
-inline void MCamDisplay::SetPixColorPedestal(const MPedestalPix &pix, const UInt_t i, Float_t min, Float_t max)
-{
-    if (i>=fNumPixels)
-        return;
-
-    //
-    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
-    //
-    const Float_t ratio = fGeomCam->GetPixRatio(i);
-    const Float_t pnum  = ratio*pix.GetMean();
-
-    (*this)[i].SetFillColor(GetColor(pnum, min, max));
-}
-
-inline void MCamDisplay::SetPixColorError(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
-{
-    if (i>=fNumPixels)
-        return;
-
-    //
-    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
-    //
-    const Float_t ratio = fGeomCam->GetPixRatio(i);
-    const Float_t pnum  = sqrt(ratio)*pix.GetErrorPhot();
-
-    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
-}
-
-inline void MCamDisplay::SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max)
-{
-    //
-    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
-    //
-    // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
-    //    if (entry * ratio <= fCleanLvl1 * noise)
-
-    const Float_t  entry = pix.GetNumPhotons();
-    const Float_t  noise = pix.GetErrorPhot();
-    const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
-
-    const Float_t r = entry*ratio/noise;
-    //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
-
-    (*this)[pix.GetPixId()].SetFillColor(GetColor(r, min, max));
-}
-
-inline void MCamDisplay::SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2)
-{
-    const Int_t maxcolidx = kItemsLegend-1;
-
-    MHexagon &hex = (*this)[pix.GetPixId()];
-
-    // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
-    //    if (entry * ratio <= fCleanLvl1 * noise)
-
-    const Float_t  entry = pix.GetNumPhotons();
-    const Float_t  noise = pix.GetErrorPhot();
-    const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
-
-    const Float_t r = entry*ratio/noise;
-
-    if (r>lvl1)
-        hex.SetFillColor(fColors[4*maxcolidx/5]);
-    else
-        if (r>lvl2)
-            hex.SetFillColor(fColors[maxcolidx/2]);
-        else
-            hex.SetFillColor(fColors[maxcolidx/5]);
-}
-
 // ------------------------------------------------------------------------
 //
@@ -300,5 +224,5 @@
     // gPad->SetFixedAspectRatio()
 
-    TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 750, 600);
+    TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
     pad->SetBorderMode(0);
     pad->SetFillColor(16);
@@ -326,4 +250,39 @@
 }
 
+void MCamDisplay::Update(Bool_t islog)
+{
+    // FIXME: Don't do this if nothing changed!
+    if (fAutoScale)
+    {
+        fMinimum =  FLT_MAX;
+        fMaximum = -FLT_MAX;
+
+        for (UInt_t i=0; i<fNumPixels; i++)
+        {
+            if (!(*this)[i].TestBit(kIsUsed))
+                continue;
+
+            if (fData[i]<fMinimum)
+                fMinimum = fData[i];
+            if (fData[i]>fMaximum)
+                fMaximum = fData[i];
+        }
+    }
+
+    if (fMinimum==fMaximum)
+        fMaximum = fMinimum + 1;
+
+    UpdateLegend(fMinimum, fMaximum, islog);
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        if ((*this)[i].TestBit(kIsUsed))
+            (*this)[i].SetFillColor(GetColor(fData[i], fMinimum, fMaximum, islog));
+        else
+            (*this)[i].SetFillColor(10);
+
+    }
+}
+
 // ------------------------------------------------------------------------
 //
@@ -337,17 +296,14 @@
         return;
 
-    //
     // Maintain aspect ratio
-    //
     SetRange();
 
-    //
     // Maintain colors
-    //
     SetPalette();
 
-    //
+    // Update Contents of the pixels
+    Update(gPad->GetLogz());
+
     // Paint Legend
-    //
     fArrowX->Paint(">");
     fArrowY->Paint(">");
@@ -356,7 +312,5 @@
     fLegDegree->Paint();
 
-    //
     // Paint primitives (pixels, color legend, photons, ...)
-    //
     { fPixels->ForEach(TObject, Paint)(); }
     { fLegend->ForEach(TObject, Paint)(); }
@@ -495,29 +449,6 @@
 void MCamDisplay::FillPhotNum(const MCerPhotEvt &event)
 {
-    //
-    // Reset pixel colors to default value
-    //
     Reset();
 
-    //
-    //  if the autoscale is true, set the values for the range for
-    //  each event
-    //
-    Float_t min = 0;
-    Float_t max = 50;
-    if (fAutoScale)
-    {
-        min = event.GetNumPhotonsMin(fGeomCam);
-        max = event.GetNumPhotonsMax(fGeomCam);
-
-        if (max==min)
-            max = min +1;
-
-        UpdateLegend(min, max);
-    }
-
-    //
-    //   update the colors in the picture
-    //
     const Int_t entries = event.GetNumPixels();
 
@@ -525,9 +456,11 @@
     {
         const MCerPhotPix &pix = event[i];
-
         if (!pix.IsPixelUsed())
             continue;
 
-        SetPixColor(pix, i, min, max);
+        const Int_t id = pix.GetPixId();
+
+        fData[id] = pix.GetNumPhotons()*fGeomCam->GetPixRatio(id);
+        (*this)[id].SetBit(kIsUsed);
     }
 }
@@ -540,33 +473,12 @@
 void MCamDisplay::FillPedestals(const MPedestalCam &event)
 {
-    //
-    // Reset pixel colors to default value
-    //
     Reset();
 
-    //
-    //  if the autoscale is true, set the values for the range for
-    //  each event
-    //
-    Float_t min = 0;
-    Float_t max = 50;
-    if (fAutoScale)
-    {
-        min = event.GetMeanMin(fGeomCam);
-        max = event.GetMeanMax(fGeomCam);
-
-        if (max==min)
-            max = min +1;
-
-        UpdateLegend(min, max);
-    }
-
-    //
-    //   update the colors in the picture
-    //
     const Int_t entries = event.GetSize();
-
     for (Int_t i=0; i<entries; i++)
-        SetPixColorPedestal(event[i], i, min, max);
+    {
+        fData[i] = event[i].GetMean()*fGeomCam->GetPixRatio(i);
+        (*this)[i].SetBit(kIsUsed);
+    }
 }
 
@@ -578,29 +490,6 @@
 void MCamDisplay::FillErrorPhot(const MCerPhotEvt &event)
 {
-    //
-    // Reset pixel colors to default value
-    //
     Reset();
 
-    //
-    //  if the autoscale is true, set the values for the range for
-    //  each event
-    //
-    Float_t min = 0;
-    Float_t max = 50;
-    if (fAutoScale)
-    {
-        min = event.GetErrorPhotMin(fGeomCam);
-        max = event.GetErrorPhotMax(fGeomCam);
-
-        if (max==min)
-            max = min +1;
-
-        UpdateLegend(min, max);
-    }
-
-    //
-    //   update the colors in the picture
-    //
     const Int_t entries = event.GetNumPixels();
 
@@ -608,9 +497,11 @@
     {
         const MCerPhotPix &pix = event[i];
-
         if (!pix.IsPixelUsed())
             continue;
 
-        SetPixColorError(pix, i, min, max);
+        const Int_t id = pix.GetPixId();
+
+        fData[id] = pix.GetErrorPhot()*sqrt(fGeomCam->GetPixRatio(id));
+        (*this)[id].SetBit(kIsUsed);
     }
 }
@@ -623,26 +514,6 @@
 void MCamDisplay::FillRatio(const MCerPhotEvt &event)
 {
-    //
-    // Reset pixel colors to default value
-    //
     Reset();
 
-    //
-    //  if the autoscale is true, set the values for the range for
-    //  each event
-    //
-    Float_t min = 0;
-    Float_t max = 20;
-    if (fAutoScale)
-    {
-        min = event.GetRatioMin(fGeomCam);
-        max = event.GetRatioMax(fGeomCam);
-
-        UpdateLegend(min, max);
-    }
-
-    //
-    //   update the colors in the picture
-    //
     const Int_t entries = event.GetNumPixels();
 
@@ -654,5 +525,12 @@
             continue;
 
-        SetPixColorRatio(pix, min, max);
+        const Int_t id = pix.GetPixId();
+
+        const Float_t  entry = pix.GetNumPhotons();
+        const Float_t  noise = pix.GetErrorPhot();
+        const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(id));
+
+        fData[id] = entry*ratio/noise;
+        (*this)[id].SetBit(kIsUsed);
     }
 }
@@ -664,31 +542,14 @@
 void MCamDisplay::FillCurrents(const MCurrents &event)
 {
-    //
-    // Reset pixel colors to default value
-    //
     Reset();
 
-    //
-    //  if the autoscale is true, set the values for the range for
-    //  each event
-    //
-    Float_t min = 0;
-    Float_t max = 20;
-    if (fAutoScale)
-    {
-        min = event.GetMin();
-        max = event.GetMax();
-
-        UpdateLegend(min, max);
-    }
-
-    //
-    //   update the colors in the picture
-    //
     // FIXME: Security check missing!
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
-        (*this)[i].SetFillColor(GetColor(event[i], min, max));
+        if (event[i]<=0)
+            continue;
+
+        (*this)[i].SetBit(kIsUsed);
+        fData[i] = event[i];
     }
 }
@@ -700,22 +561,18 @@
 void MCamDisplay::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
 {
-    //
-    // Reset pixel colors to default value
-    //
-    Reset();
-
-    //
-    //   update the colors in the picture
-    //
-    const Int_t entries = event.GetNumPixels();
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        const MCerPhotPix &pix = event[i];
-
-        if (!pix.IsPixelUsed())
+    FillRatio(event);
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        if (!(*this)[i].TestBit(kIsUsed))
             continue;
 
-        SetPixColorLevel(pix, lvl1, lvl2);
+        if (fData[i]>lvl1)
+            fData[i] = 0;
+        else
+            if (fData[i]>lvl2)
+                fData[i] = 1;
+            else
+                fData[i] = 2;
     }
 }
@@ -775,5 +632,4 @@
     const Int_t entries = event.GetNumPhotons();
 
-    TArrayF arr(fNumPixels);
     for (Int_t i=0; i<entries; i++)
     {
@@ -789,40 +645,29 @@
             continue;
 
-        arr[id] += 1;
-    }
-
-    //
-    // Scale with the area and determin maximum
-    //
-    Float_t max = 0;
+        fData[id] += fGeomCam->GetPixRatio(id);
+    }
+
+    //
+    // Set color of pixels
+    //
     for (UInt_t id=0; id<fNumPixels; id++)
-    {
-        arr[id] *= fGeomCam->GetPixRatio(id);
-        if (arr[id]>max)
-            max = arr[id];
-    }
-
-    //
-    // Update legend
-    //
+        if (fData[id]>0)
+            (*this)[id].SetBit(kIsUsed);
+}
+
+// ------------------------------------------------------------------------
+//
+// Reset the all pixel colors to a default value
+//
+void MCamDisplay::Reset()
+{
+    for (UInt_t i=0; i<fNumPixels; i++)
+        (*this)[i].ResetBit(kIsUsed);
+
     if (fAutoScale)
-        UpdateLegend(0, max==0 ? 1 : max);
-
-    //
-    // Set color of pixels
-    //
-    for (UInt_t id=0; id<fNumPixels; id++)
-        if (arr[id]>0)
-            (*this)[id].SetFillColor(GetColor(arr[id], 0, max));
-}
-
-// ------------------------------------------------------------------------
-//
-// Reset the all pixel colors to a default value
-//
-void MCamDisplay::Reset()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-        (*this)[i].SetFillColor(10);
+    {
+        fMinimum = 0;
+        fMaximum = 0;
+    }
 } 
 
@@ -838,5 +683,5 @@
 //  with 0 up to 49.
 //
-Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
+Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
 {
     //
@@ -854,7 +699,10 @@
     // calculate the color index
     //
-    const Float_t ratio  = (val-min) / (max-min);
-    const Int_t   colidx = (Int_t)(ratio*maxcolidx + .5);
-
+    Float_t ratio;
+    if (islog && min>0)
+        ratio = log10(val/min) / log10(max/min);
+    else
+        ratio = (val-min) / (max-min);
+    const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
     return fColors[colidx];
 }
@@ -864,9 +712,15 @@
 //  Change the text on the legend according to the range of the Display
 //
-void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
+void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe, Bool_t islog)
 {
     for (Int_t i=0; i<kItemsLegend; i+=3)
     {
-        const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
+        const Float_t pos = (Float_t)i/kItemsLegend;
+
+        Float_t val;
+        if (islog && minphe>0)
+            val = pow(10, log10(maxphe/minphe)*pos) * minphe;
+        else
+            val = minphe + pos * (maxphe-minphe);
 
         TText &txt = *GetText(i);
@@ -928,9 +782,12 @@
 // ------------------------------------------------------------------------
 //
-// Function introduced  (31-01-03)
+// Function introduced  (31-01-03)  WILL BE REMOVED IN THE FUTURE! DON'T
+// USE IT!
 //
 void MCamDisplay::SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max)
-{ 
-    (*this)[pixnum].SetFillColor(GetColor(color, min, max));
+{
+    fData[pixnum] = color;
+    (*this)[pixnum].SetBit(kIsUsed);
+    (*this)[pixnum].SetFillColor(GetColor(color, min, max, 0));
 }
 
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 2152)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 2153)
@@ -8,7 +8,11 @@
 #include <Gtypes.h>
 #endif
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
 #endif
+
 
 class TBox;
@@ -49,6 +53,7 @@
     TClonesArray  *fPhotons;     // array of reflector photons
  
-    UInt_t         fW;           // Width of canvas
-    UInt_t         fH;           // Height of canvas
+    TArrayF        fData;
+    Float_t        fMinimum;
+    Float_t        fMaximum;
 
     TBox  *GetBox(Int_t i)  { return (TBox*) fLegend->At(i); }
@@ -57,14 +62,14 @@
     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
 
-    void  SetPixColor(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max);
-    void  SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max);
-    void  SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2);
-    void  SetPixColorError(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max);
-    void  SetPixColorPedestal(const MPedestalPix &pix, const UInt_t i, Float_t min, Float_t max);
-    Int_t GetColor(Float_t val, Float_t min, Float_t max);
+    Int_t GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog);
 
-    void UpdateLegend(Float_t min, Float_t max);
-    void SetRange();
-    void SetPalette();
+    void  Update(Bool_t islog);
+    void  UpdateLegend(Float_t min, Float_t max, Bool_t islog);
+    void  SetRange();
+    void  SetPalette();
+
+    enum {
+        kIsUsed = BIT(14)
+    };
 
 public:
@@ -73,16 +78,16 @@
     ~MCamDisplay();
 
-    void SetAutoScale(Bool_t input=kTRUE) { fAutoScale = input; }
-    void FillPhotNum(const MCerPhotEvt &event);
-    void FillRatio(const MCerPhotEvt &event);
-    void FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2);
-    void FillErrorPhot(const MCerPhotEvt &event);
-    void FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean);
-    void FillPedestals(const MPedestalCam &event);
-    void FillRflEvent(const MRflEvtData &event);
-    void FillCurrents(const MCurrents &event);
-    void ShowRflEvent(const MRflEvtData *event=NULL, EMarkerStyle m=kFullDotMedium);
+    void  SetAutoScale(Bool_t input=kTRUE) { fAutoScale = input; }
+    void  FillPhotNum(const MCerPhotEvt &event);
+    void  FillRatio(const MCerPhotEvt &event);
+    void  FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2);
+    void  FillErrorPhot(const MCerPhotEvt &event);
+    void  FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean);
+    void  FillPedestals(const MPedestalCam &event);
+    void  FillRflEvent(const MRflEvtData &event);
+    void  FillCurrents(const MCurrents &event);
+    void  ShowRflEvent(const MRflEvtData *event=NULL, EMarkerStyle m=kFullDotMedium);
 
-    void DrawPixelNumbers();
+    void  DrawPixelNumbers();
 
     void  Paint(Option_t *option="");
@@ -94,11 +99,14 @@
     //virtual void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
 
-    void SetPalette(Int_t ncolors, Int_t *colors);
+    void  SetPalette(Int_t ncolors, Int_t *colors);
 
-    void SetPrettyPalette(); // *MENU*
-    void SetDeepBlueSeaPalette(); // *MENU*
-    void SetInvDeepBlueSeaPalette(); // *MENU*
+    void  SetPrettyPalette(); // *MENU*
+    void  SetDeepBlueSeaPalette(); // *MENU*
+    void  SetInvDeepBlueSeaPalette(); // *MENU*
 
-    void SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max);      // New function added by M.Lopez in 31-01-03
+    void  SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max);      // New function added by M.Lopez in 31-01-03
+
+    void  SetMinimum(Float_t m) { fMinimum = m; }
+    void  SetMaximum(Float_t m) { fMaximum = m; }
 
     ClassDef(MCamDisplay, 0) // Displays the magic camera
