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);
