Index: trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h	(revision 4072)
@@ -8,4 +8,5 @@
 #pragma link C++ class MPSFFit+;
 #pragma link C++ class MPSFFitCalc+;
+#pragma link C++ class MSrcPlace+;
 #pragma link C++ class MSrcPosFromFile+;
 #pragma link C++ class MSrcRotate+;
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4072)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4072)
@@ -0,0 +1,192 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Javier Lopez    04/2004 <mailto:jlopez@ifae.es>
+!   Author(s): Javier Rico     04/2004 <mailto:jrico@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MSrcPlace
+//
+// Abstract task to set the source position in any place in the camera
+// It keeps a 2D histogram with the assigned positions, so that the same
+// distribution can be applied later to any data set (tipically the OFF data)
+//
+//  Input Containers:
+//    MSrcPosCam
+//
+//  Output Containers:
+//    MSrcPosCam
+//    MDCA
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <fstream>
+#include <math.h>
+
+#include "TH2F.h"
+
+#include "MParList.h"
+#include "MSrcPlace.h"
+#include "MSrcPosCam.h"
+#include "MDCA.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MSrcPlace);
+
+using namespace std;
+
+static const TString gsDefName  = "MSrcPlace";
+static const TString gsDefTitle = "Set the position of the source";
+
+// -------------------------------------------------------------------------
+//
+// Default constructor. The first (second) argument is the name of a container
+// containing the source position in the camera plain, MScrPosCam (MDCA).
+// The default is "MSrcPosCam" ("MDCA"). 
+//
+MSrcPlace::MSrcPlace(const char* srcPos, const char* dca, const char *name, const char *title)
+  : fSrcPos(NULL), fDCA(NULL)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    fSrcPosName  = srcPos;
+    fDCAName     = dca;
+
+    const Float_t cameraSize   = 600; //[mm]
+    const Float_t binPrecision =   1; //[mm] ~ 0.0033 deg
+
+    const UInt_t nbins =  (UInt_t)(cameraSize*2/binPrecision);
+    fHistSrcPos = new TH2F("HistSrcPos","",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
+
+    fMode=kOn;
+}
+// -------------------------------------------------------------------------
+//
+// Destructor
+//
+MSrcPlace::~MSrcPlace()
+{
+  delete fHistSrcPos;
+}
+// -------------------------------------------------------------------------
+//
+// Look for/create the needed containers
+// Check whether RA and DEC have been initialized
+//
+Int_t MSrcPlace::SearchForSrcPos(MParList *pList)
+{
+    // look for/create MSrcPosCam
+  fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam");
+  if (!fSrcPos)
+    {
+      *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl;
+      fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName));
+      if(!fSrcPos)
+	return kFALSE;
+    }
+
+  // look for/create MDCA
+  fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
+  if (!fDCA)
+    {
+      *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl;
+      fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
+      if(!fDCA)
+	return kFALSE;
+    }
+
+  return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+// Save the position of the source in the histogram
+//
+void MSrcPlace::SavePosIntoHisto()
+{  
+  fHistSrcPos->Fill(fSrcPos->GetX(),fSrcPos->GetY());
+}
+// -------------------------------------------------------------------------
+//
+// Read the position of the source from the histogram
+//
+void MSrcPlace::ReadPosFromHisto()
+{  
+  Axis_t x;
+  Axis_t y;
+  
+  fHistSrcPos->GetRandom2(x,y);
+  fSrcPos->SetXY(x,y);
+  fDCA->SetRefPoint(x,y);
+}
+// -------------------------------------------------------------------------
+//
+// Look for needed containers
+//
+Int_t MSrcPlace::PreProcess(MParList* plist)
+{  
+  return SearchForSrcPos(plist);
+}
+
+// -------------------------------------------------------------------------
+//
+// Call to compute a new position and then save it in the histogram (fMode==kOn) 
+// of to read the new position from the histogram (fMode==kOff)
+//
+Int_t MSrcPlace::Process()
+{  
+  switch(fMode)
+    {
+    case kOn:
+      if(!ComputeNewSrcPosition())
+	return kFALSE;
+      SavePosIntoHisto();
+      break;
+    case kOff:
+      ReadPosFromHisto();
+      break;
+    default:
+      *fLog << err << "MSrcPlace::Process Warning: Wrong mode " << fMode << endl;
+      return kFALSE;
+    }
+  return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+// Dump 2D histo statistics
+//
+Int_t MSrcPlace::PostProcess()
+{
+  *fLog << inf << endl;
+  *fLog << inf << "MSrcPlace::PostProcess Message: Created internal histogram with: ";
+  *fLog << inf << "Entries: " << fHistSrcPos->GetEntries() << endl;
+  *fLog << inf << "X projection mean: " << fHistSrcPos->ProjectionX()->GetMean() << endl;
+  *fLog << inf << "X projection rms:  " << fHistSrcPos->ProjectionX()->GetRMS() << endl;
+  *fLog << inf << "Y projection mean: " << fHistSrcPos->ProjectionY()->GetMean() << endl;
+  *fLog << inf << "Y projection rms:  " << fHistSrcPos->ProjectionY()->GetRMS() << endl;
+  
+  return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4072)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4072)
@@ -0,0 +1,58 @@
+#ifndef MARS_MSrcPlace
+#define MARS_MSrcPlace
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MDCA;
+class MSrcPosCam;
+class TH2F;
+
+class MSrcPlace : public MTask
+{
+ public:
+  enum OnOffMode_t {kOn=0,kOff};
+  
+ private:
+  MSrcPosCam*  fSrcPos;      //  Pointer to the source position
+  MDCA*        fDCA;         //  Pointer to the MDCA object
+  
+  TString      fSrcPosName;  //  Name of the MSrcPosCam object
+  TString      fDCAName;     //  Name of the MDCA object
+  
+  TH2F*        fHistSrcPos;  //  histogram of the used source positions
+  OnOffMode_t  fMode;        //  On/Off data mode (write/read to/from the histogram)
+
+  virtual Int_t PreProcess(MParList *plist);
+  virtual Int_t Process();
+  virtual Int_t PostProcess();
+
+  void  SavePosIntoHisto();
+  void  ReadPosFromHisto();
+
+
+ public:
+  MSrcPlace(const char* src="MSrcPosCam", const char* dca="MDCA",
+	    const char* name=NULL, const char* title=NULL);
+
+  virtual ~MSrcPlace();
+
+  void SetMode(OnOffMode_t mode)   {fMode=mode;}
+  void SetSrcPosName(TString name) {fSrcPosName=name;}
+  void SetDCAName(TString name)    {fDCAName=name;}
+
+  OnOffMode_t GetMode()            {return fMode;}
+  TH2F*       GetPositionHisto()   {return fHistSrcPos;}
+  MSrcPosCam* GetSrcPosCam()       {return fSrcPos;}
+  MDCA*       GetDCA()             {return fDCA;}
+
+
+  Int_t SearchForSrcPos(MParList *plist);
+  virtual Int_t ComputeNewSrcPosition() {return kTRUE;}
+
+  ClassDef(MSrcPlace, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4072)
@@ -27,5 +27,6 @@
 // MSrcPosFromFile
 //
-// Task to calculate the position of the source as a function of run number
+// Task to set the position of the source as a function of run number according
+// to the positions read from an input file
 //
 //  Output Containers:
@@ -39,5 +40,4 @@
 
 #include "MParList.h"
-
 #include "MSrcPosFromFile.h"
 
@@ -53,42 +53,37 @@
 
 static const TString gsDefName  = "MSrcPosFromFile";
-static const TString gsDefTitle = "Calculate position of the (off axis) source";
+static const TString gsDefTitle = "Set the position of the (off axis) source according to input file";
 
 // -------------------------------------------------------------------------
 //
-// Default constructor
+// Default constructor. cardpath is the name of the input file (.pos) where the
+// source positions are stored in the format Run# x y (in mm). mode indicates whether
+// to read or to save the positions of the source in/from the internal histogram
 //
 MSrcPosFromFile::MSrcPosFromFile(TString cardpath, OnOffMode_t mode, const char *name, const char *title)
-    : fRawRunHeader(NULL), fSrcPos(NULL), fMode(mode), fSourcePositionFilePath(cardpath)
-{
-    fName  = name  ? name  : gsDefName.Data();
-    fTitle = title ? title : gsDefTitle.Data();
-
-    fLastRun = 0;
-
-// Count the number of runs in the card with the source poistions
-    ReadSourcePositionsFile(kCount);
-
-    fRunList = new Int_t[fNumRuns];
-    fRunSrcPos = new MSrcPosCam[fNumRuns];
-    fRunMap = new TExMap(fNumRuns);
-
-    Float_t cameraSize   = 600; //[mm]
-    Float_t binPrecision =  3;  //[mm] ~ 0.01 deg
-
-    UInt_t nbins =  (UInt_t)(cameraSize*2/binPrecision);
-
-    fHistSrcPos = new TH2F("HistSrcPos","",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
-
-// Read card with the source poistions
-    ReadSourcePositionsFile(kRead);
+  : fRawRunHeader(NULL), fSourcePositionFilePath(cardpath)
+{
+  fName  = name  ? name  : gsDefName.Data();
+  fTitle = title ? title : gsDefTitle.Data();
+  SetMode(mode);
+
+  fLastRun = 0;
+  
+  // Count the number of runs in the card with the source poistions
+  ReadSourcePositionsFile(kCount);
+  
+  fRunList = new Int_t[fNumRuns];
+  fRunSrcPos = new MSrcPosCam[fNumRuns];
+  fRunMap = new TExMap(fNumRuns);
+  
+  // Read card with the source poistions
+  ReadSourcePositionsFile(kRead);
 }
 
 MSrcPosFromFile::~MSrcPosFromFile()
 {
-    delete [] fRunList;
-    delete [] fRunSrcPos;
-    delete fRunMap;
-    delete fHistSrcPos;
+  delete [] fRunList;
+  delete [] fRunSrcPos;
+  delete fRunMap;
 }
 
@@ -97,24 +92,53 @@
 Int_t MSrcPosFromFile::PreProcess(MParList *pList)
 {
-
-    fRawRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
-    if (!fRawRunHeader)
+  if(!SearchForSrcPos(pList))
+    return kFALSE;
+  
+  fRawRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
+  if (!fRawRunHeader)
     {
       *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting" << endl;
-        return kFALSE;
-    }
-
-    fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
-    if (!fSrcPos)
-	return kFALSE;
-
-    return kTRUE;
+      return kFALSE;
+    }
+  
+  return kTRUE;
 }
 
 // --------------------------------------------------------------------------
 //
+// In case we enter a new run, look for the position in the read list
+// If there is no value for that run, take the previous one
 // 
-Bool_t MSrcPosFromFile::ReInit(MParList *pList)
-{
+Int_t MSrcPosFromFile::ComputeNewSrcPosition()
+{
+  const UInt_t run = fRawRunHeader->GetRunNumber();
+  if(run!=fLastRun)
+    {      
+      fLastRun=run;
+      MSrcPosCam* srcpos = (MSrcPosCam*)fRunMap->GetValue(run);
+      
+      Float_t x;
+      Float_t y;
+	
+      if (srcpos)
+	{
+	  x = srcpos->GetX();
+	  y = srcpos->GetY();
+	  
+	  GetSrcPosCam()->SetXY(x,y);
+		
+	  *fLog << inf << "Source position for run " << run;
+	  *fLog << inf << "\tX\t" << setprecision(3) << x;
+	  *fLog << inf << "\tY\t" << setprecision(3) << y << endl;
+	}	    
+      else
+	{
+	  *fLog << inf << "Source position for run " << run << " not found in file. ";
+	  *fLog << inf << "Taking previous position: ";
+	  *fLog << inf << "\tX\t" << setprecision(3) << x;
+	  *fLog << inf << "\tY\t" << setprecision(3) << y << endl;	  
+	}
+    }
+  
   return kTRUE;
 }
@@ -122,127 +146,57 @@
 // --------------------------------------------------------------------------
 //
+// Read file with table of source positions as function of run
 // 
-Int_t MSrcPosFromFile::Process()
-{
-
-    switch(fMode)
+Int_t MSrcPosFromFile::ReadSourcePositionsFile(UShort_t readmode)
+{
+  
+  ifstream fin(fSourcePositionFilePath);
+  if(!fin)
+    {
+      *fLog << err << "MSrcPosFromFile::ReadSourcePositionsFile. Cannot open file " << fSourcePositionFilePath << endl;
+      return kFALSE;
+    }
+  
+  UInt_t run;
+  Float_t x,y;
+  
+  fNumRuns=0;
+  
+  *fLog << dbg << "MSrcPosFromFile::ReadSourcePositionsFile(" << readmode << ')' << endl;
+  while(1)
+    {
+      fin >> run >> x >> y;
+      if(fin.eof())
+	break;
+      
+      switch(readmode)
 	{
-	    case kOn:
-	    {
-		const UInt_t run = fRawRunHeader->GetRunNumber();
-
-		MSrcPosCam* srcpos = (MSrcPosCam*)fRunMap->GetValue(run);
-		
-		Float_t x;
-		Float_t y;
-		
-		if (srcpos)
-		{
-		    x = srcpos->GetX();
-		    y = srcpos->GetY();
-		    
-		    
-		    if (srcpos && run != fLastRun)
-		    {
-			fSrcPos->SetXY(x,y);
+	case kCount:
+	  {
 	    
-			*fLog << inf << "Source position for run " << run;
-			*fLog << inf << "\tX\t" << setprecision(2) << x;
-			*fLog << inf << "\tY\t" << setprecision(2) << y << endl;
-		    }
-		    
-		    fLastRun = run;
-		}
-		
-		x = fSrcPos->GetX();
-		y = fSrcPos->GetY();
-		
-		fHistSrcPos->Fill(x,y);
-		break;
-	    }
-	    case kOff:
-	    {
-		Axis_t x;
-		Axis_t y;
-
-		fHistSrcPos->GetRandom2(x,y);
-		fSrcPos->SetXY(x,y);
-
-		break;
-	    }
-	    default:
-		*fLog << err << "Wrond mode " << fMode << endl;
-		return kFALSE;
+	    *fLog << dbg << "Source position for run " << run;
+	    *fLog << dbg << "\tX\t" << x << " mm";
+	    *fLog << dbg << "\tY\t" << y << " mm" << endl;
+	    
+	    fNumRuns++;
+	    break;
+	  }
+	case kRead:
+	  {
+	    fRunList[fNumRuns] = run;
+	    fRunSrcPos[fNumRuns].SetXY(x,y);
+	    fRunMap->Add(fRunList[fNumRuns],(Long_t)&(fRunSrcPos[fNumRuns]));
+	    fNumRuns++;
+	    break;
+	  }
+	default:
+	  *fLog << err << "Read mode " << readmode << " node defined" << endl;
+	  return kFALSE;
 	}
-
-    return kTRUE;
-}
-
-
-Int_t MSrcPosFromFile::PostProcess()
-{
-
-    *fLog << dbg << endl;
-    *fLog << dbg << "fHistSrcPos->GetEntries() " << fHistSrcPos->GetEntries() << endl;
-    *fLog << dbg << "fHistSrcPos->ProjectionX()->GetMean() " << fHistSrcPos->ProjectionX()->GetMean() << endl;
-    *fLog << dbg << "fHistSrcPos->ProjectionX()->GetRMS() " << fHistSrcPos->ProjectionX()->GetRMS() << endl;
-    *fLog << dbg << "fHistSrcPos->ProjectionY()->GetMean() " << fHistSrcPos->ProjectionY()->GetMean() << endl;
-    *fLog << dbg << "fHistSrcPos->ProjectionY()->GetRMS() " << fHistSrcPos->ProjectionY()->GetRMS() << endl;
-
-    return kTRUE;
-}
-
-
-Int_t MSrcPosFromFile::ReadSourcePositionsFile(UShort_t readmode)
-{
-
-    ifstream fin(fSourcePositionFilePath);
-    if(!fin)
-    {
-	*fLog << err << "MSrcPosFromFile::ReadSourcePositionsFile. Cannot open file " << fSourcePositionFilePath << endl;
-	return kFALSE;
-    }
-
-    UInt_t run;
-    Float_t x,y;
-
-    fNumRuns=0;
-
-    *fLog << dbg << "MSrcPosFromFile::ReadSourcePositionsFile(" << readmode << ')' << endl;
-    while(1)
-    {
-	fin >> run >> x >> y;
-	if(fin.eof())
-	    break;
-
-	switch(readmode)
-	{
-	    case kCount:
-	    {
-
-		*fLog << dbg << "Source position for run " << run;
-		*fLog << dbg << "\tX\t" << x << " mm";
-		*fLog << dbg << "\tY\t" << y << " mm" << endl;
-
-		fNumRuns++;
-		break;
-	    }
-	    case kRead:
-	    {
-		fRunList[fNumRuns] = run;
-		fRunSrcPos[fNumRuns].SetXY(x,y);
-		fRunMap->Add(fRunList[fNumRuns],(Long_t)&(fRunSrcPos[fNumRuns]));
-		fNumRuns++;
-		break;
-	    }
-	    default:
-		*fLog << err << "Read mode " << readmode << " node defined" << endl;
-		return kFALSE;
-	}
-    }
-
-    fin.close();
-
-
-    return kTRUE;
-}
+    }
+  
+  fin.close();
+  
+  
+  return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4072)
@@ -2,6 +2,6 @@
 #define MARS_MSrcPosFromFile
 
-#ifndef MARS_MTask
-#include "MTask.h"
+#ifndef MARS_MSrcPlace
+#include "MSrcPlace.h"
 #endif
 
@@ -10,15 +10,12 @@
 #endif
 
-class TH2F;
-
 class MRawRunHeader;
 class MSrcPosCam;
 
-class MSrcPosFromFile : public MTask
+class MSrcPosFromFile : public MSrcPlace
 {
  private:
 
     MRawRunHeader *fRawRunHeader;
-    MSrcPosCam    *fSrcPos;   //  Pointer to the source position
 
     Int_t  fNumRuns;
@@ -29,24 +26,16 @@
     TExMap     *fRunMap;   // list of run numbers positions
 
-    TH2F    *fHistSrcPos;
-    UShort_t fMode;
+    TString fSourcePositionFilePath;
 
-    TString fSourcePositionFilePath;
-    Int_t ReadSourcePositionsFile(UShort_t readmode);
-
-    Int_t PreProcess(MParList *plist);
-    Bool_t ReInit(MParList *plist);
-    Int_t Process();
-    Int_t PostProcess();
-
-public:
+    virtual Int_t ReadSourcePositionsFile(UShort_t readmode);
+    virtual Int_t ComputeNewSrcPosition();
     
+    virtual Int_t PreProcess(MParList *plist);
+    
+public:    
     enum ReadMode_t {kCount=0,kRead};
-    enum OnOffMode_t {kOn=0,kOff};
 
     MSrcPosFromFile(TString cardpath, OnOffMode_t mode=kOn, const char *name=NULL, const char *title=NULL);
     ~MSrcPosFromFile();
-    
-    void SetMode(OnOffMode_t mode) {fMode=mode;}
 
     ClassDef(MSrcPosFromFile, 0) // task to calculate the position of the source as a function of the run number 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4072)
@@ -26,6 +26,5 @@
 // MSrcRotate
 //
-// Task to rotate the position of the source as a function of Azimuth and 
-// Zenith angles
+// Task to rotate the position of the source as a function of time
 //
 //  Input Containers:
@@ -45,9 +44,9 @@
 #include "MRawEvtHeader.h"
 #include "MSrcRotate.h"
-#include "MSrcPosCam.h"
-#include "MDCA.h"
 
 #include "MAstroSky2Local.h"
 #include "MObservatory.h"
+#include "MSrcPosCam.h"
+#include "MDCA.h"
 
 #include "MLog.h"
@@ -59,5 +58,5 @@
 
 static const TString gsDefName  = "MSrcRotate";
-static const TString gsDefTitle = "De-rotate position of the source";
+static const TString gsDefTitle = "Rotate position of the source";
 
 // -------------------------------------------------------------------------
@@ -68,11 +67,11 @@
 //
 MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title)
-  : fSrcPos(NULL), fDCA(NULL), fRA(0), fDEC(0), fRunNumber(0)
+  : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
 {
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
 
-    fSrcPosName  = srcPos;
-    fDCAName     = dca;
+    SetSrcPosName(srcPos);
+    SetDCAName(dca);
 }
 
@@ -84,24 +83,7 @@
 Int_t MSrcRotate::PreProcess(MParList *pList)
 {
-    // look for/create MSrcPosCam
-  fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam");
-  if (!fSrcPos)
-    {
-      *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl;
-      fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName));
-      if(!fSrcPos)
-	return kFALSE;
-    }
-
-  // look for/create MDCA
-  fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
-  if (!fDCA)
-    {
-      *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl;
-      fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
-      if(!fDCA)
-	return kFALSE;
-    }
-
+  if(!SearchForSrcPos(pList))
+    return kFALSE;
+  
   // look for MRawRunHeader
   fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
@@ -141,10 +123,10 @@
 // FIXME: for the time being, this is computed by assuming constant event rate
 //
-Int_t MSrcRotate::Process()
+Int_t MSrcRotate::ComputeNewSrcPosition()
 {  
   if(fRunHeader->GetRunNumber()!=fRunNumber)
     {
       fRunNumber=fRunHeader->GetRunNumber();
-
+      
       // save the number of events, initial and final times
       fNEvts    = fRunHeader->GetNumEvents();
@@ -155,8 +137,8 @@
       if((ULong_t)TMath::Nint(fIniTime.GetMjd())!=(ULong_t)TMath::Nint(fFinTime.GetMjd()))
 	{
-	  *fLog << err << "MSrcRotate::Process Error: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl;
+	  *fLog << err << "MSrcRotate::ComputeNewSrcPosition Error: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl;
 	  return kFALSE;
 	}
-
+      
 #ifdef DEBUG
       cout << endl << "********************"  << endl;
@@ -169,5 +151,5 @@
     }
   
-
+  
   // Compute the event time
   // FIXME: for the time being, this is computed by assuming constant event rate
@@ -177,9 +159,9 @@
   MTime refTime;
   refTime.SetMjd(fRefMJD);
-
+  
   // de-rotate the source position
   const MAstroSky2Local Observation(eventTime, *fObservatory);
   const MAstroSky2Local RefObservation(refTime, *fObservatory);
-
+  
 #ifdef DEBUG
   printf("Run:%d, Event:%d, iniMJD=%15.5f, finMJD=%15.5f, fDeltaT=%15.5f, newMJD=%15.5f, fRefMJD=%15.5f, rotation=%15.5f, ref=%15.5f\n",
@@ -190,22 +172,26 @@
   //  cout << "newMJD=" << newMJD << ", fRefMJD="<<fRefMJD<<", rotation="<<Observation.RotationAngle(fRA,fDEC)<<", ref="<<RefObservation.RotationAngle(fRA,fDEC)<< endl;
 #endif
-
-  Double_t rotationAngle = Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC);
+  
+  Double_t rotationAngle = fRefMJD ? 
+    Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC) :
+    Observation.RotationAngle(fRA,fDEC) ;
+  MSrcPosCam* srcpos = GetSrcPosCam();
+  MDCA* dca = GetDCA();
   
   Float_t c = TMath::Cos(rotationAngle);
   Float_t s = TMath::Sin(rotationAngle);
   // perform a rotation of -rotationAngle to move the source back to the "initial" position
-  Float_t newX = c*fSrcPos->GetX()-s*fSrcPos->GetY();
-  Float_t newY = s*fSrcPos->GetX()+c*fSrcPos->GetY();
-
+  Float_t newX = c*srcpos->GetX()-s*srcpos->GetY();
+  Float_t newY = s*srcpos->GetX()+c*srcpos->GetY();
+  
 #ifdef DEBUG
   Double_t rotationAngleComp = fObservatory->RotationAngle(0.1256,2.63);
   cout << "Event " << fEvtHeader->GetDAQEvtNumber() << endl;
-  cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl,
+  cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl;
 #endif
-
-  fSrcPos->SetX(newX);
-  fSrcPos->SetY(newY);
-  fDCA->SetRefPoint(newX,newY);
+  
+  srcpos->SetX(newX);
+  srcpos->SetY(newY);
+  dca->SetRefPoint(newX,newY);
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h	(revision 4072)
@@ -2,48 +2,41 @@
 #define MARS_MSrcRotate
 
-#ifndef MARS_MTask
-#include "MTask.h"
+#ifndef MARS_MSrcPlace
+#include "MSrcPlace.h"
 #endif
 
-#include <TArrayF.h>
 #include "MTime.h"
-#include "MSrcPosCam.h"
 
-class MDCA;
 class MObservatory;
 class MRawEvtHeader;
 class MRawRunHeader;
 
-class MSrcRotate : public MTask
+class MSrcRotate : public MSrcPlace
 {
-private:
-    MSrcPosCam*    fSrcPos;      //  Pointer to the source position
-    MDCA*          fDCA;         //  Pointer to the MDCA object
-    MRawEvtHeader* fEvtHeader;   //  Pointer to the event header
-    MRawRunHeader* fRunHeader;   //  Pointer to the run header
-    MObservatory*  fObservatory; //  Pointer to the MObservatory    
-
-    TString     fSrcPosName;
-    TString     fDCAName;
-
-    Double_t   fRA;          //  [rad] Right ascention 
-    Double_t   fDEC;         //  [rad] Declination
-    Double_t   fRefMJD;      //  [MJ date] reference time for rotation
-    UInt_t     fNEvts;       //  Number of events in file
-    MTime      fIniTime;     //  Run initial time 
-    MTime      fFinTime;     //  Run final time 
-    Double_t   fDeltaT;      //  DeltaT between two events
-    UInt_t     fRunNumber;   //  Current run number
-
-    Int_t PreProcess(MParList *plist);
-    Int_t Process();
-
-public:
-    MSrcRotate(const char* src="MSrcPosCam", const char* dca="MDCA",
-	       const char* name=NULL, const char* title=NULL);
-
-    void SetRAandDECandRefMJD(Double_t ra, Double_t dec, Double_t ref) {fRA=ra;fDEC=dec;fRefMJD=ref;}
-
-    ClassDef(MSrcRotate, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles
+ private:
+  MRawEvtHeader* fEvtHeader;   //  Pointer to the event header
+  MRawRunHeader* fRunHeader;   //  Pointer to the run header
+  MObservatory*  fObservatory; //  Pointer to the MObservatory    
+  
+  Double_t   fRA;          //  [rad] Right ascenssion 
+  Double_t   fDEC;         //  [rad] Declination
+  Double_t   fRefMJD;      //  [MJ date] reference time for rotation
+  UInt_t     fNEvts;       //  Number of events in file
+  MTime      fIniTime;     //  Run initial time 
+  MTime      fFinTime;     //  Run final time 
+  Double_t   fDeltaT;      //  DeltaT between two events
+  UInt_t     fRunNumber;   //  Current run number
+  
+  virtual Int_t PreProcess(MParList *plist);
+  
+ public:
+  MSrcRotate(const char* src="MSrcPosCam", const char* dca="MDCA",
+	     const char* name=NULL, const char* title=NULL);
+  
+  void SetRAandDECandRefMJD(Double_t ra, Double_t dec, Double_t ref=0) {fRA=ra;fDEC=dec;fRefMJD=ref;}
+  void SetRAandDEC(Double_t ra, Double_t dec){SetRAandDECandRefMJD(ra,dec);}
+  virtual Int_t ComputeNewSrcPosition();
+  
+  ClassDef(MSrcRotate, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles
 };
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile	(revision 4063)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile	(revision 4072)
@@ -51,4 +51,5 @@
         MPSFFit.cc \
         MPSFFitCalc.cc \
+	MSrcPlace.cc \
         MSrcPosFromFile.cc \
 	MSrcRotate.cc \
