#define MAXFLAT 8
//--------------------------------------------------------------------
//
//  Make a 2D histogram
//
//--------------------------------------------------------------------

#include <string>
#include "CLHEP/Random/DRand48Engine.h"
#include "CLHEP/Random/RandGauss.h"
#include "CLHEP/Random/RandExponential.h"
#include "HepTuple/HepHBookHist2D.h"
#include "HepTuple/TupleManager.h"
#include "HepTuple/HBookFile.h"
#include <stdlib.h>
#include <iostream.h>
#include <math.h>

DRand48Engine someEngine;
RandGauss Rgauss(someEngine);
RandExponential Rexp(someEngine);

main()  {

  int nsamp=10000;
  void generate(long);

//  Book and fill some histograms in a function named generate.
  generate(nsamp);

  return 0;
}

void generate(long samples)  {

  double x,y;
  double mu=2.5;
  double sig=0.9;
  double lambda = 2.0;
  HBookFile * tManager = new HBookFile( "x3.rz" );

  cout << "Function generate called to produce " << samples << " events." << endl;

//  Book a gang of histograms.

  cout << "\n Populate a 2D histogram." << endl;
  HepHist2D & rge = tManager->hist2D("Gauss/exponential distribution",
                                      50,-6.0f, 6.0f ,50, 0.0f,10.0f);

//  Make some entries.  Fill with random numbers from various distributions.

  for( int j=0; j<samples; j++ ) {

    x = Rgauss.fire( mu, sig );
    y = Rexp.fire( lambda );
    rge.accumulate((float)x,(float)y);

  }
  rge.release();

//  Write out the histograms and bail out
  cout << "\n Histograms filled.  Write the file." << endl;
  tManager->write();
  delete tManager;

  return;
}