Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:25

0001 #ifndef GammaNumericalGenerator_H
0002 #define GammaNumericalGenerator_H
0003 #include "FastSimulation/Utilities/interface/BaseNumericalRandomGenerator.h"
0004 
0005 #include <cmath>
0006 /** Numerical Random Generator for Gamma distribution.
0007  *  Copy of LandauFluctuations
0008  */
0009 
0010 class RandomEngineAndDistribution;
0011 
0012 class GammaNumericalGenerator : public BaseNumericalRandomGenerator {
0013 public:
0014   /// Constructor : initialization of the Random Generator
0015   GammaNumericalGenerator(double a = 0, double b = 0, double x1 = 0, double x2 = 0)
0016       : BaseNumericalRandomGenerator(x1, x2, 1000), a_(a), b_(b), valid(false) {
0017     if (a > 0 && b > 0) {
0018       valid = true;
0019       initialize();
0020     }
0021   }
0022 
0023   /// Default destructor
0024   ~GammaNumericalGenerator() override {}
0025 
0026   /// Random generator
0027   double gamma(RandomEngineAndDistribution const* random) const { return generate(random); }
0028 
0029   double gamma_exp(RandomEngineAndDistribution const* random) const { return generateExp(random); }
0030 
0031   double gamma_lin(RandomEngineAndDistribution const* random) const { return generateLin(random); }
0032 
0033   /// The probability density function implementation
0034   double function(double x) override { return ersatzt(x); }
0035 
0036   inline bool isValid() const { return valid; }
0037 
0038 private:
0039   /// Gamma Function
0040   double ersatzt(double x) {
0041     double bt = b_ * x;
0042     return b_ * pow(bt, a_ - 1) * exp(-bt);
0043   }
0044 
0045   // gamma distribution parameters
0046   double a_, b_;
0047   bool valid;
0048 };
0049 
0050 #endif