Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 7148)
+++ trunk/MagicSoft/Mars/Makefile	(revision 7149)
@@ -66,4 +66,5 @@
           mranforest \
           mjobs \
+          mjoptim \
           mtools \
           mmuon
Index: trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.cc	(revision 7148)
+++ trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.cc	(revision 7149)
@@ -39,16 +39,8 @@
 //
 // Output:
-//   MEnergyEst
+//   MEnergyEst [MParameterD]
 //
 /////////////////////////////////////////////////////////////////////////////
 #include "MEnergyEstimate.h"
-
-#include "MParList.h"
-
-#include "MDataChain.h"
-#include "MParameters.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
 
 ClassImp(MEnergyEstimate);
@@ -61,128 +53,9 @@
 //
 MEnergyEstimate::MEnergyEstimate(const char *name, const char *title)
-    : fData(0), fEnergy(0)
+    : MParameterCalc("MMcEvt.fEnergy")
 {
     fName  = name  ? name  : "MEnergyEstimate";
     fTitle = title ? title : "Task to estimate the energy by a rule";
 
-    fData = new MDataChain("MMcEvt.fEnergy");
+    SetNameParameter("MEnergyEst");
 }
-
-// --------------------------------------------------------------------------
-//
-// delete fData
-//
-MEnergyEstimate::~MEnergyEstimate()
-{
-    delete fData;
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete fData. Initialize a new MDataChain with rule.
-// Returns if fData->IsValid()
-//
-Bool_t MEnergyEstimate::SetRule(const char *rule)
-{
-    delete fData;
-    fData = new MDataChain(rule);
-
-    return fData->IsValid();
-}
-
-// --------------------------------------------------------------------------
-//
-// Forwards SetVariables to fData to allow optimizations.
-//
-void MEnergyEstimate::SetVariables(const TArrayD &arr)
-{
-    fData->SetVariables(arr);
-}
-
-// --------------------------------------------------------------------------
-//
-// FindCreate "MEnergyEst"
-// PreProcess fData.
-//
-Int_t MEnergyEstimate::PreProcess(MParList *plist)
-{
-    fEnergy = (MParameterD*)plist->FindCreateObj("MParameterD", "MEnergyEst");
-    if (!fEnergy)
-        return kFALSE;
-
-    *fLog << inf << "Rule for energy estimation: " << fData->GetRule() << endl;
-
-    if (!fData->PreProcess(plist))
-        return kFALSE;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Get value from fData and set it to fEnergy. SetReadyToSave for fEnergy.
-// Return kCONTINUE if value is NaN (Not a Number)
-//
-Int_t MEnergyEstimate::Process()
-{
-    const Double_t val = fData->GetValue();
-    if (TMath::IsNaN(val))
-        return kCONTINUE;
-
-    fEnergy->SetVal(val);
-    fEnergy->SetReadyToSave();
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Print the rule used for energy estimation
-//
-void MEnergyEstimate::Print(Option_t *o) const
-{
-    *fLog << all << GetDescriptor() << ":";
-    if (!fData)
-        *fLog << " <n/a>" << endl;
-    else
-        *fLog << endl << fData->GetRule() << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-// Check for corresponding entries in resource file and setup filters.
-// Avoid trailing 0's!
-//
-// Example:
-//   test.C:
-//     MEnergyEstimate est("MyEstimator");
-//
-//   test.rc:
-//     MyEstimator.Rule: {0} + {1}
-//     MyEstimator.0: log10(MHillas.fSize)
-//     MyEstimator.1: 5.5
-//
-// For more details see MDataChain::ReadEnv
-//
-Int_t MEnergyEstimate::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
-{
-    MDataChain *f = new MDataChain;
-    f->SetName(fName);
-
-    const Bool_t rc = f->ReadEnv(env, prefix, print);
-    if (rc!=kTRUE)
-    {
-        delete f;
-        return rc;
-    }
-
-    delete fData;
-    fData = f;
-
-    if (!fData->IsValid())
-    {
-        *fLog << err << "MEnergyEst::ReadEnv - ERROR: Inavlid rule from resource file." << endl;
-        return kERROR;
-    }
-
-    return kTRUE;
-}
Index: trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 7148)
+++ trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 7149)
@@ -2,31 +2,12 @@
 #define MARS_MEnergyEstimate
 
-#ifndef MARS_MTask
-#include "MTask.h"
+#ifndef MARS_MParameterCalc
+#include "MParameterCalc.h"
 #endif
 
-class MData;
-class MParameterD;
-
-class MEnergyEstimate : public MTask
+class MEnergyEstimate : public MParameterCalc
 {
-private:
-    MData       *fData;    //->
-    MParameterD *fEnergy;  //!
-
-    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
-
 public:
     MEnergyEstimate(const char *name=NULL, const char *title=NULL);
-    ~MEnergyEstimate();
-
-    Bool_t SetRule(const char *rule);
-
-    Int_t PreProcess(MParList *plist);
-    Int_t Process();
-
-    void SetVariables(const TArrayD &);
-
-    void Print(Option_t *o="") const; //*MENU*
 
     ClassDef(MEnergyEstimate, 1) // Task to estimate the energy by a rule
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 7148)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 7149)
@@ -28,4 +28,5 @@
 SRCFILES = MGeomApply.cc \
            MCameraData.cc \
+           MParameterCalc.cc \
            MEnergyEstimate.cc \
            MMatrixLoop.cc \
