Index: trunk/MagicSoft/Mars/mfit/MTFitLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mfit/MTFitLoop.cc	(revision 3582)
+++ trunk/MagicSoft/Mars/mfit/MTFitLoop.cc	(revision 4358)
@@ -47,13 +47,22 @@
 #include "MTFitLoop.h"
 
+#include <TArrayD.h>
 #include <TMinuit.h>
 #include <TStopwatch.h>
 
 #include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MParameters.h"
+
 #include "MRead.h"
-#include "MEvtLoop.h"
 
 #include "MLog.h"
 #include "MLogManip.h"
+
+ClassImp(MTFitLoop);
+
+using namespace std;
 
 //------------------------------------------------------------------------
@@ -74,6 +83,6 @@
     MParList *plist = fEvtLoop->GetParList();
 
-    MParameterD   *eval = (MParameterD*)plist->FindCreateObj("MParameterD", fFitParameter);
-    MParContainer *pars = plist->FindObject(fParametersName);
+    MParameterD   *eval = (MParameterD*)  plist->FindCreateObj("MParameterD", fFitParameter);
+    MParContainer *pars = (MParContainer*)plist->FindObject(fParametersName);
 
     MRead *read = (MRead*)plist->FindObject("MTaskList")->FindObject("MRead");
@@ -104,6 +113,6 @@
     if (fDebug>=0)
     {
-        *fLog << inf << "Set: ";
-        for (Int_t i=0; i<7; i++)
+        *fLog << inf << "Set(" << gMinuit->fMaxpar << "): ";
+        for (Int_t i=0; i<gMinuit->fMaxpar; i++)
             *fLog << par[i] << " ";
         *fLog << endl;
@@ -129,5 +138,5 @@
 }
 
-MTFitLoop::MTFitLoop()
+MTFitLoop::MTFitLoop(Int_t num) : fNum(num), fMaxIterations(1000)
 {
     fDebug     = -1;
@@ -135,23 +144,24 @@
 }
 
-void MTFitLoop::Optimize(MEvtLoop &loop)
+void MTFitLoop::Optimize(MEvtLoop &loop, TArrayD &pars)
 {
     *fLog << inf << "Event loop was setup" << endl;
-    MParList *parlist = loop->GetParList();
+    MParList *parlist = loop.GetParList();
     if (!parlist)
         return;
 
-    MParContainer *pars = plist->FindObject(fParametersName);
-    if (!pars)
-        return;
-
-    fEvtLoop = evtloop;
-
-    MParContainer &parameters = *pars;
+//    MParContainer *pars = (MParContainer*)parlist->FindObject(fParametersName);
+//    if (!pars)
+//        return;
+
+    fEvtLoop = &loop;
+
+//    MParContainer &parameters = *pars;
 
     TMinuit *minsave = gMinuit;
 
-    gMinuit = new TMinuit(parameters.GetSize());
+    gMinuit = new TMinuit(pars.GetSize());
     gMinuit->SetPrintLevel(-1);
+    gMinuit->SetMaxIterations(fMaxIterations);
 
     gMinuit->SetFCN(fcn);
@@ -164,5 +174,5 @@
      // less than 0.001*[tolerance]*UP (see [SET ERRordef]).");
      //
-    if (gMinuit->SetErrorDef(1000))
+    if (gMinuit->SetErrorDef(1))
     {
         *fLog << err << dbginf << "SetErrorDef failed." << endl;
@@ -173,11 +183,11 @@
     // Set starting values and step sizes for parameters
     //
-    for (Int_t i=0; i<parameters.GetSize(); i++)
+    for (Int_t i=0; i<pars.GetSize(); i++)
     {
         TString name = "par[";
         name += i;
         name += "]";
-        Double_t vinit = parameters[i];
-        Double_t step  = fabs(parameters[i]/3);
+        Double_t vinit = pars[i];
+        Double_t step  = fabs(pars[i]/3);
 
         Double_t limlo = 0; // limlo=limup=0: no limits
@@ -192,9 +202,7 @@
     }
 
-    for (int i=0; i<parameters.GetSize(); i++)
-        if (i<fFixParams.GetSize() && fFixParams[i]!=0)
+    for (int i=0; i<pars.GetSize() && i<fFixedParams.GetSize(); i++)
+        if (fFixedParams[i]!=0)
             gMinuit->FixParameter(i);
-        else
-            gMinuit->Release(i);
 
     // Now ready for minimization step:
@@ -217,13 +225,13 @@
     // Update values of fA, fB:
     //
-    for (Int_t i=0; i<parameters.GetSize(); i++)
+    for (Int_t i=0; i<pars.GetSize(); i++)
     {
         Double_t x1, x2;
         gMinuit->GetParameter(i,x1,x2);
-        parameters[i] = x1;
-        cout << i << ": " << parameters[i] << endl;
-    }
-
-    list.SetVariables(parameters);
+        pars[i] = x1;
+        cout << i << ": " << pars[i] << endl;
+    }
+
+    //list.SetVariables(pars);
 
     gMinuit = minsave;
Index: trunk/MagicSoft/Mars/mfit/MTFitLoop.h
===================================================================
--- trunk/MagicSoft/Mars/mfit/MTFitLoop.h	(revision 3582)
+++ trunk/MagicSoft/Mars/mfit/MTFitLoop.h	(revision 4358)
@@ -28,8 +28,11 @@
     TArrayC   fFixedParams;
 
+    Int_t fNum;
+    Int_t fMaxIterations;
+
 public:
-    MTFitLoop();
+    MTFitLoop(const Int_t num=0);
 
-    void Optimize(MEvtLoop &loop);
+    void Optimize(MEvtLoop &loop, TArrayD &pars);
 
     void SetNameParameters(const char *parm) { fParametersName = parm; }
@@ -37,4 +40,5 @@
 
     void SetFixedParameters(const TArrayC &c) { fFixedParams = c; }
+    void SetMaxIterations(Int_t maxiter=500) {fMaxIterations = maxiter;} // for debugging
 
     void SetDebug(Int_t n)     { fDebug = n; }
