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)
 Constructor : initialization of the Random Generator. More...
 
virtual ~HistogramGenerator ()
 Default destructor. More...
 
- Public Member Functions inherited from BaseNumericalRandomGenerator
 BaseNumericalRandomGenerator (double xmin=0., double xmax=1., int n=1000, int iter=6)
 
double generate (RandomEngineAndDistribution const *) const
 The random generation according to function() More...
 
double generateExp (RandomEngineAndDistribution const *) const
 
double generateLin (RandomEngineAndDistribution const *) 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
 
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)
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  :
20  BaseNumericalRandomGenerator(histo->GetXaxis()->GetXmin(),
21  histo->GetXaxis()->GetXmax(),
22  100000,
23  3),
24  myHisto(histo),
25  theXaxis(histo->GetXaxis()),
26  nbins(histo->GetXaxis()->GetNbins())
27  {
28 
29  // std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl;
30  // Drop lowest and highest empty bins
31  double du = (xmax-xmin)/(float)nbins;
32  // Restrict xmin to meaningful values
33  while ( function(xmin) <= 0. ) xmin += du;
34  // Restrict xmax to meaningful values
35  while ( function(xmax) <= 0. ) xmax -= du;
36 
37  if ( xmin != histo->GetXaxis()->GetXmin() ) xmin -= du;
38  if ( xmax != histo->GetXaxis()->GetXmax() ) xmax += du;
39 
40  // std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl;
41 
42  // std::cout <<" Init " << std::endl;
43  initialize();
44  }
TH1 * myHisto
Pointer to the histogram.
BaseNumericalRandomGenerator(double xmin=0., double xmax=1., int n=1000, int iter=6)
void initialize()
The initialization (numerical integarion, inversion)
TAxis * theXaxis
the axis
virtual HistogramGenerator::~HistogramGenerator ( )
inlinevirtual

Default destructor.

Definition at line 47 of file HistogramGenerator.h.

47 {}

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 50 of file HistogramGenerator.h.

References ersatzt(), and x.

50 { 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 54 of file HistogramGenerator.h.

Referenced by ersatzt().

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

the axis

Definition at line 57 of file HistogramGenerator.h.

Referenced by ersatzt().