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;
