Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 5114)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 5143)
@@ -30,8 +30,27 @@
 // currents or enything else derived from MCamEvent
 //
+// To plot the variance instead of the rms use:
+//    MHCamEvent::SetBit(MHCamera::kVariance);
+//
+// Axis titles
+// ===========
+//
+// 1) If no other title is given 'a.u.' is used.
+// 2) If the title of MHCamEvent is different from the default,
+//    it is used as histogram title. You can use this to set the
+//    axis title, too. For more information see TH1::SetTitle, eg.
+//       SetTitle("MyHist;;y[cm];Counts");
+//    Make sure to set an empty x-axis title.
+//
+//
+// For example:
+//   MHCamEvent myhist("Titele;;y [cm]");
+//
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MHCamEvent.h"
 
 #include <TCanvas.h>
+#include <TPaveStats.h>
 
 #include "MLog.h"
@@ -48,17 +67,38 @@
 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), fRms(NULL), fEvt(NULL), fType(0)
+const TString MHCamEvent::gsDefName  = "MHCamEvent";
+const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
+
+// --------------------------------------------------------------------------
+//
+// Initialize the name and title of the task
+//
+void MHCamEvent::Init(const char *name, const char *title)
 {
     //
     //   set the name and title of this object
     //
-    fName  = name  ? name  : "MHCamEvent";
-    fTitle = title ? title : "Average of MCamEvents";
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+// Initialize the name and title of the task. Set fType to 0
+//
+MHCamEvent::MHCamEvent(const char *name, const char *title)
+    : fSum(NULL), fEvt(NULL), fType(0)
+{
+    Init(name, title);
+}
+
+// --------------------------------------------------------------------------
+//
+// Initialize the name and title of the task. Set fType to type
+//
+MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
+    : fSum(NULL), fEvt(NULL), fType(type)
+{
+    Init(name, title);
 }
 
@@ -71,6 +111,4 @@
     if (fSum)
         delete fSum;
-    if (fRms)
-        delete fRms;
 }
 
@@ -104,17 +142,15 @@
     if (fSum)
         delete (fSum);
-    if (fRms)
-        delete (fRms);
 
     const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
 
-    fSum = new MHCamera(*cam, name+";avg", fTitle);
-    fSum->SetYTitle("a.u.");
+    fSum = new MHCamera(*cam, name+";avg");
+    if (fTitle!=gsDefTitle)
+        fSum->SetTitle(fTitle);
+    if (!fTitle.Contains(";"))
+        fSum->SetYTitle("a.u.");
     fSum->SetBit(MHCamera::kProfile);
-    if(TestBit(MHCamera::kVariance))
-      fSum->SetBit(MHCamera::kVariance);
-
-    fRms = new MHCamera(*cam, name+";rms", fTitle);
-    fRms->SetYTitle("a.u.");
+    if (TestBit(MHCamera::kVariance))
+        fSum->SetBit(MHCamera::kVariance);
 
     return kTRUE;
@@ -134,15 +170,4 @@
     }
     fSum->AddCamContent(*evt, fType);
-    fRms->SetCamContent(*fSum, 1);
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Scale the sum container with the number of entries
-//
-Bool_t MHCamEvent::Finalize()
-{
-    //fRms->AddCamContent(*fSum, 1);
     return kTRUE;
 }
@@ -176,12 +201,32 @@
 TH1 *MHCamEvent::GetHistByName(const TString name)
 {
-//    name.ToLower();
-
-    if (name=="sum")
-        return fSum;
-    if (name=="rms")
-        return fRms;
-
-    return NULL;
+    return fSum;
+}
+
+void MHCamEvent::Paint(Option_t *)
+{
+    TVirtualPad *pad = gPad;
+
+    pad->cd(2);
+    if (gPad->FindObject(Form("Proj_%p", this)))
+    {
+        TH1 *h=fSum->Projection(Form("Proj_%p", this));
+        if (h->GetMaximum()>0)
+            gPad->SetLogy();
+    }
+
+    pad->cd(5);
+    if (gPad->FindObject(Form("ProfR_%p", this)))
+        fSum->RadialProfile(Form("ProfR_%p", this));
+
+    pad->cd(6);
+    if (gPad->FindObject(Form("ProfA_%p", this)))
+        fSum->AzimuthProfile(Form("ProfA_%p", this));
+
+    pad->cd(4);
+    gPad->cd(1);
+    MHCamera *cam = (MHCamera*)gPad->FindObject(Form("Err_%p", this));
+    if (cam)
+        cam->SetCamContent(*fSum, 1);
 }
 
@@ -191,21 +236,58 @@
     pad->SetBorderMode(0);
 
-    pad->Divide(1,2);
+    AppendPad();
+
+    TString name = Form("%s_5", pad->GetName());
+    TPad *p = new TPad(name,name,6./8,0.25,0.99,0.5,pad->GetFillColor(),0,0);
+    p->SetNumber(5);
+    p->Draw();
+
+    name = Form("%s_6", pad->GetName());
+    p = new TPad(name,name,6./8,0.01,0.99,0.25,pad->GetFillColor(),0,0);
+    p->SetNumber(6);
+    p->Draw();
+
+    pad->Divide(2,2);
 
     pad->cd(1);
     gPad->SetBorderMode(0);
+    gPad->SetPad(0.01, 0.5, 0.66, 0.99);
     fSum->Draw("EPhist");
 
     pad->cd(2);
     gPad->SetBorderMode(0);
-    gPad->Divide(2, 1);
-    pad = gPad;
-
-    pad->cd(1);
+    gPad->SetPad(0.66, 0.5, 0.99, 0.99);
+    TH1 *h = fSum->Projection(Form("Proj_%p", this), 50);
+    h->SetTitle("Projection");
+    h->SetBit(kCanDelete);
+    h->Draw();
+
+    pad->cd(3);
+    gPad->SetPad(0.01, 0.01, 3./8, 0.5);
     gPad->SetBorderMode(0);
     fSum->Draw();
 
-    pad->cd(2);
-    gPad->SetBorderMode(0);
-    fRms->Draw();
-}
+    pad->cd(4);
+    gPad->SetPad(3./8, 0.01, 6./8, 0.5);
+    gPad->SetBorderMode(0);
+
+    MHCamera *cam = new MHCamera(*fSum->GetGeometry());
+    cam->SetName(Form("Err_%p", this));
+    cam->SetTitle(TestBit(MHCamera::kVariance)?"Variance":"Root Mean Squared (rms)");
+    cam->SetYTitle(fSum->GetYaxis()->GetTitle());
+    cam->SetCamContent(*fSum, 1);
+    cam->SetBit(kCanDelete);
+    cam->Draw();
+
+    pad->cd(5);
+    h = (TH1*)fSum->RadialProfile(Form("ProfR_%p", this), 20);
+    h->SetTitle("Radial Profile");
+    h->SetBit(kCanDelete|TH1::kNoStats);
+    h->Draw();
+
+    pad->cd(6);
+    h = (TH1*)fSum->AzimuthProfile(Form("ProfA_%p", this), 30);
+    h->SetTitle("Azimuth Profile");
+    h->SetBit(kCanDelete|TH1::kNoStats);
+    h->Draw();
+}
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 5114)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.h	(revision 5143)
@@ -12,6 +12,8 @@
 {
 private:
+    static const TString gsDefName;
+    static const TString gsDefTitle;
+
     MHCamera  *fSum; // storing the sum
-    MHCamera  *fRms; // storing the rms
     MCamEvent *fEvt; //! the current event
 
@@ -20,10 +22,12 @@
     Int_t fType;
 
+    void Init(const char *name, const char *title);
+
     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(Int_t type, const char *name=NULL, const char *title=NULL);
     ~MHCamEvent();
 
@@ -33,4 +37,5 @@
     TH1 *GetHistByName(const TString name="");
 
+    void Paint(Option_t *o="");
     void Draw(Option_t *o="");
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 5114)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 5143)
@@ -75,4 +75,5 @@
 
 #include "MH.h"
+#include "MBinning.h"
 #include "MHexagon.h"
 
@@ -576,17 +577,27 @@
     if (!h1)
     {
-        Double_t min = GetMinimumSectors(sector, aidx);
-        Double_t max = GetMaximumSectors(sector, aidx);
-
-        Int_t newbins=0;
-
-        THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
-
-        h1 = new TH1D(pname, GetTitle(), nbins, min, max);
-        h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
+        h1 = new TH1D;
+        h1->UseCurrentStyle();
+        h1->SetName(pname);
+        h1->SetTitle(GetTitle());
+        h1->SetDirectory(0);
         h1->SetXTitle(GetYaxis()->GetTitle());
         h1->SetYTitle("Counts");
         //h1->Sumw2();
     }
+
+    Double_t min = GetMinimumSectors(sector, aidx);
+    Double_t max = GetMaximumSectors(sector, aidx);
+
+    if (min==max && max>0)
+        min=0;
+    if (min==max && min<0)
+        max=0;
+
+    Int_t newbins=0;
+    THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
+
+    MBinning bins(nbins, min, max);
+    bins.Apply(*h1);
 
     // Fill the projected histogram
@@ -630,55 +641,59 @@
 TProfile *MHCamera::RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name, const Int_t nbins) const
 {
+    // Create the projection histogram
+    TString pname(name);
+    if (name=="_rad")
+    {
+        pname.Prepend(GetName());
+        if (sector.GetSize()>0)
+        {
+            pname += ";";
+            for (int i=0; i<sector.GetSize(); i++)
+                pname += sector[i];
+        }
+        if (aidx.GetSize()>0)
+        {
+            pname += ";";
+            for (int i=0; i<aidx.GetSize(); i++)
+                pname += aidx[i];
+        }
+    }
+
+    TProfile *h1=0;
+
+    //check if histogram with identical name exist
+    TObject *h1obj = gROOT->FindObject(pname);
+    if (h1obj && h1obj->InheritsFrom("TProfile")) {
+        h1 = (TProfile*)h1obj;
+        h1->Reset();
+    }
+
+    if (!h1)
+    {
+        h1 = new TProfile;
+        h1->UseCurrentStyle();
+        h1->SetName(pname);
+        h1->SetTitle(GetTitle());
+        h1->SetDirectory(0);
+        h1->SetXTitle("Radius from camera center [mm]");
+        h1->SetYTitle(GetYaxis()->GetTitle());
+    }
+
+    Double_t min = 0.;
+    Double_t max = fGeomCam->GetMaxRadius();
+
+    Int_t newbins=0;
+
+    THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
+
+    MBinning bins(nbins, min, max);
+    bins.Apply(*h1);
   
-  // Create the projection histogram
-  TString pname(name);
-  if (name=="_rad")
-    {
-      pname.Prepend(GetName());
-      if (sector.GetSize()>0)
-        {
-          pname += ";";
-          for (int i=0; i<sector.GetSize(); i++)
-            pname += sector[i];
-        }
-      if (aidx.GetSize()>0)
-        {
-          pname += ";";
-          for (int i=0; i<aidx.GetSize(); i++)
-            pname += aidx[i];
-        }
-    }
-  
-  TProfile *h1=0;
-  
-  //check if histogram with identical name exist
-  TObject *h1obj = gROOT->FindObject(pname);
-  if (h1obj && h1obj->InheritsFrom("TProfile")) {
-    h1 = (TProfile*)h1obj;
-    h1->Reset();
-  }
-  
-  if (!h1)
-    {
-      
-      Double_t min = 0.;
-      Double_t max = fGeomCam->GetMaxRadius();
-      
-      Int_t newbins=0;
-      
-      THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
-      
-      h1 = new TProfile(pname, GetTitle(), nbins, min, max);
-      h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
-      h1->SetXTitle("Radius from camera center [mm]");
-      h1->SetYTitle(GetYaxis()->GetTitle());
-    }
-  
-  // Fill the projected histogram
-  for (Int_t idx=0; idx<fNcells-2; idx++)
-    if (IsUsed(idx) && MatchSector(idx, sector, aidx))
-      h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY()),
-               GetBinContent(idx+1));
-  return h1;
+    // Fill the projected histogram
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+        if (IsUsed(idx) && MatchSector(idx, sector, aidx))
+            h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY()),
+                     GetBinContent(idx+1));
+    return h1;
 }
 
@@ -710,53 +725,57 @@
 TProfile *MHCamera::AzimuthProfileA(const TArrayI &aidx, const char *name, const Int_t nbins) const
 {
-  
-  // Create the projection histogram
-  TString pname(name);
-  if (name=="_azi")
-    {
-      pname.Prepend(GetName());
-      if (aidx.GetSize()>0)
+    // Create the projection histogram
+    TString pname(name);
+    if (name=="_azi")
+    {
+        pname.Prepend(GetName());
+        if (aidx.GetSize()>0)
         {
-          pname += ";";
-          for (int i=0; i<aidx.GetSize(); i++)
-            pname += aidx[i];
+            pname += ";";
+            for (int i=0; i<aidx.GetSize(); i++)
+                pname += aidx[i];
         }
     }
-  
-  TProfile *h1=0;
-  
-  //check if histogram with identical name exist
-  TObject *h1obj = gROOT->FindObject(pname);
-  if (h1obj && h1obj->InheritsFrom("TProfile")) {
-    h1 = (TProfile*)h1obj;
-    h1->Reset();
-  }
-  
-  if (!h1)
-    {
-      
-      Double_t min = -0.5;
-      Double_t max = 359.5;
-      
-      Int_t newbins=0;
-      
-      THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
-      
-      h1 = new TProfile(pname, GetTitle(), nbins, min, max);
-      h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
-      h1->SetXTitle("Azimuth in camera [deg]");
-      h1->SetYTitle(GetYaxis()->GetTitle());
-    }
-  
-  // Fill the projected histogram
-  for (Int_t idx=0; idx<fNcells-2; idx++)
-    {
-      if (IsUsed(idx) && MatchSector(idx, TArrayI(), aidx))
-        h1->Fill(TMath::ATan2((*fGeomCam)[idx].GetY(),(*fGeomCam)[idx].GetX())*180./TMath::Pi()+180.,
-                 GetPixContent(idx));
-      
-    }
-  
-  return h1;
+
+    TProfile *h1=0;
+
+    //check if histogram with identical name exist
+    TObject *h1obj = gROOT->FindObject(pname);
+    if (h1obj && h1obj->InheritsFrom("TProfile")) {
+        h1 = (TProfile*)h1obj;
+        h1->Reset();
+    }
+
+    if (!h1)
+    {
+
+        h1 = new TProfile;
+        h1->UseCurrentStyle();
+        h1->SetName(pname);
+        h1->SetTitle(GetTitle());
+        h1->SetDirectory(0);
+        h1->SetXTitle("Azimuth in camera [deg]");
+        h1->SetYTitle(GetYaxis()->GetTitle());
+    }
+
+    Double_t min = 0;
+    Double_t max = 360;
+
+    Int_t newbins=0;
+    THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
+
+    MBinning bins(nbins, min, max);
+    bins.Apply(*h1);
+
+    // Fill the projected histogram
+    for (Int_t idx=0; idx<fNcells-2; idx++)
+    {
+        if (IsUsed(idx) && MatchSector(idx, TArrayI(), aidx))
+            h1->Fill(TMath::ATan2((*fGeomCam)[idx].GetY(),(*fGeomCam)[idx].GetX())*TMath::RadToDeg()+180,
+                     GetPixContent(idx));
+
+    }
+
+    return h1;
 }
 
@@ -1599,5 +1618,6 @@
         return TObject::GetObjectInfo(px, py);
 
-    sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
+    sprintf(info, "Software Pixel Idx: %d (Hardware Id=%d) c=%.1f <%s>",
+            idx, idx+1, GetBinContent(idx+1), IsUsed(idx)?"on":"off");
     return info;
 }
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 5114)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 5143)
@@ -262,5 +262,5 @@
     TH1D    *ProjectionS(const TArrayI &sector, const TArrayI &aidx, const char *name="_py", const Int_t nbins=50) const;
 
-    TProfile *RadialProfile(const char *name="_rad") const { return  RadialProfileS(TArrayI(), TArrayI(), name);}
+    TProfile *RadialProfile(const char *name="_rad", Int_t nbins=25) const { return  RadialProfileS(TArrayI(), TArrayI(), name, nbins);}
     TProfile *RadialProfileS(Int_t sector, Int_t aidx, const char *name="_rad", const Int_t nbins=25) const
     {
@@ -269,5 +269,5 @@
     TProfile *RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name="_rad", const Int_t nbins=25) const;
 
-    TProfile *AzimuthProfile(const char *name="_azi") const { return  AzimuthProfileA(TArrayI(), name);  }
+    TProfile *AzimuthProfile(const char *name="_azi", Int_t nbins=25) const { return  AzimuthProfileA(TArrayI(), name, nbins);  }
     TProfile *AzimuthProfile(Int_t aidx, const char *name="_rad", const Int_t nbins=25) const
       {
