Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2678)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2681)
@@ -56,4 +56,6 @@
 #pragma link C++ class MHCalibrationPixel+;
 
+#pragma link C++ class MHSimulatedAnnealing+;
+
 #endif
 
Index: trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.cc	(revision 2681)
+++ trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.cc	(revision 2681)
@@ -0,0 +1,246 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Markus Gaug <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+///////////////////////////////////////////////////////////////////////
+//
+// MHSimulatedAnnealing
+//
+// This class contains different histograms of the Simulated Annealing 
+//   Snapshort during optimization and the final results
+//
+///////////////////////////////////////////////////////////////////////
+#include "MHSimulatedAnnealing.h"
+#include "MBinning.h"
+
+#include <TCanvas.h>
+#include <TPad.h>
+#include <TStyle.h>
+
+ClassImp(MHSimulatedAnnealing);
+
+// --------------------------------------------------------------------------
+//
+// Setup histograms
+//
+MHSimulatedAnnealing::MHSimulatedAnnealing(UShort_t moves, UShort_t ndim, 
+	                                   const char *name, 
+					   const char *title)
+    : fDim(ndim), fMoves(moves), fTimeEvolution(NULL), fBestEver(), fBestFuncEval()
+{
+
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHSimulatedAnnealing";
+    fTitle = title ? title : "Output Histograms of a Simulated Annealing Run";
+    
+    fBestEver.SetName("Hist_BestEver");
+    fBestEver.SetTitle("Best Param. Combinations");
+    fBestEver.SetXTitle("Run Duration");
+    fBestEver.SetYTitle("Parameter Nr.");
+    fBestEver.SetZTitle("Parameter Value");
+    fBestEver.SetDirectory(NULL);
+    
+    fBestFuncEval.SetName("Hist_BestFuncEval");
+    fBestFuncEval.SetTitle("Best Function Evaluation");
+    fBestFuncEval.SetXTitle("Run Duration");
+    fBestFuncEval.SetYTitle("Function Value");
+    fBestFuncEval.SetDirectory(NULL);
+    
+    MBinning binsx, binsy;
+    binsx.SetEdges(fMoves+1, 0, 1);
+    binsy.SetEdges(fDim, 0.5, fDim+0.5);
+    MH::SetBinning(&fBestEver, &binsx, &binsy);
+    
+    // For better visibility, omit the first entry in fBestFuncEval
+    // It has nothing significant, anyway
+    binsx.SetEdges(fMoves,1./(fMoves+1), 1);
+    binsx.Apply(fBestFuncEval);
+    
+}
+
+void MHSimulatedAnnealing::InitFullSimplex()
+{
+    if (fTimeEvolution)
+      delete fTimeEvolution;
+    
+    fTimeEvolution = new TObjArray;
+    fTimeEvolution->SetOwner();
+    
+    for (Int_t i=0;i<fDim;i++) 
+    {
+        TH2F *hist = new TH2F(Form("Hist_%d", i), Form("Parameter %d", i), 
+                              fMoves+1, 0., 1.,fDim+1,0.5,fDim+1.5);
+        hist->SetXTitle("Run Duration");
+        hist->SetYTitle("Point Nr. Simplex");
+        hist->SetZTitle(Form("Value of Parameter %d",i));
+        fTimeEvolution->Add(hist);
+    }
+}
+
+Bool_t MHSimulatedAnnealing::StoreFullSimplex(const TMatrix &p, const UShort_t move) 
+{
+
+    if (!fTimeEvolution)
+        return kFALSE;
+
+    Int_t idx=0;
+    const Axis_t bin = (move-0.5)/(fMoves+1);
+    
+    TIter Next(fTimeEvolution);
+    TH2F *hist=NULL;
+    while ((hist=(TH2F*)Next()))
+      {
+        for (Int_t i=0;i<fDim+1;i++)
+          hist->Fill(bin,i,p(i,idx));
+        idx++;
+      }
+    return kTRUE;
+}
+
+Bool_t MHSimulatedAnnealing::StoreBestValueEver(const TVector &y, const Float_t yb, const UShort_t move)
+{
+    if (y.GetNrows() != fDim) 
+      return kFALSE;
+    
+    const Axis_t bin = (move-0.5)/(fMoves+1);
+    
+    for (Int_t i=0;i<fDim;i++)
+      fBestEver.Fill(bin,0.5+i,((TVector)y)(i));
+    
+    fBestFuncEval.Fill(bin,yb);
+    
+    return kTRUE;
+}
+
+Bool_t MHSimulatedAnnealing::ChangeTitle(const UShort_t index, const char* title) 
+{
+    if (!fTimeEvolution) 
+      return kFALSE;
+
+    TH2F *hist = NULL;
+    if (!(hist = (TH2F*)fTimeEvolution->At(index))) 
+      return kFALSE;
+
+    hist->SetNameTitle(Form("Hist_%s",title),title);
+    hist->SetYTitle(Form("Value of Parameter %s",title));
+
+    return kTRUE;
+}
+
+void MHSimulatedAnnealing::ChangeFuncTitle(const char* title)
+{
+  fBestFuncEval.SetTitle(title);
+}
+
+TObject *MHSimulatedAnnealing::DrawClone(Option_t *opt) const
+{
+    UShort_t i=2;
+  
+    TCanvas *c = MakeDefCanvas(this, 720, 810);
+    if (fTimeEvolution)
+      c->Divide(2,(int)(fDim/2.)+1);
+    else
+      gPad->Divide(1,2);
+  
+    gROOT->SetSelectedPad(NULL);
+  
+    c->cd(1);
+    gStyle->SetOptStat(0);
+    ((TH1&)fBestFuncEval).DrawCopy();   
+    
+    c->cd(2);
+    gStyle->SetOptStat(10);
+    ((TH2&)fBestEver).DrawCopy(opt);   
+    
+    if (fTimeEvolution)
+    {
+      TH2F *hist = NULL;
+      TIter Next(fTimeEvolution);
+      while ((hist=(TH2F*)Next())) 
+        {
+          c->cd(++i);
+          hist->DrawCopy(opt);
+        }
+    }   
+    c->Modified();
+    c->Update();
+    
+    return c;
+}
+
+
+
+// --------------------------------------------------------------------------
+//
+// Draw all histograms. 
+//
+void MHSimulatedAnnealing::Draw(Option_t *opt) 
+{
+    UShort_t i=2;
+
+    if (!gPad)
+      MakeDefCanvas(this,780,940);
+
+    if (fTimeEvolution) 
+      gPad->Divide(2,(int)(fDim/2.)+1);
+    else 
+      gPad->Divide(1,2);
+
+    gPad->cd(1);  
+    gStyle->SetOptStat(0);
+    fBestFuncEval.Draw();
+    gPad->Modified();
+    gPad->Update();
+    
+    gPad->cd(2);
+    gStyle->SetOptStat(10);
+    fBestEver.Draw(opt);
+    gPad->Modified();
+    gPad->Update();
+
+    if (!fTimeEvolution)
+        return;
+    
+    TH2F *hist = NULL;
+    TIter Next(fTimeEvolution);
+    while ((hist=(TH2F*)Next())) 
+    {
+        gPad->cd(++i);
+        hist->Draw(opt);
+    }
+    gPad->Modified();
+    gPad->Update();
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the histograms.
+//
+MHSimulatedAnnealing::~MHSimulatedAnnealing() 
+{
+  if (fTimeEvolution)
+    delete fTimeEvolution;
+}
+  
Index: trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.h	(revision 2681)
+++ trunk/MagicSoft/Mars/mhist/MHSimulatedAnnealing.h	(revision 2681)
@@ -0,0 +1,67 @@
+#ifndef MARS_MHSimulatedannealing
+#define MARS_MHSimulatedannealing
+///////////////////////////////////////////////////////////////////////////////
+//
+//  MHSimulatedAnnealing
+//
+//  Output container of MSimulatedAnnealing
+////////////////////////////////////////////////////////////////////////////////////////////////////
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+#ifndef ROOT_TMatrix
+#include "TMatrix.h"
+#endif
+
+#ifndef ROOT_TVector
+#include "TVector.h"
+#endif
+
+#ifndef ROOT_TH2
+#include "TH2.h"
+#endif
+
+#ifndef ROOT_TH1
+#include "TH1.h"
+#endif
+
+#ifndef ROOT_TObjarray
+#include "TObjArray.h"
+#endif
+
+class MHSimulatedAnnealing : public MH
+{
+private:
+    UShort_t fDim;             // The dimension of the whole thing
+    UShort_t fMoves;           // The total number of moves
+
+    TObjArray *fTimeEvolution; //-> Display the time evolution of the simplex in TH1D's
+
+    TH2F     fBestEver;        // The best values ever found during search
+    TH1F     fBestFuncEval;    // The best function values ever found during search
+
+public:
+
+    MHSimulatedAnnealing(UShort_t moves = 0,UShort_t ndim = 0, 
+	                 const char *name=NULL, const char *title=NULL);
+    ~MHSimulatedAnnealing();
+
+    void InitFullSimplex();
+    Bool_t StoreFullSimplex(const TMatrix &p, const UShort_t move);
+    Bool_t StoreBestValueEver(const TVector &y, const Float_t yb, const UShort_t move);
+    
+    Bool_t ChangeTitle(const UShort_t index, const char* title);
+    void ChangeFuncTitle(const char* title);    
+    
+    TObjArray *GetTimeEvolution() const   { return fTimeEvolution; }
+    const TH2F &GetBestEver()     const   { return fBestEver; }
+    const TH1F &GetBestFuncEval() const   { return fBestFuncEval; }
+    
+    void Draw(Option_t *opt=NULL);
+    TObject *DrawClone(Option_t *opt=NULL) const;
+    
+    ClassDef(MHSimulatedAnnealing,1) // Storage Histogram Container for Cuteval Results
+};
+    
+#endif
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 2678)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 2681)
@@ -69,5 +69,7 @@
            MHCalibrationBlindPixel.cc \
            MHCalibrationPINDiode.cc \
-           MHSupercuts.cc 
+           MHCalibrationPINDiode.cc \
+           MHSupercuts.cc \
+           MHSimulatedAnnealing.cc 
 #           MHCurrents.cc \
 
