Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 2408)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 2409)
@@ -16,12 +16,23 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Harald Kornmayer, 1/2001
+!
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
 \* ======================================================================== */
 
+/////////////////////////////////////////////////////////////////////////////
+//            
+// MCerPhotEvt
+//            
+// Class Version 1:
+//  - first version
+//
+// Class Version 2:
+//  - added fLut to accelerate GetPixById a lot
+//
+/////////////////////////////////////////////////////////////////////////////
 #include "MCerPhotEvt.h"
 
@@ -33,4 +44,5 @@
 
 #include "MLog.h"
+#include "MLogManip.h"
 
 #include "MGeomCam.h"
@@ -56,4 +68,5 @@
 // This is not yet implemented like it should.
 //
+/*
 void MCerPhotEvt::Draw(Option_t* option) 
 {
@@ -69,4 +82,5 @@
     //    disp->DrawPhotNum(this);
 }
+*/
 
 // --------------------------------------------------------------------------
@@ -77,5 +91,6 @@
 {
     fNumPixels = 0;
-//    fPixels->Delete();
+    fLut.Set(0);
+    // fPixels->Delete();
 }
 
@@ -109,13 +124,6 @@
 Bool_t MCerPhotEvt::IsPixelExisting(Int_t id) const
 {
-    const Int_t entries = fPixels->GetEntries();
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        if (id == (*this)[i].GetPixId())
-            return kTRUE;
-    }
-
-    return kFALSE;
+    const MCerPhotPix *pix = GetPixById(id);
+    return pix ? kTRUE : kFALSE;
 } 
 
@@ -126,17 +134,6 @@
 Bool_t MCerPhotEvt::IsPixelUsed(Int_t id) const
 {
-    const Int_t entries = fPixels->GetEntries();
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
-        if (!pix.IsPixelUsed())
-            continue;
-
-        if (id == pix.GetPixId() && pix.IsPixelUsed())
-            return kTRUE;
-    }
-
-    return kFALSE;
+    const MCerPhotPix *pix = GetPixById(id);
+    return pix ? pix->IsPixelUsed() : kFALSE;
 } 
 
@@ -147,17 +144,6 @@
 Bool_t MCerPhotEvt::IsPixelCore(Int_t id) const
 {
-    const Int_t entries = fPixels->GetEntries();
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
-        if (!pix.IsPixelUsed())
-            continue;
-
-        if (id == pix.GetPixId() && pix.IsPixelCore())
-            return kTRUE;
-    } 
-
-    return kFALSE;
+    const MCerPhotPix *pix = GetPixById(id);
+    return pix ? pix->IsPixelCore() : kFALSE;
 } 
 
@@ -350,26 +336,4 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// Return a pointer to the pixel with the requested id. NULL if it doesn't
-// exist.
-//
-MCerPhotPix *MCerPhotEvt::GetPixById(int id) const
-{
-    TIter Next(fPixels);
-    MCerPhotPix *pix = NULL;
-
-    while ((pix=(MCerPhotPix*)Next()))
-        if (pix->GetPixId()==id)
-            return pix;
-
-    return NULL;
-}
-
-void MCerPhotEvt::Scale(Double_t f)
-{
-    fPixels->ForEach(MCerPhotPix, Scale)(f);
-}
-
 void MCerPhotEvt::RemoveUnusedPixels()
 {
@@ -383,4 +347,24 @@
     fPixels->Compress();
     fNumPixels=fPixels->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return a pointer to the pixel with the requested id. NULL if it doesn't
+// exist.
+//
+MCerPhotPix *MCerPhotEvt::GetPixById(int idx) const
+{
+    if (fLut.GetSize()>0)
+        return idx>=0 && idx<fLut.GetSize() ? (MCerPhotPix*)(fPixels->UncheckedAt(fLut[idx])) : 0;
+
+    TIter Next(fPixels);
+    MCerPhotPix *pix = NULL;
+
+    while ((pix=(MCerPhotPix*)Next()))
+        if (pix->GetPixId()==idx)
+            return pix;
+
+    return NULL;
 }
 
@@ -425,2 +409,7 @@
     return kTRUE;
 }
+
+void MCerPhotEvt::DrawPixelContent(Int_t num, TVirtualPad *pad=NULL) const
+{
+    *fLog << warn << "MCerPhotEvt::DrawPixelContent - not available." << endl;
+}
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2408)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2409)
@@ -80,4 +80,6 @@
 void MHCamera::Init()
 {
+    UseCurrentStyle();
+
     SetDirectory(NULL);
 
@@ -241,5 +243,5 @@
 Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w)
 {
-    if (fNcells<=1)
+    if (fNcells<=1 || IsFreezed())
         return -1;
 
@@ -265,5 +267,5 @@
         mean += fArray[i];
 
-    return mean/(fNcells-2);
+    return Profile(mean/(fNcells-2));
 }
 
@@ -286,5 +288,5 @@
     sq  /= n;
 
-    return sqrt(sq-sum*sum);
+    return Profile(sqrt(sq-sum*sum));
 }
 
@@ -297,5 +299,5 @@
 {
     if (fMinimum != -1111)
-        return fMinimum;
+        return Profile(fMinimum);
 
     if (fNcells<=1)
@@ -316,5 +318,5 @@
                 minimum = fArray[idx+1];
     }
-    return minimum;
+    return Profile(minimum);
 }
 
@@ -326,6 +328,6 @@
 Double_t MHCamera::GetMaximum(Bool_t all) const
 {
-    if (fMaximum != -1111)
-        return fMaximum;
+    if (fMaximum!=-1111)
+        return Profile(fMaximum);
 
     if (fNcells<=1)
@@ -345,5 +347,5 @@
                 maximum = fArray[idx+1];
     }
-    return maximum;
+    return Profile(maximum);
 }
 
@@ -455,5 +457,5 @@
                 gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl;
 
-            hex.SetFillColor(GetColor(fArray[i+1], min, max, islog));
+            hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
         }
         else
@@ -466,5 +468,5 @@
             if (IsUsed(i) && !TMath::IsNaN(fArray[i+1]))
             {
-                Float_t size = pix.GetD()*(fArray[i+1]-min)/(max-min);
+                Float_t size = pix.GetD()*(GetBinContent(i+1)-min)/(max-min);
                 if (size>pix.GetD())
                     size=pix.GetD();
@@ -673,5 +675,5 @@
 void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
 {
-    if (fNcells<=1)
+    if (fNcells<=1 || IsFreezed())
         return;
 
@@ -699,5 +701,5 @@
 void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
 {
-    if (fNcells!=d.fNcells)
+    if (fNcells!=d.fNcells || IsFreezed())
         return;
 
@@ -733,5 +735,5 @@
 void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
 {
-    if (event.GetSize()!=fNcells-2)
+    if (event.GetSize()!=fNcells-2 || IsFreezed())
         return;
 
@@ -756,5 +758,5 @@
 void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
 {
-    if (fNcells<=1)
+    if (fNcells<=1 || IsFreezed())
         return;
 
@@ -779,5 +781,5 @@
 void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
 {
-    if (event.GetSize()!=fNcells-2)
+    if (event.GetSize()!=fNcells-2 || IsFreezed())
         return;
 
@@ -799,5 +801,5 @@
 void MHCamera::FillRandom()
 {
-    if (fNcells<=1)
+    if (fNcells<=1 || IsFreezed())
         return;
 
@@ -855,5 +857,5 @@
 void MHCamera::Reset(Option_t *opt)
 {
-    if (fNcells<=1)
+    if (fNcells<=1 || IsFreezed())
         return;
 
@@ -1127,11 +1129,13 @@
     cout << "Software Pixel Index: " << idx << endl;
     cout << "Hardware Pixel Id:    " << idx+1 << endl;
-    cout << "Contents:             " << fArray[idx+1] << "  <";
+    cout << "Contents:             " << GetBinContent(idx+1) << "  <";
     cout << (IsUsed(idx)?"on":"off");
     cout << ">" << endl;
 
     if (fNotify && fNotify->GetSize()>0)
-        new TCanvas;
-    fNotify->ForEach(MCamEvent, DrawPixelContent)(idx);
+    {
+        TCanvas *c=new TCanvas;
+        fNotify->ForEach(MCamEvent, DrawPixelContent)(idx, c);
+    }
 }
 
@@ -1140,2 +1144,8 @@
     return fGeomCam->GetNumPixels();
 }
+
+TH1 *MHCamera::DrawCopy() const
+{
+    gPad=NULL;
+    return TH1D::DrawCopy();
+} 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2408)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2409)
@@ -28,4 +28,9 @@
 class MHCamera : public TH1D
 {
+public:
+    enum {
+        kProfile = BIT(18),
+        kFreezed = BIT(19)
+    };
 private:
     MGeomCam      *fGeomCam;     // pointer to camera geometry (y-axis)
@@ -35,8 +40,19 @@
     TList         *fNotify;      //!
 
+    Bool_t         fFreezed;     //! Just a dummy!!!! ([Set,Is]Freezed)
+
     //Int_t          fOptStat;
-
     //TGStatusBar   *fStatusBar;
+
     void Init();
+
+    Stat_t Profile(Stat_t val) const
+    {
+        if (!TestBit(kProfile))
+            return val;
+
+        const Stat_t n = TH1D::GetEntries();
+        return n>0 ? val/n : val;
+    }
 
     Int_t GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog);
@@ -109,4 +125,11 @@
     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)); }
+    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); }
+    Stat_t GetBinError(Int_t bin) const { return Profile(TH1D::GetBinError(bin)); }
+    Stat_t GetBinError(Int_t binx, Int_t biny) const { return GetBinError(binx); }
+    Stat_t GetBinError(Int_t binx, Int_t biny, Int_t binz) const { return GetBinError(binx); }
+
     Double_t GetMinimum(Bool_t all) const;
     Double_t GetMaximum(Bool_t all) const;
@@ -126,7 +149,10 @@
 
     void  PrintInfo() const { Print(""); } // *MENU*
+    void  Reset(Option_t *);
+    void  Reset() { Reset(""); } // *MENU*
+    TH1  *DrawCopy() const/* { gPad=NULL; return TH1D::DrawCopy(); }*/; // *MENU*
+
     void  Print(Option_t *) const;
     void  Paint(Option_t *option="");
-    void  Reset(Option_t * = "");
     void  Draw(Option_t *option="");
     void  SavePrimitive(ofstream &out, Option_t *);
@@ -141,6 +167,11 @@
     void  SetInvDeepBlueSeaPalette(); // *MENU*
 
-    void  SetAutoScale(); // *MENU*
-    //void  SetOptStat(Int_t os=-1); // *MENU*
+    void  SetAutoScale() { fMinimum = fMaximum = -1111; } // *MENU*
+    void  DisplayAsHistogram() { SetDrawOption("histEP"); } // *MENU*
+    void  DisplayAsCamera() { SetDrawOption(""); } // *MENU*
+
+    void  SetFreezed(Bool_t f=kTRUE) { f ? SetBit(kFreezed) : ResetBit(kFreezed); } // *TOGGLE*
+    Bool_t IsFreezed() const { return TestBit(kFreezed); }
+    //void  SetOptStat(Int_t os=-1) { fOptStat = os; } // *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
@@ -159,7 +190,4 @@
     ClassDef(MHCamera, 1) // Displays the magic camera
 };
-
-inline void MHCamera::SetAutoScale() { fMinimum = fMaximum = -1111; }
-//inline void MHCamera::SetOptStat(Int_t os) { fOptStat = os; }
 
 #endif
