Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 4816)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 4817)
@@ -19,4 +19,32 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2004/08/31: Thomas Bretz
+
+   * star.cc:
+     - implemented batch- and quit-mode
+
+   * mastro/MAstroCatalog.h:
+     - implemented default argument for magnitude in MVector3
+       setters
+
+   * mbase/MDirIter.cc:
+     - fixed a typo
+
+   * mfileio/MWriteRootFile.cc:
+     - fixed a typo
+
+   * mimage/MHHillasSrc.[h,cc], mimage/MHillasSrc.[h,cc]:
+     - added DCA and DCADelta as discussed with the ETH people
+     - incrementes version number of MHillasSrc
+     - changed return type of MHillasSrc::Calc from Bool_t to Int_t
+
+   * mpointing/MPointingPos.h:
+     - added Getter for ZdA7Az in rad
+
+   * mpointing/MPointingPosCalc.cc:
+     - fixed a bug which converted Ra/Dec wrongly to rad
+
+
+
  2004/08/30: Markus Gaug
 
@@ -32,6 +60,7 @@
      - exchanged all arrays by MArray's
 
+
+
  2004/08/30: Thomas Bretz
-
 
    * showlog.cc, showplot.cc:
Index: /trunk/MagicSoft/Mars/mastro/MAstroCatalog.h
===================================================================
--- /trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 4816)
+++ /trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 4817)
@@ -38,5 +38,5 @@
     Double_t Magnitude() const { return -2.5*TMath::Log10(Mag()); }
 
-    void SetRaDec(Double_t ra, Double_t dec, Double_t mag)
+    void SetRaDec(Double_t ra, Double_t dec, Double_t mag=0)
     {
         fType = kIsRaDec;
@@ -44,10 +44,10 @@
     }
     void SetName(const TString &str) { fName = str.Strip(TString::kBoth); }
-    void SetZdAz(Double_t zd, Double_t az, Double_t mag)
+    void SetZdAz(Double_t zd, Double_t az, Double_t mag=0)
     {
         fType = kIsZdAz;
         SetMagThetaPhi(pow(10, -mag/2.5), zd, az);
     }
-    void SetAltAz(Double_t alt, Double_t az, Double_t mag)
+    void SetAltAz(Double_t alt, Double_t az, Double_t mag=0)
     {
         fType = kIsAltAz;
Index: /trunk/MagicSoft/Mars/mbase/MDirIter.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MDirIter.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/mbase/MDirIter.cc	(revision 4817)
@@ -90,5 +90,5 @@
 Int_t MDirIter::AddDirectory(const char *d, const char *filter, Int_t recursive)
 {
-    TString dir = d;
+    TString dir(d);
 
     // Sanity check
@@ -142,5 +142,5 @@
             continue;
 
-        // If entry is a directory add it with a lowere recursivity
+        // If entry is a directory add it with a lower recursivity
         if (IsDir(c)==0)
             rc += AddDirectory(c, filter, recursive-1);
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 4817)
@@ -417,6 +417,6 @@
             {
                 *fLog << warn << endl;
-                *fLog << "WARNING:   You are updating an existing branch.  For this" << endl;
-                *fLog << "     case file-splitting mode is not allowed... disabled!" << endl;
+                *fLog << "WARNING: You are updating an existing branch. For this case" << endl;
+                *fLog << "         file-splitting mode  is  not  allowed...  disabled!" << endl;
                 *fLog << endl;
                 fSplitRule = "";
Index: /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 4817)
@@ -70,19 +70,27 @@
     // connect all the histogram with the container fHist
     //
-    fAlpha = new TH1F("Alpha", "Alpha of Ellipse",            181, -90,  90);
-    fDist  = new TH1F("Dist",  "Dist of Ellipse",             100,   0, 445);
-    fCosDA = new TH1F("CosDA", "cos(Delta,Alpha) of Ellipse", 101,  -1,   1);
+    fAlpha = new TH1F("Alpha", "Alpha of Ellipse",                181, -90,  90);
+    fDist  = new TH1F("Dist",  "Dist of Ellipse",                 100,   0, 445);
+    fCosDA = new TH1F("CosDA", "cos(Delta,Alpha) of Ellipse",     101,  -1,   1);
+    fDCA   = new TH1F("DCA",   "Distance of closest aproach",     101,  -1,   1);
+    fDCADelta  = new TH1F("DCADelta",  "Angle between shower and x-axis", 101,   0, 360);
 
     fAlpha->SetDirectory(NULL);
     fDist->SetDirectory(NULL);
     fCosDA->SetDirectory(NULL);
+    fDCA->SetDirectory(NULL);
+    fDCADelta->SetDirectory(NULL);
 
     fAlpha->SetXTitle("\\alpha [\\circ]");
     fDist->SetXTitle("Dist [mm]");
     fCosDA->SetXTitle("cos(\\delta,\\alpha)");
+    fDCA->SetXTitle("DCA [\\circ]");
+    fDCADelta->SetXTitle("DCADelta [0, 2\\pi]");
 
     fAlpha->SetYTitle("Counts");
     fDist->SetYTitle("Counts");
     fCosDA->SetYTitle("Counts");
+    fDCA->SetYTitle("Counts");
+    fDCADelta->SetYTitle("Counts");
 }
 
@@ -96,4 +104,6 @@
     delete fDist;
     delete fCosDA;
+    delete fDCA;
+    delete fDCADelta;
 }
 
@@ -121,4 +131,6 @@
     ApplyBinning(*plist, "Alpha",    fAlpha);
     ApplyBinning(*plist, "Dist",     fDist);
+    ApplyBinning(*plist, "DCA",      fDCA);
+    ApplyBinning(*plist, "DCADelta",     fDCADelta);
 
     return kTRUE;
@@ -143,4 +155,6 @@
     fDist ->Fill(fUseMmScale ? h.GetDist() : fMm2Deg*h.GetDist(), w);
     fCosDA->Fill(h.GetCosDeltaAlpha(), w);
+    fDCA  ->Fill(fUseMmScale ? h.GetDCA() : fMm2Deg*h.GetDCA(), w);
+    fDCADelta ->Fill(h.GetDCADelta(), w);
 
     return kTRUE;
@@ -186,6 +200,8 @@
     const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
     MH::ScaleAxis(fDist, scale);
+    MH::ScaleAxis(fDCA,  scale);
 
     fDist->SetXTitle(mmscale ? "Dist [mm]" : "Dist [\\circ]");
+    fDCA->SetXTitle(mmscale ? "DCA [mm]" : "DCA [\\circ]");
 
     fUseMmScale = mmscale;
@@ -217,10 +233,20 @@
     fDist->Draw();
 
-    delete pad->GetPad(3);
+    pad->cd(3);
+    gPad->SetBorderMode(0);
+    fDCA->Draw();
 
     pad->cd(4);
     gPad->SetBorderMode(0);
-    //gPad->SetLogy();
+
+    TVirtualPad *p = gPad;
+    p->Divide(1,2);
+    p->cd(1);
+    gPad->SetBorderMode(0);
     fCosDA->Draw();
+
+    p->cd(2);
+    gPad->SetBorderMode(0);
+    fDCADelta->Draw();
 
     pad->Modified();
Index: /trunk/MagicSoft/Mars/mimage/MHHillasSrc.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHHillasSrc.h	(revision 4816)
+++ /trunk/MagicSoft/Mars/mimage/MHHillasSrc.h	(revision 4817)
@@ -15,4 +15,7 @@
     TH1F *fDist;      //->
     TH1F *fCosDA;     //->
+
+    TH1F *fDCA;       //->
+    TH1F *fDCADelta;  //->
 
     Float_t fMm2Deg;
@@ -34,4 +37,6 @@
     TH1F *GetHistDist()          { return fDist; }
     TH1F *GetHistCosDeltaAlpha() { return fCosDA; }
+    TH1F *GetHistDCA()           { return fDCA; }
+    TH1F *GetHistDCADelta()      { return fDCADelta; }
 
     void Draw(Option_t *opt=NULL);
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrc.cc	(revision 4817)
@@ -57,6 +57,12 @@
 // Version 4:
 // ----------
-//
 // fHeadTail        removed
+//
+//
+// Version 5:
+// ----------
+//  - added Float_t fDCA;      // [mm]   Distance to closest approach 'DCA'
+//  - added Float_t fDCADelta; // [deg]  Angle of the shower axis with respect
+//                                       to the x-axis [0,2pi]
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -91,4 +97,7 @@
     fAlpha         =  0;
     fCosDeltaAlpha =  0;
+
+    fDCA           = -1;
+    fDCADelta          =  0;
 }
 
@@ -99,53 +108,75 @@
 //  you call the Reset member function before.
 //
-Bool_t MHillasSrc::Calc(const MHillas &hillas)
-{
-    const Double_t mx = hillas.GetMeanX();     // [mm]
-    const Double_t my = hillas.GetMeanY();     // [mm]
-
-    const Double_t sx = mx - fSrcPos->GetX();   // [mm]
-    const Double_t sy = my - fSrcPos->GetY();   // [mm]
-
-    const Double_t sd = hillas.GetSinDelta();  // [1]
-    const Double_t cd = hillas.GetCosDelta();  // [1]
-
-    //
-    // Distance from source position to center of ellipse.
-    // If the distance is 0 distance, Alpha is not specified.
-    // The calculation has failed and returnes kFALSE.
-    //
-    const Double_t dist = sqrt(sx*sx + sy*sy);  // [mm]
-    if (dist==0)
-        return kFALSE;
-
-    //
-    // Calculate Alpha and Cosda = cos(d,a)
-    // The sign of Cosda will be used for quantities containing 
-    // a head-tail information
-    //
-    // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
-    // *OLD* fAlpha = asin(arg)*kRad2Deg;
-    //
-    const Double_t arg1 = cd*sy-sd*sx;          // [mm]
-    const Double_t arg2 = cd*sx+sd*sy;          // [mm]
-
-    //
-    // Due to numerical uncertanties in the calculation of the
-    // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
-    // that the absolute value of arg exceeds 1. Because this uncertainty
-    // results in an Delta Alpha which is still less than 1e-3 we don't care
-    // about this uncertainty in general and simply set values which exceed
-    // to 1 saving its sign.
-    //
-    const Double_t arg = arg1/dist;
-    fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : asin(arg)*kRad2Deg;  // [deg]
-
-    fCosDeltaAlpha = arg2/dist;                 // [1]
-    fDist          = dist;                      // [mm]
-
-    SetReadyToSave();
-
-    return kTRUE;
-} 
+Int_t MHillasSrc::Calc(const MHillas &hillas)
+{
+     const Double_t mx = hillas.GetMeanX();     // [mm]
+     const Double_t my = hillas.GetMeanY();     // [mm]
+
+     const Double_t sx = mx - fSrcPos->GetX();   // [mm]
+     const Double_t sy = my - fSrcPos->GetY();   // [mm]
+
+     const Double_t sd = hillas.GetSinDelta();  // [1]
+     const Double_t cd = hillas.GetCosDelta();  // [1]
+
+     //
+     // Distance from source position to center of ellipse.
+     // If the distance is 0 distance, Alpha is not specified.
+     // The calculation has failed and returnes kFALSE.
+     //
+     const Double_t dist = TMath::Sqrt(sx*sx + sy*sy);  // [mm]
+     if (dist==0)
+         return 1;
+
+     //
+     // Calculate Alpha and Cosda = cos(d,a)
+     // The sign of Cosda will be used for quantities containing
+     // a head-tail information
+     //
+     // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
+     // *OLD* fAlpha = asin(arg)*kRad2Deg;
+     //
+     const Double_t arg2 = cd*sx + sd*sy;          // [mm]
+     if (arg2==0)
+         return 2;
+
+     const Double_t arg1 = cd*sy - sd*sx;          // [mm]
+
+     //
+     // Due to numerical uncertanties in the calculation of the
+     // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
+     // that the absolute value of arg exceeds 1. Because this uncertainty
+     // results in an Delta Alpha which is still less than 1e-3 we don't care
+     // about this uncertainty in general and simply set values which exceed
+     // to 1 saving its sign.
+     //
+     const Double_t arg = arg1/dist;
+     fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : TMath::ASin(arg)*TMath::RadToDeg(); // [deg]
+
+     fCosDeltaAlpha = arg2/dist;                 // [1]
+     fDist          = dist;                      // [mm]
+
+     // ----- Calculation of Distance to closest approach 'DCA' -----
+
+     // Components of DCA vector
+     const Double_t fpd1 = sx - arg2*cd;         // [mm]
+     const Double_t fpd2 = sy - arg2*sd;         // [mm]
+
+     // Determine the correct sign of the DCA (cross product of DCA vector and the
+     // vector going from the intersection point of the DCA vector with the shower axis
+     // to the COG)
+     const Double_t sign = arg2*cd*fpd2 - arg2*sd*fpd1;
+     fDCA  = TMath::Sign(TMath::Sqrt(fpd1*fpd1 + fpd2*fpd2), sign); // [mm]
+
+     // Calculate angle of the shower axis with respect to the x-axis
+     fDCADelta = TMath::ACos((sx-fpd1)/TMath::Abs(arg2))*TMath::RadToDeg(); // [deg]
+
+     // Enlarge the interval of fDdca to [0, 2pi]
+     if (sy < fpd2)
+         fDCADelta = 360 - fDCADelta;
+
+     SetReadyToSave();
+
+     return 0;
+}
 
 // --------------------------------------------------------------------------
@@ -160,4 +191,6 @@
     *fLog << " - Alpha          [deg] = " << fAlpha << endl;
     *fLog << " - CosDeltaAlpha        = " << fCosDeltaAlpha << endl;
+    *fLog << " - DCA            [mm]  = " << fDCA << endl;
+    *fLog << " - DCA delta      [deg] = " << fDCADelta*TMath::RadToDeg() << endl;
 }
 
@@ -174,4 +207,6 @@
     *fLog << " - Alpha          [deg] = " << fAlpha << endl;
     *fLog << " - CosDeltaAlpha        = " << fCosDeltaAlpha << endl;
+    *fLog << " - DCA            [deg] = " << fDCA*geom.GetConvMm2Deg() << endl;
+    *fLog << " - DCA delta      [deg] = " << fDCADelta*TMath::RadToDeg() << endl;
 }
 
@@ -183,5 +218,5 @@
 void MHillasSrc::Set(const TArrayF &arr)
 {
-    if (arr.GetSize() != 3)
+    if (arr.GetSize() != 5)
         return;
 
@@ -189,3 +224,5 @@
     fDist  = arr.At(1);         // [mm]   distance between src and center of ellipse
     fCosDeltaAlpha = arr.At(2); // [1]    cosine of angle between d and a
-}
+    fDCA = arr.At(3);           // [mm]
+    fDCADelta = arr.At(4);      // [mm]
+}
Index: /trunk/MagicSoft/Mars/mimage/MHillasSrc.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 4816)
+++ /trunk/MagicSoft/Mars/mimage/MHillasSrc.h	(revision 4817)
@@ -17,4 +17,7 @@
     Float_t fCosDeltaAlpha; // [1]    cosine of angle between d and a
 
+    Float_t fDCA;           // [mm]   Distance to closest approach 'DCA'
+    Float_t fDCADelta;      // [deg]  Angle of the shower axis with respect to the x-axis
+
 public:
     MHillasSrc(const char *name=NULL, const char *title=NULL);
@@ -28,13 +31,15 @@
     Float_t GetDist()          const { return fDist; }
     Float_t GetCosDeltaAlpha() const { return fCosDeltaAlpha; }
+    Float_t GetDCA()           const { return fDCA; }
+    Float_t GetDCADelta()      const { return fDCADelta; }
 
     void Print(Option_t *opt=NULL) const;
     void Print(const MGeomCam &geom) const;
 
-    virtual Bool_t Calc(const MHillas &hillas);
+    virtual Int_t Calc(const MHillas &hillas);
 
     void Set(const TArrayF &arr);
 
-    ClassDef(MHillasSrc, 4) // Container to hold source position dependant parameters
+    ClassDef(MHillasSrc, 5) // Container to hold source position dependant parameters
 };
 
Index: /trunk/MagicSoft/Mars/mpointing/MPointingPos.h
===================================================================
--- /trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 4816)
+++ /trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 4817)
@@ -4,4 +4,9 @@
 #ifndef MARS_MParContainer
 #include "MParContainer.h"
+#endif
+
+// FIXME: Should not be here...
+#ifndef MARS_MPointing
+#include "MPointing.h"
 #endif
 
@@ -32,4 +37,9 @@
     Double_t GetAz() const  { return fAz; }
 
+    Double_t GetZdRad() const  { return fZd*TMath::DegToRad(); }
+    Double_t GetAzRad() const  { return fAz*TMath::DegToRad(); }
+
+    ZdAz GetZdAz() const { return ZdAz(fZd, fAz); }
+
     Double_t GetRa() const  { return fRa; }
     Double_t GetHa() const  { return fHa; }
Index: /trunk/MagicSoft/Mars/mpointing/MPointingPosCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpointing/MPointingPosCalc.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/mpointing/MPointingPosCalc.cc	(revision 4817)
@@ -134,5 +134,5 @@
     case MRawRunHeader::kRTData:
         fPosition->SetLocalPosition(fReport->GetNominalZd(), fReport->GetNominalAz());
-        fPosition->SetSkyPosition(fReport->GetRa()*TMath::DegToRad()/15, fReport->GetDec()*TMath::DegToRad());
+        fPosition->SetSkyPosition(fReport->GetRa()/**TMath::DegToRad()/15*/, fReport->GetDec()/**TMath::DegToRad()*/);
         return kTRUE;
 
Index: /trunk/MagicSoft/Mars/star.cc
===================================================================
--- /trunk/MagicSoft/Mars/star.cc	(revision 4816)
+++ /trunk/MagicSoft/Mars/star.cc	(revision 4817)
@@ -49,4 +49,6 @@
     gLog << "   --debug-env               Debug setting resources from file" << endl << endl;
     gLog << endl;
+    gLog << " Output options:" << endl;
+    gLog << "   -q                        Quit when job is finished" << endl;
     gLog << "   -f                        Force overwrite of existing files" << endl;
     gLog << "   -ff                       Force execution if not all files found" << endl;
@@ -87,8 +89,10 @@
     const Bool_t  kDebugEnv   = arg.HasOnlyAndRemove("--debug-env");
 
+    const Bool_t  kQuit       = arg.HasOnlyAndRemove("-q");
+    const Bool_t  kBatch      = arg.HasOnlyAndRemove("-b");
     const Bool_t  kOverwrite  = arg.HasOnlyAndRemove("-f");
     const Bool_t  kForceExec  = arg.HasOnlyAndRemove("-ff");
 
-    const TString kInpath     = arg.GetStringAndRemove("--in=",  "");
+    const TString kInpath     = arg.GetStringAndRemove("--ind=", "");
     const TString kOutpath    = arg.GetStringAndRemove("--out=", ".");
 
@@ -141,5 +145,4 @@
     //
     MDirIter iter;
-    seq.SetupDatRuns(iter, kInpath);
 
     const Int_t n0 = seq.SetupDatRuns(iter, kInpath);
@@ -179,5 +182,5 @@
 
     TApplication app("Star", &argc, argv);
-    if (gROOT->IsBatch() || !gClient)
+    if (!gROOT->IsBatch() && !gClient)
     {
         gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
@@ -219,4 +222,10 @@
     }
 
+    if (kBatch || kQuit)
+    {
+        delete d;
+        return 0;
+    }
+
     // From now on each 'Close' means: Terminate the application
     d->SetBit(MStatusDisplay::kExitLoopOnClose);
