CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/FastSimulation/Utilities/interface/HistogramGenerator.h

Go to the documentation of this file.
00001 #ifndef HistogramGenerator_H
00002 #define HistogramGenerator_H
00003 #include "FastSimulation/Utilities/interface/BaseNumericalRandomGenerator.h"
00004 
00005 #include "TH1.h"
00006 
00011 class RandomEngine;
00012 class TAxis;
00013 
00014 class HistogramGenerator : public BaseNumericalRandomGenerator
00015 {
00016  public:
00017 
00019    HistogramGenerator(TH1 * histo, const RandomEngine* engine) : 
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   }
00046 
00048   virtual ~HistogramGenerator() {}
00049 
00051   virtual double function(double x) { return ersatzt(x); }
00052 
00053  private:
00055   TH1 * myHisto;
00056 
00058   TAxis * theXaxis;
00059 
00061   int nbins;
00062 
00064    double ersatzt(double x);
00065 
00066    
00067 };
00068 
00069 #endif