Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9313)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9316)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.114 2009-02-09 11:30:53 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.115 2009-02-11 12:17:43 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -627,7 +627,7 @@
         //
         // The margin != 0 is a workaround for a problem in root 4.02/00
-        pad->Divide(1, 1, 1e-10, 1e-10, col);
-        pad->cd(1);
-        gPad->SetBorderMode(0);
+        //pad->Divide(1, 1, 1e-10, 1e-10, col);
+        //pad->cd(1);
+        //gPad->SetBorderMode(0);
     }
 
@@ -639,6 +639,6 @@
     // changes gPad...
     //
-    if (!hassame)
-        pad->cd();
+//    if (!hassame)
+//        pad->cd();
 }
 
@@ -651,4 +651,6 @@
 TObject *MHCamera::DrawClone(Option_t *option) const 
 {
+    return TObject::Clone();
+
    // Draw a clone of this object in the current pad
 
@@ -951,48 +953,4 @@
 }
 
-
-// ------------------------------------------------------------------------
-//
-// Resizes the current pad so that the camera is displayed in its
-// correct aspect ratio
-//
-void MHCamera::SetRange()
-{
-    const Float_t range = fGeomCam->GetMaxRadius()*1.05;
-
-    //
-    // Maintain aspect ratio
-    //
-    const float ratio = TestBit(kNoLegend) ? 1 : 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);
-}
-
 // ------------------------------------------------------------------------
 //
@@ -1140,9 +1098,15 @@
 
     if (!hassame)
-    {
         gPad->Clear();
 
+    if (!fGeomCam)
+        return;
+
+    if (!hassame)
+    {
         // Maintain aspect ratio
-        SetRange();
+        const Float_t r = fGeomCam->GetMaxRadius();
+
+        MH::SetPadRange(-r*1.02, -r*1.02, TestBit(kNoLegend) ? r : 1.15*r, r*1.2);
 
         if (GetPainter())
@@ -1909,11 +1873,11 @@
 void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
 {
-    const Float_t range = fGeomCam->GetMaxRadius()*1.05;
+    const Float_t range = fGeomCam->GetMaxRadius();
 
     if (!TestBit(kNoScale))
     {
         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);
+        arr.PaintArrow(-range*.99, -range*.99, -range*.60, -range*.99, 0.010);
+        arr.PaintArrow(-range*.99, -range*.99, -range*.99, -range*.60, 0.010);
 
         TString text;
@@ -1923,5 +1887,5 @@
         TText newtxt2;
         newtxt2.SetTextSize(0.04);
-        newtxt2.PaintText(-range*.85, -range*.85, text);
+        newtxt2.PaintText(-range*.95, -range*.95, text);
 
         text = MString::Format("%.2f\\circ", range*.3*fGeomCam->GetConvMm2Deg());
@@ -1929,5 +1893,5 @@
 
         TLatex latex;
-        latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
+        latex.PaintLatex(-range*.95, -range*.85, 0, 0.04, text);
     }
 
@@ -1936,6 +1900,6 @@
         TPaveStats *stats = GetStatisticBox();
 
-        const Float_t hndc   = 0.92 - (stats ? stats->GetY1NDC() : 1);
-        const Float_t H      = (0.75-hndc)*range;
+        const Float_t hndc   = 0.88 - (stats ? stats->GetY1NDC() : 1);
+        const Float_t H      = (0.80-hndc)*range;
         const Float_t offset = hndc*range;
 
@@ -2215,68 +2179,49 @@
 void MHCamera::DrawProjection(Int_t fit) const
 {
-    TArrayI inner(1);
-    inner[0] = 0;
-
-    TArrayI outer(1);
-    outer[0] = 1;
-
     if (fit==5 || fit==6)
     {
-        if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
+        const UInt_t n = fGeomCam->GetNumAreas();
+
+        TVirtualPad *pad = gPad;
+        pad->Divide(n, 1, 1e-5, 1e-5);;
+
+        for (UInt_t i=0; i<n; i++)
         {
-            TArrayI s0(6);
-            s0[0] = 6;
-            s0[1] = 1;
-            s0[2] = 2;
-            s0[3] = 3;
-            s0[4] = 4;
-            s0[5] = 5;
-
-            TArrayI s1(3);
-            s1[0] = 6;
-            s1[1] = 1;
-            s1[2] = 2;
-
-            TArrayI s2(3);
-            s2[0] = 3;
-            s2[1] = 4;
-            s2[2] = 5;
-
-            gPad->Clear();
-            TVirtualPad *pad = gPad;
-            pad->Divide(2,1);
-
-            TH1D *inout[2];
-            inout[0] = ProjectionS(s0, inner, "Inner");
-            inout[1] = ProjectionS(s0, outer, "Outer");
-
-            inout[0]->SetDirectory(NULL);
-            inout[1]->SetDirectory(NULL);
-
-            for (int i=0; i<2; i++)
+            pad->cd(i+1);
+            gPad->SetBorderMode(0);
+            gPad->SetRightMargin(0.025);
+            gPad->SetTicks();
+
+            TH1D &h = *ProjectionS(TArrayI(), TArrayI(1, (Int_t*)&i),
+                                   MString::Format("%s_%d", GetName(), i));
+            h.SetTitle(MString::Format("%s %d", GetTitle(), i));
+            h.SetDirectory(NULL);
+            h.SetBit(kCanDelete);
+            h.Draw();
+
+            TAxis *xaxe = h.GetXaxis();
+            TAxis *yaxe = h.GetYaxis();
+
+            xaxe->CenterTitle();
+            yaxe->CenterTitle();
+            xaxe->SetTitleSize(0.06);
+            yaxe->SetTitleSize(0.06);
+            xaxe->SetTitleOffset(0.8);
+            yaxe->SetTitleOffset(0.85);
+            xaxe->SetLabelSize(0.05);
+            yaxe->SetLabelSize(0.05);
+            if (i>0)
+                yaxe->SetTitle("");
+
+            if (fit==5)
+                continue;
+
+            h.Fit("gaus", "Q");
+
+            TF1 *f = h.GetFunction("gaus");
+            if (f)
             {
-                pad->cd(i+1);
-                gPad->SetBorderMode(0);
-
-                inout[i]->SetLineColor(kRed+i);
-                inout[i]->SetBit(kCanDelete);
-                inout[i]->Draw();
-                inout[i]->Fit("gaus","Q");
-
-                if (fit == 6)
-                {
-                    TH1D *half[2];
-                    half[0] = ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
-                    half[1] = ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
-
-                    for (int j=0; j<2; j++)
-                    {
-                        half[j]->SetLineColor(kRed+i+2*j+1);
-                        half[j]->SetDirectory(NULL);
-                        half[j]->SetBit(kCanDelete);
-                        half[j]->Draw("same");
-                    }
-                }
-
+                f->SetLineWidth(2);
+                f->SetLineColor(kBlue);
             }
         }
@@ -2289,51 +2234,14 @@
     obj2->SetBit(kCanDelete);
 
-    if (fit == 0)
-        return;
-
-    if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
-    {
-        TArrayI s0(3);
-        s0[0] = 6;
-        s0[1] = 1;
-        s0[2] = 2;
-
-        TArrayI s1(3);
-        s1[0] = 3;
-        s1[1] = 4;
-        s1[2] = 5;
-
-        TH1D *halfInOut[4];
-
-        // Just to get the right (maximum) binning
-        halfInOut[0] = ProjectionS(s0, inner, "Sector 6-1-2 Inner");
-        halfInOut[1] = ProjectionS(s1, inner, "Sector 3-4-5 Inner");
-        halfInOut[2] = ProjectionS(s0, outer, "Sector 6-1-2 Outer");
-        halfInOut[3] = ProjectionS(s1, outer, "Sector 3-4-5 Outer");
-
-        TLegend *leg = new TLegend(0.05,0.65,0.35,0.9);
-
-        for (int i=0; i<4; i++)
-        {
-            halfInOut[i]->SetLineColor(kRed+i);
-            halfInOut[i]->SetDirectory(0);
-            halfInOut[i]->SetBit(kCanDelete);
-            halfInOut[i]->Draw("same");
-            leg->AddEntry(halfInOut[i],halfInOut[i]->GetTitle(),"l");
-        }
-
-        if (fit==7)
-            leg->Draw();
-      
-        gPad->Modified();
-        gPad->Update();
-    }
-
-    const Double_t min   = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
-    const Double_t max   = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
+    if (fit==0)
+        return;
+
+    const Double_t xmin  = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
+    const Double_t xmax  = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
     const Double_t integ = obj2->Integral("width")/2.5;
+    const Double_t max   = obj2->GetMaximum();
     const Double_t mean  = obj2->GetMean();
     const Double_t rms   = obj2->GetRMS();
-    const Double_t width = max-min;
+    const Double_t width = xmax-xmin;
 
     const TString dgausformula = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
@@ -2347,57 +2255,57 @@
     switch (fit)
     {
-    case 1:
-        f = new TF1("sgaus", "gaus(0)", min, max);
-        f->SetLineColor(kYellow);
+    case 1: // Single gauss
+        f = new TF1("sgaus", "gaus", xmin, xmax);
+        f->SetLineColor(kBlue);
         f->SetBit(kCanDelete);
-        f->SetParNames("Area", "#mu", "#sigma");
-        f->SetParameters(integ/rms, mean, rms);
-        f->SetParLimits(0, 0,   integ);
-        f->SetParLimits(1, min, max);
-        f->SetParLimits(2, 0,   width/1.5);
+        f->SetParNames("Max", "#mu", "#sigma");
+        f->SetParameters(max, mean, rms);
+        f->SetParLimits(0, 0,    max*2);
+        f->SetParLimits(1, xmin, xmax);
+        f->SetParLimits(2, 0,    width/1.5);
 
         obj2->Fit(f, "QLR");
         break;
 
-    case 2:
-        f = new TF1("dgaus",dgausformula.Data(),min,max);
-        f->SetLineColor(kYellow);
+    case 2: // Double gauss
+        f = new TF1("dgaus", dgausformula, xmin, xmax);
+        f->SetLineColor(kBlue);
         f->SetBit(kCanDelete);
         f->SetParNames("A_{tot}", "#mu1", "#sigma1", "A2", "#mu2", "#sigma2");
-        f->SetParameters(integ,(min+mean)/2.,width/4.,
-                         integ/width/2.,(max+mean)/2.,width/4.);
+        f->SetParameters(integ, (xmin+mean)/2., width/4.,
+                         integ/width/2., (xmax+mean)/2., width/4.);
         // The left-sided Gauss
-        f->SetParLimits(0,integ-1.5      , integ+1.5);
-        f->SetParLimits(1,min+(width/10.), mean);
-        f->SetParLimits(2,0              , width/2.);
+        f->SetParLimits(0, integ-1.5,        integ+1.5);
+        f->SetParLimits(1, xmin+(width/10.), mean);
+        f->SetParLimits(2, 0,                width/2.);
         // The right-sided Gauss
-        f->SetParLimits(3,0   , integ);
-        f->SetParLimits(4,mean, max-(width/10.));
-        f->SetParLimits(5,0   , width/2.);
+        f->SetParLimits(3, 0,    integ);
+        f->SetParLimits(4, mean, xmax-(width/10.));
+        f->SetParLimits(5, 0,    width/2.);
         obj2->Fit(f,"QLRM");
         break;
 
-    case 3:
-        f = new TF1("tgaus",tgausformula.Data(),min,max);
-        f->SetLineColor(kYellow);
+    case 3: // Triple gauss
+        f = new TF1("tgaus", tgausformula, xmin,xmax);
+        f->SetLineColor(kBlue);
         f->SetBit(kCanDelete);
         f->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
                        "A_{2}","#mu_{2}","#sigma_{2}",
                        "A_{3}","#mu_{3}","#sigma_{3}");
-        f->SetParameters(integ,(min+mean)/2,width/4.,
-                         integ/width/3.,(max+mean)/2.,width/4.,
-                         integ/width/3.,mean,width/2.);
+        f->SetParameters(integ, (xmin+mean)/2, width/4.,
+                         integ/width/3., (xmax+mean)/2., width/4.,
+                         integ/width/3., mean,width/2.);
         // The left-sided Gauss
-        f->SetParLimits(0,integ-1.5,integ+1.5);
-        f->SetParLimits(1,min+(width/10.),mean);
-        f->SetParLimits(2,width/15.,width/2.);
+        f->SetParLimits(0, integ-1.5,        integ+1.5);
+        f->SetParLimits(1, xmin+(width/10.), mean);
+        f->SetParLimits(2, width/15.,        width/2.);
         // The right-sided Gauss
-        f->SetParLimits(3,0.,integ);
-        f->SetParLimits(4,mean,max-(width/10.));
-        f->SetParLimits(5,width/15.,width/2.);
+        f->SetParLimits(3, 0.,               integ);
+        f->SetParLimits(4, mean,             xmax-(width/10.));
+        f->SetParLimits(5, width/15.,        width/2.);
         // The Gauss describing the outliers
-        f->SetParLimits(6,0.,integ);
-        f->SetParLimits(7,min,max);
-        f->SetParLimits(8,width/4.,width/1.5);
+        f->SetParLimits(6, 0.,               integ);
+        f->SetParLimits(7, xmin,             xmax);
+        f->SetParLimits(8, width/4.,         width/1.5);
         obj2->Fit(f,"QLRM");
         break;
@@ -2405,5 +2313,5 @@
     case 4:
         obj2->Fit("pol0", "Q");
-        obj2->GetFunction("pol0")->SetLineColor(kYellow);
+        obj2->GetFunction("pol0")->SetLineColor(kBlue);
         break;
 
@@ -2413,9 +2321,9 @@
     default:
         obj2->Fit("gaus", "Q");
-        obj2->GetFunction("gaus")->SetLineColor(kYellow);
+        obj2->GetFunction("gaus")->SetLineColor(kBlue);
         break;
     }
 }
-
+/*
 // --------------------------------------------------------------------------
 //
@@ -2508,5 +2416,5 @@
     }
 }
-
+*/
 // --------------------------------------------------------------------------
 //
@@ -2527,12 +2435,14 @@
 //
 void MHCamera::CamDraw(TCanvas &c, const Int_t x, const Int_t y, 
-                       const Int_t fit, const Int_t rad, const Int_t azi,
+                       const Int_t fit, /*const Int_t rad, const Int_t azi,*/
                        TObject *notify)
 {
     c.cd(x);
     gPad->SetBorderMode(0);
+    gPad->SetRightMargin(0.02);
     gPad->SetTicks();
     MHCamera *obj1=(MHCamera*)DrawCopy("hist");
     obj1->SetDirectory(NULL);
+    obj1->SetStats(kFALSE);
 
     if (notify)
@@ -2545,5 +2455,5 @@
 
     Int_t cnt = 2;
-
+/*
     if (rad)
     {
@@ -2563,10 +2473,11 @@
         cnt++;
     }
-
-    if (!fit)
+  */
+    if (fit<0)
         return;
 
     c.cd(x + cnt*y);
     gPad->SetBorderMode(0);
+    gPad->SetRightMargin(0.025);
     gPad->SetTicks();
     DrawProjection(fit);
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9313)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9316)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.67 2009-02-09 11:30:53 tbretz Exp $
+!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.68 2009-02-11 12:17:43 tbretz Exp $
 \* ======================================================================== */
 #ifndef MARS_MHCamera
@@ -80,5 +80,4 @@
     void  Update(Bool_t islog, Bool_t isbox, Bool_t iscol, Bool_t issame);
     void  UpdateLegend(Float_t min, Float_t max, Bool_t islog);
-    void  SetRange();
 
     TPaveStats *GetStatisticBox();
@@ -231,6 +230,6 @@
     TObject *DrawClone(Option_t *option="") const;
     void     DrawProjection (Int_t fit=0) const;
-    void     DrawRadialProfile()           const;
-    void     DrawAzimuthProfile()          const;
+//    void     DrawRadialProfile()           const;
+//    void     DrawAzimuthProfile()          const;
 
     void     SavePrimitive(ostream &out, Option_t *);
@@ -320,5 +319,5 @@
     
     void CamDraw(TCanvas &c, const Int_t x, const Int_t y, 
-                 const Int_t fit, const Int_t rad=0, const Int_t azi=0,
+                 const Int_t fit, /*const Int_t rad=0, const Int_t azi=0,*/
                  TObject *notify=NULL);             
     
