Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 2222)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 2225)
@@ -56,4 +56,9 @@
 // MFillH.
 //
+// If you are using filtercuts which gives you only two discrete values
+// of the hadronness (0.25 and 0.75) you may want to use MHHadronness(2).
+// If you request Q05() from such a MHHadronness instance you will get
+// Acc_g/sqrt(Acc_h)
+//
 ////////////////////////////////////////////////////////////////////////////
 #include "MHHadronness.h"
@@ -65,11 +70,12 @@
 #include <TMarker.h>
 
+#include "MParList.h"
+#include "MBinning.h"
+#include "MHMatrix.h"
+#include "MHadronness.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
 
-#include "MParList.h"
-#include "MBinning.h"
-#include "MHadronness.h"
-
 #include "MMcEvt.hxx"
 
@@ -84,4 +90,5 @@
 //
 MHHadronness::MHHadronness(Int_t nbins, const char *name, const char *title)
+    : fMatrix(NULL)
 {
     //
@@ -95,16 +102,16 @@
     fGraph->SetMarkerStyle(kFullDotSmall);
 
-    fGhness = new TH1D("Ghness", "H. Gammas",  nbins, 0, 1);
-    fPhness = new TH1D("Phness", "H. Hadrons", nbins, 0, 1);
+    fGhness = new TH1D("Ghness", "Acceptance vs. Hadronness (Gammas)",  nbins, 0, 1);
+    fPhness = new TH1D("Phness", "Acceptance vs. Hadronness (Hadrons)", nbins, 0, 1);
     fGhness->SetXTitle("Hadronness");
     fPhness->SetXTitle("Hadronness");
-    fGhness->SetYTitle("Counts");
-    fPhness->SetYTitle("Counts");
+    fGhness->SetYTitle("Acceptance");
+    fPhness->SetYTitle("Acceptance");
     fPhness->SetLineColor(kRed);
     fGhness->SetDirectory(NULL);
     fPhness->SetDirectory(NULL);
     
-    fIntGhness = new TH1D("AccGammas",  "Acceptance", nbins, 0, 1);
-    fIntPhness = new TH1D("AccHadrons", "Acceptance", nbins, 0, 1);
+    fIntGhness = new TH1D("AccGammas",  "Integral Acceptance vs. Hadronness (Gammas)", nbins, 0, 1);
+    fIntPhness = new TH1D("AccHadrons", "Integral Acceptance vs. Hadronness (Hadrons)", nbins, 0, 1);
     fIntGhness->SetXTitle("Hadronness");
     fIntPhness->SetXTitle("Hadronness");
@@ -145,12 +152,18 @@
 Bool_t MHHadronness::SetupFill(const MParList *plist)
 {
-    fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
-    if (!fMcEvt)
-    {
-        *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
-        return kFALSE;
+    if (!fMatrix)
+    {
+        fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
+        if (!fMcEvt)
+        {
+            *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
+            return kFALSE;
+        }
     }
 
     fHadronness = (MHadronness*)plist->FindObject("MHadronness");
+
+    fGhness->Reset();
+    fPhness->Reset();
 
     /*
@@ -200,5 +213,7 @@
         return kCONTINUE;
 
-    if (fMcEvt->GetPartId()==kGAMMA)
+    const Int_t particleid = fMatrix ? (Int_t)(*fMatrix)[fMap] : fMcEvt->GetPartId();
+
+    if (particleid==kGAMMA)
         fGhness->Fill(h, w);
     else
@@ -208,7 +223,40 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Returns the quality factor at gamma acceptance 0.5.
+//
+// If the histogram containes only two bins we return the
+// naive quality: ag/sqrt(ah)
+// with ag the acceptance of gammas and ah the acceptance of hadrons.
+//
+// You can use this (nbins=2) in case of some kind of filter cuts giving
+// only a result: gamma yes/no (means discrete values of hadronness 0.25
+// or 0.75)
+//
+// FIXME: In the later case weights cannot be used!
+//
 Float_t MHHadronness::GetQ05() const
 {
-    Int_t n = fQfac->GetN();
+    if (fGhness->GetNbinsX()==2)
+    {
+        // acceptance of all gamma-like gammas  (h<0.5)
+        const Double_t ig = fGhness->GetBinContent(1);
+
+        // acceptance of all gamma-like hadrons (h<0.5)
+        const Double_t ip = fPhness->GetBinContent(1);
+
+        if (ip==0)
+            return 0; // FIXME!
+
+        // naive quality factor
+        const Double_t q = ig / sqrt(ip);
+
+        *fLog << all << ip << "/" << ig << ": " << q << endl;
+
+        return q;
+    }
+
+    const Int_t n = fQfac->GetN();
 
     Double_t val1x=0;
@@ -479,2 +527,26 @@
     }
 }
+
+// --------------------------------------------------------------------------
+//
+// You can use this function if you want to use a MHMatrix instead of
+// MMcEvt. This function adds all necessary columns to the
+// given matrix. Afterward you should fill the matrix with the corresponding
+// data (eg from a file by using MHMatrix::Fill). If you now loop
+// through the matrix (eg using MMatrixLoop) MHHadronness::Fill
+// will take the values from the matrix instead of the containers.
+//
+void MHHadronness::InitMapping(MHMatrix *mat)
+{
+    if (fMatrix)
+        return;
+
+    fMatrix = mat;
+    fMap = fMatrix->AddColumn("MMcEvt.fPartId");
+}
+
+void MHHadronness::StopMapping()
+{
+    fMatrix = NULL; 
+}
+
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 2222)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 2225)
@@ -11,4 +11,5 @@
 class MMcEvt;
 class MHadronness;
+class MHMatrix;
 
 class MHHadronness : public MH
@@ -17,4 +18,6 @@
     const MMcEvt *fMcEvt;           //!
     const MHadronness *fHadronness; //!
+    MHMatrix *fMatrix;        //!
+    Int_t fMap;                     //!
 
     TH1D* fPhness;    //-> Hadrons Hadronness
@@ -48,4 +51,7 @@
     Bool_t Finalize();
 
+    void InitMapping(MHMatrix *mat);
+    void StopMapping();
+
     void Print(Option_t *option="") const;
 
