Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MH.cc	(revision 2296)
@@ -796,10 +796,12 @@
 // Otherwise the present gPad is returned.
 //
-TVirtualPad *MH::GetNewPad(Option_t *opt)
-{
-    TString str(opt);
-
-    if (!str.Contains("nonew", TString::kIgnoreCase))
+TVirtualPad *MH::GetNewPad(TString &opt)
+{
+    opt.ToLower();
+
+    if (!opt.Contains("nonew"))
         return NULL;
+
+    opt.ReplaceAll("nonew", "");
 
     return gPad;
@@ -813,9 +815,8 @@
 TObject *MH::Clone(const char *name) const
 {
-    Bool_t store = TH1::AddDirectoryStatus();
+    const Bool_t store = TH1::AddDirectoryStatus();
+
     TH1::AddDirectory(kFALSE);
-
     TObject *o = MParContainer::Clone(name);
-
     TH1::AddDirectory(store);
 
@@ -831,5 +832,7 @@
 TObject *MH::DrawClone(Option_t *opt, Int_t w, Int_t h) const
 {
-    TVirtualPad *p = GetNewPad(opt);
+    TString option(opt);
+
+    TVirtualPad *p = GetNewPad(option);
     if (!p)
         p = MakeDefCanvas(this, w, h);
@@ -839,5 +842,5 @@
     gROOT->SetSelectedPad(NULL);
 
-    TObject *o = MParContainer::DrawClone(opt);
+    TObject *o = MParContainer::DrawClone(option);
     o->SetBit(kCanDelete);
     return o;
Index: trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.h	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MH.h	(revision 2296)
@@ -75,5 +75,5 @@
     }
 
-    static TVirtualPad *GetNewPad(Option_t *opt);
+    static TVirtualPad *GetNewPad(TString &opt);
 
     static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 2296)
@@ -430,4 +430,17 @@
 // --------------------------------------------------------------------------
 //
+// Search the hadronness corresponding to a given hadron acceptance.
+//
+Double_t MHHadronness::GetHadronness(Double_t acchad) const
+{
+    for (int i=1; i<fIntPhness->GetNbinsX()+1; i++)
+        if (fIntPhness->GetBinContent(i)>acchad)
+            return fIntPhness->GetBinLowEdge(i);
+
+    return -1;
+}
+
+// --------------------------------------------------------------------------
+//
 // Print the corresponding Gammas Acceptance for a hadron acceptance of
 // 10%, 20%, 30%, 40% and 50%. Also the minimum distance to the optimum
@@ -448,12 +461,12 @@
 
     *fLog << "Used " << fGhness->GetEntries() << " Gammas and " << fPhness->GetEntries() << " Hadrons." << endl;
-    *fLog << "acc(hadron)  acc(gamma)  acc(g)/acc(h)" << endl <<endl;
-
-    *fLog << "    0.005    " << Form("%6.3f", GetGammaAcceptance(0.005)) << "    " << Form("%6.3f", GetGammaAcceptance(0.005)/0.005) << endl;
-    *fLog << "    0.02     " << Form("%6.3f", GetGammaAcceptance(0.02))  << "    " << Form("%6.3f", GetGammaAcceptance(0.02)/0.02) << endl;
-    *fLog << "    0.05     " << Form("%6.3f", GetGammaAcceptance(0.05))  << "    " << Form("%6.3f", GetGammaAcceptance(0.05)/0.05) << endl;
-    *fLog << "    0.1      " << Form("%6.3f", GetGammaAcceptance(0.1 ))  << "    " << Form("%6.3f", GetGammaAcceptance(0.1)/0.1) << endl;
-    *fLog << "    0.2      " << Form("%6.3f", GetGammaAcceptance(0.2 ))  << "    " << Form("%6.3f", GetGammaAcceptance(0.2)/0.2) << endl;
-    *fLog << "    0.3      " << Form("%6.3f", GetGammaAcceptance(0.3 ))  << "    " << Form("%6.3f", GetGammaAcceptance(0.3)/0.3) << endl;
+    *fLog << "acc(hadron) acc(gamma) acc(g)/acc(h)  h" << endl <<endl;
+
+    *fLog << "    0.005    " << Form("%6.3f", GetGammaAcceptance(0.005)) << "      " << Form("%6.3f", GetGammaAcceptance(0.005)/0.005) << "      " << GetHadronness(0.005) << endl;
+    *fLog << "    0.02     " << Form("%6.3f", GetGammaAcceptance(0.02))  << "      " << Form("%6.3f", GetGammaAcceptance(0.02)/0.02)   << "      " << GetHadronness(0.02) << endl;
+    *fLog << "    0.05     " << Form("%6.3f", GetGammaAcceptance(0.05))  << "      " << Form("%6.3f", GetGammaAcceptance(0.05)/0.05)   << "      " << GetHadronness(0.05) << endl;
+    *fLog << "    0.1      " << Form("%6.3f", GetGammaAcceptance(0.1 ))  << "      " << Form("%6.3f", GetGammaAcceptance(0.1)/0.1)     << "      " << GetHadronness(0.1) << endl;
+    *fLog << "    0.2      " << Form("%6.3f", GetGammaAcceptance(0.2 ))  << "      " << Form("%6.3f", GetGammaAcceptance(0.2)/0.2)     << "      " << GetHadronness(0.2) << endl;
+    *fLog << "    0.3      " << Form("%6.3f", GetGammaAcceptance(0.3 ))  << "      " << Form("%6.3f", GetGammaAcceptance(0.3)/0.3)     << "      " << GetHadronness(0.3) << endl;
     *fLog << Form("%6.3f", GetHadronAcceptance(0.1)) << "        0.1  " << endl;
     *fLog << Form("%6.3f", GetHadronAcceptance(0.2)) << "        0.2  " << endl;
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 2296)
@@ -38,4 +38,5 @@
     Double_t GetGammaAcceptance(Double_t acchad) const;
     Double_t GetHadronAcceptance(Double_t accgam) const;
+    Double_t GetHadronness(Double_t acchad) const;
 
     TH1D *Getghness() const  { return fGhness; }
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 2296)
@@ -260,4 +260,5 @@
     return kTRUE;
 }
+
 /*
 // --------------------------------------------------------------------------
@@ -503,4 +504,10 @@
     if (!fM2.IsValid())
     {
+        if (!fM.IsValid())
+        {
+            *fLog << err << "MHMatrix::CalcDist - ERROR: fM not valid." << endl;
+            return -1;
+        }
+
         const TMatrix *m = InvertPosDef();
         if (!m)
@@ -625,13 +632,13 @@
     tlist.AddToList(&fillh);
 
-    MProgressBar bar;
+    //MProgressBar bar;
     MEvtLoop evtloop;
     evtloop.SetParList(plist);
-    evtloop.SetProgressBar(&bar);
+    //evtloop.SetProgressBar(&bar);
 
     if (!evtloop.Eventloop())
         return kFALSE;
 
-    tlist.PrintStatistics(0, kTRUE);
+    tlist.PrintStatistics();
 
     plist->Remove(&tlist);
@@ -1097,19 +1104,33 @@
 void MHMatrix::ShuffleRows(UInt_t seed)
 {
-  TRandom rnd(seed);
-
-  for (Int_t irow = 0; irow < fNumRow; irow++)
-    {
-      Int_t jrow = rnd.Integer(fNumRow);
-
-      for (Int_t icol = 0; icol < fM.GetNcols(); icol++)
-	{
-	  Real_t tmp = fM(irow,icol);
-	  fM(irow,icol) = fM(jrow,icol);
-	  fM(jrow,icol) = tmp;
-	}
-    }
-
-  *fLog << warn << this->GetName() << " : Attention! Matrix rows have been shuffled." << endl;
-
-}
+    TRandom rnd(seed);
+
+    TVector v(fM.GetNcols());
+    TVector tmp(fM.GetNcols());
+    for (Int_t irow = 0; irow<fNumRow; irow++)
+    {
+        const Int_t jrow = rnd.Integer(fNumRow);
+
+        v = TMatrixRow(fM, irow);
+        TMatrixRow(fM, irow) = tmp = TMatrixRow(fM, jrow);
+        TMatrixRow(fM, jrow) = v;
+    }
+
+    *fLog << warn << GetDescriptor() << ": Attention! Matrix rows have been shuffled." << endl;
+}
+
+void MHMatrix::ReduceRows(UInt_t num)
+{
+    if ((Int_t)num>=fM.GetNrows())
+    {
+        *fLog << warn << GetDescriptor() << ": Warning - " << num << " >= rows=" << fM.GetNrows() << endl;
+        return;
+    }
+
+    const TMatrix m(fM);
+    fM.ResizeTo(num, fM.GetNcols());
+
+    TVector tmp(fM.GetNcols());
+    for (UInt_t irow=0; irow<num; irow++)
+        TMatrixRow(fM, irow) = tmp = TMatrixRow(m, irow);
+}
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 2282)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 2296)
@@ -113,4 +113,5 @@
 
     void ShuffleRows(UInt_t seed);
+    void ReduceRows(UInt_t num);
 
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
