Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1222)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1227)
@@ -1,3 +1,19 @@
                                                                   -*-*- END -*-*-
+
+ 2002/02/28: Thomas Bretz
+
+   * mhist/MHMcEnergyImpact.[h,cc], mhist/MHMcEfficiency.[h,cc]:
+     - added
+     
+   * mhist/Makefile, mhist/HistLinkDef.h:
+     - added MHMcEnergyImpact and MHMcEfficiency
+
+   * mhist/*.cc:
+     - repaced some *&-> casts by &.
+
+   * mhist/MHMcCollectionArea.[h,cc]:
+     - changed to be able to use new MHMcEfficiency.
+
+
 
  2002/02/21: Abelardo Moralejo
Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1227)
@@ -15,6 +15,4 @@
 #pragma link C++ class MHEnergyTime+;
 #pragma link C++ class MHEnergyTheta+;
-#pragma link C++ class MHMcEnergy+;
-#pragma link C++ class MHMcCollectionArea+;
 #pragma link C++ class MHAlphaEnergyTime;
 #pragma link C++ class MHAlphaEnergyTheta;
@@ -27,4 +25,8 @@
 
 #pragma link C++ class MHMcRate+;
+#pragma link C++ class MHMcEfficiency+;
+#pragma link C++ class MHMcEnergy+;
+#pragma link C++ class MHMcEnergyImpact+;
+#pragma link C++ class MHMcCollectionArea+;
 
 #endif
Index: trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.cc	(revision 1227)
@@ -165,5 +165,5 @@
 
     c->cd(4);
-    ((TH3*)(&fHist))->DrawCopy(opt);
+    ((TH3&)fHist).DrawCopy(opt);
 
     c->Modified();
Index: trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.cc	(revision 1227)
@@ -169,5 +169,5 @@
 
     c->cd(4);
-    ((TH3D*)(&fHist))->DrawCopy(opt);
+    ((TH3D&)fHist).DrawCopy(opt);
 
     c->Modified();
Index: trunk/MagicSoft/Mars/mhist/MHEffOnTimeTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEffOnTimeTheta.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHEffOnTimeTheta.cc	(revision 1227)
@@ -139,5 +139,5 @@
     gROOT->SetSelectedPad(NULL);
 
-    ((TH2*)(&fHist))->DrawCopy(opt);
+    ((TH2&)fHist).DrawCopy(opt);
 
     c->Modified();
Index: trunk/MagicSoft/Mars/mhist/MHEffOnTimeTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEffOnTimeTime.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHEffOnTimeTime.cc	(revision 1227)
@@ -78,5 +78,5 @@
     gROOT->SetSelectedPad(NULL);
 
-    ((TH2*)(&fHist))->DrawCopy(opt);
+    ((TH2&)fHist).DrawCopy(opt);
 
     c->Modified();
Index: trunk/MagicSoft/Mars/mhist/MHEnergyTheta.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEnergyTheta.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHEnergyTheta.cc	(revision 1227)
@@ -133,5 +133,5 @@
     gROOT->SetSelectedPad(NULL);
 
-    ((TH2D*)&fHist)->DrawCopy(option);
+    ((TH2D&)fHist).DrawCopy(option);
     gPad->SetLogy();
 
Index: trunk/MagicSoft/Mars/mhist/MHEnergyTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEnergyTime.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHEnergyTime.cc	(revision 1227)
@@ -141,5 +141,5 @@
     gROOT->SetSelectedPad(NULL);
 
-    ((TH2D*)&fHist)->DrawCopy(option);
+    ((TH2D&)fHist).DrawCopy(option);
     gPad->SetLogy();
 
Index: trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc	(revision 1227)
@@ -30,4 +30,5 @@
 
 #include "MH.h"
+#include "MHMcEfficiency.h"
 
 ClassImp(MHMcCollectionArea);
@@ -192,4 +193,41 @@
 }
 
+void MHMcCollectionArea::Calc(MHMcEfficiency *heff)
+{
+    //
+    //  now calculate the Collection area for different
+    //  energies
+    //
+    TH2D &h = (TH2D&)*heff->GetHist();
+
+    const Int_t nbinx = h.GetXaxis()->GetNbins();
+    const Int_t nbiny = h.GetYaxis()->GetNbins();
+
+    for (Int_t ix=1; ix<=nbinx; ix++)
+    {
+        Double_t errA = 0;
+        Double_t colA = 0;
+
+        for (Int_t iy=1; iy<=nbiny; iy++)
+        {
+            TAxis *yaxis = h.GetYaxis();
+
+            const Double_t r1  = yaxis->GetBinLowEdge(iy);
+            const Double_t r2  = yaxis->GetBinLowEdge(iy+1);
+
+            const Double_t A   = TMath::Pi() * (r2*r2 - r1*r1);
+
+            const Double_t eff = h.GetCellContent(ix, iy);
+            const Double_t err = h.GetCellError(ix, iy);
+
+            colA += eff*A;
+            errA += A*A * err*err;
+        }
+
+        fHistCol->SetBinContent(ix, colA);
+        fHistCol->SetBinError(ix, sqrt(errA));
+    }
+}
+
 // --------------------------------------------------------------------------
 //
@@ -201,4 +239,5 @@
     // Description!
 
+    /*
     //
     //  first of all calculate the efficency
@@ -258,5 +297,10 @@
         fHistCol->SetBinContent(ix, colA);
         fHistCol->SetBinError(ix, sqrt(errA));
-    }
+        }
+        */
+    MHMcEfficiency heff;
+    heff.Calc(fHistSel, fHistAll);
+
+    Calc(&heff);
 
     SetReadyToSave();
Index: trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.h	(revision 1227)
@@ -8,4 +8,6 @@
 class TH1D;
 class TH2D;
+
+class MHMcEfficiency;
 
 class MHMcCollectionArea : public MParContainer
@@ -33,4 +35,6 @@
     void CalcEfficiency();
 
+    void Calc(MHMcEfficiency *eff);
+
     ClassDef(MHMcCollectionArea, 1)  // Data Container to calculate Collection Area
 };
Index: trunk/MagicSoft/Mars/mhist/MHMcEfficiency.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEfficiency.cc	(revision 1227)
+++ trunk/MagicSoft/Mars/mhist/MHMcEfficiency.cc	(revision 1227)
@@ -0,0 +1,166 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Javier Lopez 05/2001 <mailto:jlopez@ifae.es>
+!   Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MHMcEfficiency
+//
+// This class holds the information (histogram and fit function)
+// about the energy threshold for a particular trigger condition.
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MHMcEfficiency.h" 
+
+#include <math.h>
+
+#include <TH2.h>
+#include <TCanvas.h>
+
+#include "MH.h"
+#include "MBinning.h"
+
+ClassImp(MHMcEfficiency);
+
+// -------------------------------------------------------------------------
+//
+//  Default Constructor.
+//
+MHMcEfficiency::MHMcEfficiency(const char *name, const char *title)
+    : fHist()
+{
+    fName  = name  ? name  : "MHMcEfficiency";
+    fTitle = title ? title : "Trigger Efficieny (Energy-Impact parameter plane)";
+
+    //  - we initialize the histogram
+    //  - we have to give diferent names for the diferent histograms because
+    //    root don't allow us to have diferent histograms with the same name
+
+    fHist.SetName(fName);
+    fHist.SetTitle(fTitle);
+
+    fHist.SetDirectory(NULL);
+
+    fHist.SetXTitle("E [GeV]");
+    fHist.SetYTitle("r [m]");
+    fHist.SetZTitle("Trig. Eff. [1]");
+
+
+    MBinning binsx;
+    binsx.SetEdgesLog(10, 1, 100000); // [GeV]
+
+    MBinning binsy;
+    binsy.SetEdges(9, 0, 450);       // [m]
+    MH::SetBinning(&fHist, &binsx, &binsy);
+}
+
+void MHMcEfficiency::SetName(const char *name)
+{
+    fName = name;
+    fHist.SetName(name);
+    fHist.SetDirectory(NULL);
+}
+
+void MHMcEfficiency::SetTitle(const char *title)
+{
+    fTitle = title;
+    fHist.SetTitle(title);
+}
+
+//-------------------------------------------------------------------------
+//
+//  Defualt Destructor
+//
+MHMcEfficiency::~MHMcEfficiency()
+{
+}
+
+// ------------------------------------------------------------------------
+// 
+// Drawing function. It creates its own canvas.
+//
+void MHMcEfficiency::Draw(Option_t *option)
+{
+    if (!gPad)
+        MH::MakeDefCanvas(&fHist);
+
+    gPad->SetLogx();
+
+    fHist.Draw(option);
+
+    gPad->Modified();
+    gPad->Update();
+}
+
+TObject *MHMcEfficiency::DrawClone(Option_t *option) const
+{
+    TCanvas *c = MH::MakeDefCanvas(&fHist);
+
+    c->SetLogx();
+
+    //
+    // This is necessary to get the expected bahviour of DrawClone
+    //
+    gROOT->SetSelectedPad(NULL);
+
+    ((TH2D&)fHist).DrawCopy(option);
+
+    c->Modified();
+    c->Update();
+
+    return c;
+}
+
+
+// --------------------------------------------------------------------------
+//
+//  Calculate the Efficiency and set the 'ReadyToSave' flag.
+//  The Efficiency is calculated as the number of selected showers
+//  (eg. triggered ones) divided by the number of all showers.
+//  For error calculation Binomial errors are computed.
+//
+void MHMcEfficiency::Calc(TH2D *hsel, TH2D *hall)
+{
+    //
+    // Set the binning from the two axis of one of the two histograms
+    //
+    MH::SetBinning(&fHist, hsel->GetXaxis(), hsel->GetYaxis());
+
+    //
+    // This is necessary to initialize thze error calculation correctly
+    // (Nothing important: The histogram set the size of its internal
+    // array storing the errors to the correct size)
+    //
+    fHist.Sumw2();
+
+    //
+    // Calculate the efficiency by dividing the number of selected
+    // (eg. triggered) showers by the number of all showers per bin.
+    // Both histograms are weighted with weight 1, and for the error
+    // calculation we assume a binomial error calculation.
+    //
+    fHist.Divide(hsel, hall, 1, 1, "B");
+
+    SetReadyToSave();
+}
Index: trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1227)
+++ trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1227)
@@ -0,0 +1,39 @@
+#ifndef MARS_MHMcEfficiency
+#define MARS_MHMcEfficiency
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+#ifndef ROOT_TH2
+#include <TH2.h>
+#endif
+
+class MMcEvt;
+
+class MHMcEfficiency : public MParContainer
+{
+private:
+
+    TH2D fHist;           // histogram with the logarith of the energy
+
+    // const MMcEvt *fMcEvt;  //! container to fill histogram from
+
+public:
+    MHMcEfficiency(const char *name=NULL, const char *title=NULL);
+    ~MHMcEfficiency();
+
+    void SetName(const char *name);
+    void SetTitle(const char *title);
+
+    const TH2D *GetHist()       { return &fHist; }
+    const TH2D *GetHist() const { return &fHist; }
+
+    void Draw(Option_t* option = "");
+    TObject *DrawClone(Option_t* option = "") const;
+
+    void Calc(TH2D *hsel, TH2D *hall);
+
+    ClassDef(MHMcEfficiency, 1)  // Histogram container for montecarlo energy threshold
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.cc	(revision 1227)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.cc	(revision 1227)
@@ -0,0 +1,168 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Javier Lopez 05/2001 <mailto:jlopez@ifae.es>
+!   Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MHMcEnergyImpact
+//
+// This class holds the information (histogram and fit function)
+// about the energy threshold for a particular trigger condition.
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MHMcEnergyImpact.h" 
+
+#include <TH2.h>
+#include <TCanvas.h>
+
+#include "MParList.h"
+#include "MBinning.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MMcEvt.hxx"
+
+ClassImp(MHMcEnergyImpact);
+
+// -------------------------------------------------------------------------
+//
+//  Default Constructor.
+//
+MHMcEnergyImpact::MHMcEnergyImpact(const char *name, const char *title)
+    : fHist()
+{
+    fName  = name  ? name  : "MHMcEnergyImpact";
+    fTitle = title ? title : "Impact (radius) vs Energy distribution";
+
+    //  - we initialize the histogram
+    //  - we have to give diferent names for the diferent histograms because
+    //    root don't allow us to have diferent histograms with the same name
+
+    fHist.SetName(fName);
+    fHist.SetTitle(fTitle);
+
+    fHist.SetDirectory(NULL);
+
+    fHist.SetXTitle("E [GeV]");
+    fHist.SetYTitle("r [m]");
+    fHist.SetZTitle("N");
+
+    MBinning binsx;
+    binsx.SetEdgesLog(10, 1, 100000); // [GeV]
+
+    MBinning binsy;
+    binsy.SetEdges(9, 0, 450);       // [m]
+
+    SetBinning(&fHist, &binsx, &binsy);
+
+}
+
+void MHMcEnergyImpact::SetName(const char *name)
+{
+    fName = name;
+    fHist.SetName(name);
+    fHist.SetDirectory(NULL);
+}
+
+void MHMcEnergyImpact::SetTitle(const char *title)
+{
+    fTitle = title;
+    fHist.SetName(title);
+}
+
+//-------------------------------------------------------------------------
+//
+//  Defualt Destructor
+//
+MHMcEnergyImpact::~MHMcEnergyImpact()
+{
+}
+
+
+Bool_t MHMcEnergyImpact::SetupFill(const MParList *pList)
+{
+    const MBinning *binsx = (MBinning*)pList->FindObject("BinningEnergy", "MBinning");
+    const MBinning *binsy = (MBinning*)pList->FindObject("BinningImpact", "MBinning");
+
+    if (!binsx || !binsy)
+        return kTRUE;
+
+    SetBinning(&fHist, binsx, binsy);
+
+    return kTRUE;
+}
+
+//--------------------------------------------------------------------------
+//
+//  Fill the histogram with the log10 of the energy for triggered events.
+//
+Bool_t MHMcEnergyImpact::Fill(const MParContainer *cont)
+{
+    const MMcEvt &mcevt = *(MMcEvt*)cont;
+
+    const Float_t energy = mcevt.GetEnergy();
+    const Float_t impact = mcevt.GetImpact()/100.;
+
+    fHist.Fill(energy, impact);
+
+    return kTRUE;
+}
+
+// ------------------------------------------------------------------------
+// 
+// Drawing function. It creates its own canvas.
+//
+void MHMcEnergyImpact::Draw(Option_t *option)
+{
+    if (!gPad)
+        MH::MakeDefCanvas(&fHist);
+
+    gPad->SetLogx();
+
+    fHist.Draw(option);
+
+    gPad->Modified();
+    gPad->Update();
+}
+
+TObject *MHMcEnergyImpact::DrawClone(Option_t *option) const
+{
+    TCanvas *c = MH::MakeDefCanvas(&fHist);
+
+    c->SetLogx();
+
+    //
+    // This is necessary to get the expected bahviour of DrawClone
+    //
+    gROOT->SetSelectedPad(NULL);
+
+    ((TH2D&)fHist).DrawCopy(option);
+
+    c->Modified();
+    c->Update();
+
+    return c;
+}
+
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1227)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1227)
@@ -0,0 +1,37 @@
+#ifndef MARS_MHMcEnergyImpact
+#define MARS_MHMcEnergyImpact
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+#ifndef ROOT_TH2
+#include <TH2.h>
+#endif
+
+class MMcEvt;
+
+class MHMcEnergyImpact : public MH
+{
+private:
+    TH2D fHist; // histogram with the logarith of the energy
+
+public:
+    MHMcEnergyImpact(const char *name=NULL, const char *title=NULL);
+    ~MHMcEnergyImpact();
+
+    void SetName(const char *name);
+    void SetTitle(const char *title);
+
+    Bool_t SetupFill(const MParList *pList);
+    Bool_t Fill(const MParContainer *pcont=NULL);
+
+    const TH2D *GetHist()       { return &fHist; }
+    const TH2D *GetHist() const { return &fHist; }
+
+    void Draw(Option_t* option = "");
+    TObject *DrawClone(Option_t* option = "") const;
+
+    ClassDef(MHMcEnergyImpact, 1)  // Histogram container for montecarlo energy threshold
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 1222)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 1227)
@@ -46,4 +46,6 @@
            MHTimeDiffTheta.cc \
            MHMcEnergy.cc \
+           MHMcEfficiency.cc \
+           MHMcEnergyImpact.cc \
 	   MHMcRate.cc
 
