Index: trunk/MagicSoft/Mars/mbase/MStatusArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusArray.cc	(revision 9518)
+++ trunk/MagicSoft/Mars/mbase/MStatusArray.cc	(revision 9519)
@@ -72,4 +72,89 @@
 // --------------------------------------------------------------------------
 //
+// Remove objects matching the id (the first character of their class
+// name) recuresively
+//
+void MStatusArray::RecursiveDelete(TVirtualPad *p, const char id) const
+{
+    if (!p)
+        return;
+
+    TIter Next2(p->GetListOfPrimitives());
+    TObject *o=0;
+    while ((o=Next2()))
+    {
+        if (!dynamic_cast<TVirtualPad*>(o) && (o->ClassName()[0]==id || id==0))
+            delete p->GetListOfPrimitives()->Remove(o);
+        else
+            RecursiveDelete(dynamic_cast<TVirtualPad*>(o), id);
+    }
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Make sure to set the kMustCleanup for all object in our tree
+// which will later be deleted when the array is destructed.
+//
+void MStatusArray::SetCleanup(TObject *obj) const
+{
+    if (!obj)
+        return;
+
+    TVirtualPad *pad = dynamic_cast<TVirtualPad*>(obj);
+
+    // Do not set the bit for pads because it would end in
+    // endless recursions
+    if (pad && !dynamic_cast<TCanvas*>(obj))
+        obj->ResetBit(kMustCleanup);
+    else
+        obj->SetBit(kMustCleanup);
+
+    if (!pad)
+        return;
+
+    TIter Next(pad->GetListOfPrimitives());
+    TObject *o=0;
+    while ((o=Next()))
+        SetCleanup(o);
+}
+
+// --------------------------------------------------------------------------
+//
+// Try to do a delete of the whole list in a way which is less vulnarable
+// to double deletion due to wrongly set bits or other things
+//
+void MStatusArray::Delete(Option_t *)
+{
+    // Add this to the list of cleanups to ensure as many cleaning
+    // operations as possible are propagated
+    gROOT->GetListOfCleanups()->Add(this);
+
+    // First make sure that all kMustCleanup bits are se
+    TIter Next(this);
+    TObject *o=0;
+    while ((o=Next()))
+        SetCleanup(o);
+
+    // Now delete the MARS object first because we have full control
+    // of them
+    TIter Next2(this);
+    while ((o=Next2()))
+        RecursiveDelete(dynamic_cast<TVirtualPad*>(o), 'M');
+
+    // Now delete all root objects
+    TIter Next3(this);
+    while ((o=Next3()))
+        RecursiveDelete(dynamic_cast<TVirtualPad*>(o));
+
+    // And delete all the rest
+    TObjArray::Delete();
+
+    // Remove it from the list again
+    gROOT->GetListOfCleanups()->Remove(this);
+}
+
+// --------------------------------------------------------------------------
+//
 // If o==NULL a new status display is created, otherwise the one with name o
 // is searched in gROOT->GetListOfSpecials().
@@ -335,4 +420,19 @@
 }
 
+MStatusArray::~MStatusArray()
+{
+    // This is the destructor from TObjArray...
+    // It must be here, because for some reason I don't know it
+    // is otherwise not correctly executed from the Interpreter
+    // (root 5.12/00f)
+    if (IsOwner())
+        Delete();
+
+    TStorage::Dealloc(fCont);
+
+    fCont = 0;
+    fSize = 0;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -344,4 +444,6 @@
     // It seems that the contents are not properly deleted by TObjArray::Read
     Delete();
+
+    SetOwner();
 
     const TString keyname = name?name:"MStatusDisplay";
@@ -372,5 +474,5 @@
             TObject *o2=0;
             while ((o2=Next2()))
-                if (o2->InheritsFrom("MParContainer"))
+                if (o2->InheritsFrom(MParContainer::Class()))
                     o2->SetBit(kCanDelete);
         }
Index: trunk/MagicSoft/Mars/mbase/MStatusArray.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusArray.h	(revision 9518)
+++ trunk/MagicSoft/Mars/mbase/MStatusArray.h	(revision 9519)
@@ -19,4 +19,7 @@
     };
 
+    void     SetCleanup(TObject *obj) const;
+    void     RecursiveDelete(TVirtualPad *p, const char id=0) const;
+
     void     SetCanDelete(const TCollection *list) const;
     void     SetMyCanDelete(const TCollection *list) const;
@@ -28,4 +31,5 @@
     MStatusArray() : TObjArray() { }
     MStatusArray(const MStatusDisplay &d);
+    ~MStatusArray();
 
     TObject *DisplayIn(Option_t *o=0) const;         // *MENU*
@@ -56,4 +60,5 @@
 
     void EnableTH1Workaround(const TCollection *list=0) const;
+    void Delete(Option_t *option="");
 
     ClassDef(MStatusArray, 0) // Helper class for status display
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9518)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9519)
@@ -38,5 +38,5 @@
     }
 
-    void SetD(Float_t d=1) { fD=d; fA=d*d*gsTan60/2; }
+    void SetD(Float_t d=1) { fD=d; fA=d*d*gsSin60; }
     void SetPhi(Double_t phi=0);
 
@@ -45,6 +45,6 @@
     Float_t GetT() const  { return fD/gsTan60; } // Distance between two opposite edges (traverse)
 
-    Float_t GetDx() const { return fD; }           // Distance of two rows in x-direction (without rotation)
-    Float_t GetDy() const { return fD*gsTan60/2; } // Distance of two rows in y-direction (without rotation)
+    Float_t GetDx() const { return fD; }         // Distance of two rows in x-direction (without rotation)
+    Float_t GetDy() const { return fD*gsSin60; } // Distance of two rows in y-direction (without rotation)
 
     Bool_t  IsInside(Float_t px, Float_t py) const;
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 9518)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 9519)
@@ -6,6 +6,6 @@
 #
 ##################################################################
+include ../Makefile.conf.general
 include ../Makefile.conf.$(OSTYPE)
-include ../Makefile.conf.general
 
 #------------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 9518)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 9519)
@@ -126,5 +126,5 @@
 //
 MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
-    : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kTRUE), fIsMovieMode(kFALSE)
+    : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kTRUE), fIsMovieMode(kFALSE), fIsTestMode(kFALSE)
 {
     fName  = name  ? name  : "MJCalibrateSignal";
@@ -263,5 +263,5 @@
     if (fSequence.IsValid())
     {
-        if (fSequence.GetRuns(iter, MSequence::kRawDat)<=0)
+        if (fSequence.GetRuns(iter, fIsTestMode?MSequence::kRawCal:MSequence::kRawDat)<=0)
             return kFALSE;
     }
@@ -383,5 +383,5 @@
     read->AddFiles(iter);
 
-    const TString fname(Form("s/(([0-9]+_)?(M[12]_)?[0-9.]+)_D_(.*[.])(raw|raw[.]gz|root)$/%s\\/$1_Y_$4root/",
+    const TString fname(Form("s/(([0-9]+_)?(M[12]_)?[0-9.]+)_[CD]_(.*[.])(raw|raw[.]gz|root)$/%s\\/$1_Y_$4root/",
                              Esc(fPathOut).Data()));
 
@@ -460,4 +460,6 @@
     fcalped.AllowTriggerLvl2();
     fcalped.AllowSumTrigger();
+    if (fIsTestMode)
+        fcalped.AllowCalibration();
 
     // This will skip interleaved events with a cal- or ped-trigger
@@ -810,5 +812,5 @@
 
     //MFDataPhrase filcalco("MCalibrationConstCam.IsReadyToSave>0.5", "CalibConstFilter");
-    if (fIsInterlaced)
+    if (fIsInterlaced && !fIsTestMode)
     {
         // The task list is executed for all events with the calibration
@@ -867,5 +869,6 @@
     // Check if we have an extremely bright event (remove them,
     // they are presumably errornous events or calibration events)
-    tlist2.AddToList(&contbright);
+    if (!fIsTestMode)
+        tlist2.AddToList(&contbright);
 
     /*
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 9518)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 9519)
@@ -25,4 +25,5 @@
     Bool_t fIsRelTimesUpdate;           // Choose to update relative times from interlaced
     Bool_t fIsMovieMode;                // Choose to encode a movie
+    Bool_t fIsTestMode;                 // Testmode to calibrate the cal run
 
     Bool_t CheckEnvLocal();
@@ -46,4 +47,5 @@
     void SetRelTimesUpdate(const Bool_t b=kTRUE) { fIsRelTimesUpdate = b; }
     void SetMovieMode     (const Bool_t b=kTRUE) { fIsMovieMode      = b; }
+    void SetTestMode      (const Bool_t b=kTRUE) { fIsTestMode       = b; }
 
     void SetExtractor(const MExtractor *ext=NULL);
Index: trunk/MagicSoft/Mars/mjtrain/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mjtrain/Makefile	(revision 9518)
+++ trunk/MagicSoft/Mars/mjtrain/Makefile	(revision 9519)
@@ -6,6 +6,6 @@
 #
 ##################################################################
+include ../Makefile.conf.general
 include ../Makefile.conf.$(OSTYPE)
-include ../Makefile.conf.general
 
 #------------------------------------------------------------------------------
