CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HistogramGenerator Class Reference

#include <HistogramGenerator.h>

Inheritance diagram for HistogramGenerator:
BaseNumericalRandomGenerator

Public Member Functions

virtual double function (double x)
 The probability density function implementation. More...
 
 HistogramGenerator (TH1 *histo, const RandomEngine *engine)
 Constructor : initialization of the Random Generator. More...
 
virtual ~HistogramGenerator ()
 Default destructor. More...
 
- Public Member Functions inherited from BaseNumericalRandomGenerator
 BaseNumericalRandomGenerator (const RandomEngine *engine, double xmin=0., double xmax=1., int n=1000, int iter=6)
 
double generate () const
 The random generation according to function() More...
 
double generateExp () const
 
double generateLin () const
 
void initialize ()
 The initialization (numerical integarion, inversion) More...
 
bool setSubInterval (double x1, double x2)
 To shoot in a given interval. More...
 
virtual ~BaseNumericalRandomGenerator ()
 Default destructor. More...
 

Private Member Functions

double ersatzt (double x)
 Gamma Function. More...
 

Private Attributes

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

Additional Inherited Members

- Protected Attributes inherited from BaseNumericalRandomGenerator
double deltar
 
std::vector< double > f
 
int iter
 
int n
 
const RandomEnginerandom
 
double rmin
 
std::vector< double > sampling
 
double xmax
 
double xmin
 

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 BaseNumericalRandomGenerator::initialize(), nbins, BaseNumericalRandomGenerator::xmax, and BaseNumericalRandomGenerator::xmin.

19  :
21  histo->GetXaxis()->GetXmin(),
22  histo->GetXaxis()->GetXmax(),
23  100000,
24  3),
25  myHisto(histo),
26  theXaxis(histo->GetXaxis()),
27  nbins(histo->GetXaxis()->GetNbins())
28  {
29 
30  // std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl;
31  // Drop lowest and highest empty bins
32  double du = (xmax-xmin)/(float)nbins;
33  // Restrict xmin to meaningful values
34  while ( function(xmin) <= 0. ) xmin += du;
35  // Restrict xmax to meaningful values
36  while ( function(xmax) <= 0. ) xmax -= du;
37 
38  if ( xmin != histo->GetXaxis()->GetXmin() ) xmin -= du;
39  if ( xmax != histo->GetXaxis()->GetXmax() ) xmax += du;
40 
41  // std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl;
42 
43  // std::cout <<" Init " << std::endl;
44  initialize();
45  }
TH1 * myHisto
Pointer to the histogram.
void initialize()
The initialization (numerical integarion, inversion)
TAxis * theXaxis
the axis
BaseNumericalRandomGenerator(const RandomEngine *engine, double xmin=0., double xmax=1., int n=1000, int iter=6)
virtual HistogramGenerator::~HistogramGenerator ( )
inlinevirtual

Default destructor.

Definition at line 48 of file HistogramGenerator.h.

48 {}

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().

6 {
7  int ibin=theXaxis->FindBin(x);
8  // std::cout << x << " Bin " << ibin << std::endl;
9  double x1=myHisto->GetBinLowEdge(ibin);
10  double x2=x1+myHisto->GetBinWidth(ibin);
11  double y1=myHisto->GetBinContent(ibin);
12  double y2;
13  if(ibin<nbins)
14  y2=myHisto->GetBinContent(ibin+1);
15  else
16  y2=y1;
17  // std::cout << " X1 " << x1 <<" X2 " << x2 << " Y1 " <<y1 << " Y2 " << y2 << std::endl;
18  return y2 + (y1-y2)*(x2-x)/(x2-x1);
19 }
TH1 * myHisto
Pointer to the histogram.
TAxis * theXaxis
the axis
Definition: DDAxes.h:10
virtual double HistogramGenerator::function ( double  x)
inlinevirtual

The probability density function implementation.

Implements BaseNumericalRandomGenerator.

Definition at line 51 of file HistogramGenerator.h.

References ersatzt(), and x.

51 { return ersatzt(x); }
Definition: DDAxes.h:10
double ersatzt(double x)
Gamma Function.

Member Data Documentation

TH1* HistogramGenerator::myHisto
private

Pointer to the histogram.

Definition at line 55 of file HistogramGenerator.h.

Referenced by ersatzt().

int HistogramGenerator::nbins
private
TAxis* HistogramGenerator::theXaxis
private

the axis

Definition at line 58 of file HistogramGenerator.h.

Referenced by ersatzt().