Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8635)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8636)
@@ -18,4 +18,39 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2007/07/15 Thomas Bretz
+
+   * mdata/MDataPhrase.[h,cc]:
+     - fixed a problem with predefined variables (such as used for
+       disp optimization [0])
+     - added a debug member function GetRuleRaw()
+
+   * mhflux/MHAlpha.[h,cc]:
+     - allow to set the watermark from the DrawNice menu entry
+
+   * mjobs/MDataSet.cc:
+     - allow to set the default sequence- and data-path from
+       the dataset file
+
+   * mjobs/MJCut.cc:
+     - set the number of random off-source position for the on-data
+     - fixed a "&", should have been a logical And
+     - make sure that even for MCs the source position is always
+       calculated (this is necessary for more than one wobble position)
+
+   * mjoptim/MJOptimizeDisp.cc:
+     - fixed a typo which made the optimtrain.C fail (kDegToRad does
+       not exist)
+
+   * mjtrain/MJTrainEnergy.cc:
+     - some cosmetics: changed kRad2Deg to TMath::RadToDeg()
+
+   * mpointing/MSrcPosCalc.[h,cc]:
+     - added a random off-source position calculation to make the
+       more-than-one-off-source-position analysis symmetric in case of
+       on-source 
+     - added lots of comments
+
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 8635)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 8636)
@@ -11,4 +11,13 @@
      resource file (to check it open it in the TBrowser and choose Print()
      from the context menu)
+
+   - general: Dataset files now allow to overwrite the default path
+     to search for sequence and data files. Note, that the program
+     option and individual resources will overwrite it. For example:
+        SequencePath: /magic/montecarlo/sequences
+        DataPath:     /magic/montecarlo/star
+
+   - general: Fixed a problem with variables in MDataPhrase. It seems
+     that only optimdisp (didn't work) was effected.
 
    - merpp: Merpp can read file format version 9 now. Please realize
@@ -113,4 +122,13 @@
      is not properly set.
      (Rem: ThetaSqN is no longer needed)
+
+   - ganymed: is now storing the events of all source (on- and off-
+     source positions) even in the case of more than one off-source
+     position. This should allow sponde to work properly and the
+     energy estimation is done correctly in all cases (without any
+     "nearest position" trick)
+
+   - ganymed: From XXXX on a real starguider calibration with a real
+     pointing model for the starguider is done.
 
    - ganymed: From 85340 (19.3.2006) on a real starguider calibration
Index: /trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8636)
@@ -885,5 +885,5 @@
 }
 
-void MHAlpha::DrawNicePlot(Bool_t newc, const char *title)
+void MHAlpha::DrawNicePlot(Bool_t newc, const char *title, const char *watermark)
 {
     if (!newc && !fDisplay)
@@ -972,5 +972,6 @@
     text.SetTextSize(0.07);
     text.SetTextAngle(2.5);
-    text.DrawLatex(0.45, 0.2, "preliminary");
+    if (watermark)
+        text.DrawLatex(0.45, 0.2, watermark);
     //enum { kTextNDC = BIT(14) };
 
Index: /trunk/MagicSoft/Mars/mhflux/MHAlpha.h
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHAlpha.h	(revision 8635)
+++ /trunk/MagicSoft/Mars/mhflux/MHAlpha.h	(revision 8636)
@@ -132,6 +132,6 @@
     void ForceUsingSize(Bool_t b=kTRUE) { fForceUsingSize=b; }
 
-    void DrawNicePlot(const char *title="MAGIC Telescope observation") { DrawNicePlot(kTRUE, title); } //*MENU*
-    void DrawNicePlot(Bool_t newc, const char *title=0);
+    void DrawNicePlot(const char *title="MAGIC Telescope observation", const char *watermark="preliminary") { DrawNicePlot(kTRUE, title, watermark); } //*MENU*
+    void DrawNicePlot(Bool_t newc, const char *title=0, const char *watermark=0);
     void DrawAll() { DrawAll(kTRUE); } //*MENU*
     void DrawAll(Bool_t newc);
Index: /trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8636)
@@ -38,4 +38,7 @@
 //       SequencesOff: 36817
 //
+//       SequencePath: /magic/sequences
+//       DataPath:     /magic/data/star
+//
 //       Sequence00035222.File: sequences/sequence035222.txt
 //       Sequence00036817.File: sequences/sequence036817.txt
@@ -44,11 +47,28 @@
 //       Sequence00036817.Dir: /data2/wuerzburg/Crab-Analyse/images/036817
 //
-// The analysis number is an artifical number used to name the output
-// files automatically if the names are not overwritten in the corresponding
-// programs.
-//
-// The sequence number are used to concatenate the filenames of the
-// sequences using the file structure used in the datacenter. Each sequence
-// can be added to the on and off data at the same time but only once.
+//       MonteCarlo: No
+//
+// AnalysisNumber: The analysis number is an artifical number used to name
+// the output files automatically if the names are not overwritten in the
+// corresponding programs.
+//
+// SequencePath: In case it is not specified the datacenter default path is
+// used. If it is given it is the place at which the sequence files
+// are searched, if not overwritten by either a program command line
+// option (aka. a argument to the constructor) or a resource for
+// an individual sequence file. Note, that the four digits high-level
+// directories to sort the sequences are added to the given path.
+//
+// DataPath: In case it is not specified the datacenter default path is
+// used. If it is given it is the place at which the data files
+// are searched, if not overwritten by either a program command line
+// option (aka. a argument to the constructor) or a resource for
+// an individual data path.  Note, that the four digits high-level
+// directories to sort the sequences are added to the given path.
+//
+// SequencesOn/Off: The sequence number are used to concatenate the filenames
+// of the sequences using the file structure used in the datacenter. Each
+// sequence can be added to the on and off data at the same time but only
+// once.
 //
 // If you have different file names you can overwrite the default file names
@@ -59,4 +79,6 @@
 // overwrite the directories in which the sequence-files (eg I-files) are
 // stored using Sequence%08d.Dir (make sure you have 8 digits!)
+//
+//
 //
 // Resource file entries are case sensitive!
@@ -226,6 +248,9 @@
     fComment      = env.GetValue("Comment",    "");
 
-    SetupDefaultPath(sequences, GetDefPathSequences());
-    SetupDefaultPath(data,      GetDefPathDataFiles());
+    const TString defpathseq  = env.GetValue("SequencePath", GetDefPathSequences());
+    const TString defpathdata = env.GetValue("DataPath",     GetDefPathDataFile());
+
+    SetupDefaultPath(sequences, defpathseq);
+    SetupDefaultPath(data,      defpathdata);
 
     fPathSequences = sequences;
Index: /trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8636)
@@ -873,4 +873,5 @@
 
     scalc.SetMode(MSrcPosCalc::kDefault);
+    scalc.SetNumRandomOffPositions(fNumOffSourcePos);
 
     MFillH fill1b("MHHillasOnPre  [MHHillas]",      "MHillas",      "FillHillasPre");
@@ -947,5 +948,6 @@
     MFillH fillsrc(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
     fillsrc.SetNameTab("SrcPos");
-    if (set.IsWobbleMode() & !set.IsMonteCarlo())
+
+    if (set.IsWobbleMode() && !set.IsMonteCarlo())
         tlist2.AddToListBefore(&fillsrc, &hcalc);
 
@@ -983,6 +985,8 @@
         if (!set.IsMonteCarlo())
             tlist.AddToList(&fillvs, "EffectiveOnTime");
-        else
-            tlist2.AddToListBefore(&fillvs, &scalc);
+
+        // It is not really necessary to re-calculate the image parameters
+        // for the the on-source for MCs, but it is done for symmetry reasons
+        tlist2.AddToListBefore(&fillvs, &scalc);
     }
 
Index: /trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc	(revision 8636)
@@ -117,4 +117,5 @@
     parlist.AddToList(&fit);
 
+    // To avoid this hard-coded we have to switch to MReadMarsFile
     MGeomCamMagic geom; // For GetConvMm2Deg
     parlist.AddToList(&geom);
@@ -125,5 +126,5 @@
 
     const Int_t num1 = m.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
-    const Int_t num2 = m.AddColumn("MHillasSrc.fAlpha*kDegToRad");
+    const Int_t num2 = m.AddColumn("MHillasSrc.fAlpha*TMath::DegToRad()");
     const Int_t num3 = m.AddColumn("MHillas.fSize");
 
@@ -202,6 +203,7 @@
 
     // Print the result
-    *fLog << inf << "Finished processing of " << fname << endl;
-    *fLog << inf << "With Rule: " << rule << endl;
+    *fLog << inf;
+    *fLog << "Finished processing of " << fname << endl;
+    *fLog << "With Rule: " << rule << endl;
     hist.GetAlphaFitter().Print("result");
 
Index: /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8636)
@@ -112,5 +112,5 @@
         train.AddColumn("MWeight.fVal");
     train.AddColumn("MMcEvt.fImpact/100");
-    train.AddColumn("MMcEvt.fTelescopeTheta*kRad2Deg");
+    train.AddColumn("MMcEvt.fTelescopeTheta*TMath::RadToDeg()");
     train.AddColumn("MMcEvt.fEnergy");
 
Index: /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8635)
+++ /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8636)
@@ -42,5 +42,7 @@
 // is taken from MGeomCam. The time is taken from MTime, and the
 // coordinates of the observatory from MObservatory.
-// 
+//
+// FIXME: Add here some information about the more-cycle calculation
+//
 // Input Container:
 //   MPointingPos
@@ -65,4 +67,5 @@
 #include "MSrcPosCalc.h"
 
+#include <TRandom.h>
 #include <TVector2.h>
 
@@ -96,5 +99,5 @@
     : fObservatory(NULL), fPointPos(NULL), fSourcePos(NULL), fDeviation(NULL),
     fSrcPosCam(NULL), fSrcPosAnti(NULL), fGeom(NULL), fTime(NULL), fCallback(NULL),
-    fMode(kDefault)
+    fMode(kDefault), fNumRandomOffPositions(0)
 {
     fName  = name  ? name  : "MSrcPosCalc";
@@ -157,4 +160,7 @@
 Int_t MSrcPosCalc::PreProcess(MParList *pList)
 {
+    // Reset fixed position
+    fFixedPos = TVector2();
+
     fSrcPosCam = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
     if (!fSrcPosCam)
@@ -172,5 +178,5 @@
             *fLog << inf;
             *fLog << "MSourcePos [MPointPos] not found... The source position" << endl;
-            *fLog << "set in MSrcPosCam will be set to  (0/0)  or in the case" << endl;
+            *fLog << "set in MSrcPosCam will be set to (0/0)  or in the case" << endl;
             *fLog << "of  Monte Carlo set to the appropriate wobble position." << endl;
             return kTRUE;
@@ -199,5 +205,7 @@
     *fLog << "Source Position: " << GetRaDec(*fSourcePos) << endl;
     if (fCallback)
-        *fLog << "Using " << fCallback->GetNumPasses() << " off-regions." << endl;
+        *fLog << "Calculating " << fCallback->GetNumPasses() << " off-regions." << endl;
+    if (fNumRandomOffPositions)
+        *fLog << "Calculating " << fNumRandomOffPositions << " random off-regions." << endl;
 
     // For the case ReInit is never called we try:
@@ -211,4 +219,15 @@
 // --------------------------------------------------------------------------
 //
+// Divide the 360deg into num+1 positions. Rotate the given vector
+// by pass+1 steps and return the result.
+//
+TVector2 MSrcPosCalc::Rotate(TVector2 v, Int_t pass, Int_t num) const
+{
+    const Double_t step = TMath::TwoPi()/(num+1);
+    return v.Rotate(step*(pass+1));
+}
+
+// --------------------------------------------------------------------------
+//
 // If fIsWobbleMode==kFALSE set source position to v and anto-source
 // position to -v, if fIsWobbleMode==kTRUE vice versa.
@@ -218,20 +237,25 @@
     if (fMode==kWobble)
     {
+        // The trick here is that the anti-source position in case
+        // of the off-source regions is always the on-source positon
+        // thus a proper anti-source cut is possible.
         fSrcPosAnti->SetXY(v);
-
         if (fCallback)
-        {
-            const Double_t step = TMath::TwoPi()/(fCallback->GetNumPasses()+1);
-            v = v.Rotate(step*(fCallback->GetNumPass()+1));
-        }
+            v = Rotate(v, fCallback->GetNumPass(), fCallback->GetNumPasses());
         else
             v *= -1;
-
         fSrcPosCam->SetXY(v);
     }
     else
     {
+        // Because we don't process this three times like in the
+        // wobble case we have to find another way to determine which
+        // off-source region is the right anti-source position
+        // We do it randomly.
         fSrcPosCam->SetXY(v);
-        v *= -1;
+        if (fNumRandomOffPositions>1)
+            v = Rotate(v, gRandom->Integer(fNumRandomOffPositions), fNumRandomOffPositions);
+        else
+            v *= -1;
         fSrcPosAnti->SetXY(v);
     }
@@ -247,5 +271,9 @@
     if (fMode==kOffData)
     {
-        SetSrcPos(TVector2());
+        // Set fixed position to camera center
+        fFixedPos = TVector2();
+
+        // It is set here for the cases in which Process is not called at all
+        fSrcPosCam->SetXY(fFixedPos);
         return kTRUE;
     }
@@ -284,4 +312,5 @@
     }
 
+    // Determine Monte Carlo position from Monte Carlo header
     TVector2 v(0, 0);
     if (h->GetWobbleMode()>0.5)
@@ -290,9 +319,14 @@
         v.Set(-120., 0.);
 
-    SetSrcPos(v);
-
+    // Set fixed position
+    fFixedPos = v;
+
+    // It is set here for the cases in which Process is not called at all
+    fSrcPosCam->SetXY(fFixedPos);
+
+    // Informal message output
     *fLog << inf;
-    *fLog << "Source Position set to x=" << fSrcPosCam->GetX() << "mm ";
-    *fLog << "y=" << fSrcPosCam->GetY() << "mm" << endl;
+    *fLog << "Source Position set to x=" << fFixedPos.X() << "mm ";
+    *fLog << "y=" << fFixedPos.Y() << "mm" << endl;
 
     return kTRUE;
@@ -350,10 +384,5 @@
     if (fRunType==MRawRunHeader::kRTMonteCarlo || !fSourcePos || !fTime || !fObservatory || fMode==kOffData)
     {
-        // If this is MC data do not change source position
-        if (fRunType==MRawRunHeader::kRTMonteCarlo)
-            return kTRUE;
-
-        // For real data reset source position to 0/0
-        SetSrcPos();
+        SetSrcPos(fFixedPos);
         return kTRUE;
     }
Index: /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 8635)
+++ /trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 8636)
@@ -23,7 +23,7 @@
 public:
     enum Mode_t {
-        kDefault = 0,
-        kOffData = 1,
-        kWobble  = 2
+        kDefault = 0,   // Set source position to on-position
+        kOffData = 1,   // The source position is fixed to (0/0)
+        kWobble  = 2    // The source position is set to the wobble aka. anti-source position depending on the cycle number
     };
 private:
@@ -32,20 +32,25 @@
     };
 
-    MObservatory *fObservatory;
-    MPointingPos *fPointPos;
-    MPointingPos *fSourcePos;
-    MPointingDev *fDeviation;
-    MSrcPosCam   *fSrcPosCam;
-    MSrcPosCam   *fSrcPosAnti;
-    MGeomCam     *fGeom;
-    MTime        *fTime;
-    MTaskList    *fCallback;
+    MObservatory *fObservatory;   //! Observatory location
+    MPointingPos *fPointPos;      //! Present pointing position of the telescope in Zd/Az
+    MPointingPos *fSourcePos;     //! Source Postion in sky coordinates
+    MPointingDev *fDeviation;     //! Deviation calculated from starguider data
+    MSrcPosCam   *fSrcPosCam;     //! Output: Source position in the camera
+    MSrcPosCam   *fSrcPosAnti;    //! Output: Anti Source position in the camera
+    MGeomCam     *fGeom;          //! Camera geomety
+    MTime        *fTime;          //! Time of the current event
+    MTaskList    *fCallback;      //! Callback function to get the number of the cycle
 
     UShort_t fRunType;            //! Run Type to decide where to get pointing position from
 
-    Int_t fMode;
+    TVector2 fFixedPos;           //! Fixed source position
+
+    Int_t fMode;                  // Mode how the source position is calculated
+
+    Int_t fNumRandomOffPositions; // Number of possible random off-sourcr position
 
     // MSrcPosCalc
     void     SetSrcPos(TVector2 v=TVector2()) const;
+    TVector2 Rotate(TVector2 v, Int_t pass, Int_t num) const;
     TVector2 CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const;
     TString  GetRaDec(const MPointingPos &pos) const;
@@ -71,4 +76,5 @@
     void SetMode(Mode_t m=kDefault) { fMode = m; }
     void SetCallback(MTaskList *list) { fCallback=list; }
+    void SetNumRandomOffPositions(Int_t num=0) { fNumRandomOffPositions=num; }
 
     ClassDef(MSrcPosCalc, 0) // Calculates the source position in the camera
