Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1800)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1809)
@@ -235,5 +235,11 @@
     }
 
-    return val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
+    Float_t retValue;
+    if (val2x-val1x != 0.0)
+      retValue = val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
+    else
+      retValue = 0.0;
+
+    return retValue;
 }
 
@@ -252,6 +258,41 @@
     fQfac->Set(n);
 
-    const Stat_t sumg = fGhness->Integral(1, n+1);
-    const Stat_t sump = fPhness->Integral(1, n+1);
+    Stat_t sumg;
+    Stat_t sump;
+
+    sumg = fGhness->Integral(1, n);
+    sump = fPhness->Integral(1, n);
+
+    if (sumg == 0.0  ||  sump == 0.0)
+    {
+      *fLog << "MHHadronness::Finalize; sumg or sump is zero;   sumg, sump = "
+            << sumg << ",  " << sump << ".  Cannot calculate hadronness" 
+            << endl;
+    }
+
+
+    // Normalize photon distribution
+    Stat_t con;
+    if (sumg > 0.0)
+      for (Int_t i=1; i<=n; i++)
+      {
+	con = (fGhness->GetBinContent(i)) / sumg;
+        fGhness->SetBinContent(i, con);       
+      }
+
+    // Normalize hadron distribution
+    if (sump > 0.0)
+      for (Int_t i=1; i<=n; i++)
+      {
+	con = (fPhness->GetBinContent(i)) / sump;
+        fPhness->SetBinContent(i, con);       
+      }
+
+    // Calculate acceptances
+    sumg = fGhness->Integral(1, n);
+    sump = fPhness->Integral(1, n);
+
+    *fLog << "MHHadronness::Finalize; sumg, sump = " << sumg << ",  "
+          << sump << endl;
 
     Float_t max=0;
@@ -259,6 +300,15 @@
     for (Int_t i=1; i<=n; i++)
     {
-        const Stat_t ip = fPhness->Integral(1, i)/sump;
-        const Stat_t ig = fGhness->Integral(1, i)/sumg;
+        Stat_t ip; 
+        if (sump != 0.0)
+          ip = fPhness->Integral(1, i)/sump;
+        else
+          ip = 0;
+
+        Stat_t ig;
+        if (sumg != 0.0)
+          ig = fGhness->Integral(1, i)/sumg;
+        else
+          ig = 0;
 
         fIntPhness->SetBinContent(i, ip);
@@ -409,10 +459,10 @@
 
     c.cd(1);
-    gStyle->SetOptStat(10);
+    //gStyle->SetOptStat(10);
     Getghness()->DrawCopy();
     Getphness()->SetLineColor(kRed);
     Getphness()->DrawCopy("same");
     c.cd(2);
-    gStyle->SetOptStat(0);
+    //gStyle->SetOptStat(0);
     Getighness()->DrawCopy();
     Getiphness()->SetLineColor(kRed);
@@ -483,10 +533,10 @@
 
     gPad->cd(1);
-    gStyle->SetOptStat(10);
+    //gStyle->SetOptStat(10);
     Getghness()->Draw();
     Getphness()->SetLineColor(kRed);
     Getphness()->Draw("same");
     gPad->cd(2);
-    gStyle->SetOptStat(0);
+    //gStyle->SetOptStat(0);
     Getighness()->Draw();
     Getiphness()->SetLineColor(kRed);
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1800)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1809)
@@ -504,4 +504,6 @@
 }
 
+// --------------------------------------------------------------------------
+//
 void MHMatrix::Reassign()
 {
@@ -691,6 +693,6 @@
 //
 // Define the reference matrix
-//   refcolumn  number of the column containing the variable, for which a
-//              target distribution may be given;
+//   refcolumn  number of the column (starting at 1)containing the variable, 
+//              for which a target distribution may be given;
 //              if refcolumn is negative the target distribution will be set 
 //              equal to the real distribution; the events in the reference
@@ -748,14 +750,15 @@
    //---------------------------------------------------------
    //
-   // if refcol < 0 : select reference events randomly
-   //                 i.e. set the normaliztion factotrs equal to 1.0
+   // if refcolumn < 0 : select reference events randomly
+   //                    i.e. set the normaliztion factotrs equal to 1.0
+   // refcol is the column number starting at 0; it is >= 0 
 
    if (refcolumn<0) 
    {
-     frefcol = -refcolumn;
+     frefcol = -refcolumn - 1;
    }
    else
    {
-     frefcol = refcolumn;
+     frefcol =  refcolumn - 1;
    }
    
@@ -790,15 +793,4 @@
      //      << ",  " << fM(j-1,frefcol) << endl;
    }
-
-   // if refcolumn<0 set target distribution equal to the real distribution
-   // in order to obtain normalization factors = 1.0
-   //if (refcolumn<0) 
-   //{
-   //  for (Int_t j=1; j<=fnbins; j++) 
-   //  {
-   //    float cont = fHth-> GetBinContent(j);
-   //    fHthsh->SetBinContent(j, cont);
-   //  }
-   //}
 
    //---------------------------------------------------------
@@ -816,5 +808,5 @@
 
      // if refcolumn < 0 set the correction factors equal to 1
-     if ( refcolumn>=0.0 )
+     if ( refcolumn>=0 )
        b = fHthsh->GetBinContent(j);
      else
@@ -948,5 +940,5 @@
    {
      *fLog <<ir <<" ";
-     for (Int_t ic=0;ic<13;ic++) cout<<Mnew(ir,ic)<<" ";
+     for (Int_t ic=0; ic<Mnew.GetNcols(); ic++) cout<<Mnew(ir,ic)<<" ";
      *fLog <<endl;
    }
@@ -957,5 +949,5 @@
    {
      float a = fHthaft->GetBinContent(j);
-     if (a>0) *fLog << j << "  "<< a << "   ";
+     *fLog << j << "  "<< a << "   ";
    }
    *fLog <<endl;
@@ -967,21 +959,16 @@
 
    th1->cd(1);
-   ((TH1F*)fHthsh)->Draw();      // target
+   ((TH1F*)fHthsh)->DrawCopy();      // target
 
    th1->cd(2);
-   ((TH1F*)fHth)->Draw();        // real histogram before
+   ((TH1F*)fHth)->DrawCopy();        // real histogram before
 
    th1->cd(3);
-   ((TH1F*)fHthd) -> Draw();     // correction factors
+   ((TH1F*)fHthd)->DrawCopy();       // correction factors
 
    th1->cd(4);
-   ((TH1F*)fHthaft) -> Draw();   // histogram after
-
-   //---------------------------------------------------------
-   // --- write onto output file
-   //
-   //TFile *outfile = new TFile(fileNameout, "RECREATE", "");
-   //Mnew.Write(fileNameout);
-   //outfile->Close();
+   ((TH1F*)fHthaft)->DrawCopy();     // histogram after
+
+   //---------------------------------------------------------
 
    return kTRUE;
Index: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 1800)
+++ trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc	(revision 1809)
@@ -224,5 +224,5 @@
 TObject *MHSigmaTheta::DrawClone(Option_t *opt) 
 {
-    TCanvas &c = *MakeDefCanvas("SigmaTheta", "Sigmabar vs. Theta",
+    TCanvas &c = *MakeDefCanvas("SigmaThetaPlot", "Sigmabar vs. Theta",
                                  900, 900);
     c.Divide(3, 3);
@@ -236,9 +236,10 @@
     c.cd(1);
     h = ((TH2*)&fSigmaTheta)->ProjectionX("ProjX-Theta", -1, 9999, "E");
+    h->SetDirectory(NULL);
     h->SetTitle("Distribution of \\Theta");
     h->SetXTitle("\\Theta [\\circ]");
     h->SetYTitle("No.of events");
 
-    h->Draw(opt);
+    h->DrawCopy(opt);
     h->SetBit(kCanDelete);;
     gPad->SetLogy();
@@ -246,9 +247,10 @@
     c.cd(4);
     h = ((TH2*)&fSigmaTheta)->ProjectionY("ProjY-sigma", -1, 9999, "E");
+    h->SetDirectory(NULL);
     h->SetTitle("Distribution of Sigmabar");
     h->SetXTitle("Sigmabar");
     h->SetYTitle("No.of events");
 
-    h->Draw(opt);
+    h->DrawCopy(opt);
     h->SetBit(kCanDelete);;
 
@@ -263,18 +265,20 @@
     c.cd(2);
     l = (TH2D*) ((TH3*)&fDiffPixTheta)->Project3D("zx");
+    l->SetDirectory(NULL);
     l->SetTitle("Sigma^2-Sigmabar^2 vs. \\Theta (all pixels)");
     l->SetXTitle("\\Theta [\\circ]");
     l->SetYTitle("Sigma^2-Sigmabar^2");
 
-    l->Draw("box");
+    l->DrawCopy("box");
     l->SetBit(kCanDelete);;
 
     c.cd(5);
     l = (TH2D*) ((TH3*)&fDiffPixTheta)->Project3D("zy");
+    l->SetDirectory(NULL);
     l->SetTitle("Sigma^2-Sigmabar^2 vs. pixel number (all \\Theta)");
     l->SetXTitle("pixel");
     l->SetYTitle("Sigma^2-Sigmabar^2");
 
-    l->Draw("box");
+    l->DrawCopy("box");
     l->SetBit(kCanDelete);;
 
@@ -290,18 +294,20 @@
     c.cd(3);
     k = (TH2D*) ((TH3*)&fSigmaPixTheta)->Project3D("zx");
+    k->SetDirectory(NULL);
     k->SetTitle("Sigma vs. \\Theta (all pixels)");
     k->SetXTitle("\\Theta [\\circ]");
     k->SetYTitle("Sigma");
 
-    k->Draw("box");
+    k->DrawCopy("box");
     k->SetBit(kCanDelete);;
 
     c.cd(6);
     k = (TH2D*) ((TH3*)&fSigmaPixTheta)->Project3D("zy");
+    k->SetDirectory(NULL);
     k->SetTitle("Sigma vs. pixel number (all \\Theta)");
     k->SetXTitle("pixel");
     k->SetYTitle("Sigma");
 
-    k->Draw("box");
+    k->DrawCopy("box");
     k->SetBit(kCanDelete);;
 
