#define MAXFLAT 8
//--------------------------------------------------------------------
//
//  Make a profile histogram
//
//--------------------------------------------------------------------

#include <string>
#include "CLHEP/Random/DRand48Engine.h"
#include "CLHEP/Random/RandGauss.h"
#include "CLHEP/Random/RandExponential.h"
#include "HepTuple/HepHBookHistProf.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=0.0;
  double lambda=2.0;
  HBookFile * tManager = new HBookFile( "x4.rz" );

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

//  Book a gang of histograms.

  cout << "\n Populate a profile histogram." << endl;
  HepHistProf & rge = tManager->histProf("Gauss/exponential distribution",
                                          50, 0.0f, 5.0f, -5.0f, 5.0f);

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

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

    x = Rexp.fire( lambda );
    y = Rgauss.fire( mu, x );
    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;
}