Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef BaseNumericalRandomGenerator_H
0002 #define BaseNumericalRandomGenerator_H
0003 
0004 /**
0005  * This abstract class provides a C++ version of the REMT package from 
0006  * Ronald Kleiss. 
0007  *
0008  * In the constructor, the probability density function according to 
0009  * which random numbers have to be generated is numerically integrated
0010  * and inversed. The arguments are the generation bounds, the size of 
0011  * the internal numerical tables, and the number of iterations for 
0012  * integration and inversion.
0013  *
0014  * The method generate() generates random number according to the 
0015  * aforementioned probability density function(). The latter must be 
0016  * implemented in a real class inheriting from BaseNumericalRandomGenerator.
0017  * (This fuction cannot be abstract, because the constructor uses it.)
0018  * A normal flat random generation between 0 and 1 is performed otherwise.
0019  *
0020  * \author Patrick Janot
0021  * $Date: 12 Jan 2004 14:40 */
0022 
0023 #include <vector>
0024 
0025 class RandomEngineAndDistribution;
0026 
0027 class BaseNumericalRandomGenerator {
0028 public:
0029   /// Constructor that perform the necessary integration and inversion steps
0030   /// xmin and xmax are the generation bounds, n is the internal table size
0031   /// and iter is the number of iterations for the numerical part.
0032   BaseNumericalRandomGenerator(double xmin = 0., double xmax = 1., int n = 1000, int iter = 6);
0033 
0034   /// Default destructor
0035   virtual ~BaseNumericalRandomGenerator() {}
0036 
0037   /// The initialization (numerical integarion, inversion)
0038   void initialize();
0039 
0040   /// The random generation according to function()
0041   double generate(RandomEngineAndDistribution const*) const;
0042 
0043   /// The random generation according to function(), refined to generate
0044   /// as an exponential in each of the intervals
0045   double generateExp(RandomEngineAndDistribution const*) const;
0046 
0047   /// The random generation according to function(), refined to generate
0048   /// as a linear function in each of the intervals
0049   double generateLin(RandomEngineAndDistribution const*) const;
0050 
0051   // The probability density function, to be implemented in the real class
0052   virtual double function(double x) = 0;
0053 
0054   /// To shoot in a given interval
0055   bool setSubInterval(double x1, double x2);
0056 
0057 protected:
0058   std::vector<double> sampling;
0059   std::vector<double> f;
0060   double xmin, xmax;
0061   int n, iter;
0062   double rmin, deltar;
0063 
0064 private:
0065   int m;
0066 };
0067 #endif