Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2743)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2744)
@@ -20,4 +20,29 @@
    * mfilter/MFEventSelector2.[h,cc]:
      - added some comments
+
+   * macros/dohtml.C, macros/rootlogon.C:
+     - added mcalib
+     - added mhbase
+     
+   * macros/estfit.C:
+     - get chisq from MParameterD
+     
+   * manalysis/MEventRateCalc.cc:
+     - added comments
+     
+   * mbase/MParContainer.h:
+     - added a comment
+     
+   * mhist/MHCamera.h:
+     - added default argument for DrawClone
+     
+   * mmontecarlo/MMcEnergyEst.cc:
+     - use an MParameterD instead of accessing MChisqEval
+     
+   * mtools/MChisqEval.[h,cc]:
+     - write result to an MParameterD
+
+   * mtools/MTFillMatrix.[h,cc]:
+     - some more features
 
 
Index: trunk/MagicSoft/Mars/macros/dohtml.C
===================================================================
--- trunk/MagicSoft/Mars/macros/dohtml.C	(revision 2743)
+++ trunk/MagicSoft/Mars/macros/dohtml.C	(revision 2744)
@@ -38,4 +38,5 @@
     sourcedir += "manalysis:";
     sourcedir += "mbase:";
+    sourcedir += "mcalib:";
     sourcedir += "mdata:";
     sourcedir += "mfileio:";
@@ -43,4 +44,5 @@
     sourcedir += "mgeom:";
     sourcedir += "mgui:";
+    sourcedir += "mhbase:";
     sourcedir += "mhist:";
     sourcedir += "mhistmc:";
Index: trunk/MagicSoft/Mars/macros/estfit.C
===================================================================
--- trunk/MagicSoft/Mars/macros/estfit.C	(revision 2743)
+++ trunk/MagicSoft/Mars/macros/estfit.C	(revision 2744)
@@ -10,4 +10,5 @@
 #include "MChisqEval.h"
 #include "MMatrixLoop.h"
+#include "MParameterD.h"
 #include "MDataMember.h"
 #include "MDataElement.h"
@@ -20,7 +21,8 @@
     MEvtLoop *evtloop = (MEvtLoop*)gMinuit->GetObjectFit();
 
-    MTaskList *tlist  = (MTaskList*)evtloop->GetParList()->FindObject("MTaskList"); //GetTaskList();
-
-    MChisqEval      *eval = (MChisqEval*)     tlist->FindObject("MChisqEval");
+    MParList  *plist  = evtloop->GetParList();
+    MTaskList *tlist  = evtloop->GetTaskList();
+
+    MChisqEval      *eval = (MChisqEval*)     plist->FindObject("MFitResult", "MParameterD");
     MEnergyEstParam *eest = (MEnergyEstParam*)tlist->FindObject("MEnergyEstParam");
 
@@ -29,5 +31,5 @@
     evtloop->Eventloop();
 
-    f = eval->GetChisq();
+    f = eval->GetVal();
 }
 
Index: trunk/MagicSoft/Mars/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 2743)
+++ trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 2744)
@@ -100,4 +100,5 @@
     gInterpreter->AddIncludePath(dir+"manalysis");
     gInterpreter->AddIncludePath(dir+"mbase");
+    gInterpreter->AddIncludePath(dir+"mcalib");
     gInterpreter->AddIncludePath(dir+"mdata");
     gInterpreter->AddIncludePath(dir+"mfileio");
@@ -105,4 +106,5 @@
     gInterpreter->AddIncludePath(dir+"mgeom");
     gInterpreter->AddIncludePath(dir+"mgui");
+    gInterpreter->AddIncludePath(dir+"mhbase");
     gInterpreter->AddIncludePath(dir+"mhist");
     gInterpreter->AddIncludePath(dir+"mhistmc");
Index: trunk/MagicSoft/Mars/manalysis/MEventRateCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MEventRateCalc.cc	(revision 2743)
+++ trunk/MagicSoft/Mars/manalysis/MEventRateCalc.cc	(revision 2744)
@@ -29,6 +29,5 @@
 //  This task calculates the event rates from the event times and numbers.
 //
-//  It is under construction: More information comming soon....
-//
+//  The algorithm is explained in Process()
 //
 //  Input Containers:
@@ -38,4 +37,9 @@
 //    MEventRate
 //    MTimeRate [MTime] (missing)
+//
+//  FIXME: For convinience we could implement a mode which always takes
+//         n events to calculate the event rate and sets the corresponding
+//         time. This mode could be used to UPADTE files with the event
+//         rate.
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -68,5 +72,10 @@
 //
 // The PreProcess searches for the following input containers:
-//  ...
+//   MTime
+//
+// The PreProcess searches for the following input containers:
+//   MEventRate
+//
+// Reset all times in the buffer
 //
 Int_t MEventRateCalc::PreProcess(MParList *pList)
@@ -90,4 +99,7 @@
 // --------------------------------------------------------------------------
 //
+// Calculate the events rate as (t1-t0)/n while t1 is the n-th event after
+// t0. If there are not yet enough events in the buffer n is the number
+// of available events. Otherwise the number setup in SetNumEvents.
 //
 Int_t MEventRateCalc::Process()
@@ -109,6 +121,4 @@
     fRate->SetReadyToSave();
 
-    // *fLog << inf << "   ---   Event Rate [Hz]: " << rate << "  (" << cnt << ")" << endl;
-
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 2743)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 2744)
@@ -52,4 +52,5 @@
     Bool_t  fReadyToSave; // should be set to true if the contents of the container is changed somehow
 
+    // FIXME: Change to ostream!
     virtual void StreamPrimitive(ofstream &out) const;
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2743)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 2744)
@@ -159,5 +159,5 @@
     void     Paint(Option_t *option="");
     void     Draw(Option_t *option="");
-    TObject *DrawClone(Option_t *option) const;
+    TObject *DrawClone(Option_t *option="") const;
     void     SavePrimitive(ofstream &out, Option_t *);
     Int_t    DistancetoPrimitive(Int_t px, Int_t py);
Index: trunk/MagicSoft/Mars/mmontecarlo/MMcEnergyEst.cc
===================================================================
--- trunk/MagicSoft/Mars/mmontecarlo/MMcEnergyEst.cc	(revision 2743)
+++ trunk/MagicSoft/Mars/mmontecarlo/MMcEnergyEst.cc	(revision 2744)
@@ -60,4 +60,5 @@
 #include "MLog.h"
 #include "MLogManip.h"
+#include "MParameters.h"
 
 ClassImp(MMcEnergyEst);
@@ -71,16 +72,17 @@
 static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
 {
-  MEvtLoop *evtloop = (MEvtLoop*)gMinuit->GetObjectFit();
- 
-  MTaskList *tlist  = (MTaskList*)evtloop->GetParList()->FindObject("MTaskList"); // GetTaskList();
-
-  MChisqEval      *eval = (MChisqEval*)     tlist->FindObject("MChisqEval");
-  MEnergyEstParam *eest = (MEnergyEstParam*)tlist->FindObject("MEnergyEstParam");
-
-  eest->SetCoeff(TArrayD(eest->GetNumCoeff(), par));
-
-  evtloop->Eventloop();
-
-  f = eval->GetChisq();
+    MEvtLoop *evtloop = (MEvtLoop*)gMinuit->GetObjectFit();
+
+    MParList  *plist  = evtloop->GetParList();
+    MTaskList *tlist  = evtloop->GetTaskList();
+
+    MParameterD     *eval = (MParameterD*)    plist->FindObject("MFitResult", "MParameterD");
+    MEnergyEstParam *eest = (MEnergyEstParam*)tlist->FindObject("MEnergyEstParam");
+
+    eest->SetCoeff(TArrayD(eest->GetNumCoeff(), par));
+
+    evtloop->Eventloop();
+
+    f = eval->GetVal();
 }
 
@@ -340,4 +342,2 @@
 
 }
-
-
Index: trunk/MagicSoft/Mars/mtools/MChisqEval.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MChisqEval.cc	(revision 2743)
+++ trunk/MagicSoft/Mars/mtools/MChisqEval.cc	(revision 2744)
@@ -32,4 +32,7 @@
 
 #include "MDataChain.h"
+#include "MParameters.h" // MParameterD
+
+#include "MParList.h"
 
 ClassImp(MChisqEval);
@@ -120,4 +123,8 @@
             return kFALSE;
 
+    fResult = (MParameterD*)plist->FindCreateObj("MParameterD", "MFitResult");
+    if (!fResult)
+        return kFALSE;
+
     return kTRUE;
 }
@@ -138,4 +145,7 @@
 {
     fChisq /= GetNumExecutions();
+
+    fResult->SetVal(fChisq);
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mtools/MChisqEval.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MChisqEval.h	(revision 2743)
+++ trunk/MagicSoft/Mars/mtools/MChisqEval.h	(revision 2744)
@@ -7,4 +7,5 @@
 
 class MData;
+class MParameterD;
 
 class MChisqEval : public MTask
@@ -14,5 +15,6 @@
     static const TString gsDefTitle;
 
-    Double_t fChisq; //! Evaluated chi square
+    Double_t     fChisq;  //! Evaluated chi square
+    MParameterD *fResult; //! Storage for result
 
     MData   *fData0; // Data Member one (monte carlo data or chisq function)
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 2743)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 2744)
@@ -35,4 +35,7 @@
 // reference histogram.
 //
+// If no reference histogram is available the number of events are
+// randomly choosen from the sample with a probability which fits
+// the total destination number of events.
 //
 // Here is an example of how to choose 1000 events somehow distributed in
@@ -49,5 +52,5 @@
 // read.DisableAutoScheme();           // make sure everything is read
 //
-// MTFillMatrix fill(ref);             // setup MTFillMatrix
+// MTFillMatrix fill(&ref);            // setup MTFillMatrix
 // fill.SetNumDestEvents1(1000);       // setup number of events to select
 // fill.SetDestMatrix1(&matrix1);      // setup destination matrix
@@ -91,5 +94,5 @@
 #include "MContinue.h"
 #include "MFilterList.h"
-#include "MFRandomSplit.h"
+#include "MFEventSelector.h"
 #include "MFEventSelector2.h"
 
@@ -151,13 +154,23 @@
 // at MFEventSelector2 which is used to select the events.
 //
-// FIXME: Make a copy of ref.
-//
-MTFillMatrix::MTFillMatrix(const MH3 &ref)
-: fReference(ref), fReader(0), fDestMatrix1(0),
-fDestMatrix2(0), fNumDestEvents1(0), fNumDestEvents2(0),
-fWriteFile1(0), fWriteFile2(0)
+// If no MH3 *ref is given the events are randomly selected from the
+// total sample - this may result in samples which don't have exactly
+// the predefined size, but it is much faster.
+//
+MTFillMatrix::MTFillMatrix(const MH3 *ref)
+: fReference(0), fReader(0), fDestMatrix1(0), fDestMatrix2(0),
+  fNumDestEvents1(0), fNumDestEvents2(0), fWriteFile1(0), fWriteFile2(0)
 {
     fName  = "MFillMatrix";
     fTitle = "Tool to fill MHMatrix from file";
+
+    if (ref)
+        fReference = (MH3*)ref->Clone();
+}
+
+MTFillMatrix::~MTFillMatrix()
+{
+    if (fReference)
+        delete fReference;
 }
 
@@ -178,7 +191,7 @@
     *fLog << "Fill " << fDestMatrix1->GetDescriptor() << " with " << fNumDestEvents1 << endl;
     *fLog << "Fill " << fDestMatrix2->GetDescriptor() << " with " << fNumDestEvents2 << endl;
-        *fLog << "Distribution choosen ";
-    if (fReference.GetHist().GetEntries()>0)
-        *fLog << "from " << fReference.GetDescriptor();
+    *fLog << "Distribution choosen ";
+    if (fReference && fReference->GetHist().GetEntries()>0)
+        *fLog << "from " << fReference->GetDescriptor();
     else
         *fLog << "randomly";
@@ -195,7 +208,26 @@
     // A selector to select a given number of events from a sample
     //
-    MFEventSelector2 selector(fReference);
-    selector.SetNumMax(fNumDestEvents1+fNumDestEvents2);
-    selector.SetInverted();
+    // FIXME: Merge MFEventSelector and MFEventSelector2
+    MFilter *selector=0;
+    if (fReference)
+    {
+        // Case of a reference/nominal distribution
+        // The events must be read before selection
+        MFEventSelector2 *sel = new MFEventSelector2(*fReference);
+        sel->SetNumMax(fNumDestEvents1+fNumDestEvents2);
+        sel->SetInverted();
+
+        selector = sel;
+    }
+    else
+    {
+        // Case of a random distribution
+        // The events can be selected before reading
+        MFEventSelector *sel = new MFEventSelector;
+        sel->SetNumSelectEvts(fNumDestEvents1+fNumDestEvents2);
+        fReader->SetSelector(sel);
+
+        selector = sel;
+    }
 
     //
@@ -203,5 +235,5 @@
     // selected by the 'selector'
     //
-    MContinue cont(&selector);
+    MContinue cont(selector);
 
     //
@@ -209,5 +241,6 @@
     //
     const Double_t prob = (Double_t)fNumDestEvents1/(fNumDestEvents1+fNumDestEvents2);
-    MFRandomSplit split(prob);
+    MFEventSelector split;
+    split.SetSelectionRatio(prob);
 
     //
@@ -227,11 +260,12 @@
 
     // entries in MTaskList
-    tlist.AddToList(fReader);    // Read events
-    tlist.AddToList(&cont);      // select a sample of events
-    tlist.AddToList(&invsplit);  // process invsplit (which implicitly processes split)
+    tlist.AddToList(fReader);        // Read events
+    if (fReference)
+        tlist.AddToList(&cont);      // select a sample of events
+    tlist.AddToList(&invsplit);      // process invsplit (which implicitly processes split)
     if (fDestMatrix1 && fNumDestEvents1>0)
-        tlist.AddToList(&fill1); // fill matrix 1
+        tlist.AddToList(&fill1);     // fill matrix 1
     if (fDestMatrix2 && fNumDestEvents2>0)
-        tlist.AddToList(&fill2); // fill matrix 2
+        tlist.AddToList(&fill2);     // fill matrix 2
     if (fWriteFile1)
     {
@@ -252,12 +286,18 @@
     evtloop.SetDisplay(fDisplay);
     evtloop.SetLogStream(fLog);
-    if (!evtloop.Eventloop())
+
+    const Bool_t rc = evtloop.Eventloop();
+
+    // Print execution statistics of the tasklist
+    if (rc)
+        tlist.PrintStatistics();
+
+    delete selector;
+
+    if (!rc)
     {
         *fLog << err << GetDescriptor() << ": Failed." << endl;
         return kFALSE;
     }
-
-    // Print execution statistics of the tasklist
-    tlist.PrintStatistics();
 
     // Check the result of filling...
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 2743)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 2744)
@@ -13,5 +13,5 @@
 {
 private:
-    MH3       fReference;
+    MH3      *fReference;
     MRead    *fReader;
     MHMatrix *fDestMatrix1;
@@ -26,5 +26,6 @@
 
 public:
-    MTFillMatrix(const MH3 &ref);
+    MTFillMatrix(const MH3 *ref=NULL);
+    ~MTFillMatrix();
 
     void SetDestMatrix1(MHMatrix *matrix, UInt_t num=0)
