Index: trunk/MagicSoft/Mars/mhbase/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 4966)
+++ trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 4991)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -24,51 +24,56 @@
 
 //////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MFillH                                                                  //
-//                                                                          //
-//  This is a common interface (task) to fill mars histograms. Every mars   //
-//  histogram which is derived from MH can be filled with this task.        //
-//                                                                          //
-//  There are two options to use:                                           //
-//                                                                          //
-//  1) You specifiy the parameter container with which data the             //
-//     histogram container should be filled, and the histogram container    //
-//     which has to be filled. This can be done by either specifing the     //
-//     name of the objects in the parameter list or by specifiing a pointer //
-//     to the object. (s. Constructor)                                      //
-//                                                                          //
-//  2) You specify the name and/or type of the histogram to become filled.  //
-//     Any other action imust be taken by the histogram class.              //
-//                                                                          //
-//  PreProcess: In the preprocessing of this task we setup all pointers     //
-//              to instances which are needed and call FillSetup of the     //
-//              histogram class with the parameter list as an argument.     //
-//                                                                          //
-//  Process: The process function calls the Fill member function of the     //
-//           histogram class instance (inheriting from MH) with either      //
-//           a NULL pointer or a pointer to the corresponding container     //
-//           as an argument.                                                //
-//                                                                          //
-// To use a weight for each event filled in a histogram call                //
-// SetWeight(). You can eithe use the name of a MWeight container stored    //
-// in the parameter list or a pointer to it as an argument.                 //
-//                                                                          //
-//                                                                          //
-//  WARNING:                                                                //
-//   Because MFillH is a generalized task to fill histograms it doesn't     //
-//   know about which branches from a file are necessary to fill the        //
-//   histograms. If you are reading data from a file which is directly      //
-//   filled into a histogram via MFillH, please call either                 //
-//   MReadTree::DisableAutoScheme() or enable the necessary branches by     //
-//   yourself, using MReadTree::EnableBranch()                              //
-//                                                                          //
-//   Checkout the Warning in MTaskList.                                     //
-//                                                                          //
-//  Input Containers:                                                       //
-//   A parameter container                                                  //
-//                                                                          //
-//  Output Containers:                                                      //
-//   A histogram container                                                  //
-//                                                                          //
+//
+//  MFillH
+//
+//  This is a common interface (task) to fill mars histograms. Every mars
+//  histogram which is derived from MH can be filled with this task.
+//
+//  There are two options to use:
+//
+//  1) You specifiy the parameter container with which data the
+//     histogram container should be filled, and the histogram container
+//     which has to be filled. This can be done by either specifing the
+//     name of the objects in the parameter list or by specifiing a pointer
+//     to the object. (s. Constructor)
+//
+//  2) You specify the name and/or type of the histogram to become filled.
+//     Any other action imust be taken by the histogram class.
+//
+//  PreProcess: In the preprocessing of this task we setup all pointers
+//              to instances which are needed and call FillSetup of the
+//              histogram class with the parameter list as an argument.
+//
+//  Process: The process function calls the Fill member function of the
+//           histogram class instance (inheriting from MH) with either
+//           a NULL pointer or a pointer to the corresponding container
+//           as an argument.
+//
+// To use a weight for each event filled in a histogram call
+// SetWeight(). You can eithe use the name of a MWeight container stored
+// in the parameter list or a pointer to it as an argument.
+//
+//
+//  WARNING:
+//   Because MFillH is a generalized task to fill histograms it doesn't
+//   know about which branches from a file are necessary to fill the
+//   histograms. If you are reading data from a file which is directly
+//   filled into a histogram via MFillH, please call either
+//   MReadTree::DisableAutoScheme() or enable the necessary branches by
+//   yourself, using MReadTree::EnableBranch()
+//
+//   Checkout the Warning in MTaskList.
+//
+//  Version 2:
+//  ----------
+//   - added fNumExcutions
+//
+//
+//  Input Containers:
+//   A parameter container
+//
+//  Output Containers:
+//   A histogram container
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MFillH.h"
@@ -457,4 +462,5 @@
     //
     fH->SetSerialNumber(GetSerialNumber());
+    fH->SetNumExecutions(0);
     if (!fH->SetupFill(pList))
     {
@@ -519,14 +525,15 @@
      ((MHArray*)fH)->SetIndex(idx);
      */
-
+/*
     TVirtualPad *save = gPad;
     if (fCanvas)
         fCanvas->cd();
-
+  */
     const Bool_t rc = fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1);
-
+    fH->SetNumExecutions(GetNumExecutions()+1);
+/*
     if (save && fCanvas)
         save->cd();
-
+  */
     return rc;
 } 
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 4966)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 4991)
@@ -1271,42 +1271,6 @@
                        const char* name, const char* title)
 {
-    const Int_t size = array.GetSize();
-
-    TH1I *h1=0;
-
-    //check if histogram with identical name exist
-    TObject *h1obj = gROOT->FindObject(name);
-    if (h1obj && h1obj->InheritsFrom("TH1I"))
-    {
-        h1 = (TH1I*)h1obj;
-        h1->Reset();
-    }
-
-    Double_t min = size>0 ? array[0] : 0;
-    Double_t max = size>0 ? array[0] : 1;
-
-    // first loop over array to find the min and max
-    for (Int_t i=1; i<size;i++)
-    {
-        max = TMath::Max((Double_t)array[i], max);
-        min = TMath::Min((Double_t)array[i], min);
-    }
-
-    Int_t newbins = 0;
-    FindGoodLimits(nbins, newbins, min, max, kFALSE);
-
-    if (!h1)
-    {
-        h1 = new TH1I(name, title, nbins, min, max);
-        h1->SetXTitle("");
-        h1->SetYTitle("Counts");
-        h1->SetDirectory(gROOT);
-    }
-
-    // Second loop to fill the histogram
-    for (Int_t i=0;i<size;i++)
-        h1->Fill(array[i]);
-
-    return h1;
+    const TArrayF arr(array.GetSize(), array.GetArray());
+    return ProjectArray(array, nbins, name, title);
 }
 
@@ -1317,41 +1281,16 @@
 TH1I* MH::ProjectArray(const MArrayD &array, Int_t nbins, const char* name, const char* title)
 {
-    const Int_t size = array.GetSize();
-    TH1I *h1=0;
-
-    //check if histogram with identical name exist
-    TObject *h1obj = gROOT->FindObject(name);
-    if (h1obj && h1obj->InheritsFrom("TH1I"))
-    {
-        h1 = (TH1I*)h1obj;
-        h1->Reset();
-    }
-
-    Double_t min = size>0 ? array[0] : 0;
-    Double_t max = size>0 ? array[0] : 1;
-
-    // first loop over array to find the min and max
-    for (Int_t i=1; i<size;i++)
-    {
-        max = TMath::Max(array[i], max);
-        min = TMath::Min(array[i], min);
-    }
-
-    Int_t newbins = 0;
-    FindGoodLimits(nbins, newbins, min, max, kFALSE);
-
-    if (!h1)
-    {
-        h1 = new TH1I(name, title, newbins, min, max);
-        h1->SetXTitle("");
-        h1->SetYTitle("Counts");
-        h1->SetDirectory(gROOT);
-    }
-
-    // Second loop to fill the histogram
-    for (Int_t i=0;i<size;i++)
-        h1->Fill(array[i]);
-
-    return h1;
-}
-
+    const TArrayD arr(array.GetSize(), array.GetArray());
+    return ProjectArray(array, nbins, name, title);
+}
+
+// --------------------------------------------------------------------------
+//
+// See MTask::PrintSkipped
+//
+void MH::PrintSkipped(UInt_t n, const char *str)
+{
+    *fLog << " " << setw(7) << n << " (";
+    *fLog << setw(3) << (int)(100.*n/GetNumExecutions());
+    *fLog << "%) Evts skipped: " << str << endl;
+}
Index: trunk/MagicSoft/Mars/mhbase/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.h	(revision 4966)
+++ trunk/MagicSoft/Mars/mhbase/MH.h	(revision 4991)
@@ -24,9 +24,9 @@
 {
 private:
-    Byte_t fSerialNumber;
+    Byte_t fSerialNumber;   // Serial number (eg of telecope)
+    UInt_t fNumExecutions;  // Number of calls to Fill function
 
 public:
     MH(const char *name=NULL, const char *title=NULL);
-
 
     virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; }
@@ -34,4 +34,9 @@
     TString AddSerialNumber(const char *str) const { TString s(str); if (fSerialNumber==0) return s; s += ";"; s += fSerialNumber; return s; }
     TString AddSerialNumber(const TString &str) const { return AddSerialNumber((const char*)str); }
+
+    UInt_t GetNumExecutions() const { return fNumExecutions; }
+    void SetNumExecutions(UInt_t n) { fNumExecutions=n; }
+
+    void PrintSkipped(UInt_t n, const char *str);
 
     Bool_t OverwritesDraw(TClass *cls=NULL) const;
@@ -110,5 +115,5 @@
     static TObject *FindObjectInPad(const char *name, TVirtualPad *pad=NULL);
 
-    ClassDef(MH, 1) //A base class for Mars histograms
+    ClassDef(MH, 2) //A base class for Mars histograms
 };
 
