#include <FastSimulation/Utilities/interface/HistogramGenerator.h>
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 |
Definition at line 14 of file HistogramGenerator.h.
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.
00019 : 00020 BaseNumericalRandomGenerator(engine, 00021 histo->GetXaxis()->GetXmin(), 00022 histo->GetXaxis()->GetXmax(), 00023 100000, 00024 3), 00025 myHisto(histo), 00026 theXaxis(histo->GetXaxis()), 00027 nbins(histo->GetXaxis()->GetNbins()) 00028 { 00029 00030 // std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl; 00031 // Drop lowest and highest empty bins 00032 double du = (xmax-xmin)/(float)nbins; 00033 // Restrict xmin to meaningful values 00034 while ( function(xmin) <= 0. ) xmin += du; 00035 // Restrict xmax to meaningful values 00036 while ( function(xmax) <= 0. ) xmax -= du; 00037 00038 if ( xmin != histo->GetXaxis()->GetXmin() ) xmin -= du; 00039 if ( xmax != histo->GetXaxis()->GetXmax() ) xmax += du; 00040 00041 // std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl; 00042 00043 // std::cout <<" Init " << std::endl; 00044 initialize(); 00045 }
virtual HistogramGenerator::~HistogramGenerator | ( | ) | [inline, virtual] |
double HistogramGenerator::ersatzt | ( | double | x | ) | [private] |
Gamma Function.
Definition at line 5 of file HistogramGenerator.cc.
References myHisto, nbins, and theXaxis.
Referenced by function().
00006 { 00007 int ibin=theXaxis->FindBin(x); 00008 // std::cout << x << " Bin " << ibin << std::endl; 00009 double x1=myHisto->GetBinLowEdge(ibin); 00010 double x2=x1+myHisto->GetBinWidth(ibin); 00011 double y1=myHisto->GetBinContent(ibin); 00012 double y2; 00013 if(ibin<nbins) 00014 y2=myHisto->GetBinContent(ibin+1); 00015 else 00016 y2=y1; 00017 // std::cout << " X1 " << x1 <<" X2 " << x2 << " Y1 " <<y1 << " Y2 " << y2 << std::endl; 00018 return y2 + (y1-y2)*(x2-x)/(x2-x1); 00019 }
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().
TH1* HistogramGenerator::myHisto [private] |
Pointer to the histogram.
Definition at line 55 of file HistogramGenerator.h.
Referenced by ersatzt().
int HistogramGenerator::nbins [private] |
n bins
Definition at line 61 of file HistogramGenerator.h.
Referenced by ersatzt(), and HistogramGenerator().
TAxis* HistogramGenerator::theXaxis [private] |