Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7000)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7001)
@@ -21,4 +21,55 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/05/09 Thomas Bretz
+
+   * callisto.cc, ganymed.cc, mars.cc, merpp.cc, readdaq.cc,
+     readraw.cc, showplot.cc, sinope.cc, sponde.cc, star.cc:
+     - changed order of initialization such that a real NULL 
+       output is possible
+     - changed TApplication name from upper to lower case
+     - in some applications replaced manual setup of gLog with
+       gLog.Setup
+
+   * showlog.cc:
+     - improved alorithm
+
+   * showplot.cc:
+     - implemented Print options
+
+   * mbase/MLog.[h,cc]:
+     - fixed a bug which caused output in NULL output
+     - added Getter IsNullOutput
+
+   * mbase/MStatusDisplay.[h,cc]:
+     - implemented PDF and SVG printing
+     - moved "Save As Something" to new submenu
+     - fixed and improved printing
+     - implemented PrintDialog for printing
+     - implemented printing of log (untested)
+     - allow saving by extension (line Print() in root): SaveAs
+
+   * mfileio/MWriteRootFile.h:
+     - replaced BIT(17) by BIT(23) to improve compatibility with
+       root 4.04/00 and upcomming versions
+
+   * mhflux/Makefile, mjobs/MJCut.cc:
+     - replaced MTheta by MThetaSq to get rid of a problem
+       with the automatic naming of the binning (BinningTheta)
+
+   * mhist/MHCamera.[h,cc]:
+     - fixed a workaround (it has been fixed in root 4.04/00)
+     - allow setting the palette through the Draw-option. This allows
+       storage of the palette
+     - removed fColor. The palette is now diretly set though gStyle in
+       Paint
+
+   * mjobs/MJOptimize.cc:
+     - restore null output correctly after eventloop
+
+   * mjobs/MJSpectrum.cc:
+     - renamed Hist and HistOff to HistE and HistEOff
+     - added binnings M3Long and Conc1
+
+
 
  2005/05/06 Thomas Bretz
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 7000)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 7001)
@@ -51,4 +51,22 @@
      this variable (one is already existing: MHTheta, which is now the
      default in ganymed). It is setup through ganymed.rc
+
+   - Improved support for printing in status display:
+     + A default can now be set in .rootrc (for more details see 
+       MStatusDisplay::PrintPS)
+     + A print dialog is opened so that printer and command line
+       can be canged
+
+   - improved showplot
+     + The new graphics formats have been implemented 
+       (pdf, svg, png, jpg and xpm)
+     + Implemented an interface for printing. Because you can change
+       the printing command from the command line you can use all
+       the nice postscript tool. To print a booklet for example call: 
+       showplot -b --print --print-cmd="cat %f" filename.root | lpr
+       showplot -b --print --print-cmd="psbook %f | psnup -2 | lpr" filename.root
+       showplot -b --null --print --print-cmd="psbook %f" filename.root > book.ps
+
+   - The storage of the palette in MHCamera is now possible
 
 
Index: /trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- /trunk/MagicSoft/Mars/callisto.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/callisto.cc	(revision 7001)
@@ -142,10 +142,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -157,6 +158,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     const TString kConfig     = arg.GetStringAndRemove("--config=", "callisto.rc");
@@ -322,5 +321,5 @@
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    TApplication app("Callisto", &argc, argv);
+    TApplication app("callisto", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
Index: /trunk/MagicSoft/Mars/ganymed.cc
===================================================================
--- /trunk/MagicSoft/Mars/ganymed.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/ganymed.cc	(revision 7001)
@@ -89,10 +89,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -104,6 +105,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     const TString kConfig       = arg.GetStringAndRemove("--config=", "ganymed.rc");
@@ -204,5 +203,5 @@
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    TApplication app("Ganymed", &argc, argv);
+    TApplication app("ganymed", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
Index: /trunk/MagicSoft/Mars/mars.cc
===================================================================
--- /trunk/MagicSoft/Mars/mars.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mars.cc	(revision 7001)
@@ -69,6 +69,5 @@
     gLog << "Sorry the usage is:" << endl;
     gLog << "   mars [-h] [-?] [-a0] [-vn]" << endl << endl;
-    gLog << "     -a0: Do not use Ansii codes." << endl;
-    gLog << "     -vn: Verbosity level n [default=2]" << endl;
+    gLog.Usage();
     gLog << "     -?/-h: This help" << endl << endl;
 }
@@ -76,10 +75,11 @@
 int main(int argc, char **argv)
 {
-    StartUpMessage();
-
     //
     // Evaluate arguments
     //
-    MArgs arg(argc, argv);
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
+    StartUpMessage();
 
     if (arg.HasOption("-?") || arg.HasOption("-h"))
@@ -88,12 +88,4 @@
         return 2;
     }
-
-    //
-    // Set verbosity to highest level.
-    //
-    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
-
-    if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
-        gLog.SetNoColors();
 
 #ifdef HAVE_XPM
@@ -105,5 +97,5 @@
     // initialise ROOT
     //
-    TApplication app("Mars", &argc, argv);
+    TApplication app("mars", &argc, argv);
     if (gROOT->IsBatch() || !gClient)
     {
Index: /trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 7001)
@@ -134,8 +134,8 @@
 #endif
 const char *const MLog::kBlue      = "\033[34m";
-const char *const MLog::kUnderline = "\033[4m";;
-const char *const MLog::kBlink     = "\033[5m";;
-const char *const MLog::kBright    = "\033[1m";;
-const char *const MLog::kDark      = "\033[2m";;
+const char *const MLog::kUnderline = "\033[4m";
+const char *const MLog::kBlink     = "\033[5m";
+const char *const MLog::kBright    = "\033[1m";
+const char *const MLog::kDark      = "\033[2m";
 
 //
@@ -488,5 +488,5 @@
     if (fDevice&eStdout)
     {
-        if (!TestBit(eNoColors))
+        if (!fIsNull && !TestBit(eNoColors))
             cout << kReset;
         cout.flush();
Index: /trunk/MagicSoft/Mars/mbase/MLog.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MLog.h	(revision 7000)
+++ /trunk/MagicSoft/Mars/mbase/MLog.h	(revision 7001)
@@ -129,4 +129,5 @@
     void operator=(TGTextView *out)     { SetOutputGui(out);  }
 
+    Bool_t IsNullOutput() const { return fIsNull; }
     Bool_t IsOutputDeviceEnabled(int i) const { return fDevice & i; }
 
Index: /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7001)
@@ -33,5 +33,5 @@
 // To write gif files of C-Macros use SaveAsGif()/SaveAsPNG() or SaveAsC().
 // Direct printing to the default printer (via lpr) can be done by
-// PrintToLpr().
+// PrintPS().
 //
 // It has also to half status lines which can be used to display the status
@@ -64,4 +64,6 @@
 
 #include <TH1.h>                  // TH1::AddDirectory
+#include <TPDF.h>                 // TPDF
+#include <TSVG.h>                 // TSVG
 #include <TEnv.h>                 // TEnv
 #include <TLine.h>                // TLine
@@ -74,4 +76,5 @@
 #include <TDatime.h>              // TDatime
 #include <TRandom.h>              // TRandom
+#include <TRegexp.h>              // TRegexp
 #include <TThread.h>              // TThread::Self()
 #include <TBrowser.h>             // TBrowser
@@ -80,5 +83,4 @@
 #include <TMethodCall.h>          // TMethodCall
 
-//#include <TRint.h>                // gApplication, TRint::Class()
 #include <TInterpreter.h>         // gInterpreter
 
@@ -92,4 +94,5 @@
 #include <TGFileDialog.h>         // TGFileDialog
 #include <TGProgressBar.h>        // TGHProgressBar
+#include <TGTextEditDialogs.h>    // TGPrintDialog
 #include <TRootEmbeddedCanvas.h>  // TRootEmbeddedCanvas
 
@@ -245,26 +248,36 @@
     //
     MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
-    // filemenu->AddEntry("Save &As...", kFileSaveAs);
-    filemenu->AddEntry("New Can&vas",   kFileCanvas);
-    filemenu->AddEntry("New &Browser",  kFileBrowser);
+    filemenu->AddEntry("New &Canvas",       kFileCanvas);
+    filemenu->AddEntry("New &Browser",      kFileBrowser);
     filemenu->AddSeparator();
-    filemenu->AddEntry("Save status.&ps",   kFileSaveAsPS);
-    filemenu->AddEntry("Save status.&png",  kFileSaveAsPNG);
-    filemenu->AddEntry("Save status.&gif",  kFileSaveAsGIF);
-    filemenu->AddEntry("Save status.&jpg",  kFileSaveAsJPG);
-    filemenu->AddEntry("Save status.&xpm",  kFileSaveAsXPM);
-    filemenu->AddEntry("Save status.&C",    kFileSaveAsC);
-    filemenu->AddEntry("Save status.&root", kFileSaveAsRoot);
+
+    const TString fname(MString::Form("Save %s.", gROOT->GetName()));
+    MGPopupMenu *savemenu = new MGPopupMenu(gClient->GetRoot());
+    savemenu->AddEntry(MString::Form("%s&ps",  fname.Data()),  kFileSaveAsPS);
+    savemenu->AddEntry(MString::Form("%sp&df", fname.Data()),  kFileSaveAsPDF);
+    savemenu->AddEntry(MString::Form("%s&svg", fname.Data()),  kFileSaveAsSVG);
+    savemenu->AddSeparator();
+    savemenu->AddEntry(MString::Form("%sp&ng", fname.Data()),  kFileSaveAsPNG);
+    savemenu->AddEntry(MString::Form("%s&gif", fname.Data()),  kFileSaveAsGIF);
+    savemenu->AddEntry(MString::Form("%s&jpg", fname.Data()),  kFileSaveAsJPG);
+    savemenu->AddEntry(MString::Form("%s&xpm", fname.Data()),  kFileSaveAsXPM);
+    //savemenu->AddEntry("Save status.x&cf",  kFileSaveAsXCF);
+    //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF);
+    //savemenu->AddEntry("Save status.&bmp",  kFileSaveAsBMP);
+    savemenu->AddSeparator();
+    savemenu->AddEntry(MString::Form("%s&C",    fname.Data()), kFileSaveAsC);
+    savemenu->AddEntry(MString::Form("%s&root", fname.Data()), kFileSaveAsRoot);
+    savemenu->Associate(this);
+
+    filemenu->AddEntry("&Open...",          kFileOpen);
+    filemenu->AddPopup("&Save", savemenu);
+    filemenu->AddEntry("Save &As...",       kFileSaveAs);
     filemenu->AddSeparator();
-    filemenu->AddEntry("&Open...",             kFileOpen);
-    filemenu->AddEntry("Save &As...",          kFileSaveAs);
+    filemenu->AddEntry("&Reset",            kFileReset);
     filemenu->AddSeparator();
-    filemenu->AddEntry("Re&set",               kFileReset);
+    filemenu->AddEntry("&Print",            kFilePrint);
     filemenu->AddSeparator();
-    filemenu->AddEntry("Print with &lpr",      kFilePrint);
-    //filemenu->AddEntry("Set printer &name",    kFilePrinterName);
-    filemenu->AddSeparator();
-    filemenu->AddEntry("C&lose", kFileClose);
-    filemenu->AddEntry("E&xit", kFileExit);
+    filemenu->AddEntry("C&lose",            kFileClose);
+    filemenu->AddEntry("E&xit",             kFileExit);
     filemenu->Associate(this);
 
@@ -273,20 +286,32 @@
     //
     MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
-    tabmenu->AddEntry("Next [&+]",           kTabNext);
-    tabmenu->AddEntry("Previous [&-]",       kTabPrevious);
+    tabmenu->AddEntry("Next [&+]",          kTabNext);
+    tabmenu->AddEntry("Previous [&-]",      kTabPrevious);
     tabmenu->AddSeparator();
-    tabmenu->AddEntry("Save tab-i.&ps",   kTabSaveAsPS);
-    tabmenu->AddEntry("Save tab-i.&png",  kTabSaveAsPNG);
-    tabmenu->AddEntry("Save tab-i.&gif",  kTabSaveAsGIF);
-    tabmenu->AddEntry("Save tab-i.&jpg",  kTabSaveAsJPG);
-    tabmenu->AddEntry("Save tab-i.&xpm",  kTabSaveAsXPM);
-    tabmenu->AddEntry("Save tab-i.&C",    kTabSaveAsC);
-    tabmenu->AddEntry("Save tab-i.&root", kTabSaveAsRoot);
+
+    const TString fname2(MString::Form("Save %s-i.", gROOT->GetName()));
+    MGPopupMenu *savemenu2 = new MGPopupMenu(gClient->GetRoot());
+    savemenu2->AddEntry(MString::Form("%s&ps",  fname2.Data()),  kTabSaveAsPS);
+    savemenu2->AddEntry(MString::Form("%sp&df", fname2.Data()),  kTabSaveAsPDF);
+    savemenu2->AddEntry(MString::Form("%s&svg", fname2.Data()),  kTabSaveAsSVG);
+    savemenu2->AddSeparator();
+    savemenu2->AddEntry(MString::Form("%sp&ng", fname2.Data()),  kTabSaveAsPNG);
+    savemenu2->AddEntry(MString::Form("%s&gif", fname2.Data()),  kTabSaveAsGIF);
+    savemenu2->AddEntry(MString::Form("%s&jpg", fname2.Data()),  kTabSaveAsJPG);
+    savemenu2->AddEntry(MString::Form("%s&xpm", fname2.Data()),  kTabSaveAsXPM);
+    //savemenu->AddEntry("Save status.x&cf",  kFileSaveAsXCF);
+    //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF);
+    //savemenu->AddEntry("Save status.&bmp",  kFileSaveAsBMP);
+    savemenu2->AddSeparator();
+    savemenu2->AddEntry(MString::Form("%s&C",    fname2.Data()), kTabSaveAsC);
+    savemenu2->AddEntry(MString::Form("%s&root", fname2.Data()), kTabSaveAsRoot);
+    savemenu2->Associate(this);
+
+    tabmenu->AddPopup("&Save", savemenu2);
+    tabmenu->AddEntry("Save tab &As...",    kTabSaveAs);
     tabmenu->AddSeparator();
-    tabmenu->AddEntry("Save tab &As...",         kTabSaveAs);
+    tabmenu->AddEntry("&Remove",            kTabRemove);
     tabmenu->AddSeparator();
-    tabmenu->AddEntry("Re&move",             kTabRemove);
-    tabmenu->AddSeparator();
-    tabmenu->AddEntry("Print with &lpr",     kTabPrint);
+    tabmenu->AddEntry("&Print",             kTabPrint);
     tabmenu->Associate(this);
 
@@ -326,4 +351,6 @@
     logmenu->AddEntry("&Save",          kLogSave);
     logmenu->AddEntry("Save &append",   kLogAppend);
+    logmenu->AddSeparator();
+    logmenu->AddEntry("&Print",         kLogPrint);
     logmenu->Associate(this);
 
@@ -355,4 +382,6 @@
     // Add everything to autodel list
     //
+    fList->Add(savemenu);
+    fList->Add(savemenu2);
     fList->Add(filemenu);
     fList->Add(loopmenu);
@@ -1085,42 +1114,125 @@
 }
 
+TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext)
+{
+    // If not in batch mode open a user dialog
+    if (!gROOT->IsBatch())
+    {
+        char *cprinter = StrDup(p);
+        char *ccmd     = StrDup(c);
+
+        Int_t rc=0;
+        new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc);
+        if (rc)
+        {
+            p = cprinter; // default has been changed
+            c = ccmd;
+        }
+
+        delete [] cprinter;
+        delete [] ccmd;
+
+        if (!rc)
+            return "";
+    }
+
+
+    if (c.Contains("%f") && ext)
+    {
+        // Get temporary file name
+        TString name = "mars";
+
+        FILE *f = gSystem->TempFileName(name, t);
+        if (!f)
+        {
+            *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl;
+            SetStatusLine2("failed!");
+            return "";
+        }
+        fclose(f);
+
+        // remove temp file
+        gSystem->Unlink(name);
+        name += ".";
+        name += ext;
+
+        t = name;
+    }
+
+    // compile command
+    TString cmd(c);
+
+    // if sprinter.IsNull we assume that everything around %p can
+    // be omitted and the program uses some kind of default
+    if (p.IsNull())
+    {
+        TString sub;
+        while (1)
+        {
+            sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth);
+            if (sub.IsNull())
+                break;
+
+            cmd.ReplaceAll(sub, "");
+        }
+    }
+
+    cmd.ReplaceAll("%p", p);
+    cmd.ReplaceAll("%f", t);
+
+    return cmd;
+}
+
 // --------------------------------------------------------------------------
 //
 // Saves the given canvas (pad) or all pads (num<0) as a temporary
-// postscript file and prints it using 'lpr'. If a printer name is set
-// via SetPrinter 'lpr -Pname' is used.
-//
-Int_t MStatusDisplay::PrintToLpr(Int_t num)
-{
-    TString name = "mars";
-
-    for (int i=0; i<6; i++)
-        name += (char)(gRandom->Uniform(25)+65);
-
-    name += ".ps";
-
-    const Int_t pages = SaveAsPS(num, name);
-
+// postscript file and prints it.
+//
+// The default command line c is: lpr -P%p %f
+//   %p: printer name
+//   %f: temporary file name
+//
+// The default printer name p is: <empty>
+//
+// Both can be changed in .rootrc by:
+//   PrintPS.Printer
+//   PrintPS.Command
+//
+// Ant the location of the temporary file t can by changed by
+//   Print.Directory
+// the default is the system default directory (normally /tmp)
+//
+Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t)
+{
+    static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:"");
+    static TString scmd     = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f");
+
+    TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory());
+
+    TString cmd = PrintDialog(sprinter, scmd, tmp, "ps");
+    if (cmd.IsNull())
+        return 0;
+
+    // set status lines
     SetStatusLine1("Printing...");
     SetStatusLine2("");
 
+    // print to temporary file
+    const Int_t pages = SaveAsPS(num, tmp);
+
+    // check
     if (!pages)
     {
-        *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
+        *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl;
         SetStatusLine2("Failed!");
         return 0;
     }
 
-    TString cmd="lpr ";
-    if (!fPrinter.IsNull())
-    {
-        cmd += "-P";
-        cmd += fPrinter;
-        cmd += " ";
-    }
-    cmd += name;
-
+    // execute command
+    *fLog << dbg << "Executing: " << cmd << endl;
     gSystem->Exec(cmd);
-    gSystem->Unlink(name);
+
+    // remove temporary file
+    gSystem->Unlink(tmp);
 
     SetStatusLine2(MString::Form("Done (%dpage(s))", pages));
@@ -1226,4 +1338,97 @@
 }
 
+Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const
+{
+    TString name(n);
+    AddExtension(name, "ps");
+
+    // Code taken from TGTextEdit::Print
+    const TString pipe = MString::Form("a2ps -o%s", name.Data());
+    FILE *p = gSystem->OpenPipe(pipe, "w");
+    if (!p)
+    {
+        *fLog << err << "ERROR - Couldn't open pipe " << pipe << endl;
+        return kFALSE;
+    }
+
+    TGText *text = fLogBox->GetText();
+
+    char   *buf1, *buf2;
+    Long_t  len;
+    ULong_t i = 0;
+    TGLongPosition pos;
+
+    pos.fX = pos.fY = 0;
+    while (pos.fY < text->RowCount())
+    {
+        len = text->GetLineLength(pos.fY);
+        buf1 = text->GetLine(pos, len);
+        buf2 = new char[len + 2];
+        strncpy(buf2, buf1, (UInt_t)len);
+        buf2[len]   = '\n';
+        buf2[len+1] = '\0';
+        while (buf2[i] != '\0') {
+            if (buf2[i] == '\t') {
+                ULong_t j = i+1;
+                while (buf2[j] == 16 && buf2[j] != '\0')
+                    j++;
+                strcpy(buf2+i+1, buf2+j);
+            }
+            i++;
+        }
+        fwrite(buf2, sizeof(char), strlen(buf2)+1, p);
+
+        delete [] buf1;
+        delete [] buf2;
+        pos.fY++;
+    }
+    gSystem->ClosePipe(p);
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the log text.
+//
+// The default command line c is: a2ps -P%p
+//   %p: printer name
+//
+// The default printer name p is: <empty>
+//
+// Both can be changed in .rootrc by:
+//   PrintText.Printer
+//   PrintText.Command
+//
+Bool_t MStatusDisplay::PrintLog(const char *p, const char *c)
+{
+    static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:"");
+    static TString scmd     = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p");
+
+    TString tmp;
+    TString cmd = PrintDialog(sprinter, scmd, tmp);
+    if (cmd.IsNull())
+        return kFALSE;
+
+    // set status lines
+    SetStatusLine1("Printing...");
+    SetStatusLine2("");
+
+    // print to temporary file
+    if (!SaveLogAsPS(cmd))
+    {
+        *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl;
+        SetStatusLine2("Failed!");
+        return kFALSE;
+    }
+
+    // execute command
+    *fLog << dbg << "Executing: " << cmd << endl;
+    gSystem->Exec(cmd);
+
+    SetStatusLine2("Done.");
+
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1267,4 +1472,12 @@
         return kTRUE;
 
+    case kFileSaveAsPDF:
+        SaveAsPDF();
+        return kTRUE;
+
+    case kFileSaveAsSVG:
+        SaveAsSVG();
+        return kTRUE;
+
     case kFileSaveAsPNG:
         SaveAsPNG();
@@ -1283,4 +1496,16 @@
         return kTRUE;
 
+    //case kFileSaveAsXCF:
+    //    SaveAsXCF();
+    //    return kTRUE;
+
+    //case kFileSaveAsTIFF:
+    //    SaveAsTIFF();
+    //    return kTRUE;
+
+    //case kFileSaveAsBMP:
+    //    SaveAsBMP();
+    //    return kTRUE;
+
     case kFileSaveAsC:
         SaveAsC();
@@ -1292,5 +1517,5 @@
 
     case kFilePrint:
-        PrintToLpr();
+        PrintPS();
         return kTRUE;
 
@@ -1303,4 +1528,12 @@
         return kTRUE;
 
+    case kTabSaveAsPDF:
+        SaveAsPDF(fTab->GetCurrent());
+        return kTRUE;
+
+    case kTabSaveAsSVG:
+        SaveAsSVG(fTab->GetCurrent());
+        return kTRUE;
+
     case kTabSaveAsPNG:
         SaveAsPNG(fTab->GetCurrent());
@@ -1319,4 +1552,16 @@
         return kTRUE;
 
+    //case kTabSaveAsXCF:
+    //    SaveAsXCF(fTab->GetCurrent());
+    //    return kTRUE;
+
+    //case kTabSaveAsBMP:
+    //    SaveAsBMP(fTab->GetCurrent());
+    //    return kTRUE;
+
+    //case kTabSaveAsTIFF:
+    //    SaveAsTIFF(fTab->GetCurrent());
+    //    return kTRUE;
+
     case kTabSaveAsC:
         SaveAsC(fTab->GetCurrent());
@@ -1328,5 +1573,5 @@
 
     case kTabPrint:
-        PrintToLpr(fTab->GetCurrent());
+        PrintPS(fTab->GetCurrent());
         return kTRUE;
 
@@ -1386,5 +1631,5 @@
         SetStatusLine2("");
         *fLog << inf << "Saving log... " << flush;
-        if (fLogBox->GetText()->Save("statusdisplay.log"))
+        if (fLogBox->GetText()->Save(MString::Form("%s.log", gROOT->GetName())))
         {
             *fLog << "done." << endl;
@@ -1402,5 +1647,5 @@
         SetStatusLine2("");
         *fLog << inf << "Appending log... " << flush;
-        if (fLogBox->GetText()->Append("statusdisplay.log"))
+        if (fLogBox->GetText()->Append(MString::Form("%s.log", gROOT->GetName())))
         {
             *fLog << "done." << endl;
@@ -1412,4 +1657,8 @@
             SetStatusLine2("Failed!");
         }
+        return kTRUE;
+
+    case kLogPrint:
+        PrintLog();
         return kTRUE;
 #ifdef DEBUG
@@ -1973,5 +2222,5 @@
     if (name.IsNull())
     {
-        name = "status";
+        name = gROOT->GetName();
         if (num>0)
         {
@@ -2042,57 +2291,32 @@
     gSystem->Unlink(name);
     gSystem->Rename(name+".$$$", name);
-/*
-    //
-    // Old style algorithm. Shifts blocks inside a single file --- SLOW!
-    //
-    const Int_t l = newstr.Length();
-
-    Long_t t[4]; // { id, size, flags, modtime }
-    gSystem->GetPathInfo(name, t, t+1, t+2, t+3);
-
-    char *c[2] = { new char[l], new char[l] };
-
-    fstream f(name, ios::in|ios::out);
-
-    TString str;
-    f >> str >> c[0][0];     // Read "%!PS-Adobe-2.0\n" (Mini Header)
-    f.read(c[0], l);
-    f.seekp(-l, ios::cur);
-    f.write(newstr, l);
-
-    int i=0;
-    while (1)
-    {
-        f.read(c[(i+1)%2], l);
-        f.seekp(-l, ios::cur);
-
-        if (f)
-        {
-            f.write(c[i%2],l);
-            i++;
-            i%=2;
-            continue;
-        }
-
-        const Int_t ssz   = str.Length()+1;        // Length of Mini-Header
-        const Int_t block = t[1]-ssz;              // Length of block to be shifted
-        const Int_t size  = block%l;               // Reminder
-        const Int_t pos   = (block/l)*l + ssz + 1; // Position to start writing
-
-        f.clear();
-        f.seekp(pos);
-        f.write(c[i%2], l);
-        f.write(c[(i+1)%2], size);
-        break;
-    }
-
-    delete c[1];
-    delete c[0];
-*/
-}
-
-// --------------------------------------------------------------------------
-//
-// In case of num<0 all tabs are written into the PS file. If num>0
+}
+
+void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
+{
+    if (vps.InheritsFrom(TPostScript::Class()))
+        static_cast<TPostScript&>(vps).Range(psw, psh);
+    // if (vps.InheritsFrom(TPDF::Class()))
+    //     static_cast<TPDF&>(vps).Range(psw/2, psh/2);
+    // if (vps.InheritsFrom(TSVG::Class()))
+    //     static_cast<TSVG&>(vps).Range(psw, psh);
+}
+
+void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
+{
+    if (vps.InheritsFrom(TPostScript::Class()))
+        static_cast<TPostScript&>(vps).TextNDC(u, v, string);
+    // if (vps.InheritsFrom(TPDF::Class()))
+    //    static_cast<TPDF&>(vps).TextNDC(u, v, string);
+    // if (vps.InheritsFrom(TSVG::Class()))
+    //    static_cast<TSVG&>(vps).TextNDC(u, v, string);
+}
+
+// --------------------------------------------------------------------------
+//
+// Write some VGF (vector graphics format). Currently PS, PDF and SVG
+// is available. Specified by ext.
+//
+// In case of num<0 all tabs are written into the VGF file. If num>0
 // the canvas in the corresponding tab is written to the file.
 // Name is the name of the file (with or without extension).
@@ -2100,5 +2324,5 @@
 // Returns the number of pages written.
 //
-// To write all tabs you can also use SaveAsPS(name)
+// To write all tabs you can also use SaveAsVGF(name, ext)
 //
 // If the third argument is given a bottom line is drawn with the text
@@ -2106,7 +2330,7 @@
 // fTitle (SetTitle) is not empty.
 //
-Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name, const TString addon)
-{
-    SetStatusLine1("Writing Postscript file...");
+Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
+{
+    SetStatusLine1(Form("Writing %s file...",ext.Data()));
     SetStatusLine2("");
 
@@ -2117,8 +2341,8 @@
     }
 
-    AddExtension(name, "ps", num);
+    AddExtension(name, ext, num);
 
     if (num<0)
-        *fLog << inf << "Open ps-File: " << name << endl;
+        *fLog << inf << "Open " << ext << "-File: " << name << endl;
 
     TPad       *padsav = (TPad*)gPad;
@@ -2127,9 +2351,35 @@
     TDatime d;
 
-    TPostScript ps(name, 112);
-    ps.SetBit(TPad::kPrintingPS);
-    ps.PrintFast(13, "/nan {1} def ");
-
-    gVirtualPS = &ps;
+    Int_t type = -1;
+
+    TVirtualPS *ps =0;
+    if (!ext.CompareTo("ps", TString::kIgnoreCase))
+    {
+        ps = new TPostScript(name, 112);
+        type = 1;
+    }
+    if (!ext.CompareTo("pdf", TString::kIgnoreCase))
+    {
+        ps = new TPDF(name, 112);
+        type = 2;
+    }
+    if (!ext.CompareTo("svg", TString::kIgnoreCase))
+    {
+        ps = new TSVG(name, 112);
+        type = 3;
+    }
+
+    if (!ps)
+    {
+        *fLog << err << "Extension " << ext << " unknown..." << endl;
+        SetStatusLine2("Failed!");
+        return 0;
+    }
+
+    ps->SetBit(TPad::kPrintingPS);
+    if (type==1)
+        ps->PrintFast(13, "/nan {1} def ");
+
+    gVirtualPS = ps;
 
     //
@@ -2170,5 +2420,6 @@
         // has the same Aspect Ratio than on the screen.
         //
-        ps.NewPage();
+        if (i>from)
+            ps->NewPage();
 
         //
@@ -2176,5 +2427,5 @@
         // such that the page title can be set above the canvas...
         //
-        Float_t psw = 28.0; // A4 - width (29.7)
+        Float_t psw = 28.0; // A4 - width  (29.7)
         Float_t psh = 21.0; // A4 - height (21.0)
 
@@ -2187,5 +2438,5 @@
             psh = ch/cw*psw;
 
-        ps.Range(psw, psh); // A4
+        PSToolsRange(*ps, psw, psh);
 
         //
@@ -2219,13 +2470,13 @@
         // Print overlaying text (NDC = %)
         //
-        ps.SetTextColor(kBlack);
-        ps.SetTextSize(0.015);
-        ps.SetTextFont(22);
-        ps.SetTextAlign(11); // left top
-        ps.TextNDC(0, 1.015, TString("  ")+n->GetName());
-        ps.SetTextAlign(21); // cent top
-        ps.TextNDC(0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());
-        ps.SetTextAlign(31); // right top
-        ps.TextNDC(1, 1.015, MString::Form("Page No.%i (%i)  ", page++, i));
+        ps->SetTextColor(kBlack);
+        ps->SetTextSize(0.015);
+        ps->SetTextFont(22);
+        ps->SetTextAlign(11); // left top
+        PSToolsTextNDC(*ps, 0, 1.015, TString("  ")+n->GetName());
+        ps->SetTextAlign(21); // cent top
+        PSToolsTextNDC(*ps, 0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());
+        ps->SetTextAlign(31); // right top
+        PSToolsTextNDC(*ps, 1, 1.015, MString::Form("Page No.%i (%i)  ", page++, i));
         line.PaintLineNDC(0, 1.01, 1, 1.01);
 
@@ -2234,8 +2485,8 @@
         {
             line.PaintLineNDC(0, -0.00, 1, -0.00);
-            ps.SetTextAlign(11); // left top
-            ps.TextNDC(0, -0.015, TString("  ")+txt);
-            ps.SetTextAlign(31); // right top
-            ps.TextNDC(1, -0.015, "(c) 2000-2004, Thomas Bretz  ");
+            ps->SetTextAlign(11); // left top
+            PSToolsTextNDC(*ps, 0, -0.015, TString("  ")+txt);
+            ps->SetTextAlign(31); // right top
+            PSToolsTextNDC(*ps, 1, -0.015, "(c) 2000-2005, Thomas Bretz  ");
         }
 
@@ -2250,13 +2501,17 @@
     l.Delete();
 
-    ps.Close();
-
-    SetStatusLine2("Updating header of PS file...");
-
-    if (num<0)
-        *fLog << " - Updating header of PS file... " << flush;
-    UpdatePSHeader(name);
-    if (num<0)
-        *fLog << inf << "done." << endl;
+    ps->Close();
+    delete ps;
+
+    if (type==1)
+    {
+        SetStatusLine2("Updating header of PS file...");
+
+        if (num<0)
+            *fLog << " - Updating header of PS file... " << flush;
+        UpdatePSHeader(name);
+        if (num<0)
+            *fLog << inf << "done." << endl;
+    }
 
     gVirtualPS = psave;
@@ -2274,4 +2529,5 @@
 Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
 {
+//#if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00)
     if (gROOT->IsBatch())
     {
@@ -2280,5 +2536,6 @@
         return 0;
     }
-    //SetStatusLine1("Writing GIF file...");
+//#endif
+
     SetStatusLine1("Writing image file... <please be patient>");
     SetStatusLine2("");
@@ -2306,6 +2563,9 @@
         ext = AddExtension(name, "jpg", num);
         break;
-//    case TImage::kXcf:
-//        ext = AddExtension(name, "xcf", num);
+    case TImage::kGif:
+        ext = AddExtension(name, "gif", num);
+        break;
+//    case TImage::kTiff:
+//        ext = AddExtension(name, "tiff", num);
 //        break;
 //    case TImage::kPpm:
@@ -2315,7 +2575,4 @@
 //        ext = AddExtension(name, "pnm", num);
 //        break;
-//    case TImage::kBmp:
-//        ext = AddExtension(name, "bmp", num);
-//        break;
 //    case TImage::kIco:
 //        ext = AddExtension(name, "ico", num);
@@ -2324,9 +2581,9 @@
 //        ext = AddExtension(name, "cur", num);
 //        break;
-    case TImage::kGif:
-        ext = AddExtension(name, "gif", num);
-        break;
-//    case TImage::kTiff:
-//        ext = AddExtension(name, "tif", num);
+//    case TImage::kBmp:
+//        ext = AddExtension(name, "bmp", num);
+//        break;
+//    case TImage::kXcf:
+//        ext = AddExtension(name, "xcf", num);
 //        break;
 //    case TImage::kXbm:
@@ -2397,5 +2654,7 @@
         *fLog << "..." << flush;
 
+#if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00)
         c->Draw();
+
         if (type==TImage::kGif)
             c->SaveAs(writename); // FIXME: Seems not to work well in TImage! (root 3.10/02)
@@ -2407,5 +2666,7 @@
             delete img;
         }
-
+#else
+        c->Print(writename);
+#endif
         if (num<0)
             *fLog << "done." << endl;
@@ -2535,4 +2796,25 @@
 // --------------------------------------------------------------------------
 //
+// Determin File type to save file as by extension. Allowed extensions are:
+//   root, ps, pdf, svg, gif, png, jpg, xpm, C
+//
+// returns -1 if file type is unknown. Otherwise return value of SaveAs*
+//
+Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
+{
+    if (name.EndsWith(".root")) return SaveAsRoot(num, name);
+    if (name.EndsWith(".ps"))   return SaveAsPS(num, name);
+    if (name.EndsWith(".pdf"))  return SaveAsPDF(num, name);
+    if (name.EndsWith(".svg"))  return SaveAsSVG(num, name);
+    if (name.EndsWith(".gif"))  return SaveAsGIF(num, name);
+    if (name.EndsWith(".png"))  return SaveAsPNG(num, name);
+    if (name.EndsWith(".jpg"))  return SaveAsJPG(num, name);
+    if (name.EndsWith(".xpm"))  return SaveAsXPM(num, name);
+    if (name.EndsWith(".C"))    return SaveAsC(num, name);
+    return -1;
+}
+
+// --------------------------------------------------------------------------
+//
 //  Opens a save as dialog
 //
@@ -2542,5 +2824,11 @@
     {
         "PostScript",   "*.ps",
+        "Acrobat pdf",  "*.pdf",
+        "SVG vector",   "*.svg",
         "Gif files",    "*.gif",
+        "Png files",    "*.png",
+        "Gif files",    "*.gif",
+        "Jpeg files",   "*.jpeg",
+        "Xpm files",    "*.xpm",
         "Macro files",  "*.C",
         "ROOT files",   "*.root",
@@ -2563,10 +2851,7 @@
     dir = fi.fIniDir;
 
-    const TString name(fi.fFilename);
-
-    if (name.EndsWith(".root")) return SaveAsRoot(num, name);
-    if (name.EndsWith(".ps"))   return SaveAsPS(num, name);
-    if (name.EndsWith(".gif"))  return SaveAsGIF(num, name);
-    if (name.EndsWith(".C"))    return SaveAsC(num, name);
+    const Int_t rc = SaveAs(num, fi.fFilename);
+    if (rc>=0)
+        return rc;
 
     Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
Index: /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 7000)
+++ /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 7001)
@@ -26,4 +26,5 @@
 class TMutex;
 class TCanvas;
+class TVirtualPS;
 
 class TGTab;
@@ -42,13 +43,17 @@
     typedef enum {
         // kFile
-        kFileBrowser, kFileCanvas, kFileOpen, kFileSave, kFileSaveAs, kFileSaveAsPS,
-        kFileSaveAsRoot, kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG,
-        kFileSaveAsXPM, kFileSaveAsC, kFilePrint, kFilePrinterName,
+        kFileBrowser, kFileCanvas, kFileOpen, kFileSave, kFileSaveAs,
+        kFileSaveAsPS, kFileSaveAsPDF, kFileSaveAsSVG, kFileSaveAsRoot,
+        kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG, kFileSaveAsXPM,
+        /*kFileSaveAsBMP, kFileSaveAsXCF, kFileSaveAsTIFF,*/
+        kFileSaveAsC, kFilePrint, kFilePrinterName,
         kFileClose, kFileExit, kFileReset,
         // kLoop
         kLoopNone, kLoopStop,
         // kTab
-        kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsRoot, kTabSaveAsPNG,
-        kTabSaveAsGIF, kTabSaveAsJPG, kTabSaveAsXPM, kTabSaveAsC,
+        kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsPDF, kTabSaveAsSVG,
+        kTabSaveAsRoot, kTabSaveAsPNG, kTabSaveAsGIF, kTabSaveAsJPG,
+        kTabSaveAsXPM, /*kTabSaveAsBMP, kTabSaveAsXCF, kTabSaveAsTIFF,*/
+        kTabSaveAsC,
         kTabPrint, kTabNext, kTabPrevious, kTabRemove,
         // kSize
@@ -57,4 +62,5 @@
         // kLog
         kLogCopy, kLogClear, kLogSelect, kLogFind, kLogSave, kLogAppend,
+        kLogPrint,
         // kPic
         kPicMagic, kPicMars,
@@ -91,6 +97,4 @@
 
     Status_t fStatus;
-
-    TString fPrinter;
 
     Int_t fLogIdx;
@@ -134,5 +138,5 @@
     Bool_t Display(const TObjArray &list, const char *tab=0);
 
-    const TString &AddExtension(TString &name, const TString &ext, Int_t num) const;
+    const TString &AddExtension(TString &name, const TString &ext, Int_t num=-1) const;
 
     void UpdatePSHeader(const TString &name) const;
@@ -144,4 +148,10 @@
 
     Bool_t SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type);
+    Int_t  SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext);
+
+    void PSToolsRange(TVirtualPS &vps, Float_t w, Float_t h) const;
+    void PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const;
+    TString PrintDialog(TString &p, TString &c, TString &t, const char *ext=0);
+
 
 public:
@@ -161,6 +171,4 @@
      void SetStatusLine2(const char *txt) { SetStatusLine(txt, 1); }
      void SetStatusLine2(const MParContainer &cont);
-
-     void SetPrinter(const TString &lpr) { fPrinter = lpr; }
 
      virtual void SetName(const char *name) { fName = name; }
@@ -198,21 +206,35 @@
      void SetNoContextMenu(Bool_t flag=kTRUE);
 
-     Int_t  SaveAsPS(TString name="", const TString addon="") { return SaveAsPS(-1, name, addon); }
-     Bool_t SaveAsPNG(TString name="") { return SaveAsPNG(-1, name); }
-     Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); }
-     Bool_t SaveAsXPM(TString name="") { return SaveAsXPM(-1, name); }
-     Bool_t SaveAsJPG(TString name="") { return SaveAsJPG(-1, name); }
-     Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); }
+     Int_t  SaveAsPS(TString name="",  const TString addon="") { return SaveAsVGF(-1, name, addon, "ps"); }
+     Int_t  SaveAsPDF(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "pdf"); }
+     Int_t  SaveAsSVG(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "svg"); }
+     Bool_t SaveAsPNG(TString name="")  { return SaveAsPNG(-1, name); }
+     Bool_t SaveAsGIF(TString name="")  { return SaveAsGIF(-1, name); }
+     Bool_t SaveAsXPM(TString name="")  { return SaveAsXPM(-1, name); }
+     Bool_t SaveAsJPG(TString name="")  { return SaveAsJPG(-1, name); }
+     //Bool_t SaveAsTIFF(TString name="") { return SaveAsTIFF(-1, name); }
+     //Bool_t SaveAsXCF(TString name="")  { return SaveAsXCF(-1, name); }
+     //Bool_t SaveAsBMP(TString name="")  { return SaveAsBMP(-1, name); }
+     Bool_t SaveAsC(TString name="")    { return SaveAsC(-1, name); }
      Int_t  SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
-     Int_t  PrintToLpr() { return PrintToLpr(-1); }
-
-     Int_t  SaveAsPS(Int_t num, TString name="", const TString addon="");
-     Bool_t SaveAsPNG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kPng); }
-     Bool_t SaveAsGIF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kGif); }
-     Bool_t SaveAsXPM(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXpm); }
-     Bool_t SaveAsJPG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kJpeg); }
+     Int_t  SaveAs(TString name)        { return SaveAs(-1, name); }
+     Int_t  PrintPS() { return PrintPS(-1); }
+
+     Int_t  SaveAsPS(Int_t num, TString name="",  const TString addon="") { return SaveAsVGF(num, name, addon, "ps"); }
+     Int_t  SaveAsPDF(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "pdf"); }
+     Int_t  SaveAsSVG(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "svg"); }
+     Bool_t SaveAsPNG(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kPng); }
+     Bool_t SaveAsGIF(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kGif); }
+     Bool_t SaveAsXPM(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kXpm); }
+     Bool_t SaveAsJPG(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kJpeg); }
+     //Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); }
+     //Bool_t SaveAsXCF(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kXcf); }
+     //Bool_t SaveAsBMP(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kBmp); }
      Bool_t SaveAsC(Int_t num, TString name="");
      Int_t  SaveAsRoot(Int_t num, TString name="");
-     Int_t  PrintToLpr(Int_t num);
+     Int_t  SaveAs(Int_t num, TString name);
+     Int_t  PrintPS(Int_t num, const char *p=0, const char *cmd=0, const char *tmp=0);
+     Bool_t PrintLog(const char *p=0, const char *c=0);
+     Bool_t SaveLogAsPS(const char *name) const;
 
      Int_t  SaveAs(Int_t num=-1);
Index: /trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- /trunk/MagicSoft/Mars/merpp.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/merpp.cc	(revision 7001)
@@ -145,10 +145,11 @@
 int main(const int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -160,6 +161,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     const Int_t  kComprlvl   = arg.GetIntAndRemove("-c", 2);
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 7000)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 7001)
@@ -89,5 +89,5 @@
         // TBranchElement::kDeleteObject = BIT(16)
         // TTree::kFriendLock = BIT(17)
-        kIsNewTree  = BIT(17)
+        kIsNewTree  = BIT(23)
     };
 
Index: /trunk/MagicSoft/Mars/mhflux/FluxLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/FluxLinkDef.h	(revision 7000)
+++ /trunk/MagicSoft/Mars/mhflux/FluxLinkDef.h	(revision 7001)
@@ -8,9 +8,12 @@
 
 #pragma link C++ class MHAlpha+;
-#pragma link C++ class MHTheta+;
+#pragma link C++ class MHThetaSq+;
 #pragma link C++ class MHEnergyEst+;
 #pragma link C++ class MHFalseSource+;
 #pragma link C++ class MHEffectiveOnTime+;
 #pragma link C++ class MHCollectionArea+;
+#pragma link C++ class MMatrixHist+;
+#pragma link C++ class MMatrixUnfold+;
+#pragma link C++ class MUnfoldBert+;
 
 #endif
Index: unk/MagicSoft/Mars/mhflux/MHTheta.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHTheta.cc	(revision 7000)
+++ 	(revision )
@@ -1,103 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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, 5/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2005
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//
-// MHTheta
-//
-// This is a MHAlpha using "ThetaSquared [MParameterD]" as 'alpha'
-//
-// For more detailes see MHAlpha.
-//
-//////////////////////////////////////////////////////////////////////////////
-#include "MHTheta.h"
-
-#include "MParameters.h"
-#include "MHMatrix.h"
-
-#include "MBinning.h"
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHTheta);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor
-//
-MHTheta::MHTheta(const char *name, const char *title)
-    : MHAlpha(name, title), fThetaSq(0)
-{
-    //
-    //   set the name and title of this object
-    //
-    fName  = name  ? name  : "MHTheta";
-    fTitle = title ? title : "Theta Squared plot";
-
-    fNameParameter = "ThetaSquared";
-
-    fHist.SetName("Theta");
-    fHist.SetTitle("Theta");
-    fHist.SetZTitle("\\theta^{2} [deg^{2}]");
-    fHist.SetDirectory(NULL);
-
-    // Main histogram
-    fHistTime.SetName("Theta");
-    fHistTime.SetXTitle("\\theta^{2} [deg^{2}]");
-    fHistTime.SetDirectory(NULL);
-
-    //fHistTime.SetYTitle("\\theta^{2] [deg^{2}]");
-    /*
-    TArrayD arr(50);
-    for (int i=1; i<50; i++)
-        arr[i] = sqrt((arr[i-1]+1)*(arr[i-1]+1) + 1.1)-1;
-    */
-    MBinning binsa, binse, binst;
-    binsa.SetEdges(75, 0, 1.5);
-    //binsa.SetEdges(arr);
-    binse.SetEdgesLog(15, 10, 100000);
-    binst.SetEdgesCos(50, 0, 60);
-    binsa.Apply(fHistTime);
-
-    MH::SetBinning(&fHist, &binst, &binse, &binsa);
-}
-
-Bool_t MHTheta::GetParameter(const MParList &pl)
-{
-    fParameter = (MParContainer*)pl.FindObject(fNameParameter, "MParameterD");
-    if (fParameter)
-        return kTRUE;
-
-    *fLog << err << fNameParameter << " [MParameterD] not found... abort." << endl;
-    return kFALSE;
-}
-
-Double_t MHTheta::GetVal() const
-{
-    return static_cast<const MParameterD*>(fParameter)->GetVal();
-}
Index: unk/MagicSoft/Mars/mhflux/MHTheta.h
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHTheta.h	(revision 7000)
+++ 	(revision )
@@ -1,26 +1,0 @@
-#ifndef MARS_MHTheta
-#define MARS_MHTheta
-
-#ifndef MARS_MHAlpha
-#include "MHAlpha.h"
-#endif
-
-class MHTheta : public MHAlpha
-{
-private:
-    MParameterD  *fThetaSq;     //!
-
-    Bool_t      GetParameter(const MParList &pl);
-    Double_t    GetVal() const;
-    const char *GetParameterRule() const
-    {
-        return "ThetaSquared.fVal";
-    }
-
-public:
-    MHTheta(const char *name=NULL, const char *title=NULL);
-
-    ClassDef(MHTheta, 1) // Theta-Plot which is fitted online
-};
-
-#endif
Index: /trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 7001)
+++ /trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 7001)
@@ -0,0 +1,103 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MHThetaSq
+//
+// This is a MHAlpha using "ThetaSquared [MParameterD]" as 'alpha'
+//
+// For more detailes see MHAlpha.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MHThetaSq.h"
+
+#include "MParameters.h"
+#include "MHMatrix.h"
+
+#include "MBinning.h"
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHThetaSq);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor
+//
+MHThetaSq::MHThetaSq(const char *name, const char *title)
+    : MHAlpha(name, title), fThetaSq(0)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHThetaSq";
+    fTitle = title ? title : "Theta Squared plot";
+
+    fNameParameter = "ThetaSquared";
+
+    fHist.SetName("Theta");
+    fHist.SetTitle("Theta");
+    fHist.SetZTitle("\\theta^{2} [deg^{2}]");
+    fHist.SetDirectory(NULL);
+
+    // Main histogram
+    fHistTime.SetName("Theta");
+    fHistTime.SetXTitle("\\theta^{2} [deg^{2}]");
+    fHistTime.SetDirectory(NULL);
+
+    //fHistTime.SetYTitle("\\theta^{2] [deg^{2}]");
+    /*
+    TArrayD arr(50);
+    for (int i=1; i<50; i++)
+        arr[i] = sqrt((arr[i-1]+1)*(arr[i-1]+1) + 1.1)-1;
+    */
+    MBinning binsa, binse, binst;
+    binsa.SetEdges(75, 0, 1.5);
+    //binsa.SetEdges(arr);
+    binse.SetEdgesLog(15, 10, 100000);
+    binst.SetEdgesCos(50, 0, 60);
+    binsa.Apply(fHistTime);
+
+    MH::SetBinning(&fHist, &binst, &binse, &binsa);
+}
+
+Bool_t MHThetaSq::GetParameter(const MParList &pl)
+{
+    fParameter = (MParContainer*)pl.FindObject(fNameParameter, "MParameterD");
+    if (fParameter)
+        return kTRUE;
+
+    *fLog << err << fNameParameter << " [MParameterD] not found... abort." << endl;
+    return kFALSE;
+}
+
+Double_t MHThetaSq::GetVal() const
+{
+    return static_cast<const MParameterD*>(fParameter)->GetVal();
+}
Index: /trunk/MagicSoft/Mars/mhflux/MHThetaSq.h
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHThetaSq.h	(revision 7001)
+++ /trunk/MagicSoft/Mars/mhflux/MHThetaSq.h	(revision 7001)
@@ -0,0 +1,26 @@
+#ifndef MARS_MHThetaSq
+#define MARS_MHThetaSq
+
+#ifndef MARS_MHAlpha
+#include "MHAlpha.h"
+#endif
+
+class MHThetaSq : public MHAlpha
+{
+private:
+    MParameterD  *fThetaSq;     //!
+
+    Bool_t      GetParameter(const MParList &pl);
+    Double_t    GetVal() const;
+    const char *GetParameterRule() const
+    {
+        return "ThetaSquared.fVal";
+    }
+
+public:
+    MHThetaSq(const char *name=NULL, const char *title=NULL);
+
+    ClassDef(MHThetaSq, 1) // Theta-Plot which is fitted online
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mhflux/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/Makefile	(revision 7000)
+++ /trunk/MagicSoft/Mars/mhflux/Makefile	(revision 7001)
@@ -27,6 +27,7 @@
 	   MHEnergyEst.cc \
 	   MHAlpha.cc \
-           MHTheta.cc \
+           MHThetaSq.cc \
            MHEnergyEst.cc \
+           MUnfolding.cc \
 	   MHEffectiveOnTime.cc \
            MHCollectionArea.cc \
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 7001)
@@ -107,11 +107,17 @@
     TVirtualPad *save = gPad;
     gPad = 0;
+    /*
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     SetPalette(1, 0);
-#else
+#endif
+    */
+/*
+#if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00)
     SetPrettyPalette();
+#elese
     // WORAROUND - FIXME: Calling it many times becomes slower and slower
-    //SetInvDeepBlueSeaPalette();
+    SetInvDeepBlueSeaPalette();
 #endif
+*/
     gPad = save;
 }
@@ -121,5 +127,5 @@
 //  Default Constructor. To be used by the root system ONLY.
 //
-MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend), fAbberation(0)
+MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fAbberation(0)
 {
     Init();
@@ -133,5 +139,5 @@
 //
 MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
-: fGeomCam(NULL), fColors(kItemsLegend), fAbberation(0)
+: fGeomCam(NULL), fAbberation(0)
 {
     //fGeomCam = (MGeomCam*)geom.Clone();
@@ -463,4 +469,7 @@
 //                 GeMinimum() ((val-min)/(max-min))
 //   'proj'        Display the y-projection of the histogram
+//   'pal0'        Use Pretty palette
+//   'pal1'        Use Deep Blue Sea palette
+//   'pal2'        Use Inverse Depp Blue Sea palette
 //   'same'        Draw trandparent pixels on top of an existing pad. This
 //                 makes it possible to draw the camera image on top of an
@@ -970,4 +979,12 @@
     {
         opt.ReplaceAll("hist", "");
+        opt.ReplaceAll("box", "");
+        opt.ReplaceAll("pixelindex", "");
+        opt.ReplaceAll("sectorindex", "");
+        opt.ReplaceAll("content", "");
+        opt.ReplaceAll("proj", "");
+        opt.ReplaceAll("pal0", "");
+        opt.ReplaceAll("pal1", "");
+        opt.ReplaceAll("pal2", "");
         TH1D::Paint(opt);
         return;
@@ -1007,4 +1024,16 @@
     }
 
+    const Bool_t pal1 = opt.Contains("pal1");
+    const Bool_t pal2 = opt.Contains("pal2");
+
+    if (!pal1 && !pal2)
+        SetPrettyPalette();
+
+    if (pal1)
+        SetDeepBlueSeaPalette();
+
+    if (pal2)
+        SetInvDeepBlueSeaPalette();
+
     // Update Contents of the pixels and paint legend
     Update(gPad->GetLogy(), hasbox, hascol, hassame);
@@ -1021,4 +1050,23 @@
 }
 
+void MHCamera::SetDrawOption(Option_t *option)
+{
+    // This is a workaround. For some reason MHCamera is
+    // stored in a TObjLink instead of a TObjOptLink
+    if (!option || !gPad)
+        return;
+
+    TListIter next(gPad->GetListOfPrimitives());
+    delete gPad->FindObject("Tframe");
+    TObject *obj;
+    while ((obj = next()))
+        if (obj == this && (TString)next.GetOption()!=(TString)option)
+        {
+            gPad->GetListOfPrimitives()->Remove(this);
+            gPad->GetListOfPrimitives()->AddFirst(this, option);
+            return;
+        }
+}
+
 // ------------------------------------------------------------------------
 //
@@ -1053,8 +1101,4 @@
     else
         gStyle->SetPalette(ncolors, colors);
-
-    fColors.Set(kItemsLegend);
-    for (int i=0; i<kItemsLegend; i++)
-        fColors[i] = gStyle->GetColorPalette(i);
 }
 
@@ -1068,6 +1112,13 @@
 void MHCamera::SetPrettyPalette()
 {
-    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+    TString opt(GetDrawOption());
+
+    if (!opt.Contains("hist", TString::kIgnoreCase))
         SetPalette(1, 0);
+
+    opt.ReplaceAll("pal1", "");
+    opt.ReplaceAll("pal2", "");
+
+    SetDrawOption(opt);
 }
 
@@ -1080,6 +1131,14 @@
 void MHCamera::SetDeepBlueSeaPalette()
 {
-    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+    TString opt(GetDrawOption());
+
+    if (!opt.Contains("hist", TString::kIgnoreCase))
         SetPalette(51, 0);
+
+    opt.ReplaceAll("pal1", "");
+    opt.ReplaceAll("pal2", "");
+    opt += "pal1";
+
+    SetDrawOption(opt);
 }
 
@@ -1092,6 +1151,14 @@
 void MHCamera::SetInvDeepBlueSeaPalette()
 {
-    if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
+    TString opt(GetDrawOption());
+
+    if (!opt.Contains("hist", TString::kIgnoreCase))
         SetPalette(52, 0);
+
+    opt.ReplaceAll("pal1", "");
+    opt.ReplaceAll("pal2", "");
+    opt += "pal2";
+
+    SetDrawOption(opt);
 }
 
@@ -1515,8 +1582,8 @@
 
     if (val >= max)
-        return fColors[maxcolidx];
+        return gStyle->GetColorPalette(maxcolidx);
 
     if (val <= min)
-        return fColors[0];
+        return gStyle->GetColorPalette(0);
 
     //
@@ -1530,5 +1597,5 @@
 
     const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
-    return fColors[colidx];
+    return gStyle->GetColorPalette(colidx);
 }
 
@@ -1612,5 +1679,5 @@
     for (Int_t i=0; i<kItemsLegend; i++)
     {
-        newbox.SetFillColor(fColors[i]);
+        newbox.SetFillColor(gStyle->GetColorPalette(i));
         newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
     }
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 7000)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 7001)
@@ -48,5 +48,4 @@
     TArrayI        fBinEntries;  // number of entries per bin
 
-    TArrayI        fColors;      //! Color conversion table
     TList         *fNotify;      //!
 
@@ -214,4 +213,5 @@
     char    *GetObjectInfo(Int_t px, Int_t py) const;
     void     ExecuteEvent(Int_t event, Int_t px, Int_t py);
+    void     SetDrawOption(Option_t *option); //*MENU*
 
     void     SetPalette(Int_t ncolors, Int_t *colors);
@@ -222,6 +222,4 @@
 
     void     SetAutoScale() { fMinimum = fMaximum = -1111; } // *MENU*
-    void     DisplayAsHistogram() { SetDrawOption("histEP"); } // *MENU*
-    void     DisplayAsCamera() { SetDrawOption(""); } // *MENU*
 
     void     SetFreezed(Bool_t f=kTRUE) { f ? SetBit(kFreezed) : ResetBit(kFreezed); } // *TOGGLE* *GETTER=IsFreezed
Index: unk/MagicSoft/Mars/mhist/MHGamma.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHGamma.cc	(revision 7000)
+++ 	(revision )
@@ -1,286 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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 time saving 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): Wolfgang Wittek 6/2002 <mailto:wittek@mppmu.mpg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MHGamma                                                                 //
-//                                                                          //
-//  manipulation of alpha distributions                                     //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "MHGamma.h"
-
-#include <TCanvas.h>
-#include <TPad.h>
-
-#include <math.h>
-
-#include <TH2.h>
-#include <TH3.h>
-
-#include "MHAlphaEnergyTheta.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHGamma);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. 
-//
-MHGamma::MHGamma(const TString &name, const TString &title)
-    : fHist(NULL), fProject(NULL)
-{
-    fName  = name.IsNull()  ? (TString)"MHGamma" : name;
-    fTitle = title.IsNull() ? (TString)"3D-histogram of Alpha, E_est, Theta (Gamma sample)" : title;
-}
-
-TH3D *MHGamma::Subtract(const MHAlphaEnergyTheta &h1, const MHAlphaEnergyTheta &h2)
-{
-    return Subtract(h1.GetHist(), h2.GetHist());
-}
-
-TObject *MHGamma::DrawClone(Option_t *opt) const
-{
-    DrawClone1();
-    DrawClone2();
-
-    return NULL;
-}
-
-void MHGamma::DrawClone1() const
-{
-    if (!fHist)
-        return;
-
-    //
-    // ------------- Part 1 ---------------------
-    //
-    TString titlex = fHist->GetXaxis()->GetTitle();
-    TString titley = fHist->GetYaxis()->GetTitle();
-    TString titlez = fHist->GetYaxis()->GetTitle();
-
-    TString canvtitle = "3D-plot "; //of ";
-    /*
-     canvtitle += titlex;
-     canvtitle += ", ";
-     canvtitle += titley;
-     canvtitle += ", ";
-     canvtitle += titlez+" ";
-     */
-    canvtitle += "for 'gamma' sample";
-
-    TCanvas &c = *MakeDefCanvas("Alpha", canvtitle);
-
-    c.Divide(2, 2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    TH1 *h;
-
-    c.cd(1);
-    h = ((TH3D*)(fHist))->Project3D(fName+"_ex");
-
-    TString title= "Source-Antisource: ";
-    h->SetTitle(title + titlex);
-    h->SetXTitle(titlex);
-    h->SetYTitle("Counts");
-
-    h->Draw();
-    h->SetBit(kCanDelete);
-
-    c.cd(2);
-    h = ((TH3D*)(fHist))->Project3D(fName+"_ey");
-
-    h->SetTitle(title + titley);
-    h->SetXTitle(titley);
-    h->SetYTitle("Counts");
-
-    h->Draw();
-    h->SetBit(kCanDelete);
-    gPad->SetLogx();
-
-    c.cd(3);
-    h = ((TH3D*)(fHist))->Project3D(fName+"_ez");
-
-    h->SetTitle(title + titlez);
-    h->SetXTitle(titlez);
-    h->SetYTitle("Counts");
-
-    h->Draw();
-    h->SetBit(kCanDelete);
-
-    c.cd(4);
-    ((TH3D*)fHist)->DrawCopy();
-
-    c.Modified();
-    c.Update();
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Calculate the histogram as the difference of two histograms :
-//          fHist(gamma) = h1(source) - h2(antisource)
-// 
-TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2)
-{
-    if (fHist)
-        delete fHist;
-
-    fHist = new TH3D;
-    fHist->SetName(fName);
-    fHist->SetTitle(fTitle);
-    fHist->SetDirectory(NULL);
-
-    SetBinning((TH1*)fHist, (TH1*)h1);
-
-    fHist->SetXTitle((((TH1*)h1)->GetXaxis())->GetTitle());
-    fHist->SetYTitle((((TH1*)h1)->GetYaxis())->GetTitle());
-    fHist->SetZTitle((((TH1*)h1)->GetZaxis())->GetTitle());
-
-    fHist->Add((TH1*)h1, (TH1*)h2, 1, -1); // ROOT: FIXME!
-
-    return fHist;
-}
-
-// --------------------------------------------------------------------------
-//
-// Integrate fHist(gamma) in the alpha range (lo, up)
-// 
-TH2D *MHGamma::GetAlphaProjection(Axis_t lo, Axis_t up)
-{
-    if (up < lo)
-    {
-        *fLog << err << fName << "MHGamma : Alpha projection not possible: lo=" << lo << " up=" << up << endl;
-        return NULL;
-    }
-
-    TAxis &axe = *fHist->GetXaxis();
-
-    Int_t ilo = axe.FindFixBin(lo);
-    Int_t iup = axe.FindFixBin(up);
-
-    const Double_t epslo1 = lo-axe.GetBinLowEdge(ilo);
-    const Double_t epslo2 = axe.GetBinUpEdge(ilo)-lo;
-
-    const Double_t epsup1 = up-axe.GetBinLowEdge(iup);
-    const Double_t epsup2 = axe.GetBinUpEdge(iup)-up;
-
-    const Double_t epslo = epslo1<epslo2 ? epslo1 : epslo2;
-    const Double_t epsup = epsup1<epsup2 ? epsup1 : epsup2;
-
-    if (epslo1>epslo2)
-        ilo++;
-
-    if (epsup1<epsup2)
-        iup--;
-
-    if (epslo>0.01*axe.GetBinWidth(ilo) || epsup>0.01*axe.GetBinWidth(iup))
-    {
-        *fLog << err << fName << "MHGamma : binning is not adequate for the requested projection:" << endl;
-        *fLog << "Please specify a lower or upper limit which is not more than 1% away from a bin edge" << endl;
-        *fLog << " epslo = " << epslo << endl;
-        *fLog << " epsup = " << epsup << endl;
-        *fLog << " dwl   = " << axe.GetBinWidth(ilo) << endl;
-        *fLog << " dwu   = " << axe.GetBinWidth(iup) << endl;
-        return NULL;
-    }
-
-    axe.SetRange(ilo, iup);
-
-    fLo = lo;
-    fHi = up;
-
-    if (fProject)
-        delete fProject;
-    fProject = (TH2D*)fHist->Project3D(fName+"_ezy");
-
-    const TString title = "2D-plot of ";
-    const TString titley = fHist->GetYaxis()->GetTitle();
-    const TString titlez = fHist->GetZaxis()->GetTitle();
-
-    fProject->SetTitle(title + titley + " vs. " + titlez);
-    fProject->SetXTitle(titley);
-    fProject->SetYTitle(titlez);
-
-    return fProject;
-}
-
-void MHGamma::DrawClone2() const
-{
-    if (!fProject)
-        return;
-
-    const TString titley = fHist->GetYaxis()->GetTitle();
-    const TString titlez = fHist->GetZaxis()->GetTitle();
-
-    TString canvtitle = "No.of Gammas ";//vs. ";
-    /*
-     canvtitle += titley;
-     canvtitle += " and ";
-     canvtitle += titlez;
-     */
-    canvtitle += Form("(%.1f < alpha < %.1f deg)", fLo, fHi);
-
-    TCanvas &c = *MakeDefCanvas("Gamma", canvtitle);
-
-    c.Divide(2, 2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    TH1 *h;
-
-    c.cd(1);
-    h = fProject->ProjectionX(fName+"_xpro", -1, 9999, "E");
-    TString title = "No.of gammas: ";
-    h->SetTitle(title+titley);
-    h->SetXTitle(titley);
-    h->SetYTitle("Counts");
-
-    h->Draw();
-    h->SetBit(kCanDelete);
-    gPad->SetLogx();
-
-    c.cd(2);
-    h = fProject->ProjectionY(fName+"_ypro", -1, 9999, "E");
-    h->SetTitle(title+titlez);
-    h->SetXTitle(titlez);
-    h->SetYTitle("Counts");
-
-    h->Draw();
-    h->SetBit(kCanDelete);
-
-    c.cd(3);
-
-    fProject->DrawCopy();
-    gPad->SetLogx();
-
-    c.Modified();
-    c.Update();
-}
Index: unk/MagicSoft/Mars/mhist/MHGamma.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHGamma.h	(revision 7000)
+++ 	(revision )
@@ -1,46 +1,0 @@
-#ifndef MARS_MHGamma
-#define MARS_MHGamma
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-class TH2D;
-class TH3D;
-
-class MHAlphaEnergyTheta;
-
-class MHGamma : public MH 
-{
-private:
-    TH3D *fHist;    //!
-    TH2D *fProject; //!
-
-    Axis_t fLo; //!
-    Axis_t fHi; //!
-
-public:
-    MHGamma(const TString &name="", const TString &title="");
-
-    TH3D *Subtract(const TH3D *h1, const TH3D *h2);
-
-    TH3D *Subtract(const MHAlphaEnergyTheta &h1, const MHAlphaEnergyTheta &h2);
-
-    TH2D *GetAlphaProjection(Axis_t lo, Axis_t up);
-
-    TObject *DrawClone(Option_t *opt="") const;
-    void DrawClone1() const;
-    void DrawClone2() const;
-
-    const TH2D *GetProject() const { return fProject; }
-
-    ClassDef(MHGamma, 0) // manipulation of alpha distributions
-};
-
-#endif
-
-
-
-
-
-
Index: unk/MagicSoft/Mars/mhist/MHOnSubtraction.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHOnSubtraction.cc	(revision 7000)
+++ 	(revision )
@@ -1,1767 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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 expressed
-! * or implied warranty.
-! *
-!
-!
-!   Author(s): Robert Wagner 9/2002 <mailto:rw@rwagner.de>
-!   Author(s): Robert Wagner 3/2003 <mailto:rw@rwagner.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MHOnSubtraction                                                         //
-//                                                                          //
-//                                                                          //
-//  extracts the gamma signal from a pure ON-signal given in an             //
-//  ALPHA-Energy-Theta histogram. The class will take this histogram from   //
-//  the parameter list and will provide result histograms in the            //
-//  parameter list.                                                         //
-//                                                                          //
-//  This class still is work in progress.                                   //
-//                                                                          //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-
-// This part of MARS is code still evolving. Please do not change the code 
-// without prior feedback by the author.
-
-#include "MHOnSubtraction.h"
-
-#include <TPaveText.h>
-#include <TPaveLabel.h>
-#include <TF1.h>
-#include <TLegend.h>
-#include <TCanvas.h>
-#include <TStyle.h>
-#include <TGraph.h>
-
-#include "MBinning.h"
-#include "MParList.h"
-#include "MHArray.h"
-#include "MH3.h"
-
-#include "MHAlphaEnergyTheta.h"
-#include "MHAlphaEnergyTime.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MHOnSubtraction);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor.
-//
-MHOnSubtraction::MHOnSubtraction(const char *name, const char *title) : fMaxSignif(0),	fMaxRedChiSq(0), fSlope(20.0)
-{ 
-  fName  = name  ? name  : "MHOnSubtraction";
-  fTitle = title ? title : "Extracts Gamma signal from pure ON data";
-  fHistogramType = "Theta";
-  fChiSquareHisto=0;
-  fSignificanceHisto=0;
-  fSummedAlphaPlots=0;
-  fThetaBin=0;
-  
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Destructor.
-//
-MHOnSubtraction::~MHOnSubtraction()
-{ 
-  if (fChiSquareHisto) delete fChiSquareHisto;
-  if (fSignificanceHisto) delete fSignificanceHisto;
-  if (fSummedAlphaPlots) delete fSummedAlphaPlots;
-}
-
-// -----------------------------------------------------------------------
-//
-// Calculate Significance according to Li and Ma, ApJ 272 (1983) 317, eq
-// (17). n_{On}, n_{Off} and the ratio of On-times for On and Off 
-// measurements have to be provided.
-//
-// This function underestimates the true significance for it does not take
-// into account errors on the event numbers. A more accurate variation wil
-// be provided soon
-//
-Double_t MHOnSubtraction::CalcSignificance(Double_t nOn, Double_t nOff, Double_t theta)
-{ 
-  if (nOn<=0)
-    *fLog << warn << "Got " << nOn << " total events, " << flush;
-  if (nOff<=0)
-    *fLog << warn << "Got " << nOff << " background events, " << flush;
-  if (nOn<=0 || nOff<=0.0) {
-    *fLog << warn << "returning significance of 0.0" << endl;
-    return 0.0;
-  }
-  return sqrt(2*(nOn*log((1+theta)*nOn/(theta*(nOn+nOff)))
-		 +nOff*log((1+theta)*(nOff/(nOn+nOff)))));
-}
-
-// -----------------------------------------------------------------------
-//
-// This function takes a first look at a given ALPHA distribution
-// and determines if a fit is applicable.
-//
-// Fits a given TH1 containing an ALPHA distribution with a combined
-// gaussian plus polynomial of third grade and returns the fitted 
-// function. By signalRegionFactor the width of the region in which
-// signal extraction is to be performed can be specified in units of
-// sigma of the gaussian which is fitted to the distribution (default: 
-// 3.5). Accordingly, FitHistogram returns the range in which it suggests 
-// signal extraction (lowerBin < ALPHA < upperBin). An estimated 
-// significance of the signal is also provided. draw specifies whether
-// FitHistogram should draw the distribution.
-//
-Bool_t MHOnSubtraction::FitHistogram(TH1 &alphaHisto, Double_t &sigLiMa,
-			       Double_t &lowerBin, Double_t &upperBin,
-			       Float_t signalRegionFactor, const Bool_t draw,
-			       TString funcName)
-{
-  if (alphaHisto.GetEntries() == 0) {
-    *fLog << warn << "Histogram contains no entries. Returning. " << endl;
-    lowerBin=0;
-    upperBin=0;
-    sigLiMa=0;    
-    if (draw) {
-      TPaveLabel* lab = new TPaveLabel(0.1,0.2,0.9,0.8,"(no events)");
-      lab->SetFillStyle(0);
-      lab->SetBorderSize(0);
-      lab->Draw();  
-    }
-    return kFALSE;
-  }
-  
-  //cosmetics
-  alphaHisto.GetXaxis()->SetTitle("ALPHA");
-  alphaHisto.GetYaxis()->SetTitle("events");
-
-  Double_t outerEvents = 0.0;
-  Double_t innerEvents = 0.0;
-  Int_t outerBins = 0;
-  Int_t innerBins = 0;
-  Int_t outerBinsZero = 0;
-  Int_t innerBinsZero = 0;
-
-  for (Int_t alphaBin = 1; alphaBin < alphaHisto.GetNbinsX(); alphaBin++) {
-    if ((alphaHisto.GetBinLowEdge(alphaBin) >= -35.)&& //inner Region
-  	(alphaHisto.GetBinLowEdge(alphaBin+1) <= 35.0)) {
-      innerEvents+=alphaHisto.GetBinContent(alphaBin);
-      innerBins++;
-      if (alphaHisto.GetBinContent(alphaBin)==0.0)
-  	innerBinsZero++;     
-    } else {
-      if ((alphaHisto.GetBinLowEdge(alphaBin) >= -89.5)&& //outer Region
-	  (alphaHisto.GetBinLowEdge(alphaBin+1) <=89.5)) {
-	outerEvents+=alphaHisto.GetBinContent(alphaBin);
-	outerBins++;
-	if (alphaHisto.GetBinContent(alphaBin)==0.0)
-	  outerBinsZero++;     
-      }
-    }
-  }
-
-   *fLog << dbg << "Plot contains " << 
-     outerEvents << " outer ev (" << outerEvents/outerBins << "/bin), " <<
-     innerEvents << " inner ev (" << innerEvents/innerBins << "/bin) " << endl;
-
-  if ((outerBinsZero!=0) || (innerBinsZero != 0))
-    *fLog << warn << "There are ";
-  if (outerBinsZero != 0)
-    *fLog << dbg << outerBinsZero << " empty outer bins ";
-  if (innerBinsZero != 0)
-    *fLog << dbg <<innerBinsZero << " empty inner bins ";
-  if ((outerBinsZero!=0) || (innerBinsZero != 0))
-    *fLog << endl;
-
-  if (outerEvents == 0.0) {
-     *fLog << warn << "No events in OFF region. Assuming background = 0" 
-	   << endl;
-     TF1 *po = new TF1("pol0"+funcName,"pol0(0)",-89.5,89.5);
-     po->SetLineWidth(2);
-     po->SetLineColor(2);
-     po->SetParNames("c");
-     po->SetParameter(0,0.0);
-     alphaHisto.GetListOfFunctions()->Add(po);
-     alphaHisto.SetLineColor(97);
-     if (draw) {
-       alphaHisto.DrawCopy(); //rwagner
-       po->Draw("SAME");
-     }
-     sigLiMa = 0;
-     lowerBin = 1;
-     upperBin = alphaHisto.GetNbinsX()-1;
-     signalRegionFactor = 0;
-    
-     return kFALSE; //No gaus fit applied
-  }
-
-  if (outerEvents/outerBins < 2.5) {
-    *fLog << warn << "Only " << /*setprecision(2) <<*/ outerEvents/outerBins 
-	  << " events/bin in OFF region: "
-	  << "Assuming this as background." << endl;
-   
-     TF1 *po = new TF1("pol0"+funcName,"pol0(0)",-89.5,89.5);
-     po->SetLineWidth(2);
-     po->SetLineColor(94);
-     po->SetParNames("c");
-     po->SetParameter(0,outerEvents/outerBins);
-     alphaHisto.GetListOfFunctions()->Add(po);    
-     if (draw) {
-       alphaHisto.DrawCopy(); //rwagner
-       po->Draw("SAME");
-     }
-    
-     Int_t centerBin = alphaHisto.GetXaxis()->FindBin((Double_t)0.0);
-     Int_t maxBin    = centerBin > alphaHisto.GetNbinsX() - centerBin ? 
-       alphaHisto.GetNbinsX()- centerBin : centerBin;
-     
-     Int_t lowerSignalEdge = centerBin;
-     for (Int_t i=3; i < maxBin; i++) {
-       if ((Double_t)alphaHisto.GetBinContent(centerBin-i) 
-	   < outerEvents/outerBins) {
-	 lowerSignalEdge = centerBin-i+1;
-	 break;
-       }
-     }
-     if (centerBin<lowerSignalEdge) lowerSignalEdge=centerBin;
-
-     Int_t upperSignalEdge = centerBin;
-     for (Int_t i=3; i < maxBin; i++) {
-       if ((Double_t)alphaHisto.GetBinContent(centerBin+i) 
-	   <= outerEvents/outerBins) {
-	 upperSignalEdge=centerBin+i-1;
-	 break;
-       } 
-     }
-     if (centerBin>upperSignalEdge) upperSignalEdge=centerBin;
-
-     Double_t nOnInt = 0;
-     for (Int_t i=1; i < alphaHisto.GetNbinsX(); i++)
-       nOnInt += alphaHisto.GetBinContent(i) - outerEvents/outerBins;
-     
-     Double_t nOffInt = (upperSignalEdge - lowerSignalEdge + 1) 
-       * (outerEvents/outerBins);
-     
-     sigLiMa = CalcSignificance(nOnInt, nOffInt, 1);
-
-     if (sigLiMa < 3) 
-       alphaHisto.SetLineColor(2);   
-
-   
-     *fLog << inf << "Estimated significance is " << sigLiMa 
-	   << " sigma " << endl;   
-     *fLog << inf << "Signal region is " 
-	   << lowerBin << " < ALPHA < " << upperBin 
-	   << " (Most likely you wanna ignore this)" << endl;
-
-     return kFALSE; //No gaus fit applied    
-  }
-  
-  //fit combined gaus+pol3 to data
-  TF1 *gp = new TF1("gauspol3"+funcName,"gaus(0)+pol3(3)",-89.5,89.5);
-  gp->SetLineWidth(2);
-  gp->SetLineColor(2);
-  gp->SetParNames("Excess","A","sigma","a","b","c","d");
-  gp->SetParLimits(0, 200,2000); 
-  gp->SetParLimits(1, -4.,4.); 
-  gp->SetParLimits(2, 2.,20.);
-  // gp->SetParameter(6,  0.0000); // include for slope(0)=0 constrain
-  TString gpDrawOptions = draw ? "RIQ" : "RIQ0";
-  gpDrawOptions = "RIQ0"; // rwagner
-  alphaHisto.Fit("gauspol3"+funcName,gpDrawOptions);
-  alphaHisto.DrawCopy(); //rwagner
-  alphaHisto.SetDirectory(NULL); //rwagner
-  
-  Double_t gausMean  = gp->GetParameter(1);
-  Double_t gausSigma = gp->GetParameter(2);
-
-//   TF1 *p3 = new TF1("p3"+funcName,"pol3(0)",-signalRegionFactor*gausSigma+gausMean,
-// 		    signalRegionFactor*gausSigma+gausMean);
-  TF1 *p3 = new TF1("p3"+funcName,"pol3(0)",-100,
-		    100);
-  p3->SetParameters(gp->GetParameter(3),gp->GetParameter(4),
-		    gp->GetParameter(5),gp->GetParameter(6));
-  // p3->SetLineStyle(2);
-  p3->SetLineColor(4);
-  p3->SetLineWidth(1);
-  if (draw) p3->Draw("SAME");   
-   
-  TF1 *ga = new TF1("ga"+funcName,"gaus(0)",-40,40);
-  ga->SetParameters(gp->GetParameter(0),gp->GetParameter(1),gp->GetParameter(2));
-  ga->SetLineColor(93);
-  ga->SetLineWidth(2);
-  //  if (draw) ga->Draw("SAME");
-
-  // identify the signal region: signalRegionFactor*gausSigma
-  // this allows us to
-  // (1) determine n_{ON}, n_{OFF}
-  Double_t scalingFactor = 
-    (alphaHisto.GetXaxis()->GetBinLowEdge(alphaHisto.GetNbinsX()+1)
-     - alphaHisto.GetXaxis()->GetBinLowEdge(1)) / alphaHisto.GetNbinsX();
-  
-  Double_t nOnInt  = (gp->Integral(-signalRegionFactor*gausSigma+gausMean, 
-				 signalRegionFactor*gausSigma+gausMean) / scalingFactor);
-  Double_t nOffInt = (p3->Integral(-signalRegionFactor*gausSigma+gausMean, 
-				 signalRegionFactor*gausSigma+gausMean) / scalingFactor);
-
-  // (2) determine the signal region from fit in degrees
-  // we do it a bit more complicated: assuming that the binning in all 
-  // histograms is the same, we want to be sure that summing up is always
-  // done over the same bins.
-
-  lowerBin = alphaHisto.GetXaxis()->FindBin(-signalRegionFactor*gausSigma+gausMean);
-  upperBin = alphaHisto.GetXaxis()->FindBin( signalRegionFactor*gausSigma+gausMean);
-
-  lowerBin = alphaHisto.GetBinLowEdge((Int_t)lowerBin);
-  upperBin = alphaHisto.GetBinLowEdge((Int_t)upperBin)+alphaHisto.GetBinWidth((Int_t)upperBin);
-  
-  sigLiMa = CalcSignificance(nOnInt, nOffInt, 1);
-//   if (sigLiMa < 3)
-//     alphaHisto.SetLineColor(2);   
-
-
-  *fLog << inf << "Fit estimates significance to be " 
-	<< sigLiMa << " sigma " << endl; 
-
-  *fLog << inf << "Fit yields signal region to be " 
-	<< lowerBin << " < ALPHA < " << upperBin
-	<< " (Chisquare/dof=" << gp->GetChisquare()/gp->GetNDF() 
-	<< ", prob="  <<  gp->GetProb() << ")" << endl;
-
-  return kTRUE; //returning gaus fit
-}
-
-
-
-
-
-// -----------------------------------------------------------------------
-//
-// Does the actual extraction of the gamma signal. For performance 
-// reasons, fits already done by MHOnSubtraction::FitHistogram are used 
-// and not redone.
-// From it, a polynomial function for the background is evaluated and the
-// gamma signal is extracted in the region given by lowerBin < ALPHA < 
-// upperBin.
-// Significance of the signal is also provided. draw specifies whether
-// FitHistogram should draw the distribution.
-//
-Bool_t MHOnSubtraction::ExtractSignal(TH1 &alphaHisto, Double_t &sigLiMa,
-   Double_t &lowerBin, Double_t &upperBin,
-   Double_t &gammaSignal, Double_t &errorGammaSignal,
-   Double_t &off, Double_t &errorOff,
-   Float_t signalRegionFactor, const Bool_t draw, TString funcName,
-   TPad *drawPad, Int_t drawBase)
-{
-  TF1 *gausPol = alphaHisto.GetFunction("gauspol3"+funcName);
-  TF1 *pol = alphaHisto.GetFunction("pol0"+funcName);
-  
-  if (!gausPol && !pol) {
-    *fLog << err << "Fatal: ALPHA histogram has no gauspol or pol "  
-	  << " fit attached to it." << endl;
-    TPaveLabel* lab = new TPaveLabel(0.1,0.2,0.9,0.8,"(no fit)");
-    lab->SetFillStyle(3000);
-    lab->SetBorderSize(0);
-    lab->DrawClone();  
-    lab->SetBit(kCanDelete);
-    return kFALSE;
-  } 
-
-  TF1* po;
-  po = NULL;
-
-  if (gausPol) {
-    Double_t gausMean  = gausPol->GetParameter(1);
-    Double_t gausSigma = gausPol->GetParameter(2);
-    po = new TF1("po"+funcName,"pol3(0)",
-		  -signalRegionFactor*gausSigma+gausMean,
-		  signalRegionFactor*gausSigma+gausMean);
-    po->SetParameters(gausPol->GetParameter(3),gausPol->GetParameter(4),
-		      gausPol->GetParameter(5),gausPol->GetParameter(6));
-
-    TF1 *ga = new TF1("ga"+funcName,"gaus(0)",-40,40);
-    ga->SetParameters(gausPol->GetParameter(0),gausPol->GetParameter(1),
-		      gausPol->GetParameter(2));
-    
-    if (draw) {
-      alphaHisto.Draw();
-      gausPol->Draw("SAME"); //Maybe not even necessary?
-      
-      po->SetLineColor(4);
-      po->SetLineWidth(2);
-      po->Draw("SAME");   
-      
-      ga->SetLineColor(93);
-      ga->SetLineWidth(2);    
-      ga->Draw("SAME");   
-      
-      char legendTitle[80];
-      sprintf(legendTitle, "Signal region: %2.1f < #alpha < %2.1f", 
-	      lowerBin, upperBin);
-      
-      TLegend *legend = new TLegend(0.13, 0.52, 0.47, 0.72, legendTitle);
-      
-      legend->SetBorderSize(0);
-      legend->SetFillColor(10);
-      legend->SetFillStyle(0);
-      legend->AddEntry(gausPol, "combined N_{on}","l");
-      legend->AddEntry(po,"polynomial N_{bg} Signal region","l");
-      legend->AddEntry(ga, "putative gaussian N_{S}","l");
-      legend->Draw();
-    }
-  } // gausPol
-
-
-  if (pol) {
-    po = pol;
-    
-    if (draw) {
-      alphaHisto.Draw();
-      
-      po->SetLineColor(6);
-      po->SetLineWidth(2);
-      po->Draw("SAME");   
-            
-      char legendTitle[80];
-      sprintf(legendTitle, "Signal region: %2.1f < #alpha < %2.1f", 
-	      lowerBin, upperBin);
-      
-      TLegend *legend = new TLegend(0.13, 0.52, 0.47, 0.72, legendTitle);
-      
-      legend->SetBorderSize(0);
-      legend->SetFillColor(10);
-      legend->SetFillStyle(0);
-      legend->AddEntry(po,"polynomial N_{bg} Signal region","l");
-      legend->Draw();
-    }
-  } // pol
-    
-  Double_t nOn = 0;
-  Double_t eNOn = 0;
-
-  Int_t binNumberLow = alphaHisto.GetXaxis()->FindBin(lowerBin);
-  Int_t binNumberHigh = alphaHisto.GetXaxis()->FindBin(upperBin);
-  
-  for (Int_t bin=binNumberLow; bin<binNumberHigh+1; bin++) {
-    nOn += alphaHisto.GetBinContent(bin);
-    eNOn += alphaHisto.GetBinError(bin) * alphaHisto.GetBinError(bin);
-  } //for bin
-  eNOn = sqrt(eNOn);
-     
-  // Evaluate background
-  
-  Double_t nOff = 0;
-  Double_t eNOff = 0;
-  for (Int_t bin=binNumberLow; bin<binNumberHigh+1; bin++) {
-    Double_t x = .5*(alphaHisto.GetBinLowEdge(bin)+alphaHisto.GetBinLowEdge(bin+1));
-    Double_t offEvts = po->Eval(x);
-    //cout << bin << ": " << offEvts << endl;
-    nOff += offEvts;
-  } //for bin
-  eNOff = sqrt(fabs(nOff));
-  
-  if (nOn==0)   // there should not be a negative number of signal events
-    nOff=0;
-  
-  if (nOff<0) { // there should not be a negative number of off events
-    nOff=0;
-    eNOff=0;
-  }
-    
-  *fLog << inf << "nEvts = " << nOn << "+-" << eNOn << ", ";
-
-  off = nOff;              errorOff = eNOff;
-  gammaSignal = nOn-nOff;  errorGammaSignal = sqrt(eNOn*eNOn + eNOff*eNOff); 
-
-  *fLog << inf << "nBack = " << nOff << "+-" << eNOff << ", ";
-  *fLog << inf << "nSig = " << gammaSignal << "+-" << errorGammaSignal << endl;
-
-  sigLiMa = CalcSignificance(nOn, nOff, 1);  
-  //  Double_t sigFit=(ga->GetParameter(1))/(ga->GetParError(1)); //Mean / sigMean
-  
-  *fLog << inf << "Significance: "<<sigLiMa<<" sigma "<<endl;
-
-  if (draw) { 
-    TPaveText *pt = new TPaveText(0.11,.74,.57,.88,"NDC ");
-    char tx[60];
-    sprintf(tx, "Excess: %2.2f #pm %2.2f", nOn-nOff, sqrt(eNOn*eNOn + eNOff*eNOff));
-    pt->AddText(tx);
-    sprintf(tx, "Off:    %2.2f #pm %2.2f", nOff, eNOff);
-    pt->AddText(tx);
-    sprintf(tx, "Significance: %2.2f   #sigma", sigLiMa);
-    pt->AddText(tx);
-    pt->SetFillStyle(0);
-    pt->SetBorderSize(0);
-    pt->SetTextAlign(12);
-    pt->Draw("");
-  }  
-  if (draw||drawPad) {
-
-    // Plot significance vs alpha_cut
-    
-    Int_t centerBin = alphaHisto.GetXaxis()->FindBin((Double_t)0.0);
-    Int_t maxBin    = centerBin > alphaHisto.GetNbinsX()- centerBin ? 
-      alphaHisto.GetNbinsX()- centerBin : centerBin;
-         
-    const Int_t totalBins = centerBin;
-    Float_t alpha[totalBins];
-    Float_t signi[totalBins];
-    Float_t maxSigni = 0;
-    
-    for (Int_t i=0; i < maxBin; i++) {
-      Double_t nOn = 0;  Double_t eNOn = 0;
-      Double_t nOff = 0; Double_t eNOff = 0;
-      for (Int_t bin=centerBin-i; bin<centerBin+i+1; bin++) {
-	nOn += alphaHisto.GetBinContent(bin);
-	eNOn += alphaHisto.GetBinError(bin) * alphaHisto.GetBinError(bin);
-	Double_t x = .5*(alphaHisto.GetBinLowEdge(bin)+alphaHisto.GetBinLowEdge(bin+1));
-	Double_t offEvts = po->Eval(x);
-	nOff += offEvts;
-      } //for bin
-      eNOn = sqrt(eNOn);
-      eNOff = sqrt(nOff);  
-      alpha[i] = 
-	(alphaHisto.GetXaxis()->GetBinLowEdge(centerBin+i+1)-
-	 alphaHisto.GetXaxis()->GetBinLowEdge(centerBin-i))/2;
-      signi[i] = CalcSignificance(nOn, nOff, 1);  
-      maxSigni = maxSigni > signi[i] ? maxSigni : signi[i];
-    }
-
-    if (!drawPad) {
-      TCanvas *c3 = new TCanvas("c3"+funcName, "Significance vs ALPHA cut", 800,600);
-      c3->cd();
-    }
-
-    if (drawPad) 
-      drawPad->cd(drawBase-1);
-    
-    TGraph* gr = new TGraph(totalBins-2,alpha,signi);
-    TString drawOpt = "L";
-    
-    if (draw || (drawPad && fSigniPlotIndex == 0))
-      drawOpt += "A";
-    
-    gr->Draw(drawOpt);
-    if (drawPad && fSigniPlotIndex == 0) {
-      gr->GetXaxis()->SetTitle("|#alpha_{max}|");
-      gr->GetYaxis()->SetTitle("Significance");
-    }
-    gr->SetMarkerStyle(2);
-    gr->SetMarkerSize(1);
-    gr->SetMarkerColor(4+fSigniPlotIndex);
-    gr->SetLineColor(4+fSigniPlotIndex);
-    gr->SetLineWidth(1);
-    gr->SetTitle("Significance vs ALPHA integration range");
-    gr->Draw("L");
-
-    fSigniPlotIndex++;      
-    
-  } //draw
-
-  return kTRUE;
-}
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a MHAlphaEnergyTheta or 
-// MHAlphaEnergyTime object expected in the ParList.
-//
-Bool_t MHOnSubtraction::Calc(MParList *parlist, const Bool_t Draw)
-{
-  //Find source histograms
-  fHistogramType = "Theta";
-  MHAlphaEnergyTheta* mhisttheta = (MHAlphaEnergyTheta*)parlist->FindObject("MHAlphaEnergyTheta"); 
-  if (mhisttheta) return Calc((TH3D*)mhisttheta->GetHist(), parlist, Draw);
-
-  fHistogramType = "Time";
-  MHAlphaEnergyTime* mhisttime = (MHAlphaEnergyTime*)parlist->FindObject("MHAlphaEnergyTime");  
-  if (mhisttime) return Calc((TH3D*)mhisttime->GetHist(), parlist, Draw);
-
-  *fLog << err << "No MHAlphaEnergyTheta type object found in the parameter list. Aborting." << endl;
-  return kFALSE; 
-}
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a TH3D histogram in
-// ALPHA, Energy and Theta.
-//
-Bool_t MHOnSubtraction::CalcAET(TH3D *aetHisto, MParList *parlist, const Bool_t Draw)
-{
-  // Analyze aetHisto
-  // -------------------------------------
-  Int_t alphaBins =  aetHisto->GetNbinsX();  // # of alpha bins 
-  Int_t energyBins = aetHisto->GetNbinsY();  
-  Int_t thetaBins =  aetHisto->GetNbinsZ();  
-  
-  // We output an array of histograms to the parlist.
-  // Create a template for such a histogram, needed by MHArray
-  // -------------------------------------
-  MBinning *binsfft = new MBinning("BinningMH3X");
-  binsfft->SetEdgesLog(energyBins,aetHisto->GetYaxis()->GetBinLowEdge(1),
-		aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1));
-  parlist->AddToList(binsfft);  
-  MH3 *energyHistogram = new MH3(1); // The template histogram in energy
-                                     // for a given theta value
-  energyHistogram->SetName("MHOnSubtractionEnergyHistogramTemplate");
-  parlist->AddToList(energyHistogram);
-
-  fThetaHistoArray = new MHArray("MHOnSubtractionEnergyHistogramTemplate", kTRUE, 
-				 "MHOnSubtractionGammaSignalArray", 
-				 "Array of histograms in energy bins");
-  fThetaHistoArray->SetupFill(parlist);
-  parlist->AddToList(fThetaHistoArray);
-  
-  // Canvases---direct debug output for the time being
-  // -------------------------------------
-  TCanvas *c3 = new TCanvas("c3", "Plots by MHOnSubtraction::ExtractSignal", 800,600);
-  cout << thetaBins << " x " << energyBins << endl;
-  c3->Divide(thetaBins,energyBins);
-
-  TCanvas *c4a = new TCanvas("c4a", "Energy distributions for different ZA", 800,600);
-  
-  TH1D* histalphaon[energyBins*thetaBins]; // ALPHA histograms
-
-  fChiSquareHisto = new TH1D("fChiSquareHisto", "#chi^{2}/d.o.f. of fits", 50, 0, 5);
-  fSignificanceHisto = new TH1D("fSignificanceHisto", "Significances", 41, -0.5, 40.5);
-  fSummedAlphaPlots = new TH1D("fSummedAlphaPlots", "Cumulative Alpha", 
-			       alphaBins,aetHisto->GetXaxis()->GetBinLowEdge(1),
-			       aetHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));
-  
-  // -------------------------------------
-
-  fThetaLegend = new TLegend(0.83, 0.07, 0.98, 0.42, "Energy Distributions");  
-  fThetaLegend->SetBorderSize(1);
-  
-  Double_t overallSigLiMa = 0;
-
-  for (Int_t thetaBin = 1; thetaBin < thetaBins+1; thetaBin++) {
-    
-    char hname[80];  
-    sprintf(hname, "Energy distribution for %s bin %d", fHistogramType.Data(), 
-	    thetaBin);
-    *fLog << all << "Calculating " << hname << endl;
-
-    Double_t minLowerBin = -10; // minimum integration range
-    Double_t maxUpperBin =  10; // minimum integration range
-    Double_t maxAlpha =  70; // maximum integration range
-
-    Double_t sumSigLiMa = 0;
-    
-    // This loop just fixes the integration range
-    // And alerts when no significant excess is found.
-
-    for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) {
-
-      sprintf(hname, "histalphaon%d", (thetaBin-1)*(energyBins)+energyBin);
-      histalphaon[(thetaBin-1)*(energyBins)+energyBin] = 
-	new TH1D(hname, "ALPHA histogram",
-		 alphaBins,aetHisto->GetXaxis()->GetBinLowEdge(1),
-		 aetHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));
-      histalphaon[(thetaBin-1)*(energyBins)+energyBin]->Sumw2();    
-      histalphaon[(thetaBin-1)*(energyBins)+energyBin]->SetTitle(hname);
-     
-      sprintf(hname,"ALPHA distribution for E bin %d, theta bin %d",
-	      energyBin, thetaBin);
-      *fLog << inf << hname << endl;
-
-      // now we fill one histogram for one particular set
-      // of Energy and Theta...
-      
-      if (aetHisto->InheritsFrom("TH3D")||aetHisto->InheritsFrom("TH2D")) {
-	aetHisto->GetYaxis()->SetRange(energyBin,energyBin); // E
-	if (aetHisto->InheritsFrom("TH3D"))
-	  aetHisto->GetZaxis()->SetRange(thetaBin,thetaBin); // theta
-	histalphaon[(thetaBin-1)*(energyBins)+energyBin] = (TH1D*)aetHisto->Project3D("xe");
-      } else {
-	histalphaon[(thetaBin-1)*(energyBins)+energyBin] = (TH1D*)aetHisto;
-      }
-
-      *fLog << inf << "This histogram has " 
-	    << histalphaon[(thetaBin-1)*(energyBins)+energyBin]->GetEntries()
-	    << " entries" << endl;
-
-      sprintf(hname, "histalphaon%d", (thetaBin-1)*(energyBins)+energyBin);
-      histalphaon[(thetaBin-1)*(energyBins)+energyBin]->SetName(hname);
-      
-      // Test: Find signal region and significance in histogram
-      Double_t lowerBin, upperBin, sSigLiMa;
-      FitHistogram(*histalphaon[(thetaBin-1)*(energyBins)+energyBin],
-		   sSigLiMa, lowerBin, upperBin, (Float_t)3.5, kFALSE);
-
-      Double_t redChiSq = histalphaon[(thetaBin-1)*(energyBins)+energyBin]->GetFunction("gauspol3")->GetChisquare()/histalphaon[(thetaBin-1)*(energyBins)+energyBin]->GetFunction("gauspol3")->GetNDF();
-
-      fChiSquareHisto->Fill(redChiSq);
-      fMaxRedChiSq = redChiSq > fMaxRedChiSq ? redChiSq : fMaxRedChiSq;
-
-      // histalphaon[(thetaBin-1)*(energyBins)+energyBin]->GetFunction("gauspol3")->GetProb() <<endl;
-
-      fSummedAlphaPlots->Add(histalphaon[(thetaBin-1)*(energyBins)+energyBin], 1);
-      
-      if (sSigLiMa < 3)
-	*fLog << inf << "No significant excess for this bin (sigma="<< sSigLiMa <<")!"<<endl;
-      sumSigLiMa+=sSigLiMa;
-   
-      // Evaluate integration range
-
-      lowerBin = (lowerBin < -maxAlpha) ? -maxAlpha : lowerBin;
-      minLowerBin = (lowerBin < minLowerBin) ? lowerBin : minLowerBin;
-
-      upperBin = (upperBin > maxAlpha) ? maxAlpha : upperBin;
-      maxUpperBin = (upperBin > maxUpperBin) ? upperBin : maxUpperBin;
-
-    } //energyBin
-    
-    *fLog << inf << "Integration range for this " << fHistogramType 
-	  << " value will be " << minLowerBin << " < ALPHA < "
-	  << maxUpperBin << endl;
-    
-    *fLog << inf << "Summed estd. significance for this " << fHistogramType 
-	  << " value is " << sumSigLiMa << endl;
-
-    // Create Histogram in Energy for this Theta value
-    cout << "STARTIGN REAL CALC1 "<< endl;
-    fThetaHistoArray->AddHistogram();
-    cout << "STARTIGN REAL CALC1a "<< endl;
-    fThetaHistoArray->SetIndex(thetaBin-1);
-    
-    MH3 &mThetaHisto = *(MH3*)(fThetaHistoArray->GetH());
-    mThetaHisto.Print();
-   
-    TH1D &thetaHisto = (TH1D&)(mThetaHisto.GetHist());
-    sprintf(hname,"Energy distribution for theta bin %d", thetaBin);
-    thetaHisto.SetTitle(hname);
-    thetaHisto.SetEntries(0);
-      
-    // we have a rough idea of what is going on in the ALPHA plot...
-    // So now we can indeed extract the signal.
-         
-//     cout << "STARTIGN REAL CALC "<< endl;
-
-    sumSigLiMa = 0;
-    for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) {
-
-      sprintf(hname,"ALPHA distribution for E bin %d, theta bin %d",
-	      energyBin, thetaBin);
-      *fLog << inf << hname << endl;
-  
-      Double_t gammaSignal, errorGammaSignal, off, errorOff, sigLiMa;
-
-      c3->cd((thetaBin-1)*(energyBins)+energyBin);
-  
-      ExtractSignal(*histalphaon[(thetaBin-1)*(energyBins)+energyBin],
-		    sigLiMa, minLowerBin, maxUpperBin, 
-		    gammaSignal, errorGammaSignal, 
-		    off, errorOff, (Float_t)3, kTRUE);
-      
-      fSignificanceHisto->Fill(sigLiMa);
-      fMaxSignif = sigLiMa > fMaxSignif ? sigLiMa : fMaxSignif;
-
-      thetaHisto.SetBinContent(energyBin, gammaSignal*TMath::Exp(7-energyBin));
-      thetaHisto.SetBinError(energyBin, errorGammaSignal);
-      thetaHisto.SetEntries(thetaHisto.GetEntries()+gammaSignal);
-     
-      sumSigLiMa += sigLiMa;
-      
-    }//energyBin
-
-    *fLog << inf << "Summed significance for this " << fHistogramType 
-	  << " value is " << sumSigLiMa << endl;
-
-    //fit exponential function to data
-    TF1* e = new TF1("expF","expo",0,5);
-    e->SetLineWidth(3);
-    e->SetLineColor(thetaBin);
-    // e->SetParLimits(1, -0.5,3); //limits on slope
-    
-     if (fSlope!=20.0) {
-       e->SetParameter(1, fSlope);
-       *fLog << inf << "Fixing slope to " << e->GetParameter(1) << endl;
-     }
-
-    TString eDrawOptions = Draw ? "RIQ" : "RIQ0";
-    cout << "doing the fit" << endl;
-    thetaHisto.Fit("expF");
-    
-    Double_t expoSlope = e->GetParameter(1);
-    
-    *fLog << inf << "Determined slope for energy distribution is " 
-	  << expoSlope << endl;
-
-    Double_t integralEvts =
-      e->Integral(aetHisto->GetYaxis()->GetBinLowEdge(1), 
-		  aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1));
-    
-    *fLog << inf << "Integral in E range [" <<
-      aetHisto->GetYaxis()->GetBinLowEdge(1) << ";" <<
-      aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1) << "] is " << 
-      integralEvts << endl;
-      
-    // Plot Energy histogram
-  
-    c4a->cd(0);
-    thetaHisto.SetLineColor(thetaBin);
-    if (thetaBin==1) {      
-      thetaHisto.Draw();
-    } else {
-      thetaHisto.Draw("SAME");
-    }
-
-    sprintf(hname,"Theta bin %d",thetaBin);
-    fThetaLegend->AddEntry(&thetaHisto, hname, "l");
-
-    overallSigLiMa += sumSigLiMa;
-
-  } //thetaBin
-
-  fThetaLegend->Draw();
-
-  Double_t sigLiMa, lowerBin, upperBin;    
-  FitHistogram(*fSummedAlphaPlots, sigLiMa, lowerBin, upperBin);
-  fSummedAlphaPlots->SetTitle("Cumulative ALPHA distribution");
-
-  *fLog << inf << "Summed overall significance is " << overallSigLiMa << endl;
-
-  *fLog << inf << "Setting range for Significance histo " << fMaxSignif << endl;
-  // fSignificanceHisto->GetXaxis()->SetRange(0,fMaxSignif+1);
-
-  // *fLog << inf << "Setting range for chisq histo " << fMaxRedChiSq << endl;
-  // fChiSquareHisto->GetXaxis()->SetRange(0,fMaxRedChiSq+5);
-  
-  return kTRUE;
-}
-
-
-
-
-
-
-
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a TH3D histogram in
-// ALPHA, Energy and Theta. Output to parameter list: TH2 histograms
-// in energy and Theta.
-//
-Bool_t MHOnSubtraction::Calc(TH3 *aetHisto, MParList *parlist, const Bool_t Draw)
-{
-  // Analyze aetHisto
-  // -------------------------------------
-  Int_t energyBins = aetHisto->GetNbinsY();  
-  Int_t thetaBins =  aetHisto->GetNbinsZ();  
-
-  *fLog << "Total events:     " << aetHisto->GetEntries() << endl;
-  *fLog << "Total energy bins: " << energyBins << endl;
-  *fLog << "Total theta bins:  " << thetaBins << endl;
-  
-  // We output results in an array of histograms to the parameter list.
-  // Create a template for such a histogram, needed by MH3
-  // -------------------------------------
-  MBinning *binsmh3x = new MBinning("BinningMH3X");
-  // dummy binning, real one follows some lines down
-  binsmh3x->SetEdgesLog(energyBins,aetHisto->GetYaxis()->GetBinLowEdge(1),
-			aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1));
-  parlist->AddToList(binsmh3x);  
-
-  MBinning *binsmh3y = new MBinning("BinningMH3Y");
-  // dummy binning, real one follows some lines down
-  binsmh3y->SetEdges(thetaBins,aetHisto->GetZaxis()->GetBinLowEdge(1),
-		     aetHisto->GetZaxis()->GetBinLowEdge(thetaBins+1));
-  parlist->AddToList(binsmh3y);  
-  
-  MH3 *signalHisto = new MH3(2); // Signal(E,t)
-  signalHisto->SetupFill(parlist);
-  parlist->AddToList(signalHisto);
-  signalHisto->SetName("MHOnSubtractionSignal");
-  signalHisto->SetTitle("Gamma Events");
-
-  MH3 *offHisto = new MH3(2); // Off(E,t)
-  offHisto->SetupFill(parlist);
-  parlist->AddToList(offHisto);
-  offHisto->SetName("MHOnSubtractionOff");
-  offHisto->SetTitle("Background Events");
-
-  MH3 *signifHisto = new MH3(2); // Significance(E,t)
-  signifHisto->SetupFill(parlist);
-  parlist->AddToList(signifHisto);
-  signifHisto->SetName("MHOnSubtractionSignif");
-  signifHisto->SetTitle("Significance");
-
-//   if (!fChiSquareHisto) 
-//     fChiSquareHisto = new TH1D("fChiSquareHisto", "#chi^{2}/d.o.f. of fits", 50, 0, 5);
-//   if (!fSignificanceHisto) 
-//     fSignificanceHisto = new TH1D("fSignificanceHisto", "Significances", 40.5, -0.5, 41);
-//   if (!fSummedAlphaPlots)
-//     fSummedAlphaPlots = new TH1D("fSummedAlphaPlots", "Cumulative Alpha", 
-// 				 alphaBins,aetHisto->GetXaxis()->GetBinLowEdge(1),
-// 				 aetHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));
-  
-  TCanvas *c4 = new TCanvas("c4", "MHOnSubtraction Detailed Result Plots", 800,600);
-  c4->Divide(energyBins+3,thetaBins,0,0,0);
-  
-  TH2D& signalTH2DHist = (TH2D&)signalHisto->GetHist();
-  TH2D& offTH2DHist =    (TH2D&)offHisto->GetHist();
-  TH2D& signifTH2DHist = (TH2D&)signifHisto->GetHist();
-  
-  signalTH2DHist.Reset();
-  signalTH2DHist.SetTitle("Gamma Signal");
-  signalTH2DHist.SetXTitle("E [GeV]");
-  signalTH2DHist.SetYTitle("theta [deg]");
-  signalHisto->SetBinning(&signalTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis());
-  signalTH2DHist.Sumw2();
-  
-  offTH2DHist.Reset();
-  offTH2DHist.SetTitle("Off Signal");
-  offTH2DHist.SetXTitle("E [GeV]");
-  offTH2DHist.SetYTitle("theta [deg]");
-  offHisto->SetBinning(&offTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis());
-  offTH2DHist.Sumw2();  
-
-  signifTH2DHist.Reset();
-  signifTH2DHist.SetTitle("Significance");
-  signifTH2DHist.SetXTitle("E [GeV]");
-  signifTH2DHist.SetYTitle("theta [deg]");
-  signifHisto->SetBinning(&signifTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis());
-  signifTH2DHist.Sumw2();
- 
-  for (Int_t thetaBin = 1; thetaBin < thetaBins+1; thetaBin++) {  
-
-    *fLog << dbg << "--------------------------------------" << endl;
-    *fLog << dbg << "Processing ALPHA plots for theta bin " << thetaBin << endl;           
-    *fLog << dbg << "--------------------------------------" << endl;
-    aetHisto->GetZaxis()->SetRange(thetaBin, thetaBin);
-    TH2F* aeHisto = (TH2F*)aetHisto->Project3D("yxe");
-    aeHisto->SetDirectory(NULL);
-    char hname[80];
-    sprintf(hname, "%2.1f < #theta < %2.1f", 
-	    aetHisto->GetZaxis()->GetBinLowEdge(thetaBin),
-	    aetHisto->GetZaxis()->GetBinLowEdge(thetaBin+1));
-    *fLog << inf << "There are " << aeHisto->GetEntries() 
- 	  << " entries in " << hname << endl;
-    aeHisto->SetTitle(hname);
-    sprintf(hname, "MHOnSubtractionThetaBin%d", thetaBin);
-    aeHisto->SetName(hname);
-
-    c4->cd((energyBins+3)*(thetaBin-1)+1);
-    aeHisto->SetMarkerColor(3);
-    aeHisto->DrawCopy();
-
-    c4->Update();
-
-    // We hand over a nonstandard parameter list, which
-    // contails lower-dimensional result histograms 
-    // signalHisto, offHisto and signifHisto
-
-//     cout << fLog->GetDebugLevel() << endl;
-    fLog->SetDebugLevel(1);
-
-    MParList *parlistth2 = new MParList();
-    //    parlistth2->SetNullOutput();
-    parlistth2->AddToList(binsmh3x);  
-
-    MH3* signalHisto2 = new MH3(1); // Signal(E)
-    signalHisto2->SetupFill(parlistth2);
-    parlistth2->AddToList(signalHisto2);
-    signalHisto2->SetName("MHOnSubtractionSignal");
-    signalHisto2->SetTitle("Gamma Events");
-
-    MH3* offHisto2 = new MH3(1); // Off(E)
-    offHisto2->SetupFill(parlistth2);
-    parlistth2->AddToList(offHisto2);
-    offHisto2->SetName("MHOnSubtractionOff");
-    offHisto2->SetTitle("Background Events");
-
-    MH3* signifHisto2 = new MH3(1); // Significance(E)
-    signifHisto2->SetupFill(parlistth2);
-    parlistth2->AddToList(signifHisto2);
-    signifHisto2->SetName("MHOnSubtractionSignif");
-    signifHisto2->SetTitle("Significance");
-
-    fLog->SetDebugLevel(-1);
-
-    TH1D& signalTH1DHist = (TH1D&)signalHisto2->GetHist();
-    TH1D& offTH1DHist =    (TH1D&)offHisto2->GetHist();
-    TH1D& signifTH1DHist = (TH1D&)signifHisto2->GetHist();
-
-    signalTH1DHist.Sumw2();
-    offTH1DHist.Sumw2();
-    signifTH1DHist.Sumw2();
-
-    TH2Calc(aeHisto, parlistth2, kFALSE, c4,   
-	    (energyBins+3)*(thetaBin-1)+4);
-
-
-    for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) {  
-    
-   //    cout << "filling " << thetaBin << " " << energyBin << ": " 
-// 		      << signalTH1DHist.GetBinContent(energyBin) << "+-" 
-// 	   << signalTH1DHist.GetBinError(energyBin)  <<  " " 
-// 		      << offTH1DHist.GetBinContent(energyBin) << "+-" 
-// 		      << offTH1DHist.GetBinError(energyBin) << endl;
-        
-      if (signalTH1DHist.GetBinContent(energyBin)>=0.0) {
-	signalTH2DHist.SetBinContent(energyBin, thetaBin,
-				     signalTH1DHist.GetBinContent(energyBin));
-	signalTH2DHist.SetBinError(energyBin, thetaBin,
-				   signalTH1DHist.GetBinError(energyBin));
-      }
-      
-      if (offTH1DHist.GetBinContent(energyBin)>=0.0) {
-	offTH2DHist.SetBinContent(energyBin, thetaBin, 
-				  offTH1DHist.GetBinContent(energyBin));
-	offTH2DHist.SetBinError(energyBin, thetaBin,
-				offTH1DHist.GetBinError(energyBin));
-      }
-      
-      signifTH2DHist.SetBinContent(energyBin, thetaBin,
- 				   signifTH1DHist.GetBinContent(energyBin));
-      signifTH2DHist.SetBinError(energyBin, thetaBin,
- 				 signifTH1DHist.GetBinError(energyBin));           
-    } //energyBin
-
-  
-    c4->cd((energyBins+3)*(thetaBin-1)+2);
-    sprintf(hname,"c4_%d",(energyBins+3)*(thetaBin-1)+2);     
-    TPad* tp = (TPad*)(gROOT->FindObject(hname));
-    tp->SetLogx();     
-    signalTH1DHist.SetLineColor(2);
-    signalTH1DHist.DrawCopy();     
-    offTH1DHist.SetLineColor(4);
-    offTH1DHist.DrawCopy("SAME");          
-    c4->Update();
-           
-    signalTH2DHist.SetEntries(signalTH2DHist.GetEntries()+signalTH1DHist.GetEntries());
-    offTH2DHist.SetEntries(offTH2DHist.GetEntries()+offTH1DHist.GetEntries());
-    signifTH2DHist.SetEntries(signifTH2DHist.GetEntries()+signifTH1DHist.GetEntries());
-    
-    delete signifHisto2;
-    delete offHisto2;
-    delete signalHisto2;
-    delete parlistth2;
-  
-  }
-
-
-  c4->Update();
-
-  return kTRUE;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/*
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a TH3D histogram in
-// ALPHA, Energy and Theta. Output to parameter list: TH2 histograms
-// in energy and Theta.
-//
-Bool_t MHOnSubtraction::CalcLightCurve(TH3 *aetHisto, MParList *parlist, const Bool_t draw)
-{
-  // Analyze aetHisto
-  // -------------------------------------
-  Int_t alphaBins = aetHisto->GetNbinsX(); 
-  Int_t energyBins = aetHisto->GetNbinsY();  
-  Int_t timeBins =  aetHisto->GetNbinsZ();  
-
-  *fLog << "Total events:      " << aetHisto->GetEntries() << endl;
-  *fLog << "Total energy bins: " << energyBins << endl;
-  *fLog << "Total time bins:   " << timeBins << endl;
-
-  // We output results in an array of histograms to the parameter list.
-  // Create a template for such a histogram, needed by MH3
-  // -------------------------------------
-  MBinning *binsmh3x = new MBinning("BinningMH3X");
-  // dummy binning, real one follows some lines down
-  binsmh3x->SetEdges(timeBins,aetHisto->GetZaxis()->GetBinLowEdge(1),
-		     aetHisto->GetZaxis()->GetBinLowEdge(timeBins+1));
-  parlist->AddToList(binsmh3x); 
-  
-  MH3 *signalHisto = new MH3(1); // Signal(t)
-  signalHisto->SetupFill(parlist);
-  parlist->AddToList(signalHisto);
-  signalHisto->SetName("MHOnSubtractionSignal");
-  signalHisto->SetTitle("Gamma Events");
-
-  MH3 *offHisto = new MH3(1); // Off(t)
-  offHisto->SetupFill(parlist);
-  parlist->AddToList(offHisto);
-  offHisto->SetName("MHOnSubtractionOff");
-  offHisto->SetTitle("Background Events");
-
-  MH3 *signifHisto = new MH3(1); // Significance(t)
-  signifHisto->SetupFill(parlist);
-  parlist->AddToList(signifHisto);
-  signifHisto->SetName("MHOnSubtractionSignif");
-  signifHisto->SetTitle("Significance");
-
-  TH1D& signalTH1DHist = (TH1D&)signalHisto->GetHist();
-  TH1D& offTH1DHist =    (TH1D&)offHisto->GetHist();
-  TH1D& signifTH1DHist = (TH1D&)signifHisto->GetHist();
-  
-  signalTH1DHist.Reset();
-  signalTH1DHist.SetTitle("Gamma Signal");
-  signalTH1DHist.SetXTitle("Time [MJD]");
-  signalTH1DHist.SetYTitle("Events");
-  signalHisto->SetBinning(&signalTH1DHist, aetHisto->GetZaxis());
-  signalTH1DHist.Sumw2();
-  
-  offTH1DHist.Reset();
-  offTH1DHist.SetTitle("Background Signal");
-  offTH1DHist.SetXTitle("Time [MJD]");
-  offTH1DHist.SetYTitle("Events");
-  offHisto->SetBinning(&offTH1DHist,  aetHisto->GetZaxis());
-  offTH1DHist.Sumw2();  
-
-  signifTH1DHist.Reset();
-  signifTH1DHist.SetTitle("Significance");
-  signifTH1DHist.SetXTitle("Time [MJD]");
-  signifTH1DHist.SetYTitle("Significance #sigma");
-  signifHisto->SetBinning(&signifTH1DHist, aetHisto->GetZaxis());
-  signifTH1DHist.Sumw2();
- 
-  //The following histogram is an additional histogram needed for
-  //the light curve
-
-  TCanvas *c4 = new TCanvas("c4", "MHOnSubtraction Detailed Result Plots", 800,600);
-  c4->Divide(8,7,0,0,0);
-
- 
-
-  // The following loop fixes a common integration region for each
-  // energy bin and alerts when no significant excess is found.
-  
-  Double_t minLowerBin = -10; // minimum integration range
-  Double_t maxUpperBin =  10; // minimum integration range
-  Double_t maxAlpha =  70; // maximum integration range
-  Double_t sumSigLiMa = 0;
-
-  TH1F* alphaHisto[timeBins];
-
-  for (Int_t timeBin = 1; timeBin < timeBins+1; timeBin++) {  
-
-    *fLog << dbg << "--------------------------------------" << endl;
-    *fLog << dbg << "Processing ALPHA plots for time bin " << timeBin << endl;           
-    *fLog << dbg << "--------------------------------------" << endl;
-   
-    aetHisto->GetZaxis()->SetRange(timeBin, timeBin);
-
-    char hname[80];
-    sprintf(hname, "MHOnSubtractionTimeBin%d", timeBin);    
-    alphaHisto[timeBin-1] =
-      new TH1F(hname, "ALPHA histogram",
-	       alphaBins,aetHisto->GetXaxis()->GetBinLowEdge(1),
-	       aetHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));
-    alphaHisto[timeBin-1]->SetDirectory(NULL);
-    alphaHisto[timeBin-1]->Sumw2();
-    alphaHisto[timeBin-1] = (TH1F*)aetHisto->Project3D("xe");
-    alphaHisto[timeBin-1]->SetName(hname);
-    alphaHisto[timeBin-1]->SetDirectory(NULL);
-
-    sprintf(hname, "%6.0f < t < %6.0f", 
-	    aetHisto->GetZaxis()->GetBinLowEdge(timeBin),
-	    aetHisto->GetZaxis()->GetBinLowEdge(timeBin+1));
-    *fLog << inf << "There are " << alphaHisto[timeBin-1]->GetEntries() 
- 	  << " entries in " << hname << endl;
-    alphaHisto[timeBin-1]->SetTitle(hname);
-      
-    // Find signal region and significance in histogram
-    Double_t lowerBin, upperBin, sSigLiMa;
-    char funcName[20];
-    sprintf(funcName, "%2d", timeBin);
-
-    Bool_t drawFit = kTRUE;
-
-    c4->cd(timeBin);
-//     alphaHisto[timeBin-1]->SetMarkerColor(3);
-    alphaHisto[timeBin-1]->DrawCopy();
-
-    c4->Update();
-
-    fSigniPlotColor = 0;
- ;
-    Bool_t fit = FitHistogram(*alphaHisto[timeBin-1], sSigLiMa, 
-			      lowerBin, upperBin, (Float_t)3.0, drawFit, 
-			      funcName);
-
-    if (fit) { 
-      if (sSigLiMa < 3)
-	*fLog << warn << "No significant excess for this bin (sigma="<< sSigLiMa <<")!"<<endl;
-      sumSigLiMa+=sSigLiMa;
-   
-      // Evaluate integration range
-      lowerBin = (lowerBin < -maxAlpha) ? -maxAlpha : lowerBin;
-      minLowerBin = (lowerBin < minLowerBin) ? lowerBin : minLowerBin;    
-      upperBin = (upperBin > maxAlpha) ? maxAlpha : upperBin;
-      maxUpperBin = (upperBin > maxUpperBin) ? upperBin : maxUpperBin;
-    }
-
-
-    
-
-
-
-  } //timeBin
-  
-  *fLog << inf << "=> Integration range will be " << minLowerBin << " < ALPHA < "
-	<< maxUpperBin << "," << endl;    
-  *fLog << inf << "   Summed estimated significance is " << sumSigLiMa << endl;
-      
-  // we have an idea of what is going on in the ALPHA plot...
-  // So now we can indeed extract the signal.
-         
-  sumSigLiMa = 0;
-  for (Int_t timeBin = 1; timeBin < timeBins+1; timeBin++) {
-    *fLog << inf << "Processing ALPHA distribution for time bin " << timeBin << endl;
-    if (alphaHisto[timeBin-1]->GetEntries() == 0) {
-       *fLog << warn << "No attempt to extract a signal from 0 events." << endl;       
-       if (draw) {
-	 TPaveLabel* lab = new TPaveLabel(0.2,0.4,0.8,0.6,"-(nothing to extract)-");
-	 lab->SetBorderSize(0);
-	 lab->Draw();  
-       }
-    } else {
-      char funcName[20];
-      sprintf(funcName, "%2d", timeBin);
-      
-      Double_t gammaSignal, errorGammaSignal, off, errorOff, sigLiMa;    
-
-      Bool_t drawFit = kFALSE;     
-
-      ExtractSignal(*alphaHisto[timeBin-1],
-		    sigLiMa, minLowerBin, maxUpperBin, 
-		    gammaSignal, errorGammaSignal, off, errorOff, (Float_t)3, drawFit,
-		    funcName, NULL, 1);
-
-      sumSigLiMa += sigLiMa;      
-
-      fMaxSignif = sigLiMa > fMaxSignif ? sigLiMa : fMaxSignif;
-
-      // Fill Signal 
-      TH1D &h = (TH1D&)(signalHisto->GetHist());
-      h.SetBinContent(timeBin, gammaSignal);
-      h.SetBinError(timeBin, errorGammaSignal);
-      h.SetEntries(h.GetEntries()+gammaSignal);
-      
-      // Fill Off Events
-      TH1D &ho = (TH1D&)(offHisto->GetHist());
-      ho.SetBinContent(timeBin, off);
-      ho.SetBinError(timeBin, errorOff);
-      ho.SetEntries(ho.GetEntries()+off);
-      
-      // Fill Significance
-      TH1D &hg = (TH1D&)(signifHisto->GetHist());
-      hg.SetBinContent(timeBin, sigLiMa);
-      hg.SetEntries(hg.GetEntries()+sigLiMa);           
-    }
-    
-  }//timeBin
-
-  *fLog << inf << "Summed significance is " << sumSigLiMa << endl;
-
-
-  if (draw) {
-    Double_t sigLiMa, lowerBin, upperBin;    
-    FitHistogram(*fSummedAlphaPlots, sigLiMa, lowerBin, upperBin);
-    fSummedAlphaPlots->SetTitle("Cumulative ALPHA distribution");
-
-    *fLog << inf << "Setting range for Significance histo " << fMaxSignif << endl;
-    // fSignificanceHisto->GetXaxis()->SetRange(0,fMaxSignif+1);
-    
-    // *fLog << inf << "Setting range for chisq histo " << fMaxRedChiSq << endl;
-    // fChiSquareHisto->GetXaxis()->SetRange(0,fMaxRedChiSq+5);
-    
-    fChiSquareHisto->DrawClone();
-    fSignificanceHisto->DrawClone();
-    fSummedAlphaPlots->DrawClone();
-  }
-  
-  return kTRUE;
-}
-
-
-
-
-
-*/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a TH2 histogram in
-// ALPHA and Energy. Output to parameter list is TH1 histogram in
-// energy
-//
-Bool_t MHOnSubtraction::TH2Calc(TH2 *aeHisto, MParList *parlist, const Bool_t draw, TPad *drawPad, Int_t drawBase)
-{
-
-  fSigniPlotColor = 0;
-
-  // Analyze aeHisto
-  // -------------------------------------
-  const Int_t alphaBins =  aeHisto->GetNbinsX();  // # of alpha bins 
-  const Int_t energyBins = aeHisto->GetNbinsY();  
-
-  // Check availability of result histograms
-  // -------------------------------------
-
-  MH3* signalHisto = (MH3*)parlist->FindObject("MHOnSubtractionSignal","MH3");
-  MH3* offHisto =    (MH3*)parlist->FindObject("MHOnSubtractionOff","MH3");
-  MH3* signifHisto = (MH3*)parlist->FindObject("MHOnSubtractionSignif","MH3");
-
-  if (signalHisto && offHisto && signifHisto) {  
-//     *fLog << dbg << "Result histograms are present in parameter list " <<
-//       "and will be used further." << endl;
-  } else {
-
-    *fLog << warn << "Result histograms are not present in parameter " <<
-      "list and thus are going to be created now." << endl;
-
-    MBinning *binsmh3x = new MBinning("BinningMH3X");
-    binsmh3x->SetEdgesLog(energyBins,aeHisto->GetYaxis()->GetBinLowEdge(1),
-		       aeHisto->GetYaxis()->GetBinLowEdge(energyBins+1));
-    parlist->AddToList(binsmh3x);  
-  
-    signalHisto = new MH3(1); // Signal(E)
-    signalHisto->SetName("MHOnSubtractionSignal");
-    signalHisto->SetTitle("Extracted Signal");
-    parlist->AddToList(signalHisto);
-    signalHisto->SetBinning(&((TH1D&)signalHisto->GetHist()), 
-			    aeHisto->GetYaxis());
-
-    offHisto = new MH3(1); // Off(E)
-    offHisto->SetName("MHOnSubtractionOff");
-    offHisto->SetTitle("Off Signal");
-    parlist->AddToList(offHisto);
-    offHisto->SetBinning(&((TH1D&)offHisto->GetHist()), 
-			    aeHisto->GetYaxis());
-    
-    signifHisto = new MH3(1); // Significance(E)
-    signifHisto->SetName("MHOnSubtractionSignif");
-    signifHisto->SetTitle("Significance");
-    parlist->AddToList(signifHisto);
-    signifHisto->SetBinning(&((TH1D&)signifHisto->GetHist()), 
-			    aeHisto->GetYaxis());
-
-  }
-  if (fChiSquareHisto==0x0)
-    fChiSquareHisto = new TH1D("fChiSquareHisto", "#chi^{2}/d.o.f. of fits", 50, 0, 5);
-  if (fSignificanceHisto==0x0)
-    fSignificanceHisto = new TH1D("fSignificanceHisto", "Significances", 41, -0.5, 40.5);
-  if (fSummedAlphaPlots==0x0)
-    fSummedAlphaPlots = new TH1D("fSummedAlphaPlots", "Cumulative Alpha", 
-				 alphaBins,aeHisto->GetXaxis()->GetBinLowEdge(1),
-				 aeHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));  
-         
-  // The following loop fixes a common integration region for each
-  // energy bin and alerts when no significant excess is found.
-  
-  Double_t minLowerBin = -10; // minimum integration range
-  Double_t maxUpperBin =  10; // minimum integration range
-  Double_t maxAlpha =  70; // maximum integration range
-  Double_t sumSigLiMa = 0;
-
-  TH1F* alphaHisto[energyBins];
-
-  fSigniPlotIndex = 0; // cf. ExtractSignal
- 
-  for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) {
-    *fLog << inf << "Preprocessing ALPHA distribution for E bin " << energyBin << endl;
-    char hname[80];
-    sprintf(hname, "MHOnSubtractionAlpha%d", energyBin);    
-    alphaHisto[energyBin-1] =
-      new TH1F(hname, "ALPHA histogram",
-	       alphaBins,aeHisto->GetXaxis()->GetBinLowEdge(1),
-	       aeHisto->GetXaxis()->GetBinLowEdge(alphaBins+1));
-    alphaHisto[energyBin-1]->SetDirectory(NULL);
-    alphaHisto[energyBin-1]->Sumw2();
-    alphaHisto[energyBin-1] = (TH1F*)aeHisto->ProjectionX("xe", energyBin, energyBin);
-    alphaHisto[energyBin-1]->SetName(hname);
-    alphaHisto[energyBin-1]->SetDirectory(NULL);
-
-    sprintf(hname, "%2.1f < E < %2.1f", 
-	    aeHisto->GetYaxis()->GetBinLowEdge(energyBin),
-	    aeHisto->GetYaxis()->GetBinLowEdge(energyBin+1));
-    alphaHisto[energyBin-1]->SetTitle(hname);
-    //    alphaHisto[energyBin-1]->DrawCopy();
-    alphaHisto[energyBin-1]->SetDirectory(NULL);
-      
-    // Find signal region and significance in histogram
-    Double_t lowerBin, upperBin, sSigLiMa;
-    char funcName[20];
-    sprintf(funcName, "%2d", energyBin);
-
-    Bool_t drawFit = kFALSE;
-
-    if (drawPad) {
-      drawPad->cd(drawBase+energyBin-1);
-      drawFit = kTRUE;
-    }
-
-    Bool_t fit = FitHistogram(*alphaHisto[energyBin-1], sSigLiMa, 
-			      lowerBin, upperBin, (Float_t)3.0, drawFit, 
-			      funcName);
-
-    if (fit) { 
-      Double_t redChiSq = alphaHisto[energyBin-1]->GetFunction("gauspol3"+(TString)funcName)->GetChisquare()/
-	alphaHisto[energyBin-1]->GetFunction("gauspol3"+(TString)funcName)->GetNDF();
-      fChiSquareHisto->Fill(redChiSq);
-      fMaxRedChiSq = redChiSq > fMaxRedChiSq ? redChiSq : fMaxRedChiSq;
-      fSummedAlphaPlots->Add(alphaHisto[energyBin-1], 1);
-      if (sSigLiMa < 3)
-	*fLog << warn << "No significant excess for this bin (sigma="<< sSigLiMa <<")!"<<endl;
-      sumSigLiMa+=sSigLiMa;
-   
-      // Evaluate integration range
-      lowerBin = (lowerBin < -maxAlpha) ? -maxAlpha : lowerBin;
-      minLowerBin = (lowerBin < minLowerBin) ? lowerBin : minLowerBin;    
-      upperBin = (upperBin > maxAlpha) ? maxAlpha : upperBin;
-      maxUpperBin = (upperBin > maxUpperBin) ? upperBin : maxUpperBin;
-    } else {
-      fChiSquareHisto->Fill(0);
-    }
-
-//     debugOut->Update();
-
-  } //energyBin
-  
-  *fLog << inf << "=> Integration range for this theta bin will be " << minLowerBin << " < ALPHA < "
-	<< maxUpperBin << "," << endl;    
-  *fLog << inf << "   Summed estimated significance is " << sumSigLiMa << endl;
-      
-  // we have an idea of what is going on in the ALPHA plot...
-  // So now we can indeed extract the signal.
-         
-  sumSigLiMa = 0;
-  for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) {
-    *fLog << inf << "Processing ALPHA distribution for E bin " << energyBin << endl;
-    if (alphaHisto[energyBin-1]->GetEntries() == 0) {
-       *fLog << warn << "No attempt to extract a signal from 0 events." << endl;       
-       if (draw) {
-	 TPaveLabel* lab = new TPaveLabel(0.2,0.4,0.8,0.6,"-(nothing to extract)-");
-	 lab->SetBorderSize(0);
-	 lab->Draw();  
-       }
-    } else {
-      char funcName[20];
-      sprintf(funcName, "%2d", energyBin);
-      
-      Double_t gammaSignal, errorGammaSignal, off, errorOff, sigLiMa;    
-
-      Bool_t drawFit = kFALSE;
-      
-//       if (drawPad) {
-// 	cout << "Going to use pad " <<drawBase+energyBin-1 << endl;
-// 	drawPad->cd(drawBase+energyBin-1);
-// 	drawFit = kTRUE;
-//       }
-
-
-      ExtractSignal(*alphaHisto[energyBin-1],
-		    sigLiMa, minLowerBin, maxUpperBin, 
-		    gammaSignal, errorGammaSignal, off, errorOff, (Float_t)3, drawFit,
-		    funcName, drawPad, drawBase);
-
-      sumSigLiMa += sigLiMa;      
-      fSignificanceHisto->Fill(sigLiMa);
-      fMaxSignif = sigLiMa > fMaxSignif ? sigLiMa : fMaxSignif;
-
-      // Fill Signal 
-      TH1D &h = (TH1D&)(signalHisto->GetHist());
-      h.SetBinContent(energyBin, gammaSignal);
-      h.SetBinError(energyBin, errorGammaSignal);
-      h.SetEntries(h.GetEntries()+gammaSignal);
-      
-      // Fill Off Events
-      TH1D &ho = (TH1D&)(offHisto->GetHist());
-      ho.SetBinContent(energyBin, off);
-      ho.SetBinError(energyBin, errorOff);
-      ho.SetEntries(ho.GetEntries()+off);
-      
-      // Fill Significance
-      TH1D &hg = (TH1D&)(signifHisto->GetHist());
-      hg.SetBinContent(energyBin, sigLiMa);
-      hg.SetEntries(hg.GetEntries()+sigLiMa);           
-    }
-    
-  }//energyBin
-
-  *fLog << inf << "Summed significance is " << sumSigLiMa << endl;
-
-
-  if (draw) {
-    Double_t sigLiMa, lowerBin, upperBin;    
-    FitHistogram(*fSummedAlphaPlots, sigLiMa, lowerBin, upperBin);
-    fSummedAlphaPlots->SetTitle("Cumulative ALPHA distribution");
-
-    *fLog << inf << "Setting range for Significance histo " << fMaxSignif << endl;
-    // fSignificanceHisto->GetXaxis()->SetRange(0,fMaxSignif+1);
-    
-    // *fLog << inf << "Setting range for chisq histo " << fMaxRedChiSq << endl;
-    // fChiSquareHisto->GetXaxis()->SetRange(0,fMaxRedChiSq+5);
-    
-    fChiSquareHisto->DrawClone();
-    fSignificanceHisto->DrawClone();
-    fSummedAlphaPlots->DrawClone();
-  }
-  
-  return kTRUE;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// -----------------------------------------------------------------------
-//
-// Extraction of Gamma signal is performed on a TH1 histogram in ALPHA
-// 
-//
-Bool_t MHOnSubtraction::Calc(TH1 *aHisto, MParList *parlist, 
-			     const Bool_t draw, Float_t signalRegion)
-{ 
-  // Find signal region and estimate significance
-  Double_t lowerBin, upperBin, sigLiMa;
-  FitHistogram(*aHisto,	sigLiMa, lowerBin, upperBin, (Float_t)3.5, kFALSE);
-
-  //if (sigLiMa < 3)
-  //  *fLog << err << "No significant excess (sigma=" << sigLiMa <<")!"<<endl;
-
-  if (signalRegion!=0) {
-    lowerBin = -signalRegion;
-    upperBin =  signalRegion;
-  }
-       
-  Double_t gammaSignal, errorGammaSignal, off, errorOff;
-
-  ExtractSignal(*aHisto, sigLiMa, lowerBin, upperBin, 
-		gammaSignal, errorGammaSignal, off, errorOff, 
-		(Float_t)3.0, draw);
-
-  fSignificance = sigLiMa;
-  
-  *fLog << inf << "Signal is " 
-	<< gammaSignal << "+-" << errorGammaSignal << endl
-	<< inf << "Significance is " << sigLiMa << endl;
-
-  return kTRUE;
-}
-
-// -------------------------------------------------------------------------
-//
-// Draw a copy of the histogram
-//
-TObject *MHOnSubtraction::DrawClone(Option_t *opt) const
-{  
-    TCanvas &c = *MakeDefCanvas("OnSubtraction", "Results from OnSubtraction");
-    c.Divide(2,2);
-
-    gROOT->SetSelectedPad(NULL);
-    gStyle->SetOptStat(0);
-
-    c.cd(1);
-    fSummedAlphaPlots->DrawCopy(opt);
-
-    c.cd(2);
-    fSignificanceHisto->DrawCopy(opt);
-
-    c.cd(3);  
-    TString drawopt="";
-    for (fThetaHistoArray->SetIndex(0); 
- 	 MH3* h=(MH3*)(fThetaHistoArray->GetH()); 
- 	 fThetaHistoArray->IncIndex())
-      {
-	// Get the current histogram
-	TH1D& hist = (TH1D&)h->GetHist();
-	fSummedAlphaPlots->SetTitle("Energy distributions for different theta bins");
-	hist.Draw(drawopt);
-	drawopt="SAME";
-      }
-    fThetaLegend->Draw();
-    
-    c.cd(4);
-    fChiSquareHisto->DrawCopy(opt);
-    
-    c.Modified();
-    c.Update();
-
-    return &c;
-}
-
-// -------------------------------------------------------------------------
-//
-// Draw the histogram
-//
-void MHOnSubtraction::Draw(Option_t *opt) 
-{ 
-    if (!gPad)
-      MakeDefCanvas("OnSubtraction", "Results from OnSubtraction");
-
-    gPad->Divide(2,3);
-
-// Ok, at some point this will be implemented
-
-    gPad->Modified();
-    gPad->Update();
-}
-
-
-
-
-
Index: unk/MagicSoft/Mars/mhist/MHOnSubtraction.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHOnSubtraction.h	(revision 7000)
+++ 	(revision )
@@ -1,75 +1,0 @@
-#ifndef MARS_MHOnSubtraction
-#define MARS_MHOnSubtraction
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-class TH1D;
-class TH3D;
-class TPad;
-class TGraph;
-class TLegend;
-class TPaveLabel;
-
-class MHArray;
-
-class MHOnSubtraction : public MH
-{
-private:
-  TString fHistogramType;
-  TH1D*   fChiSquareHisto;
-  TH1D*   fSignificanceHisto;
-  TH1D*   fSummedAlphaPlots;
-  MHArray *fThetaHistoArray;
-  TLegend *fThetaLegend;
-  Double_t fMaxSignif;
-  Double_t fMaxRedChiSq;
-  Double_t fSlope;             // slope for exponential fit
-  Int_t fThetaBin;
-  Int_t fSigniPlotIndex;
-  Int_t fSigniPlotColor;
-
-  Double_t fSignificance;
-
-  Bool_t CalcAET(TH3D *histon, MParList *parlist, const Bool_t Draw);
-
-  Bool_t FitHistogram(TH1 &alphaHisto, Double_t &sigLiMa,
-		      Double_t &lowerBin, Double_t &upperBin,
-		      Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE,
-		      TString funcName = "");
-
-  Bool_t ExtractSignal(TH1 &alphaHisto, Double_t &sigLiMa,
-		       Double_t &lowerBin, Double_t &upperBin,
-		       Double_t &gammaSignal, Double_t &errorGammaSignal,
-		       Double_t &off, Double_t &errorOff,
- 		       Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE,
- 		       TString funcName = "", TPad *drawPad = 0, Int_t drawBase = 0);
-
-
-
-public:
-  MHOnSubtraction(const char *name=NULL, const char *title=NULL);
-  ~MHOnSubtraction();
-
-  Double_t CalcSignificance(Double_t nOn, Double_t nOff, Double_t theta);
-  Double_t GetSignificance()  { return fSignificance; };
-
-  void SetExpoSlope(Double_t slope) { fSlope = slope; }
-  
-  Bool_t Calc(MParList *parlist, const Bool_t Draw);
-
-  Bool_t Calc(TH3 *histon, MParList *parlist, const Bool_t Draw);
-  Bool_t TH2Calc(TH2 *aeHisto, MParList *parlist, const Bool_t Draw, 
-		 TPad *drawPad = 0, Int_t drawBase = 0);
-  Bool_t Calc(TH1 *histon, MParList *parlist, const Bool_t Draw,
-	      Float_t signalRegion = 0);
-
-  void Draw(Option_t *option="");
-  TObject *DrawClone(Option_t *option="") const;
-
-  ClassDef(MHOnSubtraction, 1) //Extracts gamma signals from pure ON-data
-};
-
-#endif
-
Index: /trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7001)
@@ -78,5 +78,5 @@
     : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE),
     fIsWobble(kFALSE), fIsMonteCarlo(kFALSE),  fFullDisplay(kFALSE),
-    fNameHist("MHTheta"), fCalcHadronness(0)
+    fNameHist("MHThetaSq"), fCalcHadronness(0)
 {
     fName  = name  ? name  : "MJCut";
@@ -428,4 +428,6 @@
     MBinning bins7("BinningDist");
     MBinning bins8("BinningMaxDist");
+    MBinning bins9("BinningM3Long");
+    MBinning bins0("BinningConc1");
     plist.AddToList(&bins1);
     plist.AddToList(&bins2);
@@ -436,4 +438,6 @@
     plist.AddToList(&bins7);
     plist.AddToList(&bins8);
+    plist.AddToList(&bins9);
+    plist.AddToList(&bins0);
 
     // --------------------------------------------------------------------------------
Index: /trunk/MagicSoft/Mars/mjobs/MJOptimize.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 7001)
@@ -181,4 +181,5 @@
     eval->SetVal(0);
 
+    const Bool_t isnull = gLog.IsNullOutput();
     if (fDebug<3)
         gLog.SetNullOutput(kTRUE);
@@ -190,5 +191,5 @@
 
     if (fDebug<3)
-        gLog.SetNullOutput(kFALSE);
+        gLog.SetNullOutput(isnull);
 
     const Double_t f = eval->GetVal();
Index: /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 7001)
@@ -178,4 +178,10 @@
         return -1;
 
+    TObject *hist = arr.FindObjectInCanvas("Hist", "MHAlpha", "Hist");
+    cout << "HIST: " << hist << endl;
+    if (hist)
+        cout << "TYPE: " << hist->ClassName() << endl;
+    arr.Print();
+
     vstime->Copy(h1);
     size->Copy(h2);
@@ -344,6 +350,6 @@
     taskenv1.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est);
 
-    MFillH fill1("HistOff [MHAlpha]", "MHillasSrc", "FillHistOff");
-    MFillH fill2("HistOn  [MHAlpha]", "MHillasSrc", "FillHistOn");
+    MFillH fill1("HistEOff [MHAlpha]", "MHillasSrc", "FillHistEOff");
+    MFillH fill2("HistE    [MHAlpha]", "MHillasSrc", "FillHistE");
 
     MFDataMember f0("DataType.fVal", '<', 0.5, "FilterOffData");
@@ -382,8 +388,8 @@
     }
 
-    const MHAlpha *halpha = (MHAlpha *)plist.FindObject("HistOn");
+    const MHAlpha *halpha = (MHAlpha *)plist.FindObject("HistE");
     if (!halpha)
     {
-        *fLog << err << GetDescriptor() << ": HistOn [MHAlpha] not found... abort." << endl;
+        *fLog << err << GetDescriptor() << ": HistE [MHAlpha] not found... abort." << endl;
         return kFALSE;
     }
@@ -597,5 +603,4 @@
     *fLog << inf << "Reading from file: " << fPathIn << endl;
 
-    cout << "Opening..." << endl;
     TFile file(fPathIn, "READ");
     if (!file.IsOpen())
@@ -605,5 +610,4 @@
     }
 
-    cout << "Reading..." << endl;
     file.cd();
     MStatusArray arr;
@@ -614,11 +618,7 @@
     }
 
-    cout << "Searching..." << endl;
-
     TH1 *excess = (TH1D*)arr.FindObjectInCanvas("Excess", "TH1D", "Hist");
     if (!excess)
         return kFALSE;
-
-    cout << "Displaying..." << endl;
 
     // ------------------- Plot excess versus size ------------------- 
@@ -638,6 +638,4 @@
     // Don't do this on the original object!
     excess->SetStats(kFALSE);
-
-    cout << "ExcessSize..." << endl;
 
     TObject *o=0;
@@ -656,26 +654,16 @@
     }
 
-    cout << "Dist..." << endl;
-
     // -------------- Comparison of Image Parameters --------------
     c.cd(2);
     PlotSame(arr, plist, "Dist",   "HilSrc",  "MHHilSrcMCPost");
 
-    cout << "Length..." << endl;
-
     c.cd(3);
     PlotSame(arr, plist, "Length", "PostCut", "MHHillasMCPost");
 
-    cout << "M3l..." << endl;
-
     c.cd(4);
     PlotSame(arr, plist, "M3l",    "HilExt",  "MHHilExtMCPost");
 
-    cout << "Conc1..." << endl;
-
     c.cd(5);
     PlotSame(arr, plist, "Conc1",  "NewPar",  "MHNewParMCPost");
-
-    cout << "Width..." << endl;
 
     c.cd(6);
@@ -710,4 +698,6 @@
     MBinning bins7("BinningDist");
     MBinning bins8("BinningMaxDist");
+    MBinning bins9("BinningM3Long");
+    MBinning bins0("BinningConc1");
 
     MAlphaFitter fit;
@@ -722,4 +712,6 @@
     plist.AddToList(&bins7);
     plist.AddToList(&bins8);
+    plist.AddToList(&bins9);
+    plist.AddToList(&bins0);
     plist.AddToList(&fit);
 
Index: /trunk/MagicSoft/Mars/readdaq.cc
===================================================================
--- /trunk/MagicSoft/Mars/readdaq.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/readdaq.cc	(revision 7001)
@@ -51,6 +51,5 @@
     gLog << "   readdaq [-h] [-?] [-vn] [-dec] [-a0] inputfile[.raw]" << endl << endl;
     gLog << "     input file:   Magic DAQ binary file." << endl;
-    gLog << "     -a0: Do not use Ansii codes." << endl;
-    gLog << "     -vn: Verbosity level n [default=2]" << endl;
+    gLog.Usage();
     gLog << "     -d1: print data in decimal values" << endl;
     gLog << "     -c1: print MRawCrateArray data" << endl;
@@ -60,10 +59,11 @@
 int main(int argc, char **argv)
 {
-    StartUpMessage();
-
     //
     // Evaluate arguments
     //
     MArgs arg(argc, argv);
+    gLog.Setup(arg);
+
+    StartUpMessage();
 
     if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
@@ -76,9 +76,4 @@
     // Set verbosity to highest level.
     //
-    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
-
-    if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
-        gLog.SetNoColors();
-
     const bool kDecimal    = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
     const bool kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
Index: /trunk/MagicSoft/Mars/readraw.cc
===================================================================
--- /trunk/MagicSoft/Mars/readraw.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/readraw.cc	(revision 7001)
@@ -54,5 +54,5 @@
     gLog << "   readraw [-h] [-?] [-vn] [-dec] [-a0] inputfile[.root]" << endl << endl;
     gLog << "     input file:   Magic DAQ binary file." << endl;
-    gLog << "     -vn: Verbosity level n [default=2]" << endl;
+    gLog.Usage();
     gLog << "     -d, --dec: print data in decimal values" << endl;
     gLog << "     -a, --no-colors: Do not use Ansii color codes" << endl;
@@ -71,8 +71,9 @@
 int main(int argc, char **argv)
 {
-    StartUpMessage();
-
     // Evaluate arguments
     MArgs arg(argc, argv);
+    gLog.Setup(arg);
+
+    StartUpMessage();
 
     // check for the right usage of the program
@@ -83,11 +84,4 @@
         return 2;
     }
-
-    // Set verbosity
-    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
-
-    // Set color usage
-    if (arg.HasOnlyAndRemove("--no-colors") || arg.HasOnlyAndRemove("-a"))
-        gLog.SetNoColors();
 
     // Set usage of decimal values
Index: /trunk/MagicSoft/Mars/showlog.cc
===================================================================
--- /trunk/MagicSoft/Mars/showlog.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/showlog.cc	(revision 7001)
@@ -100,55 +100,43 @@
             s.ReplaceAll("", "\033");
 
-        // Check whether it is an empty line
-        if (s=="\033[0m")
+        const char *end = s.Data()+s.Length();
+        for (const char *c=s.Data(); c<end; c++)
         {
-            gLog << endl;
-            continue;
-        }
+            char *to = NULL;
+            Int_t n  = -1;
 
-        while (!s.IsNull())
-        {
-            Ssiz_t pos = s.First("\033[");
-            if (pos<0)
+            if (c+1<end-1 && *c=='\033' && *(c+1)=='[')
+                n = strtol(c+2, &to, 10);
+
+            if (to==NULL || *to!='m')
             {
-                gLog << s;
-                break;
+                gLog << *c;
+                continue;
             }
 
-            gLog << s(0, pos);
-            s.Remove(0, pos+1);
-            if (s.BeginsWith("0m") && s.Length()>3)
+            c = to;
+
+            switch (n)
             {
-                gLog << all;
-                s.Remove(0, 2);
+            case 0:
+                if (c<end-1)
+                    gLog << flush << all;
+                continue;
+            case 31:
+                gLog << flush << err;
+                continue;
+            case 32:
+                gLog << flush << inf;
+                continue;
+            case 33:
+                gLog << flush << warn;
+                continue;
+            case 34:
+                gLog << flush << dbg;
                 continue;
             }
-            if (s.BeginsWith("31m"))
-            {
-                gLog << err;
-                s.Remove(0, 3);
-                continue;
-            }
-            if (s.BeginsWith("32m"))
-            {
-                gLog << inf;
-                s.Remove(0, 3);
-                continue;
-            }
-            if (s.BeginsWith("33m"))
-            {
-                gLog << warn;
-                s.Remove(0, 3);
-                continue;
-            }
-            if (s.BeginsWith("34m"))
-            {
-                gLog << dbg;
-                s.Remove(0, 3);
-                continue;
-            }
-            gLog << "\033[";
+            gLog << flush << "\033[" << n << "m";
         }
-        gLog << endl;
+        gLog << endl << all;
     }
 
Index: /trunk/MagicSoft/Mars/showplot.cc
===================================================================
--- /trunk/MagicSoft/Mars/showplot.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/showplot.cc	(revision 7001)
@@ -37,9 +37,20 @@
     gLog << "   -q                        Quit when job is finished" << endl;
     gLog << endl;
-    gLog << " Output Options: "<< endl;
+    gLog << " General Output Options: "<< endl;
+    gLog << "   --print[=printer]         Print to printer" << endl;
     gLog << "   --save-as-ps[=filename]   Save plots as postscript" << endl;
+    gLog << "   --save-as-pdf[=filename]  Save plots as pdf-file" << endl;
+    gLog << "   --save-as-svg[=filename]  Save plots as svg-file" << endl;
+    gLog << "   --save-as-root[=filename] Save plots as root file" << endl;
+    gLog << "   --save-as-C[=filename]    Save plots as root scripts" << endl;
+    gLog << "   --tab=num                 Save only tab number num" << endl << endl;
+    gLog << " Print only options:" << endl;
+    gLog << "   --print-cmd='lpr -P%p %f' Set the printer command" << endl;
+    gLog << "   --print-dir=/tmp          Set the printing temp directory" << endl << endl;
+    gLog << " GUI only options:" << endl;
     gLog << "   --save-as-gif[=filename]  Save plots as gif files" << endl;
-    gLog << "   --save-as-C[=filename]    Save plots as root scripts" << endl;
-    gLog << "   --tab=num                 Save only tab number num" << endl;
+    gLog << "   --save-as-jpg[=filename]  Save plots as jpg files" << endl;
+    gLog << "   --save-as-xpm[=filename]  Save plots as xpm files" << endl;
+    gLog << "   --save-as-png[=filename]  Save plots as png files" << endl;
     gLog << endl;
     gLog << "   --version, -V             Show startup message with version number" << endl;
@@ -49,5 +60,15 @@
     gLog << " Use showplot to display a MStatusArray in an MStatusDisplay." << endl;
     gLog << " MStatusArrays are typically written by programs showing data" << endl;
-    gLog << " check plots, like callisto." << endl;
+    gLog << " check plots, like callisto." << endl << endl;
+    gLog << "Printing:" << endl;
+    gLog << " For more details see MStatusDisplay::PrintPS" << endl << endl;
+    gLog << "Examples:" << endl;
+    gLog << " showplot filename.root" << endl;
+    gLog << " showplot -b --null --print --print-cmd='psnup -2 %f' filename.root | lpr" << endl;
+    gLog << " showplot -b --print --print-cmd='psbook %f | psnup -2 | lpr' filename.root" << endl;
+    gLog << " showplot -b --print --print-cmd='cat %f' filename.root > filename.ps" << endl;
+    gLog << " showplot -b --save-as-ps filename.root" << endl;
+    gLog << " showplot -q --save-as-gif=tab5.gif --tab=5 filename.root" << endl;
+    gLog << " showplot -b --save-as-ps --print=lp2 filename.root" << endl;
     gLog << endl;
 }
@@ -55,10 +76,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -71,18 +93,32 @@
     }
 
-    gLog.Setup(arg);
-
-    const Bool_t kQuit      = arg.HasOnlyAndRemove("-q");
-    const Bool_t kBatch     = arg.HasOnlyAndRemove("-b");
-
-    const Int_t  kTab       = arg.GetIntAndRemove("--tab=", -1);
-
-    const Bool_t kSaveAsPs  = arg.HasOnlyAndRemove("--save-as-ps")  || arg.Has("--save-as-ps=");
-    const Bool_t kSaveAsGif = arg.HasOnlyAndRemove("--save-as-gif") || arg.Has("--save-as-gif=");
-    const Bool_t kSaveAsC   = arg.HasOnlyAndRemove("--save-as-C")   || arg.Has("--save-as-C=");
-
-    TString kNamePs  = arg.GetStringAndRemove("--save-as-ps=");
-    TString kNameGif = arg.GetStringAndRemove("--save-as-gif=");
-    TString kNameC   = arg.GetStringAndRemove("--save-as-C=");
+    const Bool_t kQuit       = arg.HasOnlyAndRemove("-q");
+    const Bool_t kBatch      = arg.HasOnlyAndRemove("-b");
+
+    const Int_t  kTab        = arg.GetIntAndRemove("--tab=", -1);
+
+    const Bool_t kPrint      = arg.HasOnlyAndRemove("--print")        || arg.Has("--print=");
+    const Bool_t kSaveAsPs   = arg.HasOnlyAndRemove("--save-as-ps")   || arg.Has("--save-as-ps=");
+    const Bool_t kSaveAsPdf  = arg.HasOnlyAndRemove("--save-as-pdf")  || arg.Has("--save-as-pdf=");
+    const Bool_t kSaveAsSvg  = arg.HasOnlyAndRemove("--save-as-svg")  || arg.Has("--save-as-svg=");
+    const Bool_t kSaveAsGif  = arg.HasOnlyAndRemove("--save-as-gif")  || arg.Has("--save-as-gif=");
+    const Bool_t kSaveAsJpg  = arg.HasOnlyAndRemove("--save-as-jpg")  || arg.Has("--save-as-jpg=");
+    const Bool_t kSaveAsXpm  = arg.HasOnlyAndRemove("--save-as-xpm")  || arg.Has("--save-as-xpm=");
+    const Bool_t kSaveAsPng  = arg.HasOnlyAndRemove("--save-as-png")  || arg.Has("--save-as-png=");
+    const Bool_t kSaveAsRoot = arg.HasOnlyAndRemove("--save-as-root") || arg.Has("--save-as-root=");
+    const Bool_t kSaveAsC    = arg.HasOnlyAndRemove("--save-as-C")    || arg.Has("--save-as-C=");
+
+    TString kNamePrint = arg.GetStringAndRemove("--print=");
+    TString kPrintCmd  = arg.GetStringAndRemove("--print-cmd=");
+    TString kPrintDir  = arg.GetStringAndRemove("--print-dir=");
+    TString kNamePs    = arg.GetStringAndRemove("--save-as-ps=");
+    TString kNamePdf   = arg.GetStringAndRemove("--save-as-pdf=");
+    TString kNameSvg   = arg.GetStringAndRemove("--save-as-svg=");
+    TString kNameGif   = arg.GetStringAndRemove("--save-as-gif=");
+    TString kNameJpg   = arg.GetStringAndRemove("--save-as-jpg=");
+    TString kNameXpm   = arg.GetStringAndRemove("--save-as-xpm=");
+    TString kNamePng   = arg.GetStringAndRemove("--save-as-png=");
+    TString kNameRoot  = arg.GetStringAndRemove("--save-as-root=");
+    TString kNameC     = arg.GetStringAndRemove("--save-as-C=");
 
 
@@ -90,4 +126,11 @@
     // check for the right usage of the program
     //
+    if (arg.GetNumOptions()>0)
+    {
+        gLog << err << "Unknown commandline options..." << endl;
+        arg.Print("options");
+        gLog << endl;
+        return 3;
+    }
     if (arg.GetNumArguments()!=1)
     {
@@ -96,5 +139,5 @@
     }
 
-    TApplication app("Showplot", &argc, argv);
+    TApplication app("showplot", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
@@ -108,9 +151,21 @@
     const TString kInput = arg.GetArgumentStr(0);
 
-    if (kNamePs.IsNull()  && kSaveAsPs)
+    if (kNamePs.IsNull()    && kSaveAsPs)
         kNamePs = kInput;
-    if (kNameGif.IsNull() && kSaveAsGif)
+    if (kNamePdf.IsNull()   && kSaveAsPdf)
+        kNamePdf = kInput;
+    if (kNameSvg.IsNull()   && kSaveAsSvg)
+        kNameSvg = kInput;
+    if (kNameGif.IsNull()   && kSaveAsGif)
         kNameGif = kInput;
-    if (kNameC.IsNull()   && kSaveAsC)
+    if (kNameJpg.IsNull()   && kSaveAsJpg)
+        kNameJpg = kInput;
+    if (kNameXpm.IsNull()   && kSaveAsXpm)
+        kNameXpm = kInput;
+    if (kNamePng.IsNull()   && kSaveAsPng)
+        kNamePng = kInput;
+    if (kNameRoot.IsNull()  && kSaveAsRoot)
+        kNameRoot = kInput;
+    if (kNameC.IsNull()     && kSaveAsC)
         kNameC = kInput;
 
@@ -124,10 +179,24 @@
     d->Open(kInput);
 
+    if (kPrint)
+        d->PrintPS(kTab,    kNamePrint, kPrintCmd, kPrintDir);
     if (kSaveAsPs)
-        d->SaveAsPS(kTab, kNamePs);
+        d->SaveAsPS(kTab,   kNamePs);
+    if (kSaveAsPdf)
+        d->SaveAsPDF(kTab,  kNamePdf);
+    if (kSaveAsSvg)
+        d->SaveAsSVG(kTab,  kNameSvg);
     if (kSaveAsGif)
-        d->SaveAsGIF(kTab, kNameGif);
+        d->SaveAsGIF(kTab,  kNameGif);
+    if (kSaveAsJpg)
+        d->SaveAsJPG(kTab,  kNameJpg);
+    if (kSaveAsXpm)
+        d->SaveAsXPM(kTab,  kNameXpm);
+    if (kSaveAsPng)
+        d->SaveAsPNG(kTab,  kNamePng);
+    if (kSaveAsRoot)
+        d->SaveAsRoot(kTab, kNameRoot);
     if (kSaveAsC)
-        d->SaveAsC(kTab, kNameC);
+        d->SaveAsC(kTab,    kNameC);
 
     if (kBatch || kQuit)
Index: /trunk/MagicSoft/Mars/sinope.cc
===================================================================
--- /trunk/MagicSoft/Mars/sinope.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/sinope.cc	(revision 7001)
@@ -249,10 +249,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -264,6 +265,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     //const TString kConfig     = arg.GetStringAndRemove("--config=", "callisto.rc");
@@ -379,5 +378,5 @@
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    TApplication app("Sinope", &argc, argv);
+    TApplication app("sinope", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
Index: /trunk/MagicSoft/Mars/sponde.cc
===================================================================
--- /trunk/MagicSoft/Mars/sponde.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/sponde.cc	(revision 7001)
@@ -89,10 +89,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -104,6 +105,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     const TString kConfig       =  arg.GetStringAndRemove("--config=", "sponde.rc");
@@ -184,5 +183,5 @@
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    TApplication app("Sponde", &argc, argv);
+    TApplication app("sponde", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
Index: /trunk/MagicSoft/Mars/star.cc
===================================================================
--- /trunk/MagicSoft/Mars/star.cc	(revision 7000)
+++ /trunk/MagicSoft/Mars/star.cc	(revision 7001)
@@ -91,10 +91,11 @@
 int main(int argc, char **argv)
 {
+    //
+    // Evaluate arguments
+    //
+    MArgs arg(argc, argv, kTRUE);
+    gLog.Setup(arg);
+
     StartUpMessage();
-
-    //
-    // Evaluate arguments
-    //
-    MArgs arg(argc, argv, kTRUE);
 
     if (arg.HasOnly("-V") || arg.HasOnly("--version"))
@@ -106,6 +107,4 @@
         return 2;
     }
-
-    gLog.Setup(arg);
 
     const TString kConfig     = arg.GetStringAndRemove("--config=", "star.rc");
@@ -193,5 +192,5 @@
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    TApplication app("Star", &argc, argv);
+    TApplication app("star", &argc, argv);
     if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
     {
