Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1839)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1840)
@@ -7,4 +7,6 @@
 	root CT1 Monte Carlo file from Wolfgang).
 
+
+
  2003/03/19: Robert Wagner
 
@@ -14,4 +16,5 @@
 
 
+
  2003/03/19: Thomas Bretz
 
@@ -25,4 +28,13 @@
       meventdisp/MReadMarsFile.cc:
       - changed MReadTree::GetEventNum to MReadTree::GetNumEntry
+
+    * macros/estfit.C:
+      - adopted to new MChisqEval
+
+    * mtools/MChisqEval.[h,cc]:
+      - added
+
+    * mtools/Makefile, mtools/ToolsLinkDef.h:
+      - added MChisqEval
 
 
Index: trunk/MagicSoft/Mars/macros/estfit.C
===================================================================
--- trunk/MagicSoft/Mars/macros/estfit.C	(revision 1839)
+++ trunk/MagicSoft/Mars/macros/estfit.C	(revision 1840)
@@ -1,141 +1,18 @@
-#include <fstream.h>
+#include <TStopwatch.h>
+#include <TMinuit.h>
 
-#include "MTask.h"
 #include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
 
-#include "MDataChain.h"
-
-class MChisqEval : public MTask
-{
-private:
-    static const TString gsDefName;
-    static const TString gsDefTitle;
-
-    Double_t fChisq; //! Evaluated chi square
-
-    MData   *fData0; // Data Member one (monte carlo data or chisq function)
-    MData   *fData1; // Data Member two (measured data)
-
-    // --------------------------------------------------------------------------
-    //
-    // Implementation of SavePrimitive. Used to write the call to a constructor
-    // to a macro. In the original root implementation it is used to write
-    // gui elements to a macro-file.
-    //
-    void StreamPrimitive(ofstream &out) const
-    {
-        out << "   MChisqEval " << GetUniqueName() << ";";
-        if (fData0)
-            out << "   " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
-        if (fData1)
-            out << "   " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
-    }
-
-    enum { kIsOwner = BIT(14) };
-
-public:
-    MChisqEval(const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
-    {
-        fName  = name  ? name  : gsDefName.Data();
-        fTitle = title ? title : gsDefTitle.Data();
-    }
-
-    MChisqEval(MData *y1, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
-    {
-        fName  = name  ? name  : gsDefName.Data();
-        fTitle = title ? title : gsDefTitle.Data();
-        SetY1(y1);
-    }
-    MChisqEval(MData *y1, MData *y2, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
-    {
-        fName  = name  ? name  : gsDefName.Data();
-        fTitle = title ? title : gsDefTitle.Data();
-        SetY1(y1);
-        SetY2(y2);
-    }
-    ~MChisqEval()
-    {
-        if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
-            delete fData0;
-
-        if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
-            delete fData1;
-    }
-
-    void SetY1(MData *data)
-    {
-        // Set MC value
-        if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
-            delete fData0;
-        fData0 = data;
-        fData0->SetBit(kCanDelete);
-        AddToBranchList(fData0->GetDataMember());
-    }
-    void SetY2(MData *data)
-    {
-        // Set measured/estimated value
-        if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
-            delete fData1;
-        fData1 = data;
-        fData1->SetBit(kCanDelete);
-        AddToBranchList(fData1->GetDataMember());
-    }
-    void SetY1(const TString data) { SetY1(new MDataChain(data)); }
-    void SetY2(const TString data) { SetY2(new MDataChain(data)); }
-
-    void SetOwner(Bool_t o=kTRUE) { o ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
-
-    Bool_t PreProcess(MParList *plist)
-    {
-        fChisq = 0;
-
-        if (!fData0)
-            return kFALSE;
-
-        if (!fData0->PreProcess(plist))
-            return kFALSE;
-
-        if (fData1)
-            if (!fData1->PreProcess(plist))
-                return kFALSE;
-
-        return kTRUE;
-    }
-
-    Bool_t Process()
-    {
-        const Double_t y1 = fData0->GetValue();
-        const Double_t y2 = fData1 ? fData1->GetValue() : 0;
-
-        const Double_t dy  = y2-y1;
-        const Double_t err = fData1 ? y1*y1 : 1;
-
-        fChisq += dy*dy/err;
-        return kTRUE;
-    }
-
-    Bool_t PostProcess()
-    {
-        fChisq /= GetNumExecutions();
-        return kTRUE;
-    }
-
-    Double_t GetChisq() const { return fChisq; }
- 
-    ClassDef(MChisqEval, 0)
-};
-
-ClassImp(MChisqEval);
-
-const TString MChisqEval::gsDefName  = "MChisqEval";
-const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
+#include "MReadTree.h"
+#include "MHMatrix.h"
+#include "MChisqEval.h"
+#include "MMatrixLoop.h"
+#include "MDataMember.h"
+#include "MDataElement.h"
+#include "MEnergyEstParam.h"
 
 // --------------------------------------------------------------------------
-
-#include <TMinuit.h>
-
-#include "MEvtLoop.h"
-#include "MTaskList.h"
-#include "MEnergyEstParam.h"
 
 void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
@@ -156,14 +33,4 @@
 
 // --------------------------------------------------------------------------
-#include <TStopwatch.h>
-
-#include "MHMatrix.h"
-#include "MEnergyEst.h"
-
-#include "MDataMember.h"
-#include "MDataElement.h"
-
-#include "MReadTree.h"
-#include "MMatrixLoop.h"
 
 void estfit(Bool_t evalenergy=kFALSE)
@@ -177,9 +44,9 @@
     Int_t col = matrix.AddColumn(evalenergy?"MMcEvt.fEnergy":"MMcEvt.fImpact");
 
-    MEnergyEstParam eest;
-    eest.Add("MHillasSrc");
+    MEnergyEstParam eest("Hillas");
+    eest.Add("HillasSrc");
     eest.InitMapping(&matrix);
 
-    MReadTree read("Events", "gammas.root");
+    MReadTree read("Events", "~/ct1/MC_ON2.root");
     read.DisableAutoScheme();
 
@@ -211,4 +78,5 @@
     //
     TMinuit minuit(12);
+    minuit.SetPrintLevel(-1);
     minuit.SetFCN(fcn);
 
@@ -224,18 +92,18 @@
     //
     TArrayD fA(5);
-    fA[0] =  -2539; // [cm]
-    fA[1] =    900; // [cm]
-    fA[2] =   17.5; // [cm]
-    fA[3] =  1;//    4;
-    fA[4] =   58.3;
+    fA[0] = -3907.74; //4916.4;    //-2414.75;
+    fA[1] = 1162.3;   //149.549;   // 1134.28;
+    fA[2] = 199.351;  //-558.209;  // 132.932;
+    fA[3] = 0.403192; //0.270725;  //0.292845;
+    fA[4] = 121.921;  //107.001;   // 107.001;
 
     TArrayD fB(7);
-    fB[0] =    -8.64; // [GeV]
-    fB[1] =   -0.069; // [GeV]
-    fB[2] =  0.00066; // [GeV]
-    fB[3] =    0.033; // [GeV]
-    fB[4] = 0.000226; // [GeV]
-    fB[5] =  4.14e-8; // [GeV]
-    fB[6] =    -0.06;
+    fB[0] = -100;
+    fB[1] = 10;
+    fB[2] = 0.1;
+    fB[3] = 10;
+    fB[4] = -1;
+    fB[5] = -0.1;
+    fB[6] = -0.1;
 
     // Set starting values and step sizes for parameters
Index: trunk/MagicSoft/Mars/mtools/MChisqEval.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MChisqEval.cc	(revision 1840)
+++ trunk/MagicSoft/Mars/mtools/MChisqEval.cc	(revision 1840)
@@ -0,0 +1,143 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MChisqEval.h"
+
+#include <fstream.h>
+
+#include "MDataChain.h"
+
+ClassImp(MChisqEval);
+
+void MChisqEval::StreamPrimitive(ofstream &out) const
+{
+    out << "   MChisqEval " << GetUniqueName() << ";";
+    if (fData0)
+        out << "   " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
+    if (fData1)
+        out << "   " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
+}
+
+MChisqEval::MChisqEval(const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+MChisqEval::MChisqEval(MData *y1, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+    SetY1(y1);
+}
+
+MChisqEval::MChisqEval(MData *y1, MData *y2, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+    SetY1(y1);
+    SetY2(y2);
+}
+
+MChisqEval::~MChisqEval()
+{
+    if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
+        delete fData0;
+
+    if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
+        delete fData1;
+}
+
+void MChisqEval::SetY1(MData *data)
+{
+    // Set MC value
+    if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
+        delete fData0;
+    fData0 = data;
+    fData0->SetBit(kCanDelete);
+    AddToBranchList(fData0->GetDataMember());
+}
+
+void MChisqEval::SetY2(MData *data)
+{
+    // Set measured/estimated value
+    if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
+        delete fData1;
+    fData1 = data;
+    fData1->SetBit(kCanDelete);
+    AddToBranchList(fData1->GetDataMember());
+}
+
+void MChisqEval::SetY1(const TString data)
+{
+    SetY1(new MDataChain(data));
+}
+
+void MChisqEval::SetY2(const TString data)
+{
+    SetY2(new MDataChain(data));
+}
+
+Bool_t MChisqEval::PreProcess(MParList *plist)
+{
+    fChisq = 0;
+
+    if (!fData0)
+        return kFALSE;
+
+    if (!fData0->PreProcess(plist))
+        return kFALSE;
+
+    if (fData1)
+        if (!fData1->PreProcess(plist))
+            return kFALSE;
+
+    return kTRUE;
+}
+
+Bool_t MChisqEval::Process()
+{
+    const Double_t y1 = fData0->GetValue();
+    const Double_t y2 = fData1 ? fData1->GetValue() : 0;
+
+    const Double_t dy  = y2-y1;
+    const Double_t err = fData1 ? y1*y1 : 1;
+
+    fChisq += dy*dy/err;
+    return kTRUE;
+}
+
+Bool_t MChisqEval::PostProcess()
+{
+    fChisq /= GetNumExecutions();
+    return kTRUE;
+}
+
+const TString MChisqEval::gsDefName  = "MChisqEval";
+const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
+
Index: trunk/MagicSoft/Mars/mtools/MChisqEval.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MChisqEval.h	(revision 1840)
+++ trunk/MagicSoft/Mars/mtools/MChisqEval.h	(revision 1840)
@@ -0,0 +1,53 @@
+#ifndef MARS_MChisqEval
+#define MARS_MChisqEval
+
+#ifndef ROOT_MTask
+#include "MTask.h"
+#endif
+
+class MData;
+
+class MChisqEval : public MTask
+{
+private:
+    static const TString gsDefName;
+    static const TString gsDefTitle;
+
+    Double_t fChisq; //! Evaluated chi square
+
+    MData   *fData0; // Data Member one (monte carlo data or chisq function)
+    MData   *fData1; // Data Member two (measured data)
+
+    // --------------------------------------------------------------------------
+    //
+    // Implementation of SavePrimitive. Used to write the call to a constructor
+    // to a macro. In the original root implementation it is used to write
+    // gui elements to a macro-file.
+    //
+    void StreamPrimitive(ofstream &out) const;
+
+    enum { kIsOwner = BIT(14) };
+
+public:
+    MChisqEval(const char *name=NULL, const char *title=NULL);
+    MChisqEval(MData *y1, const char *name=NULL, const char *title=NULL);
+    MChisqEval(MData *y1, MData *y2, const char *name=NULL, const char *title=NULL);
+    ~MChisqEval();
+
+    void SetY1(MData *data);
+    void SetY2(MData *data);
+    void SetY1(const TString data);
+    void SetY2(const TString data);
+
+    void SetOwner(Bool_t o=kTRUE) { o ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
+
+    Bool_t PreProcess(MParList *plist);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+    Double_t GetChisq() const { return fChisq; }
+ 
+    ClassDef(MChisqEval, 0)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mtools/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mtools/Makefile	(revision 1839)
+++ trunk/MagicSoft/Mars/mtools/Makefile	(revision 1840)
@@ -22,5 +22,5 @@
 #  connect the include files defined in the config.mk file
 #
-INCLUDES = -I. -I../mbase -I../mgui -I../mgeom
+INCLUDES = -I. -I../mbase -I../mgui -I../mgeom -I../mdata
 
 #------------------------------------------------------------------------------
@@ -28,5 +28,7 @@
 .SUFFIXES: .c .cc .cxx .h .hxx .o 
 
-SRCFILES = MagicSnake.cc \
+SRCFILES = MChisqEval.cc \
+	   Magic5Wins.cc \
+	   MagicSnake.cc \
            MagicShow.cc \
            MagicDomino.cc \
Index: trunk/MagicSoft/Mars/mtools/ToolsLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/ToolsLinkDef.h	(revision 1839)
+++ trunk/MagicSoft/Mars/mtools/ToolsLinkDef.h	(revision 1840)
@@ -5,5 +5,8 @@
 #pragma link off all functions;
 
+#pragma link C++ class MChisqEval+;
 #pragma link C++ class MineSweeper+;
+#pragma link C++ class Magic5Wins+;
+// #pragma link C++ class MagicReversi+;
 #pragma link C++ class MagicSnake+;
 #pragma link C++ class MagicShow+;
