Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7177)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7178)
@@ -52,4 +52,40 @@
    * mimage/MHillasCalc.cc:
      - skipped printing the removed case 4 from MHillas::Calc
+
+   * mbase/MStatusDisplay.cc:
+     - fixed wrong "save as" in "open" dialog
+
+   * mbase/MTaskInteractive.[h,cc]:
+     - added ReInit
+
+   * mhflux/MAlphaFitter.cc:
+     - fixed the standard polynom order (0 instead of 1) for
+       difference histogram
+     - changed default start velue for gauss sigma in case of kThetaSq
+
+   * mhflux/MHAlpha.cc, mhflux/MHCollectionArea.cc, 
+     mhflux/MHEffectiveOnTime.cc, mhflux/MHThetaSq.cc,
+     mjobs/MJCut.cc:
+     - enhanced zenith angle range
+
+   * mhflux/MHFalseSource.h:
+     - made GetCatalog protected
+     - made SetOffData virtual
+
+   * mhflux/MHThreshold.cc:
+     - enabled Sumw2
+
+   * mjobs/MJCut.cc:
+     - removed BinningEnergyEst
+
+   * mpointing/MPointingPos.h:
+     - added copy constructor
+
+   * mpointing/MSrcPosCorrect.cc:
+     - added a comment
+
+   * mranforest/MRFEnergyEst.[h,cc]:
+     - now stores the mean energy of the bins in the forest
+     - implemented several interpolation methods
 
 
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7178)
@@ -2896,5 +2896,5 @@
     fi.fIniDir    = StrDup(dir);
 
-    new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
+    new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
 
     if (!fi.fFilename)
Index: trunk/MagicSoft/Mars/mbase/MTaskInteractive.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskInteractive.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mbase/MTaskInteractive.cc	(revision 7178)
@@ -83,4 +83,5 @@
     fCall[1] = 0;
     fCall[2] = 0;
+    fCall[3] = 0;
 }
 
@@ -94,4 +95,5 @@
     Free(1);
     Free(2);
+    Free(3);
 }
 
@@ -141,12 +143,18 @@
     {
     case 0:
-        gLog << "Pre";
+        gLog << "PreProcess";
+        break;
+    case 1:
+        gLog << "Process";
         break;
     case 2:
-        gLog << "Post";
+        gLog << "PostProcess";
+        break;
+    case 3:
+        gLog << "ReInit";
         break;
 
     }
-    gLog << "Process-function." << endl;
+    gLog << "-function." << endl;
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mbase/MTaskInteractive.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskInteractive.h	(revision 7177)
+++ trunk/MagicSoft/Mars/mbase/MTaskInteractive.h	(revision 7178)
@@ -12,13 +12,15 @@
 {
 private:
-    TMethodCall *fCall[3];
+    TMethodCall *fCall[4];
 
-    Int_t (*fPreProcess)(MParList *list);
-    Int_t (*fProcess)();
-    Int_t (*fPostProcess)();
+    Int_t  (*fPreProcess)(MParList *list);
+    Int_t  (*fProcess)();
+    Int_t  (*fPostProcess)();
+    Bool_t (*fReInit)(MParList *list);
 
-    Int_t PreProcess(MParList *list) { if (fCall[0]) return Return(0, &list); return fPreProcess  ? (*fPreProcess)(list) : kTRUE; }
-    Int_t Process()                  { if (fCall[1]) return Return(1);        return fProcess     ? (*fProcess)()        : kTRUE; }
-    Int_t PostProcess()              { if (fCall[2]) return Return(2);        return fPostProcess ? (*fPostProcess)()    : kTRUE; }
+    Int_t  PreProcess(MParList *list) { if (fCall[0]) return Return(0, &list); return fPreProcess  ? (*fPreProcess)(list) : kTRUE; }
+    Int_t  Process()                  { if (fCall[1]) return Return(1);        return fProcess     ? (*fProcess)()        : kTRUE; }
+    Int_t  PostProcess()              { if (fCall[2]) return Return(2);        return fPostProcess ? (*fPostProcess)()    : kTRUE; }
+    Bool_t ReInit(MParList *list)     { if (fCall[3]) return Return(3, &list); return fPostProcess ? (*fPostProcess)()    : kTRUE; }
 
     Int_t Return(Int_t no, void *param=NULL);
@@ -32,6 +34,7 @@
     // This is to be used in compiled code
     void SetPreProcess(Int_t (*func)(MParList *list)) { fPreProcess = func;  Free(0); }
-    void SetProcess(Int_t (*func)())                  { fProcess = func;     Free(1);  }
-    void SetPostProcess(Int_t (*func)())              { fPostProcess = func; Free(2);  }
+    void SetProcess(Int_t (*func)())                  { fProcess = func;     Free(1); }
+    void SetPostProcess(Int_t (*func)())              { fPostProcess = func; Free(2); }
+    void SetReInit(Bool_t (*func)(MParList *list))    { fReInit = func;      Free(3); }
 
     // This is for usage in CINT
@@ -39,4 +42,5 @@
     void SetProcess(void *fcn)     { Set(fcn, 1, "");          fProcess    =0; }
     void SetPostProcess(void *fcn) { Set(fcn, 2, "");          fPostProcess=0; }
+    void SetReInit(void *fcn)      { Set(fcn, 3, "MParList*"); fReInit     =0; }
 
     ClassDef(MTaskInteractive, 0) // Interactive task
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 7178)
@@ -178,5 +178,5 @@
     // Now fit a gaus in the on region on top of the polynom
     fFunc->SetParameter(0, A);
-    fFunc->SetParameter(2, sigmax*0.75);
+    fFunc->SetParameter(2, fSignalFunc==kGauss ? sigmax*0.75 : sigmax);
 
     // options : N  do not store the function, do not draw
@@ -231,5 +231,5 @@
 
     MAlphaFitter fit(*this);
-    fit.SetPolynomOrder(1);
+    fit.SetPolynomOrder(0);
 
     if (alpha<=0 || !fit.Fit(h, paint))
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 7178)
@@ -139,5 +139,5 @@
     binsa.SetEdges(18, 0, 90);
     binse.SetEdgesLog(15, 10, 100000);
-    binst.SetEdgesASin(51, -0.005, 0.505);
+    binst.SetEdgesASin(67, -0.005, 0.665);
     binse.Apply(fHEnergy);
     binst.Apply(fHTheta);
Index: trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 7178)
@@ -94,5 +94,5 @@
     MBinning binsa, binse, binst;
     binse.SetEdgesLog(15, 10, 1000000);
-    binst.SetEdgesASin(51, -0.005, 0.505);
+    binst.SetEdgesASin(67, -0.005, 0.665);
 
     binse.Apply(fHEnergy);
Index: trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 7178)
@@ -410,5 +410,5 @@
     // setup binning
     MBinning btheta("BinningTheta");
-    btheta.SetEdgesASin(51, -0.005, 0.505);
+    btheta.SetEdgesASin(67, -0.005, 0.665);
 
     MBinning btime("BinningDeltaT");
Index: trunk/MagicSoft/Mars/mhflux/MHFalseSource.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHFalseSource.h	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHFalseSource.h	(revision 7178)
@@ -46,4 +46,6 @@
     Double_t fDec;
 
+    TObject *GetCatalog();
+
 private:
     Int_t DistancetoPrimitive(Int_t px, Int_t py);
@@ -54,6 +56,4 @@
     void ProjectOn(const TH3D &src, TH2D *h, TH2D *all);
     void ProjectOnOff(TH2D *h, TH2D *all);
-
-    TObject *GetCatalog();
 
     void MakeSymmetric(TH1 *h);
@@ -78,5 +78,5 @@
     void SetBgMeanMinus5() { SetBgMean(fBgMean-5); } //*MENU*
 
-    void SetOffData(const MHFalseSource &fs) {
+    virtual void SetOffData(const MHFalseSource &fs) {
         fHistOff  = &fs.fHist;
         fMinDist  =  fs.fMinDist;
Index: trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 7178)
@@ -92,5 +92,5 @@
     //binsa.SetEdges(arr);
     binse.SetEdgesLog(15, 10, 100000);
-    binst.SetEdgesCos(50, 0, 60);
+    binst.SetEdgesASin(67, -0.005, 0.665);
     binsa.Apply(fHistTime);
 
Index: trunk/MagicSoft/Mars/mhflux/MHThreshold.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHThreshold.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mhflux/MHThreshold.cc	(revision 7178)
@@ -74,4 +74,5 @@
     fHEnergy.SetDirectory(NULL);
     fHEnergy.UseCurrentStyle();
+    fHEnergy.Sumw2();
 
     MBinning binse(80, 10, 1000000, "", "log");
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7178)
@@ -445,7 +445,7 @@
 
     // Initialize default binnings
-    MBinning bins1(18,  0,     90,    "BinningAlpha",     "lin");
-    MBinning bins2(15, 10,     1e6 ,  "BinningEnergyEst", "log");
-    MBinning bins3(51, -0.005, 0.505, "BinningTheta",     "asin");
+    MBinning bins1(18,  0,     90,    "BinningAlpha", "lin");
+    MBinning bins2(15, 10,     1e6 ,  "BinningSize",  "log");
+    MBinning bins3(67, -0.005, 0.665, "BinningTheta", "asin");
     MBinning bins4("BinningFalseSource");
     MBinning bins5("BinningWidth");
@@ -465,4 +465,5 @@
     plist.AddToList(&bins9);
     plist.AddToList(&bins0);
+    //plist.AddToList(&binsa);
 
     // --------------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mpointing/MPointingPos.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 7177)
+++ trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 7178)
@@ -30,4 +30,8 @@
         fTitle = title ? title : "Container storing the (corrected) telescope pointing position";
     }
+    MPointingPos(const MPointingPos &p) : MParContainer(p),
+        fZd(p.fZd), fAz(p.fAz), fRa(p.fRa), fHa(p.fHa), fDec(p.fDec)
+    {
+    }
 
     void SetLocalPosition(Double_t zd, Double_t az) { fZd=zd; fAz=az; }
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc	(revision 7178)
@@ -135,4 +135,5 @@
     if (fRunNumber<56161 && fRunNumber>53832)
     {
+        // dx=-0.05deg, dy=0.03deg, d=0.06deg
         static const TVector2 dxy(-14.24, -9.495);
         fSrcPosCam->Add(dxy);
Index: trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc	(revision 7177)
+++ trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc	(revision 7178)
@@ -69,9 +69,15 @@
 //
 MRFEnergyEst::MRFEnergyEst(const char *name, const char *title)
-    : fNumTrees(-1), fNumTry(-1), fNdSize(-1), fDebug(kFALSE),
-    fData(0), fEnergyEst(0), fTestMatrix(0), fEstimationMode(kMean)
+    : fDebug(kFALSE), fData(0), fEnergyEst(0),
+    fNumTrees(-1), fNumTry(-1), fNdSize(-1), 
+    fTestMatrix(0), fEstimationMode(kMean)
 {
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
+}
+
+MRFEnergyEst::~MRFEnergyEst()
+{
+    fEForests.Delete();
 }
 
@@ -163,7 +169,4 @@
         MHMatrix matrix1(mat1, "MatrixHadrons");
         MHMatrix matrix0(mat0, "MatrixGammas");
-
-        //matrix1.AddColumns(&usedrules);
-        //matrix0.AddColumns(&usedrules);
 
         // training of RF
@@ -191,11 +194,11 @@
             gLog.SetNullOutput(kFALSE);
 
-        const Double_t E = (log10(grid[ie])+log10(grid[ie+1]))/2;
+        // Calculate bin center
+        const Double_t E = (TMath::Log10(grid[ie])+TMath::Log10(grid[ie+1]))/2;
 
         // save whole forest
         MRanForest *forest=(MRanForest*)plist.FindObject("MRanForest");
-        const TString title = Form("%.10f", E);
-        forest->SetTitle(title);
-        forest->Write(title);
+        forest->SetUserVal(E);
+        forest->Write(Form("%.10f", E));
     }
 
@@ -203,6 +206,4 @@
     usedrules.Write("rules");
 
-    fileRF.Close();
-
     return kTRUE;
 }
@@ -210,5 +211,5 @@
 Int_t MRFEnergyEst::ReadForests(MParList &plist)
 {
-    TFile fileRF(fFileName,"read");
+    TFile fileRF(fFileName, "read");
     if (!fileRF.IsOpen())
     {
@@ -218,6 +219,4 @@
 
     fEForests.Delete();
-
-    Int_t i=0;
 
     TIter Next(fileRF.GetListOfKeys());
@@ -230,9 +229,5 @@
             continue;
 
-        forest->SetTitle(o->GetTitle());
-        forest->SetBit(kCanDelete);
-
-        fBinning.Set(i+1);
-        fBinning[i++] = atof(o->GetTitle());
+        forest->SetUserVal(atof(o->GetName()));
 
         fEForests.Add(forest);
@@ -283,6 +278,10 @@
 //
 //
+#include <TGraph.h>
+#include <TF1.h>
 Int_t MRFEnergyEst::Process()
 {
+    static TF1 f1("f1", "gaus");
+
     TVector event;
     if (fTestMatrix)
@@ -291,20 +290,25 @@
         *fData >> event;
 
-    Double_t eest = 0;
-    Double_t hsum = 0;
+    Double_t sume = 0;
+    Double_t sumh = 0;
     Double_t maxh = 0;
     Double_t maxe = 0;
 
-    Int_t i=0;
+    Double_t max  = -1e10;
+    Double_t min  =  1e10;
+
+    //TH1C h("", "", fEForests.GetSize(), 0, 1);
 
     TIter Next(&fEForests);
     MRanForest *rf = 0;
+
+    TGraph g;
     while ((rf=(MRanForest*)Next()))
     {
         const Double_t h = rf->CalcHadroness(event);
-        const Double_t e = fBinning[i++];
-
-        hsum += h;
-        eest += e*h;
+        const Double_t e = rf->GetUserVal();
+        g.SetPoint(g.GetN(), e, h);
+        sume += e*h;
+        sumh += h;
         if (h>maxh)
         {
@@ -312,4 +316,8 @@
             maxe = e;
         }
+        if (e>max)
+            max = e;
+        if (e<min)
+            min = e;
     }
 
@@ -317,9 +325,17 @@
     {
     case kMean:
-        fEnergyEst->SetVal(pow(10, eest/hsum));
+        fEnergyEst->SetVal(pow(10, sume/sumh));
         break;
     case kMaximum:
         fEnergyEst->SetVal(pow(10, maxe));
         break;
+    case kFit:
+        f1.SetParameter(0, maxh);
+        f1.SetParameter(1, maxe);
+        f1.SetParameter(2, 0.125);
+        g.Fit(&f1, "Q0N");
+        fEnergyEst->SetVal(pow(10, f1.GetParameter(1)));
+        break;
+
     }
     fEnergyEst->SetReadyToSave();
@@ -353,4 +369,6 @@
         if (txt==(TString)"maximum")
             fEstimationMode = kMaximum;
+        if (txt==(TString)"fit")
+            fEstimationMode = kFit;
         rc = kTRUE;
     }
Index: trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.h	(revision 7177)
+++ trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.h	(revision 7178)
@@ -23,49 +23,54 @@
     {
         kMean,
-        kMaximum
+        kMaximum,
+        kFit
     };
 private:
-    Int_t        fNumTrees;  // Training parameters
-    Int_t        fNumTry;    // Training parameters
-    Int_t        fNdSize;    // Training parameters
+    Bool_t       fDebug;      // Debugging of eventloop while training on/off
 
-    Bool_t       fDebug;     // Debugging of eventloop while training on/off
-
-    TString      fFileName;
-    TObjArray    fEForests;
+    TString      fFileName;   // File name to forest
+    TObjArray    fEForests;   // List of forests
 
     MDataArray  *fData;       //! Used to store the MDataChains to get the event values
     MParameterD *fEnergyEst;  //! Used to storeestimated energy
 
-    MHMatrix *fTestMatrix;
+    Int_t        fNumTrees;   //! Training parameters
+    Int_t        fNumTry;     //! Training parameters
+    Int_t        fNdSize;     //! Training parameters
 
-    TArrayD   fBinning;
+    MHMatrix    *fTestMatrix; //! Test Matrix
 
     EstimationMode_t fEstimationMode;
 
+    // MRFEnergyEst
+    Int_t ReadForests(MParList &plist);
+
+    // MTask
     Int_t PreProcess(MParList *plist);
     Int_t Process();
 
-    Int_t ReadForests(MParList &plist);
-
+    // MParContainer
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
 public:
     MRFEnergyEst(const char *name=NULL, const char *title=NULL);
+    ~MRFEnergyEst();
 
+    // Setter for estimation
     void  SetFileName(TString str)     { fFileName = str; }
+    void  SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
 
+    // Setter for training
     void  SetNumTrees(Int_t n=-1)      { fNumTrees = n; }
     void  SetNdSize(Int_t n=-1)        { fNdSize   = n; }
     void  SetNumTry(Int_t n=-1)        { fNumTry   = n; }
+    void  SetDebug(Bool_t b=kTRUE)     { fDebug = b; }
 
+    // Train Interface
+    Int_t Train(const MHMatrix &n, const TArrayD &grid);
+
+    // Test Interface
     void  SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
     void  InitMapping(MHMatrix *m=0)   { fTestMatrix=m; }
-
-    void  SetDebug(Bool_t b=kTRUE)     { fDebug = b; }
-
-    void  SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
-
-    Int_t Train(const MHMatrix &n, const TArrayD &grid);
 
     ClassDef(MRFEnergyEst, 0) // Task
