File indexing completed on 2024-04-06 12:11:25
0001 #ifndef HistogramGenerator_H
0002 #define HistogramGenerator_H
0003 #include "FastSimulation/Utilities/interface/BaseNumericalRandomGenerator.h"
0004
0005 #include "TH1.h"
0006
0007
0008
0009
0010
0011 class RandomEngine;
0012 class TAxis;
0013
0014 class HistogramGenerator : public BaseNumericalRandomGenerator {
0015 public:
0016
0017 HistogramGenerator(TH1* histo)
0018 : BaseNumericalRandomGenerator(histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax(), 100000, 3),
0019 myHisto(histo),
0020 theXaxis(histo->GetXaxis()),
0021 nbins(histo->GetXaxis()->GetNbins()) {
0022
0023
0024 double du = (xmax - xmin) / (float)nbins;
0025
0026 while (function(xmin) <= 0.)
0027 xmin += du;
0028
0029 while (function(xmax) <= 0.)
0030 xmax -= du;
0031
0032 if (xmin != histo->GetXaxis()->GetXmin())
0033 xmin -= du;
0034 if (xmax != histo->GetXaxis()->GetXmax())
0035 xmax += du;
0036
0037
0038
0039
0040 initialize();
0041 }
0042
0043
0044 ~HistogramGenerator() override {}
0045
0046
0047 double function(double x) override { return ersatzt(x); }
0048
0049 private:
0050
0051 TH1* myHisto;
0052
0053
0054 TAxis* theXaxis;
0055
0056
0057 int nbins;
0058
0059
0060 double ersatzt(double x);
0061 };
0062 #endif