Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8718)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8719)
@@ -18,8 +18,93 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2007/08/28 Thomas Bretz
+
+   * mbase/MEnv.[h,cc]:
+     - added handling an Include-resource. Note, that there is no
+       check for recursions, they can crash your program.
+
+   * sponde.cc:
+     - check for batch mode and no output file
+     - changed title
+     - moved HasWritePermission to MJSpectrum.cc
+
+   * mdata/MDataPhrase.cc:
+     - fixed a bug which caused a variable (eg. [0]) at the beginning
+       of a line not be detected correctly
+
+   * mhbase/MHn.cc:
+     - added some comments
+
+   * mhflux/MHDisp.[h,cc]:
+     - changed axis titles from x/y to dx/dy
+     - changed cutting out a part of the cake into stamping a hole
+       at the source position (currently with a fix PSF!)
+     - for the moment display everything in Wobble-mode (to be fixed!)
+
+   * mhflux/MMcSpectrumWeight.cc:
+     - some cosmetics to output
+
+   * mjobs/MJCut.cc:
+     - check if output file is writeable (necessary in on/off mode
+       to detect that incident before filling the source plot)
+
+   * mjobs/MJob.cc:
+     - added a comment
+     - fixed a bug in HasWritePermission (it must be fOverwrite not
+       !fOverwrite)
+
+   * mjobs/MJSpectrum.cc:
+     - replaced #cdot by a dot (it seems it is not supported anymore??)
+     - set a proper display name
+     - print an error message if writing the result failed
+
+   * mjtrain/MJTrainDisp.[h,cc]:
+     - a further small step to unify all MJOptim classes
+     - let the user change the theta-cut for the displayed efficiency
+
+   * macros/train/traindisp.C:
+     - added comment about new SetThetaCut
+
+   * mjtrain/MJTrainEnergy.[h,cc]
+     - a further small step to unify all MJOptim classes
+     - removed obsolete columns for Impact and TelescopeTheta
+       (MHEnergyEst doesn't read from the matrix here)
+     - set palette
+
+   * mpointing/MSrcPosCalc.[h,cc]:
+     - replaced CalcXYinCamera by MAstro::GetDistOnPlain. It has the
+       same accuracy and is not remarkably slower
+
+   * mpointing/MSrcPosCorrect.[h,cc]:
+     - changed comments
+     - made sure that any possible anti-source position in the camera
+       is handled correctly (maybe we should move it before
+       MSrcPosCalc and skip the anti-source here???)
+
+
+
+
  2007/08/27 Markus Meyer
 
    * mmuon/MHMuonPar.cc:
      - Reference lines changed
+
+
+
+ 2007/08/27 Thomas Bretz
+
+   * resources/starguider00000001.txt, resources/starguider0085240.txt,
+     resources/starguider00089180.txt:
+     - added more starguider calibration files
+
+   * resources/starguider.txt:
+     - removed obsolete old one
+
+
+
+ 2007/08/26 Thomas Bretz
+
+   * mranforest/MRFEnergyEst.[h,cc]:
+     - removed obsolete files
 
 
Index: trunk/MagicSoft/Mars/mdata/MDataPhrase.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataPhrase.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mdata/MDataPhrase.cc	(revision 8719)
@@ -321,5 +321,74 @@
         idx++;
     }
-
+    /*
+
+    // * HOW DO WE PROCESS THE FILTERS?
+    // * DO WE NEED THIS FOR MData derived classes? Is there any need for it?
+    // * MAYBE FIRST FILTERS (MF?) MUST REPLACE {name[class]} BEFORE
+    //   THE DATA PHRASSE IS CREATED?
+    // --> MFDataPhrase must have a list of MFilter. In Process first
+    //     all self created MFilter are processed (see MF). Then
+    //     they are evaluated and the result is given to the MDataPhrase.
+    //     Can this be done using MDataMember? We replace {Name[class]}
+    //     by Name.IsExpressionTrue and we need a way that MDataPhrase
+    //     gets the coresponding pointer.
+    // --> Alternatively we can create a MDataPhrase which allows
+    //     Pre/Processing
+    //
+    // We convert {Name[Class]} to Name.IsExpressionTrue. To process these
+    // data/filters we need a request from MFDataPhrase (new virtual
+    // memeber function?)
+    //
+    // {} Is alreaqdy used in ReadEnv.
+    //
+    // Enhance ReadEnv to allow Cut1.5 to be just a class.
+    //
+    // The difference between MFDataPhrase is
+    //   MFDataPhrase only knows MDataPhrase, while
+    //   MF also knows a filter-class.
+    //
+
+    p = 0;
+
+    // And now we check for other phrases or filters
+    // They are defined by a [, a pribtable character and
+    // any numer of word characters (a-zA-Z0-9_) and a closing ]
+    reg = TPRegexp("{[A-Za-z}\\w+(\\[[A-Za-z]\\w+\\])?}");
+    while (1)
+    {
+        // If some indices are already existing
+        // initialize them by a MDataValue
+        idx = CheckForVariable(phrase, idx);
+
+        // Check whether expression is found
+        if (reg.Match(phrase, mods, p, 130, &pos)==0)
+            break;
+
+        // Get expression from phrase
+        TString expr = phrase(pos[0], pos[1]-pos[0]);
+
+        // Zerlegen: {Name[Class]}
+
+        // Create a new MData object of kind
+        MData *dat = (MData*)GetNewObject(cls, MData::Class());
+        if (!dat)
+            return "";
+        dat->SetName(name);
+
+        // Add a corresponding MDataMember to our list
+        fMembers.AddLast(dat);
+
+        // Make the expression "Regular expression proofed"
+        expr.ReplaceAll("[", "\\[");
+        expr.ReplaceAll("]", "\\]");
+
+        // Find other occurances of arg by this regexp
+        // and start next search behind first match
+        p = pos[0] + Substitute(phrase, expr, idx);
+
+        // Step forward to the next argument
+        idx++;
+    }
+ */
     // Now we have to check if there are additional indices [idx]
     // This is mainly important if the rule has indices only!
Index: trunk/MagicSoft/Mars/mhbase/MHn.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8719)
@@ -317,4 +317,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Set additional scale factors for the current histogram
+//
 void MHn::SetScale(Double_t x, Double_t y, Double_t z) const
 {
@@ -323,4 +327,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Enable or disable displaying log-scale for the current histogram.
+// Normally it is retrieved from the corresponding MBinning
+//
 void MHn::SetLog(Bool_t x, Bool_t y, Bool_t z) const
 {
@@ -328,4 +337,12 @@
         fHist[fNum-1]->SetLog(x, y, z);
 }
+
+// --------------------------------------------------------------------------
+//
+// Set the axis range in Finalize automatically to the histogram region
+// containing contents. This is the default for the x-axis.
+// This function can be used to enable this behaviour also for the other
+// axis, or disable it for the x-axis of the current histogram.
+//
 void MHn::SetAutoRange(Bool_t x, Bool_t y, Bool_t z) const
 {
@@ -334,4 +351,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Call Sumw2 for trhe current histogram, enabling errors.
+//
 void MHn::Sumw2() const
 {
@@ -340,4 +361,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Force the given binning(s) for the current histogram. The binnings
+// do not get owned. The user is responsible for deleting them.
+//
 void MHn::SetBinnings(MBinning *x, MBinning *y, MBinning *z) const
 {
Index: trunk/MagicSoft/Mars/mhflux/MHDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHDisp.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mhflux/MHDisp.cc	(revision 8719)
@@ -70,5 +70,5 @@
 //
 MHDisp::MHDisp(const char *name, const char *title)
-    : fDisp(0), fDeviation(0), fSmearing(-1), fWobble(kFALSE),
+    : fDisp(0), fDeviation(0), fSrcAnti(0), fSmearing(-1), fWobble(kFALSE),
     fScaleMin(0.325), fScaleMax(0.475)
 {
@@ -81,6 +81,6 @@
     fHist.SetName("Alpha");
     fHist.SetTitle("3D-plot of ThetaSq vs x, y");
-    fHist.SetXTitle("x [\\circ]");
-    fHist.SetYTitle("y [\\circ]");
+    fHist.SetXTitle("dx [\\circ]");
+    fHist.SetYTitle("dy [\\circ]");
     fHist.SetZTitle("Eq.cts");
 
@@ -112,4 +112,16 @@
     }
 
+    if (fWobble)
+    {
+        fSrcAnti = (MSrcPosCam*)plist->FindObject("MSrcPosAnti", "MSrcPosCam");
+        if (!fSrcAnti)
+        {
+            *fLog << err << "MSrcPosAnti [MSrcPosCam] not found... abort." << endl;
+            return kFALSE;
+        }
+
+        *fLog << inf << "Wobble mode initialized. " << endl;
+    }
+
     fDeviation = (MPointingDev*)plist->FindObject("MPointingDev");
     if (!fDeviation)
@@ -132,14 +144,4 @@
 // --------------------------------------------------------------------------
 //
-// Calculate the delta angle between fSrcPos->GetXY() and v.
-// Return result in deg.
-//
-Double_t MHDisp::DeltaPhiSrc(const TVector2 &v) const
-{
-    return TMath::Abs(fSrcPos->GetXY().DeltaPhi(v))*TMath::RadToDeg();
-}
-
-// --------------------------------------------------------------------------
-//
 // Fill the histogram. For details see the code or the class description
 // 
@@ -162,8 +164,10 @@
     TVector2 pos1 = hil->GetMean()*fMm2Deg + hil->GetNormAxis()*fDisp->GetVal();
 
+    const TVector2 src = fSrcPos->GetXY()*fMm2Deg;
+
     Double_t w0 = 1;
     if (fWobble)
     {
-        const Double_t delta = DeltaPhiSrc(pos1);
+        const TVector2 anti = fSrcAnti->GetXY()*fMm2Deg;
 
         // Skip off-data not in the same half than the source (here: anti-source)
@@ -171,5 +175,10 @@
         if (!fHistOff)
         {
-            if (delta>180-25)
+            Double_t r = anti.Mod()>0.2*1.7 ? 0.2*1.7 : anti.Mod();
+
+            // In wobble mode processing the off-data, the anti-source
+            // position is our source position. Check if this is a possible
+            // gamma. If it is, do not fill it into our off-data histogram
+            if ((pos1-anti).Mod()<r)
                 return kTRUE;
 
@@ -181,11 +190,16 @@
             // increased uncertainty
             // FIXME: The delta stuff could be replaced by a 2*antitheta cut...
-            w0 = delta>25 ? 1 : 2;
-        }
+            //w0 = delta>25 ? 1 : 2;
+
+            w0 = (pos1+anti).Mod()<r ? 2 : 1;
+        }
+
+        // When processing off-data the anti-source is the real source
+        const TVector2 srcpos = fHistOff ? src : anti;
 
         // Define by the source position which histogram to fill
-        if (DeltaPhiSrc(fFormerSrc)>90)
+        if (TMath::Abs(srcpos.DeltaPhi(fFormerSrc))*TMath::RadToDeg()>90)
             fHalf = !fHalf;
-        fFormerSrc = fSrcPos->GetXY();
+        fFormerSrc = srcpos;
     }
 
@@ -202,5 +216,5 @@
         {
             // m: Position of the camera center in the FS plot
-            m = fSrcPos->GetXY().Rotate(-rho)*fMm2Deg;
+            m = src.Rotate(-rho);
             pos1 -= m;
         }
@@ -410,5 +424,5 @@
     const TAxis &axey = *h2.GetYaxis();
 
-    const Double_t rmax = (fWobble ? axex.GetXmax()-0.4 : axex.GetXmax()) - axex.GetBinWidth(1);
+    const Double_t rmax = (fWobble ? axex.GetXmax()/*-0.7*/ : axex.GetXmax()) - axex.GetBinWidth(1);
 
     for (int x=1; x<=axex.GetNbins(); x++)
Index: trunk/MagicSoft/Mars/mhflux/MHDisp.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHDisp.h	(revision 8718)
+++ trunk/MagicSoft/Mars/mhflux/MHDisp.h	(revision 8719)
@@ -25,4 +25,6 @@
     MPointingDev *fDeviation; //!
     //MSrcPosCam   *fAxis;      //!
+    MSrcPosCam   *fSrcAnti; //!
+
 
     TH2D         fHistBg;
@@ -41,5 +43,4 @@
     // MHDisp
     Double_t GetOffSignal(TH1 &h) const;
-    Double_t DeltaPhiSrc(const TVector2 &v) const;
 
     void Update();
Index: trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc	(revision 8719)
@@ -493,5 +493,5 @@
     if (hasold)
     {
-        *fLog << " Old Spectrum:  " << GetFormulaSpecOldX();
+        *fLog << " Old Spectrum:             " << GetFormulaSpecOldX();
         if (fEnergyMin>=0 && fEnergyMax>0)
             *fLog << "   (I=" << GetSpecOldIntegral() << ")";
@@ -500,5 +500,5 @@
     if (hasnew)
     {
-        *fLog << " New Spectrum:  " << GetFormulaSpecNewX();
+        *fLog << " New Spectrum:             " << GetFormulaSpecNewX();
         if (fEnergyMin>=0 && fEnergyMax>0)
             *fLog << "   (I=" << GetSpecNewIntegral() << ")";
@@ -506,5 +506,5 @@
     }
     if (fFunc)
-        *fLog << " Weight func:  " << fFunc->GetTitle()   << endl;
+        *fLog << " Weight func:              " << fFunc->GetTitle()   << endl;
 }
 
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8719)
@@ -550,4 +550,7 @@
         return kFALSE;
     }
+
+    if (!HasWritePermission(GetOutputFile(set.GetNumAnalysis())))
+        return kFALSE;
 
     CheckEnv();
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8719)
@@ -1009,5 +1009,5 @@
     spectrum.SetMarkerStyle(kFullDotMedium);
     spectrum.SetTitle("Differential flux times E^{2}");
-    spectrum.SetYTitle("E^{2}#cdot dN/dE [N#cdot TeV/sm^{2}]");
+    spectrum.SetYTitle("E^{2}·dN/dE [N·TeV/sm^{2}]");
     spectrum.SetDirectory(0);
     spectrum.DrawCopy();
@@ -1316,4 +1316,7 @@
     }
 
+    if (!HasWritePermission(GetPathOut()))
+        return kFALSE;
+
     CheckEnv();
 
@@ -1324,4 +1327,7 @@
     *fLog << "Compile Monte Carlo Sample (data set " << set.GetName() << ")" << endl;
     *fLog << endl;
+
+    if (fDisplay)
+        fDisplay->SetWindowName(fName);
 
     // Setup everything which is read from the ganymed file
@@ -1616,5 +1622,5 @@
     tlist2.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
 
-    MEvtLoop loop2("FillMonteCarlo"); // ***** fName *****
+    MEvtLoop loop2(fName); // ***** fName *****
     loop2.SetParList(&plist);
     loop2.SetDisplay(fDisplay);
@@ -1685,4 +1691,13 @@
         cont.Add(fDisplay);
 
-    return WriteContainer(cont, "", "RECREATE");
-}
+    if (!WriteContainer(cont, "", "RECREATE"))
+    {
+        *fLog << err << GetDescriptor() << ": Writing result failed." << endl;
+        return kFALSE;
+    }
+
+    *fLog << all << GetDescriptor() << ": Done." << endl;
+    *fLog << endl << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mjobs/MJob.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 8719)
@@ -329,5 +329,5 @@
 //
 // Checks whether write permissions to fname exists including
-// the fOverwrite data amember.
+// the fOverwrite data member. Empty file names return kTRUE
 //
 Bool_t MJob::HasWritePermission(TString fname) const
@@ -346,5 +346,5 @@
     }
 
-    if (!fOverwrite)
+    if (fOverwrite)
         return kTRUE;
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc	(revision 8719)
@@ -43,4 +43,9 @@
 //    opt.Train("rf-disp.root", set, 30000); // Number of train events
 //
+//    // Two of the displayed histograms show the cut efficiency for
+//    // a given Theta-Cut. The default is 0.215. It can be overwritten
+//    // by
+//    opt.SetThetaCut(0.165);
+//
 //
 // Random Numbers:
@@ -227,5 +232,5 @@
 Bool_t MJTrainDisp::Train(const char *out, const MDataSet &set, Int_t num)
 {
-    SetTitle(Form("TrainDisp: %s", out));
+    SetTitle(Form("Train%s: %s", fNameOutput.Data(), out));
 
     if (fDisplay)
@@ -282,5 +287,5 @@
 
     // ------------------------ Train RF --------------------------
-    MRanForestCalc rf("TrainDisp", fTitle);
+    MRanForestCalc rf("Train", fTitle);
     rf.SetNumTrees(fNumTrees);
     rf.SetNdSize(fNdSize);
@@ -292,5 +297,6 @@
     rf.SetFileName(out);
     rf.SetDebug(fDebug>1);
-    rf.SetNameOutput("Disp");
+    rf.SetNameOutput(fNameOutput);
+    rf.SetFunction(fResultFunction);
 
     /*
@@ -319,5 +325,5 @@
 
     MParameterD par("ThetaSquaredCut");
-    par.SetVal(0.215*0.215);
+    par.SetVal(fThetaCut*fThetaCut);
     plist.AddToList(&par);
 
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 8718)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h	(revision 8719)
@@ -17,4 +17,10 @@
 
     TString fTrainParameter;
+    TString fResultFunction;
+
+    Float_t fThetaCut;
+
+    // To be moved to a base class
+    TString fNameOutput;
 
     void DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const;
@@ -22,7 +28,9 @@
 
 public:
-    MJTrainDisp() : fTrainParameter(fgTrainParameter) { }
+    MJTrainDisp() : fTrainParameter(fgTrainParameter), fResultFunction("x"), fThetaCut(0.215), fNameOutput("Disp") { }
 
     void SetTrainParameter(const char *txt) { fTrainParameter=txt; }
+
+    void SetThetaCut(Float_t cut=0.215) { fThetaCut=cut; }
 
     Bool_t Train(const char *out, const MDataSet &set, Int_t num);
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc	(revision 8719)
@@ -89,5 +89,5 @@
 Bool_t MJTrainEnergy::Train(const char *out, const MDataSet &set, Int_t num)
 {
-    SetTitle(Form("TrainEnergy: %s", out));
+    SetTitle(Form("Train%s: %s", fNameOutput.Data(), out));
 
     if (fDisplay)
@@ -128,8 +128,5 @@
     if (fEnableWeights)
         train.AddColumn("MWeight.fVal");
-    train.AddColumn("MMcEvt.fImpact/100");
-    train.AddColumn("MMcEvt.fTelescopeTheta*TMath::RadToDeg()");
     train.AddColumn(fTrainParameter);
-
 
     // ----------------------- Fill Matrix RF ----------------------
@@ -147,9 +144,9 @@
 
     // ------------------------ Train RF --------------------------
-    MRanForestCalc rf("TrainEnergy", fTitle);
+    MRanForestCalc rf("Train", fTitle);
     rf.SetNumTrees(fNumTrees);
     rf.SetNdSize(fNdSize);
     rf.SetNumTry(fNumTry);
-    rf.SetNumObsoleteVariables(3);
+    rf.SetNumObsoleteVariables(1);
     rf.SetLastDataColumnHasWeights(fEnableWeights);
     rf.SetDisplay(fDisplay);
@@ -157,5 +154,5 @@
     rf.SetFileName(out);
     rf.SetDebug(fDebug>1);
-    rf.SetNameOutput("MEnergyEst");
+    rf.SetNameOutput(fNameOutput);
     rf.SetFunction(fResultFunction);
 
@@ -175,4 +172,6 @@
 
     gLog.Separator("Test");
+
+    MH::SetPalette("pretty");
 
     MParList  plist;
Index: trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 8718)
+++ trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.h	(revision 8719)
@@ -14,6 +14,9 @@
     TString fResultFunction;
 
+    // To be moved to a base class
+    TString fNameOutput;
+
 public:
-    MJTrainEnergy() { SetTrainLin(); }
+    MJTrainEnergy() : fNameOutput("MEnergyEst") { SetTrainLin(); }
 
     void SetTrainLog() { SetTrainFunc("log10(MMcEvt.fEnergy)", "pow(10, x)"); }
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 8719)
@@ -178,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;
@@ -331,47 +331,4 @@
 
     return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Loc0LocToCam
-//
-// Input :   (theta0, phi0)   direction for the position (0,0) in the camera  
-//           ( theta,  phi)   some other direction
-// 
-// Output :  (X, Y)      position in the camera corresponding to (theta, phi)
-//
-TVector2 MSrcPosCalc::CalcXYinCamera(const MVector3 &pos0, const MVector3 &pos) const
-{
-    const Double_t theta0 = pos0.Theta();
-    const Double_t phi0   = pos0.Phi();
-
-    const Double_t theta  = pos.Theta();
-    const Double_t phi    = pos.Phi();
-
-    //--------------------------------------------
-
-    /* --- OLD ---
-     const Double_t YC0 = TMath::Cos(theta0)*TMath::Tan(theta)*TMath::Cos(phi-phi0) - TMath::Sin(theta0);
-     const Double_t YC1 = TMath::Cos(theta0) + TMath::Sin(theta0)*TMath::Tan(theta);
-     const Double_t YC  = YC0 / YC1;
-
-     const Double_t XC0 =  TMath::Cos(theta0) - YC*TMath::Sin(theta0);
-     const Double_t XC  = -TMath::Sin(phi-phi0) * TMath::Tan(theta) * XC0;
-     */
-
-    /* --- NEW ---  Same as MSrcPosCorrect::CalcXYinCamera */
-    const Double_t XC0 = TMath::Sin(theta)*TMath::Sin(phi-phi0);
-    const Double_t XC1 = TMath::Cos(theta0)*TMath::Cos(theta);
-    const Double_t XC2 = TMath::Sin(theta0)*TMath::Sin(theta)*TMath::Cos(phi-phi0);
-
-    const Double_t YC0 = TMath::Sin(theta0)*TMath::Cos(theta);
-    const Double_t YC1 = TMath::Cos(theta0)*TMath::Sin(theta)*TMath::Cos(phi-phi0);
-
-    const Double_t XC  =  - XC0     / (XC1 + XC2);
-    const Double_t YC  = (-YC0+YC1) / (XC1 + XC2);
-
-    //--------------------------------------------
-    return TVector2(XC, YC);
 }
 
@@ -428,5 +385,5 @@
 
     // Calculate source position in camera, and convert to mm:
-    TVector2 v = CalcXYinCamera(pos0, pos)*fGeom->GetCameraDist()*1000;
+    TVector2 v = MAstro::GetDistOnPlain(pos0, pos, -fGeom->GetCameraDist()*1000);
 
     if (fDeviation)
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 8718)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 8719)
@@ -53,5 +53,4 @@
     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;
     Bool_t   GetCoordinate(TString str, Double_t &ret) const;
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.cc	(revision 8719)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz 6/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2005
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -27,93 +27,10 @@
 // MSrcPosCorrect
 //
-// For more details see Process()
-//
-//////////////////////////////////////////////////////////////////////////////
-#include "MSrcPosCorrect.h"
-
-#include <TVector2.h>
-
-#include "MParList.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MGeomCam.h"
-#include "MSrcPosCam.h"
-#include "MRawRunHeader.h"
-#include "MReportStarguider.h"
-
-ClassImp(MSrcPosCorrect);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-MSrcPosCorrect::MSrcPosCorrect(const char *name, const char *title)
-    : fSrcPosCam(NULL), fSrcPosAnti(NULL), fAxis(NULL), fGeom(NULL)
-     , fDx(-14.24) , fDy(-9.495)
-
-{
-    fName  = name  ? name  : "MSrcPosCorrect";
-    fTitle = title ? title : "Calculates the source position in the camera";
-}
-
-// --------------------------------------------------------------------------
-//
-// Search and if necessary create MSrcPosCam in the parameter list. Search
-// MSourcePos. If not found, do nothing else, and skip the task. If MSrcPosCam
-// did not exist before and has been created here, it will contain as source
-// position the camera center (0,0).
-// In the case that MSourcePos is found, go ahead in searching the rest of
-// necessary containers. The source position will be calculated for each
-// event in Process.
-//
-Int_t MSrcPosCorrect::PreProcess(MParList *pList)
-{
-    fSrcPosCam = (MSrcPosCam*)pList->FindObject("MSrcPosCam");
-    if (!fSrcPosCam)
-    {
-        *fLog << err << "MSrcPosCam not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fSrcPosAnti = (MSrcPosCam*)pList->FindObject("MSrcPosAnti", "MSrcPosCam");
-
-    fAxis = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", "OpticalAxis");
-    if (!fAxis)
-        return kFALSE;
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Checking for file type. If the file type is Monte Carlo the
-// source position is arbitrarily determined from the MC headers.
-//
-Bool_t MSrcPosCorrect::ReInit(MParList *plist)
-{
-    MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
-    if (!run)
-    {
-        *fLog << err << "MRawRunHeader not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRunType   = run->GetRunType();
-    fRunNumber = run->GetRunNumber();
-
-    if (fRunNumber<56161 && fRunNumber>53832)
-    {
-        *fLog << inf << "Run Number " << fRunNumber << " between 53832 and 56161." << endl;
-        *fLog << "A misfocussing correction (" << fDx << "mm/" << fDy << "mm) will be applied." << endl;
-    }
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Performs source position correction in the camera.
+// Performs a misfocussing correction for source and anti-source position
+// in the camera, i.e. it is assumed that the telscope is pointing well
+// (all starguider and other corrections are already applied to the
+// source positon) but the mirror is not focussing to the center of
+// the camera.
+//
 // Due to missfocussing a shift of
 //    dx=0.048deg and dy=0.034deg
@@ -121,4 +38,5 @@
 //    dx=14.24mm and dy=9.495mm
 // is added between run 53832 (excl) and 56161 (excl)
+//
 //
 // See also: Runbook
@@ -153,4 +71,108 @@
 //   W-Comae
 //
+//
+// For more details see Process()
+//
+// Input:
+//   MSrcPosCam
+//   MSrcPosAnti [MSrcPosCam]
+//
+// Output:
+//   OpticalAxis [MSrcPosCam]
+//   MSrcPosCam
+//   MSrcPosAnti [MSrcPosCam]
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MSrcPosCorrect.h"
+
+#include <TVector2.h>
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MSrcPosCam.h"
+#include "MRawRunHeader.h"
+#include "MReportStarguider.h"
+
+ClassImp(MSrcPosCorrect);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+MSrcPosCorrect::MSrcPosCorrect(const char *name, const char *title)
+    : fSrcPosCam(NULL), fSrcPosAnti(NULL), fAxis(NULL), fGeom(NULL)
+     , fDx(-14.24) , fDy(-9.495)
+
+{
+    fName  = name  ? name  : "MSrcPosCorrect";
+    fTitle = title ? title : "Calculates the source position in the camera";
+}
+
+// --------------------------------------------------------------------------
+//
+// Search and if necessary create MSrcPosCam in the parameter list. Search
+// MSourcePos. If not found, do nothing else, and skip the task. If MSrcPosCam
+// did not exist before and has been created here, it will contain as source
+// position the camera center (0,0).
+// In the case that MSourcePos is found, go ahead in searching the rest of
+// necessary containers. The source position will be calculated for each
+// event in Process.
+//
+Int_t MSrcPosCorrect::PreProcess(MParList *pList)
+{
+    fSrcPosCam = (MSrcPosCam*)pList->FindObject("MSrcPosCam");
+    if (!fSrcPosCam)
+    {
+        *fLog << err << "MSrcPosCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fSrcPosAnti = (MSrcPosCam*)pList->FindObject("MSrcPosAnti", "MSrcPosCam");
+
+    fAxis = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", "OpticalAxis");
+    if (!fAxis)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checking for file type. If the file type is Monte Carlo the
+// source position is arbitrarily determined from the MC headers.
+//
+Bool_t MSrcPosCorrect::ReInit(MParList *plist)
+{
+    MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
+    if (!run)
+    {
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRunType   = run->GetRunType();
+    fRunNumber = run->GetRunNumber();
+
+    if (fRunNumber<56161 && fRunNumber>53832)
+    {
+        *fLog << inf << "Run Number " << fRunNumber << " between 53832 and 56161." << endl;
+        *fLog << "A misfocussing correction (" << fDx << "mm/" << fDy << "mm) will be applied." << endl;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// The offset fDx/fDy is subtracted from the source position. The anti-
+// source position is shifted away from the camera-center and rotated
+// around the camera center according to this correction, because it
+// should always be symmetric w.r.t. the camera-center, but it is not
+// necessary on the other side of the camera (e.g. three off-regions).
+//
 Int_t MSrcPosCorrect::Process()
 {
@@ -158,24 +180,33 @@
         return kTRUE;
 
-    TVector2 d;
-    if (fRunNumber<56161 && fRunNumber>53832)
-    {
-        // dx=-0.048deg, dy=0.034deg, d=0.059deg
-        static const TVector2 dxy(fDx, fDy);
-
-        d -= dxy;
-    }
-
-    fAxis->SetXY(d);
-    fSrcPosCam->Add(d);
-    if (fSrcPosAnti)
-    {
-        d *= -1; // Anti-Source position should always be symetric
-        fSrcPosAnti->Add(d);
-    }
+    if (fRunNumber<=53832 || fRunNumber>=56161)
+        return kTRUE;
+
+    // dx=-0.048deg, dy=0.034deg, d=0.059deg
+    const TVector2 dxy(-fDx, -fDy);
+
+    const TVector2 s1(fSrcPosCam->GetXY());
+    const TVector2 a1(fSrcPosAnti->GetXY());
+    const TVector2 s2 = s1 + dxy;
+
+
+    // Anti-Source position should always be symetric w.r.t. camera center
+    TVector2 a2;
+    a2.SetMagPhi(a1.Mod()+s2.Mod()-s1.Mod(), a1.Phi()+s2.DeltaPhi(s1));
+
+    fAxis->SetXY(dxy);
+    fSrcPosCam->SetXY(s2);
+    fSrcPosAnti->SetXY(s2);
 
     return kTRUE;
 }
 
+// --------------------------------------------------------------------------
+//
+// MSrcPosCorrect.Dx: -14.24
+// MSrcPosCorrect.Dy: -9.495
+//
+// For a detailed description see the class reference.
+//
 Int_t MSrcPosCorrect::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
 {
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.h	(revision 8718)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCorrect.h	(revision 8719)
@@ -14,15 +14,15 @@
 {
 private:
-    MSrcPosCam *fSrcPosCam;   //!
-    MSrcPosCam *fSrcPosAnti;  //!
-    MSrcPosCam *fAxis;        //!
+    MSrcPosCam *fSrcPosCam;   //! Source position
+    MSrcPosCam *fSrcPosAnti;  //! Anti source position
+    MSrcPosCam *fAxis;        //! New "center of camera"
 
-    MGeomCam   *fGeom;        //!
+    MGeomCam   *fGeom;        //! Camera geometry
 
     UShort_t fRunType;        //! Run Type to decide where to get pointing position from
-    UInt_t   fRunNumber;
+    UInt_t   fRunNumber;      //! Current run number
 
-    Float_t fDx;
-    Float_t fDy;
+    Float_t fDx;              // [mm] Correction in x
+    Float_t fDy;              // [mm] Correction in y
 
     // MTask
@@ -36,5 +36,5 @@
     MSrcPosCorrect(const char *name=NULL, const char *title=NULL);
 
-    ClassDef(MSrcPosCorrect, 0) // Corrects MSrcPOsCam for missfocussing
+    ClassDef(MSrcPosCorrect, 0) // Corrects MSrcPosCam for missfocussing
 };
 
Index: trunk/MagicSoft/Mars/sponde.cc
===================================================================
--- trunk/MagicSoft/Mars/sponde.cc	(revision 8718)
+++ trunk/MagicSoft/Mars/sponde.cc	(revision 8719)
@@ -144,4 +144,10 @@
     const TString kOutfile = arg.GetArgumentStr(2);
 
+    if (kOutfile.IsNull() && kBatch)
+    {
+        gLog << err << "Writing no outputfile but running in batch mode is nonsense." << endl;
+        return 2;
+    }
+
     if (gSystem->AccessPathName(kInfile, kFileExists))
     {
@@ -211,5 +217,5 @@
     }
 
-    MJSpectrum job(Form("MJSpectrum #%d", seq.GetNumAnalysis()));
+    MJSpectrum job(Form("Spectrum - %s", seq.GetName()));
     job.SetEnv(&env);
     job.SetEnvDebug(kDebugEnv);
@@ -221,7 +227,4 @@
     job.ForceTheta(kForceTheta);
 
-    if (!job.HasWritePermission(kOutfile))
-        return 2;
-
     if (!job.Process(seq))
     {
