Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9302)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9312)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.43 2009-02-07 20:40:12 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.44 2009-02-10 20:00:09 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1813,2 +1813,58 @@
     return "MH::GetObjectInfo: unknown class.";
 }
+
+// --------------------------------------------------------------------------
+//
+// Set the pad-range such that at the smallest width it is still
+// two times max and that the displayed "pixels" (i.e. its coordinate
+// system) have the width to height ratio of aspect.
+//
+void MH::SetPadRange(Float_t max, Float_t aspect)
+{
+    if (!gPad)
+        return;
+
+    const Float_t w = gPad->GetWw();
+    const Float_t h = gPad->GetWh();
+
+    if (w>aspect*h)
+    {
+        const Double_t dx = ((w/h-aspect)/2+1)*max;
+        gPad->Range(-dx, -max, dx, max);
+    }
+    else
+    {
+        const Double_t dy = ((h/w-1./aspect)/2+1)*max;
+        gPad->Range(-max, -dy, max, dy);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the range of a pad in a way that the coordinates fit into the pad
+// without abberation.
+//
+void MH::SetPadRange(Float_t x0, Float_t y0, Float_t x1, Float_t y1)
+{
+    if (!gPad)
+        return;
+
+    const Float_t w = x1-x0;                              // Width  in user coordinates
+    const Float_t h = y1-y0;                              // Hieght in user coordinates
+
+    const Float_t ww = gPad->GetWw()*gPad->GetAbsWNDC();  // Width  of pad in pixels
+    const Float_t hh = gPad->GetWh()*gPad->GetAbsHNDC();  // Height of pad in pixels
+
+    if (ww/hh > w/h)
+    {
+        const Double_t dx = (ww/hh-w/h)/2*h;
+
+        gPad->Range(x0-dx, y0, x1+dx, y1);
+    }
+    else
+    {
+        const Double_t dy = (hh/ww-h/w)/2*w;
+
+        gPad->Range(x0, y0-dy, x1, y1+dy);
+    }
+}
Index: trunk/MagicSoft/Mars/mhbase/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.h	(revision 9302)
+++ trunk/MagicSoft/Mars/mhbase/MH.h	(revision 9312)
@@ -130,4 +130,6 @@
 
     static void SetPalette(TString paletteName="pretty", Int_t ncol=50);
+    static void SetPadRange(Float_t max, Float_t aspect=1);
+    static void SetPadRange(Float_t x0, Float_t y0, Float_t x1, Float_t y1);
 
     static char *GetObjectInfoH(Int_t px, Int_t py, const TH1 &h);
