Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:54

0001 #ifndef HistogramGenerator_H
0002 #define HistogramGenerator_H
0003 #include "FastSimulation/Utilities/interface/BaseNumericalRandomGenerator.h"
0004 
0005 #include "TH1.h"
0006 
0007 /** Numerical Random Generator for Gamma distribution.
0008  *  Copy of LandauFluctuations
0009  */
0010 
0011 class RandomEngine;
0012 class TAxis;
0013 
0014 class HistogramGenerator : public BaseNumericalRandomGenerator {
0015 public:
0016   /// Constructor : initialization of the Random Generator
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     //    std::cout << "Old xmin/xmax = " << xmin << " " << xmax << std::endl;
0023     // Drop lowest and highest empty bins
0024     double du = (xmax - xmin) / (float)nbins;
0025     // Restrict xmin to meaningful values
0026     while (function(xmin) <= 0.)
0027       xmin += du;
0028     // Restrict xmax to meaningful values
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     //    std::cout << "New xmin/xmax = " << xmin << " " << xmax << std::endl;
0038 
0039     //    std::cout <<" Init " << std::endl;
0040     initialize();
0041   }
0042 
0043   /// Default destructor
0044   ~HistogramGenerator() override {}
0045 
0046   /// The probability density function implementation
0047   double function(double x) override { return ersatzt(x); }
0048 
0049 private:
0050   /// Pointer to the histogram
0051   TH1* myHisto;
0052 
0053   /// the axis
0054   TAxis* theXaxis;
0055 
0056   /// n bins
0057   int nbins;
0058 
0059   /// Gamma Function
0060   double ersatzt(double x);
0061 };
0062 #endif