Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc	(revision 4056)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc	(revision 4072)
@@ -29,4 +29,5 @@
 #include "MArgs.h"
 #include "MWriteRootFile.h"
+#include "MTime.h"
 
 using namespace std;
@@ -40,13 +41,16 @@
 
 TString  inputFile;
+TString  offFile;
 TString  outputFile;
+TString  offOutputFile;
 ULong_t  nmaxevents=999999999;
 Float_t  xsrcpos=0.;
 Float_t  ysrcpos=0.;
 Double_t mjdpos=53050;
-Bool_t   kRotate=1;
-Bool_t   kSrcPolicy=kTRUE;
+Bool_t   kRotate=0;
+Bool_t   kSrcPolicy=kFALSE;
 Double_t fRA= -1.;
 Double_t fDEC= -1.;
+TString  srcFile;
 
 //-----------------------------------------------------------------------------
@@ -55,7 +59,4 @@
 
 const TString defaultcard="srcpos.datacard";
-
-const Float_t alphamin = 0.;       // minimum value in alpha (degrees) 
-const Float_t alphamax = 90.;      // maximum value in alpha (degrees)
 const Float_t conver   = 189./0.6; // conversion factor degrees to mm
 
@@ -147,4 +148,33 @@
   tlist.PrintStatistics();
 
+  
+  // do off-data if input file was specified
+  if(!offFile.Length())
+    return;
+
+  MReadTree read2("Parameters", offFile);
+  read2.DisableAutoScheme();  
+  tlist.AddToListBefore(&read2, &read, "All");
+  tlist.RemoveFromList(&read);
+
+  MWriteRootFile write2(offOutputFile,"RECREATE");
+  write2.AddContainer("MHillas"       , "Parameters");
+  write2.AddContainer("MHillasSrc"    , "Parameters");
+  write2.AddContainer("MHillasExt"    , "Parameters");
+  write2.AddContainer("MNewImagePar"  , "Parameters");
+  write2.AddContainer("MRawEvtHeader" , "Parameters");
+  write2.AddContainer("MRawRunHeader" , "Parameters");
+  write2.AddContainer("MConcentration" , "Parameters");
+  write2.AddContainer("MSrcPosCam"     , "Parameters");
+  tlist.AddToListBefore(&write2,&write,"All");
+  tlist.RemoveFromList(&write);
+
+  srcrotate.SetMode(MSrcPlace::kOff);
+
+  if (!evtloop.Eventloop(nmaxevents))
+    return;  
+
+  tlist.PrintStatistics();
+
 }
 //-----------------------------------------------------------------------
@@ -182,4 +212,12 @@
 	}
 
+      // off-data file name
+      if(strcmp(word.Data(),"OFFFILES")==0)
+	{
+	  if(offFile.Length())
+	    cout << "readDataCards Warning: overriding off-data file name" << endl;
+	  ifun >> offFile;
+	}
+
       // output file name
       if(strcmp(word.Data(),"OUTFILE")==0)
@@ -190,4 +228,20 @@
 	}
 
+      // output file name (off data)
+      if(strcmp(word.Data(),"OFFOUTFILE")==0)
+	{
+	  if(offOutputFile.Length())
+	    cout << "readDataCards Warning: overriding output file name for off data" << endl;
+	  ifun >> offOutputFile;
+	}
+
+      // source position input file
+      if(strcmp(word.Data(),"SRCFILE")==0)
+	{
+	  if(srcFile.Length())
+	    cout << "readDataCards Warning: overriding source-position file name" << endl;
+	  ifun >> srcFile;
+	}
+
       // source position
       if(strcmp(word.Data(),"SRCPOS")==0)
@@ -227,4 +281,10 @@
     }
 
+  if(offFile.Length() && !offOutputFile.Length())
+    {
+      cout << "No output file name specified for off data" << endl;
+      return kFALSE;
+    }
+
   if(xsrcpos==0 && ysrcpos==0)
     {
@@ -232,4 +292,6 @@
       return kFALSE;
     }
+
+  MTime thetime(mjdpos);
 
   // Dump read values
@@ -239,12 +301,22 @@
   cout << "Maximum number of input events: " << nmaxevents << endl;
   cout << "Input file name(s): " << inputFile << endl;
+  if(offFile.Length())
+    cout << "Input file name(s) for off data: " << offFile << endl;
   cout << "Output file name: " << outputFile << endl;
-  cout << "Source position (degrees) X=" << xsrcpos << ", Y="<<ysrcpos;
-  if(kSrcPolicy)
-    cout << " (RELATIVE TO INITIAL SOURCE POSITION)" << endl;
+  if(offFile.Length())
+    cout << "Output file name for off data: " << offOutputFile << endl;
+  if(srcFile.Length())
+    cout << "Reading source position from file " << srcFile << endl;
   else
-    cout << " (ABSOLUTE POSITION IN THE CAMERA)" << endl;
-  cout << "De-rotation flag " << kRotate << endl;
-  cout << "Source celestial coordiantes (rad): RA = " << fRA << ", DEC = " << fDEC << endl;
+    {
+      cout << "Source position (degrees) X=" << xsrcpos << ", Y="<<ysrcpos;
+      if(kSrcPolicy)
+	cout << " (RELATIVE TO INITIAL SOURCE POSITION)";
+      else
+	cout << " (ABSOLUTE POSITION IN THE CAMERA)";
+      cout << ", at " << thetime.GetSqlDateTime() << endl;
+      cout << "De-rotation flag " << kRotate << endl;
+      cout << "Source celestial coordiantes (rad): RA = " << fRA << ", DEC = " << fDEC << endl;
+    }
   cout << "***********" << endl << endl;
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4056)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4072)
@@ -1,13 +1,19 @@
 
 // Maximun number of on and off events to be processed)
-NEVENTS 20000
+NEVENTS 99999999
 
 // Input file name pattern
-INPUTFILES   /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OnNoCalB.root
+INPUTFILES /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OnNoCalB.root
 
-// output file name
+// Specify optionally the name of OFF-data files you want to apply the same source position distribution to
+OFFFILES  /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OffNoCal*.root
+
+// output file name (on data)
 OUTFILE  ./srcPosPrueba.root
 
-// X and Y position of the source in degrees for a MJ date (days) -important only in case of rotation
+// output file name (off data)
+OFFOUTFILE ./srcPosOffPrueba.root
+
+// X and Y position of the source (degrees) for a MJ date (days) -important only in case of rotation
 SRCPOS  0.21  0.176   53050.0773
 
@@ -24,2 +30,8 @@
 SRCCOORDS 2.899 0.667   // (Mrk 421)
 
+
+// File containing source position as a function of run number (overrides SRCPOS, SRCABS, ROTFLAG and SRCCOORDS values)
+// SRCFILE ./20040215_Mrk421.B.pos
+
+
+
