Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 7151)
@@ -259,4 +259,7 @@
 void MLog::Underline()
 {
+    if (fIsNull)
+        return;
+
     SetBit(kIsUnderlined);
 
Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 7151)
@@ -428,16 +428,5 @@
     const Double_t cud = ud<0 ? cos(ud)-1 : 1-cos(ud);
 
-    SetEdgesASin(nbins, ld, ud);
-    /*
-    const Double_t binsize = (cld-cud)/nbins;
-    fEdges.Set(nbins+1);
-    for (int i=0; i<=nbins; i++)
-    {
-        const Double_t a = cld-binsize*i;
-        fEdges[i] = a<0 ? -acos(1+a)*kRad2Deg : acos(1-a)*kRad2Deg;
-        cout << a << " " << fEdges[i] << endl;
-    }
-
-    fType = kIsCosinic;*/
+    SetEdgesASin(nbins, cld, cud);
 }
 
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 7151)
@@ -135,5 +135,8 @@
 
     for (int i=5; i<fFunc->GetNpar(); i++)
-        fFunc->ReleaseParameter(i);
+        if (fFitBackground)
+            fFunc->ReleaseParameter(i);
+        else
+            fFunc->SetParameter(i, 0);
 
     // options : N  do not store the function, do not draw
@@ -142,10 +145,13 @@
     //           Q  quiet mode
     //           E  Perform better Errors estimation using Minos technique
-    h.Fit(fFunc, "NQI", "", bgmin, bgmax);
-
-    fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF();
+    if (fFitBackground)
+    {
+        h.Fit(fFunc, "NQI", "", bgmin, bgmax);
+        fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF();
+    }
+
 
     // ------------------------------------
-    if (paint)
+    if (paint && fFitBackground)
     {
         fFunc->SetRange(0, 90);
@@ -209,4 +215,7 @@
     fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground);
 
+    if (TMath::IsNaN(fSignificance))
+        fSignificance=0;
+
     if (fEventsExcess<0)
         fEventsExcess=0;
@@ -240,53 +249,9 @@
     fSignificance     = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground/alpha, alpha);
 
+    if (TMath::IsNaN(fSignificance))
+        fSignificance=0;
     if (fEventsExcess<0)
         fEventsExcess=0;
-/*
-    TF1 func("", "gaus(0)+pol0(3)", 0., 90.);
-
-    const Double_t A  = fEventsSignal/bin;
-    const Double_t dA = TMath::Abs(A);
-    func.SetParLimits(0, -dA*4, dA*4);
-    func.SetParLimits(2, 0, 90);
-    func.SetParLimits(3, -dA, dA);
-
-    func.SetParameter(0, A);
-    func.FixParameter(1, 0);
-    func.SetParameter(2, fSigMax*0.75);
-    func.SetParameter(3, 0);
-
-    // options : N  do not store the function, do not draw
-    //           I  use integral of function in bin rather than value at bin center
-    //           R  use the range specified in the function range
-    //           Q  quiet mode
-    //           E  Perform better Errors estimation using Minos technique
-    TH1D h(hon);
-    h.Add(&hof, -1);
-    h.Fit(&func, "NQI", "", 0, 90);
-
-    fChiSqSignal = func.GetChisquare()/func.GetNDF();
-
-    const Int_t bin1 = h.GetXaxis()->FindFixBin(func.GetParameter(2)*2);
-
-    fChiSqBg = 0;
-    for (int i=bin1; i<=h.GetNbinsX(); i++)
-    {
-        const Float_t val = h.GetBinContent(i);
-        fChiSqBg = val*val;
-    }
-    if (fChiSqBg>0)
-        fChiSqBg /= h.GetNbinsX()+1-bin1;
-
-    fCoefficients.Set(func.GetNpar(), func.GetParameters());
-
-    // ------------------------------------
-    if (paint)
-    {
-        func.SetLineColor(kBlue);
-        func.SetLineWidth(2);
-        func.Paint("same");
-    }
-    // ------------------------------------
-  */
+
     return kTRUE;
 }
@@ -323,4 +288,6 @@
     f.fScaleMax     = fScaleMax;
     f.fPolynomOrder = fPolynomOrder;
+    f.fFitBackground= fFitBackground;
+    f.fSignalFunc   = fSignalFunc;
     f.fScaleMode    = fScaleMode;
     f.fScaleUser    = fScaleUser;
@@ -350,19 +317,31 @@
 {
     *fLog << GetDescriptor() << ": Fitting..." << endl;
-    *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl;
     *fLog << " ...signal to " << fSigMax << " (integrate into bin at " << fSigInt << ")" << endl;
-    *fLog << " ...polynom order " << fPolynomOrder << endl;
-    *fLog << " ...scale mode: ";
-    switch (fScaleMode)
-    {
-    case kNone:        *fLog << "none.";         break;
-    case kEntries:     *fLog << "entries.";      break;
-    case kIntegral:    *fLog << "integral.";     break;
-    case kOffRegion:   *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break;
-    case kBackground:  *fLog << "background (integral between " << fBgMin    << " and " << fBgMax    << ")"; break;
-    case kLeastSquare: *fLog << "least square (N/A)"; break;
-    case kUserScale:   *fLog << "user def (" << fScaleUser << ")"; break;
+    *fLog << " ...signal function: ";
+    switch (fSignalFunc)
+    {
+    case kGauss:       *fLog << "gauss(x)";        break;
+    case kThetaSq:     *fLog << "gauss(sqrt(x))";  break;
     }
     *fLog << endl;
+    if (!fFitBackground)
+        *fLog << " ...no background." << endl;
+    else
+    {
+        *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl;
+        *fLog << " ...polynom order " << fPolynomOrder << endl;
+        *fLog << " ...scale mode: ";
+        switch (fScaleMode)
+        {
+        case kNone:        *fLog << "none.";         break;
+        case kEntries:     *fLog << "entries.";      break;
+        case kIntegral:    *fLog << "integral.";     break;
+        case kOffRegion:   *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break;
+        case kBackground:  *fLog << "background (integral between " << fBgMin    << " and " << fBgMax    << ")"; break;
+        case kLeastSquare: *fLog << "least square (N/A)"; break;
+        case kUserScale:   *fLog << "user def (" << fScaleUser << ")"; break;
+        }
+        *fLog << endl;
+    }
 
     if (TString(o).Contains("result"))
@@ -402,4 +381,19 @@
 }
 
+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,9999);
+
+    h->SetDirectory(0);
+
+    const Bool_t rc = Fit(*h, paint);
+    delete h;
+    return rc;
+}
+
 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint)
 {
@@ -448,5 +442,28 @@
     return rc;
 }
-
+/*
+Bool_t MAlphaFitter::FitTime(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint)
+{
+    const TString name1(Form("TempAlphaTime%06d_on",  gRandom->Integer(1000000)));
+    const TString name0(Form("TempAlphaTime%06d_off", gRandom->Integer(1000000)));
+
+    hon.GetZaxis()->SetRange(bin,bin);
+    TH1D *h1 = (TH1D*)hon.Project3D("ye");
+    hon.GetZaxis()->SetRange(-1,9999);
+    h1->SetDirectory(0);
+
+    hof.GetZaxis()->SetRange(bin,bin);
+    TH1D *h0 = (TH1D*)hof.Project3D("ye");
+    hof.GetZaxis()->SetRange(-1,9999);
+    h0->SetDirectory(0);
+
+    const Bool_t rc = ScaleAndFit(*h1, h0, paint);
+
+    delete h0;
+    delete h1;
+
+    return rc;
+}
+*/
 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, const TH3D &hof, Bool_t paint)
 {
@@ -541,4 +558,6 @@
     case kExcess:
         return -GetEventsExcess();
+    case kGaussSigma:
+        return GetGausSigma();
     }
     return 0;
@@ -601,4 +620,6 @@
         if (txt==(TString)"excess")
             fStrategy = kExcess;
+        if (txt==(TString)"gausssigma" || txt==(TString)"gaussigma")
+            fStrategy = kGaussSigma;
         rc = kTRUE;
     }
@@ -625,4 +646,15 @@
         rc = kTRUE;
     }
+    if (IsEnvDefined(env, prefix, "Signalfunction", print))
+    {
+        TString txt = GetEnvValue(env, prefix, "SignalFunction", "");
+        txt = txt.Strip(TString::kBoth);
+        txt.ToLower();
+        if (txt==(TString)"gauss" || txt==(TString)"gaus")
+            SetSignalFunction(kGauss);
+        if (txt==(TString)"thetasq")
+            SetSignalFunction(kThetaSq);
+        rc = kTRUE;
+    }
     if (IsEnvDefined(env, prefix, "Scale", print))
     {
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 7151)
@@ -34,37 +34,53 @@
         kSignificanceLogExcess,
         kSignificanceExcess,
-        kExcess
+        kExcess,
+        kGaussSigma
     };
+    enum SignalFunc_t {
+        kGauss, kThetaSq
+    };
+
 private:
-    Float_t fSigInt;
-    Float_t fSigMax;
-    Float_t fBgMin;
-    Float_t fBgMax;
-    Float_t fScaleMin;
-    Float_t fScaleMax;
-    Int_t   fPolynomOrder;
-
-    Double_t fSignificance;
-    Double_t fEventsExcess;
-    Double_t fEventsSignal;
-    Double_t fEventsBackground; // fScaleFactor already applied
-
-    Double_t fChiSqSignal;
-    Double_t fChiSqBg;
-    Double_t fIntegralMax;
-    Double_t fScaleFactor;  // Scale factor for off-data
-
-    TArrayD fCoefficients;
-
-    TF1 *fFunc;
-
-    ScaleMode_t fScaleMode;
-    Double_t fScaleUser;
-
-    Strategy_t fStrategy;
+    // Fitting Setup
+    Float_t fSigInt;            // minimum of range to fit the signal
+    Float_t fSigMax;            // maximum of range to fit the signal
+    Float_t fBgMin;             // minimum of range to fit the background
+    Float_t fBgMax;             // minimum of range to fit the background
+    Float_t fScaleMin;          // minimum of range to determin the scale factor of the background
+    Float_t fScaleMax;          // maximum of range to determin the scale factor of the background
+    Int_t   fPolynomOrder;      // order of polyom to be fitted to the background
+    Bool_t  fFitBackground;     // Backround fit: yes/no
+    SignalFunc_t fSignalFunc;  // Type of signal function
+    // Result
+    Double_t fSignificance;     // significance of signal
+    Double_t fEventsExcess;     // calculated number of excess events (signal-bg)
+    Double_t fEventsSignal;     // calculated number of signal events
+    Double_t fEventsBackground; // calculated number of bg events (fScaleFactor already applied)
+
+    Double_t fChiSqSignal;      // Reduced (chi^2/NDF) chisq of signal fit
+    Double_t fChiSqBg;          // Reduced (chi^2/NDF) chisq of bg fit
+    Double_t fIntegralMax;      // Calculated bin border to which it was integrated
+    Double_t fScaleFactor;      // Scale factor for off-data
+
+    TArrayD fCoefficients;      // Fit result
+
+    // Function
+    TF1 *fFunc;                 // fit function (gauss + polynom)
+
+    // Scaling setup
+    ScaleMode_t fScaleMode;     // scaling mode
+    Double_t    fScaleUser;     // user scale factor
+
+    // Minimization strategy
+    Strategy_t fStrategy;       // How to calc minimization value
 
 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), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
+    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),
+        fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)),
+        fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
     {
         fName  = name  ? name  : "MAlphaFitter";
@@ -86,14 +102,10 @@
     }
 
+    // TObject
     void Clear(Option_t *o="");
     void Print(Option_t *o="") const; //*MENU*
     void Copy(TObject &o) const;
-    /*
-    TObject *Clone(const char *name) const
-    {
-        return new MAlphaFitter(*this);
-    }
-    */
-
+
+    // Setter
     void SetScaleUser(Float_t scale)       { fScaleUser = scale; fScaleMode=kUserScale; }
     void SetScaleMode(ScaleMode_t mode)    { fScaleMode    = mode; }
@@ -105,9 +117,34 @@
     void SetScaleMin(Float_t s)            { fScaleMin     = s; }
     void SetScaleMax(Float_t s)            { fScaleMax     = s; }
-    void SetPolynomOrder(Int_t s)          { if (s==fPolynomOrder) return; 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;
+
+        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:
+            fFunc=new TF1 ("", Form("[0]*exp(-((sqrt(x)-[1])/[2])^2) + pol%d(3)", fPolynomOrder));
+            break;
+        }
+        fSignalFunc=func;
         gROOT->GetListOfFunctions()->Remove(fFunc);
         fFunc->SetName("Dummy");
-        fCoefficients.Set(3+s+1); fCoefficients.Reset(); }
-
+        fCoefficients.Set(3+fPolynomOrder+1);
+        fCoefficients.Reset();
+    }
+    void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; }
+
+    // Getter
     Double_t GetSignalIntegralMax() const  { return fSigInt; }
 
@@ -127,7 +164,7 @@
     Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; }
     const TArrayD &GetCoefficients() const { return fCoefficients; }
-
-    void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
-
+    Double_t Eval(Double_t d) const { return fFunc ? fFunc->Eval(d) : 0; }
+
+    // Interface to fit
     Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
     Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
@@ -149,8 +186,10 @@
     Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
     Bool_t FitTheta(const TH3D &h,  UInt_t bin, Bool_t paint=kFALSE);
+    //Bool_t FitTime(const TH3D &h,  UInt_t bin, Bool_t paint=kFALSE);
 
     Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
     Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
     Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
+    //Bool_t FitTime(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
 
     Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
@@ -165,8 +204,16 @@
     {
         return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
-    }
+    }/*
+    Bool_t FitTime(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
+    {
+        return off ? FitTime(on, *off, bin, paint) : FitTime(on, bin, paint);
+    }*/
 
     Double_t Scale(TH1D &off, const TH1D &on) const;
 
+    // Interface to result
+    void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
+
+    // MTask
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 7151)
@@ -292,4 +292,7 @@
     if (!fResult)
         return kFALSE;
+    fSigma = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "GaussSigma");
+    if (!fSigma)
+        return kFALSE;
 
     //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess");
@@ -469,9 +472,6 @@
             size = fHillas->GetSize();
         energy = fEnergy   ? fEnergy->GetVal() : (fHillas?fHillas->GetSize():1000);
-        theta  = fPointPos ? fPointPos->GetZd()   : 0;
-    }
-
-    //if (size>0)
-    //    alpha /= (2.4 + 1.13*(log10((energy-14)/0.37)-5)*(log10((energy-14)/0.37)-5))/15;
+        theta  = fPointPos ? fPointPos->GetZd() : 0;
+    }
 
     // enhance histogram if necessary
@@ -480,13 +480,4 @@
     // Fill histograms
     fHist.Fill(theta, energy, TMath::Abs(alpha), w);
-
-    // Check cuts
-    /*
-    if ( (fEnergyMin>=0 && energy<fEnergyMin) ||
-         (fEnergyMax>=0 && energy>fEnergyMax) ||
-         (fSizeMin>=0   && size  <fSizeMin)   ||
-         (fSizeMax>=0   && size  >fSizeMin) )
-         return kTRUE;
-         */
 
     if (!fSkipHistTime)
@@ -851,4 +842,5 @@
 
     fResult->SetVal(fFit.GetMinimizationValue());
+    fSigma->SetVal(fFit.GetGausSigma());
 
     if (!fSkipHistEnergy)
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.h	(revision 7151)
@@ -44,4 +44,5 @@
 
     MParameterD   *fResult;     //!
+    MParameterD   *fSigma;      //!
     MParameterD   *fEnergy;     //!
     MHillas       *fHillas;     //!
Index: trunk/MagicSoft/Mars/mhflux/MHThetaSq.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHThetaSq.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mhflux/MHThetaSq.h	(revision 7151)
@@ -24,5 +24,4 @@
 
     Bool_t SetupFill(const MParList *pl);
-    void InitMapping(MHMatrix *mat, Int_t type=0);
 
     // MParContainer
@@ -31,4 +30,6 @@
 public:
     MHThetaSq(const char *name=NULL, const char *title=NULL);
+
+    void InitMapping(MHMatrix *mat, Int_t type=0);
 
     void SetNumBinsSignal(UInt_t n) { fNumBinsSignal=TMath::Max(n, 1U); }
Index: trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 7151)
@@ -19,7 +19,3 @@
 #pragma link C++ class MJSpectrum+;
 
-#pragma link C++ class MJOptimize+;
-#pragma link C++ class MJOptimizeCuts+;
-#pragma link C++ class MJOptimizeEnergy+;
-
 #endif
Index: trunk/MagicSoft/Mars/mjobs/MJOptimize.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 7151)
@@ -158,5 +158,5 @@
     MParList *plist = fEvtLoop->GetParList();
 
-    MParameterD   *eval = (MParameterD*)plist->FindObject("MinimizationValue", "MParameterD");
+    MParameterD   *eval = (MParameterD*)plist->FindObject(fNameMinimizationValue, "MParameterD");
     MParContainer *pars = (MParContainer*)plist->FindObject("MParameters", "MParContainer");
 
@@ -172,5 +172,5 @@
         *fLog << endl;
     }
- 
+
     pars->SetVariables(par);
     eval->SetVal(0);
@@ -225,5 +225,5 @@
 }
 
-MJOptimize::MJOptimize() : fDebug(-1), fNumEvents(0), fType(kSimplex), fNumMaxCalls(0), fTolerance(0), fTestTrain(0)
+MJOptimize::MJOptimize() : fDebug(-1), fNumEvents(0), fType(kSimplex), fNumMaxCalls(0), fTolerance(0), fTestTrain(0), fNameMinimizationValue("MinimizationValue")
 {
     fRules.SetOwner();
@@ -648,5 +648,5 @@
 {
     // Checks to make sure, that fcn doesn't crash
-    if (!parlist.FindCreateObj("MParameterD", "MinimizationValue"))
+    if (!parlist.FindCreateObj("MParameterD", fNameMinimizationValue))
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjobs/MJOptimize.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJOptimize.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mjobs/MJOptimize.h	(revision 7151)
@@ -73,4 +73,5 @@
     Float_t fTolerance;
     Int_t   fTestTrain;
+    TString fNameMinimizationValue;
 
     Bool_t Optimize(MEvtLoop &evtloop);
@@ -112,4 +113,5 @@
     void SetTolerance(Float_t tol=0)  { fTolerance=tol; }
     void EnableTestTrain(Int_t b=1)   { fTestTrain=b; } // Use 1 and -1
+    void SetNameMinimizationValue(const char *name="MinimizationValue") { fNameMinimizationValue = name; }
 
     // Parameter access
Index: trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.cc	(revision 7150)
+++ trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.cc	(revision 7151)
@@ -27,53 +27,21 @@
 // MJOptimize
 //
-// Class for otimizing the parameters of the supercuts
+// Class for otimizing a rule to estimate the energy. For more details see
+// MJOptimize.
 //
-// Minimization Control
-// ====================
+// Example:
+// --------
 //
-//   To choose the minimization algorithm use:
-//         void SetOptimizer(Optimizer_t o);
-//
-//   Allowed options are:
-//        enum Optimizer_t
-//        {
-//            kMigrad,      // Minimize by the method of Migrad
-//            kSimplex,     // Minimize by the method of Simplex
-//            kMinimize,    // Migrad + Simplex (if Migrad fails)
-//            kMinos,       // Minos error determination
-//            kImprove,     // Local minimum search
-//            kSeek,        // Minimize by the method of Monte Carlo
-//            kNone         // Skip optimization
-//        };
-//
-//   For more details on the methods see TMinuit.
-//
-//
-//   You can change the behaviour of the minimization using
-//
-//        void SetNumMaxCalls(UInt_t num=0);
-//        void SetTolerance(Float_t tol=0);
-//
-//   While NumMaxCalls is the first, Tolerance the second arguement.
-//   For more details start root and type
-//
-//        gMinuit->mnhelp("command")
-//
-//   while command can be
-//        * MIGRAD
-//        * SIMPLEX
-//        * MINIMIZE
-//        * MINOS
-//        * IMPROVE
-//        * SEEK
-//
-//   The default (num==0 and tol==0) should always give you the
-//   corresponding defaults used in Minuit.
-//
-//
-// FIXME: Implement changing cut in hadronness...
-// FIXME: Show MHSignificance on MStatusDisplay during filling...
-// FIXME: Choose step-size percentage as static data membewr
-// FIXME: Choose minimization method
+//    MJOptimizeEnergy opt;
+//    opt.SetDebug(2);
+//    opt.SetOptimizer(MJOptimize::kMigrad);
+//    opt.SetNumEvents(20000);
+//    opt.EnableTestTrain();
+//    opt.AddParameter("MHillas.fSize");
+//    opt.SetParameter(0, 1, 0, 2);
+//    char *r = "[0]*M[0]"; //Rule to calculate estimated energy
+//    MStatusDisplay *d = new MStatusDisplay;
+//    opt.SetDisplay(d);
+//    opt.RunDisp("ganymed-summary.root", r);
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -116,5 +84,5 @@
 // energy estimator.
 //
-Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule)
+Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule, MTask *weights)
 {
     fLog->Separator("Preparing Energy optimization");
@@ -139,6 +107,6 @@
     hist.InitMapping(&m); 
 
-    MEnergyEstimate est("MParameters");
-    est.SetRule(rule);
+    MParameterCalc est(rule, "MParameters");
+    est.SetNameParameter("MEnergyEst");
     parlist.AddToList(&est);
 
@@ -159,4 +127,6 @@
 
     MFillH fill(&hist);
+    if (weights)
+        fill.SetWeight();
 
     MMatrixLoop loop(&m);
@@ -164,4 +134,6 @@
     tasklist.AddToList(&loop);
     tasklist.AddToList(&est);
+    if (weights)
+        tasklist.AddToList(weights);
     tasklist.AddToList(&fill);
 
Index: trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.h	(revision 7150)
+++ trunk/MagicSoft/Mars/mjobs/MJOptimizeEnergy.h	(revision 7151)
@@ -6,12 +6,16 @@
 #endif
 
+class MTask;
+
 class MJOptimizeEnergy : public MJOptimize
 {
 public:
+    MJOptimizeEnergy() : MJOptimize() { }
+
     // Special optimizing routines
-    Bool_t RunEnergy(const char *fname, const char *rule);
-    Bool_t RunEnergy(const char *rule)
+    Bool_t RunEnergy(const char *fname, const char *rule, MTask *weights=0);
+    Bool_t RunEnergy(const char *rule, MTask *weights=0)
     {
-        return RunEnergy(0, rule);
+        return RunEnergy(0, rule, weights);
     }
 
