1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#ifndef GammaNumericalGenerator_H
#define GammaNumericalGenerator_H
#include "FastSimulation/Utilities/interface/BaseNumericalRandomGenerator.h"
#include <cmath>
/** Numerical Random Generator for Gamma distribution.
* Copy of LandauFluctuations
*/
class RandomEngineAndDistribution;
class GammaNumericalGenerator : public BaseNumericalRandomGenerator {
public:
/// Constructor : initialization of the Random Generator
GammaNumericalGenerator(double a = 0, double b = 0, double x1 = 0, double x2 = 0)
: BaseNumericalRandomGenerator(x1, x2, 1000), a_(a), b_(b), valid(false) {
if (a > 0 && b > 0) {
valid = true;
initialize();
}
}
/// Default destructor
~GammaNumericalGenerator() override {}
/// Random generator
double gamma(RandomEngineAndDistribution const* random) const { return generate(random); }
double gamma_exp(RandomEngineAndDistribution const* random) const { return generateExp(random); }
double gamma_lin(RandomEngineAndDistribution const* random) const { return generateLin(random); }
/// The probability density function implementation
double function(double x) override { return ersatzt(x); }
inline bool isValid() const { return valid; }
private:
/// Gamma Function
double ersatzt(double x) {
double bt = b_ * x;
return b_ * pow(bt, a_ - 1) * exp(-bt);
}
// gamma distribution parameters
double a_, b_;
bool valid;
};
#endif
|