Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4094)
@@ -18,4 +18,34 @@
 
                                                  -*-*- END OF LINE -*-*-
+	
+ 2004/05/18  Javier Rico
+   * library/MSrcPlace.[cc,h], library/MSrcRotate.[cc,h], 
+     library/MSrcTranslate.[cc,h], library/MSrcPosFromFile.[cc,h]
+     - Add the possibility of having different input and output 
+       MSrcPosCam containers (CONSTRUCTORS HAVE CHANGED!)
+     - Move the creation of internal histogram to PreProcess, so that
+       it can be configured before creation. Now configurable: whether
+       histo must be created or not (fCreateHisto), histo bin size 
+       (fHistoBinPrec), histogram name (fHistoName), with corresponding
+       getters and setters
+     - Update documentation
+
+   * library/MSrcPosFromFile.cc	
+     - If no position has been measured for the first analyzed run, use
+       the one of the first run in file instead.
+
+   * programs/falseSource.cc
+     - Change obsolete MSrcPosCam predefinitions for modern 
+       MSrcTranslate objects, which allow relative displacement of the
+       source position from a previously assigned one. 
+     - Add flag for relative translation
+     - Include control histograms (hOn[Off]SrcPos) for the source 
+       position
+
+   * programs/falsesource.datacard
+     - Add datacard SRCABS for relative/absolute source translation
+
+   * programs/srcPos.cc
+     - Avoid creation of internal histograms for the translation
 	
  2004/05/17  Javier Rico
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc	(revision 4094)
@@ -66,24 +66,21 @@
 //
 // Default constructor. The first argument is the name of the internal histo, 
-// the second (third) 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* histname, const char* srcPos, const char* dca, const char *name, const char *title)
-  : fSrcPos(NULL), fDCA(NULL)
+// the second (third) argument is the name of the input (output) container
+// containing the source position in the camera plain. Fourth argument is the
+// name of the output MDCA container.
+//
+MSrcPlace::MSrcPlace(const char* srcPosIn, const char* srcPosOut, const char* dca, const char *name, const char *title)
+  : fSrcPosIn(NULL), fSrcPosOut(NULL), fDCA(NULL), fHistoName("SrcPosHist"), 
+    fHistoBinPrec(1.), fHistPos(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);
-    
-    fHistPos = new TH2F(histname,"",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
+    fSrcPosInName   = srcPosIn;
+    fSrcPosOutName  = srcPosOut;
+    fDCAName        = dca;
 
     fMode=kOn;
+    fCreateHisto=kTRUE;
 }
 // -------------------------------------------------------------------------
@@ -103,5 +100,6 @@
 void MSrcPlace::SavePosIntoHisto()
 {  
-  fHistPos->Fill(fSrcPos->GetX(),fSrcPos->GetY());
+  if(fHistPos)
+    fHistPos->Fill(fSrcPosOut->GetX(),fSrcPosOut->GetY());
 }
 // -------------------------------------------------------------------------
@@ -111,10 +109,13 @@
 void MSrcPlace::ReadPosFromHisto()
 {  
-  Axis_t x;
-  Axis_t y;
-  
-  fHistPos->GetRandom2(x,y);
-  fSrcPos->SetXY(x,y);
-  fDCA->SetRefPoint(x,y);
+  if(fHistPos)
+    {
+      Axis_t x;
+      Axis_t y;
+      
+      fHistPos->GetRandom2(x,y);
+      fSrcPosOut->SetXY(x,y);
+      fDCA->SetRefPoint(x,y);
+    }
 }
 // -------------------------------------------------------------------------
@@ -125,11 +126,31 @@
 Int_t MSrcPlace::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)
+  // create (if needed and requested) internal histogram
+  if(fCreateHisto && !fHistPos)
+    {
+      const Float_t cameraSize   = 600; //[mm]
+      const UInt_t nbins =  (UInt_t)(cameraSize*2/fHistoBinPrec);
+      fHistPos = new TH2F(fHistoName,"",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
+      fHistPos->SetDirectory(0);
+      *fLog << inf << "MSrcPlace::PreProcess Message: internal histogram " << fHistoName << " created with " << nbins << "x" << nbins << " bins" << endl;
+    }
+
+  // look for/create input MSrcPosCam
+  fSrcPosIn = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosInName), "MSrcPosCam");
+  if (!fSrcPosIn)
+    {
+      *fLog << warn << AddSerialNumber(fSrcPosInName) << " [MSrcPosCam] not found... creating default container." << endl;
+      fSrcPosIn = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosInName));
+      if(!fSrcPosIn)
+	return kFALSE;
+    }
+
+  // look for/create output MSrcPosCam
+  fSrcPosOut = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosOutName), "MSrcPosCam");
+  if (!fSrcPosOut)
+    {
+      *fLog << warn << AddSerialNumber(fSrcPosOutName) << " [MSrcPosCam] not found... creating default container." << endl;
+      fSrcPosOut = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosOutName));
+      if(!fSrcPosOut)
 	return kFALSE;
     }
@@ -146,14 +167,17 @@
 
   // check mode, look for a filled histogram in case kOff
-  if(fMode==kOn)
-    *fLog << inf << "MSrcPlace PreProcess Message: source postions will be stored in internal histo (" << fHistPos->GetName() << ")" << endl;
-  else
-    {
-      if(fHistPos->GetEntries())
-	*fLog << inf << "MSrcPlace PreProcess Message: source postions will be read from internal histo (" << fHistPos->GetName() << ")" << endl;
+  if(fHistPos)
+    {
+      if(fMode==kOn)
+	*fLog << inf << "MSrcPlace PreProcess Message: source postions will be stored in internal histo (" << fHistPos->GetName() << ")" << endl;
       else
 	{
-	  *fLog << err << "MSrcPlace PreProcess Error: source postions attempted to be read from empty histo (" << fHistPos->GetName() << ")" << endl;
-	  return kFALSE;
+	  if(fHistPos->GetEntries())
+	    *fLog << inf << "MSrcPlace PreProcess Message: source postions will be read from internal histo (" << fHistPos->GetName() << ")" << endl;
+	  else
+	    {
+	      *fLog << err << "MSrcPlace PreProcess Error: source postions attempted to be read from empty histo (" << fHistPos->GetName() << ")" << endl;
+	      return kFALSE;
+	    }
 	}
     }
@@ -191,5 +215,5 @@
 Int_t MSrcPlace::PostProcess()
 {
-  if(fMode==kOn)
+  if(fMode==kOn && fHistPos)
     {
       *fLog << inf << endl;
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.h	(revision 4094)
@@ -16,12 +16,18 @@
   
  private:
-  MSrcPosCam*  fSrcPos;      //  Pointer to the source position
-  MDCA*        fDCA;         //  Pointer to the MDCA object
+  MSrcPosCam*  fSrcPosIn;       //  Pointer to the input source position container
+  MSrcPosCam*  fSrcPosOut;      //  Pointer to the output source position container
+  MDCA*        fDCA;            //  Pointer to the output MDCA container
   
-  TString      fSrcPosName;  //  Name of the MSrcPosCam object
-  TString      fDCAName;     //  Name of the MDCA object
-  
-  TH2F*        fHistPos;  //  histogram of the used source positions
+  TString      fSrcPosInName;   //  Name of the input MSrcPosCam object
+  TString      fSrcPosOutName;  //  Name of the output MSrcPosCam object
+  TString      fDCAName;        //  Name of the MDCA object
+
+  TString      fHistoName;      //  Name of internal histogram
+  Float_t      fHistoBinPrec;   //  [mm] internal histo bin size 
+
+  TH2F*        fHistPos;     //  histogram of the used source positions
   OnOffMode_t  fMode;        //  On/Off data mode (write/read to/from the histogram)
+  Bool_t       fCreateHisto; //  flag to decide whether internal histo is created or not
 
   void  SavePosIntoHisto();
@@ -35,18 +41,24 @@
 
  public:
-  MSrcPlace(const char* histname="HistSrcPos",
-	    const char* src="MSrcPosCam", const char* dca="MDCA",
+  MSrcPlace(const char* srcin="MSrcPosCam",const char* srcout="MSrcPosCam", 
+	    const char* dcaout="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;}
+  void SetMode(OnOffMode_t mode)            {fMode=mode;}
+  void SetInputSrcPosName(TString name)     {fSrcPosInName=name;}
+  void SetOutputSrcPosName(TString name)    {fSrcPosOutName=name;}
+  void SetDCAName(TString name)             {fDCAName=name;}
+  void SetInternalHistoName(TString name)   {fHistoName=name;}
+  void SetInternalHistoBinSize(Float_t size){fHistoBinPrec=size;}
+  void SetCreateHisto(Bool_t inp=kTRUE)     {fCreateHisto=inp;}
 
-  OnOffMode_t   GetMode()            {return fMode;}
-  TH2F*         GetPositionHisto()   {return fHistPos;}
-  MSrcPosCam*   GetSrcPosCam()       {return fSrcPos;}
-  MDCA*         GetDCA()             {return fDCA;}
+  OnOffMode_t   GetMode()              {return fMode;}
+  TH2F*         GetPositionHisto()     {return fHistPos;}
+  MSrcPosCam*   GetInputSrcPosCam()    {return fSrcPosIn;}
+  MSrcPosCam*   GetOutputSrcPosCam()   {return fSrcPosOut;}
+  MDCA*         GetDCA()               {return fDCA;}
+  TString       GetInternalHistoName() {return fHistoName;}
   
   virtual Int_t ComputeNewSrcPosition() {return kTRUE;}
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc	(revision 4094)
@@ -47,4 +47,5 @@
 #include "MLogManip.h"
 
+
 ClassImp(MSrcPosFromFile);
 
@@ -61,5 +62,5 @@
 //
 MSrcPosFromFile::MSrcPosFromFile(TString cardpath, OnOffMode_t mode, const char *name, const char *title)
-  : MSrcPlace(TString(gsDefName+"Hist").Data()), fRawRunHeader(NULL), fSourcePositionFilePath(cardpath)
+  : fRawRunHeader(NULL), fSourcePositionFilePath(cardpath)
 {
   fName  = name  ? name  : gsDefName.Data();
@@ -71,6 +72,9 @@
   fRunMap=0x0;
 
-  fLastRun = 0;
+  fLastRun  = 0;
+  fFirstRun = 0;
   fLastValidSrcPosCam=0x0;
+
+  SetInternalHistoName(TString(fName)+"Hist");
 }
 // -------------------------------------------------------------------------
@@ -139,24 +143,18 @@
       if(srcpos)
 	fLastValidSrcPosCam = srcpos;
+      else if(fLastValidSrcPosCam)
+	*fLog << inf << " not found in file. Taking previous position: ";
       else
-	*fLog << inf << " not found in file. Taking previous position: ";
-
-      if(fLastValidSrcPosCam)
 	{
-	  *fLog << inf << "\tX\t" << setprecision(3) << fLastValidSrcPosCam->GetX();
-	  *fLog << inf << "\tY\t" << setprecision(3) << fLastValidSrcPosCam->GetY() << endl;      
+	  *fLog << warn << "MSrcPosFromFile::ComputeNewSrcPosition warning: no value for the first run. Taking first found run in file, run number " << fFirstRun << endl;
+	  fLastValidSrcPosCam = (MSrcPosCam*)fRunMap->GetValue(run);
 	}
-    }
-
-  if(fLastValidSrcPosCam)
-    {
-      GetSrcPosCam()->SetXY(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
-      GetDCA()->SetRefPoint(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
-    }
-  else
-    {
-      *fLog << err << "MSrcPosFromFile::ComputeNewSrcPosition error: no value for the first run. Don't know what values to take" << endl;
-      return kFALSE;
-    }
+
+      *fLog << inf << "\tX\t" << setprecision(3) << fLastValidSrcPosCam->GetX();
+      *fLog << inf << "\tY\t" << setprecision(3) << fLastValidSrcPosCam->GetY() << endl;      
+    }
+
+  GetOutputSrcPosCam()->SetXY(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
+  GetDCA()->SetRefPoint(fLastValidSrcPosCam->GetX(),fLastValidSrcPosCam->GetY());
 
   return kTRUE;
@@ -186,4 +184,5 @@
     {
       fin >> run >> x >> y;
+      if(!fFirstRun) fFirstRun=run;
       if(fin.eof())
 	break;
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h	(revision 4094)
@@ -20,4 +20,5 @@
 
     Int_t  fNumRuns;
+    UInt_t  fFirstRun;
     UInt_t  fLastRun;
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc	(revision 4094)
@@ -62,16 +62,19 @@
 // -------------------------------------------------------------------------
 //
-// 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"). 
-//
-MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title)
-  : MSrcPlace(TString(gsDefName+"Hist").Data()), fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
+// Default constructor. The first (second) argument is the name of the
+// input (output) MSrcPosCam object containing the source position in the 
+// camera plain
+//
+MSrcRotate::MSrcRotate(const char* srcPosIn, const char* srcPosOut, const char* dca, const char *name, const char *title)
+  : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
 {
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
 
-    SetSrcPosName(srcPos);
+    SetInputSrcPosName(srcPosIn);
+    SetOutputSrcPosName(srcPosOut);
     SetDCAName(dca);
+
+    SetInternalHistoName(TString(fName)+"Hist");
 }
 
@@ -176,5 +179,6 @@
     Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC) :
     Observation.RotationAngle(fRA,fDEC) ;
-  MSrcPosCam* srcpos = GetSrcPosCam();
+  MSrcPosCam* srcposIn  = GetInputSrcPosCam();
+  MSrcPosCam* srcposOut = GetOutputSrcPosCam();
   MDCA* dca = GetDCA();
   
@@ -182,15 +186,14 @@
   Float_t s = TMath::Sin(rotationAngle);
   // perform a rotation of -rotationAngle to move the source back to the "initial" position
-  Float_t newX = c*srcpos->GetX()-s*srcpos->GetY();
-  Float_t newY = s*srcpos->GetX()+c*srcpos->GetY();
+  Float_t newX = c*srcposIn->GetX()-s*srcposIn->GetY();
+  Float_t newY = s*srcposIn->GetX()+c*srcposIn->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="<<fIniSrcPosIn.GetX()<< ", oldY="<<fIniSrcPosIn.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl;
 #endif
   
-  srcpos->SetX(newX);
-  srcpos->SetY(newY);
+  srcposOut->SetXY(newX,newY);
   dca->SetRefPoint(newX,newY);
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h	(revision 4094)
@@ -31,5 +31,6 @@
   
  public:
-  MSrcRotate(const char* src="MSrcPosCam", const char* dca="MDCA",
+  MSrcRotate(const char* srcIn="MSrcPosCam",const char* srcOut="MSrcPosCam",
+	     const char* dca="MDCA",
 	     const char* name=NULL, const char* title=NULL);
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.cc	(revision 4094)
@@ -33,5 +33,4 @@
 //  Input Containers:
 //    MSrcPosCam
-//    [MDCA]
 //
 //  Output Containers:
@@ -62,16 +61,19 @@
 // -------------------------------------------------------------------------
 //
-// 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"). 
+// Default constructor. The first (second) argument is the name of the
+// input (output) MSrcPosCam object containing the source position in the 
+// camera plain
 //
-MSrcTranslate::MSrcTranslate(const char* srcPos, const char* dca, const char *name, const char *title)
-  : MSrcPlace(TString(gsDefName+"Hist").Data()), fShiftX(0.), fShiftY(0.), fTranslationIsRelative(kTRUE)
+MSrcTranslate::MSrcTranslate(const char* srcPosIn, const char* srcPosOut, const char* dca, const char *name, const char *title)
+  : fShiftX(0.), fShiftY(0.), fTranslationIsRelative(kTRUE)
 {
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
 
-    SetSrcPosName(srcPos);
+    SetInputSrcPosName(srcPosIn);
+    SetOutputSrcPosName(srcPosOut);
     SetDCAName(dca);
+
+    SetInternalHistoName(TString(fName)+"Hist");
 }
 
@@ -100,11 +102,12 @@
   Double_t newX,newY;
 
-  MSrcPosCam* srcPos = GetSrcPosCam();
-  MDCA*       dca    = GetDCA();
-
+  MSrcPosCam* srcPosOut = GetOutputSrcPosCam();
+  MDCA*       dca       = GetDCA();
+  
   if(fTranslationIsRelative)
     {
-      newX=srcPos->GetX()+fShiftX;
-      newY=srcPos->GetY()+fShiftY;
+      MSrcPosCam* srcPosIn  = GetInputSrcPosCam();
+      newX=srcPosIn->GetX()+fShiftX;
+      newY=srcPosIn->GetY()+fShiftY;
     }
   else
@@ -114,6 +117,5 @@
     }
 
-  srcPos->SetX(newX);
-  srcPos->SetY(newY);
+  srcPosOut->SetXY(newX,newY);
   dca->SetRefPoint(newX,newY);
 
Index: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcTranslate.h	(revision 4094)
@@ -17,5 +17,6 @@
 
  public:
-  MSrcTranslate(const char* src="MSrcPosCam", const char* dca="MDCA",
+  MSrcTranslate(const char* srcIn="MSrcPosCam", const char* srcOut="MSrcPosCam", 
+		const char* dca="MDCA",
 		const char* name=NULL, const char* title=NULL);
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/macros/alpha.C
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/macros/alpha.C	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/macros/alpha.C	(revision 4094)
@@ -36,48 +36,10 @@
     
     // ON data
-    //    ton->Add("/disc01/HillasFiles/crabOnMisp3015_A.root");
-    //    ton->Add("/disc01/HillasFiles/crabOnMisp3015_B.root");
-    //    ton->Add("/disc01/HillasFiles/crabOnMisp3015_C.root");
-    //    ton->Add("/disc01/HillasFiles/crabOnMisp3015_D.root");
-    //    ton->Add("hillasCrab/crab20040215OnA.root");
-    //    ton->Add("hillasCrab/crab20040215OnB.root");
-    //    ton->Add("hillasCrab/crab20040215OnC.root");
-    //    ton->Add("hillasCrab/crab20040215OnD.root");
-    //    ton->Add("hillasCrab/crab20040215OnRotate2_-1.root");
-    ton->Add("/disc01/HillasFiles/Mrk421/mrk421OnMisp3015_A.root");
-    ton->Add("/disc01/HillasFiles/Mrk421/mrk421OnMisp3015_B.root");
-    //ton->Add("/disc01/HillasFiles/Mrk421/mrk421OnMisp3015_C.root");
-    //    ton->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOn3015_A_-1-2.root");
-    //    ton->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOn3015_B_-1-1.root");
-    //ton->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOn3015_C.root");
+    ton->Add("/mnt/users/jrico/magic/mars/mars/mtemp/mifae/programs/srcPosPrueba.root");
 
     TChain* toff= new TChain("Parameters");
 
     // OFF data
-    //toff->Add("/disc01/HillasFiles/crabOffMisp3015_A.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_B.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_C.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_D.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_E.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_F.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_G.root");
-    //    toff->Add("/disc01/HillasFiles/crabOffMisp3015_H.root");
-        //    toff->Add("hillasCrab/crab20040215OffA.root");
-    //    toff->Add("hillasCrab/crab20040215OffB.root");
-    //    toff->Add("hillasCrab/crab20040215OffC.root");
-    //    toff->Add("hillasCrab/crab20040215OffD.root");
-    //    toff->Add("hillasCrab/crab20040215OffE.root");
-    //    toff->Add("hillasCrab/crab20040215OffF.root");
-    //    toff->Add("hillasCrab/crab20040215OffG.root");
-    //    toff->Add("hillasCrab/crab20040215OffH.root");
-    //    toff->Add("hillasCrab/crab20040215OffRotate2_-1.root");
-    toff->Add("/disc01/HillasFiles/OffMrk421/mrk421OffMisp3015_A.root");
-    toff->Add("/disc01/HillasFiles/OffMrk421/mrk421OffMisp3015_B.root");
-    toff->Add("/disc01/HillasFiles/OffMrk421/mrk421OffMisp3015_C.root");
-    //    toff->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOff3015_-1-1.root");
-    //    toff->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOff3015_A.root");
-    //    toff->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOff3015_B.root");
-    //    toff->Add("~aliu/MagicData/CrabNebula/2004_03_19/crabOff3015_C.root");
-
+    toff->Add("/mnt/users/jrico/magic/mars/mars/mtemp/mifae/programs/srcPosOffPrueba.root");
     
     TCanvas *c1 = new TCanvas("c1","c1",800,500);
Index: trunk/MagicSoft/Mars/mtemp/mifae/macros/signal.C
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/macros/signal.C	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/macros/signal.C	(revision 4094)
@@ -16,5 +16,5 @@
   Float_t array[2];
   
-  Int_t nbin2d = 10;
+  Int_t nbin2d = 5;
   Int_t ntotal = 2*nbin2d+1;
   
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/falseSource.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/falseSource.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/falseSource.cc	(revision 4094)
@@ -16,9 +16,10 @@
 
 #include "TString.h"
-#include "TH1F.h"
+#include "TH2F.h"
 #include "TFile.h"
 
 #include "MHillasSrcCalc.h"
 #include "MSrcPosCam.h"
+#include "MSrcTranslate.h"
 #include "MHillasSrc.h"
 #include "MSrcRotate.h"
@@ -43,5 +44,6 @@
 TString offFile;
 TString outputFile;
-Bool_t kRotate=1;
+Bool_t  kRotate=1;
+Bool_t  kSrcPolicy=kFALSE;
 Double_t fRA= -1.;
 Double_t fDEC= -1.;
@@ -73,4 +75,7 @@
 const Float_t alphamax = 90.;      // maximum value in alpha (degrees)
 const Float_t conver   = 189./0.6; // conversion factor degrees to mm
+const Float_t srclimit = field*conver;
+const Float_t srcstep  = 3.;
+const Int_t   nsrcbin  = (Int_t) (srclimit/srcstep);
 
 //-----------------------------------------------------------------------------
@@ -131,6 +136,9 @@
   
   // create the histograms (empty)
-  TH1F *hOnAlpha[binning][binning];
-  TH1F *hOffAlpha[binning][binning];
+  TH1F* hOnAlpha[binning][binning];
+  TH1F* hOffAlpha[binning][binning];
+  TH2F* hOnSrcPos[binning];
+  TH2F* hOffSrcPos[binning];
+
   for(Int_t i = -ival; i <= ival ; i++){  
     for(Int_t j = -ival; j <= ival ; j++){
@@ -144,4 +152,14 @@
       hOffAlpha[i+ival][j+ival] = new TH1F(name, title, nbin, alphamin, alphamax);
 
+      if(j==0)
+	{
+	  sprintf(name,"hOnSrcPos[%d]", i);
+	  sprintf(title,"Source position (On data) (%d)", i);
+	  hOnSrcPos[i+ival] = new TH2F(name, title, nsrcbin, -srclimit, srclimit, nsrcbin, -srclimit, srclimit);
+	  
+	  sprintf(name,"hOffSrcPos[%d]", i);
+	  sprintf(title,"Source position (Off data) (%d)", i);
+	  hOffSrcPos[i+ival] = new TH2F(name, title, nsrcbin, -srclimit, srclimit, nsrcbin, -srclimit, srclimit);
+	}
     }
   }
@@ -154,8 +172,9 @@
   
   // source dependent hillas containers/tasks
-  MHillasSrcCalc* csrc1[binning][binning];
   MSrcPosCam*     source[binning][binning];
   MHillasSrc*     hillasSrc[binning][binning];
+  MSrcTranslate*  srctranslate[binning][binning];
   MSrcRotate*     srcrotate[binning][binning];
+  MHillasSrcCalc* csrc1[binning][binning];
 
   // normal containers/classes
@@ -171,7 +190,8 @@
   tlist.AddToList(&read);
     
-  Int_t k,l;  
   char sourceName[100];  
   char hillasSrcName[100];
+  char translateName[100];  
+  char rotateName[100];
 
   // create the tasks/containers for the different source positions
@@ -186,22 +206,28 @@
 	  if (i<0 && j<0)
 	    {
-	      k = -i;
-	      l = -j;
+	      Int_t k = -i;
+	      Int_t l = -j;
 	      sprintf(sourceName,    "MSrcPosCam_Min%dMin%d", k, l);
 	      sprintf(hillasSrcName, "MHillasSrc_Min%dMin%d", k, l);
+	      sprintf(translateName, "MSrcTranslate_Min%dMin%d", k, l);
+	      sprintf(rotateName,    "MSrcRotate_Min%dMin%d", k, l);
 	    }
 	  
 	  if (i<0 && j>=0)
 	    {
-	      k = -i;
+	      Int_t k = -i;
 	      sprintf(sourceName,    "MSrcPosCam_Min%d%d", k, j);
 	      sprintf(hillasSrcName, "MHillasSrc_Min%d%d", k, j);
+	      sprintf(translateName, "MSrcTranslate_Min%d%d", k, j);
+	      sprintf(rotateName,    "MSrcRotate_Min%d%d", k, j);
 	    }
 	  
 	  if (i>=0 && j<0)
 	    {
-	      l = -j;
+	      Int_t l = -j;
 	      sprintf(sourceName,    "MSrcPosCam_%dMin%d", i, l);
 	      sprintf(hillasSrcName, "MHillasSrc_%dMin%d", i, l);
+	      sprintf(translateName, "MSrcTranslate_%dMin%d", i, l);
+	      sprintf(rotateName,    "MSrcRotate_%dMin%d", i, l);
 	    }
 	  
@@ -210,11 +236,11 @@
 	      sprintf(sourceName,    "MSrcPosCam_%d%d", i, j);
 	      sprintf(hillasSrcName, "MHillasSrc_%d%d", i, j);
+	      sprintf(translateName, "MSrcTranslate_%d%d", i, j);
+	      sprintf(rotateName,    "MSrcRotate_%d%d", i, j);
 	    }
 
 	  // include containers in parameter list
 	  source[i+ival][j+ival] = new MSrcPosCam(sourceName);
-	  source[i+ival][j+ival]->SetXY(xpos, ypos);	  
 	  plist.AddToList(source[i+ival][j+ival]);
-	  source[i+ival][j+ival]->Print();
 	  	  
 	  hillasSrc[i+ival][j+ival] = new MHillasSrc(hillasSrcName);	  
@@ -222,10 +248,26 @@
 	  
 	  // define the different tasks and include them in the task list
-	  if(kRotate)
+	  srctranslate[i+ival][j+ival] = new MSrcTranslate("MSrcPosCam",sourceName,"MDCA",translateName);	  
+	  srctranslate[i+ival][j+ival]->SetTranslation(xpos,ypos);	  
+	  srctranslate[i+ival][j+ival]->SetRelativeTranslation(kSrcPolicy);
+	  srctranslate[i+ival][j+ival]->SetInternalHistoBinSize(5.);
+	  srctranslate[i+ival][j+ival]->SetMode(MSrcPlace::kOn);
+      
+	  tlist.AddToList(srctranslate[i+ival][j+ival]);  
+
+	  if(kRotate && !kSrcPolicy)
 	    {
-	      srcrotate[i+ival][j+ival] = new MSrcRotate(sourceName);
+	      srcrotate[i+ival][j+ival] = new MSrcRotate(sourceName,sourceName,"MDCA",rotateName);
 	      srcrotate[i+ival][j+ival]->SetRAandDEC(fRA,fDEC);	  
+
+	      srctranslate[i+ival][j+ival]->SetCreateHisto(kFALSE);
+	      srcrotate[i+ival][j+ival]->SetMode(MSrcPlace::kOn);	      
+	      srcrotate[i+ival][j+ival]->SetInternalHistoBinSize(5.);
+
 	      tlist.AddToList(srcrotate[i+ival][j+ival]);  
 	    }
+	  else
+	    srcrotate[i+ival][j+ival] = NULL;
+
 
 	  TString HilName = "MHillas";	  
@@ -266,4 +308,8 @@
 		hOnAlpha[i+ival][j+ival]->Fill(TMath::Abs(alpha));
 	      }	
+
+	    // fill source position histo
+	    if(j==0)
+	      hOnSrcPos[i+ival]->Fill(source[i+ival][j+ival]->GetX(),source[i+ival][j+ival]->GetY());
 	  }
       if(++nread>nmaxevents) break;
@@ -278,4 +324,12 @@
                         FILL OFF-DATA HISTOS
   *******************************************************************/
+ for(Int_t i=-ival;i<=ival;i++)
+   for(Int_t j=-ival;j<=ival;j++)
+     {
+       if(srcrotate[i+ival][j+ival])
+	 srcrotate[i+ival][j+ival]->SetMode(MSrcPlace::kOff);
+       srctranslate[i+ival][j+ival]->SetMode(MSrcPlace::kOff);
+     }
+
   
   MReadTree read2("Parameters", offFile);
@@ -306,4 +360,8 @@
 		hOffAlpha[i+ival][j+ival]->Fill(TMath::Abs(alpha));	      
 	      } 	
+
+	    // fill source position histo
+	    if(j==0)
+	      hOffSrcPos[i+ival]->Fill(source[i+ival][j+ival]->GetX(),source[i+ival][j+ival]->GetY());
 	  }
       if(++nread>nmaxevents) break;
@@ -319,4 +377,9 @@
       hOnAlpha[i+ival][j+ival]->Write();
       hOffAlpha[i+ival][j+ival]->Write();
+      if(j==0)
+	{
+	  hOnSrcPos[i+ival]->Write();
+	  hOffSrcPos[i+ival]->Write();
+	}
     }
   }
@@ -324,4 +387,14 @@
   f->Close();
 
+ for(Int_t i=-ival;i<=ival;i++)
+   for(Int_t j=-ival;j<=ival;j++)
+     {
+       if(srcrotate[i+ival][j+ival])
+	 delete srcrotate[i+ival][j+ival];
+       delete srctranslate[i+ival][j+ival];
+       delete source[i+ival][j+ival];
+       delete hillasSrc[i+ival][j+ival];
+       delete csrc1[i+ival][j+ival];
+     }
 }
 //-----------------------------------------------------------------------
@@ -379,4 +452,9 @@
 	ifun >> kRotate;
 
+      // source movement policy flag
+      if(strcmp(word.Data(),"SRCABS")==0)
+	ifun >> kSrcPolicy;	  
+
+
       // source celestial coordinates 
       if(strcmp(word.Data(),"SRCCOORDS")==0)
@@ -394,11 +472,7 @@
 	ifun >> binning;
 
-
       // Number of bins in alpha plots
       if(strcmp(word.Data(),"NBIN")==0)
 	ifun >> nbin;
-
-      
-
 
       // size cut
@@ -461,6 +535,11 @@
   cout << "Off-data file name(s): " << offFile << endl;
   cout << "Output file name: " << outputFile << endl;
-  cout << "De-rotation flag " << kRotate << endl;
-  cout << "Source celestial coordiantes (rad): RA = " << fRA << ", DEC = " << fDEC << endl;
+  if(kSrcPolicy)
+    cout << "Source position displaced with respect to the original existing one (no rotation applied)" << endl;
+  else
+    {
+      cout << "De-rotation flag " << kRotate << endl;
+      cout << "Source celestial coordiantes (rad): RA = " << fRA << ", DEC = " << fDEC << endl;
+    }
   cout << "Field width (degrees): " << field << endl;
   cout << "Field binning: " << binning << endl;
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/falsesource.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/falsesource.datacard	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/falsesource.datacard	(revision 4094)
@@ -4,11 +4,11 @@
 
 // On-data file name pattern
-ONFILES  /mnt/users/jrico/magic/mars/Mars_Standard01/hillasCrab/crab20040215On*.root
+ONFILES  ./srcPosPrueba.root
 
 // Off-data file name pattern
-OFFFILES /mnt/users/jrico/magic/mars/Mars_Standard01/hillasCrab/crab20040215Off*.root
+OFFFILES ./srcPosOffPrueba.root
 
 // output file name
-OUTFILE  ./rotateprueba.root
+OUTFILE  ./rotateprueba2.root
 
 // rotation flag:
@@ -19,4 +19,8 @@
 // source coordinates (RA DEC in rads)
 SRCCOORDS 1.46 0.384
+
+// Flag to determine whether source position is absolute (0) or relative to previous position (1)
+// In case SRCABS=1, no rotation is carried out
+SRCABS 1 
 
 // Width of examined field (degrees)
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/srcPos.cc	(revision 4094)
@@ -128,4 +128,5 @@
       srctranslate.SetTranslation(xpos,ypos);
       srctranslate.SetRelativeTranslation(kSrcPolicy);
+      srctranslate.SetCreateHisto(kFALSE);
       srcrotate.SetRAandDECandRefMJD(fRA,fDEC,mjdpos); 
       srcrotate.SetMode(MSrcPlace::kOn);
@@ -164,5 +165,4 @@
  
   tlist.PrintStatistics();
-
   
   // do off-data if input file was specified
@@ -196,5 +196,4 @@
 
   tlist.PrintStatistics();
-
 }
 //-----------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4093)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/srcpos.datacard	(revision 4094)
@@ -1,7 +1,7 @@
 
 // Maximun number of on and off events to be processed)
-NEVENTS 20000
+NEVENTS 9999999
 
-// Input file name pattern
+// Input file name pattern (wildcards allowed)
 INPUTFILES /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OnNoCalB.root
 
