Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.cc	(revision 5670)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.cc	(revision 5670)
@@ -0,0 +1,203 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Eva Domingo,     12/2004 <mailto:domingo@ifae.es>
+!              Wolfgang Wittek, 12/2004 <mailto:wittek@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MDisp                                                                 //
+//                                                                         //
+//   this is the container for the Disp parameterization                   //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MDisp.h"
+
+#include <math.h>
+#include <fstream>
+
+#include <TArrayD.h>
+
+#include "MImageParDisp.h"
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+
+ClassImp(MDisp);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// constructor
+//
+MDisp::MDisp(const char *name, const char *title)
+  : fLogSize0(3.), fLength0(0.1), fWidth0(0.05), fConc0(0.35),
+    fLeakage10(0.05),fLeakage20(0.1)
+{
+    fName  = name  ? name  : "MDisp";
+    fTitle = title ? title : "Container for the Disp parameters";
+
+    // set arrays size to the number of parameters used
+    fParameters.Set(5);
+    fStepsizes.Set(5);
+
+    // set Disp parameters to their default values
+    InitParameters();
+}
+
+
+// --------------------------------------------------------------------------
+//
+// set default values for the Disp parameters
+//
+void MDisp::InitParameters()
+{
+    //---------------------------------------------------
+    //  these are the default values
+
+    fParameters[0] =  1.0;
+    fParameters[1] =  0.6;
+    fParameters[2] = -0.8;
+    fParameters[3] = -0.8;
+    fParameters[4] = -1.2;
+
+
+    //---------------------------------------------------
+    // fStepsizes 
+    // if == 0.0    the parameter will be fixed in the minimization
+    //    != 0.0    initial step sizes for the parameters
+
+    fStepsizes[0] = 0.010;
+    fStepsizes[1] = 0.006;
+    fStepsizes[2] = 0.008;
+    fStepsizes[3] = 0.008;
+    fStepsizes[4] = 0.012;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the parameter values from the array 'd'
+//
+//
+Bool_t MDisp::SetParameters(const TArrayD &d)
+{
+    if (d.GetSize() != fParameters.GetSize())
+    {
+        *fLog << err << "Sizes of d and of fParameters are different : "
+              << d.GetSize() << ",  " << fParameters.GetSize() << endl;
+        return kFALSE;
+    }
+
+    fParameters = d;
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the step sizes from the array 'd'
+//
+//
+Bool_t MDisp::SetStepsizes(const TArrayD &d)
+{
+    if (d.GetSize() != fStepsizes.GetSize())
+    {
+        *fLog << err << "Sizes of d and of fStepsizes are different : "
+              << d.GetSize() << ",  " << fStepsizes.GetSize() << endl;
+        return kFALSE;
+    }
+
+    fStepsizes = d;
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the Disp parameterization and Calculate Disp
+//
+//
+Double_t MDisp::Calc(TArrayD &imagevar)
+{
+    // get parameters
+    Int_t numpar = fParameters.GetSize();
+    TArrayD p(numpar);
+    for (Int_t i=0; i<numpar; i++)
+      p[i] = fParameters[i];
+
+    // get image variables to be used in the Disp parameterization
+    Double_t logsize  = imagevar[0];
+    Double_t width    = imagevar[1];
+    Double_t length   = imagevar[2];
+    //    Double_t conc     = imagevar[3];
+    //    Double_t leakage1 = imagevar[4];
+    //    Double_t leakage2 = imagevar[5];
+    
+    // Disp parameterization to be optimized
+    //  Note: fLogSize0, fLength0... variables are introduced to uncorrelate as much
+    //        as possible the parameters in the Disp expression, with the purpose of
+    //        helping the minimization algorithm to converge. They are set approx.
+    //        to their distribution mean value in the MDisp constructor, but can be 
+    //        changed using the corresponding set function.
+    //
+
+    //    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) 
+    //      + (p[2] + p[3]*(logsize-fLogSize0))*width/length;
+
+    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) + p[4]*(length-fLength0) 
+      + (p[2] + p[3]*(logsize-fLogSize0))*width/length;
+
+    //    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) + p[4]*(length-fLength0) 
+    //      + (p[2] + p[3]*(logsize-fLogSize0))*length/width;
+
+    //    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) + p[4]*(length-fLength0) 
+    //      + (p[2] + p[3]*(logsize-fLogSize0) + p[5]*(length-fLength0))*width/length;
+
+    //    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) + p[4]*(width-fWidth0) 
+    //      + (p[2] + p[3]*(logsize-fLogSize0))*width/length;   // + p[5]*(width-fWidth0))*width/length;
+
+    //    Double_t disp = p[0] + p[1]*(logsize-fLogSize0) + p[4]*(conc-fConc0) 
+    //      + (p[2] + p[3]*(logsize-fLogSize0))*width/length;   // + p[5]*(conc-fConc0))*width/length;
+
+    //    Double_t disp = ( p[0] + p[1]*(logsize-fLogSize0) 
+    //		      + p[2]*pow(logsize-fLogSize0,2)
+    //		      + p[3]*pow(logsize-fLogSize0,3) 
+    //		      + p[4]*pow(logsize-fLogSize0,4) )
+    //                    *( 1/(1+width/length) );
+
+    //    Double_t disp = ( p[0] + p[1]*(logsize-fLogSize0) 
+    //		      + p[2]*pow(logsize-fLogSize0,2)
+    //		      + p[3]*pow(logsize-fLogSize0,3) 
+    //		      + p[4]*pow(logsize-fLogSize0,4) )
+    //                    *(1-width/length);
+
+    return disp;
+}
+
+
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.h	(revision 5670)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MDisp.h	(revision 5670)
@@ -0,0 +1,54 @@
+#ifndef MARS_MDisp
+#define MARS_MDisp
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+
+class MDisp : public MParContainer
+{
+private:
+
+    TArrayD fParameters;      // Disp parameters
+    TArrayD fStepsizes;       // step sizes of Disp parameters
+
+    Double_t fLogSize0;       // Variables introduced in the Disp expression
+    Double_t fLength0;        // to shift the minimization around the mean
+    Double_t fWidth0;         // values of the variables, so it makes easier
+    Double_t fConc0;          // to MINUIT to converge. Default values are set
+    Double_t fLeakage10;      // in the constructor (to their standard mean 
+    Double_t fLeakage20;      // distribution values) but can be changed with
+                              // the set functions.
+
+public:
+
+    MDisp(const char *name=NULL, const char *title=NULL);
+
+    void InitParameters();
+
+    Bool_t SetParameters(const TArrayD &d);
+    Bool_t SetStepsizes(const TArrayD &d);
+
+    const TArrayD &GetParameters() const   { return fParameters; }
+    const TArrayD &GetStepsizes()  const   { return fStepsizes;  }
+
+    void SetLogSize0(Double_t newmeanval)  { fLogSize0  = newmeanval; }
+    void SetWidth0(Double_t newmeanval)    { fWidth0    = newmeanval; }
+    void SetLength0(Double_t newmeanval)   { fLength0   = newmeanval; }
+    void SetConc0(Double_t newmeanval)     { fConc0     = newmeanval; }
+    void SetLeakage10(Double_t newmeanval) { fLeakage10 = newmeanval; }
+    void SetLeakage20(Double_t newmeanval) { fLeakage20 = newmeanval; }
+
+    Double_t Calc(TArrayD &imagevar);
+
+    ClassDef(MDisp, 1) // Container for the Disp parameters
+};
+
+#endif
+
+
+
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MDispCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MDispCalc.cc	(revision 5669)
+++ 	(revision )
@@ -1,129 +1,0 @@
-#include "MDispCalc.h"
-
-#include "MParList.h"
-
-#include "MDisp.h"
-#include "MHillas.h"
-#include "MHillasSrc.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MDispCalc);
-
-using namespace std;
-
-static const TString gsDefName  = "MDispCalc";
-static const TString gsDefTitle = "Calculate Disp related parameters";
-
-// -------------------------------------------------------------------------
-//
-// Default constructor.
-//
-MDispCalc::MDispCalc(const char *name, const char *title)
-    : fHillas(NULL), fHillasSrc(NULL), fSrcPos(NULL), fDisp(NULL)
-{
-    fName  = name  ? name  : gsDefName.Data();
-    fTitle = title ? title : gsDefTitle.Data();
-
-}
-
-// -------------------------------------------------------------------------
-//
-Int_t MDispCalc::PreProcess(MParList *pList)
-{
-
-    fHillas = (MHillas*)pList->FindObject("MHillas");
-    if (!fHillas)
-    {
-        *fLog << err << dbginf << "MHillas not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fHillasSrc = (MHillasSrc*)pList->FindObject("MHillasSrc");
-    if (!fHillasSrc)
-    {
-        *fLog << err << dbginf << "MHillasSrc not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fSrcPos = (MSrcPosCam*)pList->FindObject("MSrcPosCam");
-    if (!fSrcPos)
-    {
-        *fLog << err << dbginf << "SrcPosCam not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fDisp = (MDisp*)pList->FindCreateObj("MDisp");
-    if (!fDisp)
-        return kFALSE;
- 
-    return kTRUE;
-}
-
-// -------------------------------------------------------------------------
-//
-Int_t MDispCalc::Process()
-{
-
-    fDisp->SetPsi(fPsi);
-
-    if ( fHillas->GetWidth()==-1 || fHillas->GetLength()==-1 )
-      {
-	fErrors++;
-	return kTRUE;
-      }
-
-    Float_t xshift = 0.;
-    Float_t yshift = 0.;
-
-    if ( fSrcPos )
-      {
-	xshift = fSrcPos->GetX();
-	yshift = fSrcPos->GetY();
-      }
-
-    fDisp->SetDisp(fPsi*(1-(fHillas->GetWidth()/fHillas->GetLength())));
-    fDisp->SetPosDisp("X1", fHillas->GetMeanX() - (fDisp->GetDisp()*fHillas->GetCosDelta()) - xshift);
-    fDisp->SetPosDisp("Y1", fHillas->GetMeanY() - (fDisp->GetDisp()*fHillas->GetSinDelta()) - yshift);
-    fDisp->SetPosDisp("X2", fHillas->GetMeanX() + (fDisp->GetDisp()*fHillas->GetCosDelta()) - xshift);
-    fDisp->SetPosDisp("Y2", fHillas->GetMeanY() + (fDisp->GetDisp()*fHillas->GetSinDelta()) - yshift);
-
-    if ( (1-fHillas->GetWidth()/fHillas->GetLength()) == 0. )
-      {
-	fErrors++;
-	return kTRUE;
-      }
-
-    fDisp->SetPsiEvent(fHillasSrc->GetDist()/(1-fHillas->GetWidth()/fHillas->GetLength()));
-
-    fDisp->SetReadyToSave();
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Prints some statistics about the disp calculation. The percentage
-//  is calculated with respect to the number of executions of this task.
-//
-Int_t MDispCalc::PostProcess()
-{
-    if (GetNumExecutions()==0)
-        return kTRUE;
-
-    *fLog << inf << endl;
-    *fLog << GetDescriptor() << " execution statistics:" << endl;
-    *fLog << dec << setfill(' ');
-    *fLog << " " << fErrors << " (" << (int)(fErrors*100/GetNumExecutions()) << "%) Evts skipped due to: (1-w/l)==0 or (Width or Length == -1)" << endl;
-    *fLog << endl;
-
-    /*
-    delete fHillas;
-    delete fHillasSrc;
-    delete fSrcPos;
-    delete fDisp;
-    */
-
-    return kTRUE;
-}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MDispCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MDispCalc.h	(revision 5669)
+++ 	(revision )
@@ -1,45 +1,0 @@
-#ifndef MARS_MDispCalc
-#define MARS_MDispCalc
-
-#ifndef MARS_MTask
-#include "MTask.h"
-#endif
-
-#ifndef MARS_MSrcPosCam
-#include "MSrcPosCam.h"
-#endif
-
-class MHillas;
-class MHillasSrc;
-class MDisp;
-class MSrcPosCam;
-
-class MDispCalc : public MTask
-{
-private:
-
-    MHillas    *fHillas;     //! Pointer to the source independent hillas parameters
-    MHillasSrc *fHillasSrc;  //! Pointer to the source dependent hillas parameters
-    MSrcPosCam *fSrcPos;     //! Pointer to the source position
-    MDisp *fDisp; 
-
-    Float_t fPsi;                 // [mm]  Psi Disp parameter (has to fixed before Disp calculations,
-                                  //                      used for fPosDisp1, fPosDisp2, fDisp determination)
-    
-    Int_t       fErrors;
-
-    Int_t PreProcess(MParList *plist);
-    Int_t Process();
-    Int_t PostProcess();
-
-public:
-
-    MDispCalc(const char *name=NULL, const char *title=NULL);
-    
-    void SetSrcPos(Float_t xpos, Float_t ypos) {fSrcPos->SetXY(xpos,ypos);}
-    void SetPsi(Float_t psi) {fPsi = psi;}
-
-    ClassDef(MDispCalc, 0) // task to calculate the Disp parameter and related positions
-};
-
-#endif
