#ifndef HEPHBOOKHIST1D_H
#define HEPHBOOKHIST1D_H

// ----------------------------------------------------------------------
//
// HepHBookHist1D.h - class declaration for HBook one-dimensional histogram
//
// HepHBookHist1D is the implementation of the HBook one-dimensional
// histogram. It is derived from HepHist1D (the generic interface) and
// HepHBookHist. It is mainly a C++ wrapper around the CERNlib HBook
// Fortran histogramming libraries.
//
// No HepHBookHist1D objects are ever directly
// instantiated by the programmer. When creating new HepHist* objects,
// the manager is in charge of creating the appropriate HepHBook object.
//
// To use generate HBook histograms, HepHBookFileManager must be used:
//
//   int lunit = 10;
//   HepFileManager* m = new HepHBookFileManager("filename.rz", lunit);
//    :
//    :
//   HepHist1D* h(m->hist1D("Title", 100, 0.0, 23.0));
//   float x, weight;
//    :
//   [gather data]
//    :
//   h->accumulate(x, weight);
//
//
// Note that the constructor can take an ID number which is used by
// the HBook implementation of HepHist1D. If omitted, the ID number is
// generated automatically (which is recommended). The ID number is
// available through the id() method.
//
//
// History:
//   ??-???-19??  Bob Jacobsen   Initial draft, based on ideas in HepTuple
//     and the SLT histogram classes of Joe Boudreau
//   05-May-1997  Walter Brown   Initial design & draft of Hist class
//   22-May-1997  Walter Brown   Merged Hist into HepHistogram
//   30-May-1997  Walter Brown   Added cloning functions
//   29-May-1997  Jason Luther   Added comments
//   04-Jun-1997  Jason Luther   Rewrote comments to match design
//   09-Jun-1997  Jason Luther   Added cloning constructor
//   04-Aug-1998  Philippe Canal Added weight, entries, sum, etc..
//   21-Feb-2000  Walter Brown   Improved C++ standard compliance
//
// ----------------------------------------------------------------------


#ifdef HEP_SHORT_NAMES      // done early to override HepPlot
  #define Hist1D HepHBookHist1D
#endif

#ifndef HEPHBOOKFILEMANAGER_H
  #include "HepTuple/HepHBookFileManager.h"
#endif

#ifndef HEPHIST1D_H
  #include "HepTuple/HepHist1D.h"
#endif

ZM_BEGIN_NAMESPACE( zmht )	/*  namespace zmht  {  */


class HepHBookHist1D : public HepHist1D  {

  friend class HepHBookFileManager;

protected:

  // create a 1D histogram with the given title and binning
  HepHBookHist1D(
    HepHBookFileManager * manager
  , const std::string& title
  , const int nBins, const float low, const float high
  , const int id_req = 0
  );

  // Used for dummy construction ...
  // the object is then not valid ...
  HepHBookHist1D( );                           // default constructor

  // Silence g++ complaints about various functions never being called
  void silenceCompiler();

public:

  virtual ~HepHBookHist1D();

  virtual void accumulate(
    const float x
  , const float weight = 1.0
  );

  virtual float bin(		 // retrieve contents of specified bin
    const int binNum
  ) const;

  virtual float binError(	 // retrieve error for specified bin
    const int binNum
  ) const;

  virtual void getContents(	 // get contents of all in-range bins
    float * values
  ) const;

  virtual void putContents(	 // put contents of all in-range bins
    float * values
  ) const;

  virtual void getErrors(	 // get errors of all in-range bins
    float * errors
  ) const;

  virtual void putErrors(	 // put errors of all in-range bins
    float * errors
  ) const;

  virtual void getStatistics( int & numEntries, float & sumW, float & sumW2,
                              double & sumWX, double & sumWX2 ) const;

  virtual void getOverflows( float * numOver, float * numUnder ) const;

  virtual void setXTitle( const std::string& label );
  virtual void setYTitle( const std::string& label );
  virtual void setZTitle( const std::string& label );

  virtual HepRawHist importHist1D( const HepHist1D & h );

  virtual void      addHist1D( const HepRawHist & h );
  virtual void subtractHist1D( const HepRawHist & h );
  virtual void multiplyHist1D( const HepRawHist & h );
  virtual void   divideHist1D( const HepRawHist & h );

  virtual void removeImportedHist1D( const HepRawHist & h );

  virtual void reset();

  virtual int   entries() const; // number of entries

  virtual float weight() const;  // sum of all weight
  virtual float weight2() const;  // sum of all weight^2

  virtual float sum() const;     // retrieve weighted sum
  virtual float sum2() const;    // retrieve weighted sum of square (X^2)

private:

  // forbidden operations, hence private:
  //HepHBookHist1D( );              // default constructor
  HepHBookHist1D( const HepHBookHist1D & );   // copy constructor
  HepHBookHist1D & operator=( const HepHBookHist1D & );  // assignment

};  // HepHBookHist1D


ZM_END_NAMESPACE( zmht )	/*  }  // namespace zmht  */


#endif  // HEPHBOOKHIST1D_H
