Index: trunk/MagicSoft/Mars/mastro/MAstroCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 9302)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MAstroCamera.cc,v 1.30 2006-10-17 17:15:58 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MAstroCamera.cc,v 1.31 2009-02-07 20:39:55 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -88,4 +88,6 @@
 #include "MGeomMirror.h"
 
+#include "MString.h"
+
 #include "MTime.h"
 #include "MAstroSky2Local.h"
@@ -411,5 +413,5 @@
         // transform meters into millimeters (camera display works with mm)
         mean *= 1./num;
-        DrawStar(mean(0), mean(1), *radec, hasmean?kBlack:-1, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
+        DrawStar(mean(0), mean(1), *radec, hasmean?kBlack:-1, MString::Format("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
         if (hasnull)
         {
@@ -417,5 +419,5 @@
             vstar *= rot;
             const TVector3 spot = fMirror0->GetReflection(vstar, fGeom->GetCameraDist())*1000;
-            DrawStar(spot(0), spot(1), *radec, hasmean?kBlack:-1, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
+            DrawStar(spot(0), spot(1), *radec, hasmean?kBlack:-1, MString::Format("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
             // This can be used to get the abberation...
             //cout << TMath::Hypot(spot(0), spot(1)) << " " << TMath::Hypot(mean(0)-spot(0), mean(1)-spot(1)) << endl;
Index: trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 9302)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MAstroCatalog.cc,v 1.32 2009-02-03 13:27:58 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MAstroCatalog.cc,v 1.33 2009-02-07 20:40:01 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1198,7 +1198,7 @@
 
     TString txt;
-    txt += Form("\\alpha=%.2fh ",      fmod(ra/15+48, 24));
-    txt += Form("\\delta=%.1f\\circ ", fmod(dec+270,180)-90);
-    txt += Form("/ FOV=%.1f\\circ",    fRadiusFOV);
+    txt += MString::Format("\\alpha=%.2fh ",      fmod(ra/15+48, 24));
+    txt += MString::Format("\\delta=%.1f\\circ ", fmod(dec+270,180)-90);
+    txt += MString::Format("/ FOV=%.1f\\circ",    fRadiusFOV);
 
     if (!fTime || !fObservatory)
@@ -1214,7 +1214,7 @@
 
     txt.Prepend("#splitline{");
-    txt += Form("  \\theta=%.1f\\circ ", fmod(zd+270,180)-90);
-    txt += Form("\\phi=%.1f\\circ ",     fmod(az+720, 360));
-    txt += Form(" / \\rho=%.1f\\circ",   rho*TMath::RadToDeg());
+    txt += MString::Format("  \\theta=%.1f\\circ ", fmod(zd+270,180)-90);
+    txt += MString::Format("\\phi=%.1f\\circ ",     fmod(az+720, 360));
+    txt += MString::Format(" / \\rho=%.1f\\circ",   rho*TMath::RadToDeg());
     txt += "}{<";
     txt += fTime->GetSqlDateTime();
Index: trunk/MagicSoft/Mars/mbase/MContinue.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 9302)
@@ -52,4 +52,5 @@
 
 #include "MF.h"
+#include "MString.h"
 #include "MParList.h"
 #include "MTaskList.h"
@@ -105,5 +106,5 @@
 {
     fName  = name  ? name  : "MContinue";
-    fTitle = title ? title : "Task returning kCONTINUE";
+    fTitle = title ? title : "Task returning kCONTINUE (or any other return code)";
 
     SetFilter(f);
@@ -155,5 +156,5 @@
 
     if ((TString)GetFilter()->GetName()==fName)
-        GetFilter()->SetName(Form("MF:%s", fName.Data()));
+        GetFilter()->SetName(MString::Format("MF:%s", fName.Data()));
 
     if (!fTaskList->AddToListBefore(GetFilter(), this))
Index: trunk/MagicSoft/Mars/mbase/MFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 9302)
@@ -77,4 +77,6 @@
 #include "MLogManip.h"
 
+#include "MString.h"
+
 ClassImp(MFilter);
 
@@ -97,5 +99,5 @@
 TString MFilter::GetRule() const
 {
-    return Form("(%s)", ClassName()); //"<GetRule n/a for " + fName + ">";
+    return MString::Format("(%s)", ClassName()); //"<GetRule n/a for " + fName + ">";
 }
 
Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 9302)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MLog.cc,v 1.61 2008-06-16 14:58:27 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MLog.cc,v 1.62 2009-02-07 20:40:07 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -114,4 +114,5 @@
 #include "MArgs.h"
 #include "MTime.h"
+#include "MString.h"
 #include "MParContainer.h"
 
@@ -572,5 +573,5 @@
     TString f1 = arg.GetStringAndRemove("--log=", "");
     if (f1.IsNull() && arg.HasOnlyAndRemove("--log"))
-        f1 = Form("%s.log", arg.GetName());
+        f1 = MString::Format("%s.log", arg.GetName());
     if (!f1.IsNull())
     {
@@ -581,5 +582,5 @@
     TString f2 = arg.GetStringAndRemove("--html=", "");
     if (f2.IsNull() && arg.HasOnlyAndRemove("--html"))
-        f2 = Form("%s.html", arg.GetName());
+        f2 = MString::Format("%s.html", arg.GetName());
     if (!f2.IsNull())
     {
Index: trunk/MagicSoft/Mars/mbase/MMath.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 9302)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.46 2009-01-24 10:57:46 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.47 2009-02-07 20:33:22 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -876,7 +876,7 @@
     }
 
-    const char *fmt = MString::Format("%%.%de", i);
-
-    v = MString::Format(fmt, v).Atof();
+    const TString fmt = MString::Format("%%.%de", i);
+
+    v = MString::Format(fmt.Data(), v).Atof();
     e = error.Atof();
 }
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9302)
@@ -1103,6 +1103,6 @@
     for (int i=1; i<9; i++)
     {
-        const TString form = Form(id.Data(), i);
-        const TString res  = Form(form.Data(), num);
+        const TString form = MString::Format(id.Data(), i);
+        const TString res  = MString::Format(form.Data(), num);
 
         const TString str  = GetEnvValue2(env, prefix, res, "");
Index: trunk/MagicSoft/Mars/mbase/MParEmulated.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParEmulated.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MParEmulated.cc	(revision 9302)
@@ -50,4 +50,6 @@
 #include "MLogManip.h"
 
+#include "MString.h"
+
 ClassImp(MParEmulated);
 
@@ -158,5 +160,5 @@
     name.Prepend("Get");
 
-    TMethodCall *call = new TMethodCall(MParEmulated::Class(), name, proxy?Form("%p,%d", proxy, offset):Form("%d", offset));
+    TMethodCall *call = new TMethodCall(MParEmulated::Class(), name, proxy?MString::Format("%p,%d", proxy, offset):MString::Format("%d", offset));
     fgListMethodCall.Add(call);
     return call;
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 9302)
@@ -485,5 +485,5 @@
 
     // Add copyright notice
-    l = new TGLabel(f, Form("(c) MARS Software Development, 2000-%d", TDatime().GetYear()));
+    l = new TGLabel(f, MString::Format("(c) MARS Software Development, 2000-%d", TDatime().GetYear()));
     fList->Add(l);
     f->AddFrame(l, layb);
@@ -2580,5 +2580,5 @@
 Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
 {
-    SetStatusLine1(Form("Writing %s file...",ext.Data()));
+    SetStatusLine1(MString::Format("Writing %s file...",ext.Data()));
     SetStatusLine2("Please be patient!");
 
Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9302)
@@ -84,4 +84,5 @@
 
 #include "MAstro.h"
+#include "MString.h"
 
 ClassImp(MTime);
@@ -708,5 +709,5 @@
     GetTime(h, m, s, ms);
 
-    return TString(Form("%02d.%02d.%04d %02d:%02d:%02d.%03d", d, mon, y, h, m, s, ms));
+    return MString::Format("%02d.%02d.%04d %02d:%02d:%02d.%03d", d, mon, y, h, m, s, ms);
 }
 
@@ -883,5 +884,5 @@
 
     *fLog << all << GetDescriptor() << ": ";
-    *fLog << GetString() << Form(" (+%dns)", fNanoSec) << endl;
+    *fLog << GetString() << MString::Format(" (+%dns)", fNanoSec) << endl;
 } 
 
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9302)
@@ -102,4 +102,5 @@
 
     gROOT->GetListOfCleanups()->Add(this); // To remove fOut if deleted
+    SetBit(kMustCleanup);
 }
 
Index: trunk/MagicSoft/Mars/mhbase/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 9302)
@@ -93,4 +93,6 @@
 #include "MLogManip.h"
 
+#include "MString.h"
+
 #include "MH.h"
 #include "MHArray.h"
@@ -599,5 +601,5 @@
     if (fDisplay && fDisplay->HasCanvas(fCanvas))
     {
-        const TString opt(Form("nonew %s", fDrawOption.Data()));
+        const TString opt(MString::Format("nonew %s", fDrawOption.Data()));
         fCanvas->cd();
         // Remove the old class to prevent clashes calling
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9302)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.42 2008-12-21 18:09:49 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.43 2009-02-07 20:40:12 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -74,4 +74,6 @@
 #include "MLogManip.h"
 
+#include "MString.h"
+
 #include "MParList.h"
 #include "MParContainer.h"
@@ -156,5 +158,5 @@
 
     if (list->FindObject(name))
-        name += Form(" <%d>", list->GetSize()+1);
+        name += MString::Format(" <%d>", list->GetSize()+1);
 
     if (!usescreenfactor)
@@ -1507,5 +1509,5 @@
 {
     *fLog << " " << setw(7) << n << " (";
-    *fLog << Form("%5.1f", 100.*n/GetNumExecutions());
+    *fLog << MString::Format("%5.1f", 100.*n/GetNumExecutions());
     *fLog << "%) Evts skipped: " << str << endl;
 }
Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 9302)
@@ -166,4 +166,6 @@
 #include "MLog.h"
 #include "MLogManip.h"
+
+#include "MString.h"
 
 #include "MParList.h"
@@ -643,12 +645,12 @@
         if (gPad)
         {
-            const TString pfx(Form("%sProfX", fHist->GetName()));
-            const TString pfy(Form("%sProfY", fHist->GetName()));
+            const TString pfx(MString::Format("%sProfX", fHist->GetName()));
+            const TString pfy(MString::Format("%sProfY", fHist->GetName()));
 
             TProfile *p = 0;
             if ((p=dynamic_cast<TProfile*>(gPad->FindObject(pfx))))
-                p->SetName(Form("%sProfX", name));
+                p->SetName(MString::Format("%sProfX", name));
             if ((p=dynamic_cast<TProfile*>(gPad->FindObject(pfy))))
-                p->SetName(Form("%sProfY", name));
+                p->SetName(MString::Format("%sProfY", name));
         }
 
@@ -851,5 +853,5 @@
         MH::SetPalette("pretty");
 
-    const TString pfx(Form("%sProfX", fHist->GetName()));
+    const TString pfx(MString::Format("%sProfX", fHist->GetName()));
     if ((p=dynamic_cast<TProfile*>(gPad->FindObject(pfx))))
     {
@@ -859,5 +861,5 @@
     }
 
-    const TString pfy(Form("%sProfY", fHist->GetName()));
+    const TString pfy(MString::Format("%sProfY", fHist->GetName()));
     if ((p=dynamic_cast<TProfile*>(gPad->FindObject(pfy))))
     {
@@ -969,5 +971,5 @@
     if (profx)
     {
-        const TString pfx(Form("%sProfX", fHist->GetName()));
+        const TString pfx(MString::Format("%sProfX", fHist->GetName()));
 
         if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfx))))
@@ -985,5 +987,5 @@
     if (profy)
     {
-        const TString pfy(Form("%sProfY", fHist->GetName()));
+        const TString pfy(MString::Format("%sProfY", fHist->GetName()));
 
         if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfy))))
@@ -1298,2 +1300,8 @@
     delete arr;
 }
+
+void MH3::RecursiveRemove(TObject *obj)
+{
+    if (obj==fHist)
+        fHist = 0;
+}
Index: trunk/MagicSoft/Mars/mhbase/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 9301)
+++ trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 9302)
@@ -158,4 +158,6 @@
     void Paint(Option_t *opt="");
 
+    void RecursiveRemove(TObject *obj);
+
     ClassDef(MH3, 4) // Generalized 1/2/3D-histogram for Mars variables
 };
Index: trunk/MagicSoft/Mars/mhbase/MHn.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 9302)
@@ -136,4 +136,5 @@
 
 #include "MH3.h"
+#include "MString.h"
 
 ClassImp(MHn);
@@ -170,5 +171,5 @@
         if (name==fHist[i]->GetName())
         {
-            name += Form("_%d", fNum);
+            name += MString::Format("_%d", fNum);
             break;
         }
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 9301)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 9302)
@@ -71,4 +71,73 @@
 using namespace std;
 
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MAlphaFitter::MAlphaFitter(const char *name, const char *title) : fSigInt(15),
+    fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80),
+    fPolynomOrder(2), fFitBackground(kTRUE), fFunc(0),
+    fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
+{
+    fName  = name  ? name  : "MAlphaFitter";
+    fTitle = title ? title : "Fit alpha";
+
+    SetSignalFunction(kGauss);
+
+    Clear();
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor
+//
+MAlphaFitter::~MAlphaFitter()
+{
+    delete fFunc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Re-initializes fFunc either according to SignalFunc_t
+//
+void MAlphaFitter::SetSignalFunction(SignalFunc_t func)
+{
+    if (gROOT->GetListOfFunctions()->FindObject(""))
+    {
+        gLog << err << "MAlphaFitter::SetSignalFunction -- '' found!" << endl;
+        return;
+    }
+
+    delete fFunc;
+    fFunc = 0;
+
+    switch (func)
+    {
+    case kGauss:
+        fFunc=new TF1("", MString::Format("gaus(0) + pol%d(3)", fPolynomOrder));
+        break;
+    case kThetaSq:
+        if (fPolynomOrder>0)
+            fPolynomOrder = 1;
+        fFunc=new TF1("", "[0]*exp(-0.5*((sqrt(x)-[1])/[2])^2) + expo(3)");
+        break;
+    }
+
+    fSignalFunc=func;
+
+    fFunc->SetName("Dummy");
+    gROOT->GetListOfFunctions()->Remove(fFunc);
+
+    fCoefficients.Set(3+fPolynomOrder+1);
+    fCoefficients.Reset();
+
+    fErrors.Set(3+fPolynomOrder+1);
+    fErrors.Reset();
+}
+
+// --------------------------------------------------------------------------
+//
+// Reset variables which belong to results. Reset the arrays.
+//
 void MAlphaFitter::Clear(Option_t *o)
 {
@@ -86,4 +155,13 @@
     fCoefficients.Reset();
     fErrors.Reset();
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns fFunc->Eval(d) or 0 if fFunc==NULL
+//
+Double_t MAlphaFitter::Eval(Double_t d) const
+{
+    return fFunc ? fFunc->Eval(d) : 0;
 }
 
@@ -294,4 +372,5 @@
     h.SetDirectory(0);
     h.Add(&hon);
+
     h.Scale(0.5);
     for (int i=1; i<=bin+3; i++)
@@ -310,8 +389,8 @@
     // Do a gaussian error propagation to calculated the error of
     // the background estimated from the fit
-    const Double_t ea = fit.GetErrors()[3];
-    const Double_t eb = fit.GetErrors()[4];
-    const Double_t a  = fit.GetCoefficients()[3];
-    const Double_t b  = fit.GetCoefficients()[4];
+    const Double_t ea = fit.fErrors[3];
+    const Double_t eb = fit.fErrors[4];
+    const Double_t a  = fit.fCoefficients[3];
+    const Double_t b  = fit.fCoefficients[4];
 
     const Double_t t  = fIntegralMax;
@@ -333,5 +412,7 @@
     // const Double_t sc = bg * er*er / (fit2.GetEventsBackground()*fit2.GetEventsBackground());
     // Assuming that bg and fit2.GetEventsBackground() are rather identical:
-    const Double_t sc = er*er / fit.GetEventsBackground();
+    const Double_t sc = er*er / fit.fEventsBackground;
+
+
     /*
      cout << MMath::SignificanceLiMaSigned(hon.Integral(1, bin), fit.GetEventsBackground()/sc, sc) << " ";
@@ -354,8 +435,8 @@
         return kFALSE;
 
-    fChiSqSignal  = fit.GetChiSqSignal();
-    fChiSqBg      = fit.GetChiSqBg();
-    fCoefficients = fit.GetCoefficients();
-    fErrors       = fit.GetErrors();
+    fChiSqSignal  = fit.fChiSqSignal;
+    fChiSqBg      = fit.fChiSqBg;
+    fCoefficients = fit.fCoefficients;
+    fErrors       = fit.fErrors;
 
     // ----------------------------------------------------------------------------
@@ -472,9 +553,9 @@
 
     // Function
-    TF1 *fcn = f.fFunc;
+    delete f.fFunc;
+
     f.fFunc = new TF1(*fFunc);
     f.fFunc->SetName("Dummy");
     gROOT->GetListOfFunctions()->Remove(f.fFunc);
-    delete fcn;
 }
 
@@ -527,5 +608,37 @@
 {
     const TString name(MString::Format("TempAlphaEnergy%06d", gRandom->Integer(1000000)));
+
     TH1D *h = hon.ProjectionZ(name, 0, hon.GetNbinsX()+1, bin, bin, "E");
+    h->SetDirectory(0);
+
+    const Bool_t rc = Fit(*h, paint);
+
+    delete h;
+
+    return rc;
+}
+
+Bool_t MAlphaFitter::FitTheta(const TH3D &hon, UInt_t bin, Bool_t paint)
+{
+    const TString name(MString::Format("TempAlphaTheta%06d", gRandom->Integer(1000000)));
+
+    TH1D *h = hon.ProjectionZ(name, bin, bin, 0, hon.GetNbinsY()+1, "E");
+    h->SetDirectory(0);
+
+    const Bool_t rc = Fit(*h, paint);
+
+    delete h;
+
+    return rc;
+}
+/*
+Bool_t MAlphaFitter::FitTime(const TH3D &hon, UInt_t bin, Bool_t paint)
+{
+    const TString name(Form("TempAlphaTime%06d", gRandom->Integer(1000000)));
+
+    hon.GetZaxis()->SetRange(bin,bin);
+    TH1D *h = (TH1D*)hon.Project3D("ye");
+    hon.GetZaxis()->SetRange(-1,-1);
+
     h->SetDirectory(0);
 
@@ -534,39 +647,16 @@
     return rc;
 }
-
-Bool_t MAlphaFitter::FitTheta(const TH3D &hon, UInt_t bin, Bool_t paint)
-{
-    const TString name(MString::Format("TempAlphaTheta%06d", gRandom->Integer(1000000)));
-    TH1D *h = hon.ProjectionZ(name, bin, bin, 0, hon.GetNbinsY()+1, "E");
-    h->SetDirectory(0);
-
-    const Bool_t rc = Fit(*h, paint);
-    delete h;
-    return rc;
-}
-/*
-Bool_t MAlphaFitter::FitTime(const TH3D &hon, UInt_t bin, Bool_t paint)
-{
-    const TString name(Form("TempAlphaTime%06d", gRandom->Integer(1000000)));
-
-    hon.GetZaxis()->SetRange(bin,bin);
-    TH1D *h = (TH1D*)hon.Project3D("ye");
-    hon.GetZaxis()->SetRange(-1,-1);
-
-    h->SetDirectory(0);
-
-    const Bool_t rc = Fit(*h, paint);
-    delete h;
-    return rc;
-}
 */
 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint)
 {
     const TString name(MString::Format("TempAlpha%06d", gRandom->Integer(1000000)));
+
     TH1D *h = hon.ProjectionZ(name, 0, hon.GetNbinsX()+1, 0, hon.GetNbinsY()+1, "E");
     h->SetDirectory(0);
 
     const Bool_t rc = Fit(*h, paint);
+
     delete h;
+
     return rc;
 }
@@ -578,6 +668,7 @@
 
     TH1D *h1 = hon.ProjectionZ(name1, 0, hon.GetNbinsX()+1, bin, bin, "E");
+    h1->SetDirectory(0);
+
     TH1D *h0 = hof.ProjectionZ(name0, 0, hof.GetNbinsX()+1, bin, bin, "E");
-    h1->SetDirectory(0);
     h0->SetDirectory(0);
 
@@ -596,6 +687,7 @@
 
     TH1D *h1 = hon.ProjectionZ(name1, bin, bin, 0, hon.GetNbinsY()+1, "E");
+    h1->SetDirectory(0);
+
     TH1D *h0 = hof.ProjectionZ(name0, bin, bin, 0, hof.GetNbinsY()+1, "E");
-    h1->SetDirectory(0);
     h0->SetDirectory(0);
 
@@ -638,6 +730,7 @@
 
     TH1D *h1 = hon.ProjectionZ(name1, 0, hon.GetNbinsX()+1, 0, hon.GetNbinsY()+1, "E");
+    h1->SetDirectory(0);
+
     TH1D *h0 = hof.ProjectionZ(name0, 0, hof.GetNbinsX()+1, 0, hof.GetNbinsY()+1, "E");
-    h1->SetDirectory(0);
     h0->SetDirectory(0);
 
@@ -656,6 +749,7 @@
 
     TH1D *h1 = hon.ProjectionZ(name1, 0, hon.GetNbinsX()+1, bin, bin, "E");
+    h1->SetDirectory(0);
+
     TH1D *h0 = hof.ProjectionZ(name0, 0, hof.GetNbinsX()+1, bin, bin, "E");
-    h1->SetDirectory(0);
     h0->SetDirectory(0);
 
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 9301)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 9302)
@@ -10,8 +10,5 @@
 #endif
 
-#ifndef ROOT_TF1
-#include <TF1.h>
-#endif
-
+class TF1;
 class TH1D;
 class TH3D;
@@ -85,28 +82,10 @@
 public:
     // Implementing the function yourself is only about 5% faster
-    MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15),
-        fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80),
-        fPolynomOrder(2), fFitBackground(kTRUE), fSignalFunc(kGauss),
-        fCoefficients(3+fPolynomOrder+1), fErrors(3+fPolynomOrder+1),
-        fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)),
-        fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
-    {
-        fName  = name  ? name  : "MAlphaFitter";
-        fTitle = title ? title : "Fit alpha";
-
-        fFunc->SetName("Dummy");
-        gROOT->GetListOfFunctions()->Remove(fFunc);
-
-        Clear();
-    }
-
+    MAlphaFitter(const char *name=0, const char *title=0);
     MAlphaFitter(const MAlphaFitter &f) : fFunc(0)
     {
         f.Copy(*this);
     }
-    ~MAlphaFitter()
-    {
-        delete fFunc;
-    }
+    ~MAlphaFitter();
 
     // TObject
@@ -134,33 +113,6 @@
         SetSignalFunction(fSignalFunc);
     }
-    void SetSignalFunction(SignalFunc_t func)
-    {
-        delete fFunc;
-        switch (func)
-        {
-        case kGauss:
-            fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", fPolynomOrder));
-            break;
-        case kThetaSq:
-//            if (fPolynomOrder==0)
-//                fFunc=new TF1("", "[0]*exp(-0.5*((sqrt(x)-[1])/[2])^2) + pol0(3)");
-//            else
-            //            {
-            if (fPolynomOrder>0)
-                fPolynomOrder = 1;
-            fFunc=new TF1("", "[0]*exp(-0.5*((sqrt(x)-[1])/[2])^2) + expo(3)");
-//            }
-            break;
-        }
-        fSignalFunc=func;
-        fFunc->SetName("Dummy");
-        gROOT->GetListOfFunctions()->Remove(fFunc);
-
-        fCoefficients.Set(3+fPolynomOrder+1);
-        fCoefficients.Reset();
-
-        fErrors.Set(3+fPolynomOrder+1);
-        fErrors.Reset();
-    }
+    void SetSignalFunction(SignalFunc_t func);
+
     void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; }
 
@@ -193,5 +145,5 @@
     const TArrayD &GetCoefficients() const { return fCoefficients; }
     const TArrayD &GetErrors() const       { return fErrors; }
-    Double_t Eval(Double_t d) const { return fFunc ? fFunc->Eval(d) : 0; }
+    Double_t Eval(Double_t d) const;
 
     Double_t CalcUpperLimit() const;
