Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1299)
+++ trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1300)
@@ -50,4 +50,6 @@
 
 #include <TH1.h>
+#include <TH2.h>
+#include <TH3.h>
 #include <TCanvas.h>
 
@@ -136,5 +138,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy)
+void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
 {
     TAxis &x = *h->GetXaxis();
@@ -169,5 +171,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
+void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
 {
     //
@@ -214,5 +216,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy)
+void MH::SetBinning(TH2 *h, const TArrayD *binsx, const TArrayD *binsy)
 {
     MBinning bx;
@@ -223,5 +225,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz)
+void MH::SetBinning(TH3 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz)
 {
     MBinning bx;
@@ -245,5 +247,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy)
+void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy)
 {
     const Int_t nx = binsx->GetNbins();
@@ -260,5 +262,5 @@
 }
 
-void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
+void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
 {
     const Int_t nx = binsx->GetNbins();
@@ -281,4 +283,18 @@
 void MH::SetBinning(TH1 *h, TH1 *x)
 {
-    SetBinning(h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
-}
+    if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class()))
+    {
+        SetBinning((TH3*)h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
+        return;
+    }
+    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
+    {
+        SetBinning((TH2*)h, x->GetXaxis(), x->GetYaxis());
+        return;
+    }
+    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
+    {
+        SetBinning(h, x->GetXaxis());
+        return;
+    }
+}
Index: trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.h	(revision 1299)
+++ trunk/MagicSoft/Mars/mhist/MH.h	(revision 1300)
@@ -7,4 +7,6 @@
 
 class TH1;
+class TH2;
+class TH3;
 class TAxis;
 class TArrayD;
@@ -28,14 +30,14 @@
 
     static void SetBinning(TH1 *h, const MBinning *binsx);
-    static void SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy);
-    static void SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
+    static void SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy);
+    static void SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
 
     static void SetBinning(TH1 *h, const TArrayD *binsx);
-    static void SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy);
-    static void SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz);
+    static void SetBinning(TH2 *h, const TArrayD *binsx, const TArrayD *binsy);
+    static void SetBinning(TH3 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz);
 
     static void SetBinning(TH1 *h, const TAxis *binsx);
-    static void SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy);
-    static void SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
+    static void SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy);
+    static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
 
     static void SetBinning(TH1 *h, TH1 *x);
Index: trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1299)
+++ trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1300)
@@ -229,9 +229,9 @@
     case 2:
         fHist->SetTitle(title+" (2D)");
-        SetBinning(fHist, binsx, binsy);
+        SetBinning((TH2*)fHist, binsx, binsy);
         return kTRUE;
     case 3:
         fHist->SetTitle(title+" (3D)");
-        SetBinning(fHist, binsx, binsy, binsz);
+        SetBinning((TH3*)fHist, binsx, binsy, binsz);
         return kTRUE;
     }
Index: trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc	(revision 1299)
+++ trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc	(revision 1300)
@@ -196,4 +196,106 @@
 }
 
+// --------------------------------------------------------------------------
+//
+//  Calculate the Efficiency (collection area) and set the 'ReadyToSave'
+//  flag
+//
+void MHMcCollectionArea::CalcEfficiency()
+{
+    MHMcEfficiency heff;
+    heff.Calc(*fHistSel, *fHistAll);
+
+    Calc(heff);
+}
+
+void MHMcCollectionArea::CalcEfficiency(UInt_t numevts, Float_t angle)
+{
+    // Here we estimate the total number of showers in each energy bin
+    // known the energy range and spectral index of the generated showers
+    // (set now by hand since the info is not available in the header!)
+
+    TH1D &histsel = *fHistSel->ProjectionX();
+
+    TH1D histall;
+
+    TAxis &xaxis = *histsel.GetXaxis();
+
+    MH::SetBinning(&histall, &xaxis);
+    MH::SetBinning(fHistCol, &xaxis);
+
+    const Float_t emin  = 10.;
+    const Float_t emax  = 30000.;  // Energies in GeV.
+    const Float_t index = 2.6;     // Differential spectral Index.
+
+    const Float_t expo = 1.-index;
+
+    const Float_t k = (Float_t)numevts / (pow(emax,expo) - pow(emin,expo));
+
+    const Int_t nbinx = xaxis.GetNbins();
+
+    for (Int_t i=1; i<=nbinx; i++)
+    {
+        const Float_t e1 = histall.GetBinLowEdge(i);
+        const Float_t e2 = histall.GetBinLowEdge(i+1);
+
+        if (e1 < emin || e2 > emax)
+            continue;
+
+        const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
+
+        histall.SetBinContent(i, events);
+        histall.SetBinError(i, sqrt(events));
+
+    }
+
+    // -----------------------------------------------------------
+
+    // Impact parameter range:
+    const Float_t r1 = 0;
+    const Float_t r2 = 400;
+
+    const Float_t dr = TMath::Pi() * (r2*r2 - r1*r1);
+
+    angle *= TMath::Pi()/180;
+
+    for (Int_t ix=1; ix<=nbinx; ix++)
+    {
+        const Float_t Na = histall.GetBinContent(ix);
+
+        if (Na <= 0)
+            continue;
+
+        const Float_t Ns = histsel.GetBinContent(ix);
+
+        // Since Na is an estimate of the total number of showers generated
+        // in the energy bin, it may happen that Ns (triggered showers) is
+        // larger than Na. In that case, the bin is skipped:
+
+        if (Na < Ns)
+            continue;
+
+        const Double_t eff = Ns/Na;
+
+        const Double_t err = sqrt((1.-eff)*Ns)/Na;
+
+        const Float_t area = dr * cos(angle);
+
+        fHistCol->SetBinContent(ix, eff*area);
+        fHistCol->SetBinError(ix, err*area);
+    }
+
+    delete &histsel;
+
+    SetReadyToSave();
+}
+
+void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
+{
+    MHMcEfficiency heff;
+    heff.Calc(*mcsel.GetHist(), *mcall.GetHist());
+
+    Calc(heff);
+}
+
 void MHMcCollectionArea::Calc(const MHMcEfficiency &heff)
 {
@@ -242,17 +344,7 @@
 //  flag
 //
-void MHMcCollectionArea::CalcEfficiency()
-{
-    MHMcEfficiency heff;
-    heff.Calc(*fHistSel, *fHistAll);
-
-    Calc(heff);
-}
-
-void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
-{
-    MHMcEfficiency heff;
-    heff.Calc(*mcsel.GetHist(), *mcall.GetHist());
-
-    Calc(heff);
-}
+/*
+void MHMcCollectionArea::Calc(MHMcEnergyImpact &mcsel, UInt_t numevents, Float_t angle)
+{
+}
+*/
Index: trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h	(revision 1299)
+++ trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h	(revision 1300)
@@ -38,4 +38,5 @@
 
     void CalcEfficiency();
+    void CalcEfficiency(UInt_t allevts, Float_t theta);
 
     void Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall);
