SimpleHistogramGenerator

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#ifndef SimpleHistogramGenerator_H
#define SimpleHistogramGenerator_H

/**
 * This class is a simpler version (less memory demanding but slightly 
 * slower) of HistogramGenerator. provides a C++ version of the REMT package from 
 * Ronald Kleiss. 
 *
 * The method generate() generates random number according to the 
 * histogram bin content. 
 *
 * \author Patrick Janot
 * $Date: 16 July 2009 14:20 */

#include <vector>

class RandomEngineAndDistribution;
class TH1;
class TAxis;

class SimpleHistogramGenerator {
public:
  /// Constructor that perform the necessary integration and inversion steps
  /// xmin and xmax are the generation bounds, n is the internal table size
  /// and iter is the number of iterations for the numerical part.
  SimpleHistogramGenerator(TH1* histo);

  /// Default destructor
  virtual ~SimpleHistogramGenerator() {}

  /// The random generation
  double generate(RandomEngineAndDistribution const*) const;

  int binarySearch(const int& n, const std::vector<float>& array, const double& value) const;

private:
  /// Pointer to the histogram
  //TH1 * myHisto;

  /// the axis
  //TAxis * theXaxis;

  /// Number of bins
  int nBins;

  // Limits of integration
  double xMin, xMax;

  // Bin width
  double binWidth;

  /// Integral
  std::vector<float> integral;

  /// Number of entries
  double nEntries;
};
#endif