Index: /trunk/MagicSoft/Mars/mtemp/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/Changelog	(revision 4094)
+++ /trunk/MagicSoft/Mars/mtemp/Changelog	(revision 4095)
@@ -18,4 +18,13 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+2004/05/18: Sebastian Commichau
+   * meth/MHillasSrc.cc/h
+     - Added. This is a modified version, containing now
+       the DCA parameter.
+
+   * meth/MDCACalc.cc/h, MDCA.cc/h
+     - Added. Based on MHillasCalc/MHillas, it calculates
+       the DCA parameter and provides a nice draw function
 
  2004/05/17: Daniel Mazin
Index: /trunk/MagicSoft/Mars/mtemp/meth/MDCA.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MDCA.cc	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MDCA.cc	(revision 4095)
@@ -0,0 +1,261 @@
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MDCA.cc                                                                 //
+// Container to store Hillas parameters and DCA stuff                      //
+//                                                                         //
+// Author(s): S.C. Commichau, L.S. Stark, 7/2003                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MDCA.h"
+
+using namespace std;
+
+ClassImp(MDCA); 
+
+// Default constructor
+MDCA::MDCA(const char *name, const char *title) : fXRef(0.0), fYRef(0.0)
+{
+    fName = name ? name : "MDCA";
+    fTitle = title ? title : "Storage container for Hillas parameters and DCA of one event";
+ 
+    Reset();
+   
+    fEllipse = new TEllipse;
+    fRefCircle = new TEllipse;
+    
+    fLineL = new TLine;
+    fLineW = new TLine;
+    fLineX = new TLine;
+    fLineY = new TLine;
+    fLineDCA = new TLine;
+    fLineMean = new TLine;
+  
+}
+
+// Destructor: Deletes ellipse and lines if they do exist
+
+MDCA::~MDCA()
+{
+    Clear();
+}
+
+// Initialize parameters with default values
+
+void MDCA::Reset()
+{
+
+    fLength = -1;
+    fWidth  = -1;
+    fDelta0 =  0;
+    fMeanX  =  0;
+    fMeanY  =  0;
+    fDelta1 =  0;
+    fDCA    = -1;
+    fX1W    =  0;
+    fY1W    =  0;
+    fX2W    =  0;
+    fY2W    =  0;
+    fX1L    =  0;
+    fY1L    =  0;
+    fX2L    =  0;
+    fY2L    =  0;
+    fXDCA   =  0;
+    fYDCA   =  0;
+  
+}
+
+
+// Print parameters to *fLog
+
+void MDCA::Print(Option_t *) const
+{
+    Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
+
+    if (atg<0)
+        atg += 180;
+
+    *fLog << all;
+    *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Length      [mm]  = " << fLength << endl;
+    *fLog << " - Width       [mm]  = " << fWidth  << endl;
+    *fLog << " - Delta0      [deg] = " << fDelta0*kRad2Deg << endl;
+    *fLog << " - Meanx       [mm]  = " << fMeanX  << endl;
+    *fLog << " - Meany       [mm]  = " << fMeanY  << endl;
+    *fLog << " - atg(y/x)    [deg] = " << atg     << endl;
+    *fLog << " - DCA         [mm]  = " << fDCA << endl;
+    *fLog << " - Delta1      [deg] = " << fDelta1*kRad2Deg << endl;
+
+    
+}
+
+void MDCA::Paint(Option_t *opt)
+{
+    Clear();
+
+    if (fLength<=0 || fWidth<=0) //fLength<0 || fWidth<0 doesn't look nice...
+        return;                  //We get a circle!
+
+    // Length line
+    fLineL = new TLine(fX1L, fY1L, fX2L, fY2L);
+    fLineL->SetLineWidth(2);
+    fLineL->SetLineColor(2);
+    fLineL->Draw();
+
+    // Width line
+    fLineW = new TLine(fX1W, fY1W, fX2W, fY2W);
+    fLineW->SetLineWidth(2);
+    fLineW->SetLineColor(2);
+    fLineW->Draw();
+
+    // Coordinate system
+    fLineX = new TLine(-600,fYRef,600,fYRef);
+    fLineY = new TLine(fXRef,-600,fXRef,600);
+    fLineX->SetLineWidth(2);
+    fLineX->SetLineColor(1);
+    fLineY->SetLineWidth(2);
+    fLineY->SetLineColor(1);
+    fLineX->Draw();
+    fLineY->Draw();
+    
+    // DCA line
+    fLineDCA = new TLine(fXRef,fYRef,fXDCA+fXRef,fYDCA+fYRef);
+    fLineDCA->SetLineWidth(2);
+    fLineDCA->SetLineColor(2);
+    fLineDCA->Draw();
+
+    // COG line
+    fLineMean = new TLine(fXRef,fYRef,fMeanX,fMeanY);
+    fLineMean->SetLineWidth(2);
+    fLineMean->SetLineColor(2);
+    fLineMean->Draw();
+
+    // Reference point marker
+    fRefCircle = new TEllipse(fXRef, fYRef, 5, 5, 0, 360, 0);
+    fRefCircle->SetLineColor(8);
+    fRefCircle->SetFillColor(8);
+    fRefCircle->Draw();
+
+    // Hillas ellipse
+    fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth, 0, 360, fDelta0*kRad2Deg+180);
+    fEllipse->SetLineWidth(2);
+    fEllipse->SetLineColor(2);
+    fEllipse->Draw();
+
+}
+
+
+// If an ellipse and lines exist they will be deleted 
+
+void MDCA::Clear(Option_t *)
+{
+    if (!fEllipse && !fRefCircle && !fLineL && !fLineW && !fLineX && !fLineY && !fLineDCA && !fLineMean) 
+        return;
+ 
+    delete fEllipse;
+    delete fRefCircle;
+    delete fLineL;
+    delete fLineW;
+    delete fLineX;
+    delete fLineY;
+    delete fLineDCA;
+    delete fLineMean;
+     
+    fLineL = NULL;
+    fLineX = NULL;
+    fLineY = NULL;
+    fLineW = NULL;
+    fLineDCA = NULL;
+    fLineMean = NULL;
+    fEllipse = NULL;
+    fRefCircle = NULL;
+}
+
+
+Int_t MDCA::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hil)
+{
+    // Get basic Hillas parameters from MHillas
+    fDelta0 = hil.GetDelta();
+    fMeanX  = hil.GetMeanX();
+    fMeanY  = hil.GetMeanY();
+    fLength = hil.GetLength();
+    fWidth  = hil.GetWidth();
+
+    // The Length Line - rotation and shift
+    fX1L = - (fLength+OffsetL)*cos(fDelta0) + fMeanX; // [mm]    
+    fY1L = - (fLength+OffsetL)*sin(fDelta0) + fMeanY; // [mm]    
+    fX2L =   (fLength+OffsetL)*cos(fDelta0) + fMeanX; // [mm]    
+    fY2L =   (fLength+OffsetL)*sin(fDelta0) + fMeanY; // [mm]
+
+    // The Width Line - rotation and shift
+    fX1W =   (fWidth+OffsetW)*sin(fDelta0) + fMeanX;  // [mm]   
+    fY1W = - (fWidth+OffsetW)*cos(fDelta0) + fMeanY;  // [mm]   
+    fX2W = - (fWidth+OffsetW)*sin(fDelta0) + fMeanX;  // [mm]   
+    fY2W =   (fWidth+OffsetW)*cos(fDelta0) + fMeanY;  // [mm]  
+
+    // Vector of orientation of the shower axis
+    fr1 = fX2L-fX1L;  
+    fr2 = fY2L-fY1L;  
+       
+    // Determine parameters to calculate coordinates of the DCA vector
+    flambda = (fr1*(fXRef-fMeanX) + fr2*(fYRef-fMeanY))/(fr1*fr1 + fr2*fr2);
+    fmu = (fMeanY-fYRef)/fr1 + flambda*fr2/fr1;
+
+    // Components of the DCA vector
+    fXDCA = -fmu*fr2;
+    fYDCA =  fmu*fr1;
+  
+    // Components of vector going from intersection point of the DCA vector
+    // with the shower axis to the COG
+    fd1 = fMeanX + fmu*fr2 - fXRef;
+    fd2 = fMeanY - fmu*fr1 - fYRef;
+
+    // Calculate DCA value 
+    fDCA = sqrt(fXDCA*fXDCA + fYDCA*fYDCA);
+
+    // Calculate angle of the shower axis with respect to the x-axis
+    fDelta1 = acos(fd1/sqrt(fd1*fd1 + fd2*fd2));
+
+    // Calculate angle of the shower axis with respect to the y-axis
+    //fDelta1 = acos(fd2/sqrt(fd1*fd1 + fd2*fd2)); 
+
+    // Determine the correct sign of the DCA (cross product of DCA vector and 
+    // vector going from the intersection point of the DCA vector with the shower axis
+    // to the COG)
+    if((fmu*(-fr2*(fMeanY-fYRef)-fr1*(fMeanX-fXRef)))<0)
+       fDCA = -fDCA;    
+
+    gRandom->Rannor(gx,gy);
+    gx = fabs(gx);
+  
+    // This is nice but does not remove the systematics in the profile plot...
+    //if(((1-0.6*gx)*(180-kRad2Deg*fDelta1)>120) || ((1-0.6*gx)*kRad2Deg*fDelta1>120))
+      // fDCA = -1;
+
+    // Enlarge the interval of Delta correctly...
+    if((fMeanY-fYRef-fmu*fr1)<0)
+       fDelta1 = TwoPi-fDelta1;
+
+    // Enlarge the interval of Delta correctly... (Delta with respect to the y-axis)
+    // if(-(fMeanX-fXRef+fmu*fr2)<0)
+     //  fDelta1 = TwoPi-fDelta1;
+
+    // This has to be improved...
+    if(fr1 == 0 || fr2 == 0 || (fr1*fr1+fr2*fr2) == 0 || sqrt(fd1*fd1+fd2*fd2) == 0)
+       fDCA = -fDCA;
+
+    SetReadyToSave();
+   
+    return 0;
+}
+
+void MDCA::SetRefPoint(const Float_t fXRef0, const Float_t fYRef0)
+{
+    fXRef = fXRef0;
+    fYRef = fYRef0;
+}
+
+
+
+
Index: /trunk/MagicSoft/Mars/mtemp/meth/MDCA.h
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MDCA.h	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MDCA.h	(revision 4095)
@@ -0,0 +1,118 @@
+#ifndef MARS_MDCA 
+#define MARS_MDCA
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MDCA.cc                                                                 //
+// Container to store the DCA stuff                                        //
+//                                                                         //
+// Author(s): S.C. Commichau, L.S. Stark, 7/2003                           //
+//                                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include <TArrayF.h>
+#include <TEllipse.h>
+#include <TLine.h>
+#include <TCanvas.h>
+#include <TROOT.h>
+#include <TStyle.h> 
+#include <TMath.h>
+#include <math.h>
+#include <TPad.h>
+#include <TRandom.h>
+#include <TRandom2.h>
+#include <fstream>
+#include <iostream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+#include "MHillas.h"
+
+// Add offsets to the Width and Length to draw nice lines
+#define OffsetW 20.0
+#define OffsetL 440.0
+
+#define kmm2Deg 0.00317460317
+#define TwoPi 6.28318530717958623 
+
+class TArrayF;
+class TEllipse;
+class MGeoCam;
+class MCerPhotEvt;
+class MHillas;
+
+class MDCA : public MParContainer
+{
+ private:
+    
+    Float_t fLength;  // [mm]   major axis of ellipse
+    Float_t fWidth;   // [mm]   minor axis of ellipse
+    Float_t fDelta0;  // [rad]  angle of major axis with x-axis (-Pi/2 .. Pi/2)
+    Float_t fDelta1;  // [rad]  my angle of major axis with x-axis (0 .. 2*Pi)
+    Float_t fMeanX;   // [mm]   x-coordinate of center of ellipse
+    Float_t fMeanY;   // [mm]   y-coordinate of center of ellipse
+    Float_t fX1W;     // [mm]   x-coordinate of 1st point of Lline
+    Float_t fY1W;     // [mm]   y-coordinate of 1st point of Lline
+    Float_t fX2W;     // [mm]   x-coordinate of 2nd point of Lline
+    Float_t fY2W;     // [mm]   y-coordinate of 2nd point of Lline
+    Float_t fX1L;     // [mm]   x-coordinate of 1st point of Wline
+    Float_t fY1L;     // [mm]   y-coordinate of 1st point of Wline
+    Float_t fX2L;     // [mm]   x-coordinate of 2nd point of Wline
+    Float_t fY2L;     // [mm]   y-coordinate of 2nd point of Wline
+    Double_t fDCA;    // [mm]   Distance of Cloasest Approach 
+    Float_t fXDCA;    // [mm]   x-coordinate of 2nd point of the DCA-line 
+    Float_t fYDCA;    // [mm]   y-coordinate of 2nd point of the DCA-line  
+    Float_t fXRef;    // [mm]   x-coordinate of reference point
+    Float_t fYRef;    // [mm]   y-coordinate of reference point
+    Float_t fmu;
+    Float_t flambda;  
+    Float_t fr1, fr2; // [mm] Coordinates of the orientation vector of the shower axis
+    Float_t fd1, fd2; // [mm] Coordinates of the DCA vector
+    Float_t gx, gy;
+   
+    TEllipse *fEllipse;   // Graphical object to draw the ellipse, ROOT!
+    TEllipse *fRefCircle; // To draw reference point
+
+    TLine *fLineL;        // Shower axis
+    TLine *fLineW;        // Line perpendicular to the shower axis
+    TLine *fLineX;        // x-axis of the coordinate system 
+    TLine *fLineY;        // y-axis of the coordinate system  
+    TLine *fLineDCA;      // DCA line
+    TLine *fLineMean;     // Line to COG of the shower 
+
+ public:
+    MDCA(const char *name=NULL, const char *title=NULL);
+
+    ~MDCA();
+
+    void Reset();
+
+    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix, const MHillas &hil);
+
+    void Print(Option_t *opt=NULL) const;
+
+    void Paint(Option_t *opt=NULL);
+
+    void Clear(Option_t *opt=NULL);
+
+    void SetRefPoint(const Float_t fXRef0, const Float_t fYRef0);
+    
+    Float_t GetDCA() const { return fDCA; }
+ 
+    Float_t GetDelta() const { return fDelta1; }
+
+    ClassDef(MDCA, 1) 
+
+};
+
+#endif
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.cc	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.cc	(revision 4095)
@@ -0,0 +1,96 @@
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MDCACalc.cc                                                             //
+//                                                                         //
+// Author(s): S.C. Commichau, L.S. Stark, 7/2003                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MDCACalc.h"
+
+ClassImp(MDCACalc);
+
+using namespace std; 
+
+MDCACalc::MDCACalc(const char *name, const char *title)
+    : fDCAName("MDCA"), fFlags(0xff)
+{
+    fName  = name  ? name  : "MDCACalc";
+    fTitle = title ? title : "Calculate Hillas, DCA and other image parameters";
+    
+}
+
+Int_t MDCACalc::PreProcess(MParList *pList)
+{
+    fErrors = 0;
+
+    fCerPhotEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
+    if (!fCerPhotEvt)
+    {
+        *fLog << err << "MCerPhotEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+    if (!fGeomCam)
+    {
+        *fLog << err << "MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
+        return kFALSE;
+    }
+
+    fHillas = (MHillas*)pList->FindObject(AddSerialNumber("MHillas"));
+    if (!fHillas)
+    {
+        *fLog << err << "MHillas missing in Parameter List... aborting." << endl;
+        return kFALSE;
+    }
+
+    if (TestFlag(kCalcDCA))
+        fMDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
+    else
+    {
+        fMDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
+        *fLog << err << fDCAName << " [MDCA] not found... aborting." << endl;
+    }
+    if (!fMDCA)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// If the calculation wasn't sucessfull skip this event
+
+Int_t MDCACalc::Process()
+{
+
+    if (TestFlag(kCalcDCA))
+    {
+        Int_t rc = fMDCA->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
+          
+
+	if (rc == -1)
+        {
+	    fErrors++;
+            *fLog << err << dbginf << "MDCA::Calc returned ... error!" << endl;
+            return kFALSE;
+        }
+   }
+   
+    return kTRUE;
+}
+
+Int_t MDCACalc::PostProcess()
+{
+
+    *fLog << fErrors << " errors occured..." << endl;
+    *fLog << endl;
+
+    return kTRUE;
+} 
+
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.h	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MDCACalc.h	(revision 4095)
@@ -0,0 +1,69 @@
+
+#ifndef MARS_MDCACalc
+#define MARS_MDCACalc
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MDCACalc.h                                                              // 
+//                                                                         //
+// Author(s): S.C. Commichau, L.S.Stark, 7/2003                            //
+//                                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MTask.h"
+#include "MParList.h"
+#include "MDCA.h"
+#include "MCerPhotEvt.h"
+#include "MLog.h"
+#include "MLogManip.h"
+#include "MHillasCalc.h"
+
+class MGeomCam;
+class MCerPhotEvt;
+class MDCA;
+
+class MDCACalc : public MTask
+{
+    const MGeomCam    *fGeomCam;    // Camera Geometry used to calculate Hillas
+    const MCerPhotEvt *fCerPhotEvt; // Cerenkov Photon Event used for calculation
+    const MHillas     *fHillas;
+
+    MDCA        *fMDCA;  // Output container to store the result
+
+    TString      fDCAName;
+
+    Double_t par[6];
+    Double_t dca;
+
+    Int_t    fErrors;
+    Int_t    fFlags;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
+
+public:
+     enum CalcCont_t {
+        kCalcDCA      = BIT(0),
+    };
+
+     MDCACalc(const char *name=NULL, const char *title=NULL);
+
+    void SetNameDCA(const char *name)    { fDCAName = name; }
+
+    void SetFlags(Int_t f) { fFlags  =  f; }
+    void Enable(Int_t f)   { fFlags |=  f; }
+    void Disable(Int_t f)  { fFlags &= ~f; }
+    Bool_t TestFlag(CalcCont_t i) const { return fFlags&i; }
+    
+    
+    ClassDef(MDCACalc, 0) // Task to calculate DCA 
+};
+
+#endif
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.cc	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.cc	(revision 4095)
@@ -0,0 +1,231 @@
+/* ======================================================================== *\
+!
+! *
+! * 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        12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Harald Kornmayer    01/2001
+!   Author(s): Rudolf Bock         10/2001 <mailto:Rudolf.Bock@cern.ch>
+!   Author(s): Wolfgang Wittek     06/2002 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Sabrina Stark       05/2004 <mailto:stark@particle.phys.ethz.ch> 
+!   Author(s): Sebastian Commichau 05/2004 <mailto:commichau@particle.phys.ethz.ch>  
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHillasSrc
+//
+// Storage Container for image parameters
+//
+//    source-dependent image parameters
+//
+//
+// Version 1:
+// ----------
+//  fAlpha          angle between major axis and line source-to-center
+//  fDist           distance from source to center of ellipse
+//
+//
+// Version 2:
+// ----------
+//  fHeadTail       added
+//
+//
+// Version 3:
+// ----------
+//  fCosDeltaAlpha  cosine of angle between d and a, where
+//                   - d is the vector from the source position to the
+//                     center of the ellipse
+//                   - a is a vector along the main axis of the ellipse,
+//                     defined with positive x-component
+//
+//
+// Version 4:
+// ----------
+//
+// fHeadTail        removed
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHillasSrc.h"
+
+#include <fstream>
+#include <TArrayF.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MSrcPosCam.h"
+
+ClassImp(MHillasSrc);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MHillasSrc::MHillasSrc(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MHillasSrc";
+    fTitle = title ? title : "Parameters depending in source position";
+}
+
+void MHillasSrc::Reset()
+{
+    fDist          = -1;
+    fAlpha         =  0;
+    fCosDeltaAlpha =  0;
+    fDCA           =  0;
+    fDDCA           = 0;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Calculation of source-dependent parameters
+//  In case you don't call Calc from within an eventloop make sure, that
+//  you call the Reset member function before.
+//
+Bool_t MHillasSrc::Calc(const MHillas *hillas)
+{
+    const Double_t mx = hillas->GetMeanX();     // [mm]
+    const Double_t my = hillas->GetMeanY();     // [mm]
+
+    const Double_t sx = mx - fSrcPos->GetX();   // [mm]
+    const Double_t sy = my - fSrcPos->GetY();   // [mm]
+
+    //
+    // DCA: Distance of Closest Approach.
+    // Minimal distance from the shower axis to a reference point.
+
+    Double_t fDdca = hillas->GetDelta();
+    
+    // Distance between intersection point (DCA vector and the shower axis) and COG.
+    const Double_t fl = -(sx*TMath::Cos(fDdca) + sy*TMath::Sin(fDdca));
+
+    // Components of DCA vector
+    const Double_t fpd1 = TMath::Cos(fDdca)*fl+sx;
+    const Double_t fpd2 = TMath::Sin(fDdca)*fl+sy;
+
+    // Calculate DCA value 
+    Double_t fdca = sqrt(fpd1*fpd1 + fpd2*fpd2);
+
+    // Determine the correct sign of the DCA (cross product of DCA vector and the
+    // vector going from the intersection point of the DCA vector with the shower axis
+    // to the COG)
+    if ((sx-fpd1)*fpd2-(sy-fpd2)*fpd1<0.)
+      fdca = -fdca;
+
+    // Calculate angle of the shower axis with respect to the x-axis
+    fDdca = TMath::ACos((sx-fpd1)/TMath::Abs(fl));
+
+    // Enlarge the interval of fDdca to [0, 2pi]
+    if((sy-fpd2)<0)
+       fDdca = 360/kRad2Deg-fDdca;
+
+
+    //
+    // Distance from source position to center of ellipse.
+    // If the distance is 0 distance, Alpha is not specified.
+    // The calculation has failed and returnes kFALSE.
+    //
+    const Double_t dist = sqrt(sx*sx + sy*sy);  // [mm]
+    if (dist==0)
+        return kFALSE;
+
+    // Calculate Alpha and Cosda = cos(d,a)
+    // The sign of Cosda will be used for quantities containing 
+    // a head-tail information
+    //
+    // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
+    // *OLD* fAlpha = asin(arg)*kRad2Deg;
+    //
+    //    const Double_t arg1 = cd*sy-sd*sx;          // [mm]  ... equal abs(fdca)
+    //    const Double_t arg2 = cd*sx+sd*sy;          // [mm]  ... equal abs(fl)
+    const Double_t arg1 = TMath::Abs(fdca);          // [mm]  
+    const Double_t arg2 = TMath::Abs(fl);          // [mm] 
+
+    //
+    // Due to numerical uncertanties in the calculation of the
+    // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
+    // that the absolute value of arg exceeds 1. Because this uncertainty
+    // results in an Delta Alpha which is still less than 1e-3 we don't care
+    // about this uncertainty in general and simply set values which exceed
+    // to 1 saving its sign.
+    //
+    const Double_t arg = arg1/dist;
+    fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : asin(arg)*kRad2Deg;  // [deg]
+
+    fCosDeltaAlpha = arg2/dist;                 // [1]
+    fDist          = dist;                      // [mm]
+    fDCA = fdca;                                // [mm]
+    fDDCA = fDdca;                              // [rad]
+
+    SetReadyToSave();
+
+    return kTRUE;
+} 
+
+// --------------------------------------------------------------------------
+//
+// Print contents of MHillasSrc to *fLog
+//
+void MHillasSrc::Print(Option_t *) const
+{
+    *fLog << all;
+    *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Dist           [mm]  = " << fDist << endl;
+    *fLog << " - Alpha          [deg] = " << fAlpha << endl;
+    *fLog << " - CosDeltaAlpha        = " << fCosDeltaAlpha << endl;
+    *fLog << " - DCA            [mm]  = " << fDCA << endl;
+    *fLog << " - DeltaDCA       [mm]  = " << fDDCA << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print contents of MHillasSrc to *fLog depending on the geometry in
+// units of deg.
+//
+void MHillasSrc::Print(const MGeomCam &geom) const
+{
+    *fLog << all;
+    *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Dist           [deg] = " << fDist*geom.GetConvMm2Deg() << endl;
+    *fLog << " - Alpha          [deg] = " << fAlpha << endl;
+    *fLog << " - CosDeltaAlpha        = " << fCosDeltaAlpha << endl;
+    *fLog << " - DCA            [deg] = " << fDCA*geom.GetConvMm2Deg() << endl;
+    *fLog << " - DeltaDCA       [mm]  = " << fDDCA << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// This function is ment for special usage, please never try to set
+// values via this function
+//
+void MHillasSrc::Set(const TArrayF &arr)
+{
+    if (arr.GetSize() != 5)
+        return;
+
+    fAlpha = arr.At(0);         // [deg]  angle of major axis with vector to src
+    fDist  = arr.At(1);         // [mm]   distance between src and center of ellipse
+    fCosDeltaAlpha = arr.At(2); // [1]    cosine of angle between d and a
+    fDCA   = arr.At(3);         // [mm]   distance between ref. point and shower axis
+    fDDCA   = arr.At(4);         // [rad] angle between shower axis and x-axis
+}
Index: /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.h
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.h	(revision 4095)
+++ /trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.h	(revision 4095)
@@ -0,0 +1,45 @@
+#ifndef MARS_MHillasSrc
+#define MARS_MHillasSrc
+
+#ifndef MARS_MHillas
+#include "MHillas.h"
+#endif
+
+class MSrcPosCam;
+
+class MHillasSrc : public MParContainer
+{
+private:
+    const MSrcPosCam *fSrcPos; //! Source position in the camere
+
+    Float_t fAlpha;         // [deg]  angle of major axis with vector to src
+    Float_t fDist;          // [mm]   distance between src and center of ellipse
+    Float_t fDCA;          // [mm]   distance between ref. point and shower axis
+    Float_t fDDCA;          // [rad]  angle between major axis and x-axis [0, 2*pi]
+    Float_t fCosDeltaAlpha; // [1]    cosine of angle between d and a
+
+public:
+    MHillasSrc(const char *name=NULL, const char *title=NULL);
+
+    void SetSrcPos(const MSrcPosCam *pos) { fSrcPos = pos; }
+    const MSrcPosCam *GetSrcPos() const   { return fSrcPos; }
+
+    void Reset();
+
+    Float_t GetAlpha()         const { return fAlpha; }
+    Float_t GetDist()          const { return fDist; }
+    Float_t GetDCA()          const { return fDCA; }
+    Float_t GetDDCA()          const { return fDDCA; }
+    Float_t GetCosDeltaAlpha() const { return fCosDeltaAlpha; }
+
+    void Print(Option_t *opt=NULL) const;
+    void Print(const MGeomCam &geom) const;
+
+    virtual Bool_t Calc(const MHillas *hillas);
+
+    void Set(const TArrayF &arr);
+
+    ClassDef(MHillasSrc, 5) // Container to hold source position dependant parameters
+};
+
+#endif
