Index: trunk/MagicSoft/Mars/mjobs/MJSimulation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9336)
+++ trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9343)
@@ -209,4 +209,18 @@
 }
 
+void MJSimulation::SetupCommonFileStructure(MWriteRootFile &write) const
+{
+    // Common run headers
+    write.AddContainer("MCorsikaRunHeader",   "RunHeaders", kFALSE);
+    write.AddContainer("MRawRunHeader",       "RunHeaders");
+    write.AddContainer("MGeomCam",            "RunHeaders");
+    write.AddContainer("MMcRunHeader",        "RunHeaders");
+
+    // Common events
+    write.AddContainer("MCorsikaEvtHeader",   "Events", kFALSE);
+    write.AddContainer("MRawEvtHeader",       "Events");
+    write.AddContainer("MMcEvt",              "Events");
+}
+
 Bool_t MJSimulation::Process(const MArgs &args)
 {
@@ -429,43 +443,23 @@
     write3b.SetName("WriteCamMC");
 
-    write1a.AddContainer("MCorsikaEvtHeader", "Events", kFALSE);
-    write1a.AddContainer("MPhotonEvent",      "Events");
-
-    write2a.AddContainer("MCorsikaRunHeader", "RunHeaders", kFALSE);
-    write2a.AddContainer("MRawRunHeader",     "RunHeaders");
-    write2a.AddContainer("MGeomCam",          "RunHeaders");
-    write2a.AddContainer("MSignalCam",        "Events");
-    write2a.AddContainer("MRawEvtHeader",     "Events",    kFALSE);
+    SetupCommonFileStructure(write1a);
+    SetupCommonFileStructure(write2a);
+    SetupCommonFileStructure(write3a);
+
+    // R: Dedicated file structureedicated events
+    write1a.AddContainer("MPhotonEvent", "Events");
+
+    // I: Dedicated file structureedicated events
     write2a.AddContainer("MPedPhotFromExtractorRndm", "RunHeaders"); // FIXME: Needed for the signal files to be display in MARS
-    write2a.AddContainer("MMcRunHeader",       "RunHeaders");
-    /* Monte Carlo Headers
-    write.AddContainer("MMcRunHeader",              "RunHeaders", kFALSE);
-    write.AddContainer("MMcFadcHeader",             "RunHeaders", kFALSE);
-    write.AddContainer("MMcTrigHeader",             "RunHeaders", kFALSE);
-    write.AddContainer("MMcConfigRunHeader",        "RunHeaders", kFALSE);
-    write.AddContainer("MMcCorsikaRunHeader",       "RunHeaders", kFALSE);
-    // Monte Carlo
-    write.AddContainer("MMcEvt",                    "Events",     kFALSE);
-    write.AddContainer("MMcTrig",                   "Events",     kFALSE);
-    */// Data tree
-    //write.AddContainer("MPedPhotFromExtractor",     "Events");
-    //write.AddContainer("MPedPhotFromExtractorRndm", "Events");
-    //write.AddContainer("MTime",                     "Events",     kFALSE);
-    //write.AddContainer("MRawEvtHeader",             "Events");
-    //write.AddContainer("MTriggerPattern",           "Events");
-
-    write3a.AddContainer("MRawEvtData",         "Events");
-    write3a.AddContainer("MRawRunHeader",       "RunHeaders");
-    write3a.AddContainer("MGeomCam",            "RunHeaders");
-    write3a.AddContainer("MRawEvtHeader",       "Events",     kFALSE);
-    //write3.AddContainer("MPedestalCam",  "RunHeaders", kFALSE);
-    write3a.AddContainer("MMcRunHeader",        "RunHeaders");
-    write3a.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
-    write3a.AddContainer("ElectronicNoise",     "RunHeaders", kFALSE);
-    write3a.AddContainer("MMcEvt",              "Events",     kFALSE);
-
-    write1b.AddContainer("MMcEvtBasic",         "OriginalMC");
-    write2b.AddContainer("MMcEvtBasic",         "OriginalMC");
-    write3b.AddContainer("MMcEvtBasic",         "OriginalMC");
+    write2a.AddContainer("MSignalCam", "Events");
+
+    // D: Dedicated file structureedicated events
+    write3a.AddContainer("ElectronicNoise", "RunHeaders");
+    write3a.AddContainer("MRawEvtData", "Events");
+
+    // Basic MC data
+    write1b.AddContainer("MMcEvtBasic", "OriginalMC");
+    write2b.AddContainer("MMcEvtBasic", "OriginalMC");
+    write3b.AddContainer("MMcEvtBasic", "OriginalMC");
 
     // -------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mjobs/MJSimulation.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSimulation.h	(revision 9336)
+++ trunk/MagicSoft/Mars/mjobs/MJSimulation.h	(revision 9343)
@@ -9,4 +9,5 @@
 class MArgs;
 class MParList;
+class MWriteRootFile;
 
 class MJSimulation : public MJob
@@ -22,4 +23,5 @@
 
     void SetupHist(MHn &hist) const;
+    void SetupCommonFileStructure(MWriteRootFile &write) const;
 
 public:
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 9336)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 9343)
@@ -64,9 +64,10 @@
 
 // Spectrum
-#include "../mhflux/MAlphaFitter.h"
-#include "../mhflux/MHAlpha.h"
-#include "../mhflux/MHCollectionArea.h"
-#include "../mhflux/MHEnergyEst.h"
-#include "../mhflux/MMcSpectrumWeight.h"
+#include "MAlphaFitter.h"
+#include "MHAlpha.h"
+#include "MHCollectionArea.h"
+#include "MHEnergyEst.h"
+#include "MMcSpectrumWeight.h"
+#include "MHEffectiveOnTime.h"
 
 // Eventloop
@@ -91,5 +92,6 @@
 MJSpectrum::MJSpectrum(const char *name, const char *title)
     : fCutQ(0), fCut0(0),fCut1(0), fCut2(0), fCut3(0), fCutS(0),
-    fEstimateEnergy(0), fCalcHadronness(0),  fCalcDisp(0), fForceTheta(kFALSE)
+    fEstimateEnergy(0), fCalcHadronness(0),  fCalcDisp(0),
+    fForceTheta(kFALSE), fForceRunTime(kFALSE), fForceOnTimeFit(kFALSE)
 {
     fName  = name  ? name  : "MJSpectrum";
@@ -296,4 +298,8 @@
         return -1;
 
+    // We don't have to proceed. We later overwrite the result anyway
+    if (fForceOnTimeFit)
+        return 0;
+
     const Double_t ufl = vstime->GetBinContent(0);
     const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()+1);
@@ -750,4 +756,9 @@
     MFillH fill2(Form("HistE    [%s]", cls.Data()), "", "FillHistE");
 
+    // Fill a new MHEffectiveOnTime. It can either be used to
+    // re-calculate the on-time or just for manual cross check
+    MFillH fillT("MHEffectiveOnTime", "MTime", "FillOnTime");
+    fillT.SetNameTab("OnTime");
+
     MFDataMember f0("DataType.fVal", '<', 0.5, "FilterOffData");
     MFDataMember f1("DataType.fVal", '>', 0.5, "FilterOnData");
@@ -755,12 +766,14 @@
     fill1.SetFilter(&f0);
     fill2.SetFilter(&f1);
+    fillT.SetFilter(&f1);
 
     tlist.AddToList(&read);
     //tlist.AddToList(&taskenv0); // not necessary, stored in file!
     //tlist.AddToList(&taskenv1); // not necessary, stored in file!
+    tlist.AddToList(&f1);
+    tlist.AddToList(&fillT);
     tlist.AddToList(fCutS);
     tlist.AddToList(&taskenv2);
     tlist.AddToList(&f0);
-    tlist.AddToList(&f1);
     tlist.AddToList(&fill1);
     tlist.AddToList(&fill2);
@@ -1545,5 +1558,5 @@
     // Read from the ganymed file
     TH1D htheta, size;
-    const Float_t ontime = ReadInput(plist, htheta, size);
+    Float_t ontime = ReadInput(plist, htheta, size);
     if (ontime<0)
     {
@@ -1562,4 +1575,55 @@
     }
     plist.AddToList(&bins2); // For later use in MC processing
+
+    // -------------- Fill excess events versus energy ---------------
+
+    TH1D excess;
+
+    if (fForceOnTimeFit)
+    {
+        // Refill excess histogram to determine the excess events
+        // If we use the eff. on-time fit we have to loop over the data first
+        // This is not really desired, because if something is wrong with
+        // the Monte Carlos the program runs quite long before it fails
+        if (!Refill(plist, excess))
+            return kFALSE;
+
+        // Print the setup and result of the MAlphaFitter, print used cuts
+        PrintSetup(fit);
+
+        // ------------ On user request redo eff. on-time fit ------------
+        const MHEffectiveOnTime *htime = (MHEffectiveOnTime*)plist.FindObject("MHEffectiveOnTime");
+        if (!htime)
+        {
+            // This should never happen, bt you never know
+            *fLog << err;
+            *fLog << "ERROR - Use of new effective on-time fit requested for on-time determination," << endl;
+            *fLog << "        but MHEffectiveOnTime not found in parameter list... aborting." << endl;
+            return kFALSE;
+        }
+
+        const TH1D &h = htime->GetHEffOnTheta();
+        /*
+        if (!htime->IsConsistent() || h.GetNbinsX()!=htheta.GetNbinsX())
+        {
+            *fLog << err << "ERROR - Effective on-time from newly filles MHEffectiveOnTime (Tab='OnTime) invalid... aborting." << endl;
+            return kFALSE;
+        }*/
+
+        *fLog << inf;
+        *fLog << "Using eff. on-time from new MHEffectiveOnTime (see also 'OnTime')" << endl;
+        *fLog << "   Orig. value: " << ontime << "s" << endl;
+
+        // Copy ontime from newly filled and fitted eff on-time histogram
+        ontime = htime->GetEffOnTime();
+
+        *fLog << "   New   value: " << ontime << "s" << endl;
+
+        h.Copy(htheta);           // Copy contents of newly filled hist into on-time vs. theta
+        htheta.SetName("Theta");  // Copy overwrites the name needed in DisplayResult
+        htheta.SetDirectory(0);   // Remove from global directory added by SetName
+    }
+
+    // ---------------------------------------------------------------
 
     // Initialize weighting to a new spectrum as defined in the resource file
@@ -1612,14 +1676,13 @@
         return kFALSE;
 
-    // -------------- Fill excess events versus energy ---------------
-
     // Refill excess histogram to determine the excess events
-    TH1D excess;
-    if (!Refill(plist, excess))
-        return kFALSE;
-
-    // Print the setup and result of the MAlphaFitter, print used cuts
-    PrintSetup(fit);
-
+    if (!fForceOnTimeFit)
+    {
+        if (!Refill(plist, excess))
+            return kFALSE;
+
+        // Print the setup and result of the MAlphaFitter, print used cuts
+        PrintSetup(fit);
+    }
 
     // ------------------------- Final loop --------------------------
@@ -1768,5 +1831,4 @@
     fillsp.SetWeight();
 
-    // Try to find the class used to determine the signal!
     // FIXME: To be done: A task checking the lower 1% after the lower
     // energy limit!
@@ -1789,4 +1851,9 @@
         return kFALSE;
     par->SetVal(2);
+
+    // Not really necessary but for sanity
+    TObject *cam = plist.FindObject("MSrcPosCam");
+    if (cam)
+        cam->Clear();
 
     tlist2.AddToList(&read);
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 9336)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 9343)
@@ -38,4 +38,5 @@
     Bool_t fForceTheta;
     Bool_t fForceRunTime;
+    Bool_t fForceOnTimeFit;
 
     // Setup Histograms
@@ -76,4 +77,5 @@
     void ForceTheta(Bool_t b=kTRUE)   { fForceTheta=b; }
     void ForceRunTime(Bool_t b=kTRUE) { fForceRunTime=b; }
+    void ForceOnTimeFit(Bool_t b=kTRUE) { fForceOnTimeFit=b; }
 
     void SetEnergyEstimator(const MTask *task);
Index: trunk/MagicSoft/Mars/mjobs/MJStar.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 9336)
+++ trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 9343)
@@ -334,4 +334,5 @@
         write.AddContainer("MMcEvt",                "Events");
         write.AddContainer("MMcTrig",               "Events", kFALSE);
+        write.AddContainer("MSrcPosCam",            "Events");
         // Monte Carlo Run Headers
         write.AddContainer("MMcRunHeader",          "RunHeaders");
