Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1902)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1910)
@@ -19,5 +19,5 @@
 !   Author(s): Abelardo Moralejo <mailto:moralejo@pd.infn.it>
 !
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -51,11 +51,11 @@
 //    - blue cross: minimum of distance to (0, 1)
 //
+// As a default MHHadronness searches for the container "MHadronness".
+// This can be overwritten by a different pointer specified in the
+// Fill function (No type check is done!) Use a different name in
+// MFillH.
+//
 ////////////////////////////////////////////////////////////////////////////
 #include "MHHadronness.h"
-
-/*
- // - blue:  2D distance of (acceptance_hadrons, acceptances_gammas)
- //          to optimum (0, 1):  1-sqrt(Ag*Ag + (1-Ah)*(1-Ah))
- */
 
 #include <TPad.h>
@@ -107,22 +107,9 @@
     fIntPhness->SetYTitle("Acceptance");
 
-    /*
-    fQfac = new TH1D("Qfac", "Naive Quality factor", nbins, 0, 1);
-    fQfac->SetXTitle("Hadronness");
-    fQfac->SetYTitle("Quality");
-    */
     fQfac = new TGraph;
     fQfac->SetTitle(" Naive Quality factor ");
 
-    /*
-     fMinDist = new TH1D("MinDist", "Minimum Dist to (0, 1)", nbins, 0, 1);
-     fMinDist->SetXTitle("Hadronness");
-     fMinDist->SetYTitle("Distance");
-     */
-
-    //fQfac->SetDirectory(NULL);
     fGhness->SetDirectory(NULL);
     fPhness->SetDirectory(NULL);
-    //fMinDist->SetDirectory(NULL);
     fIntGhness->SetDirectory(NULL);
     fIntPhness->SetDirectory(NULL);
@@ -140,5 +127,4 @@
     delete fIntPhness;
     delete fQfac;
-    //    delete fMinDist;
     delete fGraph;
 }
@@ -159,9 +145,4 @@
 
     fHadronness = (MHadronness*)plist->FindObject("MHadronness");
-    if (!fHadronness)
-    {
-        *fLog << err << dbginf << "MHadronness not found... aborting." << endl;
-        return kFALSE;
-    }
 
     /*
@@ -186,4 +167,10 @@
 // histogram dependant on the particle id.
 //
+// Every particle Id different than kGAMMA is considered a hadron.
+//
+// If you call Fill with a pointer (eg. from MFillH) this container is
+// used as a hadronness (Warning: No type check is done!) otherwise
+// the default is used ("MHadronness")
+//
 // Sometimes a distance is calculated as NaN (not a number). Such events
 // are skipped at the moment.
@@ -192,6 +179,13 @@
 {
     // Preliminary Workaround: FIXME!
-
-    const Double_t h = fHadronness->GetHadronness();
+    if (!par && !fHadronness)
+    {
+        *fLog << err << "MHHadronness::Fill: No MHadronness container specified!" << endl;
+        return kFALSE;
+    }
+
+    const MHadronness &had = par ? *(MHadronness*)par : *fHadronness;
+
+    const Double_t h = had.GetHadronness();
 
     if (TMath::IsNaN(h))
@@ -235,11 +229,5 @@
     }
 
-    Float_t retValue;
-    if (val2x-val1x != 0.0)
-      retValue = val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
-    else
-      retValue = 0.0;
-
-    return retValue;
+    return val2x-val1x == 0 ? 0 : val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
 }
 
@@ -258,57 +246,28 @@
     fQfac->Set(n);
 
-    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;
-    }
+    const Stat_t sumg = fGhness->Integral();
+    const Stat_t sump = fPhness->Integral();
+
+    *fLog << inf << "MHHadronness::Finalize - Sum Hadronness: gammas=" << sumg << " hadrons=" << sump << endl;
+
+    if (sumg==0 || sump==0)
+        *fLog << warn << "MHHadronness::Finalize: 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);       
-      }
+    if (sumg>0)
+        fGhness->Scale(1./sumg);
 
     // Normalize hadron distribution
-    if (sump > 0.0)
-      for (Int_t i=1; i<=n; i++)
-      {
-	con = (fPhness->GetBinContent(i)) / sump;
-        fPhness->SetBinContent(i, con);       
-      }
+    if (sump>0)
+        fGhness->Scale(1./sump);
 
     // Calculate acceptances
-    sumg = fGhness->Integral(1, n);
-    sump = fPhness->Integral(1, n);
-
-    *fLog << "MHHadronness::Finalize; sumg, sump = " << sumg << ",  "
-          << sump << endl;
-
     Float_t max=0;
 
     for (Int_t i=1; i<=n; i++)
     {
-        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;
+        const Stat_t ip = sump!=0 ? fPhness->Integral(1, i)/sump : 0;
+        const Stat_t ig = sumg!=0 ? fGhness->Integral(1, i)/sumg : 0;
 
         fIntPhness->SetBinContent(i, ip);
@@ -319,6 +278,4 @@
         if (ip<=0)
             continue;
-
-        //fMinDist->SetBinContent(i, 1-sqrt(ip*ip + (ig-1)*(ig-1)));
 
         const Double_t val = ig/sqrt(ip);
@@ -432,11 +389,4 @@
     *fLog << endl;
 
-    /*
-     const Int_t h = fMinDist->GetMaximumBin();
-     *fLog << "Minimum Distance to (0, 1): " << Form("%.2f", 1-fMinDist->GetMaximum()) << " @ H=" << fMinDist->GetBinCenter(h) << endl;
-     *fLog << "  Acc Gammas = " << Form("%3.0f", fIntGhness->GetBinContent(h)*100) << "%, ";
-     *fLog << "Acc Hadrons = " << Form("%3.0f", fIntPhness->GetBinContent(h)*100) << "%" << endl;
-     */
-
     *fLog << "Q-Factor @ Acc Gammas=0.5: Q(0.5)=" << Form("%.1f", GetQ05()) << endl;
     *fLog << "  Acc Hadrons = " << Form("%5.1f", GetHadronAcceptance(0.5)*100) << "%" << endl;
@@ -463,4 +413,5 @@
     Getphness()->SetLineColor(kRed);
     Getphness()->DrawCopy("same");
+
     c.cd(2);
     //gStyle->SetOptStat(0);
@@ -468,10 +419,6 @@
     Getiphness()->SetLineColor(kRed);
     Getiphness()->DrawCopy("same");
-    /*
-     fMinDist->SetLineColor(kBlue);
-     fMinDist->DrawCopy("same");
-     */
+
     c.cd(3);
-    //GetQfac()->DrawCopy();
     TGraph &g2 = (TGraph&)*fQfac->DrawClone("A*");
     g2.SetBit(kCanDelete);
@@ -489,4 +436,5 @@
         gPad->Update();
     }
+
     c.cd(4);
     gPad->Modified();
@@ -537,4 +485,5 @@
     Getphness()->SetLineColor(kRed);
     Getphness()->Draw("same");
+
     gPad->cd(2);
     //gStyle->SetOptStat(0);
@@ -542,10 +491,6 @@
     Getiphness()->SetLineColor(kRed);
     Getiphness()->Draw("same");
-    /*
-     fMinDist->SetLineColor(kBlue);
-     fMinDist->Draw("same");
-     */
+
     gPad->cd(3);
-    //GetQfac()->Draw();
     fQfac->Draw("A*");
     gPad->Modified();
@@ -578,11 +523,3 @@
         gPad->Update();
     }
-    /*
-    const Int_t h = fMinDist->GetMaximumBin();
-    TMarker *m = new TMarker(fIntPhness->GetBinContent(h),
-                             fIntGhness->GetBinContent(h), kStar);
-    m->SetMarkerColor(kBlue);
-    m->SetBit(kCanDelete);
-    m->Draw();
-    */
-}
+}
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1902)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1910)
@@ -22,5 +22,4 @@
     TH1D* fIntPhness; //-> Hadrons Acceptance
     TH1D* fIntGhness; //-> Gammas  Acceptance
-    //TH1D* fMinDist; //-> Minimum Distance to optimum acceptance
 
     TGraph *fQfac;    //-> Quality factor
