Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1203)
@@ -21,5 +21,9 @@
 #pragma link C++ class MMcPedestalNSBAdd+;
 
+#pragma link C++ class MSrcPosCam+;
 #pragma link C++ class MHillas+;
+#pragma link C++ class MHillasSrc+;
+#pragma link C++ class MHillasSrcCalc+;
+#pragma link C++ class MHillasExt+;
 #pragma link C++ class MHillasCalc+;
 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1203)
@@ -32,4 +32,8 @@
 
 #include "MLog.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
 #include "MHexagon.h"
 
@@ -148,16 +152,25 @@
 // --------------------------------------------------------------------------
 //
-// get the minimum number of photons of all valid pixels in the list
-//
-Float_t MCerPhotEvt::GetNumPhotonsMin() const
+// get the minimum number of photons  of all valid pixels in the list
+// If you specify a geometry the number of photons is weighted with the
+// area of the pixel
+//
+Float_t MCerPhotEvt::GetNumPhotonsMin(const MGeomCam *geom) const
 {
     if (fNumPixels <= 0)
         return -5.;
 
+    const Float_t A0 = geom ? (*geom)[0].GetA() : 0;
+
     Float_t minval = (*this)[0].GetNumPhotons();
 
     for (UInt_t i=1; i<fNumPixels; i++)
     {
-        const Float_t testval = (*this)[i].GetNumPhotons();
+        const MCerPhotPix &pix = (*this)[i];
+
+        Float_t testval = pix.GetNumPhotons();
+
+        if (geom)
+            testval *= A0/(*geom)[pix.GetPixId()].GetA();
 
         if (testval < minval)
@@ -171,15 +184,23 @@
 //
 // get the maximum number of photons of all valid pixels in the list
-//
-Float_t MCerPhotEvt::GetNumPhotonsMax() const
+// If you specify a geometry the number of photons is weighted with the
+// area of the pixel
+//
+Float_t MCerPhotEvt::GetNumPhotonsMax(const MGeomCam *geom) const
 {
     if (fNumPixels <= 0)
         return 50.;
 
+    const Float_t A0 = geom ? (*geom)[0].GetA() : 0;
     Float_t maxval = (*this)[0].GetNumPhotons();
 
     for (UInt_t i=1; i<fNumPixels; i++)
     {
-        const Float_t testval = (*this)[i].GetNumPhotons();
+        const MCerPhotPix &pix = (*this)[i];
+
+        Float_t testval = pix.GetNumPhotons();
+
+        if (geom)
+            testval *= A0/(*geom)[pix.GetPixId()].GetA();
 
         if (testval > maxval)
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1203)
@@ -9,4 +9,5 @@
 #endif
 
+class MGeomCam;
 class MCerPhotPix;
 
@@ -34,6 +35,6 @@
     Bool_t  IsPixelCore    (Int_t id) const;
 
-    Float_t GetNumPhotonsMin() const;
-    Float_t GetNumPhotonsMax() const;
+    Float_t GetNumPhotonsMin(const MGeomCam *geom=NULL) const;
+    Float_t GetNumPhotonsMax(const MGeomCam *geom=NULL) const;
 
     MCerPhotPix &operator[](int i)       { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
Index: trunk/MagicSoft/Mars/manalysis/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1203)
@@ -16,6 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
+!   Author(s): Thomas Bretz    12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Harald Kornmayer 1/2001
+!   Author(s): Rudolf Bock     10/2001 <mailto:Rudolf.Bock@cern.ch>
 !
 !   Copyright: MAGIC Software Development, 2000-2001
@@ -25,19 +26,20 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MHillas                                                                 //
-//                                                                         //
-// Storage Container for the Hillas parameter                              //
-//                                                                         //
-// FIXME: - Here everybody should find an explanation of the parameters    //
-//        - using boooleans for fIsPixelUsed, fIsPixelCore, ... is rather  //
-//          slow because you have to loop over all pixels in any loop.     //
-//          There could be a huge speed improvement using Hash Tables      //
-//          (linked lists, see THashTable and THashList, too)              //
-//                                                                         //
+//
+// MHillas
+//
+// Storage Container for image parameters
+//
+//    basic image parameters
+// fLength   major axis of ellipse
+// fWidth    minor axis
+// fDelta    angle of major axis wrt x-axis
+// fSize     total sum of pixels
+// fMeanx    x of center of ellipse
+// fMeany    y of center of ellipse
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MHillas.h"
 
-#include <math.h>
 #include <fstream.h>
 
@@ -51,4 +53,5 @@
 
 #include "MLog.h"
+#include "MLogManip.h"
 
 ClassImp(MHillas);
@@ -61,8 +64,10 @@
 {
     fName  = name  ? name  : "MHillas";
-    fTitle = title ? title : "Storage container for Hillas parameter of one event";
+    fTitle = title ? title : "Storage container for image parameters of one event";
 
     Reset();
     // FIXME: (intelligent) initialization of values missing
+
+    fEllipse = new TEllipse;
 }
 
@@ -76,12 +81,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
 void MHillas::Reset()
 {
-    fAlpha  = 0;
-    fTheta  = 0;
+    fLength = 0;
     fWidth  = 0;
-    fLength = 0;
+    fDelta  = 0;
     fSize   = 0;
-    fDist   = 0;
+    fMeanx  = 0;
+    fMeany  = 0;
 
     Clear();
@@ -94,69 +101,88 @@
 void MHillas::Print(Option_t *) const
 {
-    *fLog << "Hillas Parameter: " << GetDescriptor() << endl;
-    *fLog << " - Alpha  = " << fabs(fAlpha) << " deg" << endl;
-    *fLog << " - Width  = " << fWidth  << " mm"       << endl;
-    *fLog << " - Length = " << fLength << " mm"       << endl;
-    *fLog << " - Size   = " << fSize   << " #CerPhot" << endl;
-    *fLog << " - Dist   = " << fDist   << " mm"       << endl;
+    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 << " - Meanx    [mm]  = " << fMeanx  << endl;
+    *fLog << " - Meany    [mm]  = " << fMeany  << endl;
+    *fLog << " - Delta    [deg] = " << fDelta*kRad2Deg << endl;
+    *fLog << " - atg(y/x) [deg] = " << atg     << endl;
+    *fLog << " - Size     [1]   = " << fSize   << " #CherPhot"   << endl;
 }
 
 /*
-// --------------------------------------------------------------------------
+// -----------------------------------------------------------
 //
 // call the Paint function of the Ellipse if a TEllipse exists
 //
 void MHillas::Paint(Option_t *)
+{
+     fEllipse->SetLineWidth(2);
+     fEllipse->PaintEllipse(fMeanx, fMeany, fLength, fWidth,
+                            0, 360, fDelta*kRad2Deg+180);
+}
+*/
+
+// --------------------------------------------------------------------------
+//
+// Instead of adding MHillas itself to the Pad
+// (s. AppendPad in TObject) we create an ellipse,
+// which is added to the Pad by its Draw function
+// You can remove it by deleting the Ellipse Object
+// (s. Clear() )
+//
+void MHillas::Draw(Option_t *opt)
+{
+
+    Clear();
+
+    fEllipse = new TEllipse(fMeanx, fMeany, fLength, fWidth,
+                            0, 360, fDelta*kRad2Deg+180);
+
+    fEllipse->SetLineWidth(2);
+    fEllipse->Draw();
+
+    /*
+     fEllipse->SetPhimin();
+     fEllipse->SetPhimax();
+     fEllipse->SetR1(fLength);
+     fEllipse->SetR2(fWidth);
+     fEllipse->SetTheta(fDelta*kRad2Deg+180);
+     fEllipse->SetX1(fMeanx);
+     fEllipse->SetY1(fMeany);
+
+     fEllipse->SetLineWidth(2);
+     fEllipse->PaintEllipse(fMeanx, fMeany, fLength, fWidth,
+                            0, 360, fDelta*kRad2Deg+180);
+
+      AppendPad(opt);
+
+     // This is from TH1
+     TString opt = option;
+     opt.ToLower();
+     if (gPad && !opt.Contains("same")) {
+        //the following statement is necessary in case one attempts to draw
+        //a temporary histogram already in the current pad
+      if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
+      gPad->Clear();
+      }
+      */
+}
+
+// --------------------------------------------------------------------------
+//
+// If a TEllipse object exists it is deleted
+//
+void MHillas::Clear(Option_t *)
 {
     if (!fEllipse)
         return;
 
-    fEllipse->Paint();
-}
-*/
-
-// --------------------------------------------------------------------------
-//
-// Instead of adding MHillas itself to the Pad
-// (s. AppendPad in TObject) we create an ellipse,
-// which is added to the Pad by it's Draw function
-// You can remove it by deleting the Ellipse Object
-// (s. Clear() )
-//
-void MHillas::Draw(Option_t *opt)
-{
-    Clear();
-
-    fEllipse = new TEllipse(cos(fTheta)*fDist, sin(fTheta)*fDist,
-                            fLength, fWidth,
-                            0, 360, fTheta*kRad2Deg+fAlpha-180);
-
-    fEllipse->SetLineWidth(2);
-    fEllipse->Draw();
-    //AppendPad(opt);
-
-    /*
-     This is from TH1
-     TString opt = option;
-   opt.ToLower();
-   if (gPad && !opt.Contains("same")) {
-      //the following statement is necessary in case one attempts to draw
-      //a temporary histogram already in the current pad
-      if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
-      gPad->Clear();
-   }
-   AppendPad(opt.Data());
-   */
-}
-
-// --------------------------------------------------------------------------
-//
-// If a TEllipse object exists it is deleted
-//
-void MHillas::Clear(Option_t *)
-{
-    if (!fEllipse)
-        return;
-
     delete fEllipse;
 
@@ -164,31 +190,33 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// Calculate the Hillas parameters from a cerenkov photon event
-// (The calcualtion is some kind of two dimentional statistics)
-//
-//   FIXME: MHillas::Calc is rather slow at the moment because it loops
-//          unnecessarily over all pixels in all its loops (s.MImgCleanStd)
-//          The speed could be improved very much by using Hash-Tables
-//          (linked lists, see THashTable and THashList, too)
+
+// --------------------------------------------------------------------------
+//
+// Calculate the image parameters from a Cherenkov photon event
+// assuming Cher.photons/pixel and pixel coordinates are given
 //
 Bool_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
 {
-    const UInt_t nevt = evt.GetNumPixels();
+    // FIXME: MHillas::Calc is rather slow at the moment because it loops
+    //    unnecessarily over all pixels in all its loops (s.MImgCleanStd)
+    //    The speed could be improved very much by using Hash-Tables
+    //    (linked lists, see THashTable and THashList, too)
+    //
+
+    const UInt_t npixevt = evt.GetNumPixels();
 
     //
     // sanity check
     //
-    if (nevt <= 2)
+    if (npixevt <= 2)
         return kFALSE;
 
     //
-    // calculate mean valu of pixels
-    //
-    float xmean =0;
-    float ymean =0;
-
-    fSize = 0;
+    // calculate mean value of pixel coordinates and fSize
+    // -----------------------------------------------------
+    //
+    fMeanx = 0;
+    fMeany = 0;
+    fSize  = 0;
 
     //
@@ -196,5 +224,5 @@
     //
     UShort_t npix=0;
-    for (UInt_t i=0; i<nevt; i++)
+    for (UInt_t i=0; i<npixevt; i++)
     {
         const MCerPhotPix &pix = evt[i];
@@ -207,7 +235,7 @@
         const float nphot = pix.GetNumPhotons();
 
-        fSize += nphot;
-        xmean += nphot * gpix.GetX(); // [mm]
-        ymean += nphot * gpix.GetY(); // [mm]
+        fSize  += nphot;		             // [counter]
+        fMeanx += nphot * gpix.GetX();               // [mm]
+        fMeany += nphot * gpix.GetY();               // [mm]
 
         npix++;
@@ -220,15 +248,16 @@
         return kFALSE;
 
-    xmean /= fSize; // [mm]
-    ymean /= fSize; // [mm]
-
-    //
-    // calculate sdev
-    //
-    float sigmaxx=0;
-    float sigmaxy=0;
-    float sigmayy=0;
-
-    for (UInt_t i=0; i<nevt; i++)
+    fMeanx /= fSize;                                 // [mm]
+    fMeany /= fSize;                                 // [mm]
+
+    //
+    // calculate 2nd moments
+    // -------------------
+    //
+    float corrxx=0;                                  // [m^2]
+    float corrxy=0;                                  // [m^2]
+    float corryy=0;                                  // [m^2]
+
+    for (UInt_t i=0; i<npixevt; i++)
     {
         const MCerPhotPix &pix = evt[i];
@@ -238,63 +267,34 @@
 
         const MGeomPix &gpix = geom[pix.GetPixId()];
-
-        const float dx = gpix.GetX() - xmean;
-        const float dy = gpix.GetY() - ymean;
-
-        const float nphot = pix.GetNumPhotons();
-
-        sigmaxx += nphot * dx*dx; // [mm^2]
-        sigmaxy += nphot * dx*dy; // [mm^2]
-        sigmayy += nphot * dy*dy; // [mm^2]
+        const float dx = gpix.GetX() - fMeanx;       // [mm]
+        const float dy = gpix.GetY() - fMeany;       // [mm]
+
+        const float nphot = pix.GetNumPhotons();     // [#phot]
+
+        corrxx += nphot * dx*dx;                     // [mm^2]
+        corrxy += nphot * dx*dy;                     // [mm^2]
+        corryy += nphot * dy*dy;                     // [mm^2]
     }
 
     //
-    // check for orientation
-    //
-    const float theta = atan(sigmaxy/(sigmaxx-sigmayy)*2)/2;
-
-    float c = cos(theta); // [1]
-    float s = sin(theta); // [1]
-
-    //
-    // calculate the length of the two axis
-    //
-    float axis1 =  2.0*c*s*sigmaxy + c*c*sigmaxx + s*s*sigmayy; // [mm^2]
-    float axis2 = -2.0*c*s*sigmaxy + s*s*sigmaxx + c*c*sigmayy; // [mm^2]
-
-    axis1 /= fSize; // [mm^2]
-    axis2 /= fSize; // [mm^2]
-
-    //
-    // check for numerical negatives
-    // (very small number can get negative by chance)
-    //
+    // calculate the basic Hillas parameters: orientation and size of axes
+    // -------------------------------------------------------------------
+    //
+    const float d = corryy - corrxx;
+
+    fDelta = atan2(d + sqrt(d*d + corrxy*corrxy*4), corrxy*2);
+
+    fCosDelta = cos(fDelta);   // need these in derived classes
+    fSinDelta = sin(fDelta);   // like MHillasExt
+
+    float axis1 = ( fCosDelta*fSinDelta*corrxy*2 + fCosDelta*fCosDelta*corrxx + fSinDelta*fSinDelta*corryy) / fSize; // [mm^2]
+    float axis2 = (-fCosDelta*fSinDelta*corrxy*2 + fSinDelta*fSinDelta*corrxx + fCosDelta*fCosDelta*corryy) / fSize; // [mm^2]
+ 
+    // very small numbers can get negative by rounding
     if (axis1 < 0) axis1=0;
-    if (axis2 < 0) axis2=0;
-
-    //
-    // calculate the main Hillas parameters
-    //
-    // fLength, fWidth describes the two axis of the ellipse
-    // fAlpha is the angle between the length-axis and the center
-    //    of the camera
-    // fDist is the distance between the center of the camera and the
-    //    denter of the ellipse
-    //
-    const int rotation = axis1<axis2;
-
-    fLength = rotation ? sqrt(axis2) : sqrt(axis1);  // [mm]
-    fWidth  = rotation ? sqrt(axis1) : sqrt(axis2);  // [mm]
-
-    const float a = c*xmean + s*ymean;
-    const float b = c*ymean - s*xmean;
-
-    fAlpha  = rotation ? atan(a/b) : atan(-b/a);     // [rad]
-    fAlpha *= kRad2Deg;                              // [deg]
-
-    fDist   = sqrt(xmean*xmean + ymean*ymean);       // [mm]
-
-    fTheta  = atan(ymean/xmean);                     // [rad]
-    if (xmean<0) fTheta += kPI;                      // [rad]
+    if (axis2 < 0) axis2=0; 
+
+    fLength = sqrt(axis1);  // [mm]
+    fWidth  = sqrt(axis2);  // [mm]
 
     SetReadyToSave();
@@ -303,21 +303,25 @@
 }
 
+// --------------------------------------------------------------------------
+//
 void MHillas::AsciiRead(ifstream &fin)
 {
-    fin >> fAlpha;
-    fin >> fTheta;
+    fin >> fLength;
     fin >> fWidth;
-    fin >> fLength;
+    fin >> fDelta;
     fin >> fSize;
-    fin >> fDist;
-}
-
+    fin >> fMeanx;
+    fin >> fMeany;
+}
+
+// --------------------------------------------------------------------------
+//
 void MHillas::AsciiWrite(ofstream &fout) const
 {
-    fout << fAlpha << " ";
-    fout << fTheta << " ";
-    fout << fWidth << " ";
     fout << fLength << " ";
-    fout << fSize << " ";
-    fout << fDist << endl;
-}
+    fout << fWidth  << " ";
+    fout << fDelta  << " ";
+    fout << fSize   << " ";
+    fout << fMeanx  << " ";
+    fout << fMeany;
+}
Index: trunk/MagicSoft/Mars/manalysis/MHillas.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.h	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.h	(revision 1203)
@@ -14,12 +14,24 @@
 {
 private:
-    Float_t fAlpha;     // [deg] Angle between the length axis of the ellipse and the camera center
-    Float_t fTheta;     // [rad] Angle between the x axis and the center of the ellipse
-    Float_t fWidth;     // [mm]  Width of the ellipse
-    Float_t fLength;    // [mm]  Length of the ellipse
-    Float_t fSize;      // [#CerPhot] Size of the ellipse
-    Float_t fDist;      // [mm] Distance of the ellipse COM from the camera center
+    // for description see MHillas.cc
+    Float_t   fLength;   // [mm]        major axis of ellipse
+    Float_t   fWidth;    // [mm]        minor axis of ellipse
+    Float_t   fDelta;    // [rad]       angle of major axis with x-axis
+    Float_t   fSize;     // [#CerPhot]  sum of content of all pixels (number of Cherenkov photons)
+    Float_t   fMeanx;    // [mm]        x-coordinate of center of ellipse
+    Float_t   fMeany;    // [mm]        y-coordinate of center of ellipse
 
-    TEllipse *fEllipse; //! Graphical Object to Display Ellipse
+    Float_t   fSinDelta; //! [1] sin of Delta (to be used in derived classes)
+    Float_t   fCosDelta; //! [1] cos of Delta (to be used in derived classes)
+
+    TEllipse *fEllipse;  //! Graphical Object to Display Ellipse
+
+protected:
+    //
+    // This is only for calculations in derived classes because
+    // we don't want to read/write this data members
+    //
+    Float_t GetCosDelta() const { return fCosDelta; }
+    Float_t GetSinDelta() const { return fSinDelta; }
 
 public:
@@ -29,21 +41,21 @@
     void Reset();
 
-    Bool_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix);
+    virtual Bool_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix);
 
-    void Print(Option_t *opt=NULL) const;
-    void Draw(Option_t *opt=NULL);
-    //void Paint(Option_t *opt=NULL);
+    virtual void Print(Option_t *opt=NULL) const;
+    virtual void Draw(Option_t *opt=NULL);
+    //virtual void Paint(Option_t *);
 
-    void Clear(Option_t *opt=NULL);
+    virtual void Clear(Option_t *opt=NULL);
 
-    Float_t GetAlpha() const  { return fAlpha; }
+    Float_t GetLength() const { return fLength; }
     Float_t GetWidth() const  { return fWidth; }
-    Float_t GetLength() const { return fLength; }
-    Float_t GetDist() const   { return fDist; }
+    Float_t GetDelta() const  { return fDelta; }
     Float_t GetSize() const   { return fSize; }
-    Float_t GetTheta() const  { return fTheta; }
+    Float_t GetMeanX() const  { return fMeanx; }
+    Float_t GetMeanY() const  { return fMeany; }
 
-    void AsciiRead(ifstream &fin);
-    void AsciiWrite(ofstream &fout) const;
+    virtual void AsciiRead(ifstream &fin);
+    virtual void AsciiWrite(ofstream &fout) const;
 
     ClassDef(MHillas, 1) // Storage Container for Hillas Parameter
@@ -51,3 +63,2 @@
 
 #endif
-
Index: trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MHillasCalc.cc	(revision 1203)
@@ -54,8 +54,10 @@
 // Default constructor.
 //
-MHillasCalc::MHillasCalc(const char *name, const char *title)
+MHillasCalc::MHillasCalc(const char *hil, const char *name, const char *title)
 {
     fName  = name  ? name  : "MHillasCalc";
     fTitle = title ? title : "Task to calculate Hillas parameters";
+
+    fHilName = hil;
 }
 
@@ -82,5 +84,5 @@
     }
 
-    fHillas = (MHillas*)pList->FindCreateObj("MHillas");
+    fHillas = (MHillas*)pList->FindCreateObj(fHilName);
     if (!fHillas)
         return kFALSE;
Index: trunk/MagicSoft/Mars/manalysis/MHillasCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasCalc.h	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MHillasCalc.h	(revision 1203)
@@ -24,6 +24,7 @@
           MHillas     *fHillas;     // ouput container to store result
 
+    TString fHilName;
 public:
-    MHillasCalc(const char *name=NULL, const char *title=NULL);
+    MHillasCalc(const char *hil="MHillas", const char *name=NULL, const char *title=NULL);
 
     Bool_t PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/manalysis/MHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1203)
@@ -0,0 +1,196 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Rudolf Bock     10/2001 <mailto:Rudolf.Bock@cern.ch>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHillasExt
+//
+// Storage Container for extended image parameters
+//
+//    extended image parameters
+// fConc     ratio of sum of two highest pixels over fSize
+// fConc1    ratio of highest pixel over fSize
+// fAsym     distance from highest pixel to center, projected onto major axis
+// fM3Long   third moment along major axis
+// fM3Trans  third moment along minor axis
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MHillasExt.h"
+
+#include <fstream.h>
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHillasExt);
+
+// -------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MHillasExt::MHillasExt(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MHillas";
+    fTitle = title ? title : "Storage container for extended parameter set of one event";
+
+    Reset();
+      // FIXME: (intelligent) initialization of values missing
+}
+
+// -------------------------------------------------------------------------
+//
+void MHillasExt::Reset()
+{
+    MHillas::Reset();
+
+    fConc    = 0;
+    fConc1   = 0; 
+    fAsym    = 0;
+    fM3Long  = 0;
+    fM3Trans = 0;
+}
+
+// -------------------------------------------------------------------------
+//
+void MHillasExt::Print(Option_t *) const
+{
+    MHillas::Print();
+
+    *fLog << "Extended Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Conc      = "        << fConc    << " (ratio)" << endl;
+    *fLog << " - Conc1     = "        << fConc1   << " (ratio)" << endl;
+    *fLog << " - Asymmetry = "        << fAsym    << " mm" << endl;
+    *fLog << " - 3rd Moment Long  = " << fM3Long  << " mm" << endl;
+    *fLog << " - 3rd Moment Trans = " << fM3Trans << " mm" << endl;
+}
+
+// -------------------------------------------------------------------------
+//
+//  calculation of additional parameters based on the camera geometry
+// and the cerenkov photon event
+//
+Bool_t MHillasExt::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
+{
+    if (!MHillas::Calc(geom, evt))
+        return kFALSE;
+
+    //
+    //   calculate the additional image parameters
+    // --------------------------------------------
+    //
+    //   loop to get third moments along ellipse axes and two max pixels
+    //
+    float m3x = 0;
+    float m3y = 0;
+
+    float maxpix1 = 0;                                               // [#phot]
+    float maxpix2 = 0;                                               // [#phot]
+
+    float maxpixx = 0;                                               // [mm]
+    float maxpixy = 0;                                               // [mm]
+
+    const UInt_t npixevt = evt.GetNumPixels();
+
+    for (UInt_t i=0; i<npixevt; i++)
+    {
+        const MCerPhotPix &pix = evt[i];
+        if (!pix.IsPixelUsed())
+            continue;
+
+        const MGeomPix &gpix = geom[pix.GetPixId()];
+        const float dx = gpix.GetX() - GetMeanX();                   // [mm]
+        const float dy = gpix.GetY() - GetMeanY();                   // [mm]
+
+        const float nphot = pix.GetNumPhotons();                     // [1]
+
+        const float dzx =  GetCosDelta()*dx + GetSinDelta()*dy;      // [mm]
+        const float dzy = -GetSinDelta()*dx + GetCosDelta()*dy;      // [mm]
+
+        m3x += nphot * dzx*dzx*dzx;                                  // [mm^3]
+        m3y += nphot * dzy*dzy*dzy;                                  // [mm^3]
+
+        if (nphot>maxpix1)
+        {
+            maxpix2 = maxpix1;
+            maxpix1 = nphot;                                         // [1]
+            maxpixx = dx + GetMeanX();                               // [mm]
+            maxpixy = dy + GetMeanY();                               // [mm]
+            continue;                                                // [1]
+        }
+
+        if (nphot>maxpix2)
+            maxpix2 = nphot;                                         // [1]
+    }
+
+    fAsym  = (GetMeanX()-maxpixx)*GetCosDelta() + (GetMeanY()-maxpixy)*GetSinDelta(); // [mm]
+    fConc  = (maxpix1+maxpix2)/GetSize();                            // [ratio]
+    fConc1 = maxpix1/GetSize();                                      // [ratio]
+
+    //
+    // Third moments along axes get normalized
+    //
+    m3x /= GetSize();
+    m3y /= GetSize();
+
+    fM3Long  = m3x<0 ? -pow(fabs(m3x), 1./3) : pow(fabs(m3x), 1./3); // [mm]
+    fM3Trans = m3y<0 ? -pow(fabs(m3y), 1./3) : pow(fabs(m3y), 1./3); // [mm]
+
+    SetReadyToSave();
+
+    return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+void MHillasExt::AsciiRead(ifstream &fin)
+{
+    MHillas::AsciiRead(fin);
+
+    fin >> fConc;
+    fin >> fConc1;
+    fin >> fAsym;
+    fin >> fM3Long;
+    fin >> fM3Trans;
+}
+
+// -------------------------------------------------------------------------
+//
+void MHillasExt::AsciiWrite(ofstream &fout) const
+{
+    MHillas::AsciiWrite(fout);
+
+    fout << " ";
+    fout << fConc   << " ";
+    fout << fConc1  << " ";
+    fout << fAsym   << " ";
+    fout << fM3Long << " ";
+    fout << fM3Trans;
+}
Index: trunk/MagicSoft/Mars/manalysis/MHillasExt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasExt.h	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasExt.h	(revision 1203)
@@ -0,0 +1,35 @@
+#ifndef MARS_MHillasExt
+#define MARS_MHillasExt
+
+#ifndef MARS_MHillas
+#include "MHillas.h"
+#endif
+
+class MGeomCam;
+class MCerPhotEvt;
+
+class MHillasExt : public MHillas
+{
+private:
+    // for description see MExtHillas.cc
+    Float_t fConc;    // [ratio] concentration ratio: sum of the two highest pixels / fSize
+    Float_t fConc1;   // [ratio] concentration ratio: sum of the highest pixel / fSize
+    Float_t fAsym;    // [mm]    fDist minus dist: center of ellipse, highest pixel
+    Float_t fM3Long;  // [mm]    3rd moment (e-weighted) along major axis
+    Float_t fM3Trans; // [mm]    3rd moment (e-weighted) along minor axis
+
+public:
+    MHillasExt(const char *name=NULL, const char *title=NULL);
+
+    void Reset();
+
+    Bool_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix);
+
+    void Print(Option_t *opt=NULL) const;
+
+    void AsciiRead(ifstream &fin);
+    void AsciiWrite(ofstream &fout) const;
+
+    ClassDef(MHillasExt, 1) // Storage Container for extended Hillas Parameter
+};
+#endif
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc	(revision 1203)
@@ -0,0 +1,107 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 1/2001
+!   Author(s): Rudolf Bock     10/2001 <mailto:Rudolf.Bock@cern.ch>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHillasSrc
+//
+// Storage Container for image parameters
+//
+//    source-dependent image parameters
+// fAlpha    angle between major axis and line source-to-center
+// fDist     distance from source to center of ellipse
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHillasSrc.h"
+
+#include <fstream.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MSrcPosCam.h"
+
+ClassImp(MHillasSrc);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MHillasSrc::MHillasSrc(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MHillasSrc";
+    fTitle = title ? title : "parameters depending in source position";
+}
+
+// --------------------------------------------------------------------------
+//
+//  calculation of source-dependent parameters
+//
+void 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]
+
+    const Double_t tand = tan(hillas->GetDelta()); // [1]
+
+    fDist   = sqrt(sx*sx + sy*sy);                 // [mm]
+    fAlpha  = atan2(sy - tand*sx, sx + tand*sy);   // [rad]
+    fAlpha *= kRad2Deg;                            // [deg]
+
+    fHillas = hillas;
+
+    SetReadyToSave();
+} 
+
+void MHillasSrc::Print(Option_t *) const
+{
+    *fLog << all;
+    *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
+    *fLog << " - Dist  = " << fDist  << " mm"  << endl;
+    *fLog << " - Alpha = " << fAlpha << " deg" << endl;
+}
+
+// -----------------------------------------------------------------------
+//
+// overloaded MParContainer to read MHillasSrc from an ascii file
+//
+void MHillasSrc::AsciiRead(ifstream &fin)
+{
+    fin >> fAlpha;
+    fin >> fDist;
+}
+
+// -----------------------------------------------------------------------
+//
+// overloaded MParContainer to write MHillasSrc to an ascii file
+//
+void MHillasSrc::AsciiWrite(ofstream &fout) const
+{
+    fout << fAlpha << " " << fDist;
+}
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrc.h	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrc.h	(revision 1203)
@@ -0,0 +1,44 @@
+#ifndef MARS_MHillasSrc
+#define MARS_MHillasSrc
+
+#ifndef MARS_MHillas
+#include "MHillas.h"
+#endif
+
+class MSrcPosCam;
+
+class MHillasSrc : public MParContainer
+{
+private:
+    const MHillas    *fHillas; //! Input parameters
+    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 from src to center of ellipse
+
+public:
+    MHillasSrc(const char *name=NULL, const char *title=NULL);
+
+    void SetSrcPos(const MSrcPosCam *pos) { fSrcPos = pos; }
+    const MSrcPosCam *GetSrcPos() const   { return fSrcPos; }
+
+    Float_t GetLength() const  { return fHillas->GetLength(); }
+    Float_t GetWidth()  const  { return fHillas->GetWidth(); }
+    Float_t GetDelta()  const  { return fHillas->GetDelta(); }
+    Float_t GetSize()   const  { return fHillas->GetSize(); }
+    Float_t GetMeanX()  const  { return fHillas->GetMeanX(); }
+    Float_t GetMeanY()  const  { return fHillas->GetMeanY(); }
+    Float_t GetAlpha()  const  { return fAlpha; }
+    Float_t GetDist()   const  { return fDist; }
+
+    void Print(Option_t *opt=NULL) const;
+
+    virtual void Calc(const MHillas *hillas);
+
+    virtual void AsciiRead(ifstream &fin);
+    virtual void AsciiWrite(ofstream &fout) const;
+
+    ClassDef(MHillasSrc, 1) // Container to hold source position dependant parameters
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1203)
@@ -0,0 +1,97 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Rudolf Bock     10/2001 <mailto:Rudolf.Bock@cern.ch>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MHillasSrcCalc
+//
+// Task to calculate the source dependant part of the hillas parameters
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MHillasSrcCalc.h"
+
+#include "MParList.h"
+
+#include "MHillasSrc.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHillasSrcCalc);
+
+// -------------------------------------------------------------------------
+//
+// Default constructor. The first argument is the name of a container
+// containing the source position in the camera plain (MScrPosCam).
+// The default is "MSrcPosCam". hil is the name of a container
+// of type MHillasSrc (or derived) in which the parameters are stored
+// The default is "MHillasSrc"
+//
+MHillasSrcCalc::MHillasSrcCalc(const char *src, const char *hil,
+                               const char *name, const char *title)
+{
+    fName  = name  ? name  : "MHillasSrcCalc";
+    fTitle = title ? title : "add parameters dependent on source position (MHillasSrc)";
+
+    fSrcName    = src;
+    fHillasName = hil;
+}
+
+// -------------------------------------------------------------------------
+//
+Bool_t MHillasSrcCalc::PreProcess(MParList *pList)
+{
+    fHillas = (MHillas*)pList->FindObject("MHillas");
+    if (!fHillas)
+    {
+        *fLog << dbginf << "MHillas not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fSrcPos = (MSrcPosCam*)pList->FindObject(fSrcName, "MSrcPosCam");
+    if (!fSrcPos)
+    {
+        *fLog << dbginf << "MSrcPosCam missing in Parameter List... aborting." << endl;
+        return kFALSE;
+    }
+
+    fHillasSrc = (MHillasSrc*)pList->FindCreateObj("MHillasSrc", fHillasName);
+    if (!fHillasSrc)
+        return kFALSE;
+
+    fHillasSrc->SetSrcPos(fSrcPos);
+
+    return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+Bool_t MHillasSrcCalc::Process()
+{
+    fHillasSrc->Calc(fHillas);
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h	(revision 1203)
@@ -0,0 +1,32 @@
+#ifndef MARS_MHillasSrcCalc
+#define MARS_MHillasSrcCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MHillas;
+class MHillasSrc;
+class MSrcPosCam;
+
+class MHillasSrcCalc : public MTask
+{
+private:
+    MHillas    *fHillas;
+    MSrcPosCam *fSrcPos;
+    MHillasSrc *fHillasSrc;
+
+    TString     fSrcName;
+    TString     fHillasName;
+
+public:
+    MHillasSrcCalc(const char *src="MSrcPosCam", const char *hil="MHillasSrc",
+                   const char *name=NULL, const char *title=NULL);
+
+    Bool_t PreProcess(MParList *plist);
+    Bool_t Process();
+
+    ClassDef(MHillasSrcCalc, 0) // task to calculate the source position depandant hillas parameters
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1203)
@@ -194,5 +194,5 @@
 //
 //   Look for the boundary pixels around the core pixels
-//   if a pixel has more than 2.5 (clean level 2) sigma, and
+//   if a pixel has more than 2.5 (clean level 2.5) sigma, and
 //   a core neigbor it is declared as used.
 //
Index: trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1203)
@@ -0,0 +1,80 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Rudolf Bock     10/2001 <mailto:Rudolf.Bock@cern.ch>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MSrcPosCam
+//
+// Storage Container to hold the current position of the source (or
+// anti/false source) in the camera plain
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MSrcPosCam.h"
+
+#include <fstream.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MSrcPosCam);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MSrcPosCam::MSrcPosCam(const char *name, const char *title) : fX(0), fY(0)
+{
+    fName  = name  ? name  : "MSrcPosCam";
+    fTitle = title ? title : "Source position in the camera";
+}
+
+// -----------------------------------------------------------------------
+//
+void MSrcPosCam::Print(Option_t *) const
+{
+    *fLog << all;
+    *fLog << "Source position in the camera plain (" << GetName() << ")" << endl;
+    *fLog << " - x [mm] = " << fX << endl;
+    *fLog << " - y [mm] = " << fY << endl;
+}
+
+// -----------------------------------------------------------------------
+//
+// overloaded MParContainer to read MSrcPosCam from an ascii file
+//
+void MSrcPosCam::AsciiRead(ifstream &fin)
+{
+    fin >> fX;
+    fin >> fY;
+}
+
+// -----------------------------------------------------------------------
+//
+// overloaded MParContainer to write MSrcPosCam to an ascii file
+//
+void MSrcPosCam::AsciiWrite(ofstream &fout) const
+{
+    fout << fX << " " << fY;
+}
Index: trunk/MagicSoft/Mars/manalysis/MSrcPosCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MSrcPosCam.h	(revision 1203)
+++ trunk/MagicSoft/Mars/manalysis/MSrcPosCam.h	(revision 1203)
@@ -0,0 +1,34 @@
+#ifndef MARS_MSrcPosCam
+#define MARS_MSrcPosCam
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MSrcPosCam : public MParContainer
+{
+private:
+    Float_t fX; // [mm] x position of source in camera
+    Float_t fY; // [mm] y position of source in camera
+
+public:
+    MSrcPosCam(const char *name=NULL, const char *title=NULL);
+
+    void Clear(Option_t *)           { fX = 0; fY = 0; }
+
+    void SetX(Float_t x)             { fX = x; }
+    void SetY(Float_t y)             { fY = y; }
+    void SetXY(Float_t x, Float_t y) { fX = x; fY = y; }
+
+    Float_t GetX() const             { return fX; }
+    Float_t GetY() const             { return fY; }
+
+    void Print(Option_t *opt=NULL) const;
+
+    void AsciiRead(ifstream &fin);
+    void AsciiWrite(ofstream &fout) const;
+
+    ClassDef(MSrcPosCam, 1) // container to store source position in the camera plain
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1186)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1203)
@@ -34,6 +34,10 @@
            MMcPedestalNSBAdd.cc \
            MImgCleanStd.cc \
+           MSrcPosCam.cc \
            MHillas.cc \
+           MHillasExt.cc \
            MHillasCalc.cc \
+           MHillasSrc.cc \
+           MHillasSrcCalc.cc \
            MCerPhotCalc.cc \
 	   MCerPhotEvt.cc \
