Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2327)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2328)
@@ -1120,4 +1120,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Reduces the number of rows to the given number num by cutting out the
+// last rows.
+//
 void MHMatrix::ReduceRows(UInt_t num)
 {
@@ -1135,2 +1140,37 @@
         TMatrixRow(fM, irow) = tmp = TMatrixRow(m, irow);
 }
+
+// --------------------------------------------------------------------------
+//
+// Remove rows which contains numbers not fullfilling TMath::Finite
+//
+Bool_t MHMatrix::RemoveInvalidRows()
+{
+    TMatrix m(fM);
+
+    const Int_t ncol=fM.GetNcols();
+    TVector vold(ncol);
+    int irow=0;
+
+    for (int i=0; i<m.GetNrows(); i++)
+    {
+        const TMatrixRow &row = TMatrixRow(m, i);
+
+        // finite (-> math.h) checks for NaN as well as inf
+        int jcol;
+        for (jcol=0; jcol<ncol; jcol++)
+            if (!TMath::Finite(vold(jcol)))
+                break;
+
+        if (jcol==ncol)
+            TMatrixRow(fM, irow++) = vold = row;
+        else
+            *fLog << warn << "Warning - MHMatrix::RemoveInvalidRows: row #" << i<< " removed." << endl;
+    }
+
+    // Do not use ResizeTo (in older root versions this doesn't save the contents
+    ReduceRows(irow);
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 2327)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 2328)
@@ -103,4 +103,5 @@
 
     void ReduceNumberOfRows(UInt_t numrows, const TString opt);
+    Bool_t RemoveInvalidRows();
 
     Int_t Read(const char *name);
