Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 5970)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 5971)
@@ -151,4 +151,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Removes the first edge
+//
 void MBinning::RemoveFirstEdge()
 {
@@ -159,4 +163,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Removes the last edge
+//
 void MBinning::RemoveLastEdge()
 {
@@ -205,4 +213,122 @@
 // --------------------------------------------------------------------------
 //
+// Set edged from text. With the following structure:
+//
+//     n lo hi [type [title]]
+//
+//  n:  number of bins
+//  lo: lowest edge
+//  hi: highest edge
+//  type: "lin" <default>, "log", "cos" (without quotationmarks)
+//  title: Whatever the title might be
+//
+// For example:
+//   SetEdgesRaw("12 0 1 lin This is the title");
+//
+Bool_t MBinning::SetEdgesRaw(const char *txt)
+{
+    Int_t   nbins  = 0;
+    Float_t loedge = 0;
+    Float_t upedge = 0;
+    Int_t   len    = 0;
+    if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len))
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl;
+        return kFALSE;
+    }
+
+    if (loedge>=upedge)
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl;
+        return kFALSE;
+    }
+
+    TString str(txt);
+    str.Remove(0, len);
+    str = str.Strip(TString::kBoth);
+
+    TString typ;
+    Ssiz_t pos = str.First(' ');
+    if (pos>=0)
+    {
+        typ = str(0, pos);
+        if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl;
+            return kFALSE;
+        }
+    }
+
+    SetEdges(nbins, loedge, upedge, typ.Data());
+
+    str = str.Strip(TString::kBoth);
+
+    if (!str.IsNull())
+        fTitle = str;
+
+    return kTRUE;
+}
+/*
+// --------------------------------------------------------------------------
+//
+// Set edged from text. With the following structure:
+//
+//     n= lo= hi= type= title="my title"
+//
+//  n:  number of bins
+//  lo: lowest edge
+//  hi: highest edge
+//  type: "lin" <default>, "log", "cos" (without quotationmarks)
+//  title: Whatever the title might be
+//
+// For example:
+//   SetEdgesRaw("12 0 1 lin This is the title");
+//
+Bool_t MBinning::SetEdgesRaw(const char *txt)
+{
+    Int_t   nbins  = 0;
+    Float_t loedge = 0;
+    Float_t upedge = 0;
+    Int_t   len    = 0;
+    if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len))
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl;
+        return kFALSE;
+    }
+
+    if (loedge>=upedge)
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl;
+        return kFALSE;
+    }
+
+    TString str(txt);
+    str.Remove(0, len);
+    str = str.Strip(TString::kBoth);
+
+    TString typ;
+    Ssiz_t pos = str.First(' ');
+    if (pos>=0)
+    {
+        typ = str(0, pos);
+        if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl;
+            return kFALSE;
+        }
+    }
+
+    SetEdges(nbins, loedge, upedge, typ.Data());
+
+    str = str.Strip(TString::kBoth);
+
+    if (!str.IsNull())
+        fTitle = str;
+
+    return kTRUE;
+}
+*/
+// --------------------------------------------------------------------------
+//
 // Calls SetEdgesLog if opt contains "log"
 // Calls SetEdgesCos if opt contains "cos"
@@ -276,4 +402,29 @@
 
     MH::SetBinning(&h, this);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print binning.
+//
+void MBinning::Print(Option_t *o) const
+{
+    *fLog << all;
+    *fLog << GetDescriptor() << ": nbins=" << GetNumBins() << " [";
+    *fLog << GetEdgeLo() << ", " << GetEdgeHi() << "] ";
+    switch (fType)
+    {
+    case kIsDefault:     *fLog << "deafult"; break;
+    case kIsLinear:      *fLog << "linear"; break;
+    case kIsLogarithmic: *fLog << "logarithmic"; break;
+    case kIsCosinic:     *fLog << "consinic"; break;
+    case kIsUserArray:   *fLog << "user-array"; break;
+    }
+    *fLog << ">";
+
+    if (fTitle!=gsDefTitle)
+        *fLog << " title=" << fTitle;
+
+    *fLog << endl;
 }
 
@@ -317,2 +468,86 @@
     out << "   }" << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// Allows reading a binning from resource files. The structure is as follows
+//
+Int_t MBinning::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+
+    UInt_t  nbins  = GetNumBins();
+    Float_t edgelo = GetEdgeLo();
+    Float_t edgehi = GetEdgeHi();
+    TString type;
+    if (IsEnvDefined(env, prefix, "NumBins", print))
+    {
+        nbins = GetEnvValue(env, prefix, "NumBins", GetNumBins());
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "EdgeLo", print))
+    {
+        edgelo = GetEnvValue(env, prefix, "EdgeLo", GetEdgeLo());
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "EdgeHi", print))
+    {
+        edgehi = GetEnvValue(env, prefix, "EdgeHi", GetEdgeHi());
+        rc = kTRUE;
+    }
+    if (rc==kTRUE && (type==kIsUserArray || type==kIsDefault))
+        type = kIsLinear;
+
+    if (IsEnvDefined(env, prefix, "Type", print))
+    {
+        type = GetEnvValue(env, prefix, "Type", "lin");
+        if (type!=(TString)"lin" && type!=(TString)"log" && type!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: Type is not lin, log nor cos... assuming lin." << endl;
+            type = "lin";
+        }
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "Edges", print))
+    {
+        if (rc==kTRUE)
+            *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Edges' found... ignoring any 'NumBins', 'EdgeLo' and 'EdgeHi'" << endl;
+
+        const TString type = GetEnvValue(env, prefix, "Edges", "");
+        //type = kIsUserArray;
+        /* MISSING */
+        rc = kTRUE;
+        *fLog << err << " SORRY USER ARRAY NOT YET IMPLEMENTED" << endl;
+        return kERROR;
+    }
+
+    const Bool_t raw = IsEnvDefined(env, prefix, "Raw", print);
+    //const Bool_t fullbins    = IsEnvDefined(env, prefix, "Binning", print);
+    if (!raw && /*!fullbins &&*/ rc==kTRUE)
+        SetEdges(nbins, edgelo, edgehi, type.Data());
+
+    if (rc==kTRUE)
+        *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Binning' found... ignoring any 'NumBins', 'EdgeLo', 'EdgeHi' and 'Edges'" << endl;
+
+    if (IsEnvDefined(env, prefix, "Title", print))
+    {
+        fTitle = GetEnvValue(env, prefix, "Title", gsDefTitle.Data());
+        rc = kTRUE;
+    }
+
+    if (raw)
+    {
+        const TString txt = GetEnvValue(env, prefix, "Raw", "");
+        if (!SetEdgesRaw(txt.Data()))
+            return kERROR;
+    }
+/*
+    if (fullbins)
+    {
+        TString txt = GetEnvValue(env, prefix, "Binning", "");
+        SetEdgesRaw(txt.Data());
+    }
+   */
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mhbase/MBinning.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 5970)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 5971)
@@ -55,4 +55,6 @@
 
     Bool_t SetEdges(const MParList &list, const char *name=0);
+    Bool_t SetEdgesRaw(const char *txt);
+    //Bool_t SetEdges(const char *txt);
     void SetEdges(const TAxis &axe);
     void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; }
@@ -104,4 +106,8 @@
     void Apply(TH1 &) const;
 
+    void Print(Option_t *o="") const;
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
+
     ClassDef(MBinning, 1) //Container to store the binning of a histogram
 };
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 5970)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 5971)
@@ -493,2 +493,48 @@
     }
 }
+
+Int_t MAlphaFitter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+
+    //void SetScaleUser(Float_t scale)       { fScaleUser = scale; fScaleMode=kUserScale; }
+    //void SetScaleMode(ScaleMode_t mode)    { fScaleMode    = mode; }
+
+    if (IsEnvDefined(env, prefix, "SignalIntegralMax", print))
+    {
+        SetSignalIntegralMax(GetEnvValue(env, prefix, "SignalIntegralMax", fSigInt));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "SignalFitMax", print))
+    {
+        SetSignalIntegralMax(GetEnvValue(env, prefix, "SignalFitMax", fSigMax));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "BackgroundFitMax", print))
+    {
+        SetBackgroundFitMax(GetEnvValue(env, prefix, "BackgroundFitMax", fBgMax));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "BackgroundFitMin", print))
+    {
+        SetBackgroundFitMin(GetEnvValue(env, prefix, "BackgroundFitMin", fBgMin));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "ScaleMin", print))
+    {
+        SetScaleMin(GetEnvValue(env, prefix, "ScaleMin", fScaleMin));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "ScaleMax", print))
+    {
+        SetScaleMax(GetEnvValue(env, prefix, "ScaleMax", fScaleMax));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "PolynomOrder", print))
+    {
+        SetPolynomOrder(GetEnvValue(env, prefix, "PolynomOrder", fPolynomOrder));
+        rc = kTRUE;
+    }
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 5970)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 5971)
@@ -94,5 +94,5 @@
     void SetScaleMin(Float_t s)            { fScaleMin     = s; }
     void SetScaleMax(Float_t s)            { fScaleMax     = s; }
-    void SetPolynomOrder(Int_t s)          { fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s));
+    void SetPolynomOrder(Int_t s)          { if (s==fPolynomOrder) return; fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s));
         gROOT->GetListOfFunctions()->Remove(fFunc);
         fFunc->SetName("Dummy");
@@ -155,4 +155,6 @@
     Double_t Scale(TH1D &off, const TH1D &on) const;
 
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
+
     ClassDef(MAlphaFitter, 1)
 };
Index: trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc	(revision 5970)
+++ trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc	(revision 5971)
@@ -260,9 +260,9 @@
     else
     {
-        MBinning binsa;
-        binsa.SetEdges(18, 0, 90);
+        MBinning binsa(18, 0, 90);
+        binsa.SetEdges(*plist, "BinningAlpha");
 
         const MBinning *bins = (MBinning*)plist->FindObject("BinningFalseSource");
-        if (!bins)
+        if (!bins || bins->IsDefault())
         {
             const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg;
