Index: trunk/MagicSoft/Mars/macros/optim/optimdisp.C
===================================================================
--- trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 7396)
+++ trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 7401)
@@ -1,27 +1,19 @@
+/* More explanations at the end of the file */
 void optimdisp()
 {
-    MJOptimizeDisp opt;
-    opt.SetDebug(2);
-    opt.SetOptimizer(MJOptimize::kSimplex);
-    opt.EnableTestTrain();
+    MJOptimizeDisp opt;                     // Initialize optimization class
+    opt.SetDebug(2);                        // Choose the level of output
+    opt.SetOptimizer(MJOptimize::kMigrad);  // Choose the fit algorithm (see MJOptimize)
+    opt.EnableTestTrain();                  // Split sample into test and train
 
     // -------------------- Setup ----------------------------
-    //opt.AddParameter("1-(MHillas.fWidth/MHillas.fLength)");
-    opt.AddParameter("atan(1./(1-(MHillas.fWidth/MHillas.fLength)))");
-    //opt.AddParameter("log10(MNewImagePar.fLeakage1+1)");
+    opt.AddParameter("1-(MHillas.fWidth/MHillas.fLength)"); // M[0]
+    opt.AddParameter("log10(MNewImagePar.fLeakage1+1)");    // M[1]
 
-    opt.FixParameter(0, 0.743871,  0,  2);  //0.562676
-    opt.FixParameter(1, 0.329471,  0,  2);  //0.317315
-    opt.FixParameter(2, 1.500002,  0, 10);  //1.55754
+    opt.SetParameter(0,  1.30871);                          // Setup [0]
+    opt.SetParameter(1,  5.81119);                          // Setup [1]
+    opt.SetParameter(2,  0.763486);                         // Setup [2]
 
-    // Leakage==0: RMS = 0.030
-    // Leakage>0:  RMS = 0.010
-
-    // all: 0.029 (0.605991, 0.332266, 1.50825)
-
-    //char *r = "([0]+(pow(M[1],[1])*[2]))/M[0]";
-    //char *r = "([0]+(pow(M[1],[1])*[2]))*M[0]";
-    //char *r = "[0]*M[0]";
-    char *r = "[0]/M[0]";
+    char *r = "([0]+([1]*pow(M[1], [2])))*M[0]";            // Rule to calc Disp
 
     // -------------------- Run ----------------------------
@@ -30,5 +22,47 @@
     opt.SetDisplay(d);
 
-    opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
+    /*
+     -------------------- Magic-Cuts ----------------------
+     MFMagicCuts cuts;
+     cuts.SetHadronnessCut(MFMagicCuts::kArea);
+     cuts.SetThetaCut(MFMagicCuts::kOn);
+
+     TArrayD arr(10);
+     arr[0]=  1.3245;
+     arr[1]=  0.208700;
+     arr[2]=  0.229200;
+     arr[3]=  5.305200;
+     arr[4]=  0.098930;
+     arr[5]= -0.082950;
+     arr[6]=  8.2957;
+     arr[7]=  0.8677;
+
+     cuts.SetVariables(arr);
+
+     opt.AddPreCut(&cuts);
+
+     -------------------- Other cuts ----------------------
+     opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
+    */
+
     opt.RunDisp("ganymedmcpart.root", r);
 }
+
+/* ------------------ Good strategy -------------------
+ 1) first fix parameters:
+      opt.FixParameter(1,  0);
+      opt.FixParameter(2,  1);
+    and process only showers without leakage
+      opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
+ 2) release parameters 1 and 2 and fix 0 to the result of 1)
+      opt.FixParameter(0,  0.8362);
+      opt.SetParameter(1,  2.0);
+      opt.SetParameter(2,  0.8);
+    and process only showers with leakage
+      opt.AddPreCut("MNewImagePar.fLeakage1>0.0001");
+ 3) release all parameters and start with the result of 1) and 2)
+      opt.SetParameter(0,  0.8362);
+      opt.SetParameter(1,  5.84);
+      opt.SetParameter(2,  0.76);
+    and process all showers. (Comment out opt.PreCuts())
+ */
Index: trunk/MagicSoft/Mars/macros/optim/optimenergy.C
===================================================================
--- trunk/MagicSoft/Mars/macros/optim/optimenergy.C	(revision 7396)
+++ trunk/MagicSoft/Mars/macros/optim/optimenergy.C	(revision 7401)
@@ -18,5 +18,28 @@
     opt.SetDisplay(d);
 
-    //opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
+    /*
+     -------------------- Magic-Cuts ----------------------
+     MFMagicCuts cuts;
+     cuts.SetHadronnessCut(MFMagicCuts::kArea);
+     cuts.SetThetaCut(MFMagicCuts::kOn);
+
+     TArrayD arr(10);
+     arr[0]=  1.3245;
+     arr[1]=  0.208700;
+     arr[2]=  0.229200;
+     arr[3]=  5.305200;
+     arr[4]=  0.098930;
+     arr[5]= -0.082950;
+     arr[6]=  8.2957;
+     arr[7]=  0.8677;
+
+     cuts.SetVariables(arr);
+
+     opt.AddPreCut(&cuts);
+
+     -------------------- Other cuts ----------------------
+     opt.AddPreCut("MPointingPos.fZd<7");
+    */
+
     opt.RunEnergy("ganymedmcpart.root", r);
 }
Index: trunk/MagicSoft/Mars/macros/optim/rfenergyest.C
===================================================================
--- trunk/MagicSoft/Mars/macros/optim/rfenergyest.C	(revision 7396)
+++ trunk/MagicSoft/Mars/macros/optim/rfenergyest.C	(revision 7401)
@@ -1,6 +1,6 @@
 void rfenergyest()
 {
-    MSequence seqtst("~/Software/Mars/mranforest/sequencemc-test.txt");
-    MSequence seqtrn("~/Software/Mars/mranforest/sequencemc-train.txt");
+    MSequence seqtst("~/Software/mc/sequencemc-test.txt");
+    MSequence seqtrn("~/Software/mc/sequencemc-train.txt");
 
     if (!seqtst.IsValid())
@@ -22,6 +22,6 @@
 
     MDirIter iter, iter2;
-    seqtrn.SetupDatRuns(iter,  MSequence::kImages, "~/Software/mc");
-    seqtst.SetupDatRuns(iter2, MSequence::kImages, "~/Software/mc");
+    seqtrn.SetupDatRuns(iter,  MSequence::kImages, "~/Software/mc/img-abs");
+    seqtst.SetupDatRuns(iter2, MSequence::kImages, "~/Software/mc/img-abs");
 
     read.AddFiles(iter);
@@ -60,4 +60,27 @@
     fill.SetReader(&read);
 
+    /* ---------- It doesn't seem to improve anything ----------
+     MFMagicCuts cuts;
+
+     cuts.SetHadronnessCut(MFMagicCuts::kArea);
+     cuts.SetThetaCut(MFMagicCuts::kOn);
+
+     TArrayD arr(10);
+     arr[0]=  1.3245;
+     arr[1]=  0.208700;
+     arr[2]=  0.229200;
+     arr[3]=  5.305200;
+     arr[4]=  0.098930;
+     arr[5]= -0.082950;
+     arr[6]=  8.2957;
+     arr[7]=  0.8677;
+
+     cuts.SetVariables(arr);
+
+     fill.AddPreCut(&cuts);
+
+     --------------- Use the cuts also in test-loop ----------------
+     */
+
     if (!fill.Process())
         return;
@@ -71,11 +94,11 @@
     MBinning b(32, 10, 100000, "BinningEnergyEst", "log");
     /*
-    if (!rf.TrainMultiRF(train, b.GetEdgesD()))    // classification
+    if (!rf.TrainMultiRF(train, b.GetEdgesD()))    // classification with one tree per bin
         return;
 
-    if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification
+    if (!rf.TrainSingleRF(train, b.GetEdgesD()))   // classification into different bins
         return;
     */
-    if (!rf.TrainSingleRF(train))                  // regression
+    if (!rf.TrainSingleRF(train))                  // regression (best choice)
         return;
 
@@ -90,7 +113,10 @@
 
     MHEnergyEst hist;
+    //MContinue cont(&cuts);
+    //cont.SetInverted();
     MFillH fillh(&hist);
 
     tlist.AddToList(&read2);
+    //tlist.AddToList(&cont);
     tlist.AddToList(&rf);
     tlist.AddToList(&fillh);
