CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

HistogramGenerator Class Reference

#include <HistogramGenerator.h>

Inheritance diagram for HistogramGenerator:
BaseNumericalRandomGenerator

List of all members.

Public Member Functions

virtual double function (double x)
 The probability density function implementation.
 HistogramGenerator (TH1 *histo, const RandomEngine *engine)
 Constructor : initialization of the Random Generator.
virtual ~HistogramGenerator ()
 Default destructor.

Private Member Functions

double ersatzt (double x)
 Gamma Function.

Private Attributes

TH1 * myHisto
 Pointer to the histogram.
int nbins
 n bins
TAxis * theXaxis
 the axis

Detailed Description

Definition at line 14 of file HistogramGenerator.h.


Constructor & Destructor Documentation

HistogramGenerator::HistogramGenerator ( TH1 *  histo,
const RandomEngine engine 
) [inline]

Constructor : initialization of the Random Generator.

Definition at line 19 of file HistogramGenerator.h.

References function(), BaseNumericalRandomGenerator::initialize(), nbins, BaseNumericalRandomGenerator::xmax, and BaseNumericalRandomGenerator::xmin.

                                                               : 
     BaseNumericalRandomGenerator(engine,
                                  histo->GetXaxis()->GetXmin(),
                                  histo->GetXaxis()->GetXmax(),
                                  100000,
                                  3),
     myHisto(histo),
     theXaxis(histo->GetXaxis()),
     nbins(histo->GetXaxis()->GetNbins())
  {

    //    std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl;
    // Drop lowest and highest empty bins 
    double du = (xmax-xmin)/(float)nbins;
    // Restrict xmin to meaningful values
    while ( function(xmin) <= 0. ) xmin += du;
    // Restrict xmax to meaningful values
    while ( function(xmax) <= 0. ) xmax -= du;

    if ( xmin != histo->GetXaxis()->GetXmin() ) xmin -= du;
    if ( xmax != histo->GetXaxis()->GetXmax() ) xmax += du;

    //    std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl;

    //    std::cout <<" Init " << std::endl;
    initialize();
  }
virtual HistogramGenerator::~HistogramGenerator ( ) [inline, virtual]

Default destructor.

Definition at line 48 of file HistogramGenerator.h.

{}

Member Function Documentation

double HistogramGenerator::ersatzt ( double  x) [private]

Gamma Function.

Definition at line 5 of file HistogramGenerator.cc.

References myHisto, nbins, and theXaxis.

Referenced by function().

{
  int ibin=theXaxis->FindBin(x);
  //  std::cout << x << " Bin " << ibin << std::endl;
  double x1=myHisto->GetBinLowEdge(ibin);
  double x2=x1+myHisto->GetBinWidth(ibin);
  double y1=myHisto->GetBinContent(ibin);  
  double y2;
  if(ibin<nbins)
    y2=myHisto->GetBinContent(ibin+1);
  else
    y2=y1;
  // std::cout << " X1 " << x1 <<" X2 " << x2 << " Y1 " <<y1 << " Y2 " << y2 << std::endl;
  return y2 + (y1-y2)*(x2-x)/(x2-x1);
}
virtual double HistogramGenerator::function ( double  x) [inline, virtual]

The probability density function implementation.

Implements BaseNumericalRandomGenerator.

Definition at line 51 of file HistogramGenerator.h.

References ersatzt().

Referenced by HistogramGenerator().

{ return ersatzt(x); }

Member Data Documentation

Pointer to the histogram.

Definition at line 55 of file HistogramGenerator.h.

Referenced by ersatzt().

n bins

Definition at line 61 of file HistogramGenerator.h.

Referenced by ersatzt(), and HistogramGenerator().

TAxis* HistogramGenerator::theXaxis [private]

the axis

Definition at line 58 of file HistogramGenerator.h.

Referenced by ersatzt().