Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1828)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1829)
@@ -87,4 +87,15 @@
 // --------------------------------------------------------------------------
 //
+//  Default Constructor
+//
+MHMatrix::MHMatrix(const TMatrix &m, const char *name, const char *title)
+    : fNumRow(m.GetNrows()), fM(m), fData(NULL)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
 //  Constructor. Initializes the columns of the matrix with the entries
 //  from a MDataArray
@@ -689,5 +700,5 @@
 //
 Bool_t MHMatrix::DefRefMatrix(const UInt_t refcolumn, const TH1F &thsh,
-                              const Int_t nmaxevts, TMatrix *rest)
+                              Int_t nmaxevts, TMatrix *rest)
 {
     if (!fM.IsValid())
@@ -720,4 +731,7 @@
         return kFALSE;
     }
+
+    if (nmaxevts==0)
+        nmaxevts = fM.GetNrows();
 
     //
@@ -917,5 +931,5 @@
 //              are not interested in this
 //
-Bool_t MHMatrix::DefRefMatrix(const Int_t nmaxevts, TMatrix *rest)
+Bool_t MHMatrix::DefRefMatrix(Int_t nmaxevts, TMatrix *rest)
 {
     if (!fM.IsValid())
@@ -924,4 +938,19 @@
         return kFALSE;
     }
+
+    if (nmaxevts>fM.GetNrows())
+    {
+        *fLog << err << dbginf << "Number of maximum events exceeds number of events" << endl;
+        return kFALSE;
+    }
+
+    if (nmaxevts<0)
+    {
+        *fLog << err << dbginf << "Number of maximum events < 0" << endl;
+        return kFALSE;
+    }
+
+    if (nmaxevts==0)
+        nmaxevts = fM.GetNrows();
 
     const Int_t nrows = fM.GetNrows();
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1828)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1829)
@@ -55,4 +55,5 @@
     MHMatrix(const char *name=NULL, const char *title=NULL);
     MHMatrix(MDataArray *mat, const char *name=NULL, const char *title=NULL);
+    MHMatrix(const TMatrix &m, const char *name=NULL, const char *title=NULL);
     ~MHMatrix();
 
@@ -100,6 +101,6 @@
 
     Bool_t DefRefMatrix(const UInt_t refcolumn, const TH1F &thsh,
-                        const Int_t nmaxevts=0, TMatrix *mrest=NULL);
-    Bool_t DefRefMatrix(const Int_t nmaxevts=0, TMatrix *mrest=NULL);
+                        Int_t nmaxevts=0, TMatrix *mrest=NULL);
+    Bool_t DefRefMatrix(Int_t nmaxevts=0, TMatrix *mrest=NULL);
 
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
