CMS 3D CMS Logo

HistogramGenerator.h
Go to the documentation of this file.
1 #ifndef HistogramGenerator_H
2 #define HistogramGenerator_H
4 
5 #include "TH1.h"
6 
11 class RandomEngine;
12 class TAxis;
13 
15 public:
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  }
42 
44  ~HistogramGenerator() override {}
45 
47  double function(double x) override { return ersatzt(x); }
48 
49 private:
51  TH1* myHisto;
52 
54  TAxis* theXaxis;
55 
57  int nbins;
58 
60  double ersatzt(double x);
61 };
62 #endif
TH1 * myHisto
Pointer to the histogram.
~HistogramGenerator() override
Default destructor.
void initialize()
The initialization (numerical integarion, inversion)
TAxis * theXaxis
the axis
HistogramGenerator(TH1 *histo)
Constructor : initialization of the Random Generator.
double ersatzt(double x)
Gamma Function.