Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 2206)
+++ trunk/MagicSoft/Mars/mhist/MH.cc	(revision 2209)
@@ -652,9 +652,16 @@
     // Rename first statistics box
     //
-    TPaveStats &s1 = *(TPaveStats*)gPad->FindObject("stats");
-    const Double_t x1 = s1.GetX1NDC()-0.01;
-    s1.SetName((TString)"Stat"+hist1.GetTitle());
-    s1.SetX1NDC(x1-(s1.GetX2NDC()-s1.GetX1NDC()));
-    s1.SetX2NDC(x1);
+    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s1)
+        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
+    else
+        s1->SetName((TString)"Stat"+hist1.GetTitle());
+
+    if (s1 && s1->GetX2NDC()>0.95)
+    {
+        const Double_t x1 = s1->GetX1NDC()-0.01;
+        s1->SetX1NDC(x1-(s1->GetX2NDC()-s1->GetX1NDC()));
+        s1->SetX2NDC(x1);
+    }
 
     //
@@ -667,17 +674,23 @@
     // Draw Legend
     //
-    TPaveStats &s2 = *(TPaveStats*)gPad->FindObject("stats");
-    TLegend &l = *new TLegend(s2.GetX1NDC(),
-                              s2.GetY1NDC()-0.015-(s2.GetY2NDC()-s2.GetY1NDC())/2,
-                              s2.GetX2NDC(),
-                              s2.GetY1NDC()-0.01
-                             );
-    l.AddEntry(h1, h1->GetTitle());
-    l.AddEntry(h2, h2->GetTitle());
-    l.SetTextSize(s2.GetTextSize());
-    l.SetTextFont(s2.GetTextFont());
-    l.SetBorderSize(s2.GetBorderSize());
-    l.SetBit(kCanDelete);
-    l.Draw();
+    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s2)
+        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
+
+    if (s2)
+    {
+        TLegend &l = *new TLegend(s2->GetX1NDC(),
+                                  s2->GetY1NDC()-0.015-(s2->GetY2NDC()-s2->GetY1NDC())/2,
+                                  s2->GetX2NDC(),
+                                  s2->GetY1NDC()-0.01
+                                 );
+        l.AddEntry(h1, h1->GetTitle());
+        l.AddEntry(h2, h2->GetTitle());
+        l.SetTextSize(s2->GetTextSize());
+        l.SetTextFont(s2->GetTextFont());
+        l.SetBorderSize(s2->GetBorderSize());
+        l.SetBit(kCanDelete);
+        l.Draw();
+    }
 }
 
@@ -740,5 +753,5 @@
         s1->SetName((TString)"Stat"+hist1.GetTitle());
 
-    if (s1)
+    if (s1 && s1->GetX2NDC()>0.95)
     {
         const Double_t x1 = s1->GetX1NDC()-0.01;
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 2209)
@@ -0,0 +1,155 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHCamEvent
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHCamEvent.h"
+
+#include <TCanvas.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MCamEvent.h"
+#include "MHCamera.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
+ClassImp(MHCamEvent);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initialize the name and title of the task.
+// Resets the sum histogram
+//
+MHCamEvent::MHCamEvent(const char *name, const char *title)
+    : fSum(NULL), fEvt(NULL), fType(0)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHCamEvent";
+    fTitle = title ? title : "Average of MCamEvents";
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the corresponding camera display if available
+//
+MHCamEvent::~MHCamEvent()
+{
+    if (fSum)
+        delete fSum;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the event (MCamEvent) the histogram might be filled with. If
+// it is not given, it is assumed, that it is filled with the argument
+// of the Fill function.
+// Looks for the camera geometry MGeomCam and resets the sum histogram.
+//
+Bool_t MHCamEvent::SetupFill(const MParList *plist)
+{
+    fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
+    if (!fEvt)
+    {
+        if (!fNameEvt.IsNull())
+        {
+            *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
+            return kFALSE;
+        }
+        *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
+    }
+
+    MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
+    if (!cam)
+        *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
+
+    if (fSum)
+        delete (fSum);
+    fSum = new MHCamera(*cam, fNameEvt+";avg", fTitle);
+    fSum->SetXTitle("a.u.");
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Fill the histograms with data from a MCamEvent-Container.
+//
+Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
+{
+    const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
+    if (!evt)
+    {
+        *fLog << err << dbginf << "No MCamEvent found..." << endl;
+        return kFALSE;
+    }
+    fSum->AddCamContent(*evt, fType);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Scale the sum container with the number of entries
+//
+Bool_t MHCamEvent::Finalize()
+{
+    if (fSum->GetEntries()>0)
+        fSum->Scale(100./fSum->GetEntries());
+    return kTRUE;
+}
+
+TH1 *MHCamEvent::GetHistByName(const TString name)
+{
+    return fSum;
+}
+
+void MHCamEvent::Draw(Option_t *)
+{
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
+    pad->SetBorderMode(0);
+
+    pad->Divide(2,2);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
+    gPad->Divide(1,1);
+    gPad->cd(1);
+    gPad->SetBorderMode(0);
+    fSum->Draw();
+
+    pad->cd(3);
+    gPad->SetBorderMode(0);
+    fSum->Draw("EPhist");
+}
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 2209)
@@ -0,0 +1,39 @@
+#ifndef MARS_MHCamEvent
+#define MARS_MHCamEvent
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+class MHCamera;
+class MCamEvent;
+
+class MHCamEvent : public MH
+{
+private:
+    MHCamera *fSum;      // storing the sum
+    MCamEvent   *fEvt;      //! the current event
+
+    TString fNameEvt;
+
+    Int_t fType;
+
+    Bool_t SetupFill(const MParList *pList);
+    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+    Bool_t Finalize();
+
+public:
+    MHCamEvent(const char *name=NULL, const char *title=NULL);
+    ~MHCamEvent();
+
+    void SetNameEvt(const TString name) { fNameEvt = name; }
+    void SetType(Int_t type) { fType = type; }
+
+    TH1 *GetHistByName(const TString name="");
+
+    void Draw(Option_t *o="");
+
+    ClassDef(MHCamEvent, 1) // Histogram to sum camera events
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 2209)
@@ -0,0 +1,1017 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Harald Kornmayer, 1/2001
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHCamera
+//
+// Camera Display. The Pixels are displayed in
+// contents/area [somthing/mm^2]
+//
+// To change the scale to a logarithmic scale SetLogz() of the Pad.
+//
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MHCamera.h"
+
+#include <fstream>
+#include <iostream>
+
+#include <TBox.h>
+#include <TArrow.h>
+#include <TLatex.h>
+#include <TStyle.h>
+#include <TMarker.h>
+#include <TCanvas.h>
+#include <TArrayF.h>
+#include <TRandom.h>
+#include <TPaveText.h>
+#include <TClonesArray.h>
+
+#include "MH.h"
+#include "MHexagon.h"
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+
+#include "MRflEvtData.h"
+#include "MRflSinglePhoton.h"
+
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
+
+#include "MCurrents.h"
+#include "MCamEvent.h"
+
+#include "MImgCleanStd.h"
+
+#define kItemsLegend 48 // see SetPalette(1,0)
+
+ClassImp(MHCamera);
+
+using namespace std;
+
+// ------------------------------------------------------------------------
+//
+//  Default Constructor. To be used by the root system ONLY.
+//
+MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend)
+{
+    SetDirectory(NULL);
+
+    fPhotons   = NULL;
+    fNotify  = NULL;
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
+    SetPalette(1, 0);
+#else
+    SetPalette(51, 0);
+#endif
+}
+
+// ------------------------------------------------------------------------
+//
+//  Constructor. Makes a clone of MGeomCam.
+//
+MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
+: TH1D(name, title, geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5),
+fUsed(geom.GetNumPixels()), fColors(kItemsLegend)
+{
+    fGeomCam = (MGeomCam*)geom.Clone();
+
+    SetDirectory(NULL);
+    Sumw2();
+
+    SetLineColor(kGreen);
+    SetMarkerStyle(kFullDotMedium);
+
+    fNotify = new TList;
+
+    //
+    //  create the hexagons of the display
+    //
+    // root 3.02
+    //  * base/inc/TObject.h:
+    //    register BIT(8) as kNoContextMenu. If an object has this bit set it will
+    //    not get an automatic context menu when clicked with the right mouse button.
+
+    fPhotons = new TClonesArray("TMarker", 0);
+
+    //
+    // Construct all hexagons. Use new-operator with placement
+    //
+    for (Int_t i=0; i<fNcells-2; i++)
+        ResetUsed(i);
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
+    SetPalette(1, 0);
+#else
+    SetPalette(51, 0);
+#endif
+}
+
+// ------------------------------------------------------------------------
+//
+// Destructor. Deletes TClonesArrays for hexagons and legend elements.
+//
+MHCamera::~MHCamera()
+{
+    if (fPhotons)
+    {
+        fPhotons->Delete();
+        delete fPhotons;
+    }
+    if (fGeomCam)
+        delete fGeomCam;
+    if (fNotify)
+        delete fNotify;
+}
+
+Int_t MHCamera::Fill(Axis_t x)
+{
+//   -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
+//                   ==================================
+//
+//    if x is less than the low-edge of the first bin, the Underflow bin is incremented
+//    if x is greater than the upper edge of last bin, the Overflow bin is incremented
+//
+//    If the storage of the sum of squares of weights has been triggered,
+//    via the function Sumw2, then the sum of the squares of weights is incremented
+//    by 1 in the bin corresponding to x.
+//
+//   -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+
+   if (fBuffer) return BufferFill(x,1);
+
+   const Int_t bin = (Int_t)x+1;
+   AddBinContent(bin);
+   if (fSumw2.fN)
+       fSumw2.fArray[bin]++;
+
+   if (bin<=0 || bin>fNcells-2)
+       return -1;
+
+   fTsumw++;
+   fTsumw2++;
+   fTsumwx  += x;
+   fTsumwx2 += x*x;
+   return bin;
+}
+
+//______________________________________________________________________________
+Int_t MHCamera::Fill(Axis_t x, Stat_t w)
+{
+//   -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
+//               =============================================
+//
+//    if x is less than the low-edge of the first bin, the Underflow bin is incremented
+//    if x is greater than the upper edge of last bin, the Overflow bin is incremented
+//
+//    If the storage of the sum of squares of weights has been triggered,
+//    via the function Sumw2, then the sum of the squares of weights is incremented
+//    by w^2 in the bin corresponding to x.
+//
+//   -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+
+   if (fBuffer) return BufferFill(x,w);
+
+   const Int_t bin = (Int_t)x+1;
+   AddBinContent(bin, w);
+   if (fSumw2.fN)
+       fSumw2.fArray[bin] += w*w;
+
+   if (bin<=0 || bin>fNcells-2)
+       return -1;
+
+   const Stat_t z = (w > 0 ? w : -w);
+   fTsumw   += z;
+   fTsumw2  += z*z;
+   fTsumwx  += z*x;
+   fTsumwx2 += z*x*x;
+   return bin;
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the minimum contents of all pixels (if all is set, otherwise
+// only of all 'used' pixels), fMinimum if fMinimum set
+//
+Double_t MHCamera::GetMinimum(Bool_t all) const
+{
+    if (fMinimum != -1111)
+        return fMinimum;
+
+    Double_t minimum=FLT_MAX;
+
+    if (all)
+    {
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            if (fArray[idx+1] < minimum)
+                minimum = fArray[idx+1];
+    }
+    else
+    {
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            if (IsUsed(idx) && fArray[idx+1] < minimum)
+                minimum = fArray[idx+1];
+    }
+    return minimum;
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the maximum contents of all pixels (if all is set, otherwise
+// only of all 'used' pixels), fMaximum if fMaximum set
+//
+Double_t MHCamera::GetMaximum(Bool_t all) const
+{
+    if (fMaximum != -1111)
+        return fMaximum;
+
+    Double_t maximum=-FLT_MAX;
+    if (all)
+    {
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            if (fArray[idx+1] > maximum)
+                maximum = fArray[idx+1];
+    }
+    else
+    {
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            if (IsUsed(idx) && fArray[idx+1] > maximum)
+                maximum = fArray[idx+1];
+    }
+    return maximum;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to draw the camera layout into your canvas.
+// Setup a drawing canvas. Add this object and all child objects
+// (hexagons, etc) to the current pad. If no pad exists a new one is
+// created.
+//
+// To draw a camera into its own pad do something like:
+//
+// TCanvas *c = new TCanvas;
+// c->Divide(2,1);
+// MGeomCamMagic m;
+// MHCamera *d=new MHCamera(&m);
+// d->FillRandom();
+// c->cd(1);
+// gPad->SetBorderMode(0);
+// gPad->Divide(1,1);
+// gPad->cd(1);
+// d->Draw();
+// d->SetBit(kCanDelete);
+//
+void MHCamera::Draw(Option_t *option)
+{
+    // root 3.02:
+    // gPad->SetFixedAspectRatio()
+    Int_t col = 16;
+
+    if (gPad)
+        col = gPad->GetFillColor();
+
+    TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
+    pad->SetBorderMode(0);
+    pad->SetFillColor(col);
+
+    AppendPad(option);
+}
+
+
+void MHCamera::SetRange()
+{
+    const Float_t range = fGeomCam->GetMaxRadius();
+
+    //
+    // Maintain aspect ratio
+    //
+    const float ratio = 1.15;
+
+    //
+    // Calculate width and height of the current pad in pixels
+    //
+    Float_t w = gPad->GetWw();
+    Float_t h = gPad->GetWh()*ratio;
+
+    //
+    // This prevents the pad from resizing itself wrongly
+    //
+    if (gPad->GetMother() != gPad)
+    {
+        w *= gPad->GetMother()->GetAbsWNDC();
+        h *= gPad->GetMother()->GetAbsHNDC();
+    }
+
+    //
+    // Set Range (coordinate system) of pad
+    //
+    gPad->Range(-range, -range, (2*ratio-1)*range, range);
+
+    //
+    // Resize Pad to given ratio
+    //
+    if (h<w)
+        gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
+    else
+        gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
+}
+
+void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol)
+{
+    Double_t min = GetMinimum(kFALSE);
+    Double_t max = GetMaximum(kFALSE);
+    if (min==FLT_MAX)
+    {
+        min = 0;
+        max = 1;
+    }
+
+    UpdateLegend(min, max, islog);
+
+    MHexagon hex;
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        if (IsUsed(i) && iscol)
+            hex.SetFillColor(GetColor(fArray[i+1], min, max, islog));
+        else
+            hex.SetFillColor(10);
+
+        MGeomPix &pix = (*fGeomCam)[i];
+        if (!isbox)
+            hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD());
+        else
+            if (IsUsed(i))
+            {
+                Float_t size = pix.GetD()*(fArray[i+1]-min)/(max-min);
+                if (size>pix.GetD())
+                    size=pix.GetD();
+                hex.PaintHexagon(pix.GetX(), pix.GetY(), size);
+            }
+    }
+}
+
+void MHCamera::Print(Option_t *) const
+{
+    cout << "Minimum: " << GetMinimum();
+    if (fMinimum==-1111)
+        cout << " <autoscaled>";
+    cout << endl;
+    cout << "Maximum: " << GetMaximum();
+    if (fMaximum==-1111)
+        cout << " <autoscaled>";
+    cout << endl;
+}
+
+void MHCamera::PaintAxisTitle()
+{
+    Float_t fRange = fGeomCam->GetMaxRadius();
+
+    TLatex *ptitle = new TLatex(1.2*fRange, .97*fRange, GetXaxis()->GetTitle());
+
+    ptitle->SetTextSize(0.03);
+    ptitle->SetTextAlign(33);
+
+    // box with the histogram title
+    ptitle->SetTextColor(gStyle->GetTitleTextColor());
+    ptitle->SetTextFont(gStyle->GetTitleFont(""));
+    ptitle->Paint();
+}
+
+void MHCamera::PaintTitle()
+{
+//    *-*-*-*-*-*-*-*-*-*Draw the histogram title*-*-*-*-*-*-*-*-*-*-*-*-*
+//                       ========================
+   //if (Hoption.Same) return;
+    if (TestBit(kNoTitle))
+        return;
+
+    const Int_t nt = strlen(GetTitle());
+
+    TPaveText *title = (TPaveText*)gPad->FindObject("title");
+    if (nt == 0 || gStyle->GetOptTitle() <= 0)
+    {
+        if (title)
+            delete title;
+        return;
+    }
+
+    Double_t ht = gStyle->GetTitleH();
+    Double_t wt = gStyle->GetTitleW();
+
+    if (ht <= 0)
+        ht = 0.05;
+    if (wt <= 0)
+    {
+        TLatex l;
+        l.SetTextSize(ht);
+        l.SetTitle(GetTitle());
+        Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
+        wt = TMath::Min(0.7, 0.02+wndc);
+    }
+    if (title)
+    {
+        TText *t0 = (TText*)title->GetLine(0);
+        if (t0)
+        {
+            if (!strcmp(t0->GetTitle(), GetTitle()))
+                return;
+
+            t0->SetTitle(GetTitle());
+            if (wt > 0)
+                title->SetX2NDC(title->GetX1NDC()+wt);
+        }
+        return;
+    }
+
+    TPaveText *ptitle = new TPaveText(
+                                      gStyle->GetTitleX(),
+                                      gStyle->GetTitleY()-ht,
+                                      gStyle->GetTitleX()+wt,
+                                      gStyle->GetTitleY(),"blNDC");
+
+    // box with the histogram title
+    ptitle->SetFillColor(gStyle->GetTitleFillColor());
+    ptitle->SetFillStyle(gStyle->GetTitleStyle());
+    ptitle->SetName("title");
+    ptitle->SetBorderSize(gStyle->GetTitleBorderSize());
+    ptitle->SetTextColor(gStyle->GetTitleTextColor());
+    ptitle->SetTextFont(gStyle->GetTitleFont(""));
+    if (gStyle->GetTitleFont("")%10 > 2)
+        ptitle->SetTextSize(gStyle->GetTitleFontSize());
+    ptitle->AddText(GetTitle());
+    ptitle->SetBit(kCanDelete);
+    ptitle->Draw();
+    ptitle->Paint();
+}
+
+// ------------------------------------------------------------------------
+//
+// This is called at any time the canvas should get repainted.
+// Here we maintain an aspect ratio of 1.15. This makes sure,
+// that the camera image doesn't get distorted by resizing the canvas.
+//
+void MHCamera::Paint(Option_t *o)
+{
+    const TString opt(o);
+
+    if (opt.Contains("hist", TString::kIgnoreCase))
+    {
+        Int_t mode = gStyle->GetOptStat();
+        TVirtualPad *save = gPad;
+        gPad=NULL;
+        gStyle->SetOptStat(1000011);
+        gPad=save;
+        TH1D::Paint(o);
+        gPad=NULL;
+        gStyle->SetOptStat(mode);
+        gPad=save;
+        return;
+    }
+
+    // Maintain aspect ratio
+    SetRange();
+
+    Bool_t isbox = opt.Contains("box", TString::kIgnoreCase);
+    Bool_t iscol = isbox ? !opt.Contains("nocol", TString::kIgnoreCase) : 1;
+
+    // Update Contents of the pixels and paint legend
+    Update(gPad->GetLogz(), isbox, iscol);
+
+    // Paint primitives (pixels, color legend, photons, ...)
+    { fPhotons->ForEach(TObject, Paint)(); }
+
+    PaintTitle();
+    PaintAxisTitle();
+}
+
+// ------------------------------------------------------------------------
+//
+//  With this function you can change the color palette. For more
+// information see TStyle::SetPalette. Only palettes with 50 colors
+// are allowed.
+// In addition you can use SetPalette(52, 0) to create an inverse
+// deep blue sea palette
+//
+void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
+{
+    //
+    // If not enough colors are specified skip this.
+    //
+    if (ncolors>1 && ncolors<50)
+    {
+        cout << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
+        return;
+    }
+
+    //
+    // If ncolors==52 create a reversed deep blue sea palette
+    //
+    if (ncolors==52)
+    {
+        gStyle->SetPalette(51, NULL);
+        TArrayI c(kItemsLegend);
+        for (int i=0; i<kItemsLegend; i++)
+            c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
+        gStyle->SetPalette(kItemsLegend, c.GetArray());
+    }
+    else
+        gStyle->SetPalette(ncolors, colors);
+
+    fColors.Set(kItemsLegend);
+    for (int i=0; i<kItemsLegend; i++)
+        fColors[i] = gStyle->GetColorPalette(i);
+}
+
+
+void MHCamera::SetPrettyPalette()
+{
+    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+        SetPalette(1, 0);
+}
+
+void MHCamera::SetDeepBlueSeaPalette()
+{
+    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+        SetPalette(51, 0);
+}
+
+void MHCamera::SetInvDeepBlueSeaPalette()
+{
+    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+        SetPalette(52, 0);
+}
+
+void MHCamera::DrawPixelNumbers()
+{
+    for (int i=0; i<kItemsLegend; i++)
+        fColors[i] = 16;
+
+    if (!gPad)
+        Draw();
+
+    TText txt;
+    txt.SetTextFont(122);
+    txt.SetTextAlign(22);   // centered/centered
+
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        TString num;
+        num += i;
+
+        const MGeomPix &h = (*fGeomCam)[i];
+        TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
+        nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius());
+    }
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
+{
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Double_t val=0;
+        if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
+            SetUsed(idx);
+
+        Fill(idx, val); // FIXME: Slow!
+        //fArray[idx+1]+=val;
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
+{
+    if (fNcells!=d.fNcells)
+        return;
+
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+        if (d.IsUsed(idx))
+            SetUsed(idx);
+
+    switch (type)
+    {
+    case 1:
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            Fill(idx, d.GetBinError(idx+1));
+        break;
+    case 2:
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            if (d.GetBinContent(idx+1)!=0)
+                Fill(idx, fabs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
+        break;
+    default:
+        for (Int_t idx=0; idx<fNcells-2; idx++)
+            Fill(idx, d.GetBinContent(idx+1));
+        break;
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MHCamera::AddCamContent(const TArrayD &event, Bool_t ispos)
+{
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Fill(idx, event[idx]); // FIXME: Slow!
+        //fArray[idx+1]+=val;
+
+        if (!ispos || fArray[idx+1]>0)
+            SetUsed(idx);
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
+{
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Double_t val=0;
+        if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
+            SetUsed(idx);
+
+        if (val>threshold)
+            Fill(idx);
+    }
+    fEntries++;
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the currents
+//
+void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
+{
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        if (event[idx]>threshold)
+            Fill(idx);
+
+        if (!ispos || fArray[idx+1]>0)
+            SetUsed(idx);
+    }
+    fEntries++;
+}
+
+void MHCamera::FillRandom()
+{
+    Reset();
+
+    // FIXME: Security check missing!
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
+        SetUsed(idx);
+    }
+    fEntries=1;
+}
+
+
+// ------------------------------------------------------------------------
+//
+// Fill the colors in respect to the cleaning levels
+//
+void MHCamera::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
+{
+    SetCamContent(event, 2);
+
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        if (!IsUsed(i))
+            continue;
+
+        if (fArray[i+1]>lvl1)
+            fArray[i+1] = 0;
+        else
+            if (fArray[i+1]>lvl2)
+                fArray[i+1] = 1;
+            else
+                fArray[i+1] = 2;
+    }
+}
+
+// ------------------------------------------------------------------------
+//
+// Fill the colors in respect to the cleaning levels
+//
+void MHCamera::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
+{
+    FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
+}
+
+// ------------------------------------------------------------------------
+//
+// Show a reflector event. EMarkerStyle is defined in root/include/Gtypes.h
+// To remove the photons from the display call FillRflEvent(NULL)
+//
+void MHCamera::ShowRflEvent(const MRflEvtData *event, EMarkerStyle ms)
+{
+    const Int_t num = event ? event->GetNumPhotons() : 0;
+
+    fPhotons->ExpandCreate(num);
+    if (num < 1)
+        return;
+
+    Int_t i=num-1;
+    do
+    {
+        const MRflSinglePhoton &ph = event->GetPhoton(i);
+        TMarker &m = *static_cast<TMarker*>(fPhotons->UncheckedAt(i));
+        m.SetX(ph.GetX());
+        m.SetY(ph.GetY());
+        m.SetMarkerStyle(ms);
+    } while (i--);
+}
+
+// ------------------------------------------------------------------------
+//
+// Reset the all pixel colors to a default value
+//
+void MHCamera::Reset(Option_t *opt)
+{
+    TH1::Reset(opt);
+
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        fArray[i+1]=0;
+        ResetUsed(i);
+    }
+    fArray[0]         = 0;
+    fArray[fNcells-1] = 0;
+} 
+
+// ------------------------------------------------------------------------
+//
+//  Here we calculate the color index for the current value.
+//  The color index is defined with the class TStyle and the
+//  Color palette inside. We use the command gStyle->SetPalette(1,0)
+//  for the display. So we have to convert the value "wert" into
+//  a color index that fits the color palette.
+//  The range of the color palette is defined by the values fMinPhe
+//  and fMaxRange. Between this values we have 50 color index, starting
+//  with 0 up to 49.
+//
+Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
+{
+    //
+    //   first treat the over- and under-flows
+    //
+    const Int_t maxcolidx = kItemsLegend-1;
+
+    if (val >= max)
+        return fColors[maxcolidx];
+
+    if (val <= min)
+        return fColors[0];
+
+    //
+    // calculate the color index
+    //
+    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];
+}
+
+// ------------------------------------------------------------------------
+//
+//  Change the text on the legend according to the range of the Display
+//
+void MHCamera::UpdateLegend(Float_t minphe, Float_t maxphe, Bool_t islog)
+{
+    const Float_t range = fGeomCam->GetMaxRadius();
+
+    const Float_t H = 0.9*range;
+    const Float_t h = 2./kItemsLegend;
+    const Float_t offset = 0.04*range;
+
+    const Float_t w = range/sqrt((float)(fNcells-2));
+
+    TBox newbox;
+    TText newtxt;
+    newtxt.SetTextSize(0.025);
+    newtxt.SetTextAlign(12);
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+    newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
+    newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
+#endif
+
+    for (Int_t i=0; i<kItemsLegend+1; i+=3)
+    {
+        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);
+
+        newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(val<1e6?"%5.1f":"%5.1e", val));
+    }
+
+    for (Int_t i=0; i<kItemsLegend; i++)
+    {
+        newbox.SetFillColor(fColors[i]);
+        newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
+    }
+
+    TArrow arr;
+    arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
+    arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
+
+    TString text;
+    text += (int)(range*.3);
+    text += "mm";
+
+    TText newtxt2;
+    newtxt2.SetTextSize(0.04);
+    newtxt2.PaintText(-range*.85, -range*.85, text);
+
+    text = "";
+    text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
+    text += "\\circ";
+    text = text.Strip(TString::kLeading);
+
+    TLatex latex;
+    latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
+}
+
+// ------------------------------------------------------------------------
+//
+// Save primitive as a C++ statement(s) on output stream out
+//
+void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
+{
+    cout << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
+    /*
+    if (!gROOT->ClassSaved(TCanvas::Class()))
+        fDrawingPad->SavePrimitive(out, opt);
+
+    out << "   " << fDrawingPad->GetName() << "->SetWindowSize(";
+    out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
+    */
+}
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Camera
+// this functions needed for graphical primitives, that
+// means without this function you are not able to interact
+// with the graphical primitive with the mouse!!!
+//
+// All calcutations are running in pixel coordinates
+//
+Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
+{
+    if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+        return TH1D::DistancetoPrimitive(px, py);
+
+    Int_t dist = 999999;
+
+    for (Int_t i=0; i<fNcells-2; i++)
+    {
+        MHexagon hex((*fGeomCam)[i]);
+        Int_t d = hex.DistancetoPrimitive(px, py);
+
+        if (d<dist)
+            dist=d;
+    }
+    return dist==0?0:999999;
+}
+
+// ------------------------------------------------------------------------
+//
+// Execute a mouse event on the camera
+//
+/*
+ void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
+ {
+ cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl;
+ }
+ */
+
+
+// ------------------------------------------------------------------------
+//
+// Function introduced  (31-01-03)  WILL BE REMOVED IN THE FUTURE! DON'T
+// USE IT!
+//
+void MHCamera::SetPix(const Int_t idx, const Int_t color, Float_t min, Float_t max)
+{
+    fArray[idx+1] = color;
+    SetUsed(idx);
+}
+
+Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const
+{
+    Int_t i;
+    for (i=0; i<fNcells-2; i++)
+    {
+        MHexagon hex((*fGeomCam)[i]);
+        if (hex.DistancetoPrimitive(px, py)>0)
+            continue;
+
+        return i;
+    }
+    return -1;
+}
+
+// ------------------------------------------------------------------------
+//
+// Returns string containing info about the object at position (px,py).
+// Returned string will be re-used (lock in MT environment).
+//
+char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
+{
+    if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+        return TH1D::GetObjectInfo(px, py);
+
+    static char info[128];
+
+    const Int_t idx=GetPixelIndex(px, py);
+
+    if (idx<0)
+        return TObject::GetObjectInfo(px, py);
+
+    sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
+    return info;
+}
+
+// ------------------------------------------------------------------------
+//
+// Execute a mouse event on the camera
+//
+void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
+{
+    if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+    {
+        TH1D::ExecuteEvent(event, px, py);
+        return;
+    }
+    //if (event==kMouseMotion && fStatusBar)
+    //    fStatusBar->SetText(GetObjectInfo(px, py), 0);
+    if (event!=kButton1Down)
+        return;
+
+    const Int_t idx = GetPixelIndex(px, py);
+    if (idx<0)
+        return;
+
+    cout << "Software Pixel Index: " << idx << endl;
+    cout << "Hardware Pixel Id:    " << idx+1 << endl;
+    cout << "Contents:             " << fArray[idx+1] << "  <";
+    cout << (IsUsed(idx)?"on":"off");
+    cout << ">" << endl << endl;
+
+    if (fNotify && fNotify->GetSize()>0)
+        new TCanvas;
+    fNotify->ForEach(MCamEvent, DrawPixelContent)(idx);
+}
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2209)
@@ -0,0 +1,319 @@
+#ifndef MARS_MHCamera
+#define MARS_MHCamera
+
+#ifndef MARS_MAGIC
+#include "MAGIC.h"
+#endif
+#ifndef ROOT_Gtypes
+#include <Gtypes.h>
+#endif
+#ifndef ROOT_TArrayC
+#include <TArrayC.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+#ifndef ROOT_TClonesArray
+#include <TClonesArray.h>
+#endif
+#ifndef ROOT_TH1
+#include <TH1.h>
+#endif
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+class TBox;
+class TText;
+class TArrow;
+class TGStatusBar;
+
+class MGeomCam;
+class MHexagon;
+class MCurrents;
+class MCamEvent;
+class MRflEvtData;
+class MCerPhotEvt;
+class MCerPhotPix;
+class MImgCleanStd;
+class MPedestalPix;
+class MPedestalCam;
+
+class MHCamera : public TH1D
+{
+private:
+    MGeomCam      *fGeomCam;     // pointer to camera geometry
+
+    TArrayC        fUsed;
+
+    TClonesArray  *fPhotons;     // array of reflector photons
+
+    TArrayI        fColors;      //! Color conversion table
+    TList         *fNotify;      //!
+
+    //TGStatusBar   *fStatusBar;
+
+    Int_t GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog);
+
+    void  Update(Bool_t islog, Bool_t isbox, Bool_t iscol);
+    void  UpdateLegend(Float_t min, Float_t max, Bool_t islog);
+    void  SetRange();
+
+    Int_t GetPixelIndex(Int_t px, Int_t py) const;
+
+    void PaintTitle();
+    void PaintAxisTitle();
+
+    enum {
+        kIsUsed = BIT(1)
+    };
+
+    Bool_t IsUsed(Int_t idx) const { return TESTBIT(fUsed[idx], kIsUsed); }
+    void   SetUsed(Int_t idx)      { SETBIT(fUsed[idx], kIsUsed); }
+    void   ResetUsed(Int_t idx)    { CLRBIT(fUsed[idx], kIsUsed); }
+
+    // This is a trick to remove TH1 entries from the context menu
+    TH1 *Rebin(Int_t ngroup=2, const char*newname="") { return this; }
+    void DrawPanel() {}
+
+    Int_t Fill(Axis_t x);
+    Int_t Fill(Axis_t x, Stat_t w);
+    Int_t Fill(const char *name, Stat_t w) { return -1; }
+    void  FillN(Int_t ntimes, const Axis_t *x, const Double_t *w, Int_t stride=1) {}
+    void  FillN(Int_t, const Axis_t *, const Axis_t *, const Double_t *, Int_t) {}
+
+public:
+    MHCamera();
+    MHCamera(const MGeomCam &geom, const char *name="", const char *title="");
+    ~MHCamera();
+
+    //void     AddPixContent(Int_t idx) const { AddBinContent(idx+1); }
+    //void     AddPixContent(Int_t idx, Stat_t w) const { AddBinContent(idx+1, w); }
+
+    // This is a trick to remove TH1 entries from the context menu
+    void Add(TF1 *h1, Double_t c1=1) { TH1::Add(h1, c1); }
+    void Add(const TH1 *h1, Double_t c1=1) { TH1::Add(h1, c1); }
+    void Add(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1) { TH1::Add(h1, h2, c1, c2); }
+    void Divide(TF1 *f1, Double_t c1=1) { TH1::Divide(f1, c1); }
+    void Divide(const TH1 *h1) { TH1::Divide(h1); }
+    void Divide(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") { TH1::Divide(h1, h2, c1, c2, option); }
+    void Multiply(TF1 *h1, Double_t c1=1) { TH1::Multiply(h1, c1); }
+    void Multiply(const TH1 *h1) { TH1::Multiply(h1); }
+    void Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") { TH1::Multiply(h1, h2, c1, c2, option); }
+    void FitPanel() { TH1::FitPanel(); }
+
+    virtual Double_t GetPixContent(Int_t idx) const { return GetBinContent(idx+1); }
+    virtual void     AddCamContent(const MCamEvent &evt, Int_t type=0);
+    virtual void     AddCamContent(const MHCamera &evt, Int_t type=0);
+    virtual void     AddCamContent(const TArrayD &arr, Bool_t ispos=kTRUE);
+    virtual void     SetCamContent(const MCamEvent &evt, Int_t type=0) { Reset(); AddCamContent(evt, type); }
+    virtual void     SetCamContent(const TArrayD &evt, Bool_t ispos=kTRUE) { Reset(); AddCamContent(evt, ispos); }
+    virtual void     SetCamContent(const MHCamera &d, Int_t type=0) { Reset(), AddCamContent(d, type); }
+    virtual void     CntCamContent(const MCamEvent &evt, Double_t threshold, Int_t type=0);
+    virtual void     CntCamContent(const TArrayD &evt, Double_t threshold, Bool_t ispos=kTRUE);
+
+    Double_t GetMinimum(Bool_t all) const;
+    Double_t GetMaximum(Bool_t all) const;
+
+    Double_t GetMinimum() const { return GetMinimum(0/*kTRUE*/); }
+    Double_t GetMaximum() const { return GetMaximum(0/*kTRUE*/); }
+
+    void  ShowRflEvent(const MRflEvtData *event=NULL, EMarkerStyle m=kFullDotMedium);
+    void  FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2);
+    void  FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean);
+
+    void  FillRandom(const char *fname, Int_t ntimes=5000) { TH1::FillRandom(fname, ntimes); }
+    void  FillRandom(TH1 *h, Int_t ntimes=5000) { TH1::FillRandom(h, ntimes); }
+    void  FillRandom();
+
+    void  DrawPixelNumbers();
+
+    void  PrintInfo() const { Print(""); } // *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 *);
+    Int_t DistancetoPrimitive(Int_t px, Int_t py);
+    char *GetObjectInfo(Int_t px, Int_t py) const;
+    void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
+
+    void  SetPalette(Int_t ncolors, Int_t *colors);
+
+    void  SetPrettyPalette(); // *MENU*
+    void  SetDeepBlueSeaPalette(); // *MENU*
+    void  SetInvDeepBlueSeaPalette(); // *MENU*
+
+    void  SetAutoScale(); // *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  AddNotify(const MCamEvent &event) { fNotify->Add((TObject*)(&event)); }
+
+    //void SetStatusBar(TGStatusBar *bar) { fStatusBar = bar; }
+
+    ClassDef(MHCamera, 1) // Displays the magic camera
+};
+
+inline void MHCamera::SetAutoScale() { fMinimum = fMaximum = -1111; }
+
+#endif
+
+/* ------------ OK ---------------
+ virtual void     Browse(TBrowser *b);
+ virtual void     FillRandom(const char *fname, Int_t ntimes=5000);
+ virtual void     FillRandom(TH1 *h, Int_t ntimes=5000);
+
+ virtual Int_t    GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0);
+ virtual Axis_t   GetRandom();
+ virtual void     GetStats(Stat_t *stats) const;
+ virtual Stat_t   GetSumOfWeights() const;
+ virtual Int_t    GetSumw2N() const {return fSumw2.fN;}
+ virtual Stat_t   GetRMS(Int_t axis=1) const;
+
+ virtual Int_t    GetNbinsX() const {return fXaxis.GetNbins();}
+ virtual Int_t    GetNbinsY() const {return fYaxis.GetNbins();}
+ virtual Int_t    GetNbinsZ() const {return fZaxis.GetNbins();}
+
+ // ------------- to check -------------------
+
+ virtual Double_t ComputeIntegral();
+ virtual Int_t    DistancetoPrimitive(Int_t px, Int_t py);
+ virtual void     Draw(Option_t *option="");
+ virtual TH1     *DrawCopy(Option_t *option="") const;
+ virtual TH1     *DrawNormalized(Option_t *option="", Double_t norm=1) const;
+ virtual Int_t    BufferEmpty(Bool_t deleteBuffer=kFALSE);
+ virtual void     Eval(TF1 *f1, Option_t *option="");
+ virtual void     ExecuteEvent(Int_t event, Int_t px, Int_t py);
+ virtual void     FillN(Int_t ntimes, const Axis_t *x, const Double_t *w, Int_t stride=1);
+ virtual void     FillN(Int_t, const Axis_t *, const Axis_t *, const Double_t *, Int_t) {;}
+ virtual Int_t    FindBin(Axis_t x, Axis_t y=0, Axis_t z=0);
+ virtual TObject *FindObject(const char *name) const;
+ virtual TObject *FindObject(const TObject *obj) const;
+ virtual Int_t    Fit(const char *formula ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0); // *MENU*
+ virtual Int_t    Fit(TF1 *f1 ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0);
+ virtual void     FitPanel(); // *MENU*
+ TH1             *GetAsymmetry(TH1* h2, Double_t c2=1, Double_t dc2=0);
+ Int_t            GetBufferLength() const {return (Int_t)fBuffer[0];}
+ Int_t            GetBufferSize  () const {return fBufferSize;}
+ const   Double_t *GetBuffer() const {return fBuffer;}
+ static  Int_t    GetDefaultBufferSize();
+ virtual Double_t *GetIntegral() {return fIntegral;}
+
+ TList           *GetListOfFunctions() const { return fFunctions; }
+
+ virtual Int_t    GetNdivisions(Option_t *axis="X") const;
+ virtual Color_t  GetAxisColor(Option_t *axis="X") const;
+ virtual Color_t  GetLabelColor(Option_t *axis="X") const;
+ virtual Style_t  GetLabelFont(Option_t *axis="X") const;
+ virtual Float_t  GetLabelOffset(Option_t *axis="X") const;
+ virtual Float_t  GetLabelSize(Option_t *axis="X") const;
+ virtual Float_t  GetTitleOffset(Option_t *axis="X") const;
+ virtual Float_t  GetTitleSize(Option_t *axis="X") const;
+ virtual Float_t  GetTickLength(Option_t *axis="X") const;
+ virtual Float_t  GetBarOffset() const {return Float_t(0.001*Float_t(fBarOffset));}
+ virtual Float_t  GetBarWidth() const  {return Float_t(0.001*Float_t(fBarWidth));}
+ virtual Int_t    GetContour(Double_t *levels=0);
+ virtual Double_t GetContourLevel(Int_t level) const;
+ virtual Double_t GetContourLevelPad(Int_t level) const;
+
+ virtual void     GetCenter(Axis_t *center) const {fXaxis.GetCenter(center);}
+ TDirectory      *GetDirectory() const {return fDirectory;}
+ virtual Stat_t   GetEntries() const;
+ virtual TF1     *GetFunction(const char *name) const;
+ virtual Int_t    GetDimension() const { return fDimension; }
+ virtual void     GetLowEdge(Axis_t *edge) const {fXaxis.GetLowEdge(edge);}
+ virtual Double_t GetMaximum() const;
+ virtual Int_t    GetMaximumBin() const;
+ virtual Int_t    GetMaximumBin(Int_t &locmax, Int_t &locmay, Int_t &locmaz) const;
+ virtual Double_t GetMaximumStored() const {return fMaximum;}
+ virtual Double_t GetMinimum() const;
+ virtual Int_t    GetMinimumBin() const;
+ virtual Int_t    GetMinimumBin(Int_t &locmix, Int_t &locmiy, Int_t &locmiz) const;
+ virtual Double_t GetMinimumStored() const {return fMinimum;}
+ virtual Stat_t   GetMean(Int_t axis=1) const;
+ virtual Double_t GetNormFactor() const {return fNormFactor;}
+ virtual char    *GetObjectInfo(Int_t px, Int_t py) const;
+ Option_t        *GetOption() const {return fOption.Data();}
+
+ TVirtualHistPainter *GetPainter();
+
+ TAxis   *GetXaxis() const;
+ TAxis   *GetYaxis() const;
+ TAxis   *GetZaxis() const;
+ virtual Stat_t   Integral(Option_t *option="") const;
+ virtual Stat_t   Integral(Int_t binx1, Int_t binx2, Option_t *option="") const;
+ virtual Stat_t   Integral(Int_t, Int_t, Int_t, Int_t, Option_t * ="") const {return 0;}
+ virtual Stat_t   Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Option_t * ="" ) const {return 0;}
+ virtual Double_t KolmogorovTest(TH1 *h2, Option_t *option="") const;
+ virtual void     LabelsDeflate(Option_t *axis="X");
+ virtual void     LabelsInflate(Option_t *axis="X");
+ virtual void     LabelsOption(Option_t *option="h", Option_t *axis="X");
+ virtual Int_t    Merge(TCollection *list);
+ virtual void     Multiply(TF1 *h1, Double_t c1=1);
+ virtual void     Multiply(const TH1 *h1);
+ virtual void     Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option=""); // *MENU*
+ virtual void     Paint(Option_t *option="");
+ virtual void     Print(Option_t *option="") const;
+ virtual void     PutStats(Stat_t *stats);
+ virtual TH1     *Rebin(Int_t ngroup=2, const char*newname="");  // *MENU*
+ virtual void     RebinAxis(Axis_t x, Option_t *axis="X");
+ virtual void     Rebuild(Option_t *option="");
+ virtual void     RecursiveRemove(TObject *obj);
+ virtual void     Reset(Option_t *option="");
+ virtual void     SavePrimitive(ofstream &out, Option_t *option);
+ virtual void     Scale(Double_t c1=1);
+ virtual void     SetAxisColor(Color_t color=1, Option_t *axis="X");
+ virtual void     SetAxisRange(Axis_t xmin, Axis_t xmax, Option_t *axis="X");
+ virtual void     SetBarOffset(Float_t offset=0.25) {fBarOffset = Short_t(1000*offset);}
+ virtual void     SetBarWidth(Float_t width=0.5) {fBarWidth = Short_t(1000*width);}
+ virtual void     SetBinContent(Int_t bin, Stat_t content);
+ virtual void     SetBinContent(Int_t binx, Int_t biny, Stat_t content);
+ virtual void     SetBinContent(Int_t binx, Int_t biny, Int_t binz, Stat_t content);
+ virtual void     SetBinError(Int_t bin, Stat_t error);
+ virtual void     SetBinError(Int_t binx, Int_t biny, Stat_t error);
+ virtual void     SetBinError(Int_t binx, Int_t biny, Int_t binz, Stat_t error);
+ virtual void     SetBins(Int_t nx, Axis_t xmin, Axis_t xmax);
+ virtual void     SetBins(Int_t nx, Axis_t xmin, Axis_t xmax, Int_t ny, Axis_t ymin, Axis_t ymax);
+ virtual void     SetBins(Int_t nx, Axis_t xmin, Axis_t xmax, Int_t ny, Axis_t ymin, Axis_t ymax,
+ Int_t nz, Axis_t zmin, Axis_t zmax);
+ virtual void     SetBinsLength(Int_t = -1) { } //refefined in derived classes
+ virtual void     SetBuffer(Int_t buffersize, Option_t *option="");
+ virtual void     SetCellContent(Int_t binx, Int_t biny, Stat_t content);
+ virtual void     SetCellError(Int_t binx, Int_t biny, Stat_t content);
+ virtual void     SetContent(const Stat_t *content);
+ virtual void     SetContour(Int_t nlevels, const Double_t *levels=0);
+ virtual void     SetContourLevel(Int_t level, Double_t value);
+ static  void     SetDefaultBufferSize(Int_t buffersize=1000);
+ virtual void     SetDirectory(TDirectory *dir);
+ virtual void     SetEntries(Stat_t n) {fEntries = n;};
+ virtual void     SetError(const Stat_t *error);
+ virtual void     SetLabelColor(Color_t color=1, Option_t *axis="X");
+ virtual void     SetLabelFont(Style_t font=62, Option_t *axis="X");
+ virtual void     SetLabelOffset(Float_t offset=0.005, Option_t *axis="X");
+ virtual void     SetLabelSize(Float_t size=0.02, Option_t *axis="X");
+
+ virtual void     SetMaximum(Double_t maximum=-1111); // *MENU*
+ virtual void     SetMinimum(Double_t minimum=-1111); // *MENU*
+ virtual void     SetName(const char *name); // *MENU*
+ virtual void     SetNameTitle(const char *name, const char *title);
+ virtual void     SetNdivisions(Int_t n=510, Option_t *axis="X");
+ virtual void     SetNormFactor(Double_t factor=1) {fNormFactor = factor;}
+ virtual void     SetStats(Bool_t stats=kTRUE);
+ virtual void     SetOption(Option_t *option=" ") {fOption = option;}
+ virtual void     SetTickLength(Float_t length=0.02, Option_t *axis="X");
+ virtual void     SetTitleOffset(Float_t offset=1, Option_t *axis="X");
+ virtual void     SetTitleSize(Float_t size=0.02, Option_t *axis="X");
+ virtual void     SetTitle(const char *title);
+ virtual void     SetXTitle(const char *title) {fXaxis.SetTitle(title);}
+ virtual void     SetYTitle(const char *title) {fYaxis.SetTitle(title);}
+ virtual void     SetZTitle(const char *title) {fZaxis.SetTitle(title);}
+ virtual void     Smooth(Int_t ntimes=1); // *MENU*
+ static  void     SmoothArray(Int_t NN, Double_t *XX, Int_t ntimes=1);
+ static Double_t  SmoothMedian(Int_t n, Double_t *a);
+ virtual void     Sumw2();
+ void             UseCurrentStyle();
+
+ ClassDef(TH1,4)  //1-Dim histogram base class
+};
+
+*/
Index: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 2206)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 2209)
@@ -115,8 +115,5 @@
     fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
     if (!fMcEvt)
-    {
-        *fLog << err << "MMcEvt not found... aborting." << endl;
-        return kFALSE;
-    }
+        *fLog << warn << "MMcEvt not found... aborting." << endl;
 
     fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
@@ -193,5 +190,5 @@
 Bool_t MHSigmaTheta::Fill(const MParContainer *par, const Stat_t w)
 {
-    Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
+    Double_t theta = fMcEvt ? fMcEvt->GetTelescopeTheta()*kRad2Deg : 0;
     Double_t mysig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
 
Index: trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.cc	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.cc	(revision 2209)
@@ -0,0 +1,158 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Abelardo Moralejo, 06/2003 <mailto:moralejo@pd.infn.it>
+!   Author(s): Thomas Bretz, 06/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHTriggerLvl0
+//
+// This is intended to be a sort of "level 0 trigger display". What it really
+// does is to store the number of events of a data file in which each pixel 
+// has gone above a given threshold (fPixelThreshold) which is chosen when
+// calling the constructor. Displaying a camera view with these values can
+// help identify noisy pixels. See the macro pixfixrate.C to see an example
+// of its use. Many things are to be fixed. Only inner pixels are shown now
+// (which are anyhow those involved in the trigger), and the camera geometry
+// (number of pixels, and how many inner ones) is not yet read from the input 
+// file. 
+// The "pedestal" we are using is just the signal in the first ADC slice 
+// (seems reasonable from the inspection of the available test data files).
+//
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHTriggerLvl0.h"
+
+#include <TCanvas.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MCamEvent.h"
+#include "MHCamera.h"
+
+#include "MGeomCam.h"
+
+ClassImp(MHTriggerLvl0);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initialize the name and title of the task.
+// Resets the sum histogram
+//
+MHTriggerLvl0::MHTriggerLvl0(Double_t t, const char *name, const char *title)
+    : fSum(NULL), fEvt(NULL), fType(0), fThreshold(t)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHTriggerLvl0";
+    fTitle = title ? title : "Number of hits above threshold per pixel";
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the corresponding camera display if available
+//
+MHTriggerLvl0::~MHTriggerLvl0()
+{
+    if (fSum)
+        delete fSum;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the event (MRawEvtData) the histogram might be filled with. If
+// it is not given, it is assumed, that it is filled with the argument
+// of the Fill function.
+// Looks for the camera geometry MGeomCam and resets the sum histogram.
+//
+Bool_t MHTriggerLvl0::SetupFill(const MParList *plist)
+{
+    fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
+    if (!fEvt)
+    {
+        if (!fNameEvt.IsNull())
+        {
+            *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
+            return kFALSE;
+        }
+        *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
+    }
+
+    MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
+    if (!cam)
+        *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
+
+    if (fSum)
+        delete (fSum);
+    fSum = new MHCamera(*cam, fNameEvt+";avg", fTitle);
+    fSum->SetXTitle("%");
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Fill the histograms with data from a MCerPhotEvt-Container.
+//
+Bool_t MHTriggerLvl0::Fill(const MParContainer *par, const Stat_t w)
+{
+    const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
+    if (!evt)
+    {
+        *fLog << err << dbginf << "No MCamEvent found..." << endl;
+        return kFALSE;
+    }
+
+    fSum->CntCamContent(*evt, fThreshold, fType);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set to Unused outer pixels.
+//
+Bool_t MHTriggerLvl0::Finalize()
+{
+    if (fSum->GetEntries()>0)
+        fSum->Scale(100./fSum->GetEntries());
+    return kTRUE;
+}
+
+TH1 *MHTriggerLvl0::GetHistByName(const TString name)
+{
+    return fSum;
+}
+
+void MHTriggerLvl0::Draw(Option_t *)
+{
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
+    pad->SetBorderMode(0);
+
+    fSum->Draw();
+}
Index: trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.h	(revision 2209)
+++ trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.h	(revision 2209)
@@ -0,0 +1,41 @@
+#ifndef MARS_MHTriggerLvl0
+#define MARS_MHTriggerLvl0
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+class MHCamera;
+class MCamEvent;
+
+class MHTriggerLvl0 : public MH
+{
+private:
+    MHCamera *fSum;      // storing the sum
+    MCamEvent   *fEvt;      //! the current event
+
+    TString fNameEvt;
+
+    Int_t fType;
+    Double_t fThreshold;
+
+    Bool_t SetupFill(const MParList *pList);
+    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+    Bool_t Finalize();
+
+public:
+    MHTriggerLvl0(Double_t t=0, const char *name=NULL, const char *title=NULL);
+    ~MHTriggerLvl0();
+
+    void SetNameEvt(const TString name) { fNameEvt = name; }
+    void SetType(Int_t type) { fType = type; }
+    void SetThreshold(Double_t t) { fThreshold = t; }
+
+    TH1 *GetHistByName(const TString name="");
+
+    void Draw(Option_t * ="");
+
+    ClassDef(MHTriggerLvl0, 1) // Histogram to sum level 0 triggers in all pixels
+};
+
+#endif
