CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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

double function (double x) override
 The probability density function implementation. More...
 
 HistogramGenerator (TH1 *histo)
 Constructor : initialization of the Random Generator. More...
 
 ~HistogramGenerator () override
 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::HistogramGenerator ( TH1 *  histo)
inline

Constructor : initialization of the Random Generator.

Definition at line 17 of file HistogramGenerator.h.

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

18  : BaseNumericalRandomGenerator(histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax(), 100000, 3),
19  myHisto(histo),
20  theXaxis(histo->GetXaxis()),
21  nbins(histo->GetXaxis()->GetNbins()) {
22  // std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl;
23  // Drop lowest and highest empty bins
24  double du = (xmax - xmin) / (float)nbins;
25  // Restrict xmin to meaningful values
26  while (function(xmin) <= 0.)
27  xmin += du;
28  // Restrict xmax to meaningful values
29  while (function(xmax) <= 0.)
30  xmax -= du;
31 
32  if (xmin != histo->GetXaxis()->GetXmin())
33  xmin -= du;
34  if (xmax != histo->GetXaxis()->GetXmax())
35  xmax += du;
36 
37  // std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl;
38 
39  // std::cout <<" Init " << std::endl;
40  initialize();
41  }
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

◆ ~HistogramGenerator()

HistogramGenerator::~HistogramGenerator ( )
inlineoverride

Default destructor.

Definition at line 44 of file HistogramGenerator.h.

44 {}

Member Function Documentation

◆ ersatzt()

double HistogramGenerator::ersatzt ( double  x)
private

Gamma Function.

Definition at line 5 of file HistogramGenerator.cc.

References myHisto, nbins, theXaxis, x, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, testProducerWithPsetDescEmpty_cfi::y1, and testProducerWithPsetDescEmpty_cfi::y2.

Referenced by function().

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

◆ function()

double HistogramGenerator::function ( double  x)
inlineoverridevirtual

The probability density function implementation.

Implements BaseNumericalRandomGenerator.

Definition at line 47 of file HistogramGenerator.h.

References ersatzt(), and x.

47 { return ersatzt(x); }
double ersatzt(double x)
Gamma Function.

Member Data Documentation

◆ myHisto

TH1* HistogramGenerator::myHisto
private

Pointer to the histogram.

Definition at line 51 of file HistogramGenerator.h.

Referenced by ersatzt().

◆ nbins

int HistogramGenerator::nbins
private

◆ theXaxis

TAxis* HistogramGenerator::theXaxis
private

the axis

Definition at line 54 of file HistogramGenerator.h.

Referenced by ersatzt().