Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 5657)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 5658)
@@ -19,4 +19,9 @@
                                                  -*-*- END OF LINE -*-*-
 
+ 2004/12/21 Pepe Flix (represented by jrico)
+    * library/MTopology.[cc,h], library/MTopologyCalc.[cc,h], 
+      library/Makefile, library/IFAELinkDef.h
+     - include topology classes
+	
  2004/12/21 Javier Rico
     * programs/makeHillas.cc, programs/makehillas.datacard
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h	(revision 5657)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h	(revision 5658)
@@ -26,4 +26,6 @@
 #pragma link C++ class MLiveTime+;
 #pragma link C++ class MLiveTimeCalc+;
+#pragma link C++ class MTopology+;
+#pragma link C++ class MTopologyCalc+;
 
 #endif
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.cc	(revision 5658)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.cc	(revision 5658)
@@ -0,0 +1,129 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Josep Flix   09/2004 <mailto:jflix@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MTopology
+//
+// Storage Container for topology parameters:
+//
+// fDistance = SUM_(i,j) D_ij , where i,j<UsedPixels and d_ij are distances
+//                              between pixels. This characterizes topology.
+//
+// fUsed = Used Pixels after image cleaning.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MTopology.h"
+
+#include <iostream>
+
+#include "MGeomPix.h"
+#include "MGeomCam.h"
+#include "MCerPhotPix.h"
+#include "MCerPhotEvt.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+using namespace std;
+ClassImp(MTopology);
+
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+
+MTopology::MTopology(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MTopology";
+    fTitle = title ? title : "Parameters related to Topology of images after image cleaning";
+
+    Reset();
+}
+
+void MTopology::Reset()
+{
+    fDistance = -1;
+    fUsed = -1;
+}
+
+void MTopology::Print(Option_t *opt) const
+{
+      *fLog << all << GetDescriptor() << ":" << endl;
+      *fLog << "Topology Distance [mm] = " << fDistance << ": ";
+      *fLog << "Used Pixels = " << fUsed << ": " << endl;
+
+}
+
+Int_t MTopology::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
+{
+    const Int_t Pixels = evt.GetNumPixels();
+   
+    Double_t X[Pixels];
+    Double_t Y[Pixels];
+    Int_t NPixels[Pixels];
+ 
+    if (Pixels < 3)
+    {
+	Reset();
+	return 1;
+    };
+
+    MCerPhotPix *pix = 0;
+    
+    TIter Next(evt);
+    
+    fN_Pixels = 0;
+
+    Double_t fDist = 0.;
+    
+    while ((pix=(MCerPhotPix*)Next()))
+    {
+	const MGeomPix &gpix = geom[pix->GetPixId()];
+	
+	NPixels[fN_Pixels] = pix->GetPixId();
+	X[fN_Pixels] = gpix.GetX();
+	Y[fN_Pixels] = gpix.GetY();
+	
+	fN_Pixels++;
+    };
+
+    for (int i = 0; i < fN_Pixels ; i++){
+	for (int j = 0; j < fN_Pixels ; j++){
+	    fDist += sqrt(pow(X[j]-X[i],2) + pow(Y[j]-Y[i],2));
+	};		
+    };
+
+    fDistance = (Int_t)(fDist+.5);
+
+    SetDistance(fDistance);
+    SetUsedPixels(fN_Pixels);
+
+    SetReadyToSave();
+
+    return 0;
+	    
+}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.h	(revision 5658)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MTopology.h	(revision 5658)
@@ -0,0 +1,39 @@
+#ifndef MARS_MTopology
+#define MARS_MTopology
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MGeomCam;
+class MCerPhotEvt;
+
+class MTopology : public MParContainer
+{
+private:
+
+    Int_t fDistance; // Evaluated sum of distances between 'used' pixels after image cleaning [mm]
+    Int_t fUsed;     // Number of pixels contained in an image
+
+    Int_t fN_Pixels;
+
+public:
+
+    MTopology(const char *name=NULL, const char *title=NULL);
+
+    void Reset();
+
+    Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &evt);
+    
+    void Print(Option_t *opt=NULL) const;
+    
+    Int_t GetDistance()             { return fDistance; } 
+    Int_t GetUsedPixels()           { return fUsed; }
+
+    void SetDistance(Int_t Dist)    { fDistance=Dist; } 
+    void SetUsedPixels(Int_t Used)  { fUsed=Used; }
+
+    ClassDef(MTopology, 1) // Container to hold Topology related parameters
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.cc	(revision 5658)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.cc	(revision 5658)
@@ -0,0 +1,133 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Josep Flix   09/2004 <mailto:jflix@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MTopologyCalc
+//
+// Taks that evaluates the Topological Parameters of images after image cleaning
+//
+// fDistance = SUM_(i,j) D_ij , where i,j<UsedPixels and d_ij are distances
+//                              between pixels. This characterizes topology.
+//
+// fUsed = Used Pixels after image cleaning.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MTopologyCalc.h"
+
+#include "MParList.h"
+
+#include "MTopology.h"
+
+#include "MCerPhotEvt.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MTopologyCalc);
+
+using namespace std;
+
+static const TString gsDefName  = "MTopologyCalc";
+static const TString gsDefTitle = "Calculate Topology related parameters";
+
+// -------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MTopologyCalc::MTopologyCalc(const char *name, const char *title)
+    : fTopology(NULL)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+}
+
+// -------------------------------------------------------------------------
+//
+Int_t MTopologyCalc::PreProcess(MParList *pList)
+{
+
+    fCerPhotEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
+    if (!fCerPhotEvt)
+    {
+        *fLog << err << dbginf << "MCerPhotEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fGeomCam)
+    {
+        *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fTopology = (MTopology*)pList->FindCreateObj("MTopology");
+    if (!fTopology)
+        return kFALSE;
+ 
+    return kTRUE;
+
+}
+
+// -------------------------------------------------------------------------
+//
+Int_t MTopologyCalc::Process()
+{
+
+    Int_t rc = fTopology->Calc(*fGeomCam, *fCerPhotEvt);
+    
+    if (rc == 1)
+	fErrors++;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Prints some statistics about the Topology calculation. The percentage
+//  is calculated with respect to the number of executions of this task.
+//
+Int_t MTopologyCalc::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 UsedPixels == -1" << endl;
+    *fLog << endl;
+
+    /*
+    delete fHillas;
+    delete fHillasSrc;
+    delete fSrcPos;
+    delete fTopology;
+    */
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.h	(revision 5658)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MTopologyCalc.h	(revision 5658)
@@ -0,0 +1,34 @@
+#ifndef MARS_MTopologyCalc
+#define MARS_MTopologyCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MGeomCam;
+class MCerPhotEvt;
+class MTopology;
+
+class MTopologyCalc : public MTask
+{
+private:
+
+    const MGeomCam     *fGeomCam;
+    const MCerPhotEvt  *fCerPhotEvt;
+
+    MTopology      *fTopology;
+
+    Int_t       fErrors;
+   
+    Int_t PreProcess(MParList *plist);
+    Int_t Process();
+    Int_t PostProcess();
+
+public:
+
+    MTopologyCalc(const char *name=NULL, const char *title=NULL);
+    
+    ClassDef(MTopologyCalc, 0) // task to calculate....
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile	(revision 5657)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile	(revision 5658)
@@ -69,5 +69,7 @@
         MSrcPosFromStars.cc \
         MLiveTime.cc \
-        MLiveTimeCalc.cc	
+        MLiveTimeCalc.cc \
+	MTopology.cc \
+	MTopologyCalc.cc
 
 
