Index: trunk/MagicSoft/Mars/mastro/MAstro.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstro.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mastro/MAstro.cc	(revision 3666)
@@ -85,5 +85,5 @@
 Double_t MAstro::Dms2Hor(Int_t deg, UInt_t min, Double_t sec, Char_t sgn)
 {
-    return Hms2Sec(deg, min, sec, sgn)/15.;
+    return Hms2Sec(deg, min, sec, sgn)/54000.;
 }
 
Index: trunk/MagicSoft/Mars/mastro/MAstroCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 3666)
@@ -148,5 +148,11 @@
 
 // --------------------------------------------------------------------------
-void MAstroCamera::AddPrimitives(Option_t *o)
+//
+// Options:
+//
+//  '*' Draw the mean of the reflections on all mirrors
+//  '.' Draw a dot for the reflection on each mirror
+//
+void MAstroCamera::AddPrimitives(TString o)
 {
     if (!fTime || !fObservatory || !fMirrors)
@@ -156,12 +162,11 @@
     }
 
-    TString opt(o);
-    if (opt.IsNull())
-        opt = "*.";
-
-    const Bool_t hashist = opt.Contains("h", TString::kIgnoreCase);
-    const Bool_t hasmean = opt.Contains("*", TString::kIgnoreCase);
-    const Bool_t hasdot  = opt.Contains(".", TString::kIgnoreCase);
-    const Bool_t usecam  = opt.Contains("c", TString::kIgnoreCase);
+    if (o.IsNull())
+        o = "*.";
+
+    const Bool_t hashist = o.Contains("h", TString::kIgnoreCase);
+    const Bool_t hasmean = o.Contains("*", TString::kIgnoreCase);
+    const Bool_t hasdot  = o.Contains(".", TString::kIgnoreCase);
+    const Bool_t usecam  = o.Contains("c", TString::kIgnoreCase);
 
     // Get camera
Index: trunk/MagicSoft/Mars/mastro/MAstroCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCamera.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mastro/MAstroCamera.h	(revision 3666)
@@ -22,6 +22,6 @@
 
     Int_t  ConvertToPad(const TVector3 &w, TVector2 &v) const;
-    void   AddPrimitives(Option_t *o);
-    void   SetRangePad() { }
+    void   AddPrimitives(TString o);
+    void   SetRangePad(Option_t *o) { }
     void   ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2);
 
Index: trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 3666)
@@ -147,14 +147,5 @@
 MAstroCatalog::~MAstroCatalog()
 {
-    if (fTime)
-        delete fTime;
-    if (fObservatory)
-        delete fObservatory;
-
-    fToolTip->Hide();
-    delete fToolTip;
-
-    DeleteMap();
-
+    // First disconnect the EventInfo...
     // FIXME: There must be an easier way!
     TIter Next(gROOT->GetListOfCanvases());
@@ -164,4 +155,14 @@
                       "EventInfo(Int_t,Int_t,Int_t,TObject*)");
 
+    // Now delete the data members
+    if (fTime)
+        delete fTime;
+    if (fObservatory)
+        delete fObservatory;
+
+    fToolTip->Hide();
+    delete fToolTip;
+
+    DeleteMap();
 }
 
@@ -438,8 +439,10 @@
 void MAstroCatalog::Paint(Option_t *o)
 {
-    SetRangePad();
+    SetRangePad(o);
 
     if (TestBit(kHasChanged))
         DrawPrimitives(o);
+
+    PaintMap();
 }
 
@@ -458,5 +461,5 @@
 
     // draw star on the camera display
-    TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotLarge);;
+    TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotMedium);;
     tip->SetMarkerColor(kBlack);
     AddMap(tip, new TString(str));
@@ -517,12 +520,13 @@
         w *= 1./w(2);
 
-    w *= TMath::RadToDeg();
-    v.Set(w(0), w(1));
+    w *= TMath::RadToDeg(); // FIXME: *conversion factor?
+    v.Set(TestBit(kMirrorX) ? -w(0) : w(0),
+          TestBit(kMirrorY) ? -w(1) : w(1));
 
     if (w(2)<0)
         return kERROR;
 
-    return w(0)>gPad->GetX1() && w(1)>gPad->GetY1() &&
-           w(0)<gPad->GetX2() && w(1)<gPad->GetY2();
+    return v.X()>gPad->GetX1() && v.Y()>gPad->GetY1() &&
+           v.X()<gPad->GetX2() && v.Y()<gPad->GetY2();
 }
 
@@ -610,6 +614,4 @@
             dx[0] = d[0]+dirs[i][0];
             dy[0] = d[1]+dirs[i][1];
-
-            //cout << dx[0] << " " << dy[0] << endl;
 
             // Draw corresponding line and iterate through grid
@@ -756,8 +758,7 @@
 
     txt.Prepend("#splitline{");
-
-    txt += Form("  \\theta=%.1fh ",    fmod(zd+270,180)-90);
-    txt += Form("\\phi=%.1f\\circ ",   fmod(az+720, 360));
-    txt += Form(" / \\rho=%.1f\\circ", rho*TMath::RadToDeg());
+    txt += Form("  \\theta=%.1f\\circ ", fmod(zd+270,180)-90);
+    txt += Form("\\phi=%.1f\\circ ",     fmod(az+720, 360));
+    txt += Form(" / \\rho=%.1f\\circ",   rho*TMath::RadToDeg());
     txt += "}{<";
     txt += fTime->GetSqlDateTime();
@@ -767,9 +768,42 @@
 
 // --------------------------------------------------------------------------
-void MAstroCatalog::AddPrimitives(Option_t *o)
-{
-    const Bool_t local = TString(o).Contains("local", TString::kIgnoreCase);
-
-    cout << "Opt: " << o << endl;
+//
+// To overlay the catalog make sure, that in any case you are using
+// the 'same' option.
+//
+// If you want to overlay this on top of any picture which is created
+// by derotation of the camera plain you have to use the 'mirror' option
+// the compensate the mirroring of the image in the camera plain.
+//
+// If you have already compensated this by x=-x and y=-y when creating
+// the histogram you can simply overlay the catalog.
+//
+// To overlay the catalog on a 2D histogram the histogram must have
+// units of degrees (which are plain, like you directly convert the
+// camera units by multiplication to degrees)
+//
+// To be 100% exact you must use the option 'plain' which assumes a plain
+// screen. This is not necessary for the MAGIC-camera because the
+// difference between both is less than 1e-3.
+//
+// You should always be aware of the fact, that the shown stars and the
+// displayed grid is the ideal case, like a reflection on a virtual
+// perfectly aligned central mirror. In reality the star-positions are
+// smeared to the edge of the camera the more the distance to the center
+// is, such that the center of gravity of the light distribution might
+// be more far away from the center than the display shows.
+//
+//
+void MAstroCatalog::AddPrimitives(TString o)
+{
+    const Bool_t same   = o.Contains("same",    TString::kIgnoreCase);
+    const Bool_t local  = o.Contains("local",   TString::kIgnoreCase);
+    const Bool_t mirx   = o.Contains("mirrorx", TString::kIgnoreCase);
+    const Bool_t miry   = o.Contains("mirrory", TString::kIgnoreCase);
+    const Bool_t mirror = o.Contains("mirror",  TString::kIgnoreCase) && !mirx && !miry;
+
+    // X is vice versa, because ra is defined anti-clockwise
+    mirx || mirror ? ResetBit(kMirrorX) : SetBit(kMirrorX);
+    miry || mirror ? SetBit(kMirrorY) : ResetBit(kMirrorY);
 
     const TRotation rot(GetGrid(local));
@@ -782,10 +816,13 @@
         TVector2 s(v->Phi(), v->Theta());
         if (Convert(rot, s)==kTRUE)
-            DrawStar(s.X(), -(TMath::Pi()/2-s.Y()), *v, kFALSE);
-    }
-
-    TPaveText *pv = new TPaveText(0.01, 0.90, 0.63, 0.99, "brNDC");
-    pv->AddText(GetPadTitle());
-    AddMap(pv);
+            DrawStar(s.X(), s.Y(), *v, kFALSE);
+    }
+
+    if (!same)
+    {
+        TPaveText *pv = new TPaveText(0.01, 0.90, 0.63, 0.99, "brNDC");
+        pv->AddText(GetPadTitle());
+        AddMap(pv);
+    }
 
     TMarker *mk=new TMarker(0, 0, kMultiply);
@@ -796,16 +833,19 @@
 
 // --------------------------------------------------------------------------
-void MAstroCatalog::SetRangePad()
-{
-     const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
-     gPad->Range(-edge, -edge, edge, edge);
-
-     const Float_t w = gPad->GetWw();
-     const Float_t h = gPad->GetWh();
-
-     if (w<h)
-         gPad->Range(-edge, -edge*h/w, edge, edge*h/w);
-     else
-         gPad->Range(-edge*w/h, -edge, edge*w/h, edge);
+void MAstroCatalog::SetRangePad(Option_t *o)
+{
+    if (TString(o).Contains("same", TString::kIgnoreCase))
+        return;
+
+    const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
+    gPad->Range(-edge, -edge, edge, edge);
+
+    const Float_t w = gPad->GetWw();
+    const Float_t h = gPad->GetWh();
+
+    if (w<h)
+        gPad->Range(-edge, -edge*h/w, edge, edge*h/w);
+    else
+        gPad->Range(-edge*w/h, -edge, edge*w/h, edge);
 }
 
@@ -815,5 +855,5 @@
     DeleteMap();
 
-    SetRangePad();
+    SetRangePad(o);
 
     TStopwatch clk;
@@ -827,17 +867,14 @@
         AppendPad(o);
 
-    // Append all objects to pad
-    DrawMap();
-
     ResetBit(kHasChanged);
 }
 
 // --------------------------------------------------------------------------
-void MAstroCatalog::DrawMap()
+void MAstroCatalog::PaintMap()
 {
     Long_t key, val;
     TExMapIter map(&fMapG);
     while (map.Next(key, val))
-        ((TObject*)key)->Draw();
+        ((TObject*)key)->Paint();
 }
 
@@ -1016,2 +1053,22 @@
     fToolTip->Show(x+4, y+4);
 }
+/*
+void MAstroCatalog::RecursiveRemove(TObject *obj)
+{
+    ULong_t hash;
+    Long_t key, val;
+
+    TExMapIter map(&fMapG);
+    while (map.Next(hash, key, val))
+    {
+        if (key != (Long_t)obj)
+            continue;
+
+        fMapG.Remove(hash, key);
+        delete (TObject*)(key);
+        if (val)
+            delete (TString*)(val);
+        break;
+    }
+}
+*/
Index: trunk/MagicSoft/Mars/mastro/MAstroCatalog.h
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 3666)
@@ -94,6 +94,6 @@
 
     virtual Int_t ConvertToPad(const TVector3 &w, TVector2 &v) const;
-    virtual void  AddPrimitives(Option_t *o);
-    virtual void  SetRangePad();
+    virtual void  AddPrimitives(TString o);
+    virtual void  SetRangePad(Option_t *o);
 
     Int_t     Convert(const TRotation &rot, TVector2 &v) const;
@@ -105,5 +105,6 @@
     void      Paint(Option_t *o="");
     Int_t     DistancetoPrimitive(Int_t px, Int_t py);
-    void      DrawMap();
+    //void      RecursiveRemove(TObject *obj);
+    void      PaintMap();
     void      DeleteMap()
     {
@@ -117,13 +118,14 @@
 
             delete (TString*)(val);
-         /*
-            Long_t key2, val2;
-            TExMapIter map2(&fMapG);
-            while (map2.Next(key2, val2))
-                if (val==val2)
-                {
-                    delete (TObject*)key;
-                    fMapG.Remove(key);
-                }*/
+            /*
+              Long_t key2, val2;
+              TExMapIter map2(&fMapG);
+              while (map2.Next(key2, val2))
+                  if (val==val2)
+                  {
+                      delete (TObject*)key;
+                      fMapG.Remove(key);
+                  }
+             */
         }
         fMapG.Delete();
@@ -134,5 +136,7 @@
         kHasChanged  = BIT(15),
         kGuiActive   = BIT(16),
-        kPlainScreen = BIT(17)
+        kPlainScreen = BIT(17),
+        kMirrorX     = BIT(18),
+        kMirrorY     = BIT(19)
     };
 
@@ -140,5 +144,5 @@
     MVector3 fRaDec;     // pointing position
 
-    MObservatory *fObservatory; // Possible obervatora location
+    MObservatory *fObservatory; // Possible obervatory location
     MTime        *fTime;        // Possible observation time
 
@@ -153,6 +157,6 @@
     void AddMap(TObject *k, void *v=0)
     {
-        k->SetBit(kCanDelete);
-        k->SetBit(kCannotPick);
+        //k->SetBit(kCanDelete);
+        //k->SetBit(kCannotPick);
         fMapG.Add(fMapG.GetSize(), (Long_t)k, (Long_t)v);
     }
@@ -164,5 +168,5 @@
     void SetTime(const MTime &time);
     void SetObservatory(const MObservatory &obs);
-    void SetLimMag(Double_t mag) { fLimMag=mag;    Update(); } // *MENU* *ARGS={mag=>fLimMag}
+    void SetLimMag(Double_t mag) { fLimMag=mag; Update(); } // *MENU* *ARGS={mag=>fLimMag}
     void SetRadiusFOV(Double_t deg)
     {
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 3666)
@@ -333,20 +333,20 @@
 
     //
-    // Update current speed each second
-    //
-    if (fDisplay && t0-t2>(TTime)1000)
-    {
-        const Int_t speed = 1000*(num-start)/(long int)(t0-t2);
+    // Update current speed each 1.5 second
+    //
+    if (fDisplay && t0-t2>(TTime)1500)
+    {
+        const Float_t speed = 1000.*(num-start)/(long int)(t0-t2);
         TString txt = "Processing...";
         if (speed>0)
         {
             txt += " (";
-            txt += speed;
+            txt += (Int_t)speed;
             txt += "Evts/s";
             if (fNumEvents>0)
             {
                 txt += ", est: ";
-                txt += (int)((long int)(t0-t2)*fNumEvents/(60000.*(num-start)));
-                txt += "m";
+                txt += (int)((fNumEvents-num)/speed/60)+1;
+                txt += "min";
             }
             //txt += (int)fmod(entries/(1000.*(num-start)/(long int)(t0-t2)), 60);
@@ -356,5 +356,5 @@
         fDisplay->SetStatusLine1(txt);
         start = num;
-        t2 = t1;
+        t2 = t0;
     }
 
Index: trunk/MagicSoft/Mars/mbase/MMath.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 3666)
@@ -52,4 +52,16 @@
 // --------------------------------------------------------------------------
 //
+// Symmetrized significance - this is somehow analog to
+// SignificanceLiMaSigned
+//
+// Returns Significance(s,b) if s>b otherwise -Significance(b, s);
+// 
+Double_t MMath::SignificanceSym(Double_t s, Double_t b)
+{
+    return s>b ? Significance(s, b) : -Significance(b, s);
+}
+
+// --------------------------------------------------------------------------
+//
 //  calculates the significance according to Li & Ma
 //  ApJ 272 (1983) 317, Formula 17
@@ -58,4 +70,6 @@
 //  b                    // b: number of off events
 //  alpha = t_on/t_off;  // t: observation time
+//
+//  The significance has the same (positive!) value for s>b and b>s.
 //
 //  Returns -1 if sum<0 or alpha<0 or the argument of sqrt<0
@@ -77,2 +91,17 @@
     return l+m<0 ? -1 : TMath::Sqrt((l+m)*2);
 }
+
+// --------------------------------------------------------------------------
+//
+// Calculates MMath::SignificanceLiMa(s, b, alpha). Returns 0 if the
+// calculation has failed. Otherwise the Li/Ma significance which was
+// calculated. If s<b a negative value is returned.
+//
+Double_t MMath::SignificanceLiMaSigned(Double_t s, Double_t b, Double_t alpha)
+{
+    const Double_t sig = SignificanceLiMa(s, b, alpha);
+    if (sig<=0)
+        return 0;
+
+    return TMath::Sign(sig, s-b);
+}
Index: trunk/MagicSoft/Mars/mbase/MMath.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MMath.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MMath.h	(revision 3666)
@@ -10,5 +10,7 @@
 public:
     static Double_t Significance(Double_t s, Double_t b);
+    static Double_t SignificanceSym(Double_t s, Double_t b);
     static Double_t SignificanceLiMa(Double_t s, Double_t b, Double_t alpha=1);
+    static Double_t SignificanceLiMaSigned(Double_t s, Double_t b, Double_t alpha=1);
 
     ClassDef(MMath, 0)
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 3666)
@@ -407,12 +407,49 @@
 TMethodCall *MParContainer::GetterMethod(const char *name) const
 {
-    TClass *cls = IsA()->GetBaseDataMember(name);
+    const TString n(name);
+    const Int_t pos1 = n.First('.');
+
+    const TString part1 = pos1<0 ? n : n(0, pos1);
+    const TString part2 = pos1<0 ? TString("") : n(pos1+1, n.Length());
+
+    TClass *cls = IsA()->GetBaseDataMember(part1);
     if (cls)
     {
-        TDataMember *member = cls->GetDataMember(name);
+        TDataMember *member = cls->GetDataMember(part1);
         if (!member)
         {
-            *fLog << err << "Datamember '" << name << "' not in " << GetDescriptor() << endl;
+            *fLog << err << "Datamember '" << part1 << "' not in " << GetDescriptor() << endl;
             return NULL;
+        }
+
+        // This handles returning references of contained objects, eg
+        // class X { TObject fO; TObject &GetO() { return fO; } };
+        if (!member->IsBasic() && !part2.IsNull())
+        {
+            cls = gROOT->GetClass(member->GetTypeName());
+            if (!cls)
+            {
+                *fLog << err << "Datamember " << part1 << " [";
+                *fLog << member->GetTypeName() << "] not in dictionary." << endl;
+                return NULL;
+            }
+            if (!cls->InheritsFrom(MParContainer::Class()))
+            {
+                *fLog << err << "Datamember " << part1 << " [";
+                *fLog << member->GetTypeName() << "] does not inherit from ";
+                *fLog << "MParContainer." << endl;
+                return NULL;
+            }
+
+            const MParContainer *sub = (MParContainer*)((ULong_t)this+member->GetOffset());
+            return sub->GetterMethod(part2);
+        }
+
+        if (member->IsaPointer())
+        {
+            *fLog << warn << "Data-member " << part1 << " is a pointer..." << endl;
+            *fLog << dbginf << "Not yet implemented!" << endl;
+            //TClass *test = gROOT->GetClass(member->GetTypeName());
+            return 0;
         }
 
@@ -422,5 +459,5 @@
     }
 
-    *fLog << warn << "No standard access for '" << name << "' in ";
+    *fLog << warn << "No standard access for '" << part1 << "' in ";
     *fLog << GetDescriptor() << " or one of its base classes." << endl;
 
@@ -428,6 +465,6 @@
 
     *fLog << warn << "Trying to find MethodCall '" << ClassName();
-    *fLog << "::Get" << name << "' instead <LEAKS MEMORY>" << endl;
-    call = new TMethodCall(IsA(), (TString)"Get"+name, "");
+    *fLog << "::Get" << part1 << "' instead <LEAKS MEMORY>" << endl;
+    call = new TMethodCall(IsA(), (TString)"Get"+part1, "");
     if (call->GetMethod())
         return call;
@@ -436,6 +473,6 @@
 
     *fLog << warn << "Trying to find MethodCall '" << ClassName();
-    *fLog << "::" << name << "' instead <LEAKS MEMORY>" << endl;
-    call = new TMethodCall(IsA(), name, "");
+    *fLog << "::" << part1 << "' instead <LEAKS MEMORY>" << endl;
+    call = new TMethodCall(IsA(), part1, "");
     if (call->GetMethod())
         return call;
@@ -443,5 +480,5 @@
     delete call;
 
-    *fLog << err << "Sorry, no getter method found for " << name << endl;
+    *fLog << err << "Sorry, no getter method found for " << part1 << endl;
     return NULL;
 }
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 3666)
@@ -1433,5 +1433,5 @@
     //        where (eg Eventloop) first!
 
-    gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
+    //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
 
     if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
@@ -1443,9 +1443,9 @@
     if (fIsLocked<=0 && IsOnHeap())
     {
-        gLog << dbg << "delete " << fName << ";" << endl;
+        //gLog << dbg << "delete " << fName << ";" << endl;
         delete this;
     }
     fStatus = kFileExit;
-    gLog << dbg << fName << ".fStatus=kFileExit;" << endl;
+    //gLog << dbg << fName << ".fStatus=kFileExit;" << endl;
 }
 
Index: trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 3666)
@@ -106,5 +106,5 @@
 MTask::MTask(const char *name, const char *title)
     : fFilter(NULL), fSerialNumber(0), fIsPreprocessed(kFALSE),
-    fNumExecutions(0), fStopwatch(0)
+    fStopwatch(0)
 {
     fName  = name  ? name  : "MTask";
@@ -194,5 +194,4 @@
 Int_t MTask::CallPreProcess(MParList *plist)
 {
-    fNumExecutions = 0;
     fStopwatch->Reset();
 
@@ -240,6 +239,4 @@
         return kTRUE;
 
-    fNumExecutions++;
-
     fStopwatch->Start(kFALSE);
     const Int_t rc = Process();
@@ -346,5 +343,16 @@
 // --------------------------------------------------------------------------
 //
-//  Return total CPU execution time of task
+//  Return the total number of calls to Process(). If Process() was not
+//  called due to a set filter this is not counted.
+//
+UInt_t MTask::GetNumExecutions() const
+{
+    return (UInt_t)fStopwatch->Counter();
+}
+
+// --------------------------------------------------------------------------
+//
+//  Return total CPU execution time in seconds of calls to Process().
+//  If Process() was not called due to a set filter this is not counted.
 //
 Double_t MTask::GetCpuTime() const
@@ -355,5 +363,6 @@
 // --------------------------------------------------------------------------
 //
-//  Return total real execution time of task
+//  Return total real execution time in seconds of calls to Process().
+//  If Process() was not called due to a set filter this is not counted.
 //
 Double_t MTask::GetRealTime() const
@@ -366,4 +375,11 @@
 //  Prints the relative time spent in Process() (relative means relative to
 //  its parent Tasklist) and the number of times Process() was executed.
+//  Don't wonder if the sum of the tasks in a tasklist is not 100%,
+//  because only the call to Process() of the task is measured. The
+//  time of the support structure is ignored. The faster your analysis is
+//  the more time is 'wasted' in the support structure.
+//  Only the CPU time is displayed. This means that exspecially task
+//  which have a huge part of file i/o will be underestimated in their
+//  relative wasted time.
 //  For convinience the lvl argument results in a number of spaces at the
 //  beginning of the line. So that the structur of a tasklist can be
@@ -379,10 +395,11 @@
 
     *fLog << all << setfill(' ') << setw(lvl) << " ";
-    if (fStopwatch->CpuTime()>0 && time>0)
-        *fLog << setw(3) << (Int_t)(fStopwatch->CpuTime()/time*100+.5) << "% ";
+
+    if (GetCpuTime()>0 && time>0 && GetCpuTime()>=0.001*time)
+        *fLog << Form("%5.1f", GetCpuTime()/time*100) << "% ";
     else
-        *fLog << "     ";
+        *fLog << "       ";
     *fLog << GetDescriptor() << "\t";
-    *fLog << dec << fNumExecutions;
+    *fLog << dec << GetNumExecutions();
     if (fFilter)
         *fLog << " <" << fFilter->GetName() << ">";
Index: trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MTask.h	(revision 3666)
@@ -29,7 +29,6 @@
 
     Bool_t fIsPreprocessed; //! Indicates the success of the PreProcessing (set by MTaskList)
-    UInt_t fNumExecutions;  //! Number of Excutions
 
-    TStopwatch *fStopwatch; //!
+    TStopwatch *fStopwatch; //! Count the execution time and number of executions
 
     virtual Int_t PreProcess(MParList *pList);
@@ -74,6 +73,6 @@
     // Filter functions
     virtual void SetFilter(MFilter *filter) { fFilter=filter; }
-    const MFilter *GetFilter() const      { return fFilter; }
-    MFilter *GetFilter()  { return fFilter; } // for MContinue only
+    const MFilter *GetFilter() const        { return fFilter; }
+    MFilter *GetFilter()                    { return fFilter; } // for MContinue only
 
     // Display functions
@@ -86,11 +85,11 @@
     TString AddSerialNumber(const TString &str) const { return AddSerialNumber(str, fSerialNumber); }
 
-    virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; }
-    Byte_t  GetSerialNumber() const { return fSerialNumber; }
+    virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num;  }
+    Byte_t GetSerialNumber() const           { return fSerialNumber; }
 
     const char *GetDescriptor() const;
 
     // Task execution statistics
-    UInt_t GetNumExecutions() const { return fNumExecutions; }
+    UInt_t   GetNumExecutions() const;
     Double_t GetCpuTime() const;
     Double_t GetRealTime() const;
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 3666)
@@ -635,4 +635,8 @@
         if (title)
             *fLog << "\t" << fTitle;
+        if (time>=0)
+            *fLog << Form(" %5.1f", GetCpuTime()/time*100) << "%";
+        else
+            *fLog << " 100.0%";
         *fLog << endl;
     }
Index: trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 3666)
@@ -70,5 +70,5 @@
 
     void Print(Option_t *opt = "") const;
-    void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const;
+    void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=-1) const;
     void SetOwner(Bool_t enable=kTRUE);
 
Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 3666)
@@ -362,5 +362,5 @@
     const Double_t sum = (r1+r2)/(24*3600);
 
-    return fmod(sum, 1)*TMath::TwoPi()+TMath::TwoPi();
+    return fmod(sum, 1)*TMath::TwoPi();//+TMath::TwoPi();
 }
 
Index: trunk/MagicSoft/Mars/mcamera/MCameraAUX.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraAUX.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraAUX.h	(revision 3666)
@@ -14,4 +14,5 @@
     Bool_t fStatusCaosLEDs;  // Monitored status: o=off, 1=on, Cam.CaOs.LED_state
     Bool_t fStatusFansFADC;  // Monitored status: o=off, 1=on, Cam.FADC.Fans_state
+
 public:
     MCameraAUX()
@@ -20,4 +21,10 @@
         fTitle = "Container storing information about the Camera auxiliary system";
     }
+
+    Bool_t GetRequestCaosLEDs() const { return fRequestCaosLEDs; }
+    Bool_t GetRequestFansFADC() const { return fRequestFansFADC; }
+    Bool_t GetStatusCaosLEDs() const  { return fStatusCaosLEDs;  }
+    Bool_t GetStatusFansFADC() const  { return fStatusFansFADC;  }
+
     ClassDef(MCameraAUX, 1) // Container storing information about the Camera auxiliary system
 };
Index: trunk/MagicSoft/Mars/mcamera/MCameraCalibration.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraCalibration.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraCalibration.h	(revision 3666)
@@ -31,4 +31,5 @@
     Byte_t GetStatusIO() const         { return fStatusIO; }
     Byte_t GetStatusLoVoltage() const  { return fStatusLoVoltage; }
+
     Bool_t GetRequestHiVoltage() const { return fRequestHiVoltage; }
     Bool_t GetRequestLoVoltage() const { return fRequestLoVoltage; }
Index: trunk/MagicSoft/Mars/mcamera/MCameraHV.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraHV.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraHV.h	(revision 3666)
@@ -28,6 +28,4 @@
     TArrayS fHV;            // [V] Measured high Voltages for all PMTs
 
-    Float_t fMean;          // [V] Mean high voltage of the camera
-
 public:
     MCameraHV() : fHV(577)
@@ -39,19 +37,21 @@
     Byte_t  GetStatus() const { return fStatus; }
     Bool_t  GetStatusRamping() const { return fStatusRamping; }
+
     Short_t GetVoltageA() const { return fVoltageA; }
     Short_t GetVoltageB() const { return fVoltageB; }
-    Byte_t GetCurrentA() const { return fCurrentA; }
-    Byte_t GetCurrentB() const { return fCurrentB; }
 
-    Float_t GetMean() { fMean = fHV.GetSum()/fHV.GetSize(); return fMean; }
+    Byte_t  GetCurrentA() const { return fCurrentA; }
+    Byte_t  GetCurrentB() const { return fCurrentB; }
+
+    Float_t GetMean() const { return fHV.GetSum()/fHV.GetSize(); }
 
     Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const
-      {
-	val = fHV[idx];
-	return val>0;
-      }
+    {
+        val = fHV[idx];
+        return val>0;
+    }
     void DrawPixelContent(Int_t num) const
-      {
-      }
+    {
+    }
 
     ClassDef(MCameraHV, 1) // Container storing information about the Camera HV
Index: trunk/MagicSoft/Mars/mcamera/MCameraLV.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraLV.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraLV.h	(revision 3666)
@@ -14,12 +14,12 @@
     friend class MReportCamera;
 private:
-    Byte_t  fStatus;                    // CaCo monitored LV PS status:  , Cam.LV_state
-    Bool_t  fRequestPowerSupply;        // Requested status: o=off, 1=on, blv_ps_status
+    Byte_t  fStatus;                  // CaCo monitored LV PS status:  , Cam.LV_state
+    Bool_t  fRequestPowerSupply;      // Requested status: o=off, 1=on, blv_ps_status
 
-    Float_t fTemp;                     // Measured status: o=off, 1=on, blv_temp
-    Byte_t  fHumidity;                 // Measured status: o=off, 1=on, blv_RelativeHumidity
+    Float_t fTemp;                    // Measured status: o=off, 1=on, blv_temp
+    Byte_t  fHumidity;                // Measured status: o=off, 1=on, blv_RelativeHumidity
 
-    MCameraPowerSupply fPowerSupplyA;   // power supply camera part A
-    MCameraPowerSupply fPowerSupplyB;   // power supply camera part B
+    MCameraPowerSupply fPowerSupplyA; // power supply camera part A
+    MCameraPowerSupply fPowerSupplyB; // power supply camera part B
 
 public:
@@ -32,6 +32,10 @@
     Byte_t  GetStatus() const { return fStatus; }
     Bool_t  GetRequestPowerSupply() const { return fRequestPowerSupply; }
+
     Float_t GetTemp() const { return fTemp; }
     Byte_t  GetHumidity() const { return fHumidity; }
+
+    const MCameraPowerSupply &GetPowerSupplyA() const { return fPowerSupplyA; }
+    const MCameraPowerSupply &GetPowerSupplyB() const { return fPowerSupplyB; }
 
     ClassDef(MCameraLV, 1) // Container storing information about the Camera LV
Index: trunk/MagicSoft/Mars/mcamera/MCameraLid.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraLid.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraLid.h	(revision 3666)
@@ -14,8 +14,11 @@
      Bool_t fLimitOpen;        // 0=not active, 1= active
      Bool_t fLimitClose;       // 0=not active, 1= active
+
      Bool_t fSafetyLimitOpen;  // 0=not active, 1= active
      Bool_t fSafetyLimitClose; // 0=not active, 1= active
+
      Byte_t fStatusLid;        // 0=positioning, 1=open, 2=closed
      Byte_t fStatusMotor;      // 0=stopped, 1=opening, 2=closing
+
 public:
     MCameraLid()
@@ -24,4 +27,14 @@
         fTitle = "Container storing information about a Camera lid";
     }
+
+    Bool_t GetLimitOpen() const        { return fLimitOpen;        }
+    Bool_t GetLimitClose() const       { return fLimitClose;       }
+
+    Bool_t GetSafetyLimitOpen() const  { return fSafetyLimitOpen;  }
+    Bool_t GetSafetyLimitClose() const { return fSafetyLimitClose; }
+
+    Byte_t GetStatusLid() const        { return fStatusLid;        }
+    Byte_t GetStatusMotor() const      { return fStatusMotor;      }
+
     ClassDef(MCameraLid, 1) // Container storing information about a Camera lid
 };
Index: trunk/MagicSoft/Mars/mcamera/MCameraLids.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraLids.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraLids.h	(revision 3666)
@@ -27,4 +27,7 @@
     Byte_t GetStatus() const { return fStatus; }
 
+    const MCameraLid &GetLidA() const { return fLidA; }
+    const MCameraLid &GetLidB() const { return fLidB; }
+
     ClassDef(MCameraLids, 1) // Container storing information about the Camera lids
 };
Index: trunk/MagicSoft/Mars/mcamera/MCameraPowerSupply.h
===================================================================
--- trunk/MagicSoft/Mars/mcamera/MCameraPowerSupply.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mcamera/MCameraPowerSupply.h	(revision 3666)
@@ -10,13 +10,13 @@
     friend class MReportCamera;
 private:
-     Float_t fVoltagePos5V;         // [V] voltage_pos5  (+5V)
-     Float_t fVoltagePos12V;        // [V] voltage_pos12 (+12V)
-     Float_t fVoltageNeg12V;        // [V] voltage_neg12 (-12V)
-     Float_t fVoltageOptLinkPos12V; // [V] volatge_opt_link_pos12 (+12V)
+    Float_t fVoltagePos5V;         // [V] voltage_pos5  (+5V)
+    Float_t fVoltagePos12V;        // [V] voltage_pos12 (+12V)
+    Float_t fVoltageNeg12V;        // [V] voltage_neg12 (-12V)
+    Float_t fVoltageOptLinkPos12V; // [V] volatge_opt_link_pos12 (+12V)
 
-     Float_t fCurrentPos5V;         // [A] current_pos5  (+5V)
-     Float_t fCurrentPos12V;        // [A] current_pos12 (+12V)
-     Float_t fCurrentNeg12V;        // [A] current_neg12 (-12V)
-     Float_t fCurrentOptLinkPos12V; // [A] current_opt_link_pos12 (+12V)
+    Float_t fCurrentPos5V;         // [A] current_pos5  (+5V)
+    Float_t fCurrentPos12V;        // [A] current_pos12 (+12V)
+    Float_t fCurrentNeg12V;        // [A] current_neg12 (-12V)
+    Float_t fCurrentOptLinkPos12V; // [A] current_opt_link_pos12 (+12V)
 
 public:
@@ -26,4 +26,15 @@
         fTitle = "Container storing information about the Camera power supply";
     }
+
+    Float_t GetVoltagePos5V() const         { return fVoltagePos5V; }
+    Float_t GetVoltagePos12V() const        { return fVoltagePos12V; }
+    Float_t GetVoltageNeg12V() const        { return fVoltageNeg12V; }
+    Float_t GetVoltageOptLinkPos12V() const { return fVoltageOptLinkPos12V; }
+
+    Float_t GetCurrentPos5V() const         { return fCurrentPos5V; }
+    Float_t GetCurrentPos12V() const        { return fCurrentPos12V; }
+    Float_t GetCurrentNeg12V() const        { return fCurrentNeg12V; }
+    Float_t GetCurrentOptLinkPos12V() const { return fCurrentOptLinkPos12V; }
+
     ClassDef(MCameraPowerSupply, 1) // Container storing information about the Camera power supply
 };
Index: trunk/MagicSoft/Mars/mdata/DataLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/DataLinkDef.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/DataLinkDef.h	(revision 3666)
@@ -12,4 +12,5 @@
 #pragma link C++ class MDataMember+;
 #pragma link C++ class MDataChain+;
+#pragma link C++ class MDataFormula+;
 
 #endif
Index: trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 3666)
@@ -25,8 +25,13 @@
 /////////////////////////////////////////////////////////////////////////////
 //
-//   MDataChain
+// MDataChain
+// ==========
 //
 // With this chain you can concatenate simple mathematical operations on
 // members of mars containers.
+//
+//
+// Rules
+// -----
 //
 // In the constructor you can give rule, like
@@ -36,10 +41,19 @@
 // in the containers. The result will be fDist divided by fLength.
 //
+// In case you want to access a data-member which is a data member object
+// you can acces it with (Remark: it must derive from MParContainer):
+//   "MCameraLV.fPowerSupplyA.fVoltagePos5V"
+//
 // You can also use brackets:
 //   "HillasDource.fDist / (MHillas.fLength + MHillas.fWidth)"
 //
-// The allowed operations are: +, -, *, /, %
+//
+// Operators
+// ---------
+//
+// The allowed operations are: +, -, *, /, %, ^
 //
 // While a%b returns the floating point reminder of a/b.
+// While a^b returns a to the power of b
 //
 // Warning: There is no priority rule build in. So better use brackets
@@ -98,30 +112,52 @@
 // inf is the symbol for an infinite number.
 //
+//
+// Constants
+// ---------
+//
 // Constants are implemented in ParseDataMember, namely:
-//   kPi:      TMath::Pi()
-//   kRad2Deg: 180/kPi
-//   kDeg2Rad: kPi/180
+//   kPi:       TMath::Pi()
+//   kRad2Deg:  180/kPi
+//   kDeg2Rad:  kPi/180
 //
 // You can also defined constants which are defined in TMath by:
-//   kLn10      for   static Double_t TMath::Ln10();
-//   kLogE      for   static Double_t TMath::LogE();
-//   kRadToDeg  for   static Double_t TMath::RadToDeg();
-//   kDegToRad  for   static Double_t TMath::DegToRad();
-//
-// Remark: In older root versions only Pi() and E() are implemented in
-//         TMath.
-//
+//   kLn10       for   static Double_t TMath::Ln10();
+//   kLogE       for   static Double_t TMath::LogE();
+//   kRadToDeg   for   static Double_t TMath::RadToDeg();
+//   kDegToRad   for   static Double_t TMath::DegToRad();
+//   ...
+//
+// Remark:
+//  In older root versions only Pi() and E() are implemented
+//  in TMath.
+//
+//
+// Variable Parameters
+// ------------------------
 // If you want to use variables, eg for fits you can use [0], [1], ...
 // These values are initialized with 0 and set by calling
 // SetVariables().
 //
+//
+// Multi-argument functions
+// ------------------------
+// You can use multi-argument functions, too. The access is implemented
+// via TFormula, which slows down thing a lot. If you can avoid usage
+// of such expression you accelerate the access a lot. Example:
+//   "TMath::Hypot(MHillas.fMeanX, MHillas.MeanY)"
+//   "pow(MHillas.fMeanX*MHillas.MeanY, -1.2)"
+// It should be possible to use all functions which are accessible
+// via the root-dictionary.
+//
+//
 // REMARK:
-//         - All the random functions are returning 0 if gRandom==0
-//         - You may get better results if you are using a TRandom3
-//
-// FIXME: The possibility to use other objects inheriting from MData
-//        is missing.
-//        Maybe we can use gInterpreter->Calc("") for this.
-//        gROOT->ProcessLineFast("line");
+//  - All the random functions are returning 0 if gRandom==0
+//  - You may get better results if you are using a TRandom3
+//
+// To Do:
+//  - The possibility to use other objects inheriting from MData
+//    is missing.
+//  - By automatic pre-adding brackets to the rule it would be possible
+//    to implement priorities for operators.
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -141,4 +177,5 @@
 #include "MDataValue.h"
 #include "MDataMember.h"
+#include "MDataFormula.h"
 #include "MDataElement.h"
 
@@ -222,5 +259,5 @@
     for (int i=0; i<l; i++)
     {
-        if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=';' && 
+        if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=':' && txt[i]!=';' &&
 	    /*txt[i]!='['&&txt[i]!=']'&&*/
             ((txt[i]!='-' && txt[i]!='+') || i!=0))
@@ -394,4 +431,5 @@
         case '/':
         case '%':
+        case '^':
             if (member0)
             {
@@ -507,6 +545,15 @@
 
             OperatorType_t op = ParseOperator(text);
+
+            Int_t first = GetBracket(txt, '(', ')');
+            TString sub = op==kENegative || op==kEPositive ? text.Remove(0,1) + txt : txt(1, first-1);
+            txt.Remove(0, first+1);
+
             if (op==kENoop)
             {
+                newmember = new MDataFormula(Form("%s(%s)", (const char*)text, (const char*)sub));
+                if (newmember->IsValid())
+                    break;
+
                 *fLog << err << dbginf << "Syntax Error: Operator '" << text << "' unknown." << endl;
                 if (member0)
@@ -514,8 +561,4 @@
                 return NULL;
             }
-
-            Int_t first = GetBracket(txt, '(', ')');
-            TString sub = op==kENegative || op==kEPositive ? text.Remove(0,1) + txt : txt(1, first-1);
-            txt.Remove(0, first+1);
 
             newmember = new MDataChain(sub, op);
@@ -604,44 +647,4 @@
     return 0;
 }
-
-    /*
-void MDataChain::Print(Option_t *opt) const
-{
-    *fLog << GetRule() << flush;
-    Bool_t bracket = fOperatorType!=kENoop && !fMember->InheritsFrom(MDataList::Class());
-
-    switch (fOperatorType)
-    {
-    case kEAbs:      *fLog << "abs"   << flush; break;
-    case kELog:      *fLog << "log"   << flush; break;
-    case kELog10:    *fLog << "log10" << flush; break;
-    case kESin:      *fLog << "sin"   << flush; break;
-    case kECos:      *fLog << "cos"   << flush; break;
-    case kETan:      *fLog << "tan"   << flush; break;
-    case kESinH:     *fLog << "sinh"  << flush; break;
-    case kECosH:     *fLog << "cosh"  << flush; break;
-    case kETanH:     *fLog << "tanh"  << flush; break;
-    case kEASin:     *fLog << "asin"  << flush; break;
-    case kEACos:     *fLog << "acos"  << flush; break;
-    case kEATan:     *fLog << "atan"  << flush; break;
-    case kESqrt:     *fLog << "sqrt"  << flush; break;
-    case kEExp:      *fLog << "exp"   << flush; break;
-    case kEPow10:    *fLog << "pow10" << flush; break;
-    case kESgn:      *fLog << "sgn"   << flush; break;
-    case kENegative: *fLog << "-" << flush; break;
-    case kEPositive: *fLog << "+" << flush; break;
-    case kENoop:
-        break;
-    }
-
-    if (bracket)
-        *fLog << "(" << flush;
-
-    fMember->Print();
-
-    if (bracket)
-        *fLog << ")" << flush;
-        }
-        */
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 3666)
@@ -17,5 +17,5 @@
 {
 private:
-    MData *fMember; // Filter
+    MData    *fMember; // Filter
 
     // PLEASE, always add new enums to the end of the enumeration,
Index: trunk/MagicSoft/Mars/mdata/MDataFormula.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataFormula.cc	(revision 3666)
+++ trunk/MagicSoft/Mars/mdata/MDataFormula.cc	(revision 3666)
@@ -0,0 +1,318 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 04/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MDataFormula
+//
+// A MDataFormula is a wrapper for TFormula. It should have access to all
+// multi-argument functions, to formulas and to single-argument functions
+// unknown by MDataChain intrinsically.
+//
+// eg.
+//  MDataFormula("myfunc(MParams.fValue)");
+//  MDataFormula("TMath::Hypot(MParams.fX, MParams.fY)");
+//  MDataFormula("TMath::Pow(MParams.fX, 7.5)");
+//  MDataFormula("TMath::Pow(MParams.fX, [6])");
+//
+// Using this should be rather slow. If you can create a 'plain' Data-Chain
+// this should be much faster.
+//
+// To do:
+//  - implement SetVariables to be used in functions like "gaus(0)" or
+//    "pol0(1)"
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MDataFormula.h"
+
+#include <TArrayD.h>
+#include <TFormula.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MDataChain.h"
+
+ClassImp(MDataFormula);
+
+using namespace std;
+
+TString MDataFormula::Parse(const char *rule)
+{
+    TString txt(rule);
+
+    Int_t pos1 = txt.First('(');
+    if (pos1<0)
+    {
+        *fLog << err << dbginf << "Syntax Error: '(' not found in " << txt << endl;
+        return "";
+    }
+
+    Int_t pos2 = txt.Last(')');
+    if (pos2<0)
+    {
+        *fLog << err << dbginf << "Syntax Error: ')' not found in " << txt << endl;
+        return "";
+    }
+
+    if (pos2<pos1+1)
+    {
+        *fLog << err << dbginf << "Syntax Error: '(' not behind ')' in " << txt << endl;
+        return "";
+    }
+
+    //TObject *func = gROOT->GetListOfFunctions()->FindObject(txt(0, pos1));
+
+    TString args = txt(pos1+1, pos2-pos1);
+    Int_t num = 0;
+
+    while (args.Length()>0 && num<5)
+    {
+        const Int_t last = args.First(',');
+        const Int_t len = last<0 ? args.Last(')') : last;
+        if (len<0)
+        {
+            *fLog << err << dbginf << "Syntax Error: ',' found after ')'" << endl;
+            return "";
+        }
+
+        const TString arg = args(0, len);
+
+        MDataChain *chain = new MDataChain(arg);
+        if (!chain->IsValid())
+        {
+            delete chain;
+            return "";
+        }
+        fMembers.AddLast(chain);
+
+        txt.ReplaceAll(arg, Form("[%d]", num++));
+        pos1 += len;
+
+        args.Remove(0, len+1);
+    }
+
+    return txt;
+}
+
+// --------------------------------------------------------------------------
+//
+//   Default Constructor. Not for usage!
+//
+MDataFormula::MDataFormula(const char *rule, const char *name, const char *title) : fFormula(0)
+{
+    fName  = name  ? name  : "MDataFormula";
+    fTitle = title ? title : rule;
+
+    fMembers.SetOwner();
+
+    if (!rule)
+        return;
+
+    const TString txt=Parse(rule);
+    if (txt.IsNull())
+    {
+        fMembers.Delete();
+        return;
+    }
+
+    fFormula = new TFormula;
+    if (fFormula->Compile(txt))
+    {
+        *fLog << err << dbginf << "Syntax Error: TFormula::Compile failed for " << txt << endl;
+        delete fFormula;
+        fFormula = 0;
+        return;
+    }
+
+    gROOT->GetListOfFunctions()->Remove(fFormula);
+}
+
+// --------------------------------------------------------------------------
+//
+//   Destructor
+//
+MDataFormula::~MDataFormula()
+{
+    if (fFormula)
+        delete fFormula;
+}
+
+// --------------------------------------------------------------------------
+//
+//   CopyConstructor
+//
+MDataFormula::MDataFormula(MDataFormula &ts)
+{
+    TFormula *f = ts.fFormula;
+
+    fName  = "MDataFormula";
+    fTitle = f ? f->GetExpFormula() : (TString)"";
+
+    fFormula = f ? (TFormula*)f->Clone() : 0;
+    gROOT->GetListOfFunctions()->Add(fFormula);
+
+    fMembers.SetOwner();
+
+    TObject *o = NULL;
+    TIter Next(&ts.fMembers);
+    while ((o=Next()))
+        fMembers.AddLast(o->Clone());
+}
+
+// --------------------------------------------------------------------------
+//
+//  Evaluates and returns the result of the member list.
+//  The expression is evaluated step by step, eg:
+//  ((member[0] # member[1]) # member[3]) # member[4])
+//  The '#' stands for the boolean operation which is specified in
+//  the constructor.
+//
+Double_t MDataFormula::GetValue() const
+{
+    TArrayD val(fMembers.GetSize());
+
+    MData *member = NULL;
+
+    Int_t i=0;
+    TIter Next(&fMembers);
+    while ((member=(MData*)Next()))
+        val[i++] = member->GetValue();
+
+    return fFormula->EvalPar(0, val.GetArray());
+}
+
+Bool_t MDataFormula::IsValid() const
+{
+    TIter Next(&fMembers);
+
+    MData *data = NULL;
+    while ((data=(MData*)Next()))
+        if (!data->IsValid())
+            return kFALSE;
+
+    return fFormula ? kTRUE : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks whether at least one member has the ready-to-save flag.
+//
+Bool_t MDataFormula::IsReadyToSave() const
+{
+    TIter Next(&fMembers);
+
+    MData *data = NULL;
+
+    while ((data=(MData*)Next()))
+        if (data->IsReadyToSave())
+            return kTRUE;
+
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// PreProcesses all members in the list
+//
+Bool_t MDataFormula::PreProcess(const MParList *plist)
+{
+    TIter Next(&fMembers);
+
+    MData *member=NULL;
+
+    //
+    // loop over all members
+    //
+    while ((member=(MData*)Next()))
+        if (!member->PreProcess(plist))
+        {
+            *fLog << err << "Error - Preprocessing Data Member ";
+            *fLog << member->GetName() << " in " << fName << endl;
+            return kFALSE;
+        }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Builds a rule from all the list members. This is a rule which could
+// be used to rebuild the list using the constructor of a MDataChain
+//
+TString MDataFormula::GetRule() const
+{
+    if (!fFormula)
+        return "<empty>";
+
+    TString rule = fFormula->GetExpFormula();
+
+    MData *member = NULL;
+
+    Int_t i=0;
+    TIter Next(&fMembers);
+    while ((member=(MData*)Next()))
+    {
+        TString r = member->GetRule();
+        r.ReplaceAll("]", "\\]");
+        rule.ReplaceAll(Form("[%d]", i++), r);
+    }
+    rule.ReplaceAll("\\]", "]");
+
+    return rule;
+}
+/*
+// --------------------------------------------------------------------------
+//
+// Return a comma seperated list of all data members used in the chain.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MDataFormula::GetDataMember() const
+{
+    TString str;
+
+    TIter Next(&fMembers);
+
+    MData *member=(MData*)Next();
+
+    if (!member->GetDataMember().IsNull())
+        str += member->GetDataMember();
+
+    while ((member=(MData*)Next()))
+    {
+        if (!member->GetDataMember().IsNull())
+        {
+            str += ",";
+            str += member->GetDataMember();
+        }
+    }
+
+    return str;
+}
+
+void MDataFormula::SetVariables(const TArrayD &arr)
+{
+    fMembers.ForEach(MData, SetVariables)(arr);
+}
+*/
Index: trunk/MagicSoft/Mars/mdata/MDataFormula.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataFormula.h	(revision 3666)
+++ trunk/MagicSoft/Mars/mdata/MDataFormula.h	(revision 3666)
@@ -0,0 +1,43 @@
+#ifndef MARS_MDataFormula
+#define MARS_MDataFormula
+
+#ifndef ROOT_TOrdCollection
+#include <TOrdCollection.h>
+#endif
+
+#ifndef MARS_MData
+#include "MData.h"
+#endif
+
+class TFormula;
+class MParList;
+
+class MDataFormula : public MData
+{
+private:
+    TFormula      *fFormula;    // TFormula
+    TOrdCollection fMembers;	// Container for the filters
+
+    TString Parse(const char *rule);
+
+public:
+    MDataFormula(const char *rule=0, const char *name=0, const char *title=0);
+    MDataFormula(MDataFormula &ts);
+    ~MDataFormula();
+
+    Bool_t IsValid() const;// { return fFormula ? kTRUE : kFALSE; }
+    Bool_t IsReadyToSave() const;
+
+    Double_t GetValue() const;
+    Bool_t PreProcess(const MParList *plist);
+
+    //    void Print(Option_t *opt = "") const;
+    TString GetRule() const;
+    //    TString GetDataMember() const;
+
+    //void SetVariables(const TArrayD &arr);
+
+    ClassDef(MDataFormula, 1) // A concatenation of MData objects by one operator
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mdata/MDataList.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 3666)
@@ -79,4 +79,7 @@
         fSign = kEModul;
         return;
+    case '^':
+        fSign = kEPow;
+        return;
     default:
         fSign = kENone;
@@ -142,8 +145,8 @@
         while ((member=(MData*)Next()))
         {
-            Double_t d = member->GetValue();
+            const Double_t d = member->GetValue();
             if (d==0)
             {
-                *fLog << warn << "Warning: Division by zero (" << member->GetName() << ")" << endl;
+                *fLog << warn << "Warning: Division by zero: " << member->GetRule() << endl;
                 return 0;
             }
@@ -155,8 +158,8 @@
         while ((member=(MData*)Next()))
         {
-            Double_t d = member->GetValue();
+            const Double_t d = member->GetValue();
             if (d==0)
             {
-                *fLog << warn << "Warning: Modulo division by zero (" << member->GetName() << ")" << endl;
+                *fLog << warn << "Warning: Modulo division by zero: " << member->GetRule() << endl;
                 return 0;
             }
@@ -164,4 +167,8 @@
         }
         break;
+    case kEPow:
+        while ((member=(MData*)Next()))
+            val = pow(val, member->GetValue());
+        break;
     }
     return val;
@@ -185,8 +192,20 @@
 }
 
+Bool_t MDataList::IsValid() const
+{
+    TIter Next(&fMembers);
+
+    MData *data = NULL;
+    while ((data=(MData*)Next()))
+        if (!data->IsValid())
+            return kFALSE;
+
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
 // If you want to add a new member to the list call this function with the
-// pointer to the member to be added. 
+// pointer to the member to be added.
 //
 Bool_t MDataList::AddToList(MData *member)
@@ -335,4 +354,8 @@
             str += "%";
             break;
+
+        case kEPow:
+            str += "^";
+            break;
         }
 
Index: trunk/MagicSoft/Mars/mdata/MDataList.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 3666)
@@ -23,5 +23,5 @@
     TOrdCollection fMembers;	// Container for the filters
 
-    typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul } SignType_t;
+    typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul, kEPow } SignType_t;
     SignType_t fSign;
 
@@ -41,5 +41,5 @@
     void SetOwner(Bool_t enable=kTRUE) { enable ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
 
-    Bool_t IsValid() const { return fMembers.GetSize() ? kTRUE : kFALSE; }
+    Bool_t IsValid() const;// { return fMembers.GetSize() ? kTRUE : kFALSE; }
     Bool_t IsReadyToSave() const;
 
Index: trunk/MagicSoft/Mars/mdata/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mdata/Makefile	(revision 3665)
+++ trunk/MagicSoft/Mars/mdata/Makefile	(revision 3666)
@@ -37,5 +37,6 @@
 	   MDataValue.cc \
 	   MDataList.cc \
-	   MDataChain.cc
+	   MDataChain.cc \
+           MDataFormula.cc
 
 SRCS    = $(SRCFILES)
Index: trunk/MagicSoft/Mars/mfbase/MFilterList.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFilterList.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mfbase/MFilterList.cc	(revision 3666)
@@ -188,5 +188,5 @@
 
     if (fFilters.FindObject(name))
-        *fLog << warn << "MFilterList::AddToList - '" << name << "' exists in List already..." << endl;
+        *fLog << inf << "MFilterList::AddToList - '" << name << "' exists in List already..." << endl;
 
     *fLog << inf << "Adding " << name << " to " << GetName() << "... " << flush;
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 3666)
@@ -53,4 +53,5 @@
 
 #include <TClass.h>     // IsA()->New()
+#include <TVector2.h>   // TVector2
 
 #include "MLog.h"
@@ -92,5 +93,5 @@
 
     for (UInt_t i=0; i<npix; i++)
-      fPixels[i] = new MGeomPix;
+        fPixels[i] = new MGeomPix;
 
     SetReadyToSave();
@@ -195,44 +196,42 @@
 void MGeomCam::CalcMaxRadius()
 {
-
-  fMaxRadius.Set(fNumAreas+1);
-  fMinRadius.Set(fNumAreas+1);  
-
-  for (Int_t i=0; i<fNumAreas+1; i++)
-    {
-      fMaxRadius[i] = 0.;
-      fMinRadius[i] = FLT_MAX;
-    }
-  
-  for (UInt_t i=0; i<fNumPixels; i++)
-    {
-
-      const MGeomPix &pix = (*this)[i];
-
-      const UInt_t  s = pix.GetAidx();      
-      const Float_t x = pix.GetX();
-      const Float_t y = pix.GetY();
-      const Float_t d = pix.GetD();
-
-      const Float_t r = TMath::Hypot(x, y);
-
-      const Float_t maxr = r + d;
-      const Float_t minr = r>d ? r-d : 0;
-      
-      if (maxr>fMaxRadius[s+1])
-        fMaxRadius[s+1] = maxr;
-
-      if (minr<fMinRadius[s+1])
-        fMinRadius[s+1] = minr;
-
-      if (minr<fMinRadius[0])
-        fMinRadius[0] = minr;
-
-      if (maxr>fMaxRadius[0])
-        fMaxRadius[0] = maxr;
-
-    }
-}
-
+    fMaxRadius.Set(fNumAreas+1);
+    fMinRadius.Set(fNumAreas+1);
+
+    for (Int_t i=0; i<fNumAreas+1; i++)
+    {
+        fMaxRadius[i] = 0.;
+        fMinRadius[i] = FLT_MAX;
+    }
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const MGeomPix &pix = (*this)[i];
+
+        const UInt_t  s = pix.GetAidx();
+        const Float_t x = pix.GetX();
+        const Float_t y = pix.GetY();
+        const Float_t d = pix.GetD();
+
+        const Float_t r = TMath::Hypot(x, y);
+
+        const Float_t maxr = r + d;
+        const Float_t minr = r>d ? r-d : 0;
+
+        if (maxr>fMaxRadius[s+1])
+            fMaxRadius[s+1] = maxr;
+
+        if (minr<fMinRadius[s+1])
+            fMinRadius[s+1] = minr;
+
+        if (minr<fMinRadius[0])
+            fMinRadius[0] = minr;
+
+        if (maxr>fMaxRadius[0])
+            fMaxRadius[0] = maxr;
+    }
+}
+
+// --------------------------------------------------------------------------
 //
 // Have to call the radii of the subcameras starting to count from 1
@@ -240,8 +239,8 @@
 Float_t MGeomCam::GetMaxRadius(const Int_t i) const
 {
-  if (i==-1) return fMaxRadius[0];
-  return i>fNumAreas ? -1 : fMaxRadius[i+1];
-}
-
+    return i<-1 || i>fNumAreas ? -1 : fMaxRadius[i+1];
+}
+
+// --------------------------------------------------------------------------
 //
 // Have to call the radii of the subcameras starting to count from 1
@@ -249,6 +248,5 @@
 Float_t MGeomCam::GetMinRadius(const Int_t i) const
 {
-  if (i==-1) return fMinRadius[0];
-  return i>fNumAreas ? -1 : fMinRadius[i+1];
+    return i<-1 || i>fNumAreas ? -1 : fMinRadius[i+1];
 }
 
@@ -302,4 +300,30 @@
     return (TObject*)IsA()->New();
 }
+
+// --------------------------------------------------------------------------
+//
+//  Return the pixel index corresponding to the coordinates given in x, y.
+//  The coordinates are given in pixel units (millimeters)
+//  If no pixel exists return -1;
+//
+Int_t MGeomCam::GetPixelIdxXY(Float_t x, Float_t y) const
+{
+    for (unsigned int i=0; i<fNumPixels; i++)
+        if ((*this)[i].IsInside(x, y))
+            return i;
+
+    return -1;
+}
+
+Int_t MGeomCam::GetPixelIdx(const TVector2 &v) const
+{
+    return GetPixelIdxXY(v.X(), v.Y());
+}
+
+Int_t MGeomCam::GetPixelIdxDeg(const TVector2 &v) const
+{
+    return GetPixelIdxXYdeg(v.X(), v.Y());
+}
+
 /*
 void MGeomCam::Streamer(TBuffer &R__b)
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 3666)
@@ -12,4 +12,5 @@
 #endif
 
+class TVector2;
 class MGeomPix;
 
@@ -73,5 +74,13 @@
 
     MGeomPix &operator[](Int_t i);
-    MGeomPix &operator[](Int_t i)          const;
+    MGeomPix &operator[](Int_t i) const;
+
+    Int_t GetPixelIdx(const TVector2 &v) const;
+    Int_t GetPixelIdxDeg(const TVector2 &v) const;
+    Int_t GetPixelIdxXY(Float_t x, Float_t y) const;
+    Int_t GetPixelIdxXYdeg(Float_t x, Float_t y) const
+    {
+        return GetPixelIdxXY(x/fConvMm2Deg, y/fConvMm2Deg);
+    }
 
     virtual void Print(Option_t *opt=NULL)   const;
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 3666)
@@ -133,2 +133,39 @@
     *fLog << "d= " << fD << "mm  A= " << fA << "mm²" << endl;
 }
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Hexagon center in
+// MGeomPix coordinates. Return kTRUE if inside.
+//
+Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
+{
+    //
+    //  compute the distance of the Point to the center of the Hexagon
+    //
+    const Double_t dx = px-fX;
+
+    //
+    // Now check if point is outside of hexagon; just check x coordinate
+    // in three coordinate systems: the default one, in which two sides of
+    // the hexagon are paralel to the y axis (see camera displays) and two 
+    // more, rotated with respect to that one by +- 60 degrees.
+    //
+    if (TMath::Abs(dx)*2>fD)
+        return kFALSE;
+
+    const Double_t dy = py-fY;
+
+    const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
+    const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
+
+    const Double_t dx2 = dx*cos60 + dy*sin60;
+    if  (TMath::Abs(dx2)*2>fD)
+        return kFALSE;
+
+    const Double_t dx3 = dx*cos60 - dy*sin60;
+    if (TMath::Abs(dx3)*2>fD)
+        return kFALSE;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 3666)
@@ -56,4 +56,6 @@
     Bool_t IsInOuterRing() const     { return TestBit(kIsInOuterRing); }
 
+    Bool_t IsInside(Float_t px, Float_t py) const;
+
     /*
      //
Index: trunk/MagicSoft/Mars/mhist/MHFalseSource.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHFalseSource.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mhist/MHFalseSource.cc	(revision 3666)
@@ -99,4 +99,6 @@
 //    also different algorithms like (Li/Ma)
 //  - implement fit for best alpha distribution -- online (Paint)
+//  - currently a constant pointing position is assumed in Fill()
+//  - the center of rotation need not to be the camera center
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -117,4 +119,5 @@
 #include "MObservatory.h"
 #include "MPointingPos.h"
+#include "MAstroCatalog.h"
 #include "MAstroSky2Local.h"
 #include "MStatusDisplay.h"
@@ -136,5 +139,6 @@
 //
 MHFalseSource::MHFalseSource(const char *name, const char *title)
-    : fMm2Deg(-1), fUseMmScale(kTRUE), fAlphaCut(12.5), fBgMean(55)
+    : fTime(0), fPointPos(0), fObservatory(0), fMm2Deg(-1),
+      fAlphaCut(12.5), fBgMean(55), fDistMin(-1), fDistMax(-1)
 {
     //
@@ -186,59 +190,4 @@
 // --------------------------------------------------------------------------
 //
-// Use this function to setup your own conversion factor between degrees
-// and millimeters. The conversion factor should be the one calculated in
-// MGeomCam. Use this function with Caution: You could create wrong values
-// by setting up your own scale factor.
-//
-void MHFalseSource::SetMm2Deg(Float_t mmdeg)
-{
-    if (mmdeg<0)
-    {
-        *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
-        return;
-    }
-
-    if (fMm2Deg>=0)
-        *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
-
-    fMm2Deg = mmdeg;
-}
-
-// --------------------------------------------------------------------------
-//
-// With this function you can convert the histogram ('on the fly') between
-// degrees and millimeters.
-//
-void MHFalseSource::SetMmScale(Bool_t mmscale)
-{
-    if (fUseMmScale == mmscale)
-        return;
-
-    if (fMm2Deg<0)
-    {
-        *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
-        return;
-    }
-
-    if (fUseMmScale)
-    {
-        fHist.SetXTitle("x [mm]");
-        fHist.SetYTitle("y [mm]");
-
-        fHist.Scale(1./fMm2Deg);
-    }
-    else
-    {
-        fHist.SetXTitle("x [\\circ]");
-        fHist.SetYTitle("y [\\circ]");
-
-        fHist.Scale(1./fMm2Deg);
-    }
-
-    fUseMmScale = mmscale;
-}
-
-// --------------------------------------------------------------------------
-//
 // Calculate Significance as
 // significance = (s-b)/sqrt(s+k*k*b) mit k=s/b
@@ -249,5 +198,5 @@
 Double_t MHFalseSource::Significance(Double_t s, Double_t b)
 {
-    return MMath::Significance(s, b);
+    return MMath::SignificanceSym(s, b);
 }
 
@@ -263,6 +212,9 @@
 Double_t MHFalseSource::SignificanceLiMa(Double_t s, Double_t b, Double_t alpha)
 {
-    const Double_t lima = MMath::SignificanceLiMa(s, b);
-    return lima<0 ? 0 : lima;
+    return MMath::SignificanceLiMaSigned(s, b);
+    /*
+     const Double_t lima = MMath::SignificanceLiMa(s, b);
+     return lima<0 ? 0 : lima;
+     */
 }
 
@@ -277,12 +229,11 @@
 {
     const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
-    if (geom)
+    if (!geom)
     {
-        fMm2Deg = geom->GetConvMm2Deg();
-        fUseMmScale = kFALSE;
-
-        fHist.SetXTitle("x [\\circ]");
-        fHist.SetYTitle("y [\\circ]");
+        *fLog << err << "MGeomCam not found... aborting." << endl;
+        return kFALSE;
     }
+
+    fMm2Deg = geom->GetConvMm2Deg();
 
     MBinning binsa;
@@ -292,8 +243,5 @@
     if (!bins)
     {
-        Float_t r = geom ? geom->GetMaxRadius() : 600;
-        r /= 3;
-        if (!fUseMmScale)
-            r *= fMm2Deg;
+        const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg;
 
         MBinning b;
@@ -314,6 +262,11 @@
     fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
     if (!fObservatory)
-        *fLog << err << "MObservatory not found...  no derotation." << endl;
-
+        *fLog << warn << "MObservatory not found... no derotation." << endl;
+
+    // FIXME: Because the pointing position could change we must check
+    // for the current pointing position and add a offset in the
+    // Fill function!
+    fRa  = fPointPos->GetRa();
+    fDec = fPointPos->GetDec();
 
     return kTRUE;
@@ -326,6 +279,12 @@
 Bool_t MHFalseSource::Fill(const MParContainer *par, const Stat_t w)
 {
-    MHillas *hil = (MHillas*)par;
-
+    const MHillas *hil = dynamic_cast<const MHillas*>(par);
+    if (!hil)
+    {
+        *fLog << err << "MHFalseSource::Fill: No container specified!" << endl;
+        return kFALSE;
+    }
+
+    // Get max radius...
     const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
 
@@ -337,8 +296,10 @@
     //    rho = fPointPos->RotationAngle(*fObservatory);
 
+    // Create necessary containers for calculation
     MSrcPosCam src;
     MHillasSrc hsrc;
     hsrc.SetSrcPos(&src);
 
+    // Get number of bins and bin-centers
     const Int_t nx = fHist.GetNbinsX();
     const Int_t ny = fHist.GetNbinsY();
@@ -352,16 +313,19 @@
         for (int iy=0; iy<ny; iy++)
         {
+            // check distance... to get a circle plot
             if (TMath::Hypot(cx[ix], cy[iy])>maxr)
                 continue;
 
+            // rotate center of bin
+            // precalculation of sin/cos doesn't accelerate
             TVector2 v(cx[ix], cy[iy]);
             if (rho!=0)
                 v=v.Rotate(rho);
 
-            if (!fUseMmScale)
-                v *= 1./fMm2Deg;
-
+            // convert degrees to millimeters
+            v *= 1./fMm2Deg;
             src.SetXY(v);
 
+            // Source dependant hillas parameters
             if (!hsrc.Calc(hil))
             {
@@ -370,6 +334,15 @@
             }
 
+            // FIXME: This should be replaced by an external MFilter
+            //        and/or MTaskList
+            // Source dependant distance cut
+            if (fDistMin>0 && hsrc.GetDist()*fMm2Deg<fDistMin)
+                continue;
+
+            if (fDistMax>0 && hil->GetLength()>fDistMax*hsrc.GetDist())
+                continue;
+
+            // Fill histogram
             const Double_t alpha = hsrc.GetAlpha();
-
             fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
         }
@@ -446,10 +419,30 @@
 // --------------------------------------------------------------------------
 //
-// Update the projections
+// Create projection for all data, taking sum of bin contents of
+// range (0, 90) - corresponding to the number of entries in this slice.
+//
+void MHFalseSource::ProjectAll(TH2D *h3)
+{
+    h3->SetTitle("Number of entries");
+
+    // Get projection for range
+    TH2D *p = (TH2D*)fHist.Project3D("yx_all");
+
+    // Move contents from projection to h3
+    h3->Reset();
+    h3->Add(p);
+    delete p;
+
+    // Set Minimum as minimum value Greater Than 0
+    h3->SetMinimum(GetMinimumGT(*h3));
+}
+
+// --------------------------------------------------------------------------
+//
+// Update the projections and paint them
 //
 void MHFalseSource::Paint(Option_t *opt)
 {
-    // sigma = (s-b)/sqrt(s+k*k*b) mit k=s/b
-
+    // Set pretty color palette
     gStyle->SetPalette(1, 0);
 
@@ -457,22 +450,31 @@
 
     TH1D* h1;
+    TH2D* h0;
     TH2D* h2;
     TH2D* h3;
     TH2D* h4;
 
-    padsave->cd(3);
+    // Update projection of all-events
+    padsave->GetPad(1)->cd(3);
+    if ((h0 = (TH2D*)gPad->FindObject("Alpha_yx_all")))
+        ProjectAll(h0);
+
+    // Update projection of off-events
+    padsave->GetPad(2)->cd(1);
+    if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off")))
+        ProjectOff(h2);
+
+    // Update projection of on-events
+    padsave->GetPad(2)->cd(2);
     if ((h3 = (TH2D*)gPad->FindObject("Alpha_yx_on")))
         ProjectOn(h3);
 
-    padsave->cd(4);
-    if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off")))
-        ProjectOff(h2);
-
-    padsave->cd(2);
+    // Update projection of significance
+    padsave->GetPad(2)->cd(3);
     if (h2 && h3 && (h4 = (TH2D*)gPad->FindObject("Alpha_yx_sig")))
     {
         const Int_t nx = h4->GetXaxis()->GetNbins();
         const Int_t ny = h4->GetYaxis()->GetNbins();
-        const Int_t nr = nx*nx + ny*ny;
+        //const Int_t nr = nx*nx + ny*ny;
 
         Int_t maxx=nx/2;
@@ -493,5 +495,5 @@
                 h4->SetBinContent(n, sig);
 
-                if (sig>h4->GetBinContent(max) && sig>0 && ix*ix+iy*iy<nr*nr/9)
+                if (sig>h4->GetBinContent(max) && sig>0/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)
                 {
                     max = n;
@@ -501,5 +503,6 @@
             }
 
-        padsave->cd(1);
+        // Update projection of 'the best alpha-plot'
+        padsave->GetPad(1)->cd(1);
         if ((h1 = (TH1D*)gPad->FindObject("Alpha")) && max>0)
         {
@@ -520,4 +523,28 @@
 // --------------------------------------------------------------------------
 //
+// Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude
+// is set to 9, while the fov is equal to the current fov of the false
+// source plot.
+//
+TObject *MHFalseSource::GetCatalog()
+{
+    const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
+
+    // Create catalog...
+    MAstroCatalog stars;
+    stars.SetLimMag(9);
+    stars.SetGuiActive(kFALSE);
+    stars.SetRadiusFOV(maxr);
+    stars.SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
+    stars.ReadBSC("bsc5.dat");
+
+    TObject *o = (MAstroCatalog*)stars.Clone();
+    o->SetBit(kCanDelete);
+
+    return o;
+}
+
+// --------------------------------------------------------------------------
+//
 // Draw the histogram
 //
@@ -529,9 +556,27 @@
     AppendPad("");
 
-    pad->Divide(2, 2);
+    pad->Divide(1, 2, 0, 0.03);
+
+    TObject *catalog = GetCatalog();
 
     // draw the 2D histogram Sigmabar versus Theta
     pad->cd(1);
     gPad->SetBorderMode(0);
+    gPad->Divide(3, 1);
+    delete pad->GetPad(1)->GetPad(2);
+
+    pad->GetPad(1)->cd(3);
+    gPad->SetBorderMode(0);
+    TH1 *h0 = fHist.Project3D("yx_all");
+    h0->SetDirectory(NULL);
+    h0->SetXTitle(fHist.GetXaxis()->GetTitle());
+    h0->SetYTitle(fHist.GetYaxis()->GetTitle());
+    h0->Draw("colz");
+    h0->SetBit(kCanDelete);
+    catalog->Draw("mirror same");
+
+    pad->GetPad(1)->cd(1);
+    gPad->SetBorderMode(0);
+
     TH1 *h1 = fHist.ProjectionZ("Alpha");
     h1->SetDirectory(NULL);
@@ -542,5 +587,11 @@
     h1->SetBit(kCanDelete);
 
-    pad->cd(4);
+    pad->cd(2);
+    gPad->SetBorderMode(0);
+    gPad->Divide(3, 1);
+
+    pad = gPad;
+
+    pad->cd(1);
     gPad->SetBorderMode(0);
     fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2);
@@ -551,6 +602,7 @@
     h2->Draw("colz");
     h2->SetBit(kCanDelete);
-
-    pad->cd(3);
+    catalog->Draw("mirror same");
+
+    pad->cd(2);
     gPad->SetBorderMode(0);
     fHist.GetZaxis()->SetRangeUser(0,fAlphaCut);
@@ -562,6 +614,7 @@
     h3->Draw("colz");
     h3->SetBit(kCanDelete);
-
-    pad->cd(2);
+    catalog->Draw("mirror same");
+
+    pad->cd(3);
     gPad->SetBorderMode(0);
     fHist.GetZaxis()->SetRange(0,0);
@@ -574,4 +627,5 @@
     h4->Draw("colz");
     h4->SetBit(kCanDelete);
+    catalog->Draw("mirror same");
 }
 
@@ -596,11 +650,13 @@
     TVirtualPad *padsave = gPad;
     padsave->Modified();
-    padsave->cd(1);
+    padsave->GetPad(1)->cd(1);
     gPad->Modified();
-    padsave->cd(2);
+    padsave->GetPad(1)->cd(3);
     gPad->Modified();
-    padsave->cd(3);
+    padsave->GetPad(2)->cd(1);
     gPad->Modified();
-    padsave->cd(4);
+    padsave->GetPad(2)->cd(2);
+    gPad->Modified();
+    padsave->GetPad(2)->cd(3);
     gPad->Modified();
     gPad->cd();
@@ -639,4 +695,6 @@
 void MHFalseSource::FitSignificance(Float_t sigint, Float_t sigmax, Float_t bgmin, Float_t bgmax, Byte_t polynom)
 {
+    TObject *catalog = GetCatalog();
+
     TH1D h0a("A",          "", 50,   0, 4000);
     TH1D h4a("chisq1",     "", 50,   0,   35);
@@ -686,13 +744,10 @@
     // Implementing the function yourself is only about 5% faster
     TF1 func("", Form("gaus(0) + pol%d(3)", polynom), 0, 90);
+    //TF1 func("", Form("[0]*(TMath::Gaus(x, [1], [2])+TMath::Gaus(x, -[1], [2]))+pol%d(3)", polynom), 0, 90);
     TArrayD maxpar(func.GetNpar());
 
-    /*
-     func.SetParName(0, "A");
-     func.SetParName(1, "mu");
-     func.SetParName(2, "sigma");
-     func.SetParName(3, "a");
-     func.SetParName(4, "b");
-     func.SetParName(5, "c");
+    /*  func.SetParName(0, "A");
+     *  func.SetParName(1, "mu");
+     *  func.SetParName(2, "sigma");
     */
 
@@ -704,5 +759,5 @@
     const Int_t nx = hist->GetXaxis()->GetNbins();
     const Int_t ny = hist->GetYaxis()->GetNbins();
-    const Int_t nr = nx*nx+ny*ny;
+    //const Int_t nr = nx*nx+ny*ny;
 
     Double_t maxalpha0=0;
@@ -748,5 +803,4 @@
 
             h->Fit(&func, "N0Q", "", bgmin, bgmax);
-            //*fLog << dbg << ix << "/" << iy << ":  " << func.GetParameter(3) << "    " << func.GetParameter(4) << endl;
 
             h4a.Fill(func.GetChisquare());
@@ -774,5 +828,4 @@
 
             h->Fit(&func, "N0Q", "", 0, sigmax);
-            //*fLog << dbg << "     " << func.GetParameter(0) << "    " << func.GetParameter(1) << "    " << func.GetParameter(2) << endl;
 
             TArrayD p(func.GetNpar(), func.GetParameters());
@@ -820,5 +873,5 @@
                 h6.Fill(sig);
 
-            if (sig>maxs && ix*ix+iy*iy<nr*nr/9)
+            if (sig>maxs/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)
             {
                 maxs = sig;
@@ -838,5 +891,5 @@
 
     clk.Stop();
-    clk.Print();
+    clk.Print("m");
 
     TCanvas *c=new TCanvas;
@@ -849,12 +902,15 @@
     hists->Draw("colz");
     hists->SetBit(kCanDelete);
+    catalog->Draw("mirror same");
     c->cd(2);
     gPad->SetBorderMode(0);
     hist->Draw("colz");
     hist->SetBit(kCanDelete);
+    catalog->Draw("mirror same");
     c->cd(3);
     gPad->SetBorderMode(0);
     histb->Draw("colz");
     histb->SetBit(kCanDelete);
+    catalog->Draw("mirror same");
     c->cd(4);
     gPad->Divide(1,3, 0, 0);
@@ -942,5 +998,5 @@
             const Double_t b = f2.Integral(0, (float)i)/w;
 
-            const Double_t sig = Significance(s, b);
+            const Double_t sig = SignificanceLiMa(s, b);
 
             g->SetPoint(g->GetN(), i, sig);
Index: trunk/MagicSoft/Mars/mhist/MHFalseSource.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHFalseSource.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mhist/MHFalseSource.h	(revision 3666)
@@ -12,6 +12,4 @@
 class TH2D;
 
-class MHillasSrc;
-class MEnergyEst;
 class MParList;
 class MTime;
@@ -22,15 +20,20 @@
 {
 private:
-    MTime        *fTime;        //! container to take the event time from
-    MPointingPos *fPointPos;    //! container to take pointing position from
-    MObservatory *fObservatory; //! conteiner to take observatory location from
+    MTime         *fTime;        //! container to take the event time from
+    MPointingPos  *fPointPos;    //! container to take pointing position from
+    MObservatory  *fObservatory; //! conteiner to take observatory location from
 
-    Float_t fMm2Deg;            // conversion factor for display in degrees
-    Bool_t  fUseMmScale;        // which scale to use?
+    Float_t fMm2Deg;             // conversion factor for display in degrees
 
-    Float_t fAlphaCut;          // Alpha cut
-    Float_t fBgMean;            // Background mean
+    Float_t fAlphaCut;           // Alpha cut
+    Float_t fBgMean;             // Background mean
 
-    TH3D    fHist;              // Alpha vs. x and y
+    Float_t fDistMin;            // Min dist
+    Float_t fDistMax;            // Maximum distance in percent of dist
+
+    TH3D    fHist;               // Alpha vs. x and y
+
+    Double_t fRa;
+    Double_t fDec;
 
     Int_t DistancetoPrimitive(Int_t px, Int_t py);
@@ -39,4 +42,7 @@
     void ProjectOff(TH2D *h);
     void ProjectOn(TH2D *h);
+    void ProjectAll(TH2D *h);
+
+    TObject *GetCatalog();
 
 public:
@@ -46,11 +52,11 @@
     Bool_t Fill(const MParContainer *par, const Stat_t w=1);
 
-    void SetMmScale(Bool_t mmscale=kTRUE);
-    void SetMm2Deg(Float_t mmdeg);
-
     TH1 *GetHistByName(const TString name) { return &fHist; }
 
     void FitSignificance(Float_t sigint=15, Float_t sigmax=70, Float_t bgmin=40, Float_t bgmax=70, Byte_t polynom=1); //*MENU*
     void FitSignificanceStd() { FitSignificance(); } //*MENU*
+
+    void SetDistMin(Float_t dist)  { fDistMin = dist;  } // Absolute minimum distance
+    void SetDistMax(Float_t ratio) { fDistMax = ratio; } // Maximum ratio between length/dist
 
     void SetAlphaCut(Float_t alpha); //*MENU*
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 3666)
@@ -34,11 +34,15 @@
 // For a given a shower, a series of points along its main axis are filled 
 // into the 2-dim histogram (x, y) of the camera plane.
-// 
+//
 // Before filling a point (x, y) into the histogram it is
 //        - shifted by (xSrc, ySrc)   (the expected source position)
 //        - and rotated in order to compensate the rotation of the
 //          sky image in the camera
-//         
-//         
+//
+// To be done:
+//  - simplification of the algorithm, by doing all translation before
+//    calculation of the line
+//  - the center of rotation need not to be the camera center
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MHStarMap.h"
Index: trunk/MagicSoft/Mars/mimage/MHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 3666)
@@ -47,4 +47,8 @@
 // fConc1    removed
 //
+// Version 3:
+// ----------
+// fMaxDist  added. Distance between center and most distant used pixel
+//
 //
 // WARNING: Before you can use fAsym, fM3Long and fM3Trans you must
@@ -96,4 +100,6 @@
     fM3Long  =  0;
     fM3Trans =  0;
+
+    fMaxDist = -1;
 }
 
@@ -109,4 +115,5 @@
     *fLog << " - 3.Moment Long  [mm]  = " << fM3Long  << endl;
     *fLog << " - 3.Moment Trans [mm]  = " << fM3Trans << endl;
+    *fLog << " - Max.Dist       [mm]  = " << fMaxDist << endl;
 }
 
@@ -123,4 +130,5 @@
     *fLog << " - 3.Moment Long  [deg] = " << fM3Long *geom.GetConvMm2Deg() << endl;
     *fLog << " - 3.Moment Trans [deg] = " << fM3Trans*geom.GetConvMm2Deg() << endl;
+    *fLog << " - Max.Dist       [deg] = " << fMaxDist*geom.GetConvMm2Deg() << endl;
 }
 
@@ -146,6 +154,7 @@
     const UInt_t npixevt = evt.GetNumPixels();
 
-    Int_t maxpixid = 0;
-    Float_t maxpix = 0;
+    Int_t maxpixid  = 0;
+    Float_t maxpix  = 0;
+    Float_t maxdist = 0;
 
     for (UInt_t i=0; i<npixevt; i++)
@@ -160,4 +169,8 @@
         const Double_t dx = gpix.GetX() - hil.GetMeanX();      // [mm]
         const Double_t dy = gpix.GetY() - hil.GetMeanY();      // [mm]
+
+        const Double_t dist = dx*dx+dy*dy;
+        if (dist>maxdist)
+            maxdist=dist;                                      // [mm^2]
 
         Double_t nphot = pix.GetNumPhotons();                  // [1]
@@ -197,4 +210,6 @@
     fM3Trans = m3y<0 ? -pow(-m3y, 1./3) : pow(m3y, 1./3);      // [mm]
 
+    fMaxDist = TMath::Sqrt(maxdist);                           // [mm]
+
     SetReadyToSave();
 
Index: trunk/MagicSoft/Mars/mimage/MHillasExt.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasExt.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mimage/MHillasExt.h	(revision 3666)
@@ -20,4 +20,6 @@
     Float_t fM3Trans; // [mm] 3rd moment (e-weighted) along minor axis
 
+    Float_t fMaxDist; // Distance between center and most distant used pixel
+
 public:
     MHillasExt(const char *name=NULL, const char *title=NULL);
@@ -29,4 +31,6 @@
     Float_t GetM3Trans() const { return fM3Trans; }
 
+    Float_t GetMaxDist() const { return fMaxDist; }
+
     Int_t Calc(const MGeomCam &geom, const MCerPhotEvt &pix, const MHillas &hil);
 
@@ -36,5 +40,5 @@
     void Set(const TArrayF &arr);
 
-    ClassDef(MHillasExt, 2) // Storage Container for extended Hillas Parameter
+    ClassDef(MHillasExt, 3) // Storage Container for extended Hillas Parameter
 };
 #endif
Index: trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mimage/MHillasSrcCalc.cc	(revision 3666)
@@ -114,5 +114,4 @@
 Int_t MHillasSrcCalc::Process()
 {
-
     if (!fHillasSrc->Calc(fHillas))
     {
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 3666)
@@ -44,4 +44,7 @@
 //  - added fInnerLeakage2
 //  - added fInnerSize
+//  - added fUsedArea
+//  - added fCoreArea
+// 
 // 
 /////////////////////////////////////////////////////////////////////////////
@@ -92,4 +95,7 @@
     fNumCorePixels = -1;
 
+    fUsedArea = -1;
+    fCoreArea = -1;
+
     fNumSaturatedPixels = -1;
     fNumHGSaturatedPixels = -1;
@@ -105,4 +111,7 @@
     fNumUsedPixels = 0;
     fNumCorePixels = 0;
+
+    fUsedArea = 0;
+    fCoreArea = 0;
 
     fNumSaturatedPixels = 0;
@@ -136,14 +145,18 @@
             continue;
 
+        // Get geometry of pixel
+        const Int_t pixid = pix.GetPixId();
+        const MGeomPix &gpix = geom[pixid];
+
         // count used and core pixels
         if (pix.IsPixelCore())
+        {
             fNumCorePixels++;
+            fCoreArea += gpix.GetA();
+        }
 
         // count used pixels
         fNumUsedPixels++;
-
-        const Int_t pixid = pix.GetPixId();
-
-        const MGeomPix &gpix = geom[pixid];
+        fUsedArea += gpix.GetA();
 
         Double_t nphot = pix.GetNumPhotons();
@@ -165,24 +178,24 @@
 	// count inner pixels: To dependent on MAGIC Camera --> FIXME
 
-	if (pixid<397){
-	  fInnerSize += nphot;
-	  if(pixid>270){
-	    edgepixin2 += nphot;
-	    if(pixid>330)
-	      edgepixin1 += nphot;
-	  }
-	}
+        if (pixid<397){
+            fInnerSize += nphot;
+            if(pixid>270){
+                edgepixin2 += nphot;
+                if(pixid>330)
+                    edgepixin1 += nphot;
+            }
+        }
 
 	// Compute Concetration 1 -2 
 
         if (nphot>maxpix1)
-	  {
+        {
             maxpix2  = maxpix1;
             maxpix1  = nphot;                            // [1]
             continue;                                    // [1]
-	  }
-	
+        }
+
         if (nphot>maxpix2)
-	  maxpix2 = nphot;                             // [1]
+            maxpix2 = nphot;                             // [1]
     }
     
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 3666)
@@ -13,15 +13,17 @@
 {
 private:
-    Float_t fLeakage1;           // (photons in most outer ring of pixels) over fSize
-    Float_t fLeakage2;           // (photons in the 2 outer rings of pixels) over fSize
-    Float_t fInnerLeakage1;      // (photons in most outer rings of inner pixels) over fInnerSize
-    Float_t fInnerLeakage2;      // (photons in the 2 outer rings of inner pixels) over fInnerSize
-    Float_t fInnerSize;          //
+    Float_t fLeakage1;             // (photons in most outer ring of pixels) over fSize
+    Float_t fLeakage2;             // (photons in the 2 outer rings of pixels) over fSize
+    Float_t fInnerLeakage1;        // (photons in most outer rings of inner pixels) over fInnerSize
+    Float_t fInnerLeakage2;        // (photons in the 2 outer rings of inner pixels) over fInnerSize
+    Float_t fInnerSize;            //
 
-    Float_t fConc;               // [ratio] concentration ratio: sum of the two highest pixels / fSize
-    Float_t fConc1;              // [ratio] concentration ratio: sum of the highest pixel / fSize
+    Float_t fConc;                 // [ratio] concentration ratio: sum of the two highest pixels / fSize
+    Float_t fConc1;                // [ratio] concentration ratio: sum of the highest pixel / fSize
 
-    Short_t fNumUsedPixels;      // Number of pixels which survived the image cleaning
-    Short_t fNumCorePixels;      // number of core pixels
+    Float_t fUsedArea;             // Area of pixels which survived the image cleaning
+    Float_t fCoreArea;             // Area of core pixels
+    Short_t fNumUsedPixels;        // Number of pixels which survived the image cleaning
+    Short_t fNumCorePixels;        // number of core pixels
     Short_t fNumHGSaturatedPixels; // number of pixels with saturating hi-gains
     Short_t fNumSaturatedPixels;   // number of pixels with saturating lo-gains
@@ -41,4 +43,7 @@
     Short_t GetNumCorePixels() const { return fNumCorePixels; }
 
+    Float_t GetNumUsedArea() const { return fUsedArea; }
+    Float_t GetNumCoreArea() const { return fCoreArea; }
+
     Short_t GetNumSaturatedPixels() const { return fNumSaturatedPixels; }
     Short_t GetNumHGSaturatedPixels() const { return fNumHGSaturatedPixels; }
Index: trunk/MagicSoft/Mars/mpointing/MPointingPos.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingPos.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mpointing/MPointingPos.cc	(revision 3666)
@@ -73,4 +73,4 @@
 Double_t MPointingPos::RotationAngle(const MObservatory &o, const MTime &t) const
 {
-    return MAstroSky2Local(t, o).RotationAngle(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
+    return MAstroSky2Local(t, o).RotationAngle(GetRaRad(), GetDecRad());
 }
Index: trunk/MagicSoft/Mars/mpointing/MPointingPos.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mpointing/MPointingPos.h	(revision 3666)
@@ -15,13 +15,13 @@
     Double_t fAz;  // [deg] Azimuth
 
-    Double_t fRa;  // [rad] Right ascension
-    Double_t fHa;  // [rad] Hour angle
-    Double_t fDec; // [rad] Declination
+    Double_t fRa;  // [h]   Right ascension
+    Double_t fHa;  // [h]   Hour angle
+    Double_t fDec; // [deg] Declination
 
 public:
-    MPointingPos()
+    MPointingPos(const char *name=0, const char *title=0)
     {
-        fName  = "MPointingPos";
-        fTitle = "Container storing the (corrected) telescope pointing position";
+        fName  = name ? name   : "MPointingPos";
+        fTitle = title ? title : "Container storing the (corrected) telescope pointing position";
     }
 
@@ -35,6 +35,13 @@
     Double_t GetDec() const { return fDec; }
 
+    Double_t GetRaRad() const  { return fRa*TMath::DegToRad()*15; }
+    Double_t GetDecRad() const { return fDec*TMath::DegToRad(); }
+
     Double_t RotationAngle(const MObservatory &o) const;
     Double_t RotationAngle(const MObservatory &o, const MTime &t) const;
+    Double_t RotationAngle(const MObservatory &o, const MTime *t) const
+    {
+        return t ? RotationAngle(o, *t) : RotationAngle(o);
+    }
 
     ClassDef(MPointingPos, 1) //Container storing the (corrected) telescope pointing position
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 3665)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc	(revision 3666)
@@ -46,4 +46,7 @@
 // To be done:
 //   - wobble mode missing
+//   - a switch between using sky-coordinates and time or local-coordinates
+//     from MPointingPos for determin the rotation angle
+//   - the center of rotation need not to be the camera center
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -101,4 +104,11 @@
     {
         *fLog << err << "MObservatory not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fTime = (MTime*)pList->FindObject("MTime");
+    if (!fTime)
+    {
+        *fLog << err << "MTime not found... aborting." << endl;
         return kFALSE;
     }
@@ -166,10 +176,10 @@
         return kTRUE;
 
+    // rotate the source position by the current rotation angle
+    const Double_t rho = fPointPos->RotationAngle(*fObservatory, *fTime);
+
     // Define source position in the camera plain
     TVector2 v(fX, fY);
-
-    // rotate the source position by the current rotation angle
-    const Double_t rho = fPointPos->RotationAngle(*fObservatory);
-    v=v.Rotate(-rho);
+    v=v.Rotate(rho);
 
     // Convert coordinates into camera plain (mm)
Index: trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 3665)
+++ trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.h	(revision 3666)
@@ -10,4 +10,5 @@
 class MSrcPosCam;
 class MGeomCam;
+class MTime;
 
 class MSrcPosCalc : public MTask
@@ -18,4 +19,5 @@
     MSrcPosCam   *fSrcPos;
     MGeomCam     *fGeom;
+    MTime        *fTime;
 
     Double_t fR;    // Distance of source to a fitted star
@@ -32,4 +34,5 @@
     MSrcPosCalc(const char *name=NULL, const char *title=NULL);
 
+    // Use is deprecated!
     void SetOffset(Double_t r, Double_t drho)
     {
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcConfigRunHeader.h
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcConfigRunHeader.h	(revision 3665)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcConfigRunHeader.h	(revision 3666)
@@ -94,4 +94,6 @@
     MGeomMirror &GetMirror(int i) const { return *(MGeomMirror*)(fMirrors->UncheckedAt(i)); }
 
+    TClonesArray *GetMirrors() { return fMirrors; }
+
     MGeomPMT &GetPMT(int i)  { return *(MGeomPMT*)(fPMTs->UncheckedAt(i)); }
     MGeomPMT &GetPMT(int i) const { return *(MGeomPMT*)(fPMTs->UncheckedAt(i)); }
