Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6948)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6949)
@@ -54,4 +54,61 @@
      - fixed a typo in output
      - allow to exchange Test-/Train-Sample
+
+   * ganymed.cc:
+     - implemented "-mc" option to allow cutting MC samples
+
+   * showlog.cc:
+     - implemented real treatment of debug-levels
+     - return 1 instead of 0 in cae of normal finish
+
+   * manalysis/MEnergyEstimate.h, mbase/MContinue.h,
+     mhflux/MAlphaFitter.h:
+     - added Print() to context //*MENU*
+
+   * manalysis/MMatrixLoop.cc:
+     - fixed returning of number of entries if using split mode
+
+   * mbase/MContinue.cc:
+     - implemented Print() function
+
+   * mbase/MParContainer.[h,cc]:
+     - in Read set name of object to argument name if argument!=NULL
+     - reordered some checks for Method calls
+
+   * mdata/MDataFormula.cc:
+     - fixed a problem with the replacement if using [?] for
+       fits
+
+   * mfbase/MFEventSelector2.cc:
+     - replaced some +=1 and -=1 by ++ and --
+
+   * mfileio/MReadMarsFile.cc:
+     - fixed a bug which caused Preprocess to crahs if instatiated
+       with default constructor
+
+   * mhbase/MH.cc, mhflux/MHEffectiveOnTime.cc:
+     - use dynamic_cast if getting "stats"
+
+   * mhflux/MAlphaFitter.cc:
+     - small updates to output
+
+   * mhflux/MHEnergyEst.cc:
+     - fixed all axis lables
+     - implemented fit of resolution
+     - initialize fBias=0 in SetupFill
+     - enhances Print() output
+
+   * mjobs/MJCalibrateSignal.cc:
+     - added all tasks for interleaved calibration events to
+       a third tasklist. Skip all following tasks for these events
+
+   * mjobs/MJCut.[h,cc]:
+     - implemented correct treatment of MC files
+     - write resulting events to result file if no filename set
+     - moved energy estimator behind cuts
+
+   * mjobs/MJOptimize.cc:
+     - changed RunEnergy such, that it can correctly treat
+       MC files written by ganymed using wobble-mode
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 6948)
+++ trunk/MagicSoft/Mars/NEWS	(revision 6949)
@@ -1,4 +1,7 @@
                                                                -*-*- END -*-*-
  *** Version <cvs>
+
+   - Do NOT further process interleaved calibration events in 
+     MJCalibrateSignal - exspecially do not write them to output!
 
 
Index: trunk/MagicSoft/Mars/ganymed.cc
===================================================================
--- trunk/MagicSoft/Mars/ganymed.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/ganymed.cc	(revision 6949)
@@ -49,4 +49,5 @@
     gLog << "   -b                        Batch mode (no graphical output to screen)" << endl<<endl;
     gLog << " Operation Mode:" << endl;
+    gLog << "   -mc                       Monte Carlo dataset (no times)" << endl;
     gLog << "   --wobble                  Force wobble mode (overwrites dataset)" << endl;
     gLog << "   --no-wobble               Force normal mode (overwrites dataset)" << endl << endl;
@@ -120,4 +121,5 @@
     //const Bool_t  kForceExec   = arg.HasOnlyAndRemove("-ff");
 
+    const Bool_t  kIsMc          = arg.HasOnlyAndRemove("-mc");
     const Bool_t  kWobbleModeOn  = arg.HasOnlyAndRemove("--wobble");
     const Bool_t  kWobbleModeOff = arg.HasOnlyAndRemove("--no-wobble");
@@ -239,4 +241,5 @@
     job.EnableWobbleMode(iswobble);
     job.EnableFullDisplay(kFullDisplay);
+    job.EnableMonteCarloMode(kIsMc);
     if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
         job.EnableStorageOfSummary();
Index: trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 6948)
+++ trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 6949)
@@ -28,5 +28,5 @@
     void SetVariables(const TArrayD &);
 
-    void Print(Option_t *o="") const;
+    void Print(Option_t *o="") const; //*MENU*
 
     ClassDef(MEnergyEstimate, 1) // Task to estimate the energy by a rule
Index: trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc	(revision 6949)
@@ -58,5 +58,8 @@
 UInt_t MMatrixLoop::GetEntries()
 {
-    return fMatrix ? fMatrix->GetNumRows() : 0;
+    if (!fMatrix)
+        return 0;
+
+    return fOperationMode==kDefault ? fMatrix->GetNumRows() : (fMatrix->GetNumRows()+1)/2;
 }
 
Index: trunk/MagicSoft/Mars/mbase/MContinue.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 6949)
@@ -227,4 +227,14 @@
 }
 
+void MContinue::Print(Option_t *o) const
+{
+    *fLog << all << GetDescriptor() << ":";
+    if (GetFilter())
+        *fLog << " <" << GetFilter()->GetDescriptor() << ">";
+    *fLog << endl;
+    if (GetFilter())
+        Getfilter()->Print();
+}
+
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mbase/MContinue.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MContinue.h	(revision 6948)
+++ trunk/MagicSoft/Mars/mbase/MContinue.h	(revision 6949)
@@ -42,5 +42,4 @@
     Bool_t IsAllowEmpty() const { return TestBit(kAllowEmpty); }
 
-
     void SetInverted(Bool_t i=kTRUE);
     Bool_t IsInverted() const;
@@ -51,4 +50,7 @@
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 
+    // TObject
+    void Print(Option_t *o="") const; //*MENU*
+
     ClassDef(MContinue, 1) //Task returning kCONTINUE
 };
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 6949)
@@ -321,4 +321,12 @@
 }
 
+Int_t MParContainer::Read(const char *name)
+{
+    const Int_t rc = TObject::Read(name?name:(const char*)fName);
+    if (name)
+        SetName(name);
+    return rc;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -640,6 +648,6 @@
 
     *fLog << "Trying to find MethodCall '" << ClassName();
-    *fLog << "::Get" << part1 << "' instead..." << flush;
-    call = new TMethodCall(IsA(), (TString)"Get"+part1, "");
+    *fLog << "::" << part1 << "' instead..." << flush;
+    call = new TMethodCall(IsA(), part1, "");
     if (call->GetMethod())
     {
@@ -653,6 +661,6 @@
 
     *fLog << "Trying to find MethodCall '" << ClassName();
-    *fLog << "::" << part1 << "' instead..." << flush;
-    call = new TMethodCall(IsA(), part1, "");
+    *fLog << "::Get" << part1 << "' instead..." << flush;
+    call = new TMethodCall(IsA(), (TString)"Get"+part1, "");
     if (call->GetMethod())
     {
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 6948)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 6949)
@@ -122,5 +122,5 @@
     virtual Bool_t AsciiWrite(ostream &out) const;
 
-    Int_t Read(const char *name=NULL) { return TObject::Read(name?name:(const char*)fName); }
+    Int_t Read(const char *name=NULL);
 
     virtual void GetNames(TObjArray &arr) const;
Index: trunk/MagicSoft/Mars/mdata/MDataFormula.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataFormula.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mdata/MDataFormula.cc	(revision 6949)
@@ -108,8 +108,8 @@
         fMembers.AddLast(chain);
 
-        txt.ReplaceAll(arg, Form("[%d]", num++));
+        args.Remove(0, len+1);
         pos1 += len;
 
-        args.Remove(0, len+1);
+        txt.Replace(txt.Index(arg), len, Form("[%d]", num++));
     }
 
Index: trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mfbase/MFEventSelector2.cc	(revision 6949)
@@ -481,5 +481,5 @@
     {
         // how many events do we still want to read in this bin
-        fNom[bin] -= 1;
+        fNom[bin]--;
         rc = kTRUE;
 
@@ -491,5 +491,5 @@
 
     // how many events are still pending to be read
-    fIs[bin] -= 1;
+    fIs[bin]--;
 
     return rc;
@@ -530,5 +530,5 @@
       {
         fResult = kFALSE;
-        fCounter[1] += 1;
+        fCounter[1]++;
         return kTRUE;
       }
@@ -539,9 +539,9 @@
     if (!fResult)
     {
-      fCounter[2] += 1;
+      fCounter[2]++;
       return kTRUE;
     }
 
-    fCounter[0] += 1;
+    fCounter[0]++;
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 6949)
@@ -142,4 +142,7 @@
     // returns the number of file which were added
     //
+    if (!fRun)
+        return -1;
+
     Int_t n1 = fRun->AddFile(fname);
     Int_t n2 = MReadTree::AddFile(fname, entries);
@@ -231,4 +234,10 @@
 Int_t MReadMarsFile::PreProcess(MParList *pList)
 {
+    if (!fRun)
+    {
+        *fLog << err << "Error - Cannot use MReadMarsFile instantiated with default constructor... aborting." << endl;
+        return kFALSE;
+    }
+
     fParList = pList;
 
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 6949)
@@ -771,7 +771,7 @@
     // Rename first statistics box
     //
-    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
+    TPaveStats *s1 = dynamic_cast<TPaveStats*>(gPad->FindObject("stats"));
     if (!s1)
-        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
+        s1 = dynamic_cast<TPaveStats*>(hist1.GetListOfFunctions()->FindObject("stats"));
     else
         s1->SetName((TString)"Stat"+hist1.GetTitle());
@@ -793,7 +793,7 @@
     // Draw Legend
     //
-    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
+    TPaveStats *s2 = dynamic_cast<TPaveStats*>(gPad->FindObject("stats"));
     if (!s2)
-        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
+        s2 = dynamic_cast<TPaveStats*>(hist2.GetListOfFunctions()->FindObject("stats"));
 
     if (s2)
@@ -866,7 +866,7 @@
     //
     // Where to get the TPaveStats depends on the root version
-    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
+    TPaveStats *s1 = dynamic_cast<TPaveStats*>(gPad->FindObject("stats"));
     if (!s1)
-        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
+        s1 = dynamic_cast<TPaveStats*>(hist1.GetListOfFunctions()->FindObject("stats"));
     else
         s1->SetName((TString)"Stat"+hist1.GetTitle());
@@ -889,7 +889,7 @@
     //
     // Where to get the TPaveStats depends on the root version
-    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
+    TPaveStats *s2 = dynamic_cast<TPaveStats*>(gPad->FindObject("stats"));
     if (!s2)
-        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
+        s2 = dynamic_cast<TPaveStats*>(hist2.GetListOfFunctions()->FindObject("stats"));
 
     if (s2)
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 6949)
@@ -347,12 +347,12 @@
     {
         *fLog << "Result:" << endl;
-        *fLog << " - Significance           " << fSignificance << endl;
-        *fLog << " - Excess Events          " << fEventsExcess << endl;
-        *fLog << " - Signal Events          " << fEventsSignal << endl;
-        *fLog << " - Background Events      " << fEventsBackground << endl;
-        *fLog << " - Chi^2/ndf (Signal)     " << fChiSqSignal << endl;
-        *fLog << " - Chi^2/ndf (Background) " << fChiSqBg << endl;
-        *fLog << " - Signal integrated      " << fIntegralMax << "°" << endl;
-        *fLog << " - Scale Factor (Off)     " << fScaleFactor << endl;
+        *fLog << " - Significance (Li/Ma)    " << fSignificance << endl;
+        *fLog << " - Excess Events           " << fEventsExcess << endl;
+        *fLog << " - Signal Events           " << fEventsSignal << endl;
+        *fLog << " - Background Events       " << fEventsBackground << endl;
+        *fLog << " - Chi^2/ndf (Signal)      " << fChiSqSignal << endl;
+        *fLog << " - Chi^2/ndf (Background)  " << fChiSqBg << endl;
+        *fLog << " - Signal integrated up to " << fIntegralMax << "°" << endl;
+        *fLog << " - Scale Factor (Off)      " << fScaleFactor << endl;
     }
 }
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 6948)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 6949)
@@ -86,5 +86,5 @@
 
     void Clear(Option_t *o="");
-    void Print(Option_t *o="") const;
+    void Print(Option_t *o="") const; //*MENU*
     void Copy(TObject &o) const;
     /*
Index: trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 6949)
@@ -660,5 +660,5 @@
             {
                 TVirtualPad *p=gPad->GetPad(x+1)->GetPad(y+1);
-                if (!(st = (TPaveStats*)p->GetPrimitive("stats")))
+                if (!(st = dynamic_cast<TPaveStats*>(p->GetPrimitive("stats"))))
                     continue;
 
Index: trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 6949)
@@ -36,6 +36,8 @@
 
 #include <TLine.h>
-#include <TCanvas.h> 
+#include <TCanvas.h>
+#include <TStyle.h>
 #include <TProfile.h>
+#include <TPaveStats.h>
 
 #include "MString.h"
@@ -78,14 +80,14 @@
     fHResolution.SetDirectory(NULL);
     fHResolution.SetName("EnergyRes");
-    fHResolution.SetTitle("Histogram in \\frac{\\Delta lg(E)}{lg(E_{mc})} vs E_{est} and E_{mc}");
+    fHResolution.SetTitle("Histogram in \\Delta lg(E) vs E_{est} and E_{mc}");
     fHResolution.SetXTitle("E_{est} [GeV]");
     fHResolution.SetYTitle("E_{mc} [GeV]");
-    fHResolution.SetZTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
+    fHResolution.SetZTitle("lg(E_{est}) - lg(E_{mc})");
 
     fHImpact.SetDirectory(NULL);
     fHImpact.SetName("Impact");
-    fHImpact.SetTitle("\\frac{\\Delta lg(E)}{lg(E)} vs Impact parameter");
+    fHImpact.SetTitle("\\Delta lg(E) vs Impact parameter");
     fHImpact.SetXTitle("Impact parameter [m]");
-    fHImpact.SetYTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
+    fHImpact.SetYTitle("lg(E_{est}) - lg(E_{mc})");
 
     fHEnergy.Sumw2();
@@ -147,4 +149,5 @@
 
     fChisq = 0;
+    fBias  = 0;
     fHEnergy.Reset();
     fHImpact.Reset();
@@ -164,6 +167,6 @@
     const Double_t imp   = fMatrix ? GetVal(1) : fMcEvt->GetImpact()/100;
     const Double_t theta = fMatrix ? GetVal(2) : fMcEvt->GetTelescopeTheta()*TMath::RadToDeg();
-    const Double_t res   = (log10(eest)-log10(etru));///log10(etru);
-    const Double_t resE   = (eest-etru)/etru;
+    const Double_t res   = log10(eest)-log10(etru);///log10(etru);
+    const Double_t resE  = (eest-etru)/etru;
 
     fHEnergy.Fill(eest, etru, theta, w);
@@ -171,6 +174,14 @@
     fHImpact.Fill(imp, resE, w);
 
-    fChisq += res*res;
-    fBias  += res;
+    //if (etru>125 && etru<750)
+    //    return kCONTINUE;
+
+    // lg(N)  = 4.3*lg(E)-6
+    // lg(N0) = 4.3*2.2-6
+
+    const Double_t n  = 2; //pow(10, -4.3*(log10(etru)-2.2));
+
+    fChisq += log10(etru)<2.2? res*res*n/2:res*res;
+    fBias  += log10(etru)<2.2? res*sqrt(n/2):res;
 
     return kTRUE;
@@ -192,7 +203,18 @@
 void MHEnergyEst::Print(Option_t *o) const
 {
+    const Double_t res  =   TMath::Sqrt(fChisq-fBias*fBias);
+    const Double_t resp =   TMath::Power(10,  res)-1;
+    const Double_t resm = 1-TMath::Power(10, -res);
+
+    if (TMath::IsNaN(res))
+    {
+        *fLog << all << "MHEnergyEst::Print: ERROR - Resolution is NaN (not a number)." << endl;
+        return;
+    }
+
     *fLog << all;
-    *fLog << "Mean log10(Energy) Resoltion: " << Form("%5.2f%%", TMath::Sqrt(fChisq-fBias*fBias)) << endl;
-    *fLog << "Mean log10(Energy) Bias:      " << Form("%5.2f%%", fBias) << endl;
+    *fLog << "Mean log10(Energy) Resoltion: +/- " << Form("%4.2f", res) << endl;
+    *fLog << "Mean log10(Energy) Bias:         "  << Form("%+4.2f", fBias) << endl;
+    *fLog << "Asymmetric Energy  Resoltion:   +"  << Form("%4.1f%%", resp*100) << " -" << Form("%4.1f%%", resm*100) << endl;
 }
 
@@ -246,6 +268,16 @@
 
             pad->GetPad(1)->GetPad(2)->cd(2);
-            /*=*/fHResolution.ProjectionZ("Resolution");
-            ///*h =*/ fHImpact.ProjectionX("Impact", -1, 9999, "e");
+            hx = (TH1D*)fHResolution.ProjectionZ("Resolution");
+            TPaveStats *stats = dynamic_cast<TPaveStats*>(hx->FindObject("stats"));
+            if (stats)
+            {
+                stats->SetBit(BIT(17)); // TStyle.cxx: kTakeStyle=BIT(17)
+                stats->SetX1NDC(0.63);
+                stats->SetY1NDC(0.68);
+            }
+
+            hx->Fit("gaus", "Q");
+            gPad=NULL;
+            gStyle->SetOptFit(101);
         }
     }
@@ -325,5 +357,5 @@
 //    h1->Draw("Chistsame");
 
-    return h1;
+    return h2;
 }
 
@@ -415,9 +447,10 @@
     //h->SetXTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
     h->SetYTitle("Counts");
-    h->SetTitle("Distribution of \\Delta lg(E) / lg(E_{mc})");
+    h->SetTitle("Distribution of \\Delta lg(E)");
     h->SetDirectory(NULL);
     h->SetBit(kCanDelete);
     h->GetXaxis()->SetRangeUser(-1.3, 1.3);
     h->Draw("");
+    //h->Fit("gaus");
     // ----------------------------------------
 
@@ -440,6 +473,6 @@
     h = MakePlot(fHResolution, "zy");
     h->SetXTitle("E_{mc} [GeV]");
-    h->SetYTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
-    h->SetTitle("Energy resolution \\Delta lg(E) / lg(E) vs Monte Carlo energy E_{mc}");
+    h->SetYTitle("lg(E_{est}) - lg(E_{mc})");
+    h->SetTitle("Energy resolution \\Delta lg(E) vs Monte Carlo energy E_{mc}");
     h->SetMinimum(-1.3);
     h->SetMaximum(1.3);
@@ -448,6 +481,6 @@
     h = MakePlot(fHResolution, "zx");
     h->SetXTitle("E_{est} [GeV]");
-    h->SetYTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
-    h->SetTitle("Energy Resolution \\Delta lg(E) / lg(E) vs estimated Energy E_{est}");
+    h->SetYTitle("lg(E_{est}) - lg(E_{mc})");
+    h->SetTitle("Energy Resolution \\Delta lg(E) vs estimated Energy E_{est}");
     h->SetMinimum(-1.3);
     h->SetMaximum(1.3);
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 6949)
@@ -726,33 +726,31 @@
     tlist2.AddToList(&pedlo3);
     //-----------------------------------------------------------
+
+    MTaskList tlist3;
+    tlist3.SetFilter(&fcalib);
+
+    MContinue contcal;
     if (fIsInterlaced)
     {
-	pinext.SetFilter(&fcalib);
-	bldext.SetFilter(&fcalib);
-	taskenv3.SetFilter(&fcalib);
-	pacalc.SetFilter(&fcalib);
-	filcam.SetFilter(&fcalib);
-        filtme.SetFilter(&fcalib);
-        filbnd.SetFilter(&fcalib);
-        filpin.SetFilter(&fcalib);
-	chcalc.SetFilter(&fcalib);
-	recalc.SetFilter(&fcalib);
-
         tlist2.AddToList(&fcalib);
-        tlist2.AddToList(&pinext);
-        tlist2.AddToList(&bldext);
-	tlist2.AddToList(&taskenv3);
-        tlist2.AddToList(&pacalc);
-        tlist2.AddToList(&filcam);
+        tlist2.AddToList(&tlist3);
+
+        tlist3.AddToList(&pinext);
+        tlist3.AddToList(&bldext);
+	tlist3.AddToList(&taskenv3);
+        tlist3.AddToList(&pacalc);
+        tlist3.AddToList(&filcam);
 	if (fIsRelTimesUpdate)
-	  tlist2.AddToList(&filtme);
+	  tlist3.AddToList(&filtme);
         if (IsUseBlindPixel())
-            tlist2.AddToList(&filbnd);
+            tlist3.AddToList(&filbnd);
         if (IsUsePINDiode())
-            tlist2.AddToList(&filpin);
-        tlist2.AddToList(&chcalc);
+            tlist3.AddToList(&filpin);
+        tlist3.AddToList(&chcalc);
 	if (fIsRelTimesUpdate)
-	  tlist2.AddToList(&recalc);
-    }
+            tlist3.AddToList(&recalc);
+        tlist3.AddToList(&fill8);
+        tlist3.AddToList(&contcal);
+    }  
 
     tlist2.AddToList(&conttp);
@@ -772,6 +770,4 @@
     if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
         tlist2.AddToList(&caltm);
-    if (fIsInterlaced)
-      tlist2.AddToList(&fill8);
     tlist2.AddToList(&bpcal);
     tlist2.AddToList(&treat);
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 6949)
@@ -45,4 +45,5 @@
 
 #include "MReadReports.h"
+#include "MReadMarsFile.h"
 #include "MPrint.h"
 #include "MContinue.h"
@@ -74,5 +75,5 @@
 MJCut::MJCut(const char *name, const char *title)
     : fStoreSummary(kFALSE), fStoreResult(kFALSE), fWriteOnly(kFALSE),
-    fIsWobble(kFALSE), fFullDisplay(kFALSE), /*fSubstraction(kFALSE),*/
+    fIsWobble(kFALSE), fIsMonteCarlo(kFALSE),  fFullDisplay(kFALSE), /*fSubstraction(kFALSE),*/
     fEstimateEnergy(0), fCalcHadronness(0)
 {
@@ -181,5 +182,5 @@
         return kFALSE;
     }
-    env1 = o ? (MTask*)o->Clone() : NULL;
+    env1 = o ? (MTask*)o->Clone() : FNULL;
 
     o = file.Get("CalcHadronness");
@@ -212,6 +213,15 @@
     *fLog << inf << "Writing to file: " << oname << endl;
 
-    TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCut", 9);
-    if (!file.IsOpen())
+    TFile *file = 0;
+    if (fNameResult.IsNull())
+    {
+        file = (TFile*)gROOT->GetListOfFiles()->FindObject(oname);
+        if (file)
+            file->cd();
+    }
+    else
+        file = TFile::Open(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCut", 9);
+
+    if (!file)
     {
         *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
@@ -219,5 +229,10 @@
     }
 
-    return WriteContainer(cont);
+    const Bool_t rc = WriteContainer(cont);
+
+    if (!fNameResult.IsNull())
+        delete file;
+
+    return rc;
 }
 
@@ -260,4 +275,5 @@
     EnableStorageOfResult(GetEnv("ResultFile", fStoreResult));
     EnableWobbleMode(GetEnv("WobbleMode", fIsWobble));
+    EnableMonteCarloMode(GetEnv("MonteCarlo", fIsMonteCarlo));
     EnableFullDisplay(GetEnv("FullDisplay", fFullDisplay));
     //EnableSubstraction(GetEnv("HistogramSubstraction", fSubstraction));
@@ -292,4 +308,5 @@
     write->AddContainer("MHadronness",    "Events", kFALSE);
     write->AddContainer("MEnergyEst",     "Events", kFALSE);
+    write->AddContainer("MMcEvt",         "Events", kFALSE);
     write->AddContainer("DataType",       "Events");
 
@@ -398,8 +415,13 @@
 
     // ------------- Loop Off Data --------------------
-    MReadReports readoff;
-    readoff.AddTree("Events", "MTime.", kTRUE);
-    readoff.AddTree("Drive");
-    readoff.AddTree("EffectiveOnTime");
+    MReadReports readoffdata;
+    readoffdata.AddTree("Events", "MTime.", kTRUE);
+    readoffdata.AddTree("Drive");
+    readoffdata.AddTree("EffectiveOnTime");
+
+    MReadMarsFile readoffmc("Events");
+    readoffmc.DisableAutoScheme();
+
+    MRead &readoff = fIsMonteCarlo ? (MRead&)readoffmc : (MRead&)readoffdata;
     if (fIsWobble)
         set.AddFilesOn(readoff);
@@ -411,5 +433,5 @@
     TString fname1(path);
     fname0 += fNameSummary.IsNull() ?  (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
-    fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d-result.root",  set.GetNumAnalysis()) : fNameResult;
+    fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult;
 
     MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
@@ -443,4 +465,5 @@
 
     MPrint print2("MEffectiveOnTime");
+    print2.EnableSkip();
 
     // How to get source position from off- and on-data?
@@ -460,5 +483,4 @@
     if (fIsWobble)
         tlist2.AddToList(&hcalc2);
-    tlist2.AddToList(&taskenv1);
     tlist2.AddToList(&taskenv2);
     tlist2.AddToList(&cont0);
@@ -468,4 +490,5 @@
         tlist2.AddToList(&fill1a);
     tlist2.AddToList(&cont1);
+    tlist2.AddToList(&taskenv1);
     if (!fWriteOnly && !fIsWobble)
         tlist2.AddToList(&ffs);
@@ -503,4 +526,18 @@
         return kFALSE;
 
+    TObjArray cont;
+    cont.Add(&fit);
+    cont.Add(&cont0);
+    cont.Add(&cont1);
+    cont.Add(&cont2);
+    cont.Add(&cont3);
+    if (taskenv1.GetTask())
+        cont.Add(taskenv1.GetTask());
+    if (taskenv2.GetTask())
+        cont.Add(taskenv2.GetTask());
+
+    if (!WriteTasks(set.GetNumAnalysis(), cont))
+        return kFALSE;
+
     if (set.HasOffSequences() || fIsWobble)
     {
@@ -524,8 +561,13 @@
 
     // ------------- Loop On Data --------------------
-    MReadReports readon;
-    readon.AddTree("Events", "MTime.", kTRUE);
-    readon.AddTree("Drive");
-    readon.AddTree("EffectiveOnTime");
+    MReadReports readondata;
+    readondata.AddTree("Events", "MTime.", kTRUE);
+    readondata.AddTree("Drive");
+    readondata.AddTree("EffectiveOnTime");
+
+    MReadMarsFile readonmc("Events");
+    readonmc.DisableAutoScheme();
+
+    MRead &readon = fIsMonteCarlo ? (MRead&)readonmc : (MRead&)readondata;
     set.AddFilesOn(readon);
 
@@ -614,21 +656,9 @@
             tlist2.Replace(&ffs2);
 
-        tlist.AddToList(&fillvs, "EffectiveOnTime");
+        if (!fIsMonteCarlo)
+            tlist.AddToList(&fillvs, "EffectiveOnTime");
     }
 
     par.SetVal(1);
-
-    TObjArray cont;
-    cont.Add(&cont0);
-    cont.Add(&cont1);
-    cont.Add(&cont2);
-    cont.Add(&cont3);
-    if (taskenv1.GetTask())
-        cont.Add(taskenv1.GetTask());
-    if (taskenv2.GetTask())
-        cont.Add(taskenv2.GetTask());
-
-    if (!WriteTasks(set.GetNumAnalysis(), cont))
-        return kFALSE;
 
     // Execute first analysis
Index: trunk/MagicSoft/Mars/mjobs/MJCut.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.h	(revision 6948)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.h	(revision 6949)
@@ -18,4 +18,5 @@
     Bool_t  fWriteOnly;
     Bool_t  fIsWobble;
+    Bool_t  fIsMonteCarlo;
     Bool_t  fFullDisplay;
     //Bool_t  fSubstraction;
@@ -48,4 +49,5 @@
     void EnableWriteOnly(Bool_t b=kTRUE)         { fWriteOnly    = b; }
     void EnableWobbleMode(Bool_t b=kTRUE)        { fIsWobble     = b; }
+    void EnableMonteCarloMode(Bool_t b=kTRUE)    { fIsMonteCarlo = b; }
     void EnableFullDisplay(Bool_t b=kTRUE)       { fFullDisplay  = b; }
     //void EnableSubstraction(Bool_t b=kTRUE)      { fSubstraction = b; }
Index: trunk/MagicSoft/Mars/mjobs/MJOptimize.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/mjobs/MJOptimize.cc	(revision 6949)
@@ -94,4 +94,5 @@
 #include "MGeomCamCT1.h"
 #include "MFEventSelector.h"
+#include "MFDataMember.h"
 #include "MReadTree.h"
 #include "MHMatrix.h"
@@ -111,5 +112,5 @@
 #include "MContinue.h"
 #include "MGeomCamMagic.h"
-#include "../mimage/MHillasSrcCalc.h"
+#include "MHillasSrcCalc.h"
 #include "MHMatrix.h"
 #include "MMatrixLoop.h"
@@ -118,5 +119,5 @@
 #include "../mhflux/MHEnergyEst.h"
 #include "MDirIter.h"
-#include "../mjobs/MSequence.h"
+#include "MSequence.h"
 
 using namespace std;
@@ -999,4 +1000,11 @@
     MParList parlist;
 
+    MParameterI par("DataType");
+    par.SetVal(1);
+    parlist.AddToList(&par);
+
+    MFDataMember filter("DataType.fVal", '>', 0.5);
+    fPreCuts.Add(&filter);
+
     MGeomCamMagic geom; // For GetConvMm2Deg
     parlist.AddToList(&geom);
@@ -1023,4 +1031,6 @@
         return kFALSE;
 
+    fPreCuts.Remove(&filter);
+
     MTaskList tasklist;
     parlist.Replace(&tasklist);
Index: trunk/MagicSoft/Mars/showlog.cc
===================================================================
--- trunk/MagicSoft/Mars/showlog.cc	(revision 6948)
+++ trunk/MagicSoft/Mars/showlog.cc	(revision 6949)
@@ -99,5 +99,56 @@
         else
             s.ReplaceAll("", "\033");
-        gLog << s << endl;
+
+        // Check whether it is an empty line
+        if (s=="\033[0m")
+        {
+            gLog << endl;
+            continue;
+        }
+
+        while (!s.IsNull())
+        {
+            Ssiz_t pos = s.First("\033[");
+            if (pos<0)
+            {
+                gLog << s;
+                break;
+            }
+
+            gLog << s(0, pos);
+            s.Remove(0, pos+1);
+            if (s.BeginsWith("0m") && s.Length()>3)
+            {
+                gLog << all;
+                s.Remove(0, 2);
+                continue;
+            }
+            if (s.BeginsWith("31m"))
+            {
+                gLog << err;
+                s.Remove(0, 3);
+                continue;
+            }
+            if (s.BeginsWith("32m"))
+            {
+                gLog << inf;
+                s.Remove(0, 3);
+                continue;
+            }
+            if (s.BeginsWith("33m"))
+            {
+                gLog << warn;
+                s.Remove(0, 3);
+                continue;
+            }
+            if (s.BeginsWith("34m"))
+            {
+                gLog << dbg;
+                s.Remove(0, 3);
+                continue;
+            }
+            gLog << "\033[";
+        }
+        gLog << endl;
     }
 
@@ -105,4 +156,4 @@
         delete in;
 
-    return 0;
+    return 1;
 }
